project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
FFmpeg
257c85cddde8633caffb76e97e9710b1aebfc511
1
static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int *coded_samples) { ADPCMDecodeContext *s = avctx->priv_data; int nb_samples = 0; int ch = avctx->channels; int has_coded_samples = 0; int header_size; *coded_samples = 0; switch (avctx->codec->id) { /* constant, only check buf_size */ case CODEC_ID_ADPCM_EA_XAS: if (buf_size < 76 * ch) nb_samples = 128; break; case CODEC_ID_ADPCM_IMA_QT: if (buf_size < 34 * ch) nb_samples = 64; break; /* simple 4-bit adpcm */ case CODEC_ID_ADPCM_CT: case CODEC_ID_ADPCM_IMA_EA_SEAD: case CODEC_ID_ADPCM_IMA_WS: case CODEC_ID_ADPCM_YAMAHA: nb_samples = buf_size * 2 / ch; break; } if (nb_samples) return nb_samples; /* simple 4-bit adpcm, with header */ header_size = 0; switch (avctx->codec->id) { case CODEC_ID_ADPCM_4XM: case CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break; case CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break; case CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4; break; } if (header_size > 0) return (buf_size - header_size) * 2 / ch; /* more complex formats */ switch (avctx->codec->id) { case CODEC_ID_ADPCM_EA: has_coded_samples = 1; if (buf_size < 4) *coded_samples = AV_RL32(buf); *coded_samples -= *coded_samples % 28; nb_samples = (buf_size - 12) / 30 * 28; break; case CODEC_ID_ADPCM_IMA_EA_EACS: has_coded_samples = 1; if (buf_size < 4) *coded_samples = AV_RL32(buf); nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch; break; case CODEC_ID_ADPCM_EA_MAXIS_XA: nb_samples = ((buf_size - ch) / (2 * ch)) * 2 * ch; break; case CODEC_ID_ADPCM_EA_R1: case CODEC_ID_ADPCM_EA_R2: case CODEC_ID_ADPCM_EA_R3: /* maximum number of samples */ /* has internal offsets and a per-frame switch to signal raw 16-bit */ has_coded_samples = 1; if (buf_size < 4) switch (avctx->codec->id) { case CODEC_ID_ADPCM_EA_R1: header_size = 4 + 9 * ch; *coded_samples = AV_RL32(buf); break; case CODEC_ID_ADPCM_EA_R2: header_size = 4 + 5 * ch; *coded_samples = AV_RL32(buf); break; case CODEC_ID_ADPCM_EA_R3: header_size = 4 + 5 * ch; *coded_samples = AV_RB32(buf); break; } *coded_samples -= *coded_samples % 28; nb_samples = (buf_size - header_size) * 2 / ch; nb_samples -= nb_samples % 28; break; case CODEC_ID_ADPCM_IMA_DK3: if (avctx->block_align > 0) buf_size = FFMIN(buf_size, avctx->block_align); nb_samples = ((buf_size - 16) * 8 / 3) / ch; break; case CODEC_ID_ADPCM_IMA_DK4: nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch; break; case CODEC_ID_ADPCM_IMA_WAV: if (avctx->block_align > 0) buf_size = FFMIN(buf_size, avctx->block_align); nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8; break; case CODEC_ID_ADPCM_MS: if (avctx->block_align > 0) buf_size = FFMIN(buf_size, avctx->block_align); nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch; break; case CODEC_ID_ADPCM_SBPRO_2: case CODEC_ID_ADPCM_SBPRO_3: case CODEC_ID_ADPCM_SBPRO_4: { int samples_per_byte; switch (avctx->codec->id) { case CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break; case CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break; case CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break; } if (!s->status[0].step_index) { nb_samples++; buf_size -= ch; } nb_samples += buf_size * samples_per_byte / ch; break; } case CODEC_ID_ADPCM_SWF: { int buf_bits = buf_size * 8 - 2; int nbits = (buf[0] >> 6) + 2; int block_hdr_size = 22 * ch; int block_size = block_hdr_size + nbits * ch * 4095; int nblocks = buf_bits / block_size; int bits_left = buf_bits - nblocks * block_size; nb_samples = nblocks * 4096; if (bits_left >= block_hdr_size) nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch); break; } case CODEC_ID_ADPCM_THP: has_coded_samples = 1; if (buf_size < 8) *coded_samples = AV_RB32(&buf[4]); *coded_samples -= *coded_samples % 14; nb_samples = (buf_size - 80) / (8 * ch) * 14; break; case CODEC_ID_ADPCM_XA: nb_samples = (buf_size / 128) * 224 / ch; break; } /* validate coded sample count */ if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples)) return AVERROR_INVALIDDATA; return nb_samples; }
10,457
FFmpeg
7da9f4523159670d577a2808d4481e64008a8894
1
static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info) { //score = FF_LAMBDA_SCALE * error + lambda * bits int x; int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4; int mb_count = s->w * h / MB_AREA; mb_info *mb; int64_t score1, score2, score3; int64_t ret = s->lambda * ((v1_size ? CHUNK_HEADER_SIZE + v1_size * entry_size : 0) + (v4_size ? CHUNK_HEADER_SIZE + v4_size * entry_size : 0) + CHUNK_HEADER_SIZE) << 3; //av_log(s->avctx, AV_LOG_INFO, "sizes %3i %3i -> %9li score mb_count %i", v1_size, v4_size, ret, mb_count); switch(mode) { case MODE_V1_ONLY: //one byte per MB ret += s->lambda * 8 * mb_count; for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; ret += FF_LAMBDA_SCALE * mb->v1_error; mb->best_encoding = ENC_V1; } break; case MODE_V1_V4: //9 or 33 bits per MB for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; score1 = s->lambda * 9 + FF_LAMBDA_SCALE * mb->v1_error; score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error[v4]; if(score1 <= score2) { ret += score1; mb->best_encoding = ENC_V1; } else { ret += score2; mb->best_encoding = ENC_V4; } } break; case MODE_MC: //1, 10 or 34 bits per MB for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error; score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error; score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error[v4]; if(score1 <= score2 && score1 <= score3) { ret += score1; mb->best_encoding = ENC_SKIP; } else if(score2 <= score1 && score2 <= score3) { ret += score2; mb->best_encoding = ENC_V1; } else { ret += score3; mb->best_encoding = ENC_V4; } } break; } return ret; }
10,458
FFmpeg
d0dafebb753f34da61058adf956663de39a815b4
1
static inline int GET_TOK(TM2Context *ctx,int type) { if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) { av_log(ctx->avctx, AV_LOG_ERROR, "Read token from stream %i out of bounds (%i>=%i)\n", type, ctx->tok_ptrs[type], ctx->tok_lens[type]); return 0; } if(type <= TM2_MOT) return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]]; return ctx->tokens[type][ctx->tok_ptrs[type]++]; }
10,459
FFmpeg
df3795025337479a639cb3cd26c93a4e82ccd4db
1
int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) { RTSPState *rt = s->priv_data; AVStream *st = NULL; int reordering_queue_size = rt->reordering_queue_size; if (reordering_queue_size < 0) { if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP || !s->max_delay) reordering_queue_size = 0; else reordering_queue_size = RTP_REORDER_QUEUE_DEFAULT_SIZE; } /* open the RTP context */ if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; if (!st) s->ctx_flags |= AVFMTCTX_NOHEADER; if (CONFIG_RTSP_MUXER && s->oformat) { int ret = ff_rtp_chain_mux_open((AVFormatContext **)&rtsp_st->transport_priv, s, st, rtsp_st->rtp_handle, RTSP_TCP_MAX_PACKET_SIZE, rtsp_st->stream_index); /* Ownership of rtp_handle is passed to the rtp mux context */ rtsp_st->rtp_handle = NULL; if (ret < 0) return ret; st->time_base = ((AVFormatContext*)rtsp_st->transport_priv)->streams[0]->time_base; } else if (rt->transport == RTSP_TRANSPORT_RAW) { return 0; // Don't need to open any parser here } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT) rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, rtsp_st->dynamic_protocol_context, rtsp_st->dynamic_handler); else if (CONFIG_RTPDEC) rtsp_st->transport_priv = ff_rtp_parse_open(s, st, rtsp_st->sdp_payload_type, reordering_queue_size); if (!rtsp_st->transport_priv) { return AVERROR(ENOMEM); } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP) { RTPDemuxContext *rtpctx = rtsp_st->transport_priv; rtpctx->ssrc = rtsp_st->ssrc; if (rtsp_st->dynamic_handler) { ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, rtsp_st->dynamic_protocol_context, rtsp_st->dynamic_handler); } if (rtsp_st->crypto_suite[0]) ff_rtp_parse_set_crypto(rtsp_st->transport_priv, rtsp_st->crypto_suite, rtsp_st->crypto_params); } return 0; }
10,460
qemu
4f298a4b2957b7833bc607c951ca27c458d98d88
1
static void chassis_control(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, uint8_t *rsp, unsigned int *rsp_len, unsigned int max_rsp_len) { IPMIInterface *s = ibs->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); IPMI_CHECK_CMD_LEN(3); switch (cmd[2] & 0xf) { case 0: /* power down */ rsp[2] = k->do_hw_op(s, IPMI_POWEROFF_CHASSIS, 0); break; case 1: /* power up */ rsp[2] = k->do_hw_op(s, IPMI_POWERON_CHASSIS, 0); break; case 2: /* power cycle */ rsp[2] = k->do_hw_op(s, IPMI_POWERCYCLE_CHASSIS, 0); break; case 3: /* hard reset */ rsp[2] = k->do_hw_op(s, IPMI_RESET_CHASSIS, 0); break; case 4: /* pulse diagnostic interrupt */ rsp[2] = k->do_hw_op(s, IPMI_PULSE_DIAG_IRQ, 0); break; case 5: /* soft shutdown via ACPI by overtemp emulation */ rsp[2] = k->do_hw_op(s, IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP, 0); break; default: rsp[2] = IPMI_CC_INVALID_DATA_FIELD; return; } }
10,461
FFmpeg
7d49abdf4750d63cd9bf71235d6f064152310fff
1
static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type) { AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; AacPsyChannel *pch = &pctx->ch[channel]; int grouping = 0; int uselongblock = 1; int attacks[AAC_NUM_BLOCKS_SHORT + 1] = { 0 }; float clippings[AAC_NUM_BLOCKS_SHORT]; int i; FFPsyWindowInfo wi = { { 0 } }; if (la) { float hpfsmpl[AAC_BLOCK_SIZE_LONG]; float const *pf = hpfsmpl; float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 }; const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN); int att_sum = 0; /* LAME comment: apply high pass filter of fs/4 */ psy_hp_filter(firbuf, hpfsmpl, psy_fir_coeffs); /* Calculate the energies of each sub-shortblock */ for (i = 0; i < PSY_LAME_NUM_SUBBLOCKS; i++) { energy_subshort[i] = pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS)]; assert(pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)] > 0); attack_intensity[i] = energy_subshort[i] / pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)]; energy_short[0] += energy_subshort[i]; } for (i = 0; i < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; i++) { float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS); float p = 1.0f; for (; pf < pfe; pf++) p = FFMAX(p, fabsf(*pf)); pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p; energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p; /* NOTE: The indexes below are [i + 3 - 2] in the LAME source. * Obviously the 3 and 2 have some significance, or this would be just [i + 1] * (which is what we use here). What the 3 stands for is ambiguous, as it is both * number of short blocks, and the number of sub-short blocks. * It seems that LAME is comparing each sub-block to sub-block + 1 in the * previous block. */ if (p > energy_subshort[i + 1]) p = p / energy_subshort[i + 1]; else if (energy_subshort[i + 1] > p * 10.0f) p = energy_subshort[i + 1] / (p * 10.0f); else p = 0.0; attack_intensity[i + PSY_LAME_NUM_SUBBLOCKS] = p; } /* compare energy between sub-short blocks */ for (i = 0; i < (AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS; i++) if (!attacks[i / PSY_LAME_NUM_SUBBLOCKS]) if (attack_intensity[i] > pch->attack_threshold) attacks[i / PSY_LAME_NUM_SUBBLOCKS] = (i % PSY_LAME_NUM_SUBBLOCKS) + 1; /* should have energy change between short blocks, in order to avoid periodic signals */ /* Good samples to show the effect are Trumpet test songs */ /* GB: tuned (1) to avoid too many short blocks for test sample TRUMPET */ /* RH: tuned (2) to let enough short blocks through for test sample FSOL and SNAPS */ for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++) { float const u = energy_short[i - 1]; float const v = energy_short[i]; float const m = FFMAX(u, v); if (m < 40000) { /* (2) */ if (u < 1.7f * v && v < 1.7f * u) { /* (1) */ if (i == 1 && attacks[0] < attacks[i]) attacks[0] = 0; attacks[i] = 0; } } att_sum += attacks[i]; } if (attacks[0] <= pch->prev_attack) attacks[0] = 0; att_sum += attacks[0]; /* 3 below indicates the previous attack happened in the last sub-block of the previous sequence */ if (pch->prev_attack == 3 || att_sum) { uselongblock = 0; for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++) if (attacks[i] && attacks[i-1]) attacks[i] = 0; } } else { /* We have no lookahead info, so just use same type as the previous sequence. */ uselongblock = !(prev_type == EIGHT_SHORT_SEQUENCE); } lame_apply_block_type(pch, &wi, uselongblock); /* Calculate input sample maximums and evaluate clipping risk */ if (audio) { for (i = 0; i < AAC_NUM_BLOCKS_SHORT; i++) { const float *wbuf = audio + i * AAC_BLOCK_SIZE_SHORT; float max = 0; int j; for (j = 0; j < AAC_BLOCK_SIZE_SHORT; j++) max = FFMAX(max, fabsf(wbuf[j])); clippings[i] = max; } } else { for (i = 0; i < 8; i++) clippings[i] = 0; } wi.window_type[1] = prev_type; if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) { float clipping = 0.0f; wi.num_windows = 1; wi.grouping[0] = 1; if (wi.window_type[0] == LONG_START_SEQUENCE) wi.window_shape = 0; else wi.window_shape = 1; for (i = 0; i < 8; i++) clipping = FFMAX(clipping, clippings[i]); wi.clipping[0] = clipping; } else { int lastgrp = 0; wi.num_windows = 8; wi.window_shape = 0; for (i = 0; i < 8; i++) { if (!((pch->next_grouping >> i) & 1)) lastgrp = i; wi.grouping[lastgrp]++; } for (i = 0; i < 8; i += wi.grouping[i]) { int w; float clipping = 0.0f; for (w = 0; w < wi.grouping[i] && !clipping; w++) clipping = FFMAX(clipping, clippings[i+w]); wi.clipping[i] = clipping; } } /* Determine grouping, based on the location of the first attack, and save for * the next frame. * FIXME: Move this to analysis. * TODO: Tune groupings depending on attack location * TODO: Handle more than one attack in a group */ for (i = 0; i < 9; i++) { if (attacks[i]) { grouping = i; break; } } pch->next_grouping = window_grouping[grouping]; pch->prev_attack = attacks[8]; return wi; }
10,463
FFmpeg
0712c230ae8b15f920e877e680e0fa6e856e8006
1
static int dca_decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int lfe_samples; int num_core_channels = 0; int i; int xch_present = 0; int16_t *samples = data; DCAContext *s = avctx->priv_data; int channels; s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE); if (s->dca_buffer_size == -1) { av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); return -1; } init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); if (dca_parse_frame_header(s) < 0) { //seems like the frame is corrupt, try with the next one *data_size=0; return buf_size; } //set AVCodec values with parsed data avctx->sample_rate = s->sample_rate; avctx->bit_rate = s->bit_rate; for (i = 0; i < (s->sample_blocks / 8); i++) { dca_decode_block(s, 0, i); } /* record number of core channels incase less than max channels are requested */ num_core_channels = s->prim_channels; /* extensions start at 32-bit boundaries into bitstream */ skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); while(get_bits_left(&s->gb) >= 32) { uint32_t bits = get_bits_long(&s->gb, 32); switch(bits) { case 0x5a5a5a5a: { int ext_base_ch = s->prim_channels; int ext_amode; /* skip length-to-end-of-frame field for the moment */ skip_bits(&s->gb, 10); /* extension amode should == 1, number of channels in extension */ /* AFAIK XCh is not used for more channels */ if ((ext_amode = get_bits(&s->gb, 4)) != 1) { av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not" " supported!\n",ext_amode); continue; } /* much like core primary audio coding header */ dca_parse_audio_coding_header(s, ext_base_ch); for (i = 0; i < (s->sample_blocks / 8); i++) { dca_decode_block(s, ext_base_ch, i); } xch_present = 1; break; } case 0x1d95f262: av_log(avctx, AV_LOG_DEBUG, "Possible X96 extension found at %d bits\n", get_bits_count(&s->gb)); av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", get_bits(&s->gb, 12)+1); av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4)); break; } skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); } channels = s->prim_channels + !!s->lfe; if (s->amode<16) { avctx->channel_layout = dca_core_channel_layout[s->amode]; if (xch_present && (!avctx->request_channels || avctx->request_channels > num_core_channels)) { avctx->channel_layout |= CH_BACK_CENTER; if (s->lfe) { avctx->channel_layout |= CH_LOW_FREQUENCY; s->channel_order_tab = dca_channel_reorder_lfe_xch[s->amode]; } else { s->channel_order_tab = dca_channel_reorder_nolfe_xch[s->amode]; } } else { if (s->lfe) { avctx->channel_layout |= CH_LOW_FREQUENCY; s->channel_order_tab = dca_channel_reorder_lfe[s->amode]; } else s->channel_order_tab = dca_channel_reorder_nolfe[s->amode]; } if (s->prim_channels > 0 && s->channel_order_tab[s->prim_channels - 1] < 0) return -1; if (avctx->request_channels == 2 && s->prim_channels > 2) { channels = 2; s->output = DCA_STEREO; avctx->channel_layout = CH_LAYOUT_STEREO; } } else { av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); return -1; } /* There is nothing that prevents a dts frame to change channel configuration but FFmpeg doesn't support that so only set the channels if it is previously unset. Ideally during the first probe for channels the crc should be checked and only set avctx->channels when the crc is ok. Right now the decoder could set the channels based on a broken first frame.*/ if (!avctx->channels) avctx->channels = channels; if (*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) return -1; *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; /* filter to get final output */ for (i = 0; i < (s->sample_blocks / 8); i++) { dca_filter_channels(s, i); s->dsp.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels); samples += 256 * channels; } /* update lfe history */ lfe_samples = 2 * s->lfe * (s->sample_blocks / 8); for (i = 0; i < 2 * s->lfe * 4; i++) { s->lfe_data[i] = s->lfe_data[i + lfe_samples]; } return buf_size; }
10,464
qemu
ff71f2e8cacefae99179993204172bc65e4303df
1
static int rtl8139_can_receive(VLANClientState *nc) { RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque; int avail; /* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) return 1; if (!rtl8139_receiver_enabled(s)) return 1; if (rtl8139_cp_receiver_enabled(s)) { /* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ return 1; } else { avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize); return (avail == 0 || avail >= 1514); } }
10,465
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
unsigned int qemu_get_be16(QEMUFile *f) { unsigned int v; v = qemu_get_byte(f) << 8; v |= qemu_get_byte(f); return v; }
10,466
qemu
0b8b8753e4d94901627b3e86431230f2319215c4
1
void migration_fd_process_incoming(QEMUFile *f) { Coroutine *co = qemu_coroutine_create(process_incoming_migration_co); migrate_decompress_threads_create(); qemu_file_set_blocking(f, false); qemu_coroutine_enter(co, f); }
10,467
FFmpeg
f6774f905fb3cfdc319523ac640be30b14c1bc55
1
void ff_xvmc_decode_mb(MpegEncContext *s) { XvMCMacroBlock *mv_block; struct xvmc_pix_fmt *render; int i, cbp, blocks_per_mb; const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; if (s->encoding) { av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n"); return; } // from MPV_decode_mb(), update DC predictors for P macroblocks if (!s->mb_intra) { s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision; } // MC doesn't skip blocks s->mb_skipped = 0; // Do I need to export quant when I could not perform postprocessing? // Anyway, it doesn't hurt. s->current_picture.qscale_table[mb_xy] = s->qscale; // start of XVMC-specific code render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; assert(render); assert(render->xvmc_id == AV_XVMC_ID); assert(render->mv_blocks); // take the next free macroblock mv_block = &render->mv_blocks[render->start_mv_blocks_num + render->filled_mv_blocks_num]; mv_block->x = s->mb_x; mv_block->y = s->mb_y; mv_block->dct_type = s->interlaced_dct; // XVMC_DCT_TYPE_FRAME/FIELD; if (s->mb_intra) { mv_block->macroblock_type = XVMC_MB_TYPE_INTRA; // no MC, all done } else { mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN; if (s->mv_dir & MV_DIR_FORWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_FORWARD; // PMV[n][dir][xy] = mv[dir][n][xy] mv_block->PMV[0][0][0] = s->mv[0][0][0]; mv_block->PMV[0][0][1] = s->mv[0][0][1]; mv_block->PMV[1][0][0] = s->mv[0][1][0]; mv_block->PMV[1][0][1] = s->mv[0][1][1]; } if (s->mv_dir & MV_DIR_BACKWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_BACKWARD; mv_block->PMV[0][1][0] = s->mv[1][0][0]; mv_block->PMV[0][1][1] = s->mv[1][0][1]; mv_block->PMV[1][1][0] = s->mv[1][1][0]; mv_block->PMV[1][1][1] = s->mv[1][1][1]; } switch(s->mv_type) { case MV_TYPE_16X16: mv_block->motion_type = XVMC_PREDICTION_FRAME; break; case MV_TYPE_16X8: mv_block->motion_type = XVMC_PREDICTION_16x8; break; case MV_TYPE_FIELD: mv_block->motion_type = XVMC_PREDICTION_FIELD; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][1] <<= 1; mv_block->PMV[1][0][1] <<= 1; mv_block->PMV[0][1][1] <<= 1; mv_block->PMV[1][1][1] <<= 1; } break; case MV_TYPE_DMV: mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][0] = s->mv[0][0][0]; // top from top mv_block->PMV[0][0][1] = s->mv[0][0][1] << 1; mv_block->PMV[0][1][0] = s->mv[0][0][0]; // bottom from bottom mv_block->PMV[0][1][1] = s->mv[0][0][1] << 1; mv_block->PMV[1][0][0] = s->mv[0][2][0]; // dmv00, top from bottom mv_block->PMV[1][0][1] = s->mv[0][2][1] << 1; // dmv01 mv_block->PMV[1][1][0] = s->mv[0][3][0]; // dmv10, bottom from top mv_block->PMV[1][1][1] = s->mv[0][3][1] << 1; // dmv11 } else { mv_block->PMV[0][1][0] = s->mv[0][2][0]; // dmv00 mv_block->PMV[0][1][1] = s->mv[0][2][1]; // dmv01 } break; default: assert(0); } mv_block->motion_vertical_field_select = 0; // set correct field references if (s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8) { mv_block->motion_vertical_field_select |= s->field_select[0][0]; mv_block->motion_vertical_field_select |= s->field_select[1][0] << 1; mv_block->motion_vertical_field_select |= s->field_select[0][1] << 2; mv_block->motion_vertical_field_select |= s->field_select[1][1] << 3; } } // !intra // time to handle data blocks mv_block->index = render->next_free_data_block_num; blocks_per_mb = 6; if (s->chroma_format >= 2) { blocks_per_mb = 4 + (1 << s->chroma_format); } // calculate cbp cbp = 0; for (i = 0; i < blocks_per_mb; i++) { cbp += cbp; if (s->block_last_index[i] >= 0) cbp++; } if (s->flags & CODEC_FLAG_GRAY) { if (s->mb_intra) { // intra frames are always full chroma blocks for (i = 4; i < blocks_per_mb; i++) { memset(s->pblocks[i], 0, sizeof(*s->pblocks[i])); // so we need to clear them if (!render->unsigned_intra) *s->pblocks[i][0] = 1 << 10; } } else { cbp &= 0xf << (blocks_per_mb - 4); blocks_per_mb = 4; // luminance blocks only } } mv_block->coded_block_pattern = cbp; if (cbp == 0) mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN; for (i = 0; i < blocks_per_mb; i++) { if (s->block_last_index[i] >= 0) { // I do not have unsigned_intra MOCO to test, hope it is OK. if (s->mb_intra && (render->idct || !render->unsigned_intra)) *s->pblocks[i][0] -= 1 << 10; if (!render->idct) { s->dsp.idct(*s->pblocks[i]); /* It is unclear if MC hardware requires pixel diff values to be * in the range [-255;255]. TODO: Clipping if such hardware is * ever found. As of now it would only be an unnecessary * slowdown. */ } // copy blocks only if the codec doesn't support pblocks reordering if (s->avctx->xvmc_acceleration == 1) { memcpy(&render->data_blocks[render->next_free_data_block_num*64], s->pblocks[i], sizeof(*s->pblocks[i])); } render->next_free_data_block_num++; } } render->filled_mv_blocks_num++; assert(render->filled_mv_blocks_num <= render->allocated_mv_blocks); assert(render->next_free_data_block_num <= render->allocated_data_blocks); /* The above conditions should not be able to fail as long as this function * is used and the following 'if ()' automatically calls a callback to free * blocks. */ if (render->filled_mv_blocks_num == render->allocated_mv_blocks) ff_mpeg_draw_horiz_band(s, 0, 0); }
10,468
FFmpeg
7667afffb8dd54595ef2a959c385babd4c9c94cf
0
static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable = s->intra_scantable.permutated; const int qscale = s->qscale; OPEN_READER(re, &s->gb); i = -1; // special case for first coefficient, no need to add second VLC table UPDATE_CACHE(re, &s->gb); if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { level = (3 * qscale) >> 1; if (GET_CACHE(re, &s->gb) & 0x40000000) level = -level; block[0] = level; i++; SKIP_BITS(re, &s->gb, 2); if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) goto end; } /* now quantify & encode AC coefficients */ for (;;) { GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); if (level != 0) { i += run; check_scantable_index(s, i); j = scantable[i]; level = ((level * 2 + 1) * qscale) >> 1; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); UPDATE_CACHE(re, &s->gb); level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); i += run; check_scantable_index(s, i); j = scantable[i]; if (level < 0) { level = ((-level * 2 + 1) * qscale) >> 1; level = -level; } else { level = ((level * 2 + 1) * qscale) >> 1; } } block[j] = level; if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) break; UPDATE_CACHE(re, &s->gb); } end: LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); s->block_last_index[n] = i; return 0; }
10,469
FFmpeg
b12e4d3bb8df994f042ff1216fb8de2b967aab9e
0
int ffio_close_null_buf(AVIOContext *s) { DynBuffer *d = s->opaque; int size; avio_flush(s); size = d->size; av_free(d); av_free(s); return size; }
10,472
FFmpeg
e0c6cce44729d94e2a5507a4b6d031f23e8bd7b6
0
static int initFilter(int16_t **outFilter, int32_t **filterPos, int *outFilterSize, int xInc, int srcW, int dstW, int filterAlign, int one, int flags, int cpu_flags, SwsVector *srcFilter, SwsVector *dstFilter, double param[2], int is_horizontal) { int i; int filterSize; int filter2Size; int minFilterSize; int64_t *filter = NULL; int64_t *filter2 = NULL; const int64_t fone = 1LL << 54; int ret = -1; emms_c(); // FIXME should not be required but IS (even for non-MMX versions) // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail); if (FFABS(xInc - 0x10000) < 10) { // unscaled int i; filterSize = 1; FF_ALLOCZ_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); for (i = 0; i < dstW; i++) { filter[i * filterSize] = fone; (*filterPos)[i] = i; } } else if (flags & SWS_POINT) { // lame looking point sampling mode int i; int xDstInSrc; filterSize = 1; FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = xInc / 2 - 0x8000; for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16; (*filterPos)[i] = xx; filter[i] = fone; xDstInSrc += xInc; } } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) || (flags & SWS_FAST_BILINEAR)) { // bilinear upscale int i; int xDstInSrc; filterSize = 2; FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = xInc / 2 - 0x8000; for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16; int j; (*filterPos)[i] = xx; // bilinear upscale / linear interpolate / area averaging for (j = 0; j < filterSize; j++) { int64_t coeff = fone - FFABS((xx << 16) - xDstInSrc) * (fone >> 16); if (coeff < 0) coeff = 0; filter[i * filterSize + j] = coeff; xx++; } xDstInSrc += xInc; } } else { int64_t xDstInSrc; int sizeFactor; if (flags & SWS_BICUBIC) sizeFactor = 4; else if (flags & SWS_X) sizeFactor = 8; else if (flags & SWS_AREA) sizeFactor = 1; // downscale only, for upscale it is bilinear else if (flags & SWS_GAUSS) sizeFactor = 8; // infinite ;) else if (flags & SWS_LANCZOS) sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6; else if (flags & SWS_SINC) sizeFactor = 20; // infinite ;) else if (flags & SWS_SPLINE) sizeFactor = 20; // infinite ;) else if (flags & SWS_BILINEAR) sizeFactor = 2; else { sizeFactor = 0; // GCC warning killer assert(0); } if (xInc <= 1 << 16) filterSize = 1 + sizeFactor; // upscale else filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW; filterSize = FFMIN(filterSize, srcW - 2); filterSize = FFMAX(filterSize, 1); FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = xInc - 0x10000; for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17); int j; (*filterPos)[i] = xx; for (j = 0; j < filterSize; j++) { int64_t d = (FFABS(((int64_t)xx << 17) - xDstInSrc)) << 13; double floatd; int64_t coeff; if (xInc > 1 << 16) d = d * dstW / srcW; floatd = d * (1.0 / (1 << 30)); if (flags & SWS_BICUBIC) { int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24); int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24); if (d >= 1LL << 31) { coeff = 0.0; } else { int64_t dd = (d * d) >> 30; int64_t ddd = (dd * d) >> 30; if (d < 1LL << 30) coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd + (-18 * (1 << 24) + 12 * B + 6 * C) * dd + (6 * (1 << 24) - 2 * B) * (1 << 30); else coeff = (-B - 6 * C) * ddd + (6 * B + 30 * C) * dd + (-12 * B - 48 * C) * d + (8 * B + 24 * C) * (1 << 30); } coeff *= fone >> (30 + 24); } #if 0 else if (flags & SWS_X) { double p = param ? param * 0.01 : 0.3; coeff = d ? sin(d * M_PI) / (d * M_PI) : 1.0; coeff *= pow(2.0, -p * d * d); } #endif else if (flags & SWS_X) { double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; double c; if (floatd < 1.0) c = cos(floatd * M_PI); else c = -1.0; if (c < 0.0) c = -pow(-c, A); else c = pow(c, A); coeff = (c * 0.5 + 0.5) * fone; } else if (flags & SWS_AREA) { int64_t d2 = d - (1 << 29); if (d2 * xInc < -(1LL << (29 + 16))) coeff = 1.0 * (1LL << (30 + 16)); else if (d2 * xInc < (1LL << (29 + 16))) coeff = -d2 * xInc + (1LL << (29 + 16)); else coeff = 0.0; coeff *= fone >> (30 + 16); } else if (flags & SWS_GAUSS) { double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (pow(2.0, -p * floatd * floatd)) * fone; } else if (flags & SWS_SINC) { coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone; } else if (flags & SWS_LANCZOS) { double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) / (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone; if (floatd > p) coeff = 0; } else if (flags & SWS_BILINEAR) { coeff = (1 << 30) - d; if (coeff < 0) coeff = 0; coeff *= fone >> 30; } else if (flags & SWS_SPLINE) { double p = -2.196152422706632; coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone; } else { coeff = 0.0; // GCC warning killer assert(0); } filter[i * filterSize + j] = coeff; xx++; } xDstInSrc += 2 * xInc; } } /* apply src & dst Filter to filter -> filter2 * av_free(filter); */ assert(filterSize > 0); filter2Size = filterSize; if (srcFilter) filter2Size += srcFilter->length - 1; if (dstFilter) filter2Size += dstFilter->length - 1; assert(filter2Size > 0); FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size * dstW * sizeof(*filter2), fail); for (i = 0; i < dstW; i++) { int j, k; if (srcFilter) { for (k = 0; k < srcFilter->length; k++) { for (j = 0; j < filterSize; j++) filter2[i * filter2Size + k + j] += srcFilter->coeff[k] * filter[i * filterSize + j]; } } else { for (j = 0; j < filterSize; j++) filter2[i * filter2Size + j] = filter[i * filterSize + j]; } // FIXME dstFilter (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2; } av_freep(&filter); /* try to reduce the filter-size (step1 find size and shift left) */ // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not). minFilterSize = 0; for (i = dstW - 1; i >= 0; i--) { int min = filter2Size; int j; int64_t cutOff = 0.0; /* get rid of near zero elements on the left by shifting left */ for (j = 0; j < filter2Size; j++) { int k; cutOff += FFABS(filter2[i * filter2Size]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone) break; /* preserve monotonicity because the core can't handle the * filter otherwise */ if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1]) break; // move filter coefficients left for (k = 1; k < filter2Size; k++) filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k]; filter2[i * filter2Size + k - 1] = 0; (*filterPos)[i]++; } cutOff = 0; /* count near zeros on the right */ for (j = filter2Size - 1; j > 0; j--) { cutOff += FFABS(filter2[i * filter2Size + j]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone) break; min--; } if (min > minFilterSize) minFilterSize = min; } if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) { // we can handle the special case 4, so we don't want to go the full 8 if (minFilterSize < 5) filterAlign = 4; /* We really don't want to waste our time doing useless computation, so * fall back on the scalar C code for very small filters. * Vectorizing is worth it only if you have a decent-sized vector. */ if (minFilterSize < 3) filterAlign = 1; } if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { // special case for unscaled vertical filtering if (minFilterSize == 1 && filterAlign == 2) filterAlign = 1; } assert(minFilterSize > 0); filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1)); assert(filterSize > 0); filter = av_malloc(filterSize * dstW * sizeof(*filter)); if (filterSize >= MAX_FILTER_SIZE * 16 / ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) goto fail; *outFilterSize = filterSize; if (flags & SWS_PRINT_INFO) av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); /* try to reduce the filter-size (step2 reduce it) */ for (i = 0; i < dstW; i++) { int j; for (j = 0; j < filterSize; j++) { if (j >= filter2Size) filter[i * filterSize + j] = 0; else filter[i * filterSize + j] = filter2[i * filter2Size + j]; if ((flags & SWS_BITEXACT) && j >= minFilterSize) filter[i * filterSize + j] = 0; } } // FIXME try to align filterPos if possible // fix borders if (is_horizontal) { for (i = 0; i < dstW; i++) { int j; if ((*filterPos)[i] < 0) { // move filter coefficients left to compensate for filterPos for (j = 1; j < filterSize; j++) { int left = FFMAX(j + (*filterPos)[i], 0); filter[i * filterSize + left] += filter[i * filterSize + j]; filter[i * filterSize + j] = 0; } (*filterPos)[i] = 0; } if ((*filterPos)[i] + filterSize > srcW) { int shift = (*filterPos)[i] + filterSize - srcW; // move filter coefficients right to compensate for filterPos for (j = filterSize - 2; j >= 0; j--) { int right = FFMIN(j + shift, filterSize - 1); filter[i * filterSize + right] += filter[i * filterSize + j]; filter[i * filterSize + j] = 0; } (*filterPos)[i] = srcW - filterSize; } } } // Note the +1 is for the MMX scaler which reads over the end /* align at 16 for AltiVec (needed by hScale_altivec_real) */ FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize * (dstW + 3) * sizeof(int16_t), fail); /* normalize & store in outFilter */ for (i = 0; i < dstW; i++) { int j; int64_t error = 0; int64_t sum = 0; for (j = 0; j < filterSize; j++) { sum += filter[i * filterSize + j]; } sum = (sum + one / 2) / one; for (j = 0; j < *outFilterSize; j++) { int64_t v = filter[i * filterSize + j] + error; int intV = ROUNDED_DIV(v, sum); (*outFilter)[i * (*outFilterSize) + j] = intV; error = v - intV * sum; } } (*filterPos)[dstW + 0] = (*filterPos)[dstW + 1] = (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will * read over the end */ for (i = 0; i < *outFilterSize; i++) { int k = (dstW - 1) * (*outFilterSize) + i; (*outFilter)[k + 1 * (*outFilterSize)] = (*outFilter)[k + 2 * (*outFilterSize)] = (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k]; } ret = 0; fail: av_free(filter); av_free(filter2); return ret; }
10,473
FFmpeg
623d217ed1ba168355b1887ef9ca02402b40eead
0
static void stereo_processing(PSContext *ps, INTFLOAT (*l)[32][2], INTFLOAT (*r)[32][2], int is34) { int e, b, k; INTFLOAT (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11; INTFLOAT (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12; INTFLOAT (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21; INTFLOAT (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22; int8_t *opd_hist = ps->opd_hist; int8_t *ipd_hist = ps->ipd_hist; int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf; int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf; int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf; int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf; const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; TABLE_CONST INTFLOAT (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; //Remapping if (ps->num_env_old) { memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0])); memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0])); memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0])); memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0])); memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0])); memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0])); memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0])); memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0])); } if (is34) { remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (!ps->is34bands_old) { map_val_20_to_34(H11[0][0]); map_val_20_to_34(H11[1][0]); map_val_20_to_34(H12[0][0]); map_val_20_to_34(H12[1][0]); map_val_20_to_34(H21[0][0]); map_val_20_to_34(H21[1][0]); map_val_20_to_34(H22[0][0]); map_val_20_to_34(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } else { remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (ps->is34bands_old) { map_val_34_to_20(H11[0][0]); map_val_34_to_20(H11[1][0]); map_val_34_to_20(H12[0][0]); map_val_34_to_20(H12[1][0]); map_val_34_to_20(H21[0][0]); map_val_34_to_20(H21[1][0]); map_val_34_to_20(H22[0][0]); map_val_34_to_20(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } //Mixing for (e = 0; e < ps->num_env; e++) { for (b = 0; b < NR_PAR_BANDS[is34]; b++) { INTFLOAT h11, h12, h21, h22; h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0]; h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1]; h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2]; h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3]; if (!PS_BASELINE && ps->enable_ipdopd && b < NR_IPDOPD_BANDS[is34]) { //The spec say says to only run this smoother when enable_ipdopd //is set but the reference decoder appears to run it constantly INTFLOAT h11i, h12i, h21i, h22i; INTFLOAT ipd_adj_re, ipd_adj_im; int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b]; int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b]; INTFLOAT opd_re = pd_re_smooth[opd_idx]; INTFLOAT opd_im = pd_im_smooth[opd_idx]; INTFLOAT ipd_re = pd_re_smooth[ipd_idx]; INTFLOAT ipd_im = pd_im_smooth[ipd_idx]; opd_hist[b] = opd_idx & 0x3F; ipd_hist[b] = ipd_idx & 0x3F; ipd_adj_re = AAC_MADD30(opd_re, ipd_re, opd_im, ipd_im); ipd_adj_im = AAC_MSUB30(opd_im, ipd_re, opd_re, ipd_im); h11i = AAC_MUL30(h11, opd_im); h11 = AAC_MUL30(h11, opd_re); h12i = AAC_MUL30(h12, ipd_adj_im); h12 = AAC_MUL30(h12, ipd_adj_re); h21i = AAC_MUL30(h21, opd_im); h21 = AAC_MUL30(h21, opd_re); h22i = AAC_MUL30(h22, ipd_adj_im); h22 = AAC_MUL30(h22, ipd_adj_re); H11[1][e+1][b] = h11i; H12[1][e+1][b] = h12i; H21[1][e+1][b] = h21i; H22[1][e+1][b] = h22i; } H11[0][e+1][b] = h11; H12[0][e+1][b] = h12; H21[0][e+1][b] = h21; H22[0][e+1][b] = h22; } for (k = 0; k < NR_BANDS[is34]; k++) { LOCAL_ALIGNED_16(INTFLOAT, h, [2], [4]); LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]); int start = ps->border_position[e]; int stop = ps->border_position[e+1]; INTFLOAT width = Q30(1.f) / ((stop - start) ? (stop - start) : 1); #if USE_FIXED width = FFMIN(2U*width, INT_MAX); #endif b = k_to_i[k]; h[0][0] = H11[0][e][b]; h[0][1] = H12[0][e][b]; h[0][2] = H21[0][e][b]; h[0][3] = H22[0][e][b]; if (!PS_BASELINE && ps->enable_ipdopd) { //Is this necessary? ps_04_new seems unchanged if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) { h[1][0] = -H11[1][e][b]; h[1][1] = -H12[1][e][b]; h[1][2] = -H21[1][e][b]; h[1][3] = -H22[1][e][b]; } else { h[1][0] = H11[1][e][b]; h[1][1] = H12[1][e][b]; h[1][2] = H21[1][e][b]; h[1][3] = H22[1][e][b]; } } //Interpolation h_step[0][0] = AAC_MSUB31_V3(H11[0][e+1][b], h[0][0], width); h_step[0][1] = AAC_MSUB31_V3(H12[0][e+1][b], h[0][1], width); h_step[0][2] = AAC_MSUB31_V3(H21[0][e+1][b], h[0][2], width); h_step[0][3] = AAC_MSUB31_V3(H22[0][e+1][b], h[0][3], width); if (!PS_BASELINE && ps->enable_ipdopd) { h_step[1][0] = AAC_MSUB31_V3(H11[1][e+1][b], h[1][0], width); h_step[1][1] = AAC_MSUB31_V3(H12[1][e+1][b], h[1][1], width); h_step[1][2] = AAC_MSUB31_V3(H21[1][e+1][b], h[1][2], width); h_step[1][3] = AAC_MSUB31_V3(H22[1][e+1][b], h[1][3], width); } ps->dsp.stereo_interpolate[!PS_BASELINE && ps->enable_ipdopd]( l[k] + 1 + start, r[k] + 1 + start, h, h_step, stop - start); } } }
10,474
qemu
a5b8dd2ce83208cd7d6eb4562339ecf5aae13574
0
int coroutine_fn bdrv_co_preadv(BlockDriverState *bs, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { BlockDriver *drv = bs->drv; BdrvTrackedRequest req; uint64_t align = bs->request_alignment; uint8_t *head_buf = NULL; uint8_t *tail_buf = NULL; QEMUIOVector local_qiov; bool use_local_qiov = false; int ret; if (!drv) { return -ENOMEDIUM; } ret = bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { return ret; } /* Don't do copy-on-read if we read data before write operation */ if (bs->copy_on_read && !(flags & BDRV_REQ_NO_SERIALISING)) { flags |= BDRV_REQ_COPY_ON_READ; } /* Align read if necessary by padding qiov */ if (offset & (align - 1)) { head_buf = qemu_blockalign(bs, align); qemu_iovec_init(&local_qiov, qiov->niov + 2); qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1)); qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size); use_local_qiov = true; bytes += offset & (align - 1); offset = offset & ~(align - 1); } if ((offset + bytes) & (align - 1)) { if (!use_local_qiov) { qemu_iovec_init(&local_qiov, qiov->niov + 1); qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size); use_local_qiov = true; } tail_buf = qemu_blockalign(bs, align); qemu_iovec_add(&local_qiov, tail_buf, align - ((offset + bytes) & (align - 1))); bytes = ROUND_UP(bytes, align); } tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_READ); ret = bdrv_aligned_preadv(bs, &req, offset, bytes, align, use_local_qiov ? &local_qiov : qiov, flags); tracked_request_end(&req); if (use_local_qiov) { qemu_iovec_destroy(&local_qiov); qemu_vfree(head_buf); qemu_vfree(tail_buf); } return ret; }
10,475
qemu
46746dbaa8c2c421b9bda78193caad57d7fb1136
0
static void vfio_add_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage *msg, bool msix) { int virq; if ((msix && !VFIO_ALLOW_KVM_MSIX) || (!msix && !VFIO_ALLOW_KVM_MSI) || !msg) { return; } if (event_notifier_init(&vector->kvm_interrupt, 0)) { return; } virq = kvm_irqchip_add_msi_route(kvm_state, *msg); if (virq < 0) { event_notifier_cleanup(&vector->kvm_interrupt); return; } if (kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, &vector->kvm_interrupt, NULL, virq) < 0) { kvm_irqchip_release_virq(kvm_state, virq); event_notifier_cleanup(&vector->kvm_interrupt); return; } vector->virq = virq; }
10,476
qemu
4678124bb9bfb49e93b83f95c4d2feeb443ea38b
0
void bios_linker_loader_add_pointer(BIOSLinker *linker, const char *dest_file, const char *src_file, void *pointer, uint8_t pointer_size) { BiosLinkerLoaderEntry entry; const BiosLinkerFileEntry *file = bios_linker_find_file(linker, dest_file); ptrdiff_t offset = (gchar *)pointer - file->blob->data; assert(offset >= 0); assert(offset + pointer_size <= file->blob->len); memset(&entry, 0, sizeof entry); strncpy(entry.pointer.dest_file, dest_file, sizeof entry.pointer.dest_file - 1); strncpy(entry.pointer.src_file, src_file, sizeof entry.pointer.src_file - 1); entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER); entry.pointer.offset = cpu_to_le32(offset); entry.pointer.size = pointer_size; assert(pointer_size == 1 || pointer_size == 2 || pointer_size == 4 || pointer_size == 8); g_array_append_vals(linker->cmd_blob, &entry, sizeof entry); }
10,477
FFmpeg
13a099799e89a76eb921ca452e1b04a7a28a9855
0
yuv2yuvX_altivec_real(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) { const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; register int i, j; { DECLARE_ALIGNED(16, int, val)[dstW]; for (i = 0; i < (dstW -7); i+=4) { vec_st(vini, i << 2, val); } for (; i < dstW; i++) { val[i] = (1 << 18); } for (j = 0; j < lumFilterSize; j++) { vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter perm = vec_lvsl(0, lumSrc[j]); l1 = vec_ld(0, lumSrc[j]); for (i = 0; i < (dstW - 7); i+=8) { int offset = i << 2; vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); vector signed int v1 = vec_ld(offset, val); vector signed int v2 = vec_ld(offset + 16, val); vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] vector signed int i1 = vec_mule(vLumFilter, ls); vector signed int i2 = vec_mulo(vLumFilter, ls); vector signed int vf1 = vec_mergeh(i1, i2); vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] vector signed int vo1 = vec_add(v1, vf1); vector signed int vo2 = vec_add(v2, vf2); vec_st(vo1, offset, val); vec_st(vo2, offset + 16, val); l1 = l2; } for ( ; i < dstW; i++) { val[i] += lumSrc[j][i] * lumFilter[j]; } } altivec_packIntArrayToCharArray(val, dest, dstW); } if (uDest != 0) { DECLARE_ALIGNED(16, int, u)[chrDstW]; DECLARE_ALIGNED(16, int, v)[chrDstW]; for (i = 0; i < (chrDstW -7); i+=4) { vec_st(vini, i << 2, u); vec_st(vini, i << 2, v); } for (; i < chrDstW; i++) { u[i] = (1 << 18); v[i] = (1 << 18); } for (j = 0; j < chrFilterSize; j++) { vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter perm = vec_lvsl(0, chrUSrc[j]); l1 = vec_ld(0, chrUSrc[j]); l1_V = vec_ld(0, chrVSrc[j]); for (i = 0; i < (chrDstW - 7); i+=8) { int offset = i << 2; vector signed short l2 = vec_ld((i << 1) + 16, chrUSrc[j]); vector signed short l2_V = vec_ld((i << 1) + 16, chrVSrc[j]); vector signed int v1 = vec_ld(offset, u); vector signed int v2 = vec_ld(offset + 16, u); vector signed int v1_V = vec_ld(offset, v); vector signed int v2_V = vec_ld(offset + 16, v); vector signed short ls = vec_perm(l1, l2, perm); // chrUSrc[j][i] ... chrUSrc[j][i+7] vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrVSrc[j][i] ... chrVSrc[j][i] vector signed int i1 = vec_mule(vChrFilter, ls); vector signed int i2 = vec_mulo(vChrFilter, ls); vector signed int i1_V = vec_mule(vChrFilter, ls_V); vector signed int i2_V = vec_mulo(vChrFilter, ls_V); vector signed int vf1 = vec_mergeh(i1, i2); vector signed int vf2 = vec_mergel(i1, i2); // chrUSrc[j][i] * chrFilter[j] ... chrUSrc[j][i+7] * chrFilter[j] vector signed int vf1_V = vec_mergeh(i1_V, i2_V); vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrVSrc[j][i] * chrFilter[j] ... chrVSrc[j][i+7] * chrFilter[j] vector signed int vo1 = vec_add(v1, vf1); vector signed int vo2 = vec_add(v2, vf2); vector signed int vo1_V = vec_add(v1_V, vf1_V); vector signed int vo2_V = vec_add(v2_V, vf2_V); vec_st(vo1, offset, u); vec_st(vo2, offset + 16, u); vec_st(vo1_V, offset, v); vec_st(vo2_V, offset + 16, v); l1 = l2; l1_V = l2_V; } for ( ; i < chrDstW; i++) { u[i] += chrUSrc[j][i] * chrFilter[j]; v[i] += chrVSrc[j][i] * chrFilter[j]; } } altivec_packIntArrayToCharArray(u, uDest, chrDstW); altivec_packIntArrayToCharArray(v, vDest, chrDstW); } }
10,479
qemu
1ea879e5580f63414693655fcf0328559cdce138
0
static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as) { int bits16, mode, channel; FMODVoiceOut *fmd = (FMODVoiceOut *) hw; audsettings_t obt_as = *as; mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0); fmd->fmod_sample = FSOUND_Sample_Alloc ( FSOUND_FREE, /* index */ conf.nb_samples, /* length */ mode, /* mode */ as->freq, /* freq */ 255, /* volume */ 128, /* pan */ 255 /* priority */ ); if (!fmd->fmod_sample) { fmod_logerr2 ("DAC", "Failed to allocate FMOD sample\n"); return -1; } channel = FSOUND_PlaySoundEx (FSOUND_FREE, fmd->fmod_sample, 0, 1); if (channel < 0) { fmod_logerr2 ("DAC", "Failed to start playing sound\n"); FSOUND_Sample_Free (fmd->fmod_sample); return -1; } fmd->channel = channel; /* FMOD always operates on little endian frames? */ obt_as.endianness = 0; audio_pcm_init_info (&hw->info, &obt_as); bits16 = (mode & FSOUND_16BITS) != 0; hw->samples = conf.nb_samples; return 0; }
10,481
qemu
f1f57066573e832438cd87600310589fa9cee202
0
void blk_dev_change_media_cb(BlockBackend *blk, bool load) { if (blk->dev_ops && blk->dev_ops->change_media_cb) { bool tray_was_closed = !blk_dev_is_tray_open(blk); blk->dev_ops->change_media_cb(blk->dev_opaque, load); if (tray_was_closed) { /* tray open */ qapi_event_send_device_tray_moved(blk_name(blk), true, &error_abort); } if (load) { /* tray close */ qapi_event_send_device_tray_moved(blk_name(blk), false, &error_abort); } } }
10,482
qemu
904d6f588063fb5ad2b61998acdf1e73fb465067
0
static void chr_read(void *opaque, const void *buf, size_t size) { VirtIORNG *vrng = opaque; size_t len; int offset; if (!is_guest_ready(vrng)) { return; } offset = 0; while (offset < size) { if (!pop_an_elem(vrng)) { break; } len = iov_from_buf(vrng->elem.in_sg, vrng->elem.in_num, 0, buf + offset, size - offset); offset += len; virtqueue_push(vrng->vq, &vrng->elem, len); vrng->popped = false; } virtio_notify(&vrng->vdev, vrng->vq); /* * Lastly, if we had multiple elems queued by the guest, and we * didn't have enough data to fill them all, indicate we want more * data. */ len = pop_an_elem(vrng); if (len) { rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); } }
10,483
qemu
0284b03ba3f47da53b6b46293a3d586c08829f7e
0
void cpu_loop(CPUX86State *env) { CPUState *cs = CPU(x86_env_get_cpu(env)); int trapnr; abi_ulong pc; target_siginfo_t info; for(;;) { cpu_exec_start(cs); trapnr = cpu_x86_exec(cs); cpu_exec_end(cs); switch(trapnr) { case 0x80: /* linux syscall from int $0x80 */ env->regs[R_EAX] = do_syscall(env, env->regs[R_EAX], env->regs[R_EBX], env->regs[R_ECX], env->regs[R_EDX], env->regs[R_ESI], env->regs[R_EDI], env->regs[R_EBP], 0, 0); break; #ifndef TARGET_ABI32 case EXCP_SYSCALL: /* linux syscall from syscall instruction */ env->regs[R_EAX] = do_syscall(env, env->regs[R_EAX], env->regs[R_EDI], env->regs[R_ESI], env->regs[R_EDX], env->regs[10], env->regs[8], env->regs[9], 0, 0); break; #endif case EXCP0B_NOSEG: case EXCP0C_STACK: info.si_signo = TARGET_SIGBUS; info.si_errno = 0; info.si_code = TARGET_SI_KERNEL; info._sifields._sigfault._addr = 0; queue_signal(env, info.si_signo, &info); break; case EXCP0D_GPF: /* XXX: potential problem if ABI32 */ #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_fault(env); } else #endif { info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; info.si_code = TARGET_SI_KERNEL; info._sifields._sigfault._addr = 0; queue_signal(env, info.si_signo, &info); } break; case EXCP0E_PAGE: info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; if (!(env->error_code & 1)) info.si_code = TARGET_SEGV_MAPERR; else info.si_code = TARGET_SEGV_ACCERR; info._sifields._sigfault._addr = env->cr[2]; queue_signal(env, info.si_signo, &info); break; case EXCP00_DIVZ: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); } else #endif { /* division by zero */ info.si_signo = TARGET_SIGFPE; info.si_errno = 0; info.si_code = TARGET_FPE_INTDIV; info._sifields._sigfault._addr = env->eip; queue_signal(env, info.si_signo, &info); } break; case EXCP01_DB: case EXCP03_INT3: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); } else #endif { info.si_signo = TARGET_SIGTRAP; info.si_errno = 0; if (trapnr == EXCP01_DB) { info.si_code = TARGET_TRAP_BRKPT; info._sifields._sigfault._addr = env->eip; } else { info.si_code = TARGET_SI_KERNEL; info._sifields._sigfault._addr = 0; } queue_signal(env, info.si_signo, &info); } break; case EXCP04_INTO: case EXCP05_BOUND: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); } else #endif { info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; info.si_code = TARGET_SI_KERNEL; info._sifields._sigfault._addr = 0; queue_signal(env, info.si_signo, &info); } break; case EXCP06_ILLOP: info.si_signo = TARGET_SIGILL; info.si_errno = 0; info.si_code = TARGET_ILL_ILLOPN; info._sifields._sigfault._addr = env->eip; queue_signal(env, info.si_signo, &info); break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; case EXCP_DEBUG: { int sig; sig = gdb_handlesig(cs, TARGET_SIGTRAP); if (sig) { info.si_signo = sig; info.si_errno = 0; info.si_code = TARGET_TRAP_BRKPT; queue_signal(env, info.si_signo, &info); } } break; default: pc = env->segs[R_CS].base + env->eip; EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n", (long)pc, trapnr); abort(); } process_pending_signals(env); } }
10,484
qemu
4a1418e07bdcfaa3177739e04707ecaec75d89e1
0
void kqemu_flush(CPUState *env, int global) { LOG_INT("kqemu_flush:\n"); nb_pages_to_flush = KQEMU_FLUSH_ALL; }
10,486
qemu
27a69bb088bee6d4efea254659422fb9c751b3c7
0
static inline void gen_evmergelohi(DisasContext *ctx) { if (unlikely(!ctx->spe_enabled)) { gen_exception(ctx, POWERPC_EXCP_APU); return; } #if defined(TARGET_PPC64) TCGv t0 = tcg_temp_new(); TCGv t1 = tcg_temp_new(); tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); tcg_temp_free(t0); tcg_temp_free(t1); #else if (rD(ctx->opcode) == rA(ctx->opcode)) { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp); tcg_temp_free_i32(tmp); } else { tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); } #endif }
10,487
qemu
342368aff7d61a32b5853068b92039a2b15507c5
0
gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, bool search_pc) { CPUState *cs = CPU(cpu); CPUMIPSState *env = &cpu->env; DisasContext ctx; target_ulong pc_start; uint16_t *gen_opc_end; CPUBreakpoint *bp; int j, lj = -1; int num_insns; int max_insns; int insn_bytes; int is_slot; if (search_pc) qemu_log("search pc %d\n", search_pc); pc_start = tb->pc; gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; ctx.pc = pc_start; ctx.saved_pc = -1; ctx.singlestep_enabled = cs->singlestep_enabled; ctx.insn_flags = env->insn_flags; ctx.CP0_Config1 = env->CP0_Config1; ctx.tb = tb; ctx.bstate = BS_NONE; ctx.kscrexist = (env->CP0_Config4 >> CP0C4_KScrExist) & 0xff; ctx.rxi = (env->CP0_Config3 >> CP0C3_RXI) & 1; ctx.ie = (env->CP0_Config4 >> CP0C4_IE) & 3; ctx.bi = (env->CP0_Config3 >> CP0C3_BI) & 1; ctx.bp = (env->CP0_Config3 >> CP0C3_BP) & 1; /* Restore delay slot state from the tb context. */ ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */ ctx.ulri = env->CP0_Config3 & (1 << CP0C3_ULRI); restore_cpu_state(env, &ctx); #ifdef CONFIG_USER_ONLY ctx.mem_idx = MIPS_HFLAG_UM; #else ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU; #endif num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) max_insns = CF_COUNT_MASK; LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags); gen_tb_start(); while (ctx.bstate == BS_NONE) { if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { if (bp->pc == ctx.pc) { save_cpu_state(&ctx, 1); ctx.bstate = BS_BRANCH; gen_helper_0e0i(raise_exception, EXCP_DEBUG); /* Include the breakpoint location or the tb won't * be flushed when it must be. */ ctx.pc += 4; goto done_generating; } } } if (search_pc) { j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; if (lj < j) { lj++; while (lj < j) tcg_ctx.gen_opc_instr_start[lj++] = 0; } tcg_ctx.gen_opc_pc[lj] = ctx.pc; gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK; gen_opc_btarget[lj] = ctx.btarget; tcg_ctx.gen_opc_instr_start[lj] = 1; tcg_ctx.gen_opc_icount[lj] = num_insns; } if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) gen_io_start(); is_slot = ctx.hflags & MIPS_HFLAG_BMASK; if (!(ctx.hflags & MIPS_HFLAG_M16)) { ctx.opcode = cpu_ldl_code(env, ctx.pc); insn_bytes = 4; decode_opc(env, &ctx); } else if (ctx.insn_flags & ASE_MICROMIPS) { ctx.opcode = cpu_lduw_code(env, ctx.pc); insn_bytes = decode_micromips_opc(env, &ctx); } else if (ctx.insn_flags & ASE_MIPS16) { ctx.opcode = cpu_lduw_code(env, ctx.pc); insn_bytes = decode_mips16_opc(env, &ctx); } else { generate_exception(&ctx, EXCP_RI); ctx.bstate = BS_STOP; break; } if (ctx.hflags & MIPS_HFLAG_BMASK) { if (!(ctx.hflags & (MIPS_HFLAG_BDS16 | MIPS_HFLAG_BDS32 | MIPS_HFLAG_FBNSLOT))) { /* force to generate branch as there is neither delay nor forbidden slot */ is_slot = 1; } } if (is_slot) { gen_branch(&ctx, insn_bytes); } ctx.pc += insn_bytes; num_insns++; /* Execute a branch and its delay slot as a single instruction. This is what GDB expects and is consistent with what the hardware does (e.g. if a delay slot instruction faults, the reported PC is the PC of the branch). */ if (cs->singlestep_enabled && (ctx.hflags & MIPS_HFLAG_BMASK) == 0) { break; } if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) break; if (tcg_ctx.gen_opc_ptr >= gen_opc_end) { break; } if (num_insns >= max_insns) break; if (singlestep) break; } if (tb->cflags & CF_LAST_IO) { gen_io_end(); } if (cs->singlestep_enabled && ctx.bstate != BS_BRANCH) { save_cpu_state(&ctx, ctx.bstate == BS_NONE); gen_helper_0e0i(raise_exception, EXCP_DEBUG); } else { switch (ctx.bstate) { case BS_STOP: gen_goto_tb(&ctx, 0, ctx.pc); break; case BS_NONE: save_cpu_state(&ctx, 0); gen_goto_tb(&ctx, 0, ctx.pc); break; case BS_EXCP: tcg_gen_exit_tb(0); break; case BS_BRANCH: default: break; } } done_generating: gen_tb_end(tb, num_insns); *tcg_ctx.gen_opc_ptr = INDEX_op_end; if (search_pc) { j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; lj++; while (lj <= j) tcg_ctx.gen_opc_instr_start[lj++] = 0; } else { tb->size = ctx.pc - pc_start; tb->icount = num_insns; } #ifdef DEBUG_DISAS LOG_DISAS("\n"); if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); log_target_disas(env, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif }
10,488
qemu
6e0d8677cb443e7408c0b7a25a93c6596d7fa380
0
static inline void gen_movs(DisasContext *s, int ot) { gen_string_movl_A0_ESI(s); gen_op_ld_T0_A0(ot + s->mem_index); gen_string_movl_A0_EDI(s); gen_op_st_T0_A0(ot + s->mem_index); gen_op_movl_T0_Dshift[ot](); #ifdef TARGET_X86_64 if (s->aflag == 2) { gen_op_addq_ESI_T0(); gen_op_addq_EDI_T0(); } else #endif if (s->aflag) { gen_op_addl_ESI_T0(); gen_op_addl_EDI_T0(); } else { gen_op_addw_ESI_T0(); gen_op_addw_EDI_T0(); } }
10,489
FFmpeg
463705bd1c644bbdded7bcf9f619bcb4203d562f
0
static int udp_read(URLContext *h, uint8_t *buf, int size) { UDPContext *s = h->priv_data; int ret; int avail; #if HAVE_PTHREADS if (s->fifo) { pthread_mutex_lock(&s->mutex); do { avail = av_fifo_size(s->fifo); if (avail) { // >=size) { uint8_t tmp[4]; pthread_mutex_unlock(&s->mutex); av_fifo_generic_read(s->fifo, tmp, 4, NULL); avail= AV_RL32(tmp); if(avail > size){ av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n"); avail= size; } av_fifo_generic_read(s->fifo, buf, avail, NULL); av_fifo_drain(s->fifo, AV_RL32(tmp) - avail); return avail; } else if(s->circular_buffer_error){ pthread_mutex_unlock(&s->mutex); return s->circular_buffer_error; } else if(h->flags & AVIO_FLAG_NONBLOCK) { pthread_mutex_unlock(&s->mutex); return AVERROR(EAGAIN); } else { pthread_cond_wait(&s->cond, &s->mutex); } } while( 1); } #endif if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ret = ff_network_wait_fd(s->udp_fd, 0); if (ret < 0) return ret; } ret = recv(s->udp_fd, buf, size, 0); return ret < 0 ? ff_neterrno() : ret; }
10,490
qemu
6652d0811c9463fbfb2d2d1cb2ec03f388145c5f
0
static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector, MSIMessage msg) { 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 ret, index, unmasked = 0; while (vq) { index = virtio_get_queue_index(vq); if (!virtio_queue_get_num(vdev, index)) { break; } ret = virtio_pci_vq_vector_unmask(proxy, index, vector, msg); if (ret < 0) { goto undo; } vq = virtio_vector_next_queue(vq); ++unmasked; } return 0; undo: vq = virtio_vector_first_queue(vdev, vector); while (vq && --unmasked >= 0) { index = virtio_get_queue_index(vq); virtio_pci_vq_vector_mask(proxy, index, vector); vq = virtio_vector_next_queue(vq); } return ret; }
10,491
qemu
4d43d3f3c8147ade184df9a1e9e82826edd39e19
0
static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) { VirtIOPCIProxy *proxy = opaque; VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); hwaddr pa; switch (addr) { case VIRTIO_PCI_GUEST_FEATURES: /* Guest does not negotiate properly? We have to assume nothing. */ if (val & (1 << VIRTIO_F_BAD_FEATURE)) { val = virtio_bus_get_vdev_bad_features(&proxy->bus); } virtio_set_features(vdev, val); break; case VIRTIO_PCI_QUEUE_PFN: pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; if (pa == 0) { virtio_pci_stop_ioeventfd(proxy); virtio_reset(vdev); msix_unuse_all_vectors(&proxy->pci_dev); } else virtio_queue_set_addr(vdev, vdev->queue_sel, pa); break; case VIRTIO_PCI_QUEUE_SEL: if (val < VIRTIO_PCI_QUEUE_MAX) vdev->queue_sel = val; break; case VIRTIO_PCI_QUEUE_NOTIFY: if (val < VIRTIO_PCI_QUEUE_MAX) { virtio_queue_notify(vdev, val); } break; case VIRTIO_PCI_STATUS: if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { virtio_pci_stop_ioeventfd(proxy); } virtio_set_status(vdev, val & 0xFF); if (val & VIRTIO_CONFIG_S_DRIVER_OK) { virtio_pci_start_ioeventfd(proxy); } if (vdev->status == 0) { virtio_reset(vdev); msix_unuse_all_vectors(&proxy->pci_dev); } /* Linux before 2.6.34 drives the device without enabling the PCI device bus master bit. Enable it automatically for the guest. This is a PCI spec violation but so is initiating DMA with bus master bit clear. */ if (val == (VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER)) { pci_default_write_config(&proxy->pci_dev, PCI_COMMAND, proxy->pci_dev.config[PCI_COMMAND] | PCI_COMMAND_MASTER, 1); } /* Linux before 2.6.34 sets the device as OK without enabling the PCI device bus master bit. In this case we need to disable some safety checks. */ if ((val & VIRTIO_CONFIG_S_DRIVER_OK) && !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG; } break; case VIRTIO_MSI_CONFIG_VECTOR: msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); /* Make it possible for guest to discover an error took place. */ if (msix_vector_use(&proxy->pci_dev, val) < 0) val = VIRTIO_NO_VECTOR; vdev->config_vector = val; break; case VIRTIO_MSI_QUEUE_VECTOR: msix_vector_unuse(&proxy->pci_dev, virtio_queue_vector(vdev, vdev->queue_sel)); /* Make it possible for guest to discover an error took place. */ if (msix_vector_use(&proxy->pci_dev, val) < 0) val = VIRTIO_NO_VECTOR; virtio_queue_set_vector(vdev, vdev->queue_sel, val); break; default: error_report("%s: unexpected address 0x%x value 0x%x", __func__, addr, val); break; } }
10,492
qemu
84fd9dd3f78ced9d41e1160d43862bb620cb462a
0
void tcg_register_helper(void *func, const char *name) { TCGContext *s = &tcg_ctx; GHashTable *table = s->helpers; if (table == NULL) { /* Use g_direct_hash/equal for direct pointer comparisons on func. */ table = g_hash_table_new(NULL, NULL); s->helpers = table; } g_hash_table_insert(table, (gpointer)func, (gpointer)name); }
10,493
qemu
da6789c27c2ea71765cfab04bad9a42b5426f0bd
0
static void nvdimm_init(Object *obj) { object_property_add(obj, "label-size", "int", nvdimm_get_label_size, nvdimm_set_label_size, NULL, NULL, NULL); }
10,495
qemu
7ad4c7200111d20eb97eed4f46b6026e3f0b0eef
0
char *g_strdup_vprintf(const char *format, va_list ap) { char ch, *s; size_t len; __coverity_string_null_sink__(format); __coverity_string_size_sink__(format); ch = *format; ch = *(char *)ap; s = __coverity_alloc_nosize__(); __coverity_writeall__(s); __coverity_mark_as_afm_allocated__(s, AFM_free); return len; }
10,496
FFmpeg
4e03f0ab08e27537512107cba6e357d34284a35f
0
static void randomize_loopfilter_buffers(int bidx, int lineoff, int str, int bit_depth, int dir, int* E, int* F, int* H, int* I, uint8_t *buf0, uint8_t *buf1) { uint32_t mask = (1 << bit_depth) - 1; int off = dir ? lineoff : lineoff * 16; int istride = dir ? 1 : 16; int jstride = dir ? str : 1; int i, j; for (i = 0; i < 2; i++) /* flat16 */ { int idx = off + i * istride, p0, q0; setpx(idx, 0, q0 = rnd() & mask); setsx(idx, -1, p0 = q0, E[bidx] >> 2); for (j = 1; j < 8; j++) { setsx(idx, -1 - j, p0, F[bidx]); setsx(idx, j, q0, F[bidx]); } } for (i = 2; i < 4; i++) /* flat8 */ { int idx = off + i * istride, p0, q0; setpx(idx, 0, q0 = rnd() & mask); setsx(idx, -1, p0 = q0, E[bidx] >> 2); for (j = 1; j < 4; j++) { setsx(idx, -1 - j, p0, F[bidx]); setsx(idx, j, q0, F[bidx]); } for (j = 4; j < 8; j++) { setpx(idx, -1 - j, rnd() & mask); setpx(idx, j, rnd() & mask); } } for (i = 4; i < 6; i++) /* regular */ { int idx = off + i * istride, p2, p1, p0, q0, q1, q2; setpx(idx, 0, q0 = rnd() & mask); setsx(idx, 1, q1 = q0, I[bidx]); setsx(idx, 2, q2 = q1, I[bidx]); setsx(idx, 3, q2, I[bidx]); setsx(idx, -1, p0 = q0, E[bidx] >> 2); setsx(idx, -2, p1 = p0, I[bidx]); setsx(idx, -3, p2 = p1, I[bidx]); setsx(idx, -4, p2, I[bidx]); for (j = 4; j < 8; j++) { setpx(idx, -1 - j, rnd() & mask); setpx(idx, j, rnd() & mask); } } for (i = 6; i < 8; i++) /* off */ { int idx = off + i * istride; for (j = 0; j < 8; j++) { setpx(idx, -1 - j, rnd() & mask); setpx(idx, j, rnd() & mask); } } }
10,497
FFmpeg
d6604b29ef544793479d7fb4e05ef6622bb3e534
0
static av_cold int bmp_encode_close(AVCodecContext *avctx) { av_frame_free(&avctx->coded_frame); return 0; }
10,499
qemu
efec3dd631d94160288392721a5f9c39e50fb2bc
1
static void pci_grackle_class_init(ObjectClass *klass, void *data) { SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); k->init = pci_grackle_init_device; dc->no_user = 1; }
10,500
FFmpeg
b8b8e82ea14016b2cb04b49ecea57f836e6ee7f8
1
static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; DNXHDContext *ctx = avctx->priv_data; ThreadFrame frame = { .f = data }; AVFrame *picture = data; int first_field = 1; int ret; ff_dlog(avctx, "frame size %d\n", buf_size); decode_coding_unit: if ((ret = dnxhd_decode_header(ctx, picture, buf, buf_size, first_field)) < 0) return ret; if ((avctx->width || avctx->height) && (ctx->width != avctx->width || ctx->height != avctx->height)) { av_log(avctx, AV_LOG_WARNING, "frame size changed: %dx%d -> %dx%d\n", avctx->width, avctx->height, ctx->width, ctx->height); first_field = 1; } if (avctx->pix_fmt != AV_PIX_FMT_NONE && avctx->pix_fmt != ctx->pix_fmt) { av_log(avctx, AV_LOG_WARNING, "pix_fmt changed: %s -> %s\n", av_get_pix_fmt_name(avctx->pix_fmt), av_get_pix_fmt_name(ctx->pix_fmt)); first_field = 1; } avctx->pix_fmt = ctx->pix_fmt; ret = ff_set_dimensions(avctx, ctx->width, ctx->height); if (ret < 0) return ret; if (first_field) { if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) return ret; picture->pict_type = AV_PICTURE_TYPE_I; picture->key_frame = 1; } ctx->buf_size = buf_size - 0x280; ctx->buf = buf + 0x280; avctx->execute2(avctx, dnxhd_decode_row, picture, NULL, ctx->mb_height); if (first_field && picture->interlaced_frame) { buf += ctx->cid_table->coding_unit_size; buf_size -= ctx->cid_table->coding_unit_size; first_field = 0; goto decode_coding_unit; } *got_frame = 1; return avpkt->size; }
10,503
qemu
ef0e8fc768a561dd13a86420b3268f6f3d5d0621
1
static void vtd_realize(DeviceState *dev, Error **errp) { PCMachineState *pcms = PC_MACHINE(qdev_get_machine()); PCIBus *bus = pcms->bus; IntelIOMMUState *s = INTEL_IOMMU_DEVICE(dev); X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev); VTD_DPRINTF(GENERAL, ""); x86_iommu->type = TYPE_INTEL; if (!vtd_decide_config(s, errp)) { return; } QLIST_INIT(&s->notifiers_list); memset(s->vtd_as_by_bus_num, 0, sizeof(s->vtd_as_by_bus_num)); memory_region_init_io(&s->csrmem, OBJECT(s), &vtd_mem_ops, s, "intel_iommu", DMAR_REG_SIZE); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->csrmem); /* No corresponding destroy */ s->iotlb = g_hash_table_new_full(vtd_uint64_hash, vtd_uint64_equal, g_free, g_free); s->vtd_as_by_busptr = g_hash_table_new_full(vtd_uint64_hash, vtd_uint64_equal, g_free, g_free); vtd_init(s); sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, Q35_HOST_BRIDGE_IOMMU_ADDR); pci_setup_iommu(bus, vtd_host_dma_iommu, dev); /* Pseudo address space under root PCI bus. */ pcms->ioapic_as = vtd_host_dma_iommu(bus, s, Q35_PSEUDO_DEVFN_IOAPIC); }
10,505
qemu
b0f74c87a1dbd6b0c5e4de7f1c5cb40197e3fbe9
1
static inline void menelaus_rtc_start(struct menelaus_s *s) { s->rtc.next =+ qemu_get_clock(rt_clock); qemu_mod_timer(s->rtc.hz, s->rtc.next); }
10,506
qemu
b027a538c6790bcfc93ef7f4819fe3e581445959
1
static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) { int trig; OSSVoiceOut *oss = (OSSVoiceOut *) hw; switch (cmd) { case VOICE_ENABLE: { va_list ap; int poll_mode; va_start (ap, cmd); poll_mode = va_arg (ap, int); va_end (ap); ldebug ("enabling voice\n"); if (poll_mode && oss_poll_out (hw)) { poll_mode = 0; } hw->poll_mode = poll_mode; if (!oss->mmapped) { return 0; } audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples); trig = PCM_ENABLE_OUTPUT; if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { oss_logerr ( errno, "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n" ); return -1; } } break; case VOICE_DISABLE: if (hw->poll_mode) { qemu_set_fd_handler (oss->fd, NULL, NULL, NULL); hw->poll_mode = 0; } if (!oss->mmapped) { return 0; } ldebug ("disabling voice\n"); trig = 0; if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n"); return -1; } break; } return 0; }
10,507
qemu
80c27194a7be757ef5a9cec978d1d8faaa4cee81
1
void op_ddiv (void) { if (T1 != 0) { env->LO = (int64_t)T0 / (int64_t)T1; env->HI = (int64_t)T0 % (int64_t)T1; } RETURN(); }
10,508
qemu
73a8912b8aeed1c992e3f9cb4880e9d1edb935de
1
static void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len) { int idx, thread_count; thread_count = migrate_decompress_threads(); while (true) { for (idx = 0; idx < thread_count; idx++) { if (!decomp_param[idx].start) { qemu_get_buffer(f, decomp_param[idx].compbuf, len); decomp_param[idx].des = host; decomp_param[idx].len = len; start_decompression(&decomp_param[idx]); break; } } if (idx < thread_count) { break; } } }
10,509
FFmpeg
6592cd22a2307dbbeb621c7499ba81961e6face8
1
static int config_input(AVFilterLink *link) { AVFilterContext *ctx = link->dst; CropContext *s = ctx->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(link->format); int ret; const char *expr; double res; s->var_values[VAR_E] = M_E; s->var_values[VAR_PHI] = M_PHI; s->var_values[VAR_PI] = M_PI; s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = ctx->inputs[0]->w; s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = ctx->inputs[0]->h; s->var_values[VAR_X] = NAN; s->var_values[VAR_Y] = NAN; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = NAN; s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = NAN; s->var_values[VAR_N] = 0; s->var_values[VAR_T] = NAN; av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; if ((ret = av_expr_parse_and_eval(&res, (expr = s->ow_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->oh_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = res; /* evaluate again ow as it may depend on oh */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->ow_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res; if (normalize_double(&s->w, s->var_values[VAR_OUT_W]) < 0 || normalize_double(&s->h, s->var_values[VAR_OUT_H]) < 0) { av_log(ctx, AV_LOG_ERROR, "Too big value or invalid expression for out_w/ow or out_h/oh. " "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n", s->ow_expr, s->oh_expr); return AVERROR(EINVAL); } s->w &= ~((1 << s->hsub) - 1); s->h &= ~((1 << s->vsub) - 1); if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0 || (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) return AVERROR(EINVAL); av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n", link->w, link->h, s->w, s->h); if (s->w <= 0 || s->h <= 0 || s->w > link->w || s->h > link->h) { av_log(ctx, AV_LOG_ERROR, "Invalid too big or non positive size for width '%d' or height '%d'\n", s->w, s->h); return AVERROR(EINVAL); } /* set default, required in the case the first computed value for x/y is NAN */ s->x = (link->w - s->w) / 2; s->y = (link->h - s->h) / 2; s->x &= ~((1 << s->hsub) - 1); s->y &= ~((1 << s->vsub) - 1); return 0; fail_expr: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }
10,510
FFmpeg
d9a3501c33a1f88350c935785dbf5435e9ffabe6
1
int av_opt_set_dict(void *obj, AVDictionary **options) { AVDictionaryEntry *t = NULL; AVDictionary *tmp = NULL; int ret = 0; while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) { ret = av_opt_set(obj, t->key, t->value, 0); if (ret == AVERROR_OPTION_NOT_FOUND) av_dict_set(&tmp, t->key, t->value, 0); else if (ret < 0) { av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); break; } ret = 0; } av_dict_free(options); *options = tmp; return ret; }
10,511
FFmpeg
79997def65fd2313b48a5f3c3a884c6149ae9b5d
0
static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, int nbits) { int i, n, n4, ret; n = 1 << nbits; n4 = n >> 2; mdct->nbits = nbits; ret = fft_init(avctx, mdct, nbits - 2); if (ret) return ret; mdct->window = ff_ac3_window; FF_ALLOC_OR_GOTO(avctx, mdct->xcos1, n4 * sizeof(*mdct->xcos1), mdct_alloc_fail); FF_ALLOC_OR_GOTO(avctx, mdct->xsin1, n4 * sizeof(*mdct->xsin1), mdct_alloc_fail); FF_ALLOC_OR_GOTO(avctx, mdct->rot_tmp, n * sizeof(*mdct->rot_tmp), mdct_alloc_fail); FF_ALLOC_OR_GOTO(avctx, mdct->cplx_tmp, n4 * sizeof(*mdct->cplx_tmp), mdct_alloc_fail); for (i = 0; i < n4; i++) { float alpha = 2.0 * M_PI * (i + 1.0 / 8.0) / n; mdct->xcos1[i] = FIX15(-cos(alpha)); mdct->xsin1[i] = FIX15(-sin(alpha)); } return 0; mdct_alloc_fail: mdct_end(mdct); return AVERROR(ENOMEM); }
10,512
FFmpeg
80a5d05108cb218e8cd2e25c6621a3bfef0a832e
0
static av_cold int vaapi_encode_h264_init_internal(AVCodecContext *avctx) { static const VAConfigAttrib default_config_attributes[] = { { .type = VAConfigAttribRTFormat, .value = VA_RT_FORMAT_YUV420 }, { .type = VAConfigAttribEncPackedHeaders, .value = (VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_SLICE) }, }; VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH264Context *priv = ctx->priv_data; VAAPIEncodeH264Options *opt = ctx->codec_options; int i, err; switch (avctx->profile) { case FF_PROFILE_H264_CONSTRAINED_BASELINE: ctx->va_profile = VAProfileH264ConstrainedBaseline; break; case FF_PROFILE_H264_BASELINE: ctx->va_profile = VAProfileH264Baseline; break; case FF_PROFILE_H264_MAIN: ctx->va_profile = VAProfileH264Main; break; case FF_PROFILE_H264_EXTENDED: av_log(avctx, AV_LOG_ERROR, "H.264 extended profile " "is not supported.\n"); return AVERROR_PATCHWELCOME; case FF_PROFILE_UNKNOWN: case FF_PROFILE_H264_HIGH: ctx->va_profile = VAProfileH264High; break; case FF_PROFILE_H264_HIGH_10: case FF_PROFILE_H264_HIGH_10_INTRA: av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles " "are not supported.\n"); return AVERROR_PATCHWELCOME; case FF_PROFILE_H264_HIGH_422: case FF_PROFILE_H264_HIGH_422_INTRA: case FF_PROFILE_H264_HIGH_444: case FF_PROFILE_H264_HIGH_444_PREDICTIVE: case FF_PROFILE_H264_HIGH_444_INTRA: case FF_PROFILE_H264_CAVLC_444: av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles " "are not supported.\n"); return AVERROR_PATCHWELCOME; default: av_log(avctx, AV_LOG_ERROR, "Unknown H.264 profile %d.\n", avctx->profile); return AVERROR(EINVAL); } if (opt->low_power) { #if VA_CHECK_VERSION(0, 39, 1) ctx->va_entrypoint = VAEntrypointEncSliceLP; #else av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not " "supported with this VAAPI version.\n"); return AVERROR(EINVAL); #endif } else { ctx->va_entrypoint = VAEntrypointEncSlice; } ctx->input_width = avctx->width; ctx->input_height = avctx->height; ctx->aligned_width = FFALIGN(ctx->input_width, 16); ctx->aligned_height = FFALIGN(ctx->input_height, 16); priv->mb_width = ctx->aligned_width / 16; priv->mb_height = ctx->aligned_height / 16; for (i = 0; i < FF_ARRAY_ELEMS(default_config_attributes); i++) { ctx->config_attributes[ctx->nb_config_attributes++] = default_config_attributes[i]; } if (avctx->bit_rate > 0) { ctx->va_rc_mode = VA_RC_CBR; err = vaapi_encode_h264_init_constant_bitrate(avctx); } else { ctx->va_rc_mode = VA_RC_CQP; err = vaapi_encode_h264_init_fixed_qp(avctx); } if (err < 0) return err; ctx->config_attributes[ctx->nb_config_attributes++] = (VAConfigAttrib) { .type = VAConfigAttribRateControl, .value = ctx->va_rc_mode, }; if (opt->quality > 0) { #if VA_CHECK_VERSION(0, 36, 0) priv->quality_params.misc.type = VAEncMiscParameterTypeQualityLevel; priv->quality_params.quality.quality_level = opt->quality; ctx->global_params[ctx->nb_global_params] = &priv->quality_params.misc; ctx->global_params_size[ctx->nb_global_params++] = sizeof(priv->quality_params); #else av_log(avctx, AV_LOG_WARNING, "The encode quality option is not " "supported with this VAAPI version.\n"); #endif } ctx->nb_recon_frames = 20; return 0; }
10,514
FFmpeg
93db2708d3b0bcc1f1d87d23ae8adbedd8ea6660
1
static void do_video_out(AVFormatContext *s, OutputStream *ost, AVFrame *next_picture, double sync_ipts) { int ret, format_video_sync; AVPacket pkt; AVCodecContext *enc = ost->enc_ctx; AVCodecContext *mux_enc = ost->st->codec; int nb_frames, nb0_frames, i; double delta, delta0; double duration = 0; int frame_size = 0; InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; if (ost->source_index >= 0) ist = input_streams[ost->source_index]; if (filter->inputs[0]->frame_rate.num > 0 && filter->inputs[0]->frame_rate.den > 0) duration = 1/(av_q2d(filter->inputs[0]->frame_rate) * av_q2d(enc->time_base)); if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num) duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base))); if (!ost->filters_script && !ost->filters && next_picture && ist && lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) { duration = lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)); } if (!next_picture) { //end, flushing nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0], ost->last_nb0_frames[1], ost->last_nb0_frames[2]); } else { delta0 = sync_ipts - ost->sync_opts; delta = delta0 + duration; /* by default, we output a single frame */ nb0_frames = 0; nb_frames = 1; format_video_sync = video_sync_method; if (format_video_sync == VSYNC_AUTO) { if(!strcmp(s->oformat->name, "avi")) { format_video_sync = VSYNC_VFR; } else format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? ((s->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR; if ( ist && format_video_sync == VSYNC_CFR && input_files[ist->file_index]->ctx->nb_streams == 1 && input_files[ist->file_index]->input_ts_offset == 0) { format_video_sync = VSYNC_VSCFR; } if (format_video_sync == VSYNC_CFR && copy_ts) { format_video_sync = VSYNC_VSCFR; } } if (delta0 < 0 && delta > 0 && format_video_sync != VSYNC_PASSTHROUGH && format_video_sync != VSYNC_DROP) { double cor = FFMIN(-delta0, duration); if (delta0 < -0.6) { av_log(NULL, AV_LOG_WARNING, "Past duration %f too large\n", -delta0); } else av_log(NULL, AV_LOG_DEBUG, "Cliping frame in rate conversion by %f\n", -delta0); sync_ipts += cor; duration -= cor; delta0 += cor; } switch (format_video_sync) { case VSYNC_VSCFR: if (ost->frame_number == 0 && delta - duration >= 0.5) { av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta - duration)); delta = duration; delta0 = 0; ost->sync_opts = lrint(sync_ipts); } case VSYNC_CFR: // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c if (frame_drop_threshold && delta < frame_drop_threshold && ost->frame_number) { nb_frames = 0; } else if (delta < -1.1) nb_frames = 0; else if (delta > 1.1) { nb_frames = lrintf(delta); if (delta0 > 1.1) nb0_frames = lrintf(delta0 - 0.6); } break; case VSYNC_VFR: if (delta <= -0.6) nb_frames = 0; else if (delta > 0.6) ost->sync_opts = lrint(sync_ipts); break; case VSYNC_DROP: case VSYNC_PASSTHROUGH: ost->sync_opts = lrint(sync_ipts); break; default: av_assert0(0); } } nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); nb0_frames = FFMIN(nb0_frames, nb_frames); memmove(ost->last_nb0_frames + 1, ost->last_nb0_frames, sizeof(ost->last_nb0_frames[0]) * (FF_ARRAY_ELEMS(ost->last_nb0_frames) - 1)); ost->last_nb0_frames[0] = nb0_frames; if (nb0_frames == 0 && ost->last_droped) { nb_frames_drop++; av_log(NULL, AV_LOG_VERBOSE, "*** dropping frame %d from stream %d at ts %"PRId64"\n", ost->frame_number, ost->st->index, ost->last_frame->pts); } if (nb_frames > (nb0_frames && ost->last_droped) + (nb_frames > nb0_frames)) { if (nb_frames > dts_error_threshold * 30) { av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skipping\n", nb_frames - 1); nb_frames_drop++; } nb_frames_dup += nb_frames - (nb0_frames && ost->last_droped) - (nb_frames > nb0_frames); av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1); } ost->last_droped = nb_frames == nb0_frames && next_picture; /* duplicates frame if needed */ for (i = 0; i < nb_frames; i++) { AVFrame *in_picture; av_init_packet(&pkt); pkt.data = NULL; pkt.size = 0; if (i < nb0_frames && ost->last_frame) { in_picture = ost->last_frame; } else in_picture = next_picture; in_picture->pts = ost->sync_opts; #if 1 if (!check_recording_time(ost)) #else if (ost->frame_number >= ost->max_frames) #endif if (s->oformat->flags & AVFMT_RAWPICTURE && enc->codec->id == AV_CODEC_ID_RAWVIDEO) { /* raw pictures are written as AVPicture structure to avoid any copies. We support temporarily the older method. */ if (in_picture->interlaced_frame) mux_enc->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT; else mux_enc->field_order = AV_FIELD_PROGRESSIVE; pkt.data = (uint8_t *)in_picture; pkt.size = sizeof(AVPicture); pkt.pts = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base); pkt.flags |= AV_PKT_FLAG_KEY; write_frame(s, &pkt, ost); } else { int got_packet, forced_keyframe = 0; double pts_time; if (enc->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME) && ost->top_field_first >= 0) in_picture->top_field_first = !!ost->top_field_first; if (in_picture->interlaced_frame) { if (enc->codec->id == AV_CODEC_ID_MJPEG) mux_enc->field_order = in_picture->top_field_first ? AV_FIELD_TT:AV_FIELD_BB; else mux_enc->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT; } else mux_enc->field_order = AV_FIELD_PROGRESSIVE; in_picture->quality = enc->global_quality; in_picture->pict_type = 0; pts_time = in_picture->pts != AV_NOPTS_VALUE ? in_picture->pts * av_q2d(enc->time_base) : NAN; if (ost->forced_kf_index < ost->forced_kf_count && in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) { ost->forced_kf_index++; forced_keyframe = 1; } else if (ost->forced_keyframes_pexpr) { double res; ost->forced_keyframes_expr_const_values[FKF_T] = pts_time; res = av_expr_eval(ost->forced_keyframes_pexpr, ost->forced_keyframes_expr_const_values, NULL); av_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n", ost->forced_keyframes_expr_const_values[FKF_N], ost->forced_keyframes_expr_const_values[FKF_N_FORCED], ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N], ost->forced_keyframes_expr_const_values[FKF_T], ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T], res); if (res) { forced_keyframe = 1; ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = ost->forced_keyframes_expr_const_values[FKF_N]; ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = ost->forced_keyframes_expr_const_values[FKF_T]; ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1; } ost->forced_keyframes_expr_const_values[FKF_N] += 1; } if (forced_keyframe) { in_picture->pict_type = AV_PICTURE_TYPE_I; av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time); } update_benchmark(NULL); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder <- type:video " "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", av_ts2str(in_picture->pts), av_ts2timestr(in_picture->pts, &enc->time_base), enc->time_base.num, enc->time_base.den); } ost->frames_encoded++; ret = avcodec_encode_video2(enc, &pkt, in_picture, &got_packet); update_benchmark("encode_video %d.%d", ost->file_index, ost->index); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); exit_program(1); } if (got_packet) { if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:video " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base), av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &enc->time_base)); } if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & CODEC_CAP_DELAY)) pkt.pts = ost->sync_opts; av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:video " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base), av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base)); } frame_size = pkt.size; write_frame(s, &pkt, ost); /* if two pass, output log */ if (ost->logfile && enc->stats_out) { fprintf(ost->logfile, "%s", enc->stats_out); } } } ost->sync_opts++; /* * For video, number of frames in == number of packets out. * But there may be reordering, so we can't throw away frames on encoder * flush, we need to limit them here, before they go into encoder. */ ost->frame_number++; if (vstats_filename && frame_size) do_video_stats(ost, frame_size); } if (!ost->last_frame) ost->last_frame = av_frame_alloc(); av_frame_unref(ost->last_frame); if (next_picture) av_frame_ref(ost->last_frame, next_picture); }
10,515
qemu
c6d34865fa02463cf34634f45369ebcc725b101b
1
static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds, uint8_t *buffer, uint32_t count) { uint32_t type, i; int ret; size_t new_size; uint32_t chunk_count; int64_t offset = 0; type = buff_read_uint32(buffer, offset); /* skip data that is not a valid MISH block (invalid magic or too small) */ if (type != 0x6d697368 || count < 244) { /* assume success for now */ return 0; } offset += 4; offset += 200; chunk_count = (count - 204) / 40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); s->types = g_realloc(s->types, new_size / 2); s->offsets = g_realloc(s->offsets, new_size); s->lengths = g_realloc(s->lengths, new_size); s->sectors = g_realloc(s->sectors, new_size); s->sectorcounts = g_realloc(s->sectorcounts, new_size); for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) { s->types[i] = buff_read_uint32(buffer, offset); offset += 4; if (s->types[i] != 0x80000005 && s->types[i] != 1 && s->types[i] != 2) { if (s->types[i] == 0xffffffff && i > 0) { ds->last_in_offset = s->offsets[i - 1] + s->lengths[i - 1]; ds->last_out_offset = s->sectors[i - 1] + s->sectorcounts[i - 1]; } chunk_count--; i--; offset += 36; continue; } offset += 4; s->sectors[i] = buff_read_uint64(buffer, offset); s->sectors[i] += ds->last_out_offset; offset += 8; s->sectorcounts[i] = buff_read_uint64(buffer, offset); offset += 8; if (s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) { error_report("sector count %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX); ret = -EINVAL; goto fail; } s->offsets[i] = buff_read_uint64(buffer, offset); s->offsets[i] += ds->last_in_offset; offset += 8; s->lengths[i] = buff_read_uint64(buffer, offset); offset += 8; if (s->lengths[i] > DMG_LENGTHS_MAX) { error_report("length %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->lengths[i], i, DMG_LENGTHS_MAX); ret = -EINVAL; goto fail; } update_max_chunk_size(s, i, &ds->max_compressed_size, &ds->max_sectors_per_chunk); } s->n_chunks += chunk_count; return 0; fail: return ret; }
10,516
FFmpeg
478f1c3d5e5463a284ea7efecfc62d47ba3be11a
1
static int png_decode_idat(PNGDecContext *s, int length) { int ret; s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); s->zstream.next_in = (unsigned char *)s->gb.buffer; bytestream2_skip(&s->gb, length); /* decode one line if possible */ while (s->zstream.avail_in > 0) { ret = inflate(&s->zstream, Z_PARTIAL_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret); return AVERROR_EXTERNAL; } if (s->zstream.avail_out == 0) { if (!(s->state & PNG_ALLIMAGE)) { png_handle_row(s); } s->zstream.avail_out = s->crow_size; s->zstream.next_out = s->crow_buf; } if (ret == Z_STREAM_END && s->zstream.avail_in > 0) { av_log(NULL, AV_LOG_WARNING, "%d undecompressed bytes left in buffer\n", s->zstream.avail_in); return 0; } } return 0; }
10,517
qemu
38f3adc34de83bf75d2023831dc520d32568a2d9
1
FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, AddressSpace *dma_as) { DeviceState *dev; SysBusDevice *sbd; FWCfgIoState *ios; FWCfgState *s; bool dma_requested = dma_iobase && dma_as; dev = qdev_create(NULL, TYPE_FW_CFG_IO); if (!dma_requested) { qdev_prop_set_bit(dev, "dma_enabled", false); } fw_cfg_init1(dev); sbd = SYS_BUS_DEVICE(dev); ios = FW_CFG_IO(dev); sysbus_add_io(sbd, iobase, &ios->comb_iomem); s = FW_CFG(dev); if (s->dma_enabled) { /* 64 bits for the address field */ s->dma_as = dma_as; s->dma_addr = 0; sysbus_add_io(sbd, dma_iobase, &s->dma_iomem); } return s; }
10,518
FFmpeg
582368626188c070d4300913c6da5efa4c24cfb2
1
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; Mpeg1Context *s = avctx->priv_data; AVFrame *picture = data; MpegEncContext *s2 = &s->mpeg_enc_ctx; av_dlog(avctx, "fill_buffer\n"); if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) { /* special case for last picture */ if (s2->low_delay == 0 && s2->next_picture_ptr) { *picture = s2->next_picture_ptr->f; s2->next_picture_ptr = NULL; *got_output = 1; } return buf_size; } if (s2->flags & CODEC_FLAG_TRUNCATED) { int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL); if (ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0) return buf_size; } if (s->mpeg_enc_ctx_allocated == 0 && avctx->codec_tag == AV_RL32("VCR2")) vcr2_init_sequence(avctx); s->slice_count = 0; if (avctx->extradata && !avctx->frame_number) { int ret = decode_chunks(avctx, picture, got_output, avctx->extradata, avctx->extradata_size); if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) return ret; } return decode_chunks(avctx, picture, got_output, buf, buf_size); }
10,519
FFmpeg
92dad6687f59a6e599834218626e524eb8a5bdae
1
av_cold void ff_fft_fixed_init_arm(FFTContext *s) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) { s->fft_permutation = FF_FFT_PERM_SWAP_LSBS; s->fft_calc = ff_fft_fixed_calc_neon; #if CONFIG_MDCT if (!s->inverse && s->mdct_bits >= 5) { s->mdct_permutation = FF_MDCT_PERM_INTERLEAVE; s->mdct_calc = ff_mdct_fixed_calc_neon; s->mdct_calcw = ff_mdct_fixed_calcw_neon; } #endif } }
10,521
qemu
c2b38b277a7882a592f4f2ec955084b2b756daaa
0
static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) { return timer_head && (timer_head->expire_time <= current_time); }
10,523
qemu
872ea0c098f63a36de8c49eb2cf348cd111292b9
0
void syscall_init(void) { IOCTLEntry *ie; const argtype *arg_type; int size; int i; #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); #include "syscall_types.h" #undef STRUCT #undef STRUCT_SPECIAL /* we patch the ioctl size if necessary. We rely on the fact that no ioctl has all the bits at '1' in the size field */ ie = ioctl_entries; while (ie->target_cmd != 0) { if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == TARGET_IOC_SIZEMASK) { arg_type = ie->arg_type; if (arg_type[0] != TYPE_PTR) { fprintf(stderr, "cannot patch size for ioctl 0x%x\n", ie->target_cmd); exit(1); } arg_type++; size = thunk_type_size(arg_type, 0); ie->target_cmd = (ie->target_cmd & ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | (size << TARGET_IOC_SIZESHIFT); } /* Build target_to_host_errno_table[] table from * host_to_target_errno_table[]. */ for (i=0; i < ERRNO_TABLE_SIZE; i++) target_to_host_errno_table[host_to_target_errno_table[i]] = i; /* automatic consistency check if same arch */ #if defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32) if (ie->target_cmd != ie->host_cmd) { fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n", ie->target_cmd, ie->host_cmd); } #endif ie++; } }
10,524
qemu
d0d7708ba29cbcc343364a46bff981e0ff88366f
0
static CharDriverState *qemu_chr_open_stdio(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { ChardevStdio *opts = backend->u.stdio; CharDriverState *chr; struct sigaction act; if (is_daemonized()) { error_setg(errp, "cannot use stdio with -daemonize"); return NULL; } if (stdio_in_use) { error_setg(errp, "cannot use stdio by multiple character devices"); return NULL; } stdio_in_use = true; old_fd0_flags = fcntl(0, F_GETFL); tcgetattr(0, &oldtty); qemu_set_nonblock(0); atexit(term_exit); memset(&act, 0, sizeof(act)); act.sa_handler = term_stdio_handler; sigaction(SIGCONT, &act, NULL); chr = qemu_chr_open_fd(0, 1); chr->chr_close = qemu_chr_close_stdio; chr->chr_set_echo = qemu_chr_set_echo_stdio; if (opts->has_signal) { stdio_allow_signal = opts->signal; } qemu_chr_fe_set_echo(chr, false); return chr; }
10,525
qemu
de9e9d9f17a36ff76c1a02a5348835e5e0a081b0
0
static inline void gen_op_eval_bg(TCGv dst, TCGv_i32 src) { gen_mov_reg_N(cpu_tmp0, src); gen_mov_reg_V(dst, src); tcg_gen_xor_tl(dst, dst, cpu_tmp0); gen_mov_reg_Z(cpu_tmp0, src); tcg_gen_or_tl(dst, dst, cpu_tmp0); tcg_gen_xori_tl(dst, dst, 0x1); }
10,526
qemu
0ac7cc2af500b948510f2481c22e84a57b0a2447
0
START_TEST(qstring_destroy_test) { QString *qstring = qstring_from_str("destroy test"); QDECREF(qstring); }
10,527
FFmpeg
f77fd34bc34c93a555eee99226d01d947d02a2a3
0
static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; float output_scale_factor; ac->avctx = avctx; ac->oc[1].m4ac.sample_rate = avctx->sample_rate; if (avctx->extradata_size > 0) { if (decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac, avctx->extradata, avctx->extradata_size*8, 1) < 0) return -1; } else { int sr, i; uint8_t layout_map[MAX_ELEM_ID*4][3]; int layout_map_tags; sr = sample_rate_idx(avctx->sample_rate); ac->oc[1].m4ac.sampling_index = sr; ac->oc[1].m4ac.channels = avctx->channels; ac->oc[1].m4ac.sbr = -1; ac->oc[1].m4ac.ps = -1; for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) if (ff_mpeg4audio_channels[i] == avctx->channels) break; if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { i = 0; } ac->oc[1].m4ac.chan_config = i; if (ac->oc[1].m4ac.chan_config) { int ret = set_default_channel_config(avctx, layout_map, &layout_map_tags, ac->oc[1].m4ac.chan_config); if (!ret) output_configure(ac, layout_map, layout_map_tags, ac->oc[1].m4ac.chan_config, OC_GLOBAL_HDR); else if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } } if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { avctx->sample_fmt = AV_SAMPLE_FMT_FLT; output_scale_factor = 1.0 / 32768.0; } else { avctx->sample_fmt = AV_SAMPLE_FMT_S16; output_scale_factor = 1.0; } AAC_INIT_VLC_STATIC( 0, 304); AAC_INIT_VLC_STATIC( 1, 270); AAC_INIT_VLC_STATIC( 2, 550); AAC_INIT_VLC_STATIC( 3, 300); AAC_INIT_VLC_STATIC( 4, 328); AAC_INIT_VLC_STATIC( 5, 294); AAC_INIT_VLC_STATIC( 6, 306); AAC_INIT_VLC_STATIC( 7, 268); AAC_INIT_VLC_STATIC( 8, 510); AAC_INIT_VLC_STATIC( 9, 366); AAC_INIT_VLC_STATIC(10, 462); ff_aac_sbr_init(); ff_dsputil_init(&ac->dsp, avctx); ff_fmt_convert_init(&ac->fmt_conv, avctx); avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ac->random_state = 0x1f2e3d4c; ff_aac_tableinit(); INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]), ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), 352); ff_mdct_init(&ac->mdct, 11, 1, output_scale_factor/1024.0); ff_mdct_init(&ac->mdct_small, 8, 1, output_scale_factor/128.0); ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0/output_scale_factor); // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows( 7); cbrt_tableinit(); avcodec_get_frame_defaults(&ac->frame); avctx->coded_frame = &ac->frame; return 0; }
10,528
qemu
0fb6395c0cb5046432a80d608ddde7a3b2f8a9ae
0
static void test_validate_union_anon(TestInputVisitorData *data, const void *unused) { UserDefAnonUnion *tmp = NULL; Visitor *v; Error *errp = NULL; v = validate_test_init(data, "42"); visit_type_UserDefAnonUnion(v, &tmp, NULL, &errp); g_assert(!error_is_set(&errp)); qapi_free_UserDefAnonUnion(tmp); }
10,529
qemu
32bafa8fdd098d52fbf1102d5a5e48d29398c0aa
0
int qemu_input_key_value_to_qcode(const KeyValue *value) { if (value->type == KEY_VALUE_KIND_QCODE) { return value->u.qcode; } else { assert(value->type == KEY_VALUE_KIND_NUMBER); return qemu_input_key_number_to_qcode(value->u.number); } }
10,530
qemu
56943e8cc14b7eeeab67d1942fa5d8bcafe3e53f
0
void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) { /* We only support one address space per cpu at the moment. */ assert(cpu->as == as); if (cpu->cpu_ases) { /* We've already registered the listener for our only AS */ return; } cpu->cpu_ases = g_new0(CPUAddressSpace, 1); cpu->cpu_ases[0].cpu = cpu; cpu->cpu_ases[0].as = as; cpu->cpu_ases[0].tcg_as_listener.commit = tcg_commit; memory_listener_register(&cpu->cpu_ases[0].tcg_as_listener, as); }
10,531
qemu
29560a6cb7a7a705de3d7dfb44e8b1c0a12ad37d
0
static struct iovec *lock_iovec(int type, abi_ulong target_addr, int count, int copy) { struct target_iovec *target_vec; struct iovec *vec; abi_ulong total_len, max_len; int i; int err = 0; if (count == 0) { errno = 0; return NULL; } if (count < 0 || count > IOV_MAX) { errno = EINVAL; return NULL; } vec = calloc(count, sizeof(struct iovec)); if (vec == NULL) { errno = ENOMEM; return NULL; } target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1); if (target_vec == NULL) { err = EFAULT; goto fail2; } /* ??? If host page size > target page size, this will result in a value larger than what we can actually support. */ max_len = 0x7fffffff & TARGET_PAGE_MASK; total_len = 0; for (i = 0; i < count; i++) { abi_ulong base = tswapal(target_vec[i].iov_base); abi_long len = tswapal(target_vec[i].iov_len); if (len < 0) { err = EINVAL; goto fail; } else if (len == 0) { /* Zero length pointer is ignored. */ vec[i].iov_base = 0; } else { vec[i].iov_base = lock_user(type, base, len, copy); if (!vec[i].iov_base) { err = EFAULT; goto fail; } if (len > max_len - total_len) { len = max_len - total_len; } } vec[i].iov_len = len; total_len += len; } unlock_user(target_vec, target_addr, 0); return vec; fail: unlock_user(target_vec, target_addr, 0); fail2: free(vec); errno = err; return NULL; }
10,532
qemu
203d65a4706be345c209f3408d3a011a3e48f0c9
0
static void imx_gpt_compute_next_timeout(IMXGPTState *s, bool event) { uint32_t timeout = TIMER_MAX; uint32_t count = 0; long long limit; if (!(s->cr & GPT_CR_EN)) { /* if not enabled just return */ return; } if (event) { /* This is a timer event */ if ((s->cr & GPT_CR_FRR) && (s->next_timeout != TIMER_MAX)) { /* * if we are in free running mode and we have not reached * the TIMER_MAX limit, then update the count */ count = imx_gpt_update_count(s); } } else { /* not a timer event, then just update the count */ count = imx_gpt_update_count(s); } /* now, find the next timeout related to count */ if (s->ir & GPT_IR_OF1IE) { timeout = imx_gpt_find_limit(count, s->ocr1, timeout); } if (s->ir & GPT_IR_OF2IE) { timeout = imx_gpt_find_limit(count, s->ocr2, timeout); } if (s->ir & GPT_IR_OF3IE) { timeout = imx_gpt_find_limit(count, s->ocr3, timeout); } /* find the next set of interrupts to raise for next timer event */ s->next_int = 0; if ((s->ir & GPT_IR_OF1IE) && (timeout == s->ocr1)) { s->next_int |= GPT_SR_OF1; } if ((s->ir & GPT_IR_OF2IE) && (timeout == s->ocr2)) { s->next_int |= GPT_SR_OF2; } if ((s->ir & GPT_IR_OF3IE) && (timeout == s->ocr3)) { s->next_int |= GPT_SR_OF3; } if ((s->ir & GPT_IR_ROVIE) && (timeout == TIMER_MAX)) { s->next_int |= GPT_SR_ROV; } /* the new range to count down from */ limit = timeout - imx_gpt_update_count(s); if (limit < 0) { /* * if we reach here, then QEMU is running too slow and we pass the * timeout limit while computing it. Let's deliver the interrupt * and compute a new limit. */ s->sr |= s->next_int; imx_gpt_compute_next_timeout(s, event); imx_gpt_update_int(s); } else { /* New timeout value */ s->next_timeout = timeout; /* reset the limit to the computed range */ ptimer_set_limit(s->timer, limit, 1); } }
10,533
qemu
62be4e3a5041e84304aa23637da623a205c53ecc
0
ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp) { return qemu_ram_alloc_from_ptr(size, NULL, mr, errp); }
10,534
qemu
7a0e58fa648736a75f2a6943afd2ab08ea15b8e0
0
bool write_list_to_cpustate(ARMCPU *cpu) { int i; bool ok = true; for (i = 0; i < cpu->cpreg_array_len; i++) { uint32_t regidx = kvm_to_cpreg_id(cpu->cpreg_indexes[i]); uint64_t v = cpu->cpreg_values[i]; const ARMCPRegInfo *ri; ri = get_arm_cp_reginfo(cpu->cp_regs, regidx); if (!ri) { ok = false; continue; } if (ri->type & ARM_CP_NO_MIGRATE) { continue; } /* Write value and confirm it reads back as written * (to catch read-only registers and partially read-only * registers where the incoming migration value doesn't match) */ write_raw_cp_reg(&cpu->env, ri, v); if (read_raw_cp_reg(&cpu->env, ri) != v) { ok = false; } } return ok; }
10,535
qemu
2f21b8d431030bcb7478ee9521bdfd3d0ef3901d
0
static int trap_msix(S390PCIBusDevice *pbdev, uint64_t offset, uint8_t pcias) { if (pbdev->msix.available && pbdev->msix.table_bar == pcias && offset >= pbdev->msix.table_offset && offset <= pbdev->msix.table_offset + (pbdev->msix.entries - 1) * PCI_MSIX_ENTRY_SIZE) { return 1; } else { return 0; } }
10,536
qemu
81ffbf5ab1458e357a761f1272105a55829b351e
0
static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name) { return !strcmp(name, VIRTFS_META_DIR); }
10,537
qemu
ff047453f56713aa627e63aade1a9046ccd3bdfd
0
static void cpu_pre_save(void *opaque) { ARMCPU *cpu = opaque; if (!write_cpustate_to_list(cpu)) { /* This should never fail. */ abort(); } cpu->cpreg_vmstate_array_len = cpu->cpreg_array_len; memcpy(cpu->cpreg_vmstate_indexes, cpu->cpreg_indexes, cpu->cpreg_array_len * sizeof(uint64_t)); memcpy(cpu->cpreg_vmstate_values, cpu->cpreg_values, cpu->cpreg_array_len * sizeof(uint64_t)); }
10,538
qemu
507563e85db880ff875f0a9498a1cf58a50cfad3
0
static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc, int rd, int rs, int rt) { const char *opn = "arith"; TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL); TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL); if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB && opc != OPC_DADD && opc != OPC_DSUB) { /* If no destination, treat it as a NOP. For add & sub, we must generate the overflow exception when needed. */ MIPS_DEBUG("NOP"); goto out; } gen_load_gpr(t0, rs); /* Specialcase the conventional move operation. */ if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU || opc == OPC_SUBU || opc == OPC_DSUBU)) { gen_store_gpr(t0, rd); goto out; } gen_load_gpr(t1, rt); switch (opc) { case OPC_ADD: { TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL); TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL); int l1 = gen_new_label(); save_cpu_state(ctx, 1); tcg_gen_ext32s_tl(r_tmp1, t0); tcg_gen_ext32s_tl(r_tmp2, t1); tcg_gen_add_tl(t0, r_tmp1, r_tmp2); tcg_gen_xor_tl(r_tmp1, r_tmp1, t1); tcg_gen_xori_tl(r_tmp1, r_tmp1, -1); tcg_gen_xor_tl(r_tmp2, t0, t1); tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2); tcg_temp_free(r_tmp2); tcg_gen_shri_tl(r_tmp1, r_tmp1, 31); tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1); tcg_temp_free(r_tmp1); /* operands of same sign, result different sign */ generate_exception(ctx, EXCP_OVERFLOW); gen_set_label(l1); tcg_gen_ext32s_tl(t0, t0); } opn = "add"; break; case OPC_ADDU: tcg_gen_ext32s_tl(t0, t0); tcg_gen_ext32s_tl(t1, t1); tcg_gen_add_tl(t0, t0, t1); tcg_gen_ext32s_tl(t0, t0); opn = "addu"; break; case OPC_SUB: { TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL); TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL); int l1 = gen_new_label(); save_cpu_state(ctx, 1); tcg_gen_ext32s_tl(r_tmp1, t0); tcg_gen_ext32s_tl(r_tmp2, t1); tcg_gen_sub_tl(t0, r_tmp1, r_tmp2); tcg_gen_xor_tl(r_tmp2, r_tmp1, t1); tcg_gen_xor_tl(r_tmp1, r_tmp1, t0); tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2); tcg_temp_free(r_tmp2); tcg_gen_shri_tl(r_tmp1, r_tmp1, 31); tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1); tcg_temp_free(r_tmp1); /* operands of different sign, first operand and result different sign */ generate_exception(ctx, EXCP_OVERFLOW); gen_set_label(l1); tcg_gen_ext32s_tl(t0, t0); } opn = "sub"; break; case OPC_SUBU: tcg_gen_ext32s_tl(t0, t0); tcg_gen_ext32s_tl(t1, t1); tcg_gen_sub_tl(t0, t0, t1); tcg_gen_ext32s_tl(t0, t0); opn = "subu"; break; #if defined(TARGET_MIPS64) case OPC_DADD: { TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL); TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL); int l1 = gen_new_label(); save_cpu_state(ctx, 1); tcg_gen_mov_tl(r_tmp1, t0); tcg_gen_add_tl(t0, t0, t1); tcg_gen_xor_tl(r_tmp1, r_tmp1, t1); tcg_gen_xori_tl(r_tmp1, r_tmp1, -1); tcg_gen_xor_tl(r_tmp2, t0, t1); tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2); tcg_temp_free(r_tmp2); tcg_gen_shri_tl(r_tmp1, r_tmp1, 63); tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1); tcg_temp_free(r_tmp1); /* operands of same sign, result different sign */ generate_exception(ctx, EXCP_OVERFLOW); gen_set_label(l1); } opn = "dadd"; break; case OPC_DADDU: tcg_gen_add_tl(t0, t0, t1); opn = "daddu"; break; case OPC_DSUB: { TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL); TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL); int l1 = gen_new_label(); save_cpu_state(ctx, 1); tcg_gen_mov_tl(r_tmp1, t0); tcg_gen_sub_tl(t0, t0, t1); tcg_gen_xor_tl(r_tmp2, r_tmp1, t1); tcg_gen_xor_tl(r_tmp1, r_tmp1, t0); tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2); tcg_temp_free(r_tmp2); tcg_gen_shri_tl(r_tmp1, r_tmp1, 63); tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1); tcg_temp_free(r_tmp1); /* operands of different sign, first operand and result different sign */ generate_exception(ctx, EXCP_OVERFLOW); gen_set_label(l1); } opn = "dsub"; break; case OPC_DSUBU: tcg_gen_sub_tl(t0, t0, t1); opn = "dsubu"; break; #endif case OPC_SLT: gen_op_lt(t0, t1); opn = "slt"; break; case OPC_SLTU: gen_op_ltu(t0, t1); opn = "sltu"; break; case OPC_AND: tcg_gen_and_tl(t0, t0, t1); opn = "and"; break; case OPC_NOR: tcg_gen_or_tl(t0, t0, t1); tcg_gen_not_tl(t0, t0); opn = "nor"; break; case OPC_OR: tcg_gen_or_tl(t0, t0, t1); opn = "or"; break; case OPC_XOR: tcg_gen_xor_tl(t0, t0, t1); opn = "xor"; break; case OPC_MUL: tcg_gen_ext32s_tl(t0, t0); tcg_gen_ext32s_tl(t1, t1); tcg_gen_mul_tl(t0, t0, t1); tcg_gen_ext32s_tl(t0, t0); opn = "mul"; break; case OPC_MOVN: { int l1 = gen_new_label(); tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); gen_store_gpr(t0, rd); gen_set_label(l1); } opn = "movn"; goto print; case OPC_MOVZ: { int l1 = gen_new_label(); tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1); gen_store_gpr(t0, rd); gen_set_label(l1); } opn = "movz"; goto print; case OPC_SLLV: tcg_gen_ext32u_tl(t0, t0); tcg_gen_ext32u_tl(t1, t1); tcg_gen_andi_tl(t0, t0, 0x1f); tcg_gen_shl_tl(t0, t1, t0); tcg_gen_ext32s_tl(t0, t0); opn = "sllv"; break; case OPC_SRAV: tcg_gen_ext32s_tl(t1, t1); tcg_gen_andi_tl(t0, t0, 0x1f); tcg_gen_sar_tl(t0, t1, t0); tcg_gen_ext32s_tl(t0, t0); opn = "srav"; break; case OPC_SRLV: switch ((ctx->opcode >> 6) & 0x1f) { case 0: tcg_gen_ext32u_tl(t1, t1); tcg_gen_andi_tl(t0, t0, 0x1f); tcg_gen_shr_tl(t0, t1, t0); tcg_gen_ext32s_tl(t0, t0); opn = "srlv"; break; case 1: /* rotrv is decoded as srlv on non-R2 CPUs */ if (env->insn_flags & ISA_MIPS32R2) { int l1 = gen_new_label(); int l2 = gen_new_label(); tcg_gen_andi_tl(t0, t0, 0x1f); tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); { TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32); TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32); tcg_gen_trunc_tl_i32(r_tmp1, t0); tcg_gen_trunc_tl_i32(r_tmp2, t1); tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2); tcg_temp_free(r_tmp1); tcg_temp_free(r_tmp2); tcg_gen_br(l2); } gen_set_label(l1); tcg_gen_mov_tl(t0, t1); gen_set_label(l2); opn = "rotrv"; } else { tcg_gen_ext32u_tl(t1, t1); tcg_gen_andi_tl(t0, t0, 0x1f); tcg_gen_shr_tl(t0, t1, t0); tcg_gen_ext32s_tl(t0, t0); opn = "srlv"; } break; default: MIPS_INVAL("invalid srlv flag"); generate_exception(ctx, EXCP_RI); break; } break; #if defined(TARGET_MIPS64) case OPC_DSLLV: tcg_gen_andi_tl(t0, t0, 0x3f); tcg_gen_shl_tl(t0, t1, t0); opn = "dsllv"; break; case OPC_DSRAV: tcg_gen_andi_tl(t0, t0, 0x3f); tcg_gen_sar_tl(t0, t1, t0); opn = "dsrav"; break; case OPC_DSRLV: switch ((ctx->opcode >> 6) & 0x1f) { case 0: tcg_gen_andi_tl(t0, t0, 0x3f); tcg_gen_shr_tl(t0, t1, t0); opn = "dsrlv"; break; case 1: /* drotrv is decoded as dsrlv on non-R2 CPUs */ if (env->insn_flags & ISA_MIPS32R2) { int l1 = gen_new_label(); int l2 = gen_new_label(); tcg_gen_andi_tl(t0, t0, 0x3f); tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); { tcg_gen_rotr_tl(t0, t1, t0); tcg_gen_br(l2); } gen_set_label(l1); tcg_gen_mov_tl(t0, t1); gen_set_label(l2); opn = "drotrv"; } else { tcg_gen_andi_tl(t0, t0, 0x3f); tcg_gen_shr_tl(t0, t1, t0); opn = "dsrlv"; } break; default: MIPS_INVAL("invalid dsrlv flag"); generate_exception(ctx, EXCP_RI); break; } break; #endif default: MIPS_INVAL(opn); generate_exception(ctx, EXCP_RI); goto out; } gen_store_gpr(t0, rd); print: MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]); out: tcg_temp_free(t0); tcg_temp_free(t1); }
10,540
qemu
494a8ebe713055d3946183f4b395f85a18b43e9e
0
static int proxy_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, int flags, FsCred *credp, V9fsFidOpenState *fs) { V9fsString fullname; v9fs_string_init(&fullname); v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); fs->fd = v9fs_request(fs_ctx->private, T_CREATE, NULL, "sdddd", &fullname, flags, credp->fc_mode, credp->fc_uid, credp->fc_gid); v9fs_string_free(&fullname); if (fs->fd < 0) { errno = -fs->fd; fs->fd = -1; } return fs->fd; }
10,541
qemu
b61359781958759317ee6fd1a45b59be0b7dbbe1
0
void memory_region_add_subregion_overlap(MemoryRegion *mr, hwaddr offset, MemoryRegion *subregion, int priority) { subregion->may_overlap = true; subregion->priority = priority; memory_region_add_subregion_common(mr, offset, subregion); }
10,542
qemu
0eb28a42284ec32e6f283985d2d638474a05eba4
0
void hd_geometry_guess(BlockBackend *blk, uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, int *ptrans) { int cylinders, heads, secs, translation; if (guess_disk_lchs(blk, &cylinders, &heads, &secs) < 0) { /* no LCHS guess: use a standard physical disk geometry */ guess_chs_for_size(blk, pcyls, pheads, psecs); translation = hd_bios_chs_auto_trans(*pcyls, *pheads, *psecs); } else if (heads > 16) { /* LCHS guess with heads > 16 means that a BIOS LBA translation was active, so a standard physical disk geometry is OK */ guess_chs_for_size(blk, pcyls, pheads, psecs); translation = *pcyls * *pheads <= 131072 ? BIOS_ATA_TRANSLATION_LARGE : BIOS_ATA_TRANSLATION_LBA; } else { /* LCHS guess with heads <= 16: use as physical geometry */ *pcyls = cylinders; *pheads = heads; *psecs = secs; /* disable any translation to be in sync with the logical geometry */ translation = BIOS_ATA_TRANSLATION_NONE; } if (ptrans) { *ptrans = translation; } trace_hd_geometry_guess(blk, *pcyls, *pheads, *psecs, translation); }
10,543
qemu
62112d181ca33fea976100c4335dfc3e2f727e6c
0
int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan) { const char *sock; const char *group; int port, mode; sock = qemu_opt_get(opts, "sock"); group = qemu_opt_get(opts, "group"); port = qemu_opt_get_number(opts, "port", 0); mode = qemu_opt_get_number(opts, "mode", 0700); if (net_vde_init(vlan, "vde", name, sock, port, group, mode) == -1) { return -1; } if (vlan) { vlan->nb_host_devs++; } return 0; }
10,544
FFmpeg
a38469e1da7b4829a2fba4279d8420a33f96832e
0
int read_ffserver_streams(AVFormatContext *s, const char *filename) { int i; AVFormatContext *ic; ic = av_open_input_file(filename, FFM_PACKET_SIZE); if (!ic) return -EIO; /* copy stream format */ s->nb_streams = ic->nb_streams; for(i=0;i<ic->nb_streams;i++) { AVStream *st; st = av_mallocz(sizeof(AVFormatContext)); memcpy(st, ic->streams[i], sizeof(AVStream)); s->streams[i] = st; } av_close_input_file(ic); return 0; }
10,545
FFmpeg
27c7ca9c12bb42d5c44d46f24cd970469d0ef55a
0
void ff_restore_parser_state(AVFormatContext *s, AVParserState *state) { int i; AVStream *st; AVParserStreamState *ss; ff_read_frame_flush(s); if (!state) return; avio_seek(s->pb, state->fpos, SEEK_SET); // copy context structures s->cur_st = state->cur_st; s->packet_buffer = state->packet_buffer; s->raw_packet_buffer = state->raw_packet_buffer; s->raw_packet_buffer_remaining_size = state->raw_packet_buffer_remaining_size; // copy stream structures for (i = 0; i < state->nb_streams; i++) { st = s->streams[i]; ss = &state->stream_states[i]; st->parser = ss->parser; st->last_IP_pts = ss->last_IP_pts; st->cur_dts = ss->cur_dts; st->reference_dts = ss->reference_dts; st->cur_ptr = ss->cur_ptr; st->cur_len = ss->cur_len; st->probe_packets = ss->probe_packets; st->cur_pkt = ss->cur_pkt; } av_free(state->stream_states); av_free(state); }
10,546
FFmpeg
e9e87822022fc81f92866f870ecedfd2f6272ac9
0
int ff_img_read_header(AVFormatContext *s1) { VideoDemuxData *s = s1->priv_data; int first_index = 1, last_index = 1; AVStream *st; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; s1->ctx_flags |= AVFMTCTX_NOHEADER; st = avformat_new_stream(s1, NULL); if (!st) { return AVERROR(ENOMEM); } if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) { av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); return AVERROR(EINVAL); } av_strlcpy(s->path, s1->filename, sizeof(s->path)); s->img_number = 0; s->img_count = 0; /* find format */ if (s1->iformat->flags & AVFMT_NOFILE) s->is_pipe = 0; else { s->is_pipe = 1; st->need_parsing = AVSTREAM_PARSE_FULL; } if (s->ts_from_file == 2) { #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n"); return AVERROR(ENOSYS); #endif avpriv_set_pts_info(st, 64, 1, 1000000000); } else if (s->ts_from_file) avpriv_set_pts_info(st, 64, 1, 1); else avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); if (s->width && s->height) { st->codec->width = s->width; st->codec->height = s->height; } if (!s->is_pipe) { if (s->pattern_type == PT_GLOB_SEQUENCE) { s->use_glob = is_glob(s->path); if (s->use_glob) { #if HAVE_GLOB char *p = s->path, *q, *dup; int gerr; #endif av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: " "use pattern_type 'glob' instead\n"); #if HAVE_GLOB dup = q = av_strdup(p); while (*q) { /* Do we have room for the next char and a \ insertion? */ if ((p - s->path) >= (sizeof(s->path) - 2)) break; if (*q == '%' && strspn(q + 1, "%*?[]{}")) ++q; else if (strspn(q, "\\*?[]{}")) *p++ = '\\'; *p++ = *q++; } *p = 0; av_free(dup); gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate); if (gerr != 0) { return AVERROR(ENOENT); } first_index = 0; last_index = s->globstate.gl_pathc - 1; #endif } } if ((s->pattern_type == PT_GLOB_SEQUENCE && !s->use_glob) || s->pattern_type == PT_SEQUENCE) { if (find_image_range(&first_index, &last_index, s->path, s->start_number, s->start_number_range) < 0) { av_log(s1, AV_LOG_ERROR, "Could find no file with path '%s' and index in the range %d-%d\n", s->path, s->start_number, s->start_number + s->start_number_range - 1); return AVERROR(ENOENT); } } else if (s->pattern_type == PT_GLOB) { #if HAVE_GLOB int gerr; gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate); if (gerr != 0) { return AVERROR(ENOENT); } first_index = 0; last_index = s->globstate.gl_pathc - 1; s->use_glob = 1; #else av_log(s1, AV_LOG_ERROR, "Pattern type 'glob' was selected but globbing " "is not supported by this libavformat build\n"); return AVERROR(ENOSYS); #endif } else if (s->pattern_type != PT_GLOB_SEQUENCE && s->pattern_type != PT_NONE) { av_log(s1, AV_LOG_ERROR, "Unknown value '%d' for pattern_type option\n", s->pattern_type); return AVERROR(EINVAL); } s->img_first = first_index; s->img_last = last_index; s->img_number = first_index; /* compute duration */ if (!s->ts_from_file) { st->start_time = 0; st->duration = last_index - first_index + 1; } } if (s1->video_codec_id) { st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = s1->video_codec_id; } else if (s1->audio_codec_id) { st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = s1->audio_codec_id; } else if (s1->iformat->raw_codec_id) { st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = s1->iformat->raw_codec_id; } else { const char *str = strrchr(s->path, '.'); s->split_planes = str && !av_strcasecmp(str + 1, "y"); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; if (s1->pb) { int probe_buffer_size = 2048; uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE); AVInputFormat *fmt = NULL; AVProbeData pd = { 0 }; if (!probe_buffer) return AVERROR(ENOMEM); probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size); if (probe_buffer_size < 0) { av_free(probe_buffer); return probe_buffer_size; } memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE); pd.buf = probe_buffer; pd.buf_size = probe_buffer_size; pd.filename = s1->filename; while ((fmt = av_iformat_next(fmt))) { if (fmt->read_header != ff_img_read_header || !fmt->read_probe || (fmt->flags & AVFMT_NOFILE) || !fmt->raw_codec_id) continue; if (fmt->read_probe(&pd) > 0) { st->codec->codec_id = fmt->raw_codec_id; break; } } if (s1->flags & AVFMT_FLAG_CUSTOM_IO) { avio_seek(s1->pb, 0, SEEK_SET); } else ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size); } if (st->codec->codec_id == AV_CODEC_ID_NONE) st->codec->codec_id = ff_guess_image2_codec(s->path); if (st->codec->codec_id == AV_CODEC_ID_LJPEG) st->codec->codec_id = AV_CODEC_ID_MJPEG; if (st->codec->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX st->codec->codec_id = AV_CODEC_ID_NONE; } if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != AV_PIX_FMT_NONE) st->codec->pix_fmt = pix_fmt; return 0; }
10,548
FFmpeg
0d632b35a04f4a54e7cd228c85cbad82549182ec
0
static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorrelate, int alpha) { int i; OPEN_READER(re, &s->gb); for (i = 0; i < count; i++) { unsigned int index; int code, n; UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); code = s->vlc[4].table[index][0]; n = s->vlc[4].table[index][1]; if (code != -1) { *(uint32_t*)&s->temp[0][4 * i] = s->pix_bgr_map[code]; LAST_SKIP_BITS(re, &s->gb, n); } else { int nb_bits; if(decorrelate) { VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); VLC_INTERN(code, s->vlc[0].table, &s->gb, re, VLC_BITS, 3); s->temp[0][4 * i + B] = code + s->temp[0][4 * i + G]; UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); VLC_INTERN(code, s->vlc[2].table, &s->gb, re, VLC_BITS, 3); s->temp[0][4 * i + R] = code + s->temp[0][4 * i + G]; } else { VLC_INTERN(s->temp[0][4 * i + B], s->vlc[0].table, &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); VLC_INTERN(s->temp[0][4 * i + R], s->vlc[2].table, &s->gb, re, VLC_BITS, 3); } if (alpha) { UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); VLC_INTERN(s->temp[0][4 * i + A], s->vlc[2].table, &s->gb, re, VLC_BITS, 3); } } } CLOSE_READER(re, &s->gb); }
10,549
FFmpeg
d31dbec3742e488156621b9ca21069f8c05aabf0
0
static int dnxhd_init_rc(DNXHDEncContext *ctx) { CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry)); if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry)); ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; ctx->qscale = 1; ctx->lambda = 2<<LAMBDA_FRAC_BITS; // qscale 2 return 0; fail: return -1; }
10,550
FFmpeg
68f593b48433842f3407586679fe07f3e5199ab9
0
static int mpeg1_decode_picture(AVCodecContext *avctx, UINT8 *buf, int buf_size) { Mpeg1Context *s1 = avctx->priv_data; MpegEncContext *s = &s1->mpeg_enc_ctx; int ref, f_code; init_get_bits(&s->gb, buf, buf_size); ref = get_bits(&s->gb, 10); /* temporal ref */ s->pict_type = get_bits(&s->gb, 3); dprintf("pict_type=%d number=%d\n", s->pict_type, s->picture_number); skip_bits(&s->gb, 16); if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { s->full_pel[0] = get_bits1(&s->gb); f_code = get_bits(&s->gb, 3); if (f_code == 0) return -1; s->mpeg_f_code[0][0] = f_code; s->mpeg_f_code[0][1] = f_code; } if (s->pict_type == B_TYPE) { s->full_pel[1] = get_bits1(&s->gb); f_code = get_bits(&s->gb, 3); if (f_code == 0) return -1; s->mpeg_f_code[1][0] = f_code; s->mpeg_f_code[1][1] = f_code; } s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == I_TYPE; s->y_dc_scale = 8; s->c_dc_scale = 8; s->first_slice = 1; return 0; }
10,551
FFmpeg
bb463d81020a2f3c5cf3403e18f980171773f48a
0
static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ ParseContext *pc= &s->parse_context; int i; uint32_t state; state= pc->state; i=0; if(!pc->frame_start_found){ for(i=0; i<buf_size; i++){ state= (state<<8) | buf[i]; if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ i++; pc->frame_start_found=1; break; } } } if(pc->frame_start_found){ for(; i<buf_size; i++){ state= (state<<8) | buf[i]; if((state&0xFFFFFF00) == 0x100){ if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ pc->frame_start_found=0; pc->state=-1; return i-3; } } } } pc->state= state; return -1; }
10,552
FFmpeg
ab61b79b1c707a9ea0512238d837ea3e8b8395ed
0
static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int i; int64_t creation_time; int version = avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ if (version == 1) { creation_time = avio_rb64(pb); avio_rb64(pb); } else { creation_time = avio_rb32(pb); avio_rb32(pb); /* modification time */ } mov_metadata_creation_time(&c->fc->metadata, creation_time); c->time_scale = avio_rb32(pb); /* time scale */ if (c->time_scale <= 0) { av_log(c->fc, AV_LOG_ERROR, "Invalid mvhd time scale %d\n", c->time_scale); return AVERROR_INVALIDDATA; } av_log(c->fc, AV_LOG_TRACE, "time scale = %i\n", c->time_scale); c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */ // set the AVCodecContext duration because the duration of individual tracks // may be inaccurate if (c->time_scale > 0 && !c->trex_data) c->fc->duration = av_rescale(c->duration, AV_TIME_BASE, c->time_scale); avio_rb32(pb); /* preferred scale */ avio_rb16(pb); /* preferred volume */ avio_skip(pb, 10); /* reserved */ /* movie display matrix, store it in main context and use it later on */ for (i = 0; i < 3; i++) { c->movie_display_matrix[i][0] = avio_rb32(pb); // 16.16 fixed point c->movie_display_matrix[i][1] = avio_rb32(pb); // 16.16 fixed point c->movie_display_matrix[i][2] = avio_rb32(pb); // 2.30 fixed point } avio_rb32(pb); /* preview time */ avio_rb32(pb); /* preview duration */ avio_rb32(pb); /* poster time */ avio_rb32(pb); /* selection time */ avio_rb32(pb); /* selection duration */ avio_rb32(pb); /* current time */ avio_rb32(pb); /* next track ID */ return 0; }
10,553
FFmpeg
914ab4cd1c59eae10771f2d6a892ec6b6f36b0e2
0
static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, Jpeg2000ResLevel *rlevel, int precno, int layno, uint8_t *expn, int numgbits) { int bandno, cblkny, cblknx, cblkno, ret; if (!(ret = get_bits(s, 1))){ j2k_flush(s); return 0; } else if (ret < 0) return ret; for (bandno = 0; bandno < rlevel->nbands; bandno++){ Jpeg2000Band *band = rlevel->band + bandno; Jpeg2000Prec *prec = band->prec + precno; int pos = 0; if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1]) continue; for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++) for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){ Jpeg2000Cblk *cblk = band->cblk + cblkno; int incl, newpasses, llen; if (cblk->npasses) incl = get_bits(s, 1); else incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno; if (!incl) continue; else if (incl < 0) return incl; if (!cblk->npasses) cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100); if ((newpasses = getnpasses(s)) < 0) return newpasses; if ((llen = getlblockinc(s)) < 0) return llen; cblk->lblock += llen; if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0) return ret; cblk->lengthinc = ret; cblk->npasses += newpasses; } } j2k_flush(s); if (codsty->csty & JPEG2000_CSTY_EPH) { if (bytestream2_peek_be16(&s->g) == JPEG2000_EPH) { bytestream2_skip(&s->g, 2); } else { av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n"); } } for (bandno = 0; bandno < rlevel->nbands; bandno++){ Jpeg2000Band *band = rlevel->band + bandno; int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0; for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){ int xi; for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){ Jpeg2000Cblk *cblk = band->cblk + yi * cblknw + xi; if (bytestream2_get_bytes_left(&s->g) < cblk->lengthinc) return AVERROR(EINVAL); bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc); cblk->length += cblk->lengthinc; cblk->lengthinc = 0; } } } return 0; }
10,555
FFmpeg
72dbc610be3272ba36603f78a39cc2d2d8fe0cc3
0
static void avc_luma_vt_and_aver_dst_8x8_msa(const uint8_t *src, int32_t src_stride, uint8_t *dst, int32_t dst_stride) { int32_t loop_cnt; int16_t filt_const0 = 0xfb01; int16_t filt_const1 = 0x1414; int16_t filt_const2 = 0x1fb; v16u8 dst0, dst1, dst2, dst3; v16i8 src0, src1, src2, src3, src4, src7, src8, src9, src10; v16i8 src10_r, src32_r, src76_r, src98_r; v16i8 src21_r, src43_r, src87_r, src109_r; v8i16 out0, out1, out2, out3; v16i8 filt0, filt1, filt2; filt0 = (v16i8) __msa_fill_h(filt_const0); filt1 = (v16i8) __msa_fill_h(filt_const1); filt2 = (v16i8) __msa_fill_h(filt_const2); LD_SB5(src, src_stride, src0, src1, src2, src3, src4); src += (5 * src_stride); XORI_B5_128_SB(src0, src1, src2, src3, src4); ILVR_B4_SB(src1, src0, src2, src1, src3, src2, src4, src3, src10_r, src21_r, src32_r, src43_r); for (loop_cnt = 2; loop_cnt--;) { LD_SB4(src, src_stride, src7, src8, src9, src10); src += (4 * src_stride); XORI_B4_128_SB(src7, src8, src9, src10); ILVR_B4_SB(src7, src4, src8, src7, src9, src8, src10, src9, src76_r, src87_r, src98_r, src109_r); out0 = DPADD_SH3_SH(src10_r, src32_r, src76_r, filt0, filt1, filt2); out1 = DPADD_SH3_SH(src21_r, src43_r, src87_r, filt0, filt1, filt2); out2 = DPADD_SH3_SH(src32_r, src76_r, src98_r, filt0, filt1, filt2); out3 = DPADD_SH3_SH(src43_r, src87_r, src109_r, filt0, filt1, filt2); SRARI_H4_SH(out0, out1, out2, out3, 5); SAT_SH4_SH(out0, out1, out2, out3, 7); LD_UB4(dst, dst_stride, dst0, dst1, dst2, dst3); ILVR_D2_UB(dst1, dst0, dst3, dst2, dst0, dst1); CONVERT_UB_AVG_ST8x4_UB(out0, out1, out2, out3, dst0, dst1, dst, dst_stride); dst += (4 * dst_stride); src10_r = src76_r; src32_r = src98_r; src21_r = src87_r; src43_r = src109_r; src4 = src10; } }
10,557
FFmpeg
50a28b13936be3e62254d5a73ab2ca6ffb001bcf
0
int main (int argc, char **argv) { int ret = 0, got_frame; if (argc != 4 && argc != 5) { fprintf(stderr, "usage: %s [-refcount=<old|new_norefcount|new_refcount>] " "input_file video_output_file audio_output_file\n" "API example program to show how to read frames from an input file.\n" "This program reads frames from a file, decodes them, and writes decoded\n" "video frames to a rawvideo file named video_output_file, and decoded\n" "audio frames to a rawaudio file named audio_output_file.\n\n" "If the -refcount option is specified, the program use the\n" "reference counting frame system which allows keeping a copy of\n" "the data for longer than one decode call. If unset, it's using\n" "the classic old method.\n" "\n", argv[0]); exit(1); } if (argc == 5) { const char *mode = argv[1] + strlen("-refcount="); if (!strcmp(mode, "old")) api_mode = API_MODE_OLD; else if (!strcmp(mode, "new_norefcount")) api_mode = API_MODE_NEW_API_NO_REF_COUNT; else if (!strcmp(mode, "new_refcount")) api_mode = API_MODE_NEW_API_REF_COUNT; else { fprintf(stderr, "unknow mode '%s'\n", mode); exit(1); } argv++; } src_filename = argv[1]; video_dst_filename = argv[2]; audio_dst_filename = argv[3]; /* register all formats and codecs */ av_register_all(); /* open input file, and allocate format context */ if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) { fprintf(stderr, "Could not open source file %s\n", src_filename); exit(1); } /* retrieve stream information */ if (avformat_find_stream_info(fmt_ctx, NULL) < 0) { fprintf(stderr, "Could not find stream information\n"); exit(1); } if (open_codec_context(&video_stream_idx, fmt_ctx, AVMEDIA_TYPE_VIDEO) >= 0) { video_stream = fmt_ctx->streams[video_stream_idx]; video_dec_ctx = video_stream->codec; video_dst_file = fopen(video_dst_filename, "wb"); if (!video_dst_file) { fprintf(stderr, "Could not open destination file %s\n", video_dst_filename); ret = 1; goto end; } /* allocate image where the decoded image will be put */ ret = av_image_alloc(video_dst_data, video_dst_linesize, video_dec_ctx->width, video_dec_ctx->height, video_dec_ctx->pix_fmt, 1); if (ret < 0) { fprintf(stderr, "Could not allocate raw video buffer\n"); goto end; } video_dst_bufsize = ret; } if (open_codec_context(&audio_stream_idx, fmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0) { audio_stream = fmt_ctx->streams[audio_stream_idx]; audio_dec_ctx = audio_stream->codec; audio_dst_file = fopen(audio_dst_filename, "wb"); if (!audio_dst_file) { fprintf(stderr, "Could not open destination file %s\n", video_dst_filename); ret = 1; goto end; } } /* dump input information to stderr */ av_dump_format(fmt_ctx, 0, src_filename, 0); if (!audio_stream && !video_stream) { fprintf(stderr, "Could not find audio or video stream in the input, aborting\n"); ret = 1; goto end; } /* When using the new API, you need to use the libavutil/frame.h API, while * the classic frame management is available in libavcodec */ if (api_mode == API_MODE_OLD) frame = avcodec_alloc_frame(); else frame = av_frame_alloc(); if (!frame) { fprintf(stderr, "Could not allocate frame\n"); ret = AVERROR(ENOMEM); goto end; } /* initialize packet, set data to NULL, let the demuxer fill it */ av_init_packet(&pkt); pkt.data = NULL; pkt.size = 0; if (video_stream) printf("Demuxing video from file '%s' into '%s'\n", src_filename, video_dst_filename); if (audio_stream) printf("Demuxing audio from file '%s' into '%s'\n", src_filename, audio_dst_filename); /* read frames from the file */ while (av_read_frame(fmt_ctx, &pkt) >= 0) { AVPacket orig_pkt = pkt; do { ret = decode_packet(&got_frame, 0); if (ret < 0) break; pkt.data += ret; pkt.size -= ret; } while (pkt.size > 0); av_free_packet(&orig_pkt); } /* flush cached frames */ pkt.data = NULL; pkt.size = 0; do { decode_packet(&got_frame, 1); } while (got_frame); printf("Demuxing succeeded.\n"); if (video_stream) { printf("Play the output video file with the command:\n" "ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n", av_get_pix_fmt_name(video_dec_ctx->pix_fmt), video_dec_ctx->width, video_dec_ctx->height, video_dst_filename); } if (audio_stream) { enum AVSampleFormat sfmt = audio_dec_ctx->sample_fmt; int n_channels = audio_dec_ctx->channels; const char *fmt; if (av_sample_fmt_is_planar(sfmt)) { const char *packed = av_get_sample_fmt_name(sfmt); printf("Warning: the sample format the decoder produced is planar " "(%s). This example will output the first channel only.\n", packed ? packed : "?"); sfmt = av_get_packed_sample_fmt(sfmt); n_channels = 1; } if ((ret = get_format_from_sample_fmt(&fmt, sfmt)) < 0) goto end; printf("Play the output audio file with the command:\n" "ffplay -f %s -ac %d -ar %d %s\n", fmt, n_channels, audio_dec_ctx->sample_rate, audio_dst_filename); } end: if (video_dec_ctx) avcodec_close(video_dec_ctx); if (audio_dec_ctx) avcodec_close(audio_dec_ctx); avformat_close_input(&fmt_ctx); if (video_dst_file) fclose(video_dst_file); if (audio_dst_file) fclose(audio_dst_file); if (api_mode == API_MODE_OLD) avcodec_free_frame(&frame); else av_frame_free(&frame); av_free(video_dst_data[0]); return ret < 0; }
10,558
FFmpeg
b1ade3d1821a29174963b28cd0caa5f7ed394998
0
void ff_celp_lp_synthesis_filterf(float *out, const float* filter_coeffs, const float* in, int buffer_length, int filter_length) { int i,n; // Avoids a +1 in the inner loop. filter_length++; for (n = 0; n < buffer_length; n++) { out[n] = in[n]; for (i = 1; i < filter_length; i++) out[n] -= filter_coeffs[i-1] * out[n-i]; } }
10,559
FFmpeg
83548fe894cdb455cc127f754d09905b6d23c173
0
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { BinkDemuxContext *bink = s->priv_data; AVStream *vst = s->streams[0]; if (!s->pb->seekable) return -1; /* seek to the first frame */ if (avio_seek(s->pb, vst->index_entries[0].pos, SEEK_SET) < 0) return -1; bink->video_pts = 0; memset(bink->audio_pts, 0, sizeof(bink->audio_pts)); bink->current_track = -1; return 0; }
10,560
FFmpeg
adb4328917f8b4e0ea9462615ca9e9b5baa7334d
0
static int dvvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, UINT8 *buf, int buf_size) { DVVideoDecodeContext *s = avctx->priv_data; int sct, dsf, apt, ds, nb_dif_segs, vs, width, height, i, packet_size; unsigned size; UINT8 *buf_ptr; const UINT16 *mb_pos_ptr; AVPicture *picture; /* parse id */ init_get_bits(&s->gb, buf, buf_size); sct = get_bits(&s->gb, 3); if (sct != 0) return -1; skip_bits(&s->gb, 5); get_bits(&s->gb, 4); /* dsn (sequence number */ get_bits(&s->gb, 1); /* fsc (channel number) */ skip_bits(&s->gb, 3); get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */ dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */ if (get_bits(&s->gb, 1) != 0) return -1; skip_bits(&s->gb, 11); apt = get_bits(&s->gb, 3); /* apt */ get_bits(&s->gb, 1); /* tf1 */ skip_bits(&s->gb, 4); get_bits(&s->gb, 3); /* ap1 */ get_bits(&s->gb, 1); /* tf2 */ skip_bits(&s->gb, 4); get_bits(&s->gb, 3); /* ap2 */ get_bits(&s->gb, 1); /* tf3 */ skip_bits(&s->gb, 4); get_bits(&s->gb, 3); /* ap3 */ /* init size */ width = 720; if (dsf) { avctx->frame_rate = 25 * FRAME_RATE_BASE; packet_size = PAL_FRAME_SIZE; height = 576; nb_dif_segs = 12; } else { avctx->frame_rate = 30 * FRAME_RATE_BASE; packet_size = NTSC_FRAME_SIZE; height = 480; nb_dif_segs = 10; } /* NOTE: we only accept several full frames */ if (buf_size < packet_size) return -1; /* XXX: is it correct to assume that 420 is always used in PAL mode ? */ s->sampling_411 = !dsf; if (s->sampling_411) { mb_pos_ptr = dv_place_411; avctx->pix_fmt = PIX_FMT_YUV411P; } else { mb_pos_ptr = dv_place_420; avctx->pix_fmt = PIX_FMT_YUV420P; } avctx->width = width; avctx->height = height; if (avctx->flags & CODEC_FLAG_DR1 && avctx->get_buffer_callback) { s->width = -1; avctx->dr_buffer[0] = avctx->dr_buffer[1] = avctx->dr_buffer[2] = 0; if(avctx->get_buffer_callback(avctx, width, height, I_TYPE) < 0){ fprintf(stderr, "get_buffer() failed\n"); return -1; } } /* (re)alloc picture if needed */ if (s->width != width || s->height != height) { if (!(avctx->flags & CODEC_FLAG_DR1)) for(i=0;i<3;i++) { if (avctx->dr_buffer[i] != s->current_picture[i]) av_freep(&s->current_picture[i]); avctx->dr_buffer[i] = 0; } for(i=0;i<3;i++) { if (avctx->dr_buffer[i]) { s->current_picture[i] = avctx->dr_buffer[i]; s->linesize[i] = (i == 0) ? avctx->dr_stride : avctx->dr_uvstride; } else { size = width * height; s->linesize[i] = width; if (i >= 1) { size >>= 2; s->linesize[i] >>= s->sampling_411 ? 2 : 1; } s->current_picture[i] = av_malloc(size); } if (!s->current_picture[i]) return -1; } s->width = width; s->height = height; } /* for each DIF segment */ buf_ptr = buf; for (ds = 0; ds < nb_dif_segs; ds++) { buf_ptr += 6 * 80; /* skip DIF segment header */ for(vs = 0; vs < 27; vs++) { if ((vs % 3) == 0) { /* skip audio block */ buf_ptr += 80; } dv_decode_video_segment(s, buf_ptr, mb_pos_ptr); buf_ptr += 5 * 80; mb_pos_ptr += 5; } } emms_c(); /* return image */ *data_size = sizeof(AVPicture); picture = data; for(i=0;i<3;i++) { picture->data[i] = s->current_picture[i]; picture->linesize[i] = s->linesize[i]; } return packet_size; }
10,561
FFmpeg
c04c3282b4334ff64cfd69d40fea010602e830fd
0
static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) { AudioData *s = s1->priv_data; AVStream *st; int ret; if (!ap || ap->sample_rate <= 0 || ap->channels <= 0) return -1; st = av_new_stream(s1, 0); if (!st) { return -ENOMEM; } s->sample_rate = ap->sample_rate; s->channels = ap->channels; ret = audio_open(s, 0, ap->device); if (ret < 0) { av_free(st); return AVERROR_IO; } /* take real parameters */ st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = s->codec_id; st->codec->sample_rate = s->sample_rate; st->codec->channels = s->channels; av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ return 0; }
10,562
FFmpeg
0ccabeeaef77e240f2a44f78271a8914a23e239b
0
char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms) { snprintf(buf, buf_size, "%s%s%s%s%s", perms & AV_PERM_READ ? "r" : "", perms & AV_PERM_WRITE ? "w" : "", perms & AV_PERM_PRESERVE ? "p" : "", perms & AV_PERM_REUSE ? "u" : "", perms & AV_PERM_REUSE2 ? "U" : ""); return buf; }
10,563
FFmpeg
c10350358da58600884292c08a8690289b81de29
0
static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h) { const int y_start = t * linesize; const uint32_t *src_px, *src_pr, *src_py = src + y_start, *dst_py = dst + y_start; const uint32_t *src_pb = src_py + t * linesize; uint32_t *dst_px; for (; src_py < src_pb; src_py += linesize, dst_py += linesize) { src_px = src_py + l; dst_px = (uint32_t *)dst_py + l; src_pr = src_px + w; for (; src_px < src_pr; src_px++, dst_px++) *dst_px = *src_px; } }
10,565
FFmpeg
bcaf64b605442e1622d16da89d4ec0e7730b8a8c
0
static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { AlacEncodeContext *s = avctx->priv_data; int out_bytes, max_frame_size, ret; s->frame_size = frame->nb_samples; if (frame->nb_samples < DEFAULT_FRAME_SIZE) max_frame_size = get_max_frame_size(s->frame_size, avctx->channels, avctx->bits_per_raw_sample); else max_frame_size = s->max_coded_frame_size; if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size))) return ret; /* use verbatim mode for compression_level 0 */ if (s->compression_level) { s->verbatim = 0; s->extra_bits = avctx->bits_per_raw_sample - 16; } else { s->verbatim = 1; s->extra_bits = 0; } out_bytes = write_frame(s, avpkt, frame->extended_data); if (out_bytes > max_frame_size) { /* frame too large. use verbatim mode */ s->verbatim = 1; s->extra_bits = 0; out_bytes = write_frame(s, avpkt, frame->extended_data); } avpkt->size = out_bytes; *got_packet_ptr = 1; return 0; }
10,566
qemu
552908fef5b67ad9d96b76d7cb8371ebc26c9bc8
0
static int bmdma_rw_buf(IDEDMA *dma, int is_write) { BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma); IDEState *s = bmdma_active_if(bm); struct { uint32_t addr; uint32_t size; } prd; int l, len; for(;;) { l = s->io_buffer_size - s->io_buffer_index; if (l <= 0) break; if (bm->cur_prd_len == 0) { /* end of table (with a fail safe of one page) */ if (bm->cur_prd_last || (bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE) return 0; cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8); bm->cur_addr += 8; prd.addr = le32_to_cpu(prd.addr); prd.size = le32_to_cpu(prd.size); len = prd.size & 0xfffe; if (len == 0) len = 0x10000; bm->cur_prd_len = len; bm->cur_prd_addr = prd.addr; bm->cur_prd_last = (prd.size & 0x80000000); } if (l > bm->cur_prd_len) l = bm->cur_prd_len; if (l > 0) { if (is_write) { cpu_physical_memory_write(bm->cur_prd_addr, s->io_buffer + s->io_buffer_index, l); } else { cpu_physical_memory_read(bm->cur_prd_addr, s->io_buffer + s->io_buffer_index, l); } bm->cur_prd_addr += l; bm->cur_prd_len -= l; s->io_buffer_index += l; } } return 1; }
10,567
qemu
b29a0341d7ed7e7df4bf77a41db8e614f1ddb645
0
static void gen_dmfc0 (DisasContext *ctx, int reg, int sel) { const char *rn = "invalid"; switch (reg) { case 0: switch (sel) { case 0: gen_op_mfc0_index(); rn = "Index"; break; case 1: // gen_op_dmfc0_mvpcontrol(); /* MT ASE */ rn = "MVPControl"; // break; case 2: // gen_op_dmfc0_mvpconf0(); /* MT ASE */ rn = "MVPConf0"; // break; case 3: // gen_op_dmfc0_mvpconf1(); /* MT ASE */ rn = "MVPConf1"; // break; default: goto die; } break; case 1: switch (sel) { case 0: gen_op_mfc0_random(); rn = "Random"; break; case 1: // gen_op_dmfc0_vpecontrol(); /* MT ASE */ rn = "VPEControl"; // break; case 2: // gen_op_dmfc0_vpeconf0(); /* MT ASE */ rn = "VPEConf0"; // break; case 3: // gen_op_dmfc0_vpeconf1(); /* MT ASE */ rn = "VPEConf1"; // break; case 4: // gen_op_dmfc0_YQMask(); /* MT ASE */ rn = "YQMask"; // break; case 5: // gen_op_dmfc0_vpeschedule(); /* MT ASE */ rn = "VPESchedule"; // break; case 6: // gen_op_dmfc0_vpeschefback(); /* MT ASE */ rn = "VPEScheFBack"; // break; case 7: // gen_op_dmfc0_vpeopt(); /* MT ASE */ rn = "VPEOpt"; // break; default: goto die; } break; case 2: switch (sel) { case 0: gen_op_dmfc0_entrylo0(); rn = "EntryLo0"; break; case 1: // gen_op_dmfc0_tcstatus(); /* MT ASE */ rn = "TCStatus"; // break; case 2: // gen_op_dmfc0_tcbind(); /* MT ASE */ rn = "TCBind"; // break; case 3: // gen_op_dmfc0_tcrestart(); /* MT ASE */ rn = "TCRestart"; // break; case 4: // gen_op_dmfc0_tchalt(); /* MT ASE */ rn = "TCHalt"; // break; case 5: // gen_op_dmfc0_tccontext(); /* MT ASE */ rn = "TCContext"; // break; case 6: // gen_op_dmfc0_tcschedule(); /* MT ASE */ rn = "TCSchedule"; // break; case 7: // gen_op_dmfc0_tcschefback(); /* MT ASE */ rn = "TCScheFBack"; // break; default: goto die; } break; case 3: switch (sel) { case 0: gen_op_dmfc0_entrylo1(); rn = "EntryLo1"; break; default: goto die; } break; case 4: switch (sel) { case 0: gen_op_dmfc0_context(); rn = "Context"; break; case 1: // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */ rn = "ContextConfig"; // break; default: goto die; } break; case 5: switch (sel) { case 0: gen_op_mfc0_pagemask(); rn = "PageMask"; break; case 1: gen_op_mfc0_pagegrain(); rn = "PageGrain"; break; default: goto die; } break; case 6: switch (sel) { case 0: gen_op_mfc0_wired(); rn = "Wired"; break; case 1: // gen_op_dmfc0_srsconf0(); /* shadow registers */ rn = "SRSConf0"; // break; case 2: // gen_op_dmfc0_srsconf1(); /* shadow registers */ rn = "SRSConf1"; // break; case 3: // gen_op_dmfc0_srsconf2(); /* shadow registers */ rn = "SRSConf2"; // break; case 4: // gen_op_dmfc0_srsconf3(); /* shadow registers */ rn = "SRSConf3"; // break; case 5: // gen_op_dmfc0_srsconf4(); /* shadow registers */ rn = "SRSConf4"; // break; default: goto die; } break; case 7: switch (sel) { case 0: gen_op_mfc0_hwrena(); rn = "HWREna"; break; default: goto die; } break; case 8: switch (sel) { case 0: gen_op_dmfc0_badvaddr(); rn = "BadVaddr"; break; default: goto die; } break; case 9: switch (sel) { case 0: gen_op_mfc0_count(); rn = "Count"; break; /* 6,7 are implementation dependent */ default: goto die; } break; case 10: switch (sel) { case 0: gen_op_dmfc0_entryhi(); rn = "EntryHi"; break; default: goto die; } break; case 11: switch (sel) { case 0: gen_op_mfc0_compare(); rn = "Compare"; break; /* 6,7 are implementation dependent */ default: goto die; } break; case 12: switch (sel) { case 0: gen_op_mfc0_status(); rn = "Status"; break; case 1: gen_op_mfc0_intctl(); rn = "IntCtl"; break; case 2: gen_op_mfc0_srsctl(); rn = "SRSCtl"; break; case 3: gen_op_mfc0_srsmap(); /* shadow registers */ rn = "SRSMap"; break; default: goto die; } break; case 13: switch (sel) { case 0: gen_op_mfc0_cause(); rn = "Cause"; break; default: goto die; } break; case 14: switch (sel) { case 0: gen_op_dmfc0_epc(); rn = "EPC"; break; default: goto die; } break; case 15: switch (sel) { case 0: gen_op_mfc0_prid(); rn = "PRid"; break; case 1: gen_op_dmfc0_ebase(); rn = "EBase"; break; default: goto die; } break; case 16: switch (sel) { case 0: gen_op_mfc0_config0(); rn = "Config"; break; case 1: gen_op_mfc0_config1(); rn = "Config1"; break; case 2: gen_op_mfc0_config2(); rn = "Config2"; break; case 3: gen_op_mfc0_config3(); rn = "Config3"; break; /* 6,7 are implementation dependent */ default: goto die; } break; case 17: switch (sel) { case 0: gen_op_dmfc0_lladdr(); rn = "LLAddr"; break; default: goto die; } break; case 18: switch (sel) { case 0: gen_op_dmfc0_watchlo0(); rn = "WatchLo"; break; case 1: // gen_op_dmfc0_watchlo1(); rn = "WatchLo1"; // break; case 2: // gen_op_dmfc0_watchlo2(); rn = "WatchLo2"; // break; case 3: // gen_op_dmfc0_watchlo3(); rn = "WatchLo3"; // break; case 4: // gen_op_dmfc0_watchlo4(); rn = "WatchLo4"; // break; case 5: // gen_op_dmfc0_watchlo5(); rn = "WatchLo5"; // break; case 6: // gen_op_dmfc0_watchlo6(); rn = "WatchLo6"; // break; case 7: // gen_op_dmfc0_watchlo7(); rn = "WatchLo7"; // break; default: goto die; } break; case 19: switch (sel) { case 0: gen_op_mfc0_watchhi0(); rn = "WatchHi"; break; case 1: // gen_op_mfc0_watchhi1(); rn = "WatchHi1"; // break; case 2: // gen_op_mfc0_watchhi2(); rn = "WatchHi2"; // break; case 3: // gen_op_mfc0_watchhi3(); rn = "WatchHi3"; // break; case 4: // gen_op_mfc0_watchhi4(); rn = "WatchHi4"; // break; case 5: // gen_op_mfc0_watchhi5(); rn = "WatchHi5"; // break; case 6: // gen_op_mfc0_watchhi6(); rn = "WatchHi6"; // break; case 7: // gen_op_mfc0_watchhi7(); rn = "WatchHi7"; // break; default: goto die; } break; case 20: switch (sel) { case 0: /* 64 bit MMU only */ gen_op_dmfc0_xcontext(); rn = "XContext"; break; default: goto die; } break; case 21: /* Officially reserved, but sel 0 is used for R1x000 framemask */ switch (sel) { case 0: gen_op_mfc0_framemask(); rn = "Framemask"; break; default: goto die; } break; case 22: /* ignored */ rn = "'Diagnostic"; /* implementation dependent */ break; case 23: switch (sel) { case 0: gen_op_mfc0_debug(); /* EJTAG support */ rn = "Debug"; break; case 1: // gen_op_dmfc0_tracecontrol(); /* PDtrace support */ rn = "TraceControl"; // break; case 2: // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */ rn = "TraceControl2"; // break; case 3: // gen_op_dmfc0_usertracedata(); /* PDtrace support */ rn = "UserTraceData"; // break; case 4: // gen_op_dmfc0_debug(); /* PDtrace support */ rn = "TraceBPC"; // break; default: goto die; } break; case 24: switch (sel) { case 0: gen_op_dmfc0_depc(); /* EJTAG support */ rn = "DEPC"; break; default: goto die; } break; case 25: switch (sel) { case 0: gen_op_mfc0_performance0(); rn = "Performance0"; break; case 1: // gen_op_dmfc0_performance1(); rn = "Performance1"; // break; case 2: // gen_op_dmfc0_performance2(); rn = "Performance2"; // break; case 3: // gen_op_dmfc0_performance3(); rn = "Performance3"; // break; case 4: // gen_op_dmfc0_performance4(); rn = "Performance4"; // break; case 5: // gen_op_dmfc0_performance5(); rn = "Performance5"; // break; case 6: // gen_op_dmfc0_performance6(); rn = "Performance6"; // break; case 7: // gen_op_dmfc0_performance7(); rn = "Performance7"; // break; default: goto die; } break; case 26: rn = "ECC"; break; case 27: switch (sel) { /* ignored */ case 0 ... 3: rn = "CacheErr"; break; default: goto die; } break; case 28: switch (sel) { case 0: case 2: case 4: case 6: gen_op_mfc0_taglo(); rn = "TagLo"; break; case 1: case 3: case 5: case 7: gen_op_mfc0_datalo(); rn = "DataLo"; break; default: goto die; } break; case 29: switch (sel) { case 0: case 2: case 4: case 6: gen_op_mfc0_taghi(); rn = "TagHi"; break; case 1: case 3: case 5: case 7: gen_op_mfc0_datahi(); rn = "DataHi"; break; default: goto die; } break; case 30: switch (sel) { case 0: gen_op_dmfc0_errorepc(); rn = "ErrorEPC"; break; default: goto die; } break; case 31: switch (sel) { case 0: gen_op_mfc0_desave(); /* EJTAG support */ rn = "DESAVE"; break; default: goto die; } break; default: goto die; } #if defined MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) { fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n", rn, reg, sel); } #endif return; die: #if defined MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) { fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n", rn, reg, sel); } #endif generate_exception(ctx, EXCP_RI); }
10,568
qemu
bff384a4fbd5d0e86939092e74e766ef0f5f592c
0
static void create_cpu(const char *cpu_model, qemu_irq *cbus_irq, qemu_irq *i8259_irq) { CPUMIPSState *env; MIPSCPU *cpu; int i; if (cpu_model == NULL) { #ifdef TARGET_MIPS64 cpu_model = "20Kc"; #else cpu_model = "24Kf"; #endif } for (i = 0; i < smp_cpus; i++) { cpu = cpu_mips_init(cpu_model); if (cpu == NULL) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } env = &cpu->env; /* Init internal devices */ cpu_mips_irq_init_cpu(env); cpu_mips_clock_init(env); qemu_register_reset(main_cpu_reset, cpu); } cpu = MIPS_CPU(first_cpu); env = &cpu->env; *i8259_irq = env->irq[2]; *cbus_irq = env->irq[4]; }
10,569
qemu
1f01e50b8330c24714ddca5841fdbb703076b121
0
void qed_release(BDRVQEDState *s) { aio_context_release(bdrv_get_aio_context(s->bs)); }
10,570
qemu
4fa4ce7107c6ec432f185307158c5df91ce54308
0
int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf) { int err; ssize_t len; V9fsState *s = pdu->s; if (v9fs_request_cancelled(pdu)) { return -EINTR; } buf->data = g_malloc(PATH_MAX); v9fs_path_read_lock(s); v9fs_co_run_in_worker( { len = s->ops->readlink(&s->ctx, path, buf->data, PATH_MAX - 1); if (len > -1) { buf->size = len; buf->data[len] = 0; err = 0; } else { err = -errno; } }); v9fs_path_unlock(s); if (err) { g_free(buf->data); buf->data = NULL; buf->size = 0; } return err; }
10,571
qemu
d1fdf257d52822695f5ace6c586e059aa17d4b79
0
int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *flags, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, off_t *size, Error **errp) { char buf[256]; uint64_t magic, s; int rc; bool zeroes = true; TRACE("Receiving negotiation tlscreds=%p hostname=%s.", tlscreds, hostname ? hostname : "<null>"); rc = -EINVAL; if (outioc) { *outioc = NULL; } if (tlscreds && !outioc) { error_setg(errp, "Output I/O channel required for TLS"); goto fail; } if (read_sync(ioc, buf, 8, errp) < 0) { error_prepend(errp, "Failed to read data"); goto fail; } buf[8] = '\0'; if (strlen(buf) == 0) { error_setg(errp, "Server connection closed unexpectedly"); goto fail; } TRACE("Magic is %c%c%c%c%c%c%c%c", qemu_isprint(buf[0]) ? buf[0] : '.', qemu_isprint(buf[1]) ? buf[1] : '.', qemu_isprint(buf[2]) ? buf[2] : '.', qemu_isprint(buf[3]) ? buf[3] : '.', qemu_isprint(buf[4]) ? buf[4] : '.', qemu_isprint(buf[5]) ? buf[5] : '.', qemu_isprint(buf[6]) ? buf[6] : '.', qemu_isprint(buf[7]) ? buf[7] : '.'); if (memcmp(buf, "NBDMAGIC", 8) != 0) { error_setg(errp, "Invalid magic received"); goto fail; } if (read_sync(ioc, &magic, sizeof(magic), errp) < 0) { error_prepend(errp, "Failed to read magic"); goto fail; } magic = be64_to_cpu(magic); TRACE("Magic is 0x%" PRIx64, magic); if (magic == NBD_OPTS_MAGIC) { uint32_t clientflags = 0; uint16_t globalflags; bool fixedNewStyle = false; if (read_sync(ioc, &globalflags, sizeof(globalflags), errp) < 0) { error_prepend(errp, "Failed to read server flags"); goto fail; } globalflags = be16_to_cpu(globalflags); TRACE("Global flags are %" PRIx32, globalflags); if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { fixedNewStyle = true; TRACE("Server supports fixed new style"); clientflags |= NBD_FLAG_C_FIXED_NEWSTYLE; } if (globalflags & NBD_FLAG_NO_ZEROES) { zeroes = false; TRACE("Server supports no zeroes"); clientflags |= NBD_FLAG_C_NO_ZEROES; } /* client requested flags */ clientflags = cpu_to_be32(clientflags); if (write_sync(ioc, &clientflags, sizeof(clientflags), errp) < 0) { error_prepend(errp, "Failed to send clientflags field"); goto fail; } if (tlscreds) { if (fixedNewStyle) { *outioc = nbd_receive_starttls(ioc, tlscreds, hostname, errp); if (!*outioc) { goto fail; } ioc = *outioc; } else { error_setg(errp, "Server does not support STARTTLS"); goto fail; } } if (!name) { TRACE("Using default NBD export name \"\""); name = ""; } if (fixedNewStyle) { /* Check our desired export is present in the * server export list. Since NBD_OPT_EXPORT_NAME * cannot return an error message, running this * query gives us good error reporting if the * server required TLS */ if (nbd_receive_query_exports(ioc, name, errp) < 0) { goto fail; } } /* write the export name request */ if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, name, errp) < 0) { goto fail; } /* Read the response */ if (read_sync(ioc, &s, sizeof(s), errp) < 0) { error_prepend(errp, "Failed to read export length"); goto fail; } *size = be64_to_cpu(s); if (read_sync(ioc, flags, sizeof(*flags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); goto fail; } be16_to_cpus(flags); } else if (magic == NBD_CLIENT_MAGIC) { uint32_t oldflags; if (name) { error_setg(errp, "Server does not support export names"); goto fail; } if (tlscreds) { error_setg(errp, "Server does not support STARTTLS"); goto fail; } if (read_sync(ioc, &s, sizeof(s), errp) < 0) { error_prepend(errp, "Failed to read export length"); goto fail; } *size = be64_to_cpu(s); TRACE("Size is %" PRIu64, *size); if (read_sync(ioc, &oldflags, sizeof(oldflags), errp) < 0) { error_prepend(errp, "Failed to read export flags"); goto fail; } be32_to_cpus(&oldflags); if (oldflags & ~0xffff) { error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags); goto fail; } *flags = oldflags; } else { error_setg(errp, "Bad magic received"); goto fail; } TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags); if (zeroes && drop_sync(ioc, 124, errp) < 0) { error_prepend(errp, "Failed to read reserved block"); goto fail; } rc = 0; fail: return rc; }
10,572
qemu
31fe14d15d08d613ff38abb249911e98c7966b86
0
void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq) { uint32_t epow_irq_ranges[] = {cpu_to_be32(epow_irq), cpu_to_be32(1)}; uint32_t epow_interrupts[] = {cpu_to_be32(epow_irq), 0}; _FDT((fdt_begin_node(fdt, "event-sources"))); _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); _FDT((fdt_property_cell(fdt, "#interrupt-cells", 2))); _FDT((fdt_property(fdt, "interrupt-ranges", epow_irq_ranges, sizeof(epow_irq_ranges)))); _FDT((fdt_begin_node(fdt, "epow-events"))); _FDT((fdt_property(fdt, "interrupts", epow_interrupts, sizeof(epow_interrupts)))); _FDT((fdt_end_node(fdt))); _FDT((fdt_end_node(fdt))); }
10,573
qemu
b47d8efa9f430c332bf96ce6eede169eb48422ad
0
static void vfio_put_device(VFIOPCIDevice *vdev) { QLIST_REMOVE(vdev, next); vdev->vbasedev.group = NULL; trace_vfio_put_device(vdev->vbasedev.fd); close(vdev->vbasedev.fd); g_free(vdev->vbasedev.name); if (vdev->msix) { g_free(vdev->msix); vdev->msix = NULL; } }
10,574
qemu
ba4b3f668abf1fcde204c8f3185ea6edeec6eaa3
0
static int open_self_cmdline(void *cpu_env, int fd) { int fd_orig = -1; bool word_skipped = false; fd_orig = open("/proc/self/cmdline", O_RDONLY); if (fd_orig < 0) { return fd_orig; } while (true) { ssize_t nb_read; char buf[128]; char *cp_buf = buf; nb_read = read(fd_orig, buf, sizeof(buf)); if (nb_read < 0) { int e = errno; fd_orig = close(fd_orig); errno = e; return -1; } else if (nb_read == 0) { break; } if (!word_skipped) { /* Skip the first string, which is the path to qemu-*-static instead of the actual command. */ cp_buf = memchr(buf, 0, sizeof(buf)); if (cp_buf) { /* Null byte found, skip one string */ cp_buf++; nb_read -= cp_buf - buf; word_skipped = true; } } if (word_skipped) { if (write(fd, cp_buf, nb_read) != nb_read) { int e = errno; close(fd_orig); errno = e; return -1; } } } return close(fd_orig); }
10,576