static int 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); if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) { av_log(avctx, AV_LOG_ERROR, "Allocated tile size %d mismatches " "parameters %d in ivi_process_empty_tile()\n", tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)); return AVERROR_INVALIDDATA; } 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; } } return 0; }


static void set_palette(AVFrame * frame, const uint8_t * palette_buffer) { uint32_t * palette = (uint32_t *)frame->data[1]; int a; for(a = 0; a < 256; a++){ palette[a] = AV_RB24(&palette_buffer[a * 3]) * 4; } frame->palette_has_changed = 1; }


static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, unsigned src_size) { const uint8_t *s = src; const uint8_t *end; #ifdef HAVE_MMX const uint8_t *mm_end; #endif uint16_t *d = (uint16_t *)dst; end = s + src_size; #ifdef HAVE_MMX mm_end = end - 15; #if 1 //is faster only if multiplies are reasonable fast (FIXME figure out on which cpus this is faster, on Athlon its slightly faster) asm volatile( "movq %3, %%mm5 \n\t" "movq %4, %%mm6 \n\t" "movq %5, %%mm7 \n\t" ".balign 16 \n\t" "1: \n\t" PREFETCH" 32(%1) \n\t" "movd (%1), %%mm0 \n\t" "movd 4(%1), %%mm3 \n\t" "punpckldq 8(%1), %%mm0 \n\t" "punpckldq 12(%1), %%mm3 \n\t" "movq %%mm0, %%mm1 \n\t" "movq %%mm3, %%mm4 \n\t" "pand %%mm6, %%mm0 \n\t" "pand %%mm6, %%mm3 \n\t" "pmaddwd %%mm7, %%mm0 \n\t" "pmaddwd %%mm7, %%mm3 \n\t" "pand %%mm5, %%mm1 \n\t" "pand %%mm5, %%mm4 \n\t" "por %%mm1, %%mm0 \n\t" "por %%mm4, %%mm3 \n\t" "psrld $6, %%mm0 \n\t" "pslld $10, %%mm3 \n\t" "por %%mm3, %%mm0 \n\t" MOVNTQ" %%mm0, (%0) \n\t" "addl $16, %1 \n\t" "addl $8, %0 \n\t" "cmpl %2, %1 \n\t" " jb 1b \n\t" : "+r" (d), "+r"(s) : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215) ); #else __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm __volatile( "movq %0, %%mm7\n\t" "movq %1, %%mm6\n\t" ::"m"(red_15mask),"m"(green_15mask)); while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movd %1, %%mm0\n\t" "movd 4%1, %%mm3\n\t" "punpckldq 8%1, %%mm0\n\t" "punpckldq 12%1, %%mm3\n\t" "movq %%mm0, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm3, %%mm4\n\t" "movq %%mm3, %%mm5\n\t" "psrlq $3, %%mm0\n\t" "psrlq $3, %%mm3\n\t" "pand %2, %%mm0\n\t" "pand %2, %%mm3\n\t" "psrlq $6, %%mm1\n\t" "psrlq $6, %%mm4\n\t" "pand %%mm6, %%mm1\n\t" "pand %%mm6, %%mm4\n\t" "psrlq $9, %%mm2\n\t" "psrlq $9, %%mm5\n\t" "pand %%mm7, %%mm2\n\t" "pand %%mm7, %%mm5\n\t" "por %%mm1, %%mm0\n\t" "por %%mm4, %%mm3\n\t" "por %%mm2, %%mm0\n\t" "por %%mm5, %%mm3\n\t" "psllq $16, %%mm3\n\t" "por %%mm3, %%mm0\n\t" MOVNTQ" %%mm0, %0\n\t" :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); d += 4; s += 16; } #endif __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { const int src= *((uint32_t*)s)++; *d++ = ((src&0xFF)>>3) + ((src&0xF800)>>6) + ((src&0xF80000)>>9); } }


void helper_do_semihosting(CPUMIPSState *env) { target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; char *p, *p2; switch (op) { case UHI_exit: qemu_log("UHI(%d): exit(%d)\n", op, (int)gpr[4]); exit(gpr[4]); case UHI_open: GET_TARGET_STRING(p, gpr[4]); if (!strcmp("/dev/stdin", p)) { gpr[2] = 0; } else if (!strcmp("/dev/stdout", p)) { gpr[2] = 1; } else if (!strcmp("/dev/stderr", p)) { gpr[2] = 2; } else { gpr[2] = open(p, get_open_flags(gpr[5]), gpr[6]); gpr[3] = errno_mips(errno); } FREE_TARGET_STRING(p, gpr[4]); break; case UHI_close: if (gpr[4] < 3) { /* ignore closing stdin/stdout/stderr */ gpr[2] = 0; goto uhi_done; } gpr[2] = close(gpr[4]); gpr[3] = errno_mips(errno); break; case UHI_read: gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], 0); gpr[3] = errno_mips(errno); break; case UHI_write: gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], 0); gpr[3] = errno_mips(errno); break; case UHI_lseek: gpr[2] = lseek(gpr[4], gpr[5], gpr[6]); gpr[3] = errno_mips(errno); break; case UHI_unlink: GET_TARGET_STRING(p, gpr[4]); gpr[2] = remove(p); gpr[3] = errno_mips(errno); FREE_TARGET_STRING(p, gpr[4]); break; case UHI_fstat: { struct stat sbuf; memset(&sbuf, 0, sizeof(sbuf)); gpr[2] = fstat(gpr[4], &sbuf); gpr[3] = errno_mips(errno); if (gpr[2]) { goto uhi_done; } gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]); gpr[3] = errno_mips(errno); } break; case UHI_argc: gpr[2] = semihosting_get_argc(); break; case UHI_argnlen: if (gpr[4] >= semihosting_get_argc()) { gpr[2] = -1; goto uhi_done; } gpr[2] = strlen(semihosting_get_arg(gpr[4])); break; case UHI_argn: if (gpr[4] >= semihosting_get_argc()) { gpr[2] = -1; goto uhi_done; } gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; case UHI_plog: GET_TARGET_STRING(p, gpr[4]); p2 = strstr(p, "%d"); if (p2) { int char_num = p2 - p; char *buf = g_malloc(char_num + 1); strncpy(buf, p, char_num); buf[char_num] = '\0'; gpr[2] = printf("%s%d%s", buf, (int)gpr[5], p2 + 2); g_free(buf); } else { gpr[2] = printf("%s", p); } FREE_TARGET_STRING(p, gpr[4]); break; case UHI_assert: GET_TARGET_STRING(p, gpr[4]); GET_TARGET_STRING(p2, gpr[5]); printf("assertion '"); printf("\"%s\"", p); printf("': file \"%s\", line %d\n", p2, (int)gpr[6]); FREE_TARGET_STRING(p2, gpr[5]); FREE_TARGET_STRING(p, gpr[4]); abort(); break; case UHI_pread: gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], gpr[7]); gpr[3] = errno_mips(errno); break; case UHI_pwrite: gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], gpr[7]); gpr[3] = errno_mips(errno); break; #ifndef _WIN32 case UHI_link: GET_TARGET_STRING(p, gpr[4]); GET_TARGET_STRING(p2, gpr[5]); gpr[2] = link(p, p2); gpr[3] = errno_mips(errno); FREE_TARGET_STRING(p2, gpr[5]); FREE_TARGET_STRING(p, gpr[4]); break; #endif default: fprintf(stderr, "Unknown UHI operation %d\n", op); abort(); } uhi_done: return; }


static int decode_mb_info(IVI5DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx) { int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, mv_scale, blks_per_mb; 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; /* 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 -1; } 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->frame_flags & 8)) { 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_bits1(&ctx->gb); } blks_per_mb = band->mb_size != band->blk_size ? 4 : 1; mb->cbp = get_bits(&ctx->gb, blks_per_mb); mb->q_delta = 0; if (band->qdelta_present) { if (band->inherit_qdelta) { if (ref_mb) mb->q_delta = ref_mb->q_delta; } else if (mb->cbp || (!band->plane && !band->band_num && (ctx->frame_flags & 8))) { 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 int init_input_stream(int ist_index, char *error, int error_len) { int i; InputStream *ist = input_streams[ist_index]; if (ist->decoding_needed) { AVCodec *codec = ist->dec; if (!codec) { snprintf(error, error_len, "Decoder (codec id %d) not found for input stream #%d:%d", ist->st->codec->codec_id, ist->file_index, ist->st->index); return AVERROR(EINVAL); } /* update requested sample format for the decoder based on the corresponding encoder sample format */ for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; if (ost->source_index == ist_index) { update_sample_fmt(ist->st->codec, codec, ost->st->codec); break; } } if (codec->type == AVMEDIA_TYPE_VIDEO && codec->capabilities & CODEC_CAP_DR1) { ist->st->codec->get_buffer = codec_get_buffer; ist->st->codec->release_buffer = codec_release_buffer; ist->st->codec->opaque = ist; } if (!av_dict_get(ist->opts, "threads", NULL, 0)) av_dict_set(&ist->opts, "threads", "auto", 0); if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { snprintf(error, error_len, "Error while opening decoder for input stream #%d:%d", ist->file_index, ist->st->index); return AVERROR(EINVAL); } assert_codec_experimental(ist->st->codec, 0); assert_avoptions(ist->opts); if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; if (ost->source_index == ist_index) { if (!ist->st->codec->channel_layout || !ost->st->codec->channel_layout) get_default_channel_layouts(ost, ist); break; } } } } ist->last_dts = ist->st->avg_frame_rate.num ? - ist->st->codec->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0; ist->next_dts = AV_NOPTS_VALUE; init_pts_correction(&ist->pts_ctx); ist->is_start = 1; return 0; }


static void init_proc_POWER9(CPUPPCState *env) { /* Common Registers */ init_proc_book3s_common(env); gen_spr_book3s_207_dbg(env); /* POWER8 Specific Registers */ gen_spr_book3s_ids(env); gen_spr_amr(env); gen_spr_iamr(env); gen_spr_book3s_purr(env); gen_spr_power5p_common(env); gen_spr_power5p_lpar(env); gen_spr_power5p_ear(env); gen_spr_power6_common(env); gen_spr_power6_dbg(env); gen_spr_power8_tce_address_control(env); gen_spr_power8_ids(env); gen_spr_power8_ebb(env); gen_spr_power8_fscr(env); gen_spr_power8_pmu_sup(env); gen_spr_power8_pmu_user(env); gen_spr_power8_tm(env); gen_spr_power8_pspb(env); gen_spr_vtb(env); gen_spr_power8_ic(env); gen_spr_power8_book4(env); gen_spr_power8_rpr(env); /* POWER9 Specific registers */ spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL, KVM_REG_PPC_TIDR, 0); /* env variables */ #if !defined(CONFIG_USER_ONLY) env->slb_nr = 32; #endif env->ci_large_pages = true; env->dcache_line_size = 128; env->icache_line_size = 128; /* Allocate hardware IRQ controller */ init_excp_POWER8(env); ppcPOWER7_irq_init(ppc_env_get_cpu(env)); }


static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { H264Context *h = avctx->priv_data; MpegEncContext *s = &h->s; AVFrame *pict = data; int buf_index; s->flags= avctx->flags; s->flags2= avctx->flags2; /* end of stream, output what is still in the buffers */ if (buf_size == 0) { Picture *out; int i, out_idx; //FIXME factorize this with the output code below out = h->delayed_pic[0]; out_idx = 0; for(i=1; h->delayed_pic[i] && h->delayed_pic[i]->poc; i++) if(h->delayed_pic[i]->poc < out->poc){ out = h->delayed_pic[i]; out_idx = i; } for(i=out_idx; h->delayed_pic[i]; i++) h->delayed_pic[i] = h->delayed_pic[i+1]; if(out){ *data_size = sizeof(AVFrame); *pict= *(AVFrame*)out; } return 0; } if(h->is_avc && !h->got_avcC) { int i, cnt, nalsize; unsigned char *p = avctx->extradata; if(avctx->extradata_size < 7) { av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); return -1; } if(*p != 1) { av_log(avctx, AV_LOG_ERROR, "Unknown avcC version %d\n", *p); return -1; } /* sps and pps in the avcC always have length coded with 2 bytes, so put a fake nal_length_size = 2 while parsing them */ h->nal_length_size = 2; // Decode sps from avcC cnt = *(p+5) & 0x1f; // Number of sps p += 6; for (i = 0; i < cnt; i++) { nalsize = AV_RB16(p) + 2; if(decode_nal_units(h, p, nalsize) < 0) { av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); return -1; } p += nalsize; } // Decode pps from avcC cnt = *(p++); // Number of pps for (i = 0; i < cnt; i++) { nalsize = AV_RB16(p) + 2; if(decode_nal_units(h, p, nalsize) != nalsize) { av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); return -1; } p += nalsize; } // Now store right nal length size, that will be use to parse all other nals h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; // Do not reparse avcC h->got_avcC = 1; } if(avctx->frame_number==0 && !h->is_avc && s->avctx->extradata_size){ if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0) return -1; } buf_index=decode_nal_units(h, buf, buf_size); if(buf_index < 0) return -1; if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0; av_log(avctx, AV_LOG_ERROR, "no frame!\n"); return -1; } if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){ Picture *out = s->current_picture_ptr; Picture *cur = s->current_picture_ptr; int i, pics, cross_idr, out_of_order, out_idx; s->mb_y= 0; s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264; s->current_picture_ptr->pict_type= s->pict_type; if(!s->dropable) { execute_ref_pic_marking(h, h->mmco, h->mmco_index); h->prev_poc_msb= h->poc_msb; h->prev_poc_lsb= h->poc_lsb; } h->prev_frame_num_offset= h->frame_num_offset; h->prev_frame_num= h->frame_num; /* * FIXME: Error handling code does not seem to support interlaced * when slices span multiple rows * The ff_er_add_slice calls don't work right for bottom * fields; they cause massive erroneous error concealing * Error marking covers both fields (top and bottom). * This causes a mismatched s->error_count * and a bad error table. Further, the error count goes to * INT_MAX when called for bottom field, because mb_y is * past end by one (callers fault) and resync_mb_y != 0 * causes problems for the first MB line, too. */ if (!FIELD_PICTURE) ff_er_frame_end(s); MPV_frame_end(s); if (s->first_field) { /* Wait for second field. */ *data_size = 0; } else { cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE; /* Derive top_field_first from field pocs. */ cur->top_field_first = cur->field_poc[0] < cur->field_poc[1]; //FIXME do something with unavailable reference frames /* Sort B-frames into display order */ if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){ s->avctx->has_b_frames = h->sps.num_reorder_frames; s->low_delay = 0; } if( s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && !h->sps.bitstream_restriction_flag){ s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT; s->low_delay= 0; } pics = 0; while(h->delayed_pic[pics]) pics++; assert(pics <= MAX_DELAYED_PIC_COUNT); h->delayed_pic[pics++] = cur; if(cur->reference == 0) cur->reference = DELAYED_PIC_REF; out = h->delayed_pic[0]; out_idx = 0; for(i=1; h->delayed_pic[i] && h->delayed_pic[i]->poc; i++) if(h->delayed_pic[i]->poc < out->poc){ out = h->delayed_pic[i]; out_idx = i; } cross_idr = !h->delayed_pic[0]->poc || !!h->delayed_pic[i]; out_of_order = !cross_idr && out->poc < h->outputed_poc; if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames) { } else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) || (s->low_delay && ((!cross_idr && out->poc > h->outputed_poc + 2) || cur->pict_type == FF_B_TYPE))) { s->low_delay = 0; s->avctx->has_b_frames++; } if(out_of_order || pics > s->avctx->has_b_frames){ out->reference &= ~DELAYED_PIC_REF; for(i=out_idx; h->delayed_pic[i]; i++) h->delayed_pic[i] = h->delayed_pic[i+1]; } if(!out_of_order && pics > s->avctx->has_b_frames){ *data_size = sizeof(AVFrame); h->outputed_poc = out->poc; *pict= *(AVFrame*)out; }else{ av_log(avctx, AV_LOG_DEBUG, "no picture\n"); } } } assert(pict->data[0] || !*data_size); ff_print_debug_info(s, pict); //printf("out %d\n", (int)pict->data[0]); #if 0 //? /* Return the Picture timestamp as the frame number */ /* we subtract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; #endif return get_consumed_bytes(s, buf_index, buf_size); }


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


void OPPROTO op_fdivr_ST0_FT0(void) { ST0 = FT0 / ST0; }


static void spectral_to_sample(AACContext *ac, int samples) { int i, type; void (*imdct_and_window)(AACContext *ac, SingleChannelElement *sce); switch (ac->oc[1].m4ac.object_type) { case AOT_ER_AAC_LD: imdct_and_window = imdct_and_windowing_ld; break; case AOT_ER_AAC_ELD: imdct_and_window = imdct_and_windowing_eld; break; default: imdct_and_window = ac->imdct_and_windowing; } for (type = 3; type >= 0; type--) { for (i = 0; i < MAX_ELEM_ID; i++) { ChannelElement *che = ac->che[type][i]; if (che && che->present) { if (type <= TYPE_CPE) apply_channel_coupling(ac, che, type, i, BEFORE_TNS, AAC_RENAME(apply_dependent_coupling)); if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) { if (che->ch[0].ics.predictor_present) { if (che->ch[0].ics.ltp.present) ac->apply_ltp(ac, &che->ch[0]); if (che->ch[1].ics.ltp.present && type == TYPE_CPE) ac->apply_ltp(ac, &che->ch[1]); } } if (che->ch[0].tns.present) ac->apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); if (che->ch[1].tns.present) ac->apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); if (type <= TYPE_CPE) apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, AAC_RENAME(apply_dependent_coupling)); if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { imdct_and_window(ac, &che->ch[0]); if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) ac->update_ltp(ac, &che->ch[0]); if (type == TYPE_CPE) { imdct_and_window(ac, &che->ch[1]); if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) ac->update_ltp(ac, &che->ch[1]); } if (ac->oc[1].m4ac.sbr > 0) { AAC_RENAME(ff_sbr_apply)(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); } } if (type <= TYPE_CCE) apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, AAC_RENAME(apply_independent_coupling)); #if USE_FIXED { int j; /* preparation for resampler */ for(j = 0; j<samples; j++){ che->ch[0].ret[j] = (int32_t)av_clip64((int64_t)che->ch[0].ret[j]<<7, INT32_MIN, INT32_MAX-0x8000)+0x8000; if(type == TYPE_CPE) che->ch[1].ret[j] = (int32_t)av_clip64((int64_t)che->ch[1].ret[j]<<7, INT32_MIN, INT32_MAX-0x8000)+0x8000; } } #endif /* USE_FIXED */ che->present = 0; } else if (che) { av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i); } } } }


static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val) { SerialState *s = opaque; unsigned char ch; addr &= 7; #ifdef DEBUG_SERIAL printf("serial: write addr=0x%02x val=0x%02x\n", addr, val); #endif switch(addr) { default: case 0: if (s->lcr & UART_LCR_DLAB) { s->divider = (s->divider & 0xff00) | val; serial_update_parameters(s); } else { s->thr_ipending = 0; s->lsr &= ~UART_LSR_THRE; serial_update_irq(s); ch = val; if (!(s->mcr & UART_MCR_LOOP)) { /* when not in loopback mode, send the char */ qemu_chr_write(s->chr, &ch, 1); } else { /* in loopback mode, say that we just received a char */ serial_receive_byte(s, ch); } if (s->tx_burst > 0) { s->tx_burst--; serial_tx_done(s); } else if (s->tx_burst == 0) { s->tx_burst--; qemu_mod_timer(s->tx_timer, qemu_get_clock(vm_clock) + ticks_per_sec * THROTTLE_TX_INTERVAL / 1000); } } break; case 1: if (s->lcr & UART_LCR_DLAB) { s->divider = (s->divider & 0x00ff) | (val << 8); serial_update_parameters(s); } else { s->ier = val & 0x0f; if (s->lsr & UART_LSR_THRE) { s->thr_ipending = 1; } serial_update_irq(s); } break; case 2: break; case 3: { int break_enable; s->lcr = val; serial_update_parameters(s); break_enable = (val >> 6) & 1; if (break_enable != s->last_break_enable) { s->last_break_enable = break_enable; qemu_chr_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK, &break_enable); } } break; case 4: s->mcr = val & 0x1f; break; case 5: break; case 6: break; case 7: s->scr = val; break; } }


int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) { int ret; if ((ret = graph_check_validity(graphctx, log_ctx))) if ((ret = graph_insert_fifos(graphctx, log_ctx)) < 0) if ((ret = graph_config_formats(graphctx, log_ctx))) if ((ret = graph_config_links(graphctx, log_ctx))) if ((ret = graph_config_pointers(graphctx, log_ctx))) return 0; }


static void process_param(float *bc, EqParameter *param, float fs) { int i; for (i = 0; i <= NBANDS; i++) { param[i].lower = i == 0 ? 0 : bands[i - 1]; param[i].upper = i == NBANDS - 1 ? fs : bands[i]; param[i].gain = bc[i]; } }


static int apng_read_packet(AVFormatContext *s, AVPacket *pkt) { APNGDemuxContext *ctx = s->priv_data; int64_t ret; int64_t size; AVIOContext *pb = s->pb; uint32_t len, tag; /* * fcTL chunk length, in bytes: * 4 (length) * 4 (tag) * 26 (actual chunk) * 4 (crc) bytes * and needed next: * 4 (length) * 4 (tag (must be fdAT or IDAT)) */ /* if num_play is not 1, then the seekback is already guaranteed */ if (ctx->num_play == 1 && (ret = ffio_ensure_seekback(pb, 46)) < 0) return ret; len = avio_rb32(pb); tag = avio_rl32(pb); switch (tag) { case MKTAG('f', 'c', 'T', 'L'): if (len != 26) return AVERROR_INVALIDDATA; if ((ret = decode_fctl_chunk(s, ctx, pkt)) < 0) return ret; /* fcTL must precede fdAT or IDAT */ len = avio_rb32(pb); tag = avio_rl32(pb); if (len > 0x7fffffff || tag != MKTAG('f', 'd', 'A', 'T') && tag != MKTAG('I', 'D', 'A', 'T')) return AVERROR_INVALIDDATA; size = 38 /* fcTL */ + 8 /* len, tag */ + len + 4 /* crc */; if (size > INT_MAX) return AVERROR(EINVAL); if ((ret = avio_seek(pb, -46, SEEK_CUR)) < 0 || (ret = av_append_packet(pb, pkt, size)) < 0) return ret; if (ctx->num_play == 1 && (ret = ffio_ensure_seekback(pb, 8)) < 0) return ret; len = avio_rb32(pb); tag = avio_rl32(pb); while (tag && tag != MKTAG('f', 'c', 'T', 'L') && tag != MKTAG('I', 'E', 'N', 'D')) { if (len > 0x7fffffff) return AVERROR_INVALIDDATA; if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0 || (ret = av_append_packet(pb, pkt, len + 12)) < 0) return ret; if (ctx->num_play == 1 && (ret = ffio_ensure_seekback(pb, 8)) < 0) return ret; len = avio_rb32(pb); tag = avio_rl32(pb); } if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0) return ret; if (ctx->is_key_frame) pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = ctx->pkt_pts; pkt->duration = ctx->pkt_duration; ctx->pkt_pts += ctx->pkt_duration; return send_extradata(ctx, pkt); case MKTAG('I', 'E', 'N', 'D'): ctx->cur_loop++; if (ctx->ignore_loop || ctx->num_play >= 1 && ctx->cur_loop == ctx->num_play) { avio_seek(pb, -8, SEEK_CUR); return AVERROR_EOF; } if ((ret = avio_seek(pb, ctx->extra_data_size + 8, SEEK_SET)) < 0) return ret; return send_extradata(ctx, pkt); default: { char tag_buf[32]; av_get_codec_tag_string(tag_buf, sizeof(tag_buf), tag); avpriv_request_sample(s, "In-stream tag=%s (0x%08X) len=%"PRIu32, tag_buf, tag, len); avio_skip(pb, len + 4); } } /* Handle the unsupported yet cases */ return AVERROR_PATCHWELCOME; }


static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx) { int ret; if (*pexpr) av_expr_free(*pexpr); *pexpr = NULL; ret = av_expr_parse(pexpr, expr, var_names, NULL, NULL, NULL, NULL, 0, log_ctx); if (ret < 0) av_log(log_ctx, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }


int MPV_encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; int i, dummy; int chroma_h_shift, chroma_v_shift; avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME s->bit_rate = avctx->bit_rate; s->width = avctx->width; s->height = avctx->height; if(avctx->gop_size > 600){ av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); avctx->gop_size=600; } s->gop_size = avctx->gop_size; s->avctx = avctx; s->flags= avctx->flags; s->flags2= avctx->flags2; s->max_b_frames= avctx->max_b_frames; s->codec_id= avctx->codec->id; s->luma_elim_threshold = avctx->luma_elim_threshold; s->chroma_elim_threshold= avctx->chroma_elim_threshold; s->strict_std_compliance= avctx->strict_std_compliance; s->data_partitioning= avctx->flags & CODEC_FLAG_PART; s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; s->mpeg_quant= avctx->mpeg_quant; s->rtp_mode= !!avctx->rtp_payload_size; if (s->gop_size <= 1) { s->intra_only = 1; s->gop_size = 12; } else { s->intra_only = 0; } s->me_method = avctx->me_method; /* Fixed QSCALE */ s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); s->adaptive_quant= ( s->avctx->lumi_masking || s->avctx->dark_masking || s->avctx->temporal_cplx_masking || s->avctx->spatial_cplx_masking || s->avctx->p_masking || (s->flags&CODEC_FLAG_QP_RD)) && !s->fixed_qscale; s->obmc= !!(s->flags & CODEC_FLAG_OBMC); s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); if(avctx->rc_max_rate && !avctx->rc_buffer_size){ av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); return -1; } if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isnt recommanded!\n"); } if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); return -1; } if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decission\n"); return -1; } if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); return -1; } if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); return -1; } if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); return -1; } if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); return -1; } if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supporetd by codec\n"); return -1; } if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){ av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); return -1; } if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); return -1; } if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet\n"); return -1; } i= ff_gcd(avctx->frame_rate, avctx->frame_rate_base); if(i > 1){ av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); avctx->frame_rate /= i; avctx->frame_rate_base /= i; // return -1; } if(s->codec_id==CODEC_ID_MJPEG){ s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x s->inter_quant_bias= 0; }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x s->inter_quant_bias= 0; }else{ s->intra_quant_bias=0; s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x } if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) s->intra_quant_bias= avctx->intra_quant_bias; if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) s->inter_quant_bias= avctx->inter_quant_bias; avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); av_reduce(&s->time_increment_resolution, &dummy, s->avctx->frame_rate, s->avctx->frame_rate_base, (1<<16)-1); s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; switch(avctx->codec->id) { case CODEC_ID_MPEG1VIDEO: s->out_format = FMT_MPEG1; s->low_delay= 0; //s->max_b_frames ? 0 : 1; avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); break; case CODEC_ID_MPEG2VIDEO: s->out_format = FMT_MPEG1; s->low_delay= 0; //s->max_b_frames ? 0 : 1; avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); s->rtp_mode= 1; break; case CODEC_ID_LJPEG: case CODEC_ID_MJPEG: s->out_format = FMT_MJPEG; s->intra_only = 1; /* force intra only for jpeg */ s->mjpeg_write_tables = 1; /* write all tables */ s->mjpeg_data_only_frames = 0; /* write all the needed headers */ s->mjpeg_vsample[0] = 1<<chroma_v_shift; s->mjpeg_vsample[1] = 1; s->mjpeg_vsample[2] = 1; s->mjpeg_hsample[0] = 1<<chroma_h_shift; s->mjpeg_hsample[1] = 1; s->mjpeg_hsample[2] = 1; if (mjpeg_init(s) < 0) return -1; avctx->delay=0; s->low_delay=1; break; #ifdef CONFIG_RISKY case CODEC_ID_H263: if (h263_get_picture_format(s->width, s->height) == 7) { av_log(avctx, AV_LOG_INFO, "Input picture size isn't suitable for h263 codec! try h263+\n"); return -1; } s->out_format = FMT_H263; s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_H263P: s->out_format = FMT_H263; s->h263_plus = 1; /* Fx */ s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0; s->modified_quant= s->h263_aic; s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; /* /Fx */ /* These are just to be sure */ avctx->delay=0; s->low_delay=1; break; case CODEC_ID_FLV1: s->out_format = FMT_H263; s->h263_flv = 2; /* format = 1; 11-bit codes */ s->unrestricted_mv = 1; s->rtp_mode=0; /* don't allow GOB */ avctx->delay=0; s->low_delay=1; break; case CODEC_ID_RV10: s->out_format = FMT_H263; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_MPEG4: s->out_format = FMT_H263; s->h263_pred = 1; s->unrestricted_mv = 1; s->low_delay= s->max_b_frames ? 0 : 1; avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); break; case CODEC_ID_MSMPEG4V1: s->out_format = FMT_H263; s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 1; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_MSMPEG4V2: s->out_format = FMT_H263; s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 2; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_MSMPEG4V3: s->out_format = FMT_H263; s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 3; s->flipflop_rounding=1; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_WMV1: s->out_format = FMT_H263; s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 4; s->flipflop_rounding=1; avctx->delay=0; s->low_delay=1; break; case CODEC_ID_WMV2: s->out_format = FMT_H263; s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 5; s->flipflop_rounding=1; avctx->delay=0; s->low_delay=1; break; #endif default: return -1; } { /* set up some save defaults, some codecs might override them later */ static int done=0; if(!done){ int i; done=1; default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); for(i=-16; i<16; i++){ default_fcode_tab[i + MAX_MV]= 1; } } } s->me.mv_penalty= default_mv_penalty; s->fcode_tab= default_fcode_tab; /* dont use mv_penalty table for crap MV as it would be confused */ //FIXME remove after fixing / removing old ME if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty; s->encoding = 1; /* init */ if (MPV_common_init(s) < 0) return -1; if(s->modified_quant) s->chroma_qscale_table= ff_h263_chroma_qscale_table; s->progressive_frame= s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)); ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); ff_init_me(s); #ifdef CONFIG_ENCODERS #ifdef CONFIG_RISKY if (s->out_format == FMT_H263) h263_encode_init(s); if(s->msmpeg4_version) ff_msmpeg4_encode_init(s); #endif if (s->out_format == FMT_MPEG1) ff_mpeg1_encode_init(s); #endif /* init default q matrix */ for(i=0;i<64;i++) { int j= s->dsp.idct_permutation[i]; #ifdef CONFIG_RISKY if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; }else if(s->out_format == FMT_H263){ s->intra_matrix[j] = s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; }else #endif { /* mpeg1/2 */ s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; } if(s->avctx->intra_matrix) s->intra_matrix[j] = s->avctx->intra_matrix[i]; if(s->avctx->inter_matrix) s->inter_matrix[j] = s->avctx->inter_matrix[i]; } /* precompute matrix */ /* for mjpeg, we do include qscale in the matrix */ if (s->out_format != FMT_MJPEG) { convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->intra_quant_bias, 1, 31); convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, s->inter_matrix, s->inter_quant_bias, 1, 31); } if(ff_rate_control_init(s) < 0) return -1; s->picture_number = 0; s->input_picture_number = 0; s->picture_in_gop_number = 0; /* motion detector init */ s->f_code = 1; s->b_code = 1; return 0; }


static int32_t ahci_dma_prepare_buf(IDEDMA *dma, int is_write) { AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma); IDEState *s = &ad->port.ifs[0]; if (ahci_populate_sglist(ad, &s->sg, s->io_buffer_offset) == -1) { DPRINTF(ad->port_no, "ahci_dma_prepare_buf failed.\n"); return -1; } s->io_buffer_size = s->sg.size; DPRINTF(ad->port_no, "len=%#x\n", s->io_buffer_size); return s->io_buffer_size; }


static int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, struct image_info * info) { struct elfhdr elf_ex; struct elfhdr interp_elf_ex; struct exec interp_ex; int interpreter_fd = -1; /* avoid warning */ unsigned long load_addr, load_bias; int load_addr_set = 0; unsigned int interpreter_type = INTERPRETER_NONE; unsigned char ibcs2_interpreter; int i; unsigned long mapped_addr; struct elf_phdr * elf_ppnt; struct elf_phdr *elf_phdata; unsigned long elf_bss, k, elf_brk; int retval; char * elf_interpreter; unsigned long elf_entry, interp_load_addr = 0; int status; unsigned long start_code, end_code, end_data; unsigned long elf_stack; char passed_fileno[6]; ibcs2_interpreter = 0; status = 0; load_addr = 0; load_bias = 0; elf_ex = *((struct elfhdr *) bprm->buf); /* exec-header */ #ifdef BSWAP_NEEDED bswap_ehdr(&elf_ex); #endif if (elf_ex.e_ident[0] != 0x7f || strncmp(&elf_ex.e_ident[1], "ELF",3) != 0) { return -ENOEXEC; } /* First of all, some simple consistency checks */ if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || (! elf_check_arch(elf_ex.e_machine))) { return -ENOEXEC; } /* Now read in all of the header information */ elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum); if (elf_phdata == NULL) { return -ENOMEM; } retval = lseek(bprm->fd, elf_ex.e_phoff, SEEK_SET); if(retval > 0) { retval = read(bprm->fd, (char *) elf_phdata, elf_ex.e_phentsize * elf_ex.e_phnum); } if (retval < 0) { perror("load_elf_binary"); exit(-1); free (elf_phdata); return -errno; } #ifdef BSWAP_NEEDED elf_ppnt = elf_phdata; for (i=0; i<elf_ex.e_phnum; i++, elf_ppnt++) { bswap_phdr(elf_ppnt); } #endif elf_ppnt = elf_phdata; elf_bss = 0; elf_brk = 0; elf_stack = ~0UL; elf_interpreter = NULL; start_code = ~0UL; end_code = 0; end_data = 0; for(i=0;i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type == PT_INTERP) { if ( elf_interpreter != NULL ) { free (elf_phdata); free(elf_interpreter); close(bprm->fd); return -EINVAL; } /* This is the program interpreter used for * shared libraries - for now assume that this * is an a.out format binary */ elf_interpreter = (char *)malloc(elf_ppnt->p_filesz); if (elf_interpreter == NULL) { free (elf_phdata); close(bprm->fd); return -ENOMEM; } retval = lseek(bprm->fd, elf_ppnt->p_offset, SEEK_SET); if(retval >= 0) { retval = read(bprm->fd, elf_interpreter, elf_ppnt->p_filesz); } if(retval < 0) { perror("load_elf_binary2"); exit(-1); } /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ /* JRP - Need to add X86 lib dir stuff here... */ if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 || strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0) { ibcs2_interpreter = 1; } #if 0 printf("Using ELF interpreter %s\n", elf_interpreter); #endif if (retval >= 0) { retval = open(path(elf_interpreter), O_RDONLY); if(retval >= 0) { interpreter_fd = retval; } else { perror(elf_interpreter); exit(-1); /* retval = -errno; */ } } if (retval >= 0) { retval = lseek(interpreter_fd, 0, SEEK_SET); if(retval >= 0) { retval = read(interpreter_fd,bprm->buf,128); } } if (retval >= 0) { interp_ex = *((struct exec *) bprm->buf); /* aout exec-header */ interp_elf_ex=*((struct elfhdr *) bprm->buf); /* elf exec-header */ } if (retval < 0) { perror("load_elf_binary3"); exit(-1); free (elf_phdata); free(elf_interpreter); close(bprm->fd); return retval; } } elf_ppnt++; } /* Some simple consistency checks for the interpreter */ if (elf_interpreter){ interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT; /* Now figure out which format our binary is */ if ((N_MAGIC(interp_ex) != OMAGIC) && (N_MAGIC(interp_ex) != ZMAGIC) && (N_MAGIC(interp_ex) != QMAGIC)) { interpreter_type = INTERPRETER_ELF; } if (interp_elf_ex.e_ident[0] != 0x7f || strncmp(&interp_elf_ex.e_ident[1], "ELF",3) != 0) { interpreter_type &= ~INTERPRETER_ELF; } if (!interpreter_type) { free(elf_interpreter); free(elf_phdata); close(bprm->fd); return -ELIBBAD; } } /* OK, we are done with that, now set up the arg stuff, and then start this sucker up */ if (!bprm->sh_bang) { char * passed_p; if (interpreter_type == INTERPRETER_AOUT) { sprintf(passed_fileno, "%d", bprm->fd); passed_p = passed_fileno; if (elf_interpreter) { bprm->p = copy_strings(1,&passed_p,bprm->page,bprm->p); bprm->argc++; } } if (!bprm->p) { if (elf_interpreter) { free(elf_interpreter); } free (elf_phdata); close(bprm->fd); return -E2BIG; } } /* OK, This is the point of no return */ info->end_data = 0; info->end_code = 0; info->start_mmap = (unsigned long)ELF_START_MMAP; info->mmap = 0; elf_entry = (unsigned long) elf_ex.e_entry; /* Do this so that we can load the interpreter, if need be. We will change some of these later */ info->rss = 0; bprm->p = setup_arg_pages(bprm->p, bprm, info); info->start_stack = bprm->p; /* Now we do a little grungy work by mmaping the ELF image into * the correct location in memory. At this point, we assume that * the image should be loaded at fixed address, not at a variable * address. */ for(i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { int elf_prot = 0; int elf_flags = 0; unsigned long error; if (elf_ppnt->p_type != PT_LOAD) continue; if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ; if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; elf_flags = MAP_PRIVATE | MAP_DENYWRITE; if (elf_ex.e_type == ET_EXEC || load_addr_set) { elf_flags |= MAP_FIXED; } else if (elf_ex.e_type == ET_DYN) { /* Try and get dynamic programs out of the way of the default mmap base, as well as whatever program they might try to exec. This is because the brk will follow the loader, and is not movable. */ /* NOTE: for qemu, we do a big mmap to get enough space without harcoding any address */ error = target_mmap(0, ET_DYN_MAP_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); if (error == -1) { perror("mmap"); exit(-1); } load_bias = TARGET_ELF_PAGESTART(error - elf_ppnt->p_vaddr); } error = target_mmap(TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr), (elf_ppnt->p_filesz + TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)), elf_prot, (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE), bprm->fd, (elf_ppnt->p_offset - TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr))); if (error == -1) { perror("mmap"); exit(-1); } #ifdef LOW_ELF_STACK if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) elf_stack = TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr); #endif if (!load_addr_set) { load_addr_set = 1; load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset; if (elf_ex.e_type == ET_DYN) { load_bias += error - TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr); load_addr += load_bias; } } k = elf_ppnt->p_vaddr; if (k < start_code) start_code = k; k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; if (k > elf_bss) elf_bss = k; if ((elf_ppnt->p_flags & PF_X) && end_code < k) end_code = k; if (end_data < k) end_data = k; k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; if (k > elf_brk) elf_brk = k; } elf_entry += load_bias; elf_bss += load_bias; elf_brk += load_bias; start_code += load_bias; end_code += load_bias; // start_data += load_bias; end_data += load_bias; if (elf_interpreter) { if (interpreter_type & 1) { elf_entry = load_aout_interp(&interp_ex, interpreter_fd); } else if (interpreter_type & 2) { elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd, &interp_load_addr); } close(interpreter_fd); free(elf_interpreter); if (elf_entry == ~0UL) { printf("Unable to load interpreter\n"); free(elf_phdata); exit(-1); return 0; } } free(elf_phdata); if (loglevel) load_symbols(&elf_ex, bprm->fd); if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd); info->personality = (ibcs2_interpreter ? PER_SVR4 : PER_LINUX); #ifdef LOW_ELF_STACK info->start_stack = bprm->p = elf_stack - 4; #endif bprm->p = (unsigned long) create_elf_tables((char *)bprm->p, bprm->argc, bprm->envc, &elf_ex, load_addr, load_bias, interp_load_addr, (interpreter_type == INTERPRETER_AOUT ? 0 : 1), info); if (interpreter_type == INTERPRETER_AOUT) info->arg_start += strlen(passed_fileno) + 1; info->start_brk = info->brk = elf_brk; info->end_code = end_code; info->start_code = start_code; info->end_data = end_data; info->start_stack = bprm->p; /* Calling set_brk effectively mmaps the pages that we need for the bss and break sections */ set_brk(elf_bss, elf_brk); padzero(elf_bss); #if 0 printf("(start_brk) %x\n" , info->start_brk); printf("(end_code) %x\n" , info->end_code); printf("(start_code) %x\n" , info->start_code); printf("(end_data) %x\n" , info->end_data); printf("(start_stack) %x\n" , info->start_stack); printf("(brk) %x\n" , info->brk); #endif if ( info->personality == PER_SVR4 ) { /* Why this, you ask??? Well SVr4 maps page 0 as read-only, and some applications "depend" upon this behavior. Since we do not have the power to recompile these, we emulate the SVr4 behavior. Sigh. */ mapped_addr = target_mmap(0, host_page_size, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, -1, 0); } #ifdef ELF_PLAT_INIT /* * The ABI may specify that certain registers be set up in special * ways (on i386 %edx is the address of a DT_FINI function, for * example. This macro performs whatever initialization to * the regs structure is required. */ ELF_PLAT_INIT(regs); #endif info->entry = elf_entry; return 0; }


static void fill_buffer(AVIOContext *s) { int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ? s->buf_end : s->buffer; int len = s->buffer_size - (dst - s->buffer); /* can't fill the buffer without read_packet, just set EOF if appropriate */ if (!s->read_packet && s->buf_ptr >= s->buf_end) s->eof_reached = 1; /* no need to do anything if EOF already reached */ if (s->eof_reached) return; if (s->update_checksum && dst == s->buffer) { if (s->buf_end > s->checksum_ptr) s->checksum = s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr); s->checksum_ptr = s->buffer; } /* make buffer smaller in case it ended up large after probing */ if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size) { if (dst == s->buffer && s->buf_ptr != dst) { int ret = ffio_set_buf_size(s, s->orig_buffer_size); if (ret < 0) av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n"); s->checksum_ptr = dst = s->buffer; } av_assert0(len >= s->orig_buffer_size); len = s->orig_buffer_size; } if (s->read_packet) len = s->read_packet(s->opaque, dst, len); else len = AVERROR_EOF; if (len == AVERROR_EOF) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ s->eof_reached = 1; } else if (len < 0) { s->eof_reached = 1; s->error= len; } else { s->pos += len; s->buf_ptr = dst; s->buf_end = dst + len; s->bytes_read += len; } }


AVFilterFormats *avfilter_make_all_channel_layouts(void) { static int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_QUAD, AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_5POINT1_BACK, AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, AV_CH_LAYOUT_7POINT1, AV_CH_LAYOUT_7POINT1_WIDE, AV_CH_LAYOUT_7POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, -1, }; return avfilter_make_format64_list(chlayouts); }


static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt) { MatroskaDemuxContext *matroska = s->priv_data; int ret = 0; while (!ret && matroska_deliver_packet(matroska, pkt)) { if (matroska->done) return AVERROR_EOF; ret = matroska_parse_cluster(matroska); } return ret; }


int av_write_header(AVFormatContext *s) { int ret, i; AVStream *st; // some sanity checks if (s->nb_streams == 0) { av_log(s, AV_LOG_ERROR, "no streams\n"); return AVERROR(EINVAL); } for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; switch (st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(st->codec->sample_rate<=0){ av_log(s, AV_LOG_ERROR, "sample rate not set\n"); return AVERROR(EINVAL); } if(!st->codec->block_align) st->codec->block_align = st->codec->channels * av_get_bits_per_sample(st->codec->codec_id) >> 3; break; case AVMEDIA_TYPE_VIDEO: if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too? av_log(s, AV_LOG_ERROR, "time base not set\n"); return AVERROR(EINVAL); } if((st->codec->width<=0 || st->codec->height<=0) && !(s->oformat->flags & AVFMT_NODIMENSIONS)){ av_log(s, AV_LOG_ERROR, "dimensions not set\n"); return AVERROR(EINVAL); } if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)){ av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder and muxer layer\n"); return AVERROR(EINVAL); } break; } if(s->oformat->codec_tag){ if(st->codec->codec_tag && st->codec->codec_id == CODEC_ID_RAWVIDEO && av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id) == 0 && !validate_codec_tag(s, st)){ //the current rawvideo encoding system ends up setting the wrong codec_tag for avi, we override it here st->codec->codec_tag= 0; } if(st->codec->codec_tag){ if (!validate_codec_tag(s, st)) { char tagbuf[32]; av_get_codec_tag_string(tagbuf, sizeof(tagbuf), st->codec->codec_tag); av_log(s, AV_LOG_ERROR, "Tag %s/0x%08x incompatible with output codec '%s'\n", tagbuf, st->codec->codec_tag, st->codec->codec->name); return AVERROR_INVALIDDATA; } }else st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id); } if(s->oformat->flags & AVFMT_GLOBALHEADER && !(st->codec->flags & CODEC_FLAG_GLOBAL_HEADER)) av_log(s, AV_LOG_WARNING, "Codec for stream %d does not use global headers but container format requires global headers\n", i); } if (!s->priv_data && s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); if (!s->priv_data) return AVERROR(ENOMEM); } #if LIBAVFORMAT_VERSION_MAJOR < 53 ff_metadata_mux_compat(s); #endif /* set muxer identification string */ if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { AVMetadata *m; AVMetadataTag *t; if (!(m = av_mallocz(sizeof(AVMetadata)))) return AVERROR(ENOMEM); av_metadata_set2(&m, "encoder", LIBAVFORMAT_IDENT, 0); metadata_conv(&m, s->oformat->metadata_conv, NULL); if ((t = av_metadata_get(m, "", NULL, AV_METADATA_IGNORE_SUFFIX))) av_metadata_set2(&s->metadata, t->key, t->value, 0); av_metadata_free(&m); } if(s->oformat->write_header){ ret = s->oformat->write_header(s); if (ret < 0) return ret; } /* init PTS generation */ for(i=0;i<s->nb_streams;i++) { int64_t den = AV_NOPTS_VALUE; st = s->streams[i]; switch (st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: den = (int64_t)st->time_base.num * st->codec->sample_rate; break; case AVMEDIA_TYPE_VIDEO: den = (int64_t)st->time_base.num * st->codec->time_base.den; break; default: break; } if (den != AV_NOPTS_VALUE) { if (den <= 0) return AVERROR_INVALIDDATA; av_frac_init(&st->pts, 0, 0, den); } } return 0; }


static TCGReg tcg_out_tlb_read(TCGContext *s, TCGMemOp s_bits, TCGReg addrlo, TCGReg addrhi, int mem_index, bool is_read) { int cmp_off = (is_read ? offsetof(CPUArchState, tlb_table[mem_index][0].addr_read) : offsetof(CPUArchState, tlb_table[mem_index][0].addr_write)); int add_off = offsetof(CPUArchState, tlb_table[mem_index][0].addend); TCGReg base = TCG_AREG0; /* Extract the page index, shifted into place for tlb index. */ if (TCG_TARGET_REG_BITS == 64) { if (TARGET_LONG_BITS == 32) { /* Zero-extend the address into a place helpful for further use. */ tcg_out_ext32u(s, TCG_REG_R4, addrlo); addrlo = TCG_REG_R4; } else { tcg_out_rld(s, RLDICL, TCG_REG_R3, addrlo, 64 - TARGET_PAGE_BITS, 64 - CPU_TLB_BITS); } } /* Compensate for very large offsets. */ if (add_off >= 0x8000) { /* Most target env are smaller than 32k; none are larger than 64k. Simplify the logic here merely to offset by 0x7ff0, giving us a range just shy of 64k. Check this assumption. */ QEMU_BUILD_BUG_ON(offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff); tcg_out32(s, ADDI | TAI(TCG_REG_TMP1, base, 0x7ff0)); base = TCG_REG_TMP1; cmp_off -= 0x7ff0; add_off -= 0x7ff0; } /* Extraction and shifting, part 2. */ if (TCG_TARGET_REG_BITS == 32 || TARGET_LONG_BITS == 32) { tcg_out_rlw(s, RLWINM, TCG_REG_R3, addrlo, 32 - (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS), 32 - (CPU_TLB_BITS + CPU_TLB_ENTRY_BITS), 31 - CPU_TLB_ENTRY_BITS); } else { tcg_out_shli64(s, TCG_REG_R3, TCG_REG_R3, CPU_TLB_ENTRY_BITS); } tcg_out32(s, ADD | TAB(TCG_REG_R3, TCG_REG_R3, base)); /* Load the tlb comparator. */ if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { tcg_out_ld(s, TCG_TYPE_I32, TCG_REG_R4, TCG_REG_R3, cmp_off); tcg_out_ld(s, TCG_TYPE_I32, TCG_REG_TMP1, TCG_REG_R3, cmp_off + 4); } else { tcg_out_ld(s, TCG_TYPE_TL, TCG_REG_TMP1, TCG_REG_R3, cmp_off); } /* Load the TLB addend for use on the fast path. Do this asap to minimize any load use delay. */ tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R3, TCG_REG_R3, add_off); /* Clear the non-page, non-alignment bits from the address. */ if (TCG_TARGET_REG_BITS == 32 || TARGET_LONG_BITS == 32) { tcg_out_rlw(s, RLWINM, TCG_REG_R0, addrlo, 0, (32 - s_bits) & 31, 31 - TARGET_PAGE_BITS); } else if (!s_bits) { tcg_out_rld(s, RLDICR, TCG_REG_R0, addrlo, 0, 63 - TARGET_PAGE_BITS); } else { tcg_out_rld(s, RLDICL, TCG_REG_R0, addrlo, 64 - TARGET_PAGE_BITS, TARGET_PAGE_BITS - s_bits); tcg_out_rld(s, RLDICL, TCG_REG_R0, TCG_REG_R0, TARGET_PAGE_BITS, 0); } if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { tcg_out_cmp(s, TCG_COND_EQ, TCG_REG_R0, TCG_REG_TMP1, 0, 7, TCG_TYPE_I32); tcg_out_cmp(s, TCG_COND_EQ, addrhi, TCG_REG_R4, 0, 6, TCG_TYPE_I32); tcg_out32(s, CRAND | BT(7, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); } else { tcg_out_cmp(s, TCG_COND_EQ, TCG_REG_R0, TCG_REG_TMP1, 0, 7, TCG_TYPE_TL); } return addrlo; }


void qemu_tcg_configure(QemuOpts *opts, Error **errp) { const char *t = qemu_opt_get(opts, "thread"); if (t) { if (strcmp(t, "multi") == 0) { if (TCG_OVERSIZED_GUEST) { error_setg(errp, "No MTTCG when guest word size > hosts"); } else if (use_icount) { error_setg(errp, "No MTTCG when icount is enabled"); } else { if (!check_tcg_memory_orders_compatible()) { error_report("Guest expects a stronger memory ordering " "than the host provides"); error_printf("This may cause strange/hard to debug errors"); } mttcg_enabled = true; } } else if (strcmp(t, "single") == 0) { mttcg_enabled = false; } else { error_setg(errp, "Invalid 'thread' setting %s", t); } } else { mttcg_enabled = default_mttcg_enabled(); } }


static int replaygain_export(AVStream *st, const uint8_t *track_gain, const uint8_t *track_peak, const uint8_t *album_gain, const uint8_t *album_peak) { AVPacketSideData *sd, *tmp; AVReplayGain *replaygain; uint8_t *data; int32_t tg, ag; uint32_t tp, ap; tg = parse_gain(track_gain); ag = parse_gain(album_gain); tp = parse_peak(track_peak); ap = parse_peak(album_peak); if (tg == INT32_MIN && ag == INT32_MIN) return 0; replaygain = av_mallocz(sizeof(*replaygain)); if (!replaygain) return AVERROR(ENOMEM); tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp)); if (!tmp) { av_freep(&replaygain); return AVERROR(ENOMEM); } st->side_data = tmp; st->nb_side_data++; sd = &st->side_data[st->nb_side_data - 1]; sd->type = AV_PKT_DATA_REPLAYGAIN; sd->data = (uint8_t*)replaygain; sd->size = sizeof(*replaygain); replaygain->track_gain = tg; replaygain->track_peak = tp; replaygain->album_gain = ag; replaygain->album_peak = ap; return 0; }


static int bytes_left(ByteIOContext *bc) { return bc->buf_end - bc->buf_ptr; }


int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { int i, ret = 0; if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) { av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n"); return AVERROR(EINVAL); } *got_sub_ptr = 0; avcodec_get_subtitle_defaults(sub); if (avpkt->size) { AVPacket pkt_recoded; AVPacket tmp = *avpkt; int did_split = av_packet_split_side_data(&tmp); //apply_param_change(avctx, &tmp); pkt_recoded = tmp; ret = recode_subtitle(avctx, &pkt_recoded, &tmp); if (ret < 0) { *got_sub_ptr = 0; } else { avctx->pkt = &pkt_recoded; if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded); av_assert1((ret >= 0) >= !!*got_sub_ptr && !!*got_sub_ptr >= !!sub->num_rects); if (sub->num_rects && !sub->end_display_time && avpkt->duration && avctx->pkt_timebase.num) { AVRational ms = { 1, 1000 }; sub->end_display_time = av_rescale_q(avpkt->duration, avctx->pkt_timebase, ms); } for (i = 0; i < sub->num_rects; i++) { if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) { av_log(avctx, AV_LOG_ERROR, "Invalid UTF-8 in decoded subtitles text; " "maybe missing -sub_charenc option\n"); avsubtitle_free(sub); return AVERROR_INVALIDDATA; } } if (tmp.data != pkt_recoded.data) { // did we recode? /* prevent from destroying side data from original packet */ pkt_recoded.side_data = NULL; pkt_recoded.side_data_elems = 0; av_free_packet(&pkt_recoded); } sub->format = !(avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB); avctx->pkt = NULL; } if (did_split) { ff_packet_free_side_data(&tmp); if(ret == tmp.size) ret = avpkt->size; } if (*got_sub_ptr) avctx->frame_number++; } return ret; }


static av_always_inline void thread_park_workers(ThreadContext *c, int thread_count) { while (c->current_job != thread_count + c->job_count) pthread_cond_wait(&c->last_job_cond, &c->current_job_lock); pthread_mutex_unlock(&c->current_job_lock); }


int ff_h264_check_intra4x4_pred_mode(H264Context *h){ MpegEncContext * const s = &h->s; static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED}; int i; if(!(h->top_samples_available&0x8000)){ for(i=0; i<4; i++){ int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ]; if(status<0){ av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); return -1; } else if(status){ h->intra4x4_pred_mode_cache[scan8[0] + i]= status; } } } if((h->left_samples_available&0x8888)!=0x8888){ static const int mask[4]={0x8000,0x2000,0x80,0x20}; for(i=0; i<4; i++){ if(!(h->left_samples_available&mask[i])){ int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ]; if(status<0){ av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); return -1; } else if(status){ h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status; } } } } return 0; } //FIXME cleanup like ff_h264_check_intra_pred_mode


static void sdram_map_bcr (ppc4xx_sdram_t *sdram) { int i; for (i = 0; i < sdram->nbanks; i++) { if (sdram->ram_sizes[i] != 0) { sdram_set_bcr(&sdram->bcr[i], sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]), 1); } else { sdram_set_bcr(&sdram->bcr[i], 0x00000000, 0); } } }


static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp) { VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); if (err) { error_propagate(errp, err); } }


static inline void gen_scas(DisasContext *s, int ot) { gen_op_mov_TN_reg(OT_LONG, 0, R_EAX); gen_string_movl_A0_EDI(s); gen_op_ld_T1_A0(ot + s->mem_index); gen_op_cmpl_T0_T1_cc(); gen_op_movl_T0_Dshift[ot](); #ifdef TARGET_X86_64 if (s->aflag == 2) { gen_op_addq_EDI_T0(); } else #endif if (s->aflag) { gen_op_addl_EDI_T0(); } else { gen_op_addw_EDI_T0(); } }


static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector) { VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev); VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); VirtQueue *vq = virtio_vector_first_queue(vdev, vector); int index; while (vq) { index = virtio_get_queue_index(vq); if (!virtio_queue_get_num(vdev, index)) { break; } virtio_pci_vq_vector_mask(proxy, index, vector); vq = virtio_vector_next_queue(vq); } }


static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) { TCGv_i32 tmp = tcg_const_i32(dest); if (((dc->pc ^ dest) & TARGET_PAGE_MASK) != 0) { slot = -1; } gen_callw_slot(dc, callinc, tmp, slot); tcg_temp_free(tmp); }


static inline void gen_neon_narrow_sats(int size, TCGv dest, TCGv src) { switch (size) { case 0: gen_helper_neon_narrow_sat_s8(dest, cpu_env, src); break; case 1: gen_helper_neon_narrow_sat_s16(dest, cpu_env, src); break; case 2: gen_helper_neon_narrow_sat_s32(dest, cpu_env, src); break; default: abort(); } }


RefPicList *ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *ref, int x0, int y0) { if (x0 < 0 || y0 < 0) { return s->ref->refPicList; } else { int x_cb = x0 >> s->sps->log2_ctb_size; int y_cb = y0 >> s->sps->log2_ctb_size; int pic_width_cb = (s->sps->width + (1 << s->sps->log2_ctb_size) - 1) >> s->sps->log2_ctb_size; int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb]; return (RefPicList *)ref->rpl_tab[ctb_addr_ts]; } }


int gtod_load(QEMUFile *f, void *opaque, int version_id) { uint64_t tod_low; uint8_t tod_high; int r; if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) { fprintf(stderr, "WARNING: Guest clock was not migrated. This could " "cause the guest to hang.\n"); return 0; } tod_high = qemu_get_byte(f); tod_low = qemu_get_be64(f); r = s390_set_clock(&tod_high, &tod_low); if (r) { fprintf(stderr, "WARNING: Unable to set guest clock value. " "s390_get_clock returned error %d. This could cause " "the guest to hang.\n", r); } return 0; }


void stw_be_phys(target_phys_addr_t addr, uint32_t val) { stw_phys_internal(addr, val, DEVICE_BIG_ENDIAN); }


static TCGv_i32 read_fp_sreg(DisasContext *s, int reg) { TCGv_i32 v = tcg_temp_new_i32(); tcg_gen_ld_i32(v, cpu_env, fp_reg_offset(reg, MO_32)); return v; }


static int kvm_client_sync_dirty_bitmap(struct CPUPhysMemoryClient *client, target_phys_addr_t start_addr, target_phys_addr_t end_addr) { return kvm_physical_sync_dirty_bitmap(start_addr, end_addr); }


static void malta_fpga_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { MaltaFPGAState *s = opaque; uint32_t saddr; saddr = (addr & 0xfffff); switch (saddr) { /* SWITCH Register */ case 0x00200: break; /* JMPRS Register */ case 0x00210: break; /* LEDBAR Register */ case 0x00408: s->leds = val & 0xff; malta_fpga_update_display(s); break; /* ASCIIWORD Register */ case 0x00410: snprintf(s->display_text, 9, "%08X", (uint32_t)val); malta_fpga_update_display(s); break; /* ASCIIPOS0 to ASCIIPOS7 Registers */ case 0x00418: case 0x00420: case 0x00428: case 0x00430: case 0x00438: case 0x00440: case 0x00448: case 0x00450: s->display_text[(saddr - 0x00418) >> 3] = (char) val; malta_fpga_update_display(s); break; /* SOFTRES Register */ case 0x00500: if (val == 0x42) qemu_system_reset_request (); break; /* BRKRES Register */ case 0x00508: s->brk = val & 0xff; break; /* UART Registers are handled directly by the serial device */ /* GPOUT Register */ case 0x00a00: s->gpout = val & 0xff; break; /* I2COE Register */ case 0x00b08: s->i2coe = val & 0x03; break; /* I2COUT Register */ case 0x00b10: eeprom24c0x_write(val & 0x02, val & 0x01); s->i2cout = val; break; /* I2CSEL Register */ case 0x00b18: s->i2csel = val & 0x01; break; default: #if 0 printf ("malta_fpga_write: Bad register offset 0x" TARGET_FMT_lx "\n", addr); #endif break; } }


static inline void reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = target - code_ptr; assert(offset == sextract64(offset, 0, 26)); /* read instruction, mask away previous PC_REL26 parameter contents, set the proper offset, then write back the instruction. */ *code_ptr = deposit32(*code_ptr, 0, 26, offset); }


static inline unsigned long align_sigframe(unsigned long sp) { unsigned long i; i = sp & ~3UL; return i; }


static av_cold void uninit(AVFilterContext *ctx) { EvalContext *eval = ctx->priv; int i; for (i = 0; i < 8; i++) { av_expr_free(eval->expr[i]); eval->expr[i] = NULL; } }


static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, int ra, int rb, int rt, int Rc) { TCGv t0, t1; t0 = tcg_temp_local_new(); t1 = tcg_temp_local_new(); switch (opc3 & 0x0D) { case 0x05: /* macchw - macchw. - macchwo - macchwo. */ /* macchws - macchws. - macchwso - macchwso. */ /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ /* mulchw - mulchw. */ tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); tcg_gen_ext16s_tl(t1, t1); break; case 0x04: /* macchwu - macchwu. - macchwuo - macchwuo. */ /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ /* mulchwu - mulchwu. */ tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); tcg_gen_ext16u_tl(t1, t1); break; case 0x01: /* machhw - machhw. - machhwo - machhwo. */ /* machhws - machhws. - machhwso - machhwso. */ /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ /* mulhhw - mulhhw. */ tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); tcg_gen_ext16s_tl(t0, t0); tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); tcg_gen_ext16s_tl(t1, t1); break; case 0x00: /* machhwu - machhwu. - machhwuo - machhwuo. */ /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ /* mulhhwu - mulhhwu. */ tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); tcg_gen_ext16u_tl(t0, t0); tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); tcg_gen_ext16u_tl(t1, t1); break; case 0x0D: /* maclhw - maclhw. - maclhwo - maclhwo. */ /* maclhws - maclhws. - maclhwso - maclhwso. */ /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ /* mullhw - mullhw. */ tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); break; case 0x0C: /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ /* mullhwu - mullhwu. */ tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); break; } if (opc2 & 0x04) { /* (n)multiply-and-accumulate (0x0C / 0x0E) */ tcg_gen_mul_tl(t1, t0, t1); if (opc2 & 0x02) { /* nmultiply-and-accumulate (0x0E) */ tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); } else { /* multiply-and-accumulate (0x0C) */ tcg_gen_add_tl(t0, cpu_gpr[rt], t1); } if (opc3 & 0x12) { /* Check overflow and/or saturate */ int l1 = gen_new_label(); if (opc3 & 0x10) { /* Start with XER OV disabled, the most likely case */ tcg_gen_movi_tl(cpu_ov, 0); } if (opc3 & 0x01) { /* Signed */ tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); if (opc3 & 0x02) { /* Saturate */ tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); tcg_gen_xori_tl(t0, t0, 0x7fffffff); } } else { /* Unsigned */ tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); if (opc3 & 0x02) { /* Saturate */ tcg_gen_movi_tl(t0, UINT32_MAX); } } if (opc3 & 0x10) { /* Check overflow */ tcg_gen_movi_tl(cpu_ov, 1); tcg_gen_movi_tl(cpu_so, 1); } gen_set_label(l1); tcg_gen_mov_tl(cpu_gpr[rt], t0); } } else { tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); } tcg_temp_free(t0); tcg_temp_free(t1); if (unlikely(Rc) != 0) { /* Update Rc0 */ gen_set_Rc0(ctx, cpu_gpr[rt]); } }


void ioinst_handle_sal(S390CPU *cpu, uint64_t reg1) { /* We do not provide address limit checking, so let's suppress it. */ if (SAL_REG1_INVALID(reg1) || reg1 & 0x000000000000ffff) { program_interrupt(&cpu->env, PGM_OPERAND, 2); } }


static void migrate_fd_put_ready(void *opaque) { MigrationState *s = opaque; int ret; if (s->state != MIG_STATE_ACTIVE) { DPRINTF("put_ready returning because of non-active state\n"); return; } DPRINTF("iterate\n"); ret = qemu_savevm_state_iterate(s->mon, s->file); if (ret < 0) { migrate_fd_error(s); } else if (ret == 1) { int old_vm_running = runstate_is_running(); DPRINTF("done iterating\n"); vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); if (qemu_savevm_state_complete(s->mon, s->file) < 0) { migrate_fd_error(s); } else { migrate_fd_completed(s); } if (s->state != MIG_STATE_COMPLETED) { if (old_vm_running) { vm_start(); } } } }


void do_info_mice(Monitor *mon, QObject **ret_data) { QEMUPutMouseEntry *cursor; QList *mice_list; int current; mice_list = qlist_new(); if (QTAILQ_EMPTY(&mouse_handlers)) { goto out; } current = QTAILQ_FIRST(&mouse_handlers)->index; QTAILQ_FOREACH(cursor, &mouse_handlers, node) { QObject *obj; obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", cursor->qemu_put_mouse_event_name, cursor->index, cursor->index == current); qlist_append_obj(mice_list, obj); } out: *ret_data = QOBJECT(mice_list); }


Visitor *validate_test_init(TestInputVisitorData *data, const char *json_string, ...) { Visitor *v; va_list ap; va_start(ap, json_string); v = validate_test_init_internal(data, json_string, &ap); va_end(ap); return v; }


static av_cold int vc1_decode_init(AVCodecContext *avctx) { VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; GetBitContext gb; /* save the container output size for WMImage */ v->output_width = avctx->width; v->output_height = avctx->height; if (!avctx->extradata_size || !avctx->extradata) return -1; if (!(avctx->flags & AV_CODEC_FLAG_GRAY)) avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts); else avctx->pix_fmt = AV_PIX_FMT_GRAY8; v->s.avctx = avctx; if (ff_vc1_init_common(v) < 0) return -1; ff_blockdsp_init(&s->bdsp, avctx); ff_h264chroma_init(&v->h264chroma, 8); ff_qpeldsp_init(&s->qdsp); if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) { int count = 0; // looks like WMV3 has a sequence header stored in the extradata // advanced sequence header may be before the first frame // the last byte of the extradata is a version number, 1 for the // samples we can decode init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8); if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) return -1; count = avctx->extradata_size*8 - get_bits_count(&gb); if (count > 0) { av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", count, get_bits_long(&gb, FFMIN(count, 32))); } else if (count < 0) { av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); } } else { // VC1/WVC1/WVP2 const uint8_t *start = avctx->extradata; uint8_t *end = avctx->extradata + avctx->extradata_size; const uint8_t *next; int size, buf2_size; uint8_t *buf2 = NULL; int seq_initialized = 0, ep_initialized = 0; if (avctx->extradata_size < 16) { av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size); return -1; } buf2 = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv next = start; for (; next < end; start = next) { next = find_next_marker(start + 4, end); size = next - start - 4; if (size <= 0) continue; buf2_size = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); switch (AV_RB32(start)) { case VC1_CODE_SEQHDR: if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) { av_free(buf2); return -1; } seq_initialized = 1; break; case VC1_CODE_ENTRYPOINT: if (ff_vc1_decode_entry_point(avctx, v, &gb) < 0) { av_free(buf2); return -1; } ep_initialized = 1; break; } } av_free(buf2); if (!seq_initialized || !ep_initialized) { av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); return -1; } v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE); } v->sprite_output_frame = av_frame_alloc(); if (!v->sprite_output_frame) return AVERROR(ENOMEM); avctx->profile = v->profile; if (v->profile == PROFILE_ADVANCED) avctx->level = v->level; avctx->has_b_frames = !!avctx->max_b_frames; if (v->color_prim == 1 || v->color_prim == 5 || v->color_prim == 6) avctx->color_primaries = v->color_prim; if (v->transfer_char == 1 || v->transfer_char == 7) avctx->color_trc = v->transfer_char; if (v->matrix_coef == 1 || v->matrix_coef == 6 || v->matrix_coef == 7) avctx->colorspace = v->matrix_coef; s->mb_width = (avctx->coded_width + 15) >> 4; s->mb_height = (avctx->coded_height + 15) >> 4; if (v->profile == PROFILE_ADVANCED || v->res_fasttx) { ff_vc1_init_transposed_scantables(v); } else { memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64); v->left_blk_sh = 3; v->top_blk_sh = 0; } if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { v->sprite_width = avctx->coded_width; v->sprite_height = avctx->coded_height; avctx->coded_width = avctx->width = v->output_width; avctx->coded_height = avctx->height = v->output_height; // prevent 16.16 overflows if (v->sprite_width > 1 << 14 || v->sprite_height > 1 << 14 || v->output_width > 1 << 14 || v->output_height > 1 << 14) return -1; } return 0; }


static void show_packets(AVFormatContext *fmt_ctx) { AVPacket pkt; av_init_packet(&pkt); while (!av_read_frame(fmt_ctx, &pkt)) show_packet(fmt_ctx, &pkt); }


static int http_open_cnx_internal(URLContext *h, AVDictionary **options) { const char *path, *proxy_path, *lower_proto = "tcp", *local_path; char hostname[1024], hoststr[1024], proto[10]; char auth[1024], proxyauth[1024] = ""; char path1[MAX_URL_SIZE]; char buf[1024], urlbuf[MAX_URL_SIZE]; int port, use_proxy, err, location_changed = 0; HTTPContext *s = h->priv_data; av_url_split(proto, sizeof(proto), auth, sizeof(auth), hostname, sizeof(hostname), &port, path1, sizeof(path1), s->location); ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); proxy_path = getenv("http_proxy"); use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) && proxy_path != NULL && av_strstart(proxy_path, "http://", NULL); if (!strcmp(proto, "https")) { lower_proto = "tls"; use_proxy = 0; if (port < 0) port = 443; } if (port < 0) port = 80; if (path1[0] == '\0') path = "/"; else path = path1; local_path = path; if (use_proxy) { /* Reassemble the request URL without auth string - we don't * want to leak the auth to the proxy. */ ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s", path1); path = urlbuf; av_url_split(NULL, 0, proxyauth, sizeof(proxyauth), hostname, sizeof(hostname), &port, NULL, 0, proxy_path); } ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); if (!s->hd) { err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback, options); if (err < 0) return err; } err = http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed); if (err < 0) return err; return location_changed; }


qio_channel_command_new_spawn(const char *const argv[], int flags, Error **errp) { pid_t pid = -1; int stdinfd[2] = { -1, -1 }; int stdoutfd[2] = { -1, -1 }; int devnull = -1; bool stdinnull = false, stdoutnull = false; QIOChannelCommand *ioc; flags = flags & O_ACCMODE; if (flags == O_RDONLY) { stdinnull = true; } if (flags == O_WRONLY) { stdoutnull = true; } if (stdinnull || stdoutnull) { devnull = open("/dev/null", O_RDWR); if (!devnull) { error_setg_errno(errp, errno, "Unable to open /dev/null"); goto error; } } if ((!stdinnull && pipe(stdinfd) < 0) || (!stdoutnull && pipe(stdoutfd) < 0)) { error_setg_errno(errp, errno, "Unable to open pipe"); goto error; } pid = qemu_fork(errp); if (pid < 0) { goto error; } if (pid == 0) { /* child */ dup2(stdinnull ? devnull : stdinfd[0], STDIN_FILENO); dup2(stdoutnull ? devnull : stdoutfd[1], STDOUT_FILENO); /* Leave stderr connected to qemu's stderr */ if (!stdinnull) { close(stdinfd[0]); close(stdinfd[1]); } if (!stdoutnull) { close(stdoutfd[0]); close(stdoutfd[1]); } execv(argv[0], (char * const *)argv); _exit(1); } if (!stdinnull) { close(stdinfd[0]); } if (!stdoutnull) { close(stdoutfd[1]); } ioc = qio_channel_command_new_pid(stdinnull ? devnull : stdinfd[1], stdoutnull ? devnull : stdoutfd[0], pid); trace_qio_channel_command_new_spawn(ioc, argv[0], flags); return ioc; error: if (stdinfd[0] != -1) { close(stdinfd[0]); } if (stdinfd[1] != -1) { close(stdinfd[1]); } if (stdoutfd[0] != -1) { close(stdoutfd[0]); } if (stdoutfd[1] != -1) { close(stdoutfd[1]); } return NULL; }


static int div_round (int dividend, int divisor) { if (dividend > 0) return (dividend + (divisor>>1)) / divisor; else return -((-dividend + (divisor>>1)) / divisor); }


long do_sigreturn(CPUX86State *env) { struct sigframe *frame; abi_ulong frame_addr = env->regs[R_ESP] - 8; target_sigset_t target_set; sigset_t set; int eax, i; #if defined(DEBUG_SIGNAL) fprintf(stderr, "do_sigreturn\n"); #endif if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; /* set blocked signals */ if (__get_user(target_set.sig[0], &frame->sc.oldmask)) goto badframe; for(i = 1; i < TARGET_NSIG_WORDS; i++) { if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) goto badframe; } target_to_host_sigset_internal(&set, &target_set); do_sigprocmask(SIG_SETMASK, &set, NULL); /* restore registers */ if (restore_sigcontext(env, &frame->sc, &eax)) goto badframe; unlock_user_struct(frame, frame_addr, 0); return eax; badframe: unlock_user_struct(frame, frame_addr, 0); force_sig(TARGET_SIGSEGV); return 0; }


void cpu_dump_state(CPUXtensaState *env, FILE *f, fprintf_function cpu_fprintf, int flags) { int i, j; cpu_fprintf(f, "PC=%08x\n\n", env->pc); for (i = j = 0; i < 256; ++i) { if (sregnames[i]) { cpu_fprintf(f, "%s=%08x%c", sregnames[i], env->sregs[i], (j++ % 4) == 3 ? '\n' : ' '); } } cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n"); for (i = j = 0; i < 256; ++i) { if (uregnames[i]) { cpu_fprintf(f, "%s=%08x%c", uregnames[i], env->uregs[i], (j++ % 4) == 3 ? '\n' : ' '); } } cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n"); for (i = 0; i < 16; ++i) { cpu_fprintf(f, "A%02d=%08x%c", i, env->regs[i], (i % 4) == 3 ? '\n' : ' '); } cpu_fprintf(f, "\n"); for (i = 0; i < env->config->nareg; ++i) { cpu_fprintf(f, "AR%02d=%08x%c", i, env->phys_regs[i], (i % 4) == 3 ? '\n' : ' '); } if (xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) { cpu_fprintf(f, "\n"); for (i = 0; i < 16; ++i) { cpu_fprintf(f, "F%02d=%08x (%+10.8e)%c", i, float32_val(env->fregs[i]), *(float *)&env->fregs[i], (i % 2) == 1 ? '\n' : ' '); } } }


int kvm_arch_init(KVMState *s) { uint64_t identity_base = 0xfffbc000; int ret; struct utsname utsname; ret = kvm_get_supported_msrs(s); if (ret < 0) { return ret; } uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0; /* * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. * In order to use vm86 mode, an EPT identity map and a TSS are needed. * Since these must be part of guest physical memory, we need to allocate * them, both by setting their start addresses in the kernel and by * creating a corresponding e820 entry. We need 4 pages before the BIOS. * * Older KVM versions may not support setting the identity map base. In * that case we need to stick with the default, i.e. a 256K maximum BIOS * size. */ #ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR if (kvm_check_extension(s, KVM_CAP_SET_IDENTITY_MAP_ADDR)) { /* Allows up to 16M BIOSes. */ identity_base = 0xfeffc000; ret = kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &identity_base); if (ret < 0) { return ret; } } #endif /* Set TSS base one page after EPT identity map. */ ret = kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base + 0x1000); if (ret < 0) { return ret; } /* Tell fw_cfg to notify the BIOS to reserve the range. */ ret = e820_add_entry(identity_base, 0x4000, E820_RESERVED); if (ret < 0) { fprintf(stderr, "e820_add_entry() table is full\n"); return ret; } return 0; }


static int matroska_parse_tracks(AVFormatContext *s) { MatroskaDemuxContext *matroska = s->priv_data; MatroskaTrack *tracks = matroska->tracks.elem; AVStream *st; int i, j, ret; int k; for (i = 0; i < matroska->tracks.nb_elem; i++) { MatroskaTrack *track = &tracks[i]; enum AVCodecID codec_id = AV_CODEC_ID_NONE; EbmlList *encodings_list = &track->encodings; MatroskaTrackEncoding *encodings = encodings_list->elem; uint8_t *extradata = NULL; int extradata_size = 0; int extradata_offset = 0; uint32_t fourcc = 0; AVIOContext b; char* key_id_base64 = NULL; int bit_depth = -1; /* Apply some sanity checks. */ if (track->type != MATROSKA_TRACK_TYPE_VIDEO && track->type != MATROSKA_TRACK_TYPE_AUDIO && track->type != MATROSKA_TRACK_TYPE_SUBTITLE && track->type != MATROSKA_TRACK_TYPE_METADATA) { av_log(matroska->ctx, AV_LOG_INFO, "Unknown or unsupported track type %"PRIu64"\n", track->type); continue; } if (!track->codec_id) continue; if (track->audio.samplerate < 0 || track->audio.samplerate > INT_MAX || isnan(track->audio.samplerate)) { av_log(matroska->ctx, AV_LOG_WARNING, "Invalid sample rate %f, defaulting to 8000 instead.\n", track->audio.samplerate); track->audio.samplerate = 8000; } if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { if (!track->default_duration && track->video.frame_rate > 0) track->default_duration = 1000000000 / track->video.frame_rate; if (track->video.display_width == -1) track->video.display_width = track->video.pixel_width; if (track->video.display_height == -1) track->video.display_height = track->video.pixel_height; if (track->video.color_space.size == 4) fourcc = AV_RL32(track->video.color_space.data); } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { if (!track->audio.out_samplerate) track->audio.out_samplerate = track->audio.samplerate; } if (encodings_list->nb_elem > 1) { av_log(matroska->ctx, AV_LOG_ERROR, "Multiple combined encodings not supported"); } else if (encodings_list->nb_elem == 1) { if (encodings[0].type) { if (encodings[0].encryption.key_id.size > 0) { /* Save the encryption key id to be stored later as a metadata tag. */ const int b64_size = AV_BASE64_SIZE(encodings[0].encryption.key_id.size); key_id_base64 = av_malloc(b64_size); if (key_id_base64 == NULL) return AVERROR(ENOMEM); av_base64_encode(key_id_base64, b64_size, encodings[0].encryption.key_id.data, encodings[0].encryption.key_id.size); } else { encodings[0].scope = 0; av_log(matroska->ctx, AV_LOG_ERROR, "Unsupported encoding type"); } } else if ( #if CONFIG_ZLIB encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB && #endif #if CONFIG_BZLIB encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB && #endif #if CONFIG_LZO encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO && #endif encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP) { encodings[0].scope = 0; av_log(matroska->ctx, AV_LOG_ERROR, "Unsupported encoding type"); } else if (track->codec_priv.size && encodings[0].scope & 2) { uint8_t *codec_priv = track->codec_priv.data; int ret = matroska_decode_buffer(&track->codec_priv.data, &track->codec_priv.size, track); if (ret < 0) { track->codec_priv.data = NULL; track->codec_priv.size = 0; av_log(matroska->ctx, AV_LOG_ERROR, "Failed to decode codec private data\n"); } if (codec_priv != track->codec_priv.data) av_free(codec_priv); } } for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { if (!strncmp(ff_mkv_codec_tags[j].str, track->codec_id, strlen(ff_mkv_codec_tags[j].str))) { codec_id = ff_mkv_codec_tags[j].id; break; } } st = track->stream = avformat_new_stream(s, NULL); if (!st) { av_free(key_id_base64); return AVERROR(ENOMEM); } if (key_id_base64) { /* export encryption key id as base64 metadata tag */ av_dict_set(&st->metadata, "enc_key_id", key_id_base64, 0); av_freep(&key_id_base64); } if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") && track->codec_priv.size >= 40 && track->codec_priv.data) { track->ms_compat = 1; bit_depth = AV_RL16(track->codec_priv.data + 14); fourcc = AV_RL32(track->codec_priv.data + 16); codec_id = ff_codec_get_id(ff_codec_bmp_tags, fourcc); if (!codec_id) codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc); extradata_offset = 40; } else if (!strcmp(track->codec_id, "A_MS/ACM") && track->codec_priv.size >= 14 && track->codec_priv.data) { int ret; ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL); ret = ff_get_wav_header(s, &b, st->codecpar, track->codec_priv.size, 0); if (ret < 0) return ret; codec_id = st->codecpar->codec_id; fourcc = st->codecpar->codec_tag; extradata_offset = FFMIN(track->codec_priv.size, 18); } else if (!strcmp(track->codec_id, "A_QUICKTIME") /* Normally 36, but allow noncompliant private data */ && (track->codec_priv.size >= 32) && (track->codec_priv.data)) { uint16_t sample_size; int ret = get_qt_codec(track, &fourcc, &codec_id); if (ret < 0) return ret; sample_size = AV_RB16(track->codec_priv.data + 26); if (fourcc == 0) { if (sample_size == 8) { fourcc = MKTAG('r','a','w',' '); codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc); } else if (sample_size == 16) { fourcc = MKTAG('t','w','o','s'); codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc); } } if ((fourcc == MKTAG('t','w','o','s') || fourcc == MKTAG('s','o','w','t')) && sample_size == 8) codec_id = AV_CODEC_ID_PCM_S8; } else if (!strcmp(track->codec_id, "V_QUICKTIME") && (track->codec_priv.size >= 21) && (track->codec_priv.data)) { int ret = get_qt_codec(track, &fourcc, &codec_id); if (ret < 0) return ret; if (codec_id == AV_CODEC_ID_NONE && AV_RL32(track->codec_priv.data+4) == AV_RL32("SMI ")) { fourcc = MKTAG('S','V','Q','3'); codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc); } if (codec_id == AV_CODEC_ID_NONE) av_log(matroska->ctx, AV_LOG_ERROR, "mov FourCC not found %s.\n", av_fourcc2str(fourcc)); if (track->codec_priv.size >= 86) { bit_depth = AV_RB16(track->codec_priv.data + 82); ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL); if (ff_get_qtpalette(codec_id, &b, track->palette)) { bit_depth &= 0x1F; track->has_palette = 1; } } } else if (codec_id == AV_CODEC_ID_PCM_S16BE) { switch (track->audio.bitdepth) { case 8: codec_id = AV_CODEC_ID_PCM_U8; break; case 24: codec_id = AV_CODEC_ID_PCM_S24BE; break; case 32: codec_id = AV_CODEC_ID_PCM_S32BE; break; } } else if (codec_id == AV_CODEC_ID_PCM_S16LE) { switch (track->audio.bitdepth) { case 8: codec_id = AV_CODEC_ID_PCM_U8; break; case 24: codec_id = AV_CODEC_ID_PCM_S24LE; break; case 32: codec_id = AV_CODEC_ID_PCM_S32LE; break; } } else if (codec_id == AV_CODEC_ID_PCM_F32LE && track->audio.bitdepth == 64) { codec_id = AV_CODEC_ID_PCM_F64LE; } else if (codec_id == AV_CODEC_ID_AAC && !track->codec_priv.size) { int profile = matroska_aac_profile(track->codec_id); int sri = matroska_aac_sri(track->audio.samplerate); extradata = av_mallocz(5 + AV_INPUT_BUFFER_PADDING_SIZE); if (!extradata) return AVERROR(ENOMEM); extradata[0] = (profile << 3) | ((sri & 0x0E) >> 1); extradata[1] = ((sri & 0x01) << 7) | (track->audio.channels << 3); if (strstr(track->codec_id, "SBR")) { sri = matroska_aac_sri(track->audio.out_samplerate); extradata[2] = 0x56; extradata[3] = 0xE5; extradata[4] = 0x80 | (sri << 3); extradata_size = 5; } else extradata_size = 2; } else if (codec_id == AV_CODEC_ID_ALAC && track->codec_priv.size && track->codec_priv.size < INT_MAX - 12 - AV_INPUT_BUFFER_PADDING_SIZE) { /* Only ALAC's magic cookie is stored in Matroska's track headers. * Create the "atom size", "tag", and "tag version" fields the * decoder expects manually. */ extradata_size = 12 + track->codec_priv.size; extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!extradata) return AVERROR(ENOMEM); AV_WB32(extradata, extradata_size); memcpy(&extradata[4], "alac", 4); AV_WB32(&extradata[8], 0); memcpy(&extradata[12], track->codec_priv.data, track->codec_priv.size); } else if (codec_id == AV_CODEC_ID_TTA) { extradata_size = 30; extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!extradata) return AVERROR(ENOMEM); ffio_init_context(&b, extradata, extradata_size, 1, NULL, NULL, NULL, NULL); avio_write(&b, "TTA1", 4); avio_wl16(&b, 1); if (track->audio.channels > UINT16_MAX || track->audio.bitdepth > UINT16_MAX) { av_log(matroska->ctx, AV_LOG_WARNING, "Too large audio channel number %"PRIu64 " or bitdepth %"PRIu64". Skipping track.\n", track->audio.channels, track->audio.bitdepth); av_freep(&extradata); if (matroska->ctx->error_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; else continue; } avio_wl16(&b, track->audio.channels); avio_wl16(&b, track->audio.bitdepth); if (track->audio.out_samplerate < 0 || track->audio.out_samplerate > INT_MAX) return AVERROR_INVALIDDATA; avio_wl32(&b, track->audio.out_samplerate); avio_wl32(&b, av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)); } else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 || codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) { extradata_offset = 26; } else if (codec_id == AV_CODEC_ID_RA_144) { track->audio.out_samplerate = 8000; track->audio.channels = 1; } else if ((codec_id == AV_CODEC_ID_RA_288 || codec_id == AV_CODEC_ID_COOK || codec_id == AV_CODEC_ID_ATRAC3 || codec_id == AV_CODEC_ID_SIPR) && track->codec_priv.data) { int flavor; ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL); avio_skip(&b, 22); flavor = avio_rb16(&b); track->audio.coded_framesize = avio_rb32(&b); avio_skip(&b, 12); track->audio.sub_packet_h = avio_rb16(&b); track->audio.frame_size = avio_rb16(&b); track->audio.sub_packet_size = avio_rb16(&b); if (flavor < 0 || track->audio.coded_framesize <= 0 || track->audio.sub_packet_h <= 0 || track->audio.frame_size <= 0 || track->audio.sub_packet_size <= 0 && codec_id != AV_CODEC_ID_SIPR) return AVERROR_INVALIDDATA; track->audio.buf = av_malloc_array(track->audio.sub_packet_h, track->audio.frame_size); if (!track->audio.buf) return AVERROR(ENOMEM); if (codec_id == AV_CODEC_ID_RA_288) { st->codecpar->block_align = track->audio.coded_framesize; track->codec_priv.size = 0; } else { if (codec_id == AV_CODEC_ID_SIPR && flavor < 4) { static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 }; track->audio.sub_packet_size = ff_sipr_subpk_size[flavor]; st->codecpar->bit_rate = sipr_bit_rate[flavor]; } st->codecpar->block_align = track->audio.sub_packet_size; extradata_offset = 78; } } else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) { ret = matroska_parse_flac(s, track, &extradata_offset); if (ret < 0) return ret; } else if (codec_id == AV_CODEC_ID_PRORES && track->codec_priv.size == 4) { fourcc = AV_RL32(track->codec_priv.data); } track->codec_priv.size -= extradata_offset; if (codec_id == AV_CODEC_ID_NONE) av_log(matroska->ctx, AV_LOG_INFO, "Unknown/unsupported AVCodecID %s.\n", track->codec_id); if (track->time_scale < 0.01) track->time_scale = 1.0; avpriv_set_pts_info(st, 64, matroska->time_scale * track->time_scale, 1000 * 1000 * 1000); /* 64 bit pts in ns */ /* convert the delay from ns to the track timebase */ track->codec_delay_in_track_tb = av_rescale_q(track->codec_delay, (AVRational){ 1, 1000000000 }, st->time_base); st->codecpar->codec_id = codec_id; if (strcmp(track->language, "und")) av_dict_set(&st->metadata, "language", track->language, 0); av_dict_set(&st->metadata, "title", track->name, 0); if (track->flag_default) st->disposition |= AV_DISPOSITION_DEFAULT; if (track->flag_forced) st->disposition |= AV_DISPOSITION_FORCED; if (!st->codecpar->extradata) { if (extradata) { st->codecpar->extradata = extradata; st->codecpar->extradata_size = extradata_size; } else if (track->codec_priv.data && track->codec_priv.size > 0) { if (ff_alloc_extradata(st->codecpar, track->codec_priv.size)) return AVERROR(ENOMEM); memcpy(st->codecpar->extradata, track->codec_priv.data + extradata_offset, track->codec_priv.size); } } if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { MatroskaTrackPlane *planes = track->operation.combine_planes.elem; int display_width_mul = 1; int display_height_mul = 1; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_tag = fourcc; if (bit_depth >= 0) st->codecpar->bits_per_coded_sample = bit_depth; st->codecpar->width = track->video.pixel_width; st->codecpar->height = track->video.pixel_height; if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED) st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order); else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE) st->codecpar->field_order = AV_FIELD_PROGRESSIVE; if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB) mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul); if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) { av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, st->codecpar->height * track->video.display_width * display_width_mul, st->codecpar->width * track->video.display_height * display_height_mul, 255); } if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) st->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, 1000000000, track->default_duration, 30000); #if FF_API_R_FRAME_RATE if ( st->avg_frame_rate.num < st->avg_frame_rate.den * 1000LL && st->avg_frame_rate.num > st->avg_frame_rate.den * 5LL) st->r_frame_rate = st->avg_frame_rate; #endif } /* export stereo mode flag as metadata tag */ if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB) av_dict_set(&st->metadata, "stereo_mode", ff_matroska_video_stereo_mode[track->video.stereo_mode], 0); /* export alpha mode flag as metadata tag */ if (track->video.alpha_mode) av_dict_set(&st->metadata, "alpha_mode", "1", 0); /* if we have virtual track, mark the real tracks */ for (j=0; j < track->operation.combine_planes.nb_elem; j++) { char buf[32]; if (planes[j].type >= MATROSKA_VIDEO_STEREO_PLANE_COUNT) continue; snprintf(buf, sizeof(buf), "%s_%d", ff_matroska_video_stereo_plane[planes[j].type], i); for (k=0; k < matroska->tracks.nb_elem; k++) if (planes[j].uid == tracks[k].uid && tracks[k].stream) { av_dict_set(&tracks[k].stream->metadata, "stereo_mode", buf, 0); break; } } // add stream level stereo3d side data if it is a supported format if (track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB && track->video.stereo_mode != 10 && track->video.stereo_mode != 12) { int ret = ff_mkv_stereo3d_conv(st, track->video.stereo_mode); if (ret < 0) return ret; } ret = mkv_parse_video_color(st, track); if (ret < 0) return ret; ret = mkv_parse_video_projection(st, track); if (ret < 0) return ret; } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_tag = fourcc; st->codecpar->sample_rate = track->audio.out_samplerate; st->codecpar->channels = track->audio.channels; if (!st->codecpar->bits_per_coded_sample) st->codecpar->bits_per_coded_sample = track->audio.bitdepth; if (st->codecpar->codec_id == AV_CODEC_ID_MP3) st->need_parsing = AVSTREAM_PARSE_FULL; else if (st->codecpar->codec_id != AV_CODEC_ID_AAC) st->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->codec_delay > 0) { st->codecpar->initial_padding = av_rescale_q(track->codec_delay, (AVRational){1, 1000000000}, (AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ? 48000 : st->codecpar->sample_rate}); } if (track->seek_preroll > 0) { st->codecpar->seek_preroll = av_rescale_q(track->seek_preroll, (AVRational){1, 1000000000}, (AVRational){1, st->codecpar->sample_rate}); } } else if (codec_id == AV_CODEC_ID_WEBVTT) { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; if (!strcmp(track->codec_id, "D_WEBVTT/CAPTIONS")) { st->disposition |= AV_DISPOSITION_CAPTIONS; } else if (!strcmp(track->codec_id, "D_WEBVTT/DESCRIPTIONS")) { st->disposition |= AV_DISPOSITION_DESCRIPTIONS; } else if (!strcmp(track->codec_id, "D_WEBVTT/METADATA")) { st->disposition |= AV_DISPOSITION_METADATA; } } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; if (st->codecpar->codec_id == AV_CODEC_ID_ASS) matroska->contains_ssa = 1; } } return 0; }


static void vnc_display_close(VncDisplay *vd) { size_t i; if (!vd) { return; } vd->is_unix = false; for (i = 0; i < vd->nlsock; i++) { if (vd->lsock_tag[i]) { g_source_remove(vd->lsock_tag[i]); } object_unref(OBJECT(vd->lsock[i])); } g_free(vd->lsock); g_free(vd->lsock_tag); vd->lsock = NULL; vd->lsock_tag = NULL; vd->nlsock = 0; for (i = 0; i < vd->nlwebsock; i++) { if (vd->lwebsock_tag[i]) { g_source_remove(vd->lwebsock_tag[i]); } object_unref(OBJECT(vd->lwebsock[i])); } g_free(vd->lwebsock); g_free(vd->lwebsock_tag); vd->lwebsock = NULL; vd->lwebsock_tag = NULL; vd->nlwebsock = 0; vd->auth = VNC_AUTH_INVALID; vd->subauth = VNC_AUTH_INVALID; if (vd->tlscreds) { object_unparent(OBJECT(vd->tlscreds)); vd->tlscreds = NULL; } g_free(vd->tlsaclname); vd->tlsaclname = NULL; if (vd->lock_key_sync) { qemu_remove_led_event_handler(vd->led); } }