id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
376
static int http_receive_data(HTTPContext *c) { int len; HTTPContext *c1; if (c->buffer_ptr >= c->buffer_end) { FFStream *feed = c->stream; /* a packet has been received : write it in the store, except if header */ if (c->data_count > FFM_PACKET_SIZE) { // printf("writing pos=0x%Lx size=0x%Lx\n", feed->feed_write_index, feed->feed_size); /* XXX: use llseek or url_seek */ lseek(c->feed_fd, feed->feed_write_index, SEEK_SET); write(c->feed_fd, c->buffer, FFM_PACKET_SIZE); feed->feed_write_index += FFM_PACKET_SIZE; /* update file size */ if (feed->feed_write_index > c->stream->feed_size) feed->feed_size = feed->feed_write_index; /* handle wrap around if max file size reached */ if (feed->feed_write_index >= c->stream->feed_max_size) feed->feed_write_index = FFM_PACKET_SIZE; /* write index */ ffm_write_write_index(c->feed_fd, feed->feed_write_index); /* wake up any waiting connections */ for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) { if (c1->state == HTTPSTATE_WAIT_FEED && c1->stream->feed == c->stream->feed) { c1->state = HTTPSTATE_SEND_DATA; } } } else { /* We have a header in our hands that contains useful data */ AVFormatContext s; ByteIOContext *pb = &s.pb; int i; memset(&s, 0, sizeof(s)); url_open_buf(pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY); pb->buf_end = c->buffer_end; /* ?? */ pb->is_streamed = 1; if (feed->fmt->read_header(&s, 0) < 0) { goto fail; } /* Now we have the actual streams */ if (s.nb_streams != feed->nb_streams) { goto fail; } for (i = 0; i < s.nb_streams; i++) { memcpy(&feed->streams[i]->codec, &s.streams[i]->codec, sizeof(AVCodecContext)); } } c->buffer_ptr = c->buffer; } len = read(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr); if (len < 0) { if (errno != EAGAIN && errno != EINTR) { /* error : close connection */ goto fail; } } else if (len == 0) { /* end of connection : close it */ goto fail; } else { c->buffer_ptr += len; c->data_count += len; } return 0; fail: c->stream->feed_opened = 0; close(c->feed_fd); return -1; }
true
FFmpeg
a6e14edde01bafbbe54f6f451efa718a48975b47
377
static int stellaris_sys_init(uint32_t base, qemu_irq irq, stellaris_board_info * board, uint8_t *macaddr) { ssys_state *s; s = (ssys_state *)g_malloc0(sizeof(ssys_state)); s->irq = irq; s->board = board; /* Most devices come preprogrammed with a MAC address in the user data. */ s->user0 = macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16); s->user1 = macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16); memory_region_init_io(&s->iomem, NULL, &ssys_ops, s, "ssys", 0x00001000); memory_region_add_subregion(get_system_memory(), base, &s->iomem); ssys_reset(s); vmstate_register(NULL, -1, &vmstate_stellaris_sys, s); return 0; }
true
qemu
b45c03f585ea9bb1af76c73e82195418c294919d
379
static int kvm_recommended_vcpus(KVMState *s) { int ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS); return (ret) ? ret : 4; }
true
qemu
11748ba72ea4fc03e975aa5f5d876b5b0902e356
380
static void reschedule_dma(void *opaque) { DMAAIOCB *dbs = (DMAAIOCB *)opaque; qemu_bh_delete(dbs->bh); dbs->bh = NULL; dma_bdrv_cb(opaque, 0); }
true
qemu
c3adb5b9168a57790b5074489b6f0275ac3cc8b5
381
static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { ADPCMContext *c = avctx->priv_data; ADPCMChannelStatus *cs; int n, m, channel, i; int block_predictor[2]; short *samples; short *samples_end; uint8_t *src; int st; /* stereo */ /* DK3 ADPCM accounting variables */ unsigned char last_byte = 0; unsigned char nibble; int decode_top_nibble_next = 0; int diff_channel; /* EA ADPCM state variables */ uint32_t samples_in_chunk; int32_t previous_left_sample, previous_right_sample; int32_t current_left_sample, current_right_sample; int32_t next_left_sample, next_right_sample; int32_t coeff1l, coeff2l, coeff1r, coeff2r; uint8_t shift_left, shift_right; int count1, count2; if (!buf_size) return 0; //should protect all 4bit ADPCM variants //8 is needed for CODEC_ID_ADPCM_IMA_WAV with 2 channels // if(*data_size/4 < buf_size + 8) return -1; samples = data; samples_end= samples + *data_size/2; *data_size= 0; src = buf; st = avctx->channels == 2 ? 1 : 0; switch(avctx->codec->id) { case CODEC_ID_ADPCM_IMA_QT: n = (buf_size - 2);/* >> 2*avctx->channels;*/ channel = c->channel; cs = &(c->status[channel]); /* (pppppp) (piiiiiii) */ /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ cs->predictor = (*src++) << 8; cs->predictor |= (*src & 0x80); cs->predictor &= 0xFF80; /* sign extension */ if(cs->predictor & 0x8000) cs->predictor -= 0x10000; CLAMP_TO_SHORT(cs->predictor); cs->step_index = (*src++) & 0x7F; if (cs->step_index > 88){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); cs->step_index = 88; } cs->step = step_table[cs->step_index]; if (st && channel) samples++; for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */ *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3); samples += avctx->channels; *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3); samples += avctx->channels; src ++; } if(st) { /* handle stereo interlacing */ c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */ if(channel == 1) { /* wait for the other packet before outputing anything */ return src - buf; } } break; case CODEC_ID_ADPCM_IMA_WAV: if (avctx->block_align != 0 && buf_size > avctx->block_align) buf_size = avctx->block_align; // samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1; for(i=0; i<avctx->channels; i++){ cs = &(c->status[i]); cs->predictor = (int16_t)(src[0] + (src[1]<<8)); src+=2; // XXX: is this correct ??: *samples++ = cs->predictor; cs->step_index = *src++; if (cs->step_index > 88){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); cs->step_index = 88; } if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */ } while(src < buf + buf_size){ for(m=0; m<4; m++){ for(i=0; i<=st; i++) *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3); for(i=0; i<=st; i++) *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3); src++; } src += 4*st; } break; case CODEC_ID_ADPCM_4XM: cs = &(c->status[0]); c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; if(st){ c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; } c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; if(st){ c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; } if (cs->step_index < 0) cs->step_index = 0; if (cs->step_index > 88) cs->step_index = 88; m= (buf_size - (src - buf))>>st; for(i=0; i<m; i++) { *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4); if (st) *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4); *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4); if (st) *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4); } src += m<<st; break; case CODEC_ID_ADPCM_MS: if (avctx->block_align != 0 && buf_size > avctx->block_align) buf_size = avctx->block_align; n = buf_size - 7 * avctx->channels; if (n < 0) return -1; block_predictor[0] = av_clip(*src++, 0, 7); block_predictor[1] = 0; if (st) block_predictor[1] = av_clip(*src++, 0, 7); c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); src+=2; if (st){ c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); src+=2; } c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]]; c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]]; c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]]; c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]]; c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); src+=2; if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); if (st) src+=2; c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); src+=2; if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); if (st) src+=2; *samples++ = c->status[0].sample1; if (st) *samples++ = c->status[1].sample1; *samples++ = c->status[0].sample2; if (st) *samples++ = c->status[1].sample2; for(;n>0;n--) { *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F); src ++; } break; case CODEC_ID_ADPCM_IMA_DK4: if (avctx->block_align != 0 && buf_size > avctx->block_align) buf_size = avctx->block_align; c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8)); c->status[0].step_index = src[2]; src += 4; *samples++ = c->status[0].predictor; if (st) { c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8)); c->status[1].step_index = src[2]; src += 4; *samples++ = c->status[1].predictor; } while (src < buf + buf_size) { /* take care of the top nibble (always left or mono channel) */ *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3); /* take care of the bottom nibble, which is right sample for * stereo, or another mono sample */ if (st) *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[0] & 0x0F, 3); else *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3); src++; } break; case CODEC_ID_ADPCM_IMA_DK3: if (avctx->block_align != 0 && buf_size > avctx->block_align) buf_size = avctx->block_align; if(buf_size + 16 > (samples_end - samples)*3/8) return -1; c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8)); c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8)); c->status[0].step_index = src[14]; c->status[1].step_index = src[15]; /* sign extend the predictors */ src += 16; diff_channel = c->status[1].predictor; /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when * the buffer is consumed */ while (1) { /* for this algorithm, c->status[0] is the sum channel and * c->status[1] is the diff channel */ /* process the first predictor of the sum channel */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], nibble, 3); /* process the diff channel predictor */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[1], nibble, 3); /* process the first pair of stereo PCM samples */ diff_channel = (diff_channel + c->status[1].predictor) / 2; *samples++ = c->status[0].predictor + c->status[1].predictor; *samples++ = c->status[0].predictor - c->status[1].predictor; /* process the second predictor of the sum channel */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], nibble, 3); /* process the second pair of stereo PCM samples */ diff_channel = (diff_channel + c->status[1].predictor) / 2; *samples++ = c->status[0].predictor + c->status[1].predictor; *samples++ = c->status[0].predictor - c->status[1].predictor; } break; case CODEC_ID_ADPCM_IMA_WS: /* no per-block initialization; just start decoding the data */ while (src < buf + buf_size) { if (st) { *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[0] & 0x0F, 3); } else { *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3); } src++; } break; case CODEC_ID_ADPCM_XA: c->status[0].sample1 = c->status[0].sample2 = c->status[1].sample1 = c->status[1].sample2 = 0; while (buf_size >= 128) { xa_decode(samples, src, &c->status[0], &c->status[1], avctx->channels); src += 128; samples += 28 * 8; buf_size -= 128; } break; case CODEC_ID_ADPCM_EA: samples_in_chunk = AV_RL32(src); if (samples_in_chunk >= ((buf_size - 12) * 2)) { src += buf_size; break; } src += 4; current_left_sample = (int16_t)AV_RL16(src); src += 2; previous_left_sample = (int16_t)AV_RL16(src); src += 2; current_right_sample = (int16_t)AV_RL16(src); src += 2; previous_right_sample = (int16_t)AV_RL16(src); src += 2; for (count1 = 0; count1 < samples_in_chunk/28;count1++) { coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F]; coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4]; coeff1r = ea_adpcm_table[*src & 0x0F]; coeff2r = ea_adpcm_table[(*src & 0x0F) + 4]; src++; shift_left = ((*src >> 4) & 0x0F) + 8; shift_right = (*src & 0x0F) + 8; src++; for (count2 = 0; count2 < 28; count2++) { next_left_sample = (((*src & 0xF0) << 24) >> shift_left); next_right_sample = (((*src & 0x0F) << 28) >> shift_right); src++; next_left_sample = (next_left_sample + (current_left_sample * coeff1l) + (previous_left_sample * coeff2l) + 0x80) >> 8; next_right_sample = (next_right_sample + (current_right_sample * coeff1r) + (previous_right_sample * coeff2r) + 0x80) >> 8; CLAMP_TO_SHORT(next_left_sample); CLAMP_TO_SHORT(next_right_sample); previous_left_sample = current_left_sample; current_left_sample = next_left_sample; previous_right_sample = current_right_sample; current_right_sample = next_right_sample; *samples++ = (unsigned short)current_left_sample; *samples++ = (unsigned short)current_right_sample; } } break; case CODEC_ID_ADPCM_IMA_SMJPEG: c->status[0].predictor = *src; src += 2; c->status[0].step_index = *src++; src++; /* skip another byte before getting to the meat */ while (src < buf + buf_size) { *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src & 0x0F, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], (*src >> 4) & 0x0F, 3); src++; } break; case CODEC_ID_ADPCM_CT: while (src < buf + buf_size) { if (st) { *samples++ = adpcm_ct_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); *samples++ = adpcm_ct_expand_nibble(&c->status[1], src[0] & 0x0F); } else { *samples++ = adpcm_ct_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); *samples++ = adpcm_ct_expand_nibble(&c->status[0], src[0] & 0x0F); } src++; } break; case CODEC_ID_ADPCM_SBPRO_4: case CODEC_ID_ADPCM_SBPRO_3: case CODEC_ID_ADPCM_SBPRO_2: if (!c->status[0].step_index) { /* the first byte is a raw sample */ *samples++ = 128 * (*src++ - 0x80); if (st) *samples++ = 128 * (*src++ - 0x80); c->status[0].step_index = 1; } if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) { while (src < buf + buf_size) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 4, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], src[0] & 0x0F, 4, 0); src++; } } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) { while (src < buf + buf_size && samples + 2 < samples_end) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 5) & 0x07, 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 2) & 0x07, 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], src[0] & 0x03, 2, 0); src++; } } else { while (src < buf + buf_size && samples + 3 < samples_end) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 6) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], (src[0] >> 4) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 2) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], src[0] & 0x03, 2, 2); src++; } } break; case CODEC_ID_ADPCM_SWF: { GetBitContext gb; const int *table; int k0, signmask, nb_bits; int size = buf_size*8; init_get_bits(&gb, buf, size); //read bits & inital values nb_bits = get_bits(&gb, 2)+2; //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits); table = swf_index_tables[nb_bits-2]; k0 = 1 << (nb_bits-2); signmask = 1 << (nb_bits-1); for (i = 0; i < avctx->channels; i++) { *samples++ = c->status[i].predictor = get_sbits(&gb, 16); c->status[i].step_index = get_bits(&gb, 6); } while (get_bits_count(&gb) < size) { int i; for (i = 0; i < avctx->channels; i++) { // similar to IMA adpcm int delta = get_bits(&gb, nb_bits); int step = step_table[c->status[i].step_index]; long vpdiff = 0; // vpdiff = (delta+0.5)*step/4 int k = k0; do { if (delta & k) vpdiff += step; step >>= 1; k >>= 1; } while(k); vpdiff += step; if (delta & signmask) c->status[i].predictor -= vpdiff; else c->status[i].predictor += vpdiff; c->status[i].step_index += table[delta & (~signmask)]; c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88); c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767); *samples++ = c->status[i].predictor; if (samples >= samples_end) { av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); return -1; } } } src += buf_size; break; } case CODEC_ID_ADPCM_YAMAHA: while (src < buf + buf_size) { if (st) { *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], src[0] & 0x0F); *samples++ = adpcm_yamaha_expand_nibble(&c->status[1], (src[0] >> 4) & 0x0F); } else { *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], src[0] & 0x0F); *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); } src++; } break; case CODEC_ID_ADPCM_THP: { int table[2][16]; unsigned int samplecnt; int prev[2][2]; int ch; if (buf_size < 80) { av_log(avctx, AV_LOG_ERROR, "frame too small\n"); return -1; } src+=4; samplecnt = bytestream_get_be32(&src); for (i = 0; i < 32; i++) table[0][i] = (int16_t)bytestream_get_be16(&src); /* Initialize the previous sample. */ for (i = 0; i < 4; i++) prev[0][i] = (int16_t)bytestream_get_be16(&src); if (samplecnt >= (samples_end - samples) / (st + 1)) { av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); return -1; } for (ch = 0; ch <= st; ch++) { samples = (unsigned short *) data + ch; /* Read in every sample for this channel. */ for (i = 0; i < samplecnt / 14; i++) { int index = (*src >> 4) & 7; unsigned int exp = 28 - (*src++ & 15); int factor1 = table[ch][index * 2]; int factor2 = table[ch][index * 2 + 1]; /* Decode 14 samples. */ for (n = 0; n < 14; n++) { int32_t sampledat; if(n&1) sampledat= *src++ <<28; else sampledat= (*src&0xF0)<<24; *samples = ((prev[ch][0]*factor1 + prev[ch][1]*factor2) >> 11) + (sampledat>>exp); prev[ch][1] = prev[ch][0]; prev[ch][0] = *samples++; /* In case of stereo, skip one sample, this sample is for the other channel. */ samples += st; } } } /* In the previous loop, in case stereo is used, samples is increased exactly one time too often. */ samples -= st; break; } default: return -1; } *data_size = (uint8_t *)samples - (uint8_t *)data; return src - buf; }
true
FFmpeg
e457023a95e449ac2c80a49256f0611d5a8fffff
382
static coroutine_fn void test_multi_co_schedule_entry(void *opaque) { g_assert(to_schedule[id] == NULL); atomic_mb_set(&to_schedule[id], qemu_coroutine_self()); while (!atomic_mb_read(&now_stopping)) { int n; n = g_test_rand_int_range(0, NUM_CONTEXTS); schedule_next(n); qemu_coroutine_yield(); g_assert(to_schedule[id] == NULL); atomic_mb_set(&to_schedule[id], qemu_coroutine_self()); } }
true
qemu
fb0c43f34eed8b18678c6e1f481d8564b35c99ed
383
static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVQcowState *s = bs->opaque; int len, i, shift, ret; QCowHeader header; ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; } be32_to_cpus(&header.magic); be32_to_cpus(&header.version); be64_to_cpus(&header.backing_file_offset); be32_to_cpus(&header.backing_file_size); be32_to_cpus(&header.mtime); be64_to_cpus(&header.size); be32_to_cpus(&header.crypt_method); be64_to_cpus(&header.l1_table_offset); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image not in qcow format"); ret = -EINVAL; goto fail; } if (header.version != QCOW_VERSION) { char version[64]; snprintf(version, sizeof(version), "QCOW version %" PRIu32, header.version); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, bs->device_name, "qcow", version); ret = -ENOTSUP; goto fail; } if (header.size <= 1) { error_setg(errp, "Image size is too small (must be at least 2 bytes)"); ret = -EINVAL; goto fail; } if (header.cluster_bits < 9 || header.cluster_bits > 16) { error_setg(errp, "Cluster size must be between 512 and 64k"); ret = -EINVAL; goto fail; } /* l2_bits specifies number of entries; storing a uint64_t in each entry, * so bytes = num_entries << 3. */ if (header.l2_bits < 9 - 3 || header.l2_bits > 16 - 3) { error_setg(errp, "L2 table size must be between 512 and 64k"); ret = -EINVAL; goto fail; } if (header.crypt_method > QCOW_CRYPT_AES) { error_setg(errp, "invalid encryption method in qcow header"); ret = -EINVAL; goto fail; } s->crypt_method_header = header.crypt_method; if (s->crypt_method_header) { bs->encrypted = 1; } s->cluster_bits = header.cluster_bits; s->cluster_size = 1 << s->cluster_bits; s->cluster_sectors = 1 << (s->cluster_bits - 9); s->l2_bits = header.l2_bits; s->l2_size = 1 << s->l2_bits; bs->total_sectors = header.size / 512; s->cluster_offset_mask = (1LL << (63 - s->cluster_bits)) - 1; /* read the level 1 table */ shift = s->cluster_bits + s->l2_bits; if (header.size > UINT64_MAX - (1LL << shift)) { error_setg(errp, "Image too large"); ret = -EINVAL; goto fail; } else { uint64_t l1_size = (header.size + (1LL << shift) - 1) >> shift; if (l1_size > INT_MAX / sizeof(uint64_t)) { error_setg(errp, "Image too large"); ret = -EINVAL; goto fail; } s->l1_size = l1_size; } s->l1_table_offset = header.l1_table_offset; s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { goto fail; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } /* alloc L2 cache */ s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); s->cluster_cache = g_malloc(s->cluster_size); s->cluster_data = g_malloc(s->cluster_size); s->cluster_cache_offset = -1; /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; if (len > 1023) { len = 1023; } ret = bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len); if (ret < 0) { goto fail; } bs->backing_file[len] = '\0'; } /* Disable migration when qcow images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "qcow", bs->device_name, "live migration"); migrate_add_blocker(s->migration_blocker); qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->l1_table); g_free(s->l2_cache); g_free(s->cluster_cache); g_free(s->cluster_data); return ret; }
true
qemu
d66e5cee002c471b78139228a4e7012736b375f9
384
static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx, AVFilterBufferRef *ref) { AVFilterLink *outlink = ctx->outputs[0]; AVFilterBufferRef *buf; int channels, data_size, i; switch (outlink->type) { case AVMEDIA_TYPE_VIDEO: buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, ref->video->w, ref->video->h); av_image_copy(buf->data, buf->linesize, (void*)ref->data, ref->linesize, ref->format, ref->video->w, ref->video->h); break; case AVMEDIA_TYPE_AUDIO: buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, ref->audio->nb_samples); channels = av_get_channel_layout_nb_channels(ref->audio->channel_layout); av_samples_copy(buf->extended_data, ref->buf->extended_data, 0, 0, ref->audio->nb_samples, channels, ref->format); break; default: } avfilter_copy_buffer_ref_props(buf, ref); return buf; }
true
FFmpeg
ac87c273a646eb8feba8e47f15da4934d119f650
385
void qmp_block_commit(const char *device, bool has_base, const char *base, const char *top, bool has_speed, int64_t speed, Error **errp) { BlockDriverState *bs; BlockDriverState *base_bs, *top_bs; Error *local_err = NULL; /* This will be part of the QMP command, if/when the * BlockdevOnError change for blkmirror makes it in */ BlockdevOnError on_error = BLOCKDEV_ON_ERROR_REPORT; /* drain all i/o before commits */ bdrv_drain_all(); bs = bdrv_find(device); if (!bs) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } if (base && has_base) { base_bs = bdrv_find_backing_image(bs, base); } else { base_bs = bdrv_find_base(bs); } if (base_bs == NULL) { error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL"); return; } /* default top_bs is the active layer */ top_bs = bs; if (top) { if (strcmp(bs->filename, top) != 0) { top_bs = bdrv_find_backing_image(bs, top); } } if (top_bs == NULL) { error_setg(errp, "Top image file %s not found", top ? top : "NULL"); return; } commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); return; } /* Grab a reference so hotplug does not delete the BlockDriverState from * underneath us. */ drive_get_ref(drive_get_by_blockdev(bs)); }
true
qemu
d5208c45be38ab858db6ec5a5097aa1c1a8ebbc9
386
static int mkv_check_tag(AVDictionary *m) { AVDictionaryEntry *t = NULL; while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) if (av_strcasecmp(t->key, "title") && av_strcasecmp(t->key, "stereo_mode")) return 1; return 0; }
false
FFmpeg
843e72ea5542845a0a9fed743517c14a92279885
387
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645NAL *nal) { int i, si, di; uint8_t *dst; nal->skipped_bytes = 0; #define STARTCODE_TEST \ if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \ if (src[i + 2] != 3 && src[i + 2] != 0) { \ /* startcode, so we must be past the end */ \ length = i; \ } \ break; \ } #if HAVE_FAST_UNALIGNED #define FIND_FIRST_ZERO \ if (i > 0 && !src[i]) \ i--; \ while (src[i]) \ i++ #if HAVE_FAST_64BIT for (i = 0; i + 1 < length; i += 9) { if (!((~AV_RN64A(src + i) & (AV_RN64A(src + i) - 0x0100010001000101ULL)) & 0x8000800080008080ULL)) continue; FIND_FIRST_ZERO; STARTCODE_TEST; i -= 7; } #else for (i = 0; i + 1 < length; i += 5) { if (!((~AV_RN32A(src + i) & (AV_RN32A(src + i) - 0x01000101U)) & 0x80008080U)) continue; FIND_FIRST_ZERO; STARTCODE_TEST; i -= 3; } #endif /* HAVE_FAST_64BIT */ #else for (i = 0; i + 1 < length; i += 2) { if (src[i]) continue; if (i > 0 && src[i - 1] == 0) i--; STARTCODE_TEST; } #endif /* HAVE_FAST_UNALIGNED */ if (i >= length - 1) { // no escaped 0 nal->data = nal->raw_data = src; nal->size = nal->raw_size = length; return length; } av_fast_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size, length + AV_INPUT_BUFFER_PADDING_SIZE); if (!nal->rbsp_buffer) return AVERROR(ENOMEM); dst = nal->rbsp_buffer; memcpy(dst, src, i); si = di = i; while (si + 2 < length) { // remove escapes (very rare 1:2^22) if (src[si + 2] > 3) { dst[di++] = src[si++]; dst[di++] = src[si++]; } else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) { if (src[si + 2] == 3) { // escape dst[di++] = 0; dst[di++] = 0; si += 3; if (nal->skipped_bytes_pos) { nal->skipped_bytes++; if (nal->skipped_bytes_pos_size < nal->skipped_bytes) { nal->skipped_bytes_pos_size *= 2; av_assert0(nal->skipped_bytes_pos_size >= nal->skipped_bytes); av_reallocp_array(&nal->skipped_bytes_pos, nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos)); if (!nal->skipped_bytes_pos) { nal->skipped_bytes_pos_size = 0; return AVERROR(ENOMEM); } } if (nal->skipped_bytes_pos) nal->skipped_bytes_pos[nal->skipped_bytes-1] = di - 1; } continue; } else // next start code goto nsc; } dst[di++] = src[si++]; } while (si < length) dst[di++] = src[si++]; nsc: memset(dst + di, 0, AV_INPUT_BUFFER_PADDING_SIZE); nal->data = dst; nal->size = di; nal->raw_data = src; nal->raw_size = si; return si; }
false
FFmpeg
cc13bc8c4f0f4afa30d0b94c3f3a369ccd2aaf0b
388
static int encode_mode(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, AVPicture *scratch_pict, strip_info *info, unsigned char *buf) { int x, y, z, flags, bits, temp_size, header_ofs, ret = 0, mb_count = s->w * h / MB_AREA; int needs_extra_bit, should_write_temp; unsigned char temp[64]; //32/2 = 16 V4 blocks at 4 B each -> 64 B mb_info *mb; AVPicture sub_scratch; //encode codebooks if(v1_size) ret += encode_codebook(s, info->v1_codebook, v1_size, 0x22, 0x26, buf + ret); if(v4_size) ret += encode_codebook(s, info->v4_codebook, v4_size, 0x20, 0x24, buf + ret); //update scratch picture for(z = y = 0; y < h; y += MB_SIZE) { for(x = 0; x < s->w; x += MB_SIZE, z++) { mb = &s->mb[z]; if(mode == MODE_MC && mb->best_encoding == ENC_SKIP) continue; get_sub_picture(s, x, y, scratch_pict, &sub_scratch); if(mode == MODE_V1_ONLY || mb->best_encoding == ENC_V1) decode_v1_vector(s, &sub_scratch, mb, info); else if(mode != MODE_V1_ONLY && mb->best_encoding == ENC_V4) decode_v4_vector(s, &sub_scratch, mb->v4_vector[v4], info); } } switch(mode) { case MODE_V1_ONLY: //av_log(s->avctx, AV_LOG_INFO, "mb_count = %i\n", mb_count); ret += write_chunk_header(buf + ret, 0x32, mb_count); for(x = 0; x < mb_count; x++) buf[ret++] = s->mb[x].v1_vector; break; case MODE_V1_V4: //remember header position header_ofs = ret; ret += CHUNK_HEADER_SIZE; for(x = 0; x < mb_count; x += 32) { flags = 0; for(y = x; y < FFMIN(x+32, mb_count); y++) if(s->mb[y].best_encoding == ENC_V4) flags |= 1 << (31 - y + x); AV_WB32(&buf[ret], flags); ret += 4; for(y = x; y < FFMIN(x+32, mb_count); y++) { mb = &s->mb[y]; if(mb->best_encoding == ENC_V1) buf[ret++] = mb->v1_vector; else for(z = 0; z < 4; z++) buf[ret++] = mb->v4_vector[v4][z]; } } write_chunk_header(buf + header_ofs, 0x30, ret - header_ofs - CHUNK_HEADER_SIZE); break; case MODE_MC: //remember header position header_ofs = ret; ret += CHUNK_HEADER_SIZE; flags = bits = temp_size = 0; for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; flags |= (mb->best_encoding != ENC_SKIP) << (31 - bits++); needs_extra_bit = 0; should_write_temp = 0; if(mb->best_encoding != ENC_SKIP) { if(bits < 32) flags |= (mb->best_encoding == ENC_V4) << (31 - bits++); else needs_extra_bit = 1; } if(bits == 32) { AV_WB32(&buf[ret], flags); ret += 4; flags = bits = 0; if(mb->best_encoding == ENC_SKIP || needs_extra_bit) { memcpy(&buf[ret], temp, temp_size); ret += temp_size; temp_size = 0; } else should_write_temp = 1; } if(needs_extra_bit) { flags = (mb->best_encoding == ENC_V4) << 31; bits = 1; } if(mb->best_encoding == ENC_V1) temp[temp_size++] = mb->v1_vector; else if(mb->best_encoding == ENC_V4) for(z = 0; z < 4; z++) temp[temp_size++] = mb->v4_vector[v4][z]; if(should_write_temp) { memcpy(&buf[ret], temp, temp_size); ret += temp_size; temp_size = 0; } } if(bits > 0) { AV_WB32(&buf[ret], flags); ret += 4; memcpy(&buf[ret], temp, temp_size); ret += temp_size; } write_chunk_header(buf + header_ofs, 0x31, ret - header_ofs - CHUNK_HEADER_SIZE); break; } return ret; }
true
FFmpeg
7da9f4523159670d577a2808d4481e64008a8894
389
static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = &s->pb; SmackerContext *smk = (SmackerContext *)s->priv_data; AVStream *st, *ast[7]; int i, ret; int tbase; /* read and check header */ smk->magic = get_le32(pb); if (smk->magic != MKTAG('S', 'M', 'K', '2') && smk->magic != MKTAG('S', 'M', 'K', '4')) smk->width = get_le32(pb); smk->height = get_le32(pb); smk->frames = get_le32(pb); smk->pts_inc = (int32_t)get_le32(pb); smk->flags = get_le32(pb); for(i = 0; i < 7; i++) smk->audio[i] = get_le32(pb); smk->treesize = get_le32(pb); smk->mmap_size = get_le32(pb); smk->mclr_size = get_le32(pb); smk->full_size = get_le32(pb); smk->type_size = get_le32(pb); for(i = 0; i < 7; i++) smk->rates[i] = get_le32(pb); smk->pad = get_le32(pb); /* setup data */ if(smk->frames > 0xFFFFFF) { av_log(s, AV_LOG_ERROR, "Too many frames: %i\n", smk->frames); smk->frm_size = av_malloc(smk->frames * 4); smk->frm_flags = av_malloc(smk->frames); smk->is_ver4 = (smk->magic != MKTAG('S', 'M', 'K', '2')); /* read frame info */ for(i = 0; i < smk->frames; i++) { smk->frm_size[i] = get_le32(pb); for(i = 0; i < smk->frames; i++) { smk->frm_flags[i] = get_byte(pb); /* init video codec */ st = av_new_stream(s, 0); if (!st) smk->videoindex = st->index; st->codec->width = smk->width; st->codec->height = smk->height; st->codec->pix_fmt = PIX_FMT_PAL8; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_SMACKVIDEO; st->codec->codec_tag = smk->is_ver4; /* Smacker uses 100000 as internal timebase */ if(smk->pts_inc < 0) smk->pts_inc = -smk->pts_inc; else smk->pts_inc *= 100; tbase = 100000; av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1); av_set_pts_info(st, 33, smk->pts_inc, tbase); /* handle possible audio streams */ for(i = 0; i < 7; i++) { smk->indexes[i] = -1; if((smk->rates[i] & 0xFFFFFF) && !(smk->rates[i] & SMK_AUD_BINKAUD)){ ast[i] = av_new_stream(s, 0); smk->indexes[i] = ast[i]->index; av_set_pts_info(ast[i], 33, smk->pts_inc, tbase); ast[i]->codec->codec_type = CODEC_TYPE_AUDIO; ast[i]->codec->codec_id = (smk->rates[i] & SMK_AUD_PACKED) ? CODEC_ID_SMACKAUDIO : CODEC_ID_PCM_U8; ast[i]->codec->codec_tag = 0; ast[i]->codec->channels = (smk->rates[i] & SMK_AUD_STEREO) ? 2 : 1; ast[i]->codec->sample_rate = smk->rates[i] & 0xFFFFFF; ast[i]->codec->bits_per_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8; if(ast[i]->codec->bits_per_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8) ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE; /* load trees to extradata, they will be unpacked by decoder */ st->codec->extradata = av_malloc(smk->treesize + 16); st->codec->extradata_size = smk->treesize + 16; if(!st->codec->extradata){ av_log(s, AV_LOG_ERROR, "Cannot allocate %i bytes of extradata\n", smk->treesize + 16); av_free(smk->frm_size); av_free(smk->frm_flags); ret = get_buffer(pb, st->codec->extradata + 16, st->codec->extradata_size - 16); if(ret != st->codec->extradata_size - 16){ av_free(smk->frm_size); av_free(smk->frm_flags); return AVERROR_IO; ((int32_t*)st->codec->extradata)[0] = le2me_32(smk->mmap_size); ((int32_t*)st->codec->extradata)[1] = le2me_32(smk->mclr_size); ((int32_t*)st->codec->extradata)[2] = le2me_32(smk->full_size); ((int32_t*)st->codec->extradata)[3] = le2me_32(smk->type_size); smk->curstream = -1; smk->nextpos = url_ftell(pb); return 0;
true
FFmpeg
a443a2530d00b7019269202ac0f5ca8ba0a021c7
392
static void pci_edu_realize(PCIDevice *pdev, Error **errp) { EduState *edu = DO_UPCAST(EduState, pdev, pdev); uint8_t *pci_conf = pdev->config; timer_init_ms(&edu->dma_timer, QEMU_CLOCK_VIRTUAL, edu_dma_timer, edu); qemu_mutex_init(&edu->thr_mutex); qemu_cond_init(&edu->thr_cond); qemu_thread_create(&edu->thread, "edu", edu_fact_thread, edu, QEMU_THREAD_JOINABLE); pci_config_set_interrupt_pin(pci_conf, 1); if (msi_init(pdev, 0, 1, true, false, errp)) { return; } memory_region_init_io(&edu->mmio, OBJECT(edu), &edu_mmio_ops, edu, "edu-mmio", 1 << 20); pci_register_bar(pdev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &edu->mmio); }
true
qemu
c25a67f0c3d0c86231f9653267a222c4effa706f
393
uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t size, Error **errp) { GSList *list = NULL, *item; uint64_t new_addr, ret = 0; uint64_t address_space_end = address_space_start + address_space_size; assert(address_space_end > address_space_size); object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list); if (hint) { new_addr = *hint; } else { new_addr = address_space_start; } /* find address range that will fit new DIMM */ for (item = list; item; item = g_slist_next(item)) { PCDIMMDevice *dimm = item->data; uint64_t dimm_size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, errp); if (errp && *errp) { goto out; } if (ranges_overlap(dimm->addr, dimm_size, new_addr, size)) { if (hint) { DeviceState *d = DEVICE(dimm); error_setg(errp, "address range conflicts with '%s'", d->id); goto out; } new_addr = dimm->addr + dimm_size; } } ret = new_addr; if (new_addr < address_space_start) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 "] at 0x%" PRIx64, new_addr, size, address_space_start); } else if ((new_addr + size) > address_space_end) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 "] beyond 0x%" PRIx64, new_addr, size, address_space_end); } out: g_slist_free(list); return ret; }
true
qemu
9b79a76cdbb43b0b00aaf6e9421298842fc68841
394
static int wma_decode_block(WMACodecContext *s) { int n, v, a, ch, bsize; int coef_nb_bits, total_gain; int nb_coefs[MAX_CHANNELS]; float mdct_norm; FFTContext *mdct; #ifdef TRACE tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num); #endif /* compute current block length */ if (s->use_variable_block_len) { n = av_log2(s->nb_block_sizes - 1) + 1; if (s->reset_block_lengths) { s->reset_block_lengths = 0; v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes){ av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; s->prev_block_len_bits = s->frame_len_bits - v; v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes){ av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; s->block_len_bits = s->frame_len_bits - v; } else { /* update block lengths */ s->prev_block_len_bits = s->block_len_bits; s->block_len_bits = s->next_block_len_bits; v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes){ av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; s->next_block_len_bits = s->frame_len_bits - v; } else { /* fixed block len */ s->next_block_len_bits = s->frame_len_bits; s->prev_block_len_bits = s->frame_len_bits; s->block_len_bits = s->frame_len_bits; if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){ av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n"); return -1; /* now check if the block length is coherent with the frame length */ s->block_len = 1 << s->block_len_bits; if ((s->block_pos + s->block_len) > s->frame_len){ av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n"); return -1; if (s->avctx->channels == 2) { s->ms_stereo = get_bits1(&s->gb); v = 0; for(ch = 0; ch < s->avctx->channels; ch++) { a = get_bits1(&s->gb); s->channel_coded[ch] = a; v |= a; bsize = s->frame_len_bits - s->block_len_bits; /* if no channel coded, no need to go further */ /* XXX: fix potential framing problems */ if (!v) goto next; /* read total gain and extract corresponding number of bits for coef escape coding */ total_gain = 1; for(;;) { a = get_bits(&s->gb, 7); total_gain += a; if (a != 127) break; coef_nb_bits= ff_wma_total_gain_to_bits(total_gain); /* compute number of coefficients */ n = s->coefs_end[bsize] - s->coefs_start; for(ch = 0; ch < s->avctx->channels; ch++) nb_coefs[ch] = n; /* complex coding */ if (s->use_noise_coding) { for(ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { int i, n, a; n = s->exponent_high_sizes[bsize]; for(i=0;i<n;i++) { a = get_bits1(&s->gb); s->high_band_coded[ch][i] = a; /* if noise coding, the coefficients are not transmitted */ if (a) nb_coefs[ch] -= s->exponent_high_bands[bsize][i]; for(ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { int i, n, val, code; n = s->exponent_high_sizes[bsize]; val = (int)0x80000000; for(i=0;i<n;i++) { if (s->high_band_coded[ch][i]) { if (val == (int)0x80000000) { val = get_bits(&s->gb, 7) - 19; } else { code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX); if (code < 0){ av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n"); return -1; val += code - 18; s->high_band_values[ch][i] = val; /* exponents can be reused in short blocks. */ if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) { for(ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { if (decode_exp_vlc(s, ch) < 0) return -1; } else { decode_exp_lsp(s, ch); s->exponents_bsize[ch] = bsize; /* parse spectral coefficients : just RLE encoding */ for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { int tindex; WMACoef* ptr = &s->coefs1[ch][0]; /* special VLC tables are used for ms stereo because there is potentially less energy there */ tindex = (ch == 1 && s->ms_stereo); memset(ptr, 0, s->block_len * sizeof(WMACoef)); ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex], s->level_table[tindex], s->run_table[tindex], 0, ptr, 0, nb_coefs[ch], s->block_len, s->frame_len_bits, coef_nb_bits); if (s->version == 1 && s->avctx->channels >= 2) { align_get_bits(&s->gb); /* normalize */ { int n4 = s->block_len / 2; mdct_norm = 1.0 / (float)n4; if (s->version == 1) { mdct_norm *= sqrt(n4); /* finally compute the MDCT coefficients */ for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { WMACoef *coefs1; float *coefs, *exponents, mult, mult1, noise; int i, j, n, n1, last_high_band, esize; float exp_power[HIGH_BAND_MAX_SIZE]; coefs1 = s->coefs1[ch]; exponents = s->exponents[ch]; esize = s->exponents_bsize[ch]; mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; mult *= mdct_norm; coefs = s->coefs[ch]; if (s->use_noise_coding) { mult1 = mult; /* very low freqs : noise */ for(i = 0;i < s->coefs_start; i++) { *coefs++ = s->noise_table[s->noise_index] * exponents[i<<bsize>>esize] * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); n1 = s->exponent_high_sizes[bsize]; /* compute power of high bands */ exponents = s->exponents[ch] + (s->high_band_start[bsize]<<bsize>>esize); last_high_band = 0; /* avoid warning */ for(j=0;j<n1;j++) { n = s->exponent_high_bands[s->frame_len_bits - s->block_len_bits][j]; if (s->high_band_coded[ch][j]) { float e2, v; e2 = 0; for(i = 0;i < n; i++) { v = exponents[i<<bsize>>esize]; e2 += v * v; exp_power[j] = e2 / n; last_high_band = j; tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n); exponents += n<<bsize>>esize; /* main freqs and high freqs */ exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize); for(j=-1;j<n1;j++) { if (j < 0) { n = s->high_band_start[bsize] - s->coefs_start; } else { n = s->exponent_high_bands[s->frame_len_bits - s->block_len_bits][j]; if (j >= 0 && s->high_band_coded[ch][j]) { /* use noise with specified power */ mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); /* XXX: use a table */ mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05); mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult); mult1 *= mdct_norm; for(i = 0;i < n; i++) { noise = s->noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ = noise * exponents[i<<bsize>>esize] * mult1; exponents += n<<bsize>>esize; } else { /* coded values + small noise */ for(i = 0;i < n; i++) { noise = s->noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ = ((*coefs1++) + noise) * exponents[i<<bsize>>esize] * mult; exponents += n<<bsize>>esize; /* very high freqs : noise */ n = s->block_len - s->coefs_end[bsize]; mult1 = mult * exponents[((-1<<bsize))>>esize]; for(i = 0; i < n; i++) { *coefs++ = s->noise_table[s->noise_index] * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); } else { /* XXX: optimize more */ for(i = 0;i < s->coefs_start; i++) *coefs++ = 0.0; n = nb_coefs[ch]; for(i = 0;i < n; i++) { *coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult; n = s->block_len - s->coefs_end[bsize]; for(i = 0;i < n; i++) *coefs++ = 0.0; #ifdef TRACE for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len); dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len); #endif if (s->ms_stereo && s->channel_coded[1]) { /* nominal case for ms stereo: we do it before mdct */ /* no need to optimize this case because it should almost never happen */ if (!s->channel_coded[0]) { tprintf(s->avctx, "rare ms-stereo case happened\n"); memset(s->coefs[0], 0, sizeof(float) * s->block_len); s->channel_coded[0] = 1; s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len); next: mdct = &s->mdct_ctx[bsize]; for (ch = 0; ch < s->avctx->channels; ch++) { int n4, index; n4 = s->block_len / 2; if(s->channel_coded[ch]){ mdct->imdct_calc(mdct, s->output, s->coefs[ch]); }else if(!(s->ms_stereo && ch==1)) memset(s->output, 0, sizeof(s->output)); /* multiply by the window and add in the frame */ index = (s->frame_len / 2) + s->block_pos - n4; wma_window(s, &s->frame_out[ch][index]); /* update block number */ s->block_num++; s->block_pos += s->block_len; if (s->block_pos >= s->frame_len) return 1; else return 0;
true
FFmpeg
ec8a4841f7e81040f9a2757f23e70dff5e6b33a4
397
static int floppy_probe_device(const char *filename) { int fd, ret; int prio = 0; struct floppy_struct fdparam; struct stat st; if (strstart(filename, "/dev/fd", NULL)) prio = 50; fd = open(filename, O_RDONLY | O_NONBLOCK); if (fd < 0) { goto out; } ret = fstat(fd, &st); if (ret == -1 || !S_ISBLK(st.st_mode)) { goto outc; } /* Attempt to detect via a floppy specific ioctl */ ret = ioctl(fd, FDGETPRM, &fdparam); if (ret >= 0) prio = 100; outc: close(fd); out: return prio; }
false
qemu
e17408283562be359f16a7e12ddfee7509d6fe11
398
struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) { struct XenDevice *xendev; TAILQ_FOREACH(xendev, &xendevs, next) { if (xendev->dom != dom) continue; if (xendev->dev != dev) continue; if (strcmp(xendev->type, type) != 0) continue; return xendev; } return NULL; }
false
qemu
72cf2d4f0e181d0d3a3122e04129c58a95da713e
400
static void dct_unquantize_mpeg1_mmx(MpegEncContext *s, DCTELEM *block, int n, int qscale) { int i, level; const UINT16 *quant_matrix; if (s->mb_intra) { if (n < 4) block[0] = block[0] * s->y_dc_scale; else block[0] = block[0] * s->c_dc_scale; if (s->out_format == FMT_H263) { i = 1; goto unquant_even; } /* XXX: only mpeg1 */ quant_matrix = s->intra_matrix; i=1; /* Align on 4 elements boundary */ while(i&3) { level = block[i]; if (level) { if (level < 0) level = -level; level = (int)(level * qscale * quant_matrix[i]) >> 3; level = (level - 1) | 1; if (block[i] < 0) level = -level; block[i] = level; } i++; } __asm __volatile( "movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */ "punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */ "movq %2, %%mm4\n\t" "movq %%mm6, %%mm7\n\t" "movq %1, %%mm5\n\t" "packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */ "pxor %%mm6, %%mm6\n\t" ::"g"(qscale),"m"(mm_wone),"m"(mm_wabs):"memory"); for(;i<64;i+=4) { __asm __volatile( "movq %1, %%mm0\n\t" "movq %%mm7, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm0, %%mm3\n\t" "pcmpgtw %%mm6, %%mm2\n\t" "pmullw %2, %%mm1\n\t" "pandn %%mm4, %%mm2\n\t" "por %%mm5, %%mm2\n\t" "pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */ "pcmpeqw %%mm6, %%mm3\n\t" "pmullw %%mm0, %%mm1\n\t" "psraw $3, %%mm1\n\t" "psubw %%mm5, %%mm1\n\t" /* block[i] --; */ "pandn %%mm4, %%mm3\n\t" /* fake of pcmpneqw : mm0 != 0 then mm1 = -1 */ "por %%mm5, %%mm1\n\t" /* block[i] |= 1 */ "pmullw %%mm2, %%mm1\n\t" /* change signs again */ "pand %%mm3, %%mm1\n\t" /* nullify if was zero */ "movq %%mm1, %0" :"=m"(block[i]) :"m"(block[i]), "m"(quant_matrix[i]) :"memory"); } } else { i = 0; unquant_even: quant_matrix = s->non_intra_matrix; /* Align on 4 elements boundary */ while(i&7) { level = block[i]; if (level) { if (level < 0) level = -level; level = (((level << 1) + 1) * qscale * ((int) quant_matrix[i])) >> 4; level = (level - 1) | 1; if(block[i] < 0) level = -level; block[i] = level; } i++; } asm volatile( "pcmpeqw %%mm7, %%mm7 \n\t" "psrlw $15, %%mm7 \n\t" "movd %2, %%mm6 \n\t" "packssdw %%mm6, %%mm6 \n\t" "packssdw %%mm6, %%mm6 \n\t" "1: \n\t" "movq (%0, %3), %%mm0 \n\t" "movq 8(%0, %3), %%mm1 \n\t" "movq (%1, %3), %%mm4 \n\t" "movq 8(%1, %3), %%mm5 \n\t" "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i] "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i] "pxor %%mm2, %%mm2 \n\t" "pxor %%mm3, %%mm3 \n\t" "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0 "pxor %%mm2, %%mm0 \n\t" "pxor %%mm3, %%mm1 \n\t" "psubw %%mm2, %%mm0 \n\t" // abs(block[i]) "psubw %%mm3, %%mm1 \n\t" // abs(block[i]) "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2 "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2 "paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1 "paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1 "pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q "pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q "pxor %%mm4, %%mm4 \n\t" "pxor %%mm5, %%mm5 \n\t" // FIXME slow "pcmpeqw (%0, %3), %%mm4 \n\t" // block[i] == 0 ? -1 : 0 "pcmpeqw 8(%0, %3), %%mm5 \n\t" // block[i] == 0 ? -1 : 0 "psraw $4, %%mm0 \n\t" "psraw $4, %%mm1 \n\t" "psubw %%mm7, %%mm0 \n\t" "psubw %%mm7, %%mm1 \n\t" "por %%mm7, %%mm0 \n\t" "por %%mm7, %%mm1 \n\t" "pxor %%mm2, %%mm0 \n\t" "pxor %%mm3, %%mm1 \n\t" "psubw %%mm2, %%mm0 \n\t" "psubw %%mm3, %%mm1 \n\t" "pandn %%mm0, %%mm4 \n\t" "pandn %%mm1, %%mm5 \n\t" "movq %%mm4, (%0, %3) \n\t" "movq %%mm5, 8(%0, %3) \n\t" "addl $16, %3 \n\t" "cmpl $128, %3 \n\t" "jb 1b \n\t" ::"r" (block), "r"(quant_matrix), "g" (qscale), "r" (2*i) : "memory" ); #if 0 __asm __volatile( "movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */ "punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */ "movq %2, %%mm4\n\t" "movq %%mm6, %%mm7\n\t" "movq %1, %%mm5\n\t" "packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */ "pxor %%mm6, %%mm6\n\t" ::"g"(qscale),"m"(mm_wone),"m"(mm_wabs)); for(;i<64;i+=4) { __asm __volatile( "movq %1, %%mm0\n\t" "movq %%mm7, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm0, %%mm3\n\t" "pcmpgtw %%mm6, %%mm2\n\t" "pmullw %2, %%mm1\n\t" "pandn %%mm4, %%mm2\n\t" "por %%mm5, %%mm2\n\t" "pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */ "psllw $1, %%mm0\n\t" /* block[i] <<= 1 */ "paddw %%mm5, %%mm0\n\t" /* block[i] ++ */ "pmullw %%mm0, %%mm1\n\t" "psraw $4, %%mm1\n\t" "pcmpeqw %%mm6, %%mm3\n\t" "psubw %%mm5, %%mm1\n\t" /* block[i] --; */ "pandn %%mm4, %%mm3\n\t" /* fake of pcmpneqw : mm0 != 0 then mm1 = -1 */ "por %%mm5, %%mm1\n\t" /* block[i] |= 1 */ "pmullw %%mm2, %%mm1\n\t" /* change signs again */ "pand %%mm3, %%mm1\n\t" /* nullify if was zero */ "movq %%mm1, %0" :"=m"(block[i]) :"m"(block[i]), "m"(quant_matrix[i])); } #endif } }
false
FFmpeg
f12e206b4737b84afa6071f4b464664a50b0c916
401
static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock *info, VqInfoBlockLegacy *linfo) { VirtIODevice *vdev = virtio_ccw_get_vdev(sch); uint16_t index = info ? info->index : linfo->index; uint16_t num = info ? info->num : linfo->num; uint64_t desc = info ? info->desc : linfo->queue; if (index >= VIRTIO_CCW_QUEUE_MAX) { return -EINVAL; } /* Current code in virtio.c relies on 4K alignment. */ if (linfo && desc && (linfo->align != 4096)) { return -EINVAL; } if (!vdev) { return -EINVAL; } if (info) { virtio_queue_set_rings(vdev, index, desc, info->avail, info->used); } else { virtio_queue_set_addr(vdev, index, desc); } if (!desc) { virtio_queue_set_vector(vdev, index, VIRTIO_NO_VECTOR); } else { if (info) { /* virtio-1 allows changing the ring size. */ if (virtio_queue_get_max_num(vdev, index) < num) { /* Fail if we exceed the maximum number. */ return -EINVAL; } virtio_queue_set_num(vdev, index, num); } else if (virtio_queue_get_num(vdev, index) > num) { /* Fail if we don't have a big enough queue. */ return -EINVAL; } /* We ignore possible increased num for legacy for compatibility. */ virtio_queue_set_vector(vdev, index, index); } /* tell notify handler in case of config change */ vdev->config_vector = VIRTIO_CCW_QUEUE_MAX; return 0; }
false
qemu
b1914b824ade1706847428e64ef5637ffc0ae238
403
void qemu_system_debug_request(void) { debug_requested = 1; vm_stop(VMSTOP_DEBUG); }
false
qemu
83f338f73ecb88cc6f85d6e7b81ebef112ce07be
405
static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags) { return bdrv_co_pwrite_zeroes(bs->file->bs, offset, count, flags); }
false
qemu
a03ef88f77af045a2eb9629b5ce774a3fb973c5e
406
void monitor_flush(Monitor *mon) { int i; if (term_outbuf_index > 0) { for (i = 0; i < MAX_MON; i++) if (monitor_hd[i] && monitor_hd[i]->focus == 0) qemu_chr_write(monitor_hd[i], term_outbuf, term_outbuf_index); term_outbuf_index = 0; } }
false
qemu
871271615108fd58273423d98b7cefe08e6f75a0
407
void qemu_co_queue_restart_all(CoQueue *queue) { while (qemu_co_queue_next(queue)) { /* Do nothing */ } }
false
qemu
28f082469650a0f4c0e37b4ccd6f9514b1a0698d
408
static void nvdimm_dsm_func_read_fit(AcpiNVDIMMState *state, NvdimmDsmIn *in, hwaddr dsm_mem_addr) { NvdimmFitBuffer *fit_buf = &state->fit_buf; NvdimmFuncReadFITIn *read_fit; NvdimmFuncReadFITOut *read_fit_out; GArray *fit; uint32_t read_len = 0, func_ret_status; int size; read_fit = (NvdimmFuncReadFITIn *)in->arg3; le32_to_cpus(&read_fit->offset); qemu_mutex_lock(&fit_buf->lock); fit = fit_buf->fit; nvdimm_debug("Read FIT: offset %#x FIT size %#x Dirty %s.\n", read_fit->offset, fit->len, fit_buf->dirty ? "Yes" : "No"); if (read_fit->offset > fit->len) { func_ret_status = 3 /* Invalid Input Parameters */; goto exit; } /* It is the first time to read FIT. */ if (!read_fit->offset) { fit_buf->dirty = false; } else if (fit_buf->dirty) { /* FIT has been changed during RFIT. */ func_ret_status = 0x100 /* fit changed */; goto exit; } func_ret_status = 0 /* Success */; read_len = MIN(fit->len - read_fit->offset, 4096 - sizeof(NvdimmFuncReadFITOut)); exit: size = sizeof(NvdimmFuncReadFITOut) + read_len; read_fit_out = g_malloc(size); read_fit_out->len = cpu_to_le32(size); read_fit_out->func_ret_status = cpu_to_le32(func_ret_status); memcpy(read_fit_out->fit, fit->data + read_fit->offset, read_len); cpu_physical_memory_write(dsm_mem_addr, read_fit_out, size); g_free(read_fit_out); qemu_mutex_unlock(&fit_buf->lock); }
false
qemu
12f86b5b3e1bdf75e0a467d771c16cc42f3a1f1a
409
static void tftp_send_error(struct tftp_session *spt, uint16_t errorcode, const char *msg, struct tftp_t *recv_tp) { struct sockaddr_in saddr, daddr; struct mbuf *m; struct tftp_t *tp; m = m_get(spt->slirp); if (!m) { goto out; } memset(m->m_data, 0, m->m_size); m->m_data += IF_MAXLINKHDR; tp = (void *)m->m_data; m->m_data += sizeof(struct udpiphdr); tp->tp_op = htons(TFTP_ERROR); tp->x.tp_error.tp_error_code = htons(errorcode); pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg); saddr.sin_addr = recv_tp->ip.ip_dst; saddr.sin_port = recv_tp->udp.uh_dport; daddr.sin_addr = spt->client_ip; daddr.sin_port = spt->client_port; m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) - sizeof(struct ip) - sizeof(struct udphdr); udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); out: tftp_session_terminate(spt); }
false
qemu
5379229a2708df3a1506113315214c3ce5325859
410
static void omap_rtc_alarm_update(struct omap_rtc_s *s) { s->alarm_ti = mktimegm(&s->alarm_tm); if (s->alarm_ti == -1) printf("%s: conversion failed\n", __FUNCTION__); }
false
qemu
a89f364ae8740dfc31b321eed9ee454e996dc3c1
411
static int http_send_data(HTTPContext *c) { int len, ret; for(;;) { if (c->buffer_ptr >= c->buffer_end) { ret = http_prepare_data(c); if (ret < 0) return -1; else if (ret != 0) /* state change requested */ break; } else { if (c->is_packetized) { /* RTP data output */ len = c->buffer_end - c->buffer_ptr; if (len < 4) { /* fail safe - should never happen */ fail1: c->buffer_ptr = c->buffer_end; return 0; } len = (c->buffer_ptr[0] << 24) | (c->buffer_ptr[1] << 16) | (c->buffer_ptr[2] << 8) | (c->buffer_ptr[3]); if (len > (c->buffer_end - c->buffer_ptr)) goto fail1; if ((get_packet_send_clock(c) - get_server_clock(c)) > 0) { /* nothing to send yet: we can wait */ return 0; } c->data_count += len; update_datarate(&c->datarate, c->data_count); if (c->stream) c->stream->bytes_served += len; if (c->rtp_protocol == RTSP_LOWER_TRANSPORT_TCP) { /* RTP packets are sent inside the RTSP TCP connection */ AVIOContext *pb; int interleaved_index, size; uint8_t header[4]; HTTPContext *rtsp_c; rtsp_c = c->rtsp_c; /* if no RTSP connection left, error */ if (!rtsp_c) return -1; /* if already sending something, then wait. */ if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST) break; if (avio_open_dyn_buf(&pb) < 0) goto fail1; interleaved_index = c->packet_stream_index * 2; /* RTCP packets are sent at odd indexes */ if (c->buffer_ptr[1] == 200) interleaved_index++; /* write RTSP TCP header */ header[0] = '$'; header[1] = interleaved_index; header[2] = len >> 8; header[3] = len; avio_write(pb, header, 4); /* write RTP packet data */ c->buffer_ptr += 4; avio_write(pb, c->buffer_ptr, len); size = avio_close_dyn_buf(pb, &c->packet_buffer); /* prepare asynchronous TCP sending */ rtsp_c->packet_buffer_ptr = c->packet_buffer; rtsp_c->packet_buffer_end = c->packet_buffer + size; c->buffer_ptr += len; /* send everything we can NOW */ len = send(rtsp_c->fd, rtsp_c->packet_buffer_ptr, rtsp_c->packet_buffer_end - rtsp_c->packet_buffer_ptr, 0); if (len > 0) rtsp_c->packet_buffer_ptr += len; if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) { /* if we could not send all the data, we will send it later, so a new state is needed to "lock" the RTSP TCP connection */ rtsp_c->state = RTSPSTATE_SEND_PACKET; break; } else /* all data has been sent */ av_freep(&c->packet_buffer); } else { /* send RTP packet directly in UDP */ c->buffer_ptr += 4; ffurl_write(c->rtp_handles[c->packet_stream_index], c->buffer_ptr, len); c->buffer_ptr += len; /* here we continue as we can send several packets per 10 ms slot */ } } else { /* TCP data output */ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { if (ff_neterrno() != AVERROR(EAGAIN) && ff_neterrno() != AVERROR(EINTR)) /* error : close connection */ return -1; else return 0; } else c->buffer_ptr += len; c->data_count += len; update_datarate(&c->datarate, c->data_count); if (c->stream) c->stream->bytes_served += len; break; } } } /* for(;;) */ return 0; }
false
FFmpeg
33d6f90e3e0241939ea0be9ca9e1f335942081c8
412
static inline bool vtd_iova_range_check(uint64_t iova, VTDContextEntry *ce) { /* * Check if @iova is above 2^X-1, where X is the minimum of MGAW * in CAP_REG and AW in context-entry. */ return !(iova & ~(vtd_iova_limit(ce) - 1)); }
false
qemu
37f51384ae05bd50f83308339dbffa3e78404874
413
DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) { const char *value; BlockBackend *blk; DriveInfo *dinfo = NULL; QDict *bs_opts; QemuOpts *legacy_opts; DriveMediaType media = MEDIA_DISK; BlockInterfaceType type; int cyls, heads, secs, translation; int max_devs, bus_id, unit_id, index; const char *devaddr; const char *werror, *rerror; bool read_only = false; bool copy_on_read; const char *serial; const char *filename; Error *local_err = NULL; int i; const char *deprecated[] = { "serial", "trans", "secs", "heads", "cyls", "addr" }; /* Change legacy command line options into QMP ones */ static const struct { const char *from; const char *to; } opt_renames[] = { { "iops", "throttling.iops-total" }, { "iops_rd", "throttling.iops-read" }, { "iops_wr", "throttling.iops-write" }, { "bps", "throttling.bps-total" }, { "bps_rd", "throttling.bps-read" }, { "bps_wr", "throttling.bps-write" }, { "iops_max", "throttling.iops-total-max" }, { "iops_rd_max", "throttling.iops-read-max" }, { "iops_wr_max", "throttling.iops-write-max" }, { "bps_max", "throttling.bps-total-max" }, { "bps_rd_max", "throttling.bps-read-max" }, { "bps_wr_max", "throttling.bps-write-max" }, { "iops_size", "throttling.iops-size" }, { "group", "throttling.group" }, { "readonly", BDRV_OPT_READ_ONLY }, }; for (i = 0; i < ARRAY_SIZE(opt_renames); i++) { qemu_opt_rename(all_opts, opt_renames[i].from, opt_renames[i].to, &local_err); if (local_err) { error_report_err(local_err); return NULL; } } value = qemu_opt_get(all_opts, "cache"); if (value) { int flags = 0; bool writethrough; if (bdrv_parse_cache_mode(value, &flags, &writethrough) != 0) { error_report("invalid cache option"); return NULL; } /* Specific options take precedence */ if (!qemu_opt_get(all_opts, BDRV_OPT_CACHE_WB)) { qemu_opt_set_bool(all_opts, BDRV_OPT_CACHE_WB, !writethrough, &error_abort); } if (!qemu_opt_get(all_opts, BDRV_OPT_CACHE_DIRECT)) { qemu_opt_set_bool(all_opts, BDRV_OPT_CACHE_DIRECT, !!(flags & BDRV_O_NOCACHE), &error_abort); } if (!qemu_opt_get(all_opts, BDRV_OPT_CACHE_NO_FLUSH)) { qemu_opt_set_bool(all_opts, BDRV_OPT_CACHE_NO_FLUSH, !!(flags & BDRV_O_NO_FLUSH), &error_abort); } qemu_opt_unset(all_opts, "cache"); } /* Get a QDict for processing the options */ bs_opts = qdict_new(); qemu_opts_to_qdict(all_opts, bs_opts); legacy_opts = qemu_opts_create(&qemu_legacy_drive_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err); if (local_err) { error_report_err(local_err); goto fail; } /* Deprecated option boot=[on|off] */ if (qemu_opt_get(legacy_opts, "boot") != NULL) { fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be " "ignored. Future versions will reject this parameter. Please " "update your scripts.\n"); } /* Other deprecated options */ if (!qtest_enabled()) { for (i = 0; i < ARRAY_SIZE(deprecated); i++) { if (qemu_opt_get(legacy_opts, deprecated[i]) != NULL) { error_report("'%s' is deprecated, please use the corresponding " "option of '-device' instead", deprecated[i]); } } } /* Media type */ value = qemu_opt_get(legacy_opts, "media"); if (value) { if (!strcmp(value, "disk")) { media = MEDIA_DISK; } else if (!strcmp(value, "cdrom")) { media = MEDIA_CDROM; read_only = true; } else { error_report("'%s' invalid media", value); goto fail; } } /* copy-on-read is disabled with a warning for read-only devices */ read_only |= qemu_opt_get_bool(legacy_opts, BDRV_OPT_READ_ONLY, false); copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false); if (read_only && copy_on_read) { error_report("warning: disabling copy-on-read on read-only drive"); copy_on_read = false; } qdict_put_str(bs_opts, BDRV_OPT_READ_ONLY, read_only ? "on" : "off"); qdict_put_str(bs_opts, "copy-on-read", copy_on_read ? "on" : "off"); /* Controller type */ value = qemu_opt_get(legacy_opts, "if"); if (value) { for (type = 0; type < IF_COUNT && strcmp(value, if_name[type]); type++) { } if (type == IF_COUNT) { error_report("unsupported bus type '%s'", value); goto fail; } } else { type = block_default_type; } /* Geometry */ cyls = qemu_opt_get_number(legacy_opts, "cyls", 0); heads = qemu_opt_get_number(legacy_opts, "heads", 0); secs = qemu_opt_get_number(legacy_opts, "secs", 0); if (cyls || heads || secs) { if (cyls < 1) { error_report("invalid physical cyls number"); goto fail; } if (heads < 1) { error_report("invalid physical heads number"); goto fail; } if (secs < 1) { error_report("invalid physical secs number"); goto fail; } } translation = BIOS_ATA_TRANSLATION_AUTO; value = qemu_opt_get(legacy_opts, "trans"); if (value != NULL) { if (!cyls) { error_report("'%s' trans must be used with cyls, heads and secs", value); goto fail; } if (!strcmp(value, "none")) { translation = BIOS_ATA_TRANSLATION_NONE; } else if (!strcmp(value, "lba")) { translation = BIOS_ATA_TRANSLATION_LBA; } else if (!strcmp(value, "large")) { translation = BIOS_ATA_TRANSLATION_LARGE; } else if (!strcmp(value, "rechs")) { translation = BIOS_ATA_TRANSLATION_RECHS; } else if (!strcmp(value, "auto")) { translation = BIOS_ATA_TRANSLATION_AUTO; } else { error_report("'%s' invalid translation type", value); goto fail; } } if (media == MEDIA_CDROM) { if (cyls || secs || heads) { error_report("CHS can't be set with media=cdrom"); goto fail; } } /* Device address specified by bus/unit or index. * If none was specified, try to find the first free one. */ bus_id = qemu_opt_get_number(legacy_opts, "bus", 0); unit_id = qemu_opt_get_number(legacy_opts, "unit", -1); index = qemu_opt_get_number(legacy_opts, "index", -1); max_devs = if_max_devs[type]; if (index != -1) { if (bus_id != 0 || unit_id != -1) { error_report("index cannot be used with bus and unit"); goto fail; } bus_id = drive_index_to_bus_id(type, index); unit_id = drive_index_to_unit_id(type, index); } if (unit_id == -1) { unit_id = 0; while (drive_get(type, bus_id, unit_id) != NULL) { unit_id++; if (max_devs && unit_id >= max_devs) { unit_id -= max_devs; bus_id++; } } } if (max_devs && unit_id >= max_devs) { error_report("unit %d too big (max is %d)", unit_id, max_devs - 1); goto fail; } if (drive_get(type, bus_id, unit_id) != NULL) { error_report("drive with bus=%d, unit=%d (index=%d) exists", bus_id, unit_id, index); goto fail; } /* Serial number */ serial = qemu_opt_get(legacy_opts, "serial"); /* no id supplied -> create one */ if (qemu_opts_id(all_opts) == NULL) { char *new_id; const char *mediastr = ""; if (type == IF_IDE || type == IF_SCSI) { mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; } if (max_devs) { new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id, mediastr, unit_id); } else { new_id = g_strdup_printf("%s%s%i", if_name[type], mediastr, unit_id); } qdict_put_str(bs_opts, "id", new_id); g_free(new_id); } /* Add virtio block device */ devaddr = qemu_opt_get(legacy_opts, "addr"); if (devaddr && type != IF_VIRTIO) { error_report("addr is not supported by this bus type"); goto fail; } if (type == IF_VIRTIO) { QemuOpts *devopts; devopts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, &error_abort); if (arch_type == QEMU_ARCH_S390X) { qemu_opt_set(devopts, "driver", "virtio-blk-ccw", &error_abort); } else { qemu_opt_set(devopts, "driver", "virtio-blk-pci", &error_abort); } qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"), &error_abort); if (devaddr) { qemu_opt_set(devopts, "addr", devaddr, &error_abort); } } filename = qemu_opt_get(legacy_opts, "file"); /* Check werror/rerror compatibility with if=... */ werror = qemu_opt_get(legacy_opts, "werror"); if (werror != NULL) { if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) { error_report("werror is not supported by this bus type"); goto fail; } qdict_put_str(bs_opts, "werror", werror); } rerror = qemu_opt_get(legacy_opts, "rerror"); if (rerror != NULL) { if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type != IF_NONE) { error_report("rerror is not supported by this bus type"); goto fail; } qdict_put_str(bs_opts, "rerror", rerror); } /* Actual block device init: Functionality shared with blockdev-add */ blk = blockdev_init(filename, bs_opts, &local_err); bs_opts = NULL; if (!blk) { if (local_err) { error_report_err(local_err); } goto fail; } else { assert(!local_err); } /* Create legacy DriveInfo */ dinfo = g_malloc0(sizeof(*dinfo)); dinfo->opts = all_opts; dinfo->cyls = cyls; dinfo->heads = heads; dinfo->secs = secs; dinfo->trans = translation; dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; dinfo->devaddr = devaddr; dinfo->serial = g_strdup(serial); blk_set_legacy_dinfo(blk, dinfo); switch(type) { case IF_IDE: case IF_SCSI: case IF_XEN: case IF_NONE: dinfo->media_cd = media == MEDIA_CDROM; break; default: break; } fail: qemu_opts_del(legacy_opts); QDECREF(bs_opts); return dinfo; }
false
qemu
3dc6f8693694a649a9c83f1e2746565b47683923
414
void qerror_report_internal(const char *file, int linenr, const char *func, const char *fmt, ...) { va_list va; QError *qerror; va_start(va, fmt); qerror = qerror_from_info(file, linenr, func, fmt, &va); va_end(va); if (cur_mon) { monitor_set_error(cur_mon, qerror); } else { qerror_print(qerror); QDECREF(qerror); } }
false
qemu
cde0fc7544ca590c83f349d4dcccf375d55d6042
415
static void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type) { Property *prop; prop = qdev_prop_find(dev, name); if (!prop) { fprintf(stderr, "%s: property \"%s.%s\" not found\n", __FUNCTION__, object_get_typename(OBJECT(dev)), name); abort(); } if (prop->info->type != type) { fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n", __FUNCTION__, object_get_typename(OBJECT(dev)), name); abort(); } qdev_prop_cpy(dev, prop, src); }
false
qemu
7a7aae21ccab06606cee9aba846d2e30cb616763
416
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value) { if (qdev_prop_set_drive(dev, name, value) < 0) { exit(1); } }
false
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
417
static int piix3_post_load(void *opaque, int version_id) { PIIX3State *piix3 = opaque; int pirq; /* Because the i8259 has not been deserialized yet, qemu_irq_raise * might bring the system to a different state than the saved one; * for example, the interrupt could be masked but the i8259 would * not know that yet and would trigger an interrupt in the CPU. * * Here, we update irq levels without raising the interrupt. * Interrupt state will be deserialized separately through the i8259. */ piix3->pic_levels = 0; for (pirq = 0; pirq < PIIX_NUM_PIRQS; pirq++) { piix3_set_irq_level_internal(piix3, pirq, pci_bus_get_irq_level(piix3->dev.bus, pirq)); } return 0; }
false
qemu
fd56e0612b6454a282fa6a953fdb09281a98c589
418
static void unset_dirty_tracking(void) { BlkMigDevState *bmds; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { aio_context_acquire(blk_get_aio_context(bmds->blk)); bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap); aio_context_release(blk_get_aio_context(bmds->blk)); } }
false
qemu
2119882c7eb7e2c612b24fc0c8d86f5887d6f1c3
419
static void cb_hmp_change_bdrv_pwd(Monitor *mon, const char *password, void *opaque) { Error *encryption_err = opaque; Error *err = NULL; const char *device; device = error_get_field(encryption_err, "device"); qmp_block_passwd(device, password, &err); hmp_handle_error(mon, &err); error_free(encryption_err); monitor_read_command(mon, 1); }
false
qemu
eef5ad1086403d8ac8d91208a0e8dc34734b671c
421
av_cold int ff_ivi_decode_close(AVCodecContext *avctx) { IVI45DecContext *ctx = avctx->priv_data; ivi_free_buffers(&ctx->planes[0]); if (ctx->mb_vlc.cust_tab.table) ff_free_vlc(&ctx->mb_vlc.cust_tab); #if IVI4_STREAM_ANALYSER if (ctx->is_indeo4) { if (ctx->is_scalable) av_log(avctx, AV_LOG_ERROR, "This video uses scalability mode!\n"); if (ctx->uses_tiling) av_log(avctx, AV_LOG_ERROR, "This video uses local decoding!\n"); if (ctx->has_b_frames) av_log(avctx, AV_LOG_ERROR, "This video contains B-frames!\n"); if (ctx->has_transp) av_log(avctx, AV_LOG_ERROR, "Transparency mode is enabled!\n"); if (ctx->uses_haar) av_log(avctx, AV_LOG_ERROR, "This video uses Haar transform!\n"); if (ctx->uses_fullpel) av_log(avctx, AV_LOG_ERROR, "This video uses fullpel motion vectors!\n"); } #endif av_frame_free(&ctx->p_frame); return 0; }
false
FFmpeg
6202e2fede75df92cbc374a3f7d6893d0c5ac721
422
static av_cold int cinepak_decode_init(AVCodecContext *avctx) { CinepakContext *s = avctx->priv_data; s->avctx = avctx; s->width = (avctx->width + 3) & ~3; s->height = (avctx->height + 3) & ~3; s->sega_film_skip_bytes = -1; /* uninitialized state */ // check for paletted data if (avctx->bits_per_coded_sample != 8) { s->palette_video = 0; avctx->pix_fmt = AV_PIX_FMT_YUV420P; } else { s->palette_video = 1; avctx->pix_fmt = AV_PIX_FMT_PAL8; } s->frame.data[0] = NULL; return 0; }
false
FFmpeg
3b199d29cd597a3518136d78860e172060b9e83d
423
static int xen_host_pci_config_open(XenHostPCIDevice *d) { char path[PATH_MAX]; int rc; rc = xen_host_pci_sysfs_path(d, "config", path, sizeof (path)); if (rc) { return rc; } d->config_fd = open(path, O_RDWR); if (d->config_fd < 0) { return -errno; } return 0; }
true
qemu
599d0c45615b7d099d256738a586d0f63bc707e6
424
void cpu_exec_init(CPUArchState *env) { CPUState *cpu = ENV_GET_CPU(env); CPUClass *cc = CPU_GET_CLASS(cpu); CPUState *some_cpu; int cpu_index; #if defined(CONFIG_USER_ONLY) cpu_list_lock(); #endif cpu_index = 0; CPU_FOREACH(some_cpu) { cpu_index++; } cpu->cpu_index = cpu_index; cpu->numa_node = 0; QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); #ifndef CONFIG_USER_ONLY cpu->as = &address_space_memory; cpu->thread_id = qemu_get_thread_id(); #endif QTAILQ_INSERT_TAIL(&cpus, cpu, node); #if defined(CONFIG_USER_ONLY) cpu_list_unlock(); #endif if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu); } #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY) register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION, cpu_save, cpu_load, env); assert(cc->vmsd == NULL); assert(qdev_get_vmsd(DEVICE(cpu)) == NULL); #endif if (cc->vmsd != NULL) { vmstate_register(NULL, cpu_index, cc->vmsd, cpu); } }
true
qemu
cba7054928b10a7fda57c64807451bbc9a31e42e
425
static int vhost_set_vring_file(struct vhost_dev *dev, VhostUserRequest request, struct vhost_vring_file *file) { int fds[VHOST_MEMORY_MAX_NREGIONS]; size_t fd_num = 0; VhostUserMsg msg = { .request = request, .flags = VHOST_USER_VERSION, .payload.u64 = file->index & VHOST_USER_VRING_IDX_MASK, .size = sizeof(msg.payload.u64), }; if (ioeventfd_enabled() && file->fd > 0) { fds[fd_num++] = file->fd; } else { msg.payload.u64 |= VHOST_USER_VRING_NOFD_MASK; } vhost_user_write(dev, &msg, fds, fd_num); return 0; }
true
qemu
c4843a45e3d4f3698b214275ab5e78cdb6a3d212
426
char *qdist_pr(const struct qdist *dist, size_t n_bins, uint32_t opt) { const char *border = opt & QDIST_PR_BORDER ? "|" : ""; char *llabel, *rlabel; char *hgram; GString *s; if (dist->n == 0) { return NULL; } s = g_string_new(""); llabel = qdist_pr_label(dist, n_bins, opt, true); rlabel = qdist_pr_label(dist, n_bins, opt, false); hgram = qdist_pr_plain(dist, n_bins); g_string_append_printf(s, "%s%s%s%s%s", llabel, border, hgram, border, rlabel); g_free(llabel); g_free(rlabel); g_free(hgram); return g_string_free(s, FALSE); }
true
qemu
11b7b07f8a15879134a54e73fade98d5e11e04f8
428
static int qemu_rdma_write_one(QEMUFile *f, RDMAContext *rdma, int current_index, uint64_t current_addr, uint64_t length) { struct ibv_sge sge; struct ibv_send_wr send_wr = { 0 }; struct ibv_send_wr *bad_wr; int reg_result_idx, ret, count = 0; uint64_t chunk, chunks; uint8_t *chunk_start, *chunk_end; RDMALocalBlock *block = &(rdma->local_ram_blocks.block[current_index]); RDMARegister reg; RDMARegisterResult *reg_result; RDMAControlHeader resp = { .type = RDMA_CONTROL_REGISTER_RESULT }; RDMAControlHeader head = { .len = sizeof(RDMARegister), .type = RDMA_CONTROL_REGISTER_REQUEST, .repeat = 1, }; retry: sge.addr = (uint64_t)(block->local_host_addr + (current_addr - block->offset)); sge.length = length; chunk = ram_chunk_index(block->local_host_addr, (uint8_t *) sge.addr); chunk_start = ram_chunk_start(block, chunk); if (block->is_ram_block) { chunks = length / (1UL << RDMA_REG_CHUNK_SHIFT); if (chunks && ((length % (1UL << RDMA_REG_CHUNK_SHIFT)) == 0)) { chunks--; } } else { chunks = block->length / (1UL << RDMA_REG_CHUNK_SHIFT); if (chunks && ((block->length % (1UL << RDMA_REG_CHUNK_SHIFT)) == 0)) { chunks--; } } DDPRINTF("Writing %" PRIu64 " chunks, (%" PRIu64 " MB)\n", chunks + 1, (chunks + 1) * (1UL << RDMA_REG_CHUNK_SHIFT) / 1024 / 1024); chunk_end = ram_chunk_end(block, chunk + chunks); if (!rdma->pin_all) { #ifdef RDMA_UNREGISTRATION_EXAMPLE qemu_rdma_unregister_waiting(rdma); #endif } while (test_bit(chunk, block->transit_bitmap)) { (void)count; DDPRINTF("(%d) Not clobbering: block: %d chunk %" PRIu64 " current %" PRIu64 " len %" PRIu64 " %d %d\n", count++, current_index, chunk, sge.addr, length, rdma->nb_sent, block->nb_chunks); ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL); if (ret < 0) { fprintf(stderr, "Failed to Wait for previous write to complete " "block %d chunk %" PRIu64 " current %" PRIu64 " len %" PRIu64 " %d\n", current_index, chunk, sge.addr, length, rdma->nb_sent); return ret; } } if (!rdma->pin_all || !block->is_ram_block) { if (!block->remote_keys[chunk]) { /* * This chunk has not yet been registered, so first check to see * if the entire chunk is zero. If so, tell the other size to * memset() + madvise() the entire chunk without RDMA. */ if (can_use_buffer_find_nonzero_offset((void *)sge.addr, length) && buffer_find_nonzero_offset((void *)sge.addr, length) == length) { RDMACompress comp = { .offset = current_addr, .value = 0, .block_idx = current_index, .length = length, }; head.len = sizeof(comp); head.type = RDMA_CONTROL_COMPRESS; DDPRINTF("Entire chunk is zero, sending compress: %" PRIu64 " for %d " "bytes, index: %d, offset: %" PRId64 "...\n", chunk, sge.length, current_index, current_addr); compress_to_network(&comp); ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) &comp, NULL, NULL, NULL); if (ret < 0) { return -EIO; } acct_update_position(f, sge.length, true); return 1; } /* * Otherwise, tell other side to register. */ reg.current_index = current_index; if (block->is_ram_block) { reg.key.current_addr = current_addr; } else { reg.key.chunk = chunk; } reg.chunks = chunks; DDPRINTF("Sending registration request chunk %" PRIu64 " for %d " "bytes, index: %d, offset: %" PRId64 "...\n", chunk, sge.length, current_index, current_addr); register_to_network(&reg); ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) &reg, &resp, &reg_result_idx, NULL); if (ret < 0) { return ret; } /* try to overlap this single registration with the one we sent. */ if (qemu_rdma_register_and_get_keys(rdma, block, (uint8_t *) sge.addr, &sge.lkey, NULL, chunk, chunk_start, chunk_end)) { fprintf(stderr, "cannot get lkey!\n"); return -EINVAL; } reg_result = (RDMARegisterResult *) rdma->wr_data[reg_result_idx].control_curr; network_to_result(reg_result); DDPRINTF("Received registration result:" " my key: %x their key %x, chunk %" PRIu64 "\n", block->remote_keys[chunk], reg_result->rkey, chunk); block->remote_keys[chunk] = reg_result->rkey; block->remote_host_addr = reg_result->host_addr; } else { /* already registered before */ if (qemu_rdma_register_and_get_keys(rdma, block, (uint8_t *)sge.addr, &sge.lkey, NULL, chunk, chunk_start, chunk_end)) { fprintf(stderr, "cannot get lkey!\n"); return -EINVAL; } } send_wr.wr.rdma.rkey = block->remote_keys[chunk]; } else { send_wr.wr.rdma.rkey = block->remote_rkey; if (qemu_rdma_register_and_get_keys(rdma, block, (uint8_t *)sge.addr, &sge.lkey, NULL, chunk, chunk_start, chunk_end)) { fprintf(stderr, "cannot get lkey!\n"); return -EINVAL; } } /* * Encode the ram block index and chunk within this wrid. * We will use this information at the time of completion * to figure out which bitmap to check against and then which * chunk in the bitmap to look for. */ send_wr.wr_id = qemu_rdma_make_wrid(RDMA_WRID_RDMA_WRITE, current_index, chunk); send_wr.opcode = IBV_WR_RDMA_WRITE; send_wr.send_flags = IBV_SEND_SIGNALED; send_wr.sg_list = &sge; send_wr.num_sge = 1; send_wr.wr.rdma.remote_addr = block->remote_host_addr + (current_addr - block->offset); DDDPRINTF("Posting chunk: %" PRIu64 ", addr: %lx" " remote: %lx, bytes %" PRIu32 "\n", chunk, sge.addr, send_wr.wr.rdma.remote_addr, sge.length); /* * ibv_post_send() does not return negative error numbers, * per the specification they are positive - no idea why. */ ret = ibv_post_send(rdma->qp, &send_wr, &bad_wr); if (ret == ENOMEM) { DDPRINTF("send queue is full. wait a little....\n"); ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL); if (ret < 0) { fprintf(stderr, "rdma migration: failed to make " "room in full send queue! %d\n", ret); return ret; } goto retry; } else if (ret > 0) { perror("rdma migration: post rdma write failed"); return -ret; } set_bit(chunk, block->transit_bitmap); acct_update_position(f, sge.length, false); rdma->total_writes++; return 0; }
true
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
429
static int init_directories(BDRVVVFATState* s, const char* dirname) { bootsector_t* bootsector; mapping_t* mapping; unsigned int i; unsigned int cluster; memset(&(s->first_sectors[0]),0,0x40*0x200); s->cluster_size=s->sectors_per_cluster*0x200; s->cluster_buffer=qemu_malloc(s->cluster_size); /* * The formula: sc = spf+1+spf*spc*(512*8/fat_type), * where sc is sector_count, * spf is sectors_per_fat, * spc is sectors_per_clusters, and * fat_type = 12, 16 or 32. */ i = 1+s->sectors_per_cluster*0x200*8/s->fat_type; s->sectors_per_fat=(s->sector_count+i)/i; /* round up */ array_init(&(s->mapping),sizeof(mapping_t)); array_init(&(s->directory),sizeof(direntry_t)); /* add volume label */ { direntry_t* entry=array_get_next(&(s->directory)); entry->attributes=0x28; /* archive | volume label */ snprintf((char*)entry->name,11,"QEMU VVFAT"); } /* Now build FAT, and write back information into directory */ init_fat(s); s->faked_sectors=s->first_sectors_number+s->sectors_per_fat*2; s->cluster_count=sector2cluster(s, s->sector_count); mapping = array_get_next(&(s->mapping)); mapping->begin = 0; mapping->dir_index = 0; mapping->info.dir.parent_mapping_index = -1; mapping->first_mapping_index = -1; mapping->path = strdup(dirname); i = strlen(mapping->path); if (i > 0 && mapping->path[i - 1] == '/') mapping->path[i - 1] = '\0'; mapping->mode = MODE_DIRECTORY; mapping->read_only = 0; s->path = mapping->path; for (i = 0, cluster = 0; i < s->mapping.next; i++) { /* MS-DOS expects the FAT to be 0 for the root directory * (except for the media byte). */ /* LATER TODO: still true for FAT32? */ int fix_fat = (i != 0); mapping = array_get(&(s->mapping), i); if (mapping->mode & MODE_DIRECTORY) { mapping->begin = cluster; if(read_directory(s, i)) { fprintf(stderr, "Could not read directory %s\n", mapping->path); return -1; } mapping = array_get(&(s->mapping), i); } else { assert(mapping->mode == MODE_UNDEFINED); mapping->mode=MODE_NORMAL; mapping->begin = cluster; if (mapping->end > 0) { direntry_t* direntry = array_get(&(s->directory), mapping->dir_index); mapping->end = cluster + 1 + (mapping->end-1)/s->cluster_size; set_begin_of_direntry(direntry, mapping->begin); } else { mapping->end = cluster + 1; fix_fat = 0; } } assert(mapping->begin < mapping->end); /* next free cluster */ cluster = mapping->end; if(cluster > s->cluster_count) { fprintf(stderr,"Directory does not fit in FAT%d (capacity %s)\n", s->fat_type, s->fat_type == 12 ? s->sector_count == 2880 ? "1.44 MB" : "2.88 MB" : "504MB"); return -EINVAL; } /* fix fat for entry */ if (fix_fat) { int j; for(j = mapping->begin; j < mapping->end - 1; j++) fat_set(s, j, j+1); fat_set(s, mapping->end - 1, s->max_fat_value); } } mapping = array_get(&(s->mapping), 0); s->sectors_of_root_directory = mapping->end * s->sectors_per_cluster; s->last_cluster_of_root_directory = mapping->end; /* the FAT signature */ fat_set(s,0,s->max_fat_value); fat_set(s,1,s->max_fat_value); s->current_mapping = NULL; bootsector=(bootsector_t*)(s->first_sectors+(s->first_sectors_number-1)*0x200); bootsector->jump[0]=0xeb; bootsector->jump[1]=0x3e; bootsector->jump[2]=0x90; memcpy(bootsector->name,"QEMU ",8); bootsector->sector_size=cpu_to_le16(0x200); bootsector->sectors_per_cluster=s->sectors_per_cluster; bootsector->reserved_sectors=cpu_to_le16(1); bootsector->number_of_fats=0x2; /* number of FATs */ bootsector->root_entries=cpu_to_le16(s->sectors_of_root_directory*0x10); bootsector->total_sectors16=s->sector_count>0xffff?0:cpu_to_le16(s->sector_count); bootsector->media_type=(s->fat_type!=12?0xf8:s->sector_count==5760?0xf9:0xf8); /* media descriptor */ s->fat.pointer[0] = bootsector->media_type; bootsector->sectors_per_fat=cpu_to_le16(s->sectors_per_fat); bootsector->sectors_per_track=cpu_to_le16(s->bs->secs); bootsector->number_of_heads=cpu_to_le16(s->bs->heads); bootsector->hidden_sectors=cpu_to_le32(s->first_sectors_number==1?0:0x3f); bootsector->total_sectors=cpu_to_le32(s->sector_count>0xffff?s->sector_count:0); /* LATER TODO: if FAT32, this is wrong */ bootsector->u.fat16.drive_number=s->fat_type==12?0:0x80; /* assume this is hda (TODO) */ bootsector->u.fat16.current_head=0; bootsector->u.fat16.signature=0x29; bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd); memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11); memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12 ":s->fat_type==16?"FAT16 ":"FAT32 "),8); bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa; return 0; }
true
qemu
2dedf83ef0cc3463783d6b71bf1b25476f691f3a
430
static int mpegts_read_header(AVFormatContext *s) { MpegTSContext *ts = s->priv_data; AVIOContext *pb = s->pb; uint8_t buf[8 * 1024] = {0}; int len; int64_t pos, probesize = s->probesize; if (ffio_ensure_seekback(pb, probesize) < 0) av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n"); /* read the first 8192 bytes to get packet size */ pos = avio_tell(pb); len = avio_read(pb, buf, sizeof(buf)); ts->raw_packet_size = get_packet_size(buf, len); if (ts->raw_packet_size <= 0) { av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting to non-FEC/DVHS\n"); ts->raw_packet_size = TS_PACKET_SIZE; } ts->stream = s; ts->auto_guess = 0; if (s->iformat == &ff_mpegts_demuxer) { /* normal demux */ /* first do a scan to get all the services */ seek_back(s, pb, pos); mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); handle_packets(ts, probesize / ts->raw_packet_size); /* if could not find service, enable auto_guess */ ts->auto_guess = 1; av_log(ts->stream, AV_LOG_TRACE, "tuning done\n"); s->ctx_flags |= AVFMTCTX_NOHEADER; } else { AVStream *st; int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l; int64_t pcrs[2], pcr_h; int packet_count[2]; uint8_t packet[TS_PACKET_SIZE]; const uint8_t *data; /* only read packets */ st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 60, 1, 27000000); st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS; /* we iterate until we find two PCRs to estimate the bitrate */ pcr_pid = -1; nb_pcrs = 0; nb_packets = 0; for (;;) { ret = read_packet(s, packet, ts->raw_packet_size, &data); if (ret < 0) return ret; pid = AV_RB16(data + 1) & 0x1fff; if ((pcr_pid == -1 || pcr_pid == pid) && parse_pcr(&pcr_h, &pcr_l, data) == 0) { finished_reading_packet(s, ts->raw_packet_size); pcr_pid = pid; packet_count[nb_pcrs] = nb_packets; pcrs[nb_pcrs] = pcr_h * 300 + pcr_l; nb_pcrs++; if (nb_pcrs >= 2) break; } else { finished_reading_packet(s, ts->raw_packet_size); } nb_packets++; } /* NOTE1: the bitrate is computed without the FEC */ /* NOTE2: it is only the bitrate of the start of the stream */ ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]); ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0]; s->bit_rate = TS_PACKET_SIZE * 8 * 27000000LL / ts->pcr_incr; st->codecpar->bit_rate = s->bit_rate; st->start_time = ts->cur_pcr; av_log(ts->stream, AV_LOG_TRACE, "start=%0.3f pcr=%0.3f incr=%d\n", st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); } seek_back(s, pb, pos); return 0; }
true
FFmpeg
1bbb18fe82fc77a10d45fa53bd2738d2c54de6c6
431
static QPCIDevice *get_ahci_device(uint32_t *fingerprint) { QPCIDevice *ahci; uint32_t ahci_fingerprint; QPCIBus *pcibus; pcibus = qpci_init_pc(); /* Find the AHCI PCI device and verify it's the right one. */ ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02)); g_assert(ahci != NULL); ahci_fingerprint = qpci_config_readl(ahci, PCI_VENDOR_ID); switch (ahci_fingerprint) { case AHCI_INTEL_ICH9: break; default: /* Unknown device. */ g_assert_not_reached(); } if (fingerprint) { *fingerprint = ahci_fingerprint; } return ahci; }
true
qemu
9a75b0a037e3a8030992244353f17b62f6daf2ab
432
static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) { int i; uint16_t limit; switch (data[0]) { case 0: if (len == 1) return 20; set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5), read_u8(data, 6), read_u8(data, 7), read_u16(data, 8), read_u16(data, 10), read_u16(data, 12), read_u8(data, 14), read_u8(data, 15), read_u8(data, 16)); break; case 2: if (len == 1) return 4; if (len == 4) return 4 + (read_u16(data, 2) * 4); limit = read_u16(data, 2); for (i = 0; i < limit; i++) { int32_t val = read_s32(data, 4 + (i * 4)); memcpy(data + 4 + (i * 4), &val, sizeof(val)); } set_encodings(vs, (int32_t *)(data + 4), limit); break; case 3: if (len == 1) return 10; framebuffer_update_request(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4), read_u16(data, 6), read_u16(data, 8)); break; case 4: if (len == 1) return 8; key_event(vs, read_u8(data, 1), read_u32(data, 4)); break; case 5: if (len == 1) return 6; pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4)); break; case 6: if (len == 1) return 8; if (len == 8) { uint32_t dlen = read_u32(data, 4); if (dlen > 0) return 8 + dlen; } client_cut_text(vs, read_u32(data, 4), data + 8); break; case 255: if (len == 1) return 2; switch (read_u8(data, 1)) { case 0: if (len == 2) return 12; ext_key_event(vs, read_u16(data, 2), read_u32(data, 4), read_u32(data, 8)); break; case 1: if (len == 2) return 4; switch (read_u16 (data, 2)) { case 0: audio_add(vs); break; case 1: audio_del(vs); break; case 2: if (len == 4) return 10; switch (read_u8(data, 4)) { case 0: vs->as.fmt = AUD_FMT_U8; break; case 1: vs->as.fmt = AUD_FMT_S8; break; case 2: vs->as.fmt = AUD_FMT_U16; break; case 3: vs->as.fmt = AUD_FMT_S16; break; case 4: vs->as.fmt = AUD_FMT_U32; break; case 5: vs->as.fmt = AUD_FMT_S32; break; default: printf("Invalid audio format %d\n", read_u8(data, 4)); vnc_client_error(vs); break; } vs->as.nchannels = read_u8(data, 5); if (vs->as.nchannels != 1 && vs->as.nchannels != 2) { printf("Invalid audio channel coount %d\n", read_u8(data, 5)); vnc_client_error(vs); break; } vs->as.freq = read_u32(data, 6); break; default: printf ("Invalid audio message %d\n", read_u8(data, 4)); vnc_client_error(vs); break; } break; default: printf("Msg: %d\n", read_u16(data, 0)); vnc_client_error(vs); break; } break; default: printf("Msg: %d\n", data[0]); vnc_client_error(vs); break; } vnc_read_when(vs, protocol_client_msg, 1); return 0; }
true
qemu
69dd5c9ffd5c0c6a01ad14b9c6a8d7135ccc2b9a
433
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AVSubtitle *sub = data; const uint8_t *buf_end = buf + buf_size; uint8_t *bitmap; int w, h, x, y, i, ret; int64_t packet_time = 0; GetBitContext gb; int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); // check that at least header fits if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) { av_log(avctx, AV_LOG_ERROR, "coded frame size %d too small\n", buf_size); return -1; } // read start and end time if (buf[0] != '[' || buf[13] != '-' || buf[26] != ']') { av_log(avctx, AV_LOG_ERROR, "invalid time code\n"); return -1; } if (avpkt->pts != AV_NOPTS_VALUE) packet_time = av_rescale_q(avpkt->pts, AV_TIME_BASE_Q, (AVRational){1, 1000}); sub->start_display_time = parse_timecode(buf + 1, packet_time); sub->end_display_time = parse_timecode(buf + 14, packet_time); buf += 27; // read header w = bytestream_get_le16(&buf); h = bytestream_get_le16(&buf); if (av_image_check_size(w, h, 0, avctx) < 0) return -1; x = bytestream_get_le16(&buf); y = bytestream_get_le16(&buf); // skip bottom right position, it gives no new information bytestream_get_le16(&buf); bytestream_get_le16(&buf); // The following value is supposed to indicate the start offset // (relative to the palette) of the data for the second field, // however there are files in which it has a bogus value and thus // we just ignore it bytestream_get_le16(&buf); // allocate sub and set values sub->rects = av_mallocz(sizeof(*sub->rects)); if (!sub->rects) return AVERROR(ENOMEM); sub->rects[0] = av_mallocz(sizeof(*sub->rects[0])); if (!sub->rects[0]) { av_freep(&sub->rects); return AVERROR(ENOMEM); } sub->rects[0]->x = x; sub->rects[0]->y = y; sub->rects[0]->w = w; sub->rects[0]->h = h; sub->rects[0]->type = SUBTITLE_BITMAP; sub->rects[0]->linesize[0] = w; sub->rects[0]->data[0] = av_malloc(w * h); sub->rects[0]->nb_colors = 4; sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE); if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1]) { av_freep(&sub->rects[0]->data[1]); av_freep(&sub->rects[0]->data[0]); av_freep(&sub->rects[0]); av_freep(&sub->rects); return AVERROR(ENOMEM); } sub->num_rects = 1; // read palette for (i = 0; i < sub->rects[0]->nb_colors; i++) ((uint32_t*)sub->rects[0]->data[1])[i] = bytestream_get_be24(&buf); if (!has_alpha) { // make all except background (first entry) non-transparent for (i = 1; i < sub->rects[0]->nb_colors; i++) ((uint32_t *)sub->rects[0]->data[1])[i] |= 0xff000000; } else { for (i = 0; i < sub->rects[0]->nb_colors; i++) ((uint32_t *)sub->rects[0]->data[1])[i] |= *buf++ << 24; } #if FF_API_AVPICTURE FF_DISABLE_DEPRECATION_WARNINGS { AVSubtitleRect *rect; int j; rect = sub->rects[0]; for (j = 0; j < 4; j++) { rect->pict.data[j] = rect->data[j]; rect->pict.linesize[j] = rect->linesize[j]; } } FF_ENABLE_DEPRECATION_WARNINGS #endif // process RLE-compressed data if ((ret = init_get_bits8(&gb, buf, buf_end - buf)) < 0) return ret; bitmap = sub->rects[0]->data[0]; for (y = 0; y < h; y++) { // interlaced: do odd lines if (y == (h + 1) / 2) bitmap = sub->rects[0]->data[0] + w; for (x = 0; x < w; ) { int log2 = ff_log2_tab[show_bits(&gb, 8)]; int run = get_bits(&gb, 14 - 4 * (log2 >> 1)); int color = get_bits(&gb, 2); run = FFMIN(run, w - x); // run length 0 means till end of row if (!run) run = w - x; memset(bitmap, color, run); bitmap += run; x += run; } // interlaced, skip every second line bitmap += w; align_get_bits(&gb); } *data_size = 1; return buf_size; }
true
FFmpeg
2002436b0c914e18eda4f45ef816b14501a1dbae
434
static void tpm_tis_initfn(Object *obj) { ISADevice *dev = ISA_DEVICE(obj); TPMState *s = TPM(obj); memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); memory_region_add_subregion(isa_address_space(dev), TPM_TIS_ADDR_BASE, &s->mmio); }
true
qemu
9dfd24ed848228643293e37c36848b5ac520ab98
435
static int process_frame(FFFrameSync *fs) { AVFilterContext *ctx = fs->parent; LUT2Context *s = fs->opaque; AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out, *srcx, *srcy; int ret; if ((ret = ff_framesync2_get_frame(&s->fs, 0, &srcx, 0)) < 0 || (ret = ff_framesync2_get_frame(&s->fs, 1, &srcy, 0)) < 0) return ret; if (ctx->is_disabled) { out = av_frame_clone(srcx); if (!out) return AVERROR(ENOMEM); } else { out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) return AVERROR(ENOMEM); av_frame_copy_props(out, srcx); s->lut2(s, out, srcx, srcy); } out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base); return ff_filter_frame(outlink, out); }
true
FFmpeg
a4d18a3f54e5b0277234d8fcff65dff8516417a0
437
static int handle_primary_tcp_pkt(NetFilterState *nf, Connection *conn, Packet *pkt) { struct tcphdr *tcp_pkt; tcp_pkt = (struct tcphdr *)pkt->transport_header; if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) { trace_colo_filter_rewriter_pkt_info(__func__, inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack), tcp_pkt->th_flags); trace_colo_filter_rewriter_conn_offset(conn->offset); } if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) { /* * we use this flag update offset func * run once in independent tcp connection */ conn->syn_flag = 1; } if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_ACK)) { if (conn->syn_flag) { /* * offset = secondary_seq - primary seq * ack packet sent by guest from primary node, * so we use th_ack - 1 get primary_seq */ conn->offset -= (ntohl(tcp_pkt->th_ack) - 1); conn->syn_flag = 0; } if (conn->offset) { /* handle packets to the secondary from the primary */ tcp_pkt->th_ack = htonl(ntohl(tcp_pkt->th_ack) + conn->offset); net_checksum_calculate((uint8_t *)pkt->data, pkt->size); } } return 0; }
true
qemu
6ce310b5356abb7edc3aa8b8b097d0b8cc76f83f
438
av_cold void ff_dsputil_init_armv6(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; if (avctx->bits_per_raw_sample <= 8 && (avctx->idct_algo == FF_IDCT_AUTO || avctx->idct_algo == FF_IDCT_SIMPLEARMV6)) { c->idct_put = ff_simple_idct_put_armv6; c->idct_add = ff_simple_idct_add_armv6; c->idct = ff_simple_idct_armv6; c->idct_permutation_type = FF_LIBMPEG2_IDCT_PERM; } if (!high_bit_depth) { c->put_pixels_tab[0][0] = ff_put_pixels16_armv6; c->put_pixels_tab[0][1] = ff_put_pixels16_x2_armv6; c->put_pixels_tab[0][2] = ff_put_pixels16_y2_armv6; /* c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_armv6; */ c->put_pixels_tab[1][0] = ff_put_pixels8_armv6; c->put_pixels_tab[1][1] = ff_put_pixels8_x2_armv6; c->put_pixels_tab[1][2] = ff_put_pixels8_y2_armv6; /* c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_armv6; */ c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_armv6; c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_armv6; c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_armv6; /* c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_armv6; */ c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_armv6; c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_armv6; c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_armv6; /* c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_armv6; */ c->avg_pixels_tab[0][0] = ff_avg_pixels16_armv6; c->avg_pixels_tab[1][0] = ff_avg_pixels8_armv6; } if (!high_bit_depth) c->get_pixels = ff_get_pixels_armv6; c->add_pixels_clamped = ff_add_pixels_clamped_armv6; c->diff_pixels = ff_diff_pixels_armv6; c->pix_abs[0][0] = ff_pix_abs16_armv6; c->pix_abs[0][1] = ff_pix_abs16_x2_armv6; c->pix_abs[0][2] = ff_pix_abs16_y2_armv6; c->pix_abs[1][0] = ff_pix_abs8_armv6; c->sad[0] = ff_pix_abs16_armv6; c->sad[1] = ff_pix_abs8_armv6; c->sse[0] = ff_sse16_armv6; c->pix_norm1 = ff_pix_norm1_armv6; c->pix_sum = ff_pix_sum_armv6; }
false
FFmpeg
70d54392f5015b9c6594fcae558f59f952501e3b
440
static int decode_exponents(AC3DecodeContext *ctx) { ac3_audio_block *ab = &ctx->audio_block; int i; uint8_t *exps; uint8_t *dexps; if (ab->flags & AC3_AB_CPLINU && ab->cplexpstr != AC3_EXPSTR_REUSE) if (_decode_exponents(ab->cplexpstr, ab->ncplgrps, ab->cplabsexp, ab->cplexps, ab->dcplexps + ab->cplstrtmant)) return -1; for (i = 0; i < ctx->bsi.nfchans; i++) if (ab->chexpstr[i] != AC3_EXPSTR_REUSE) { exps = ab->exps[i]; dexps = ab->dexps[i]; if (_decode_exponents(ab->chexpstr[i], ab->nchgrps[i], exps[0], exps + 1, dexps + 1)) return -1; } if (ctx->bsi.flags & AC3_BSI_LFEON && ab->lfeexpstr != AC3_EXPSTR_REUSE) if (_decode_exponents(ab->lfeexpstr, 2, ab->lfeexps[0], ab->lfeexps + 1, ab->dlfeexps)) return -1; return 0; }
false
FFmpeg
0058584580b87feb47898e60e4b80c7f425882ad
441
static void handle_pending_signal(CPUArchState *cpu_env, int sig, struct emulated_sigtable *k) { CPUState *cpu = ENV_GET_CPU(cpu_env); abi_ulong handler; sigset_t set; target_sigset_t target_old_set; struct target_sigaction *sa; TaskState *ts = cpu->opaque; trace_user_handle_signal(cpu_env, sig); /* dequeue signal */ k->pending = 0; sig = gdb_handlesig(cpu, sig); if (!sig) { sa = NULL; handler = TARGET_SIG_IGN; } else { sa = &sigact_table[sig - 1]; handler = sa->_sa_handler; } if (do_strace) { print_taken_signal(sig, &k->info); } if (handler == TARGET_SIG_DFL) { /* default handler : ignore some signal. The other are job control or fatal */ if (sig == TARGET_SIGTSTP || sig == TARGET_SIGTTIN || sig == TARGET_SIGTTOU) { kill(getpid(),SIGSTOP); } else if (sig != TARGET_SIGCHLD && sig != TARGET_SIGURG && sig != TARGET_SIGWINCH && sig != TARGET_SIGCONT) { force_sig(sig); } } else if (handler == TARGET_SIG_IGN) { /* ignore sig */ } else if (handler == TARGET_SIG_ERR) { force_sig(sig); } else { /* compute the blocked signals during the handler execution */ sigset_t *blocked_set; target_to_host_sigset(&set, &sa->sa_mask); /* SA_NODEFER indicates that the current signal should not be blocked during the handler */ if (!(sa->sa_flags & TARGET_SA_NODEFER)) sigaddset(&set, target_to_host_signal(sig)); /* save the previous blocked signal state to restore it at the end of the signal execution (see do_sigreturn) */ host_to_target_sigset_internal(&target_old_set, &ts->signal_mask); /* block signals in the handler */ blocked_set = ts->in_sigsuspend ? &ts->sigsuspend_mask : &ts->signal_mask; sigorset(&ts->signal_mask, blocked_set, &set); ts->in_sigsuspend = 0; /* if the CPU is in VM86 mode, we restore the 32 bit values */ #if defined(TARGET_I386) && !defined(TARGET_X86_64) { CPUX86State *env = cpu_env; if (env->eflags & VM_MASK) save_v86_state(env); } #endif /* prepare the stack frame of the virtual CPU */ #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64) \ || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX) /* These targets do not have traditional signals. */ setup_rt_frame(sig, sa, &k->info, &target_old_set, cpu_env); #else if (sa->sa_flags & TARGET_SA_SIGINFO) setup_rt_frame(sig, sa, &k->info, &target_old_set, cpu_env); else setup_frame(sig, sa, &target_old_set, cpu_env); #endif if (sa->sa_flags & TARGET_SA_RESETHAND) { sa->_sa_handler = TARGET_SIG_DFL; } } }
true
qemu
c599d4d6d6e9bfdb64e54c33a22cb26e3496b96d
442
void block_job_yield(BlockJob *job) { assert(job->busy); /* Check cancellation *before* setting busy = false, too! */ if (block_job_is_cancelled(job)) { return; } job->busy = false; if (!block_job_should_pause(job)) { qemu_coroutine_yield(); } job->busy = true; block_job_pause_point(job); }
true
qemu
356f59b8757f47c0aca3e2e4e51d6010f64cade1
445
static int udp_close(URLContext *h) { UDPContext *s = h->priv_data; if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr,(struct sockaddr *)&s->local_addr_storage); closesocket(s->udp_fd); #if HAVE_PTHREAD_CANCEL if (s->thread_started) { int ret; pthread_cancel(s->circular_buffer_thread); ret = pthread_join(s->circular_buffer_thread, NULL); if (ret != 0) av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret)); pthread_mutex_destroy(&s->mutex); pthread_cond_destroy(&s->cond); } #endif av_fifo_freep(&s->fifo); return 0; }
true
FFmpeg
9b7a8bddac52bd05dddb28afd4dff92739946d3b
447
static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, uint8_t (*layout_map)[3], GetBitContext *gb, int byte_align_ref) { int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; int sampling_index; int comment_len; int tags; skip_bits(gb, 2); // object_type sampling_index = get_bits(gb, 4); if (m4ac->sampling_index != sampling_index) av_log(avctx, AV_LOG_WARNING, "Sample rate index in program config element does not " "match the sample rate index configured by the container.\n"); num_front = get_bits(gb, 4); num_side = get_bits(gb, 4); num_back = get_bits(gb, 4); num_lfe = get_bits(gb, 2); num_assoc_data = get_bits(gb, 3); num_cc = get_bits(gb, 4); if (get_bits1(gb)) skip_bits(gb, 4); // mono_mixdown_tag if (get_bits1(gb)) skip_bits(gb, 4); // stereo_mixdown_tag if (get_bits1(gb)) skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) { av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); return -1; } decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front); tags = num_front; decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side); tags += num_side; decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back); tags += num_back; decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe); tags += num_lfe; skip_bits_long(gb, 4 * num_assoc_data); decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); tags += num_cc; relative_align_get_bits(gb, byte_align_ref); /* comment field, first byte is length */ comment_len = get_bits(gb, 8) * 8; if (get_bits_left(gb) < comment_len) { av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); return AVERROR_INVALIDDATA; } skip_bits_long(gb, comment_len); return tags; }
true
FFmpeg
df884e038f5dc95f55ef07500b5b99b722835f8a
448
void ff_decode_dxt1(const uint8_t *s, uint8_t *dst, const unsigned int w, const unsigned int h, const unsigned int stride) { unsigned int bx, by, qstride = stride/4; uint32_t *d = (uint32_t *) dst; for (by=0; by < h/4; by++, d += stride-w) for (bx=0; bx < w/4; bx++, s+=8, d+=4) dxt1_decode_pixels(s, d, qstride, 0, 0LL); }
true
FFmpeg
919f3554387e043bdfe10c6369356d1104882183
450
static const HWAccel *get_hwaccel(enum AVPixelFormat pix_fmt) { int i; for (i = 0; hwaccels[i].name; i++) if (hwaccels[i].pix_fmt == pix_fmt) return &hwaccels[i]; return NULL; }
false
FFmpeg
6a4d1c9063174234ca439244cf8f5f534afa1c28
451
static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) { VirtIOPCIProxy *proxy = opaque; VirtIODevice *vdev = proxy->vdev; target_phys_addr_t 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)) { if (vdev->bad_features) val = proxy->host_features & vdev->bad_features(vdev); else val = 0; } if (vdev->set_features) vdev->set_features(vdev, val); vdev->guest_features = val; break; case VIRTIO_PCI_QUEUE_PFN: pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; if (pa == 0) { virtio_pci_stop_ioeventfd(proxy); virtio_reset(proxy->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: 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(proxy->vdev); msix_unuse_all_vectors(&proxy->pci_dev); } /* 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; } }
true
qemu
7157e2e23e89adcd436caeab31fdd6b47eded377
453
int ff_get_cpu_flags_x86(void) { int rval = 0; #ifdef cpuid int eax, ebx, ecx, edx; int max_std_level, max_ext_level, std_caps = 0, ext_caps = 0; int family = 0, model = 0; union { int i[3]; char c[12]; } vendor; if (!cpuid_test()) return 0; /* CPUID not supported */ cpuid(0, max_std_level, vendor.i[0], vendor.i[2], vendor.i[1]); if (max_std_level >= 1) { cpuid(1, eax, ebx, ecx, std_caps); family = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); model = ((eax >> 4) & 0xf) + ((eax >> 12) & 0xf0); if (std_caps & (1 << 15)) rval |= AV_CPU_FLAG_CMOV; if (std_caps & (1 << 23)) rval |= AV_CPU_FLAG_MMX; if (std_caps & (1 << 25)) rval |= AV_CPU_FLAG_MMXEXT; #if HAVE_SSE if (std_caps & (1 << 25)) rval |= AV_CPU_FLAG_SSE; if (std_caps & (1 << 26)) rval |= AV_CPU_FLAG_SSE2; if (ecx & 1) rval |= AV_CPU_FLAG_SSE3; if (ecx & 0x00000200 ) rval |= AV_CPU_FLAG_SSSE3; if (ecx & 0x00080000 ) rval |= AV_CPU_FLAG_SSE4; if (ecx & 0x00100000 ) rval |= AV_CPU_FLAG_SSE42; #if HAVE_AVX /* Check OXSAVE and AVX bits */ if ((ecx & 0x18000000) == 0x18000000) { /* Check for OS support */ xgetbv(0, eax, edx); if ((eax & 0x6) == 0x6) { rval |= AV_CPU_FLAG_AVX; if (ecx & 0x00001000) rval |= AV_CPU_FLAG_FMA3; } } #endif /* HAVE_AVX */ #endif /* HAVE_SSE */ } if (max_std_level >= 7) { cpuid(7, eax, ebx, ecx, edx); #if HAVE_AVX2 if (ebx & 0x00000020) rval |= AV_CPU_FLAG_AVX2; #endif /* HAVE_AVX2 */ /* BMI1/2 don't need OS support */ if (ebx & 0x00000008) { rval |= AV_CPU_FLAG_BMI1; if (ebx & 0x00000100) rval |= AV_CPU_FLAG_BMI2; } } cpuid(0x80000000, max_ext_level, ebx, ecx, edx); if (max_ext_level >= 0x80000001) { cpuid(0x80000001, eax, ebx, ecx, ext_caps); if (ext_caps & (1U << 31)) rval |= AV_CPU_FLAG_3DNOW; if (ext_caps & (1 << 30)) rval |= AV_CPU_FLAG_3DNOWEXT; if (ext_caps & (1 << 23)) rval |= AV_CPU_FLAG_MMX; if (ext_caps & (1 << 22)) rval |= AV_CPU_FLAG_MMXEXT; /* Allow for selectively disabling SSE2 functions on AMD processors with SSE2 support but not SSE4a. This includes Athlon64, some Opteron, and some Sempron processors. MMX, SSE, or 3DNow! are faster than SSE2 often enough to utilize this special-case flag. AV_CPU_FLAG_SSE2 and AV_CPU_FLAG_SSE2SLOW are both set in this case so that SSE2 is used unless explicitly disabled by checking AV_CPU_FLAG_SSE2SLOW. */ if (!strncmp(vendor.c, "AuthenticAMD", 12) && rval & AV_CPU_FLAG_SSE2 && !(ecx & 0x00000040)) { rval |= AV_CPU_FLAG_SSE2SLOW; } /* XOP and FMA4 use the AVX instruction coding scheme, so they can't be * used unless the OS has AVX support. */ if (rval & AV_CPU_FLAG_AVX) { if (ecx & 0x00000800) rval |= AV_CPU_FLAG_XOP; if (ecx & 0x00010000) rval |= AV_CPU_FLAG_FMA4; } } if (!strncmp(vendor.c, "GenuineIntel", 12)) { if (family == 6 && (model == 9 || model == 13 || model == 14)) { /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and * 6/14 (core1 "yonah") theoretically support sse2, but it's * usually slower than mmx, so let's just pretend they don't. * AV_CPU_FLAG_SSE2 is disabled and AV_CPU_FLAG_SSE2SLOW is * enabled so that SSE2 is not used unless explicitly enabled * by checking AV_CPU_FLAG_SSE2SLOW. The same situation * applies for AV_CPU_FLAG_SSE3 and AV_CPU_FLAG_SSE3SLOW. */ if (rval & AV_CPU_FLAG_SSE2) rval ^= AV_CPU_FLAG_SSE2SLOW | AV_CPU_FLAG_SSE2; if (rval & AV_CPU_FLAG_SSE3) rval ^= AV_CPU_FLAG_SSE3SLOW | AV_CPU_FLAG_SSE3; } /* The Atom processor has SSSE3 support, which is useful in many cases, * but sometimes the SSSE3 version is slower than the SSE2 equivalent * on the Atom, but is generally faster on other processors supporting * SSSE3. This flag allows for selectively disabling certain SSSE3 * functions on the Atom. */ if (family == 6 && model == 28) rval |= AV_CPU_FLAG_ATOM; } #endif /* cpuid */ return rval; }
false
FFmpeg
2d9821a2081aff5dca253386c6e7e71a04509cff
454
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) { GetBitContext gb; int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; int dts_flag = -1, cts_flag = -1; int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; init_get_bits(&gb, buf, buf_size*8); if (sl->use_au_start) au_start_flag = get_bits1(&gb); if (sl->use_au_end) au_end_flag = get_bits1(&gb); if (!sl->use_au_start && !sl->use_au_end) au_start_flag = au_end_flag = 1; if (sl->ocr_len > 0) ocr_flag = get_bits1(&gb); if (sl->use_idle) idle_flag = get_bits1(&gb); if (sl->use_padding) padding_flag = get_bits1(&gb); if (padding_flag) padding_bits = get_bits(&gb, 3); if (!idle_flag && (!padding_flag || padding_bits != 0)) { if (sl->packet_seq_num_len) skip_bits_long(&gb, sl->packet_seq_num_len); if (sl->degr_prior_len) if (get_bits1(&gb)) skip_bits(&gb, sl->degr_prior_len); if (ocr_flag) skip_bits_long(&gb, sl->ocr_len); if (au_start_flag) { if (sl->use_rand_acc_pt) get_bits1(&gb); if (sl->au_seq_num_len > 0) skip_bits_long(&gb, sl->au_seq_num_len); if (sl->use_timestamps) { dts_flag = get_bits1(&gb); cts_flag = get_bits1(&gb); } } if (sl->inst_bitrate_len) inst_bitrate_flag = get_bits1(&gb); if (dts_flag == 1) dts = get_bits64(&gb, sl->timestamp_len); if (cts_flag == 1) cts = get_bits64(&gb, sl->timestamp_len); if (sl->au_len > 0) skip_bits_long(&gb, sl->au_len); if (inst_bitrate_flag) skip_bits_long(&gb, sl->inst_bitrate_len); } if (dts != AV_NOPTS_VALUE) pes->dts = dts; if (cts != AV_NOPTS_VALUE) pes->pts = cts; avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); return (get_bits_count(&gb) + 7) >> 3; }
false
FFmpeg
41bdd4adc4ab90a5ef7d63050a4046fcba711365
455
static enum AVHWDeviceType hw_device_match_type_in_name(const char *codec_name) { const char *type_name; enum AVHWDeviceType type; for (type = av_hwdevice_iterate_types(AV_HWDEVICE_TYPE_NONE); type != AV_HWDEVICE_TYPE_NONE; type = av_hwdevice_iterate_types(type)) { type_name = av_hwdevice_get_type_name(type); if (strstr(codec_name, type_name)) return type; } return AV_HWDEVICE_TYPE_NONE; }
false
FFmpeg
b0cd14fb1dab4b044f7fe6b53ac635409849de77
456
static av_cold int encode_close(AVCodecContext* avc_context) { TheoraContext *h = avc_context->priv_data; th_encode_free(h->t_state); av_freep(&h->stats); av_freep(&avc_context->coded_frame); av_freep(&avc_context->stats_out); av_freep(&avc_context->extradata); avc_context->extradata_size = 0; return 0; }
false
FFmpeg
d6604b29ef544793479d7fb4e05ef6622bb3e534
457
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice) { VAAPIEncodeContext *ctx = avctx->priv_data; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params; VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params; VAAPIEncodeH264Context *priv = ctx->priv_data; VAAPIEncodeH264Slice *pslice; VAAPIEncodeH264MiscSliceParams *mslice; int i; slice->priv_data = av_mallocz(sizeof(*pslice)); if (!slice->priv_data) return AVERROR(ENOMEM); pslice = slice->priv_data; mslice = &pslice->misc_slice_params; if (pic->type == PICTURE_TYPE_IDR) mslice->nal_unit_type = H264_NAL_IDR_SLICE; else mslice->nal_unit_type = H264_NAL_SLICE; switch (pic->type) { case PICTURE_TYPE_IDR: vslice->slice_type = SLICE_TYPE_I; mslice->nal_ref_idc = 3; break; case PICTURE_TYPE_I: vslice->slice_type = SLICE_TYPE_I; mslice->nal_ref_idc = 2; break; case PICTURE_TYPE_P: vslice->slice_type = SLICE_TYPE_P; mslice->nal_ref_idc = 1; break; case PICTURE_TYPE_B: vslice->slice_type = SLICE_TYPE_B; mslice->nal_ref_idc = 0; break; default: av_assert0(0 && "invalid picture type"); } // Only one slice per frame. vslice->macroblock_address = 0; vslice->num_macroblocks = priv->mb_width * priv->mb_height; vslice->macroblock_info = VA_INVALID_ID; vslice->pic_parameter_set_id = vpic->pic_parameter_set_id; vslice->idr_pic_id = priv->idr_pic_count++; vslice->pic_order_cnt_lsb = pic->display_order & ((1 << (4 + vseq->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4)) - 1); for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) { vslice->RefPicList0[i].picture_id = VA_INVALID_ID; vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID; vslice->RefPicList1[i].picture_id = VA_INVALID_ID; vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID; } av_assert0(pic->nb_refs <= 2); if (pic->nb_refs >= 1) { // Backward reference for P- or B-frame. av_assert0(pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B); vslice->num_ref_idx_l0_active_minus1 = 0; vslice->RefPicList0[0] = vpic->ReferenceFrames[0]; } if (pic->nb_refs >= 2) { // Forward reference for B-frame. av_assert0(pic->type == PICTURE_TYPE_B); vslice->num_ref_idx_l1_active_minus1 = 0; vslice->RefPicList1[0] = vpic->ReferenceFrames[1]; } if (pic->type == PICTURE_TYPE_B) vslice->slice_qp_delta = priv->fixed_qp_b - vpic->pic_init_qp; else if (pic->type == PICTURE_TYPE_P) vslice->slice_qp_delta = priv->fixed_qp_p - vpic->pic_init_qp; else vslice->slice_qp_delta = priv->fixed_qp_idr - vpic->pic_init_qp; vslice->direct_spatial_mv_pred_flag = 1; return 0; }
false
FFmpeg
e72662e131e5099e34d5a7519c5690d2fff7b83f
458
static char *assign_name(NetClientState *nc1, const char *model) { NetClientState *nc; char buf[256]; int id = 0; QTAILQ_FOREACH(nc, &net_clients, next) { if (nc == nc1) { continue; } /* For compatibility only bump id for net clients on a vlan */ if (strcmp(nc->model, model) == 0 && net_hub_id_for_client(nc, NULL) == 0) { id++; } } snprintf(buf, sizeof(buf), "%s.%d", model, id); return g_strdup(buf); }
false
qemu
c963530a5b3e3e0f7304841adfe84416d82f59f6
459
static void nbd_accept(void *opaque) { int server_fd = (uintptr_t) opaque; struct sockaddr_in addr; socklen_t addr_len = sizeof(addr); int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len); nbd_started = true; if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) { nb_fds++; } }
false
qemu
7860a380ac2a9fd09a6e8f31fd9db5318fc91285
460
static void dma_init2(struct dma_cont *d, int base, int dshift, int page_base, int pageh_base, qemu_irq *cpu_request_exit) { int i; d->dshift = dshift; d->cpu_request_exit = cpu_request_exit; memory_region_init_io(&d->channel_io, NULL, &channel_io_ops, d, "dma-chan", 8 << d->dshift); memory_region_add_subregion(isa_address_space_io(NULL), base, &d->channel_io); isa_register_portio_list(NULL, page_base, page_portio_list, d, "dma-page"); if (pageh_base >= 0) { isa_register_portio_list(NULL, pageh_base, pageh_portio_list, d, "dma-pageh"); } memory_region_init_io(&d->cont_io, NULL, &cont_io_ops, d, "dma-cont", 8 << d->dshift); memory_region_add_subregion(isa_address_space_io(NULL), base + (8 << d->dshift), &d->cont_io); qemu_register_reset(dma_reset, d); dma_reset(d); for (i = 0; i < ARRAY_SIZE (d->regs); ++i) { d->regs[i].transfer_handler = dma_phony_handler; } }
false
qemu
5039d6e23586fe6bbedc5e4fe302b48a66890ade
462
static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr, ram_addr_t offset) { bool ret; int nr = (mr->ram_addr + offset) >> TARGET_PAGE_BITS; ret = test_and_clear_bit(nr, migration_bitmap); if (ret) { migration_dirty_pages--; } return ret; }
false
qemu
4c8ae0f60e63478aea0a1741cca95474b68fb949
463
static inline void gen_op_eval_bge(TCGv dst, TCGv_i32 src) { gen_mov_reg_V(cpu_tmp0, src); gen_mov_reg_N(dst, src); tcg_gen_xor_tl(dst, dst, cpu_tmp0); tcg_gen_xori_tl(dst, dst, 0x1); }
false
qemu
de9e9d9f17a36ff76c1a02a5348835e5e0a081b0
464
static int qcow_set_key(BlockDriverState *bs, const char *key) { BDRVQcowState *s = bs->opaque; uint8_t keybuf[16]; int len, i; Error *err; memset(keybuf, 0, 16); len = strlen(key); if (len > 16) len = 16; /* XXX: we could compress the chars to 7 bits to increase entropy */ for(i = 0;i < len;i++) { keybuf[i] = key[i]; } assert(bs->encrypted); qcrypto_cipher_free(s->cipher); s->cipher = qcrypto_cipher_new( QCRYPTO_CIPHER_ALG_AES_128, QCRYPTO_CIPHER_MODE_CBC, keybuf, G_N_ELEMENTS(keybuf), &err); if (!s->cipher) { /* XXX would be nice if errors in this method could * be properly propagate to the caller. Would need * the bdrv_set_key() API signature to be fixed. */ error_free(err); return -1; } return 0; }
false
qemu
d85f4222b4681da7ebf8a90b26e085a68fa2c55a
465
int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, bool force) { uint64_t features; int r; if (devfd >= 0) { hdev->control = devfd; } else { hdev->control = open(devpath, O_RDWR); if (hdev->control < 0) { return -errno; } } r = ioctl(hdev->control, VHOST_SET_OWNER, NULL); if (r < 0) { goto fail; } r = ioctl(hdev->control, VHOST_GET_FEATURES, &features); if (r < 0) { goto fail; } hdev->features = features; hdev->memory_listener = (MemoryListener) { .begin = vhost_begin, .commit = vhost_commit, .region_add = vhost_region_add, .region_del = vhost_region_del, .region_nop = vhost_region_nop, .log_start = vhost_log_start, .log_stop = vhost_log_stop, .log_sync = vhost_log_sync, .log_global_start = vhost_log_global_start, .log_global_stop = vhost_log_global_stop, .eventfd_add = vhost_eventfd_add, .eventfd_del = vhost_eventfd_del, .priority = 10 }; hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions)); hdev->n_mem_sections = 0; hdev->mem_sections = NULL; hdev->log = NULL; hdev->log_size = 0; hdev->log_enabled = false; hdev->started = false; memory_listener_register(&hdev->memory_listener, NULL); hdev->force = force; return 0; fail: r = -errno; close(hdev->control); return r; }
false
qemu
0fada67420e29f389119ca6f44285203400e0730
466
static void fw_cfg_mem_realize(DeviceState *dev, Error **errp) { FWCfgMemState *s = FW_CFG_MEM(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops, FW_CFG(s), "fwcfg.ctl", FW_CFG_SIZE); sysbus_init_mmio(sbd, &s->ctl_iomem); memory_region_init_io(&s->data_iomem, OBJECT(s), &fw_cfg_data_mem_ops, FW_CFG(s), "fwcfg.data", fw_cfg_data_mem_ops.valid.max_access_size); sysbus_init_mmio(sbd, &s->data_iomem); }
false
qemu
cfaadf0e89e7c2a47462d5f96390c9a9b4de037c
467
static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int partIdx) { #define POS(c_idx, x, y) \ &s->frame->data[c_idx][((y) >> s->sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \ (((x) >> s->sps->hshift[c_idx]) << s->sps->pixel_shift)] HEVCLocalContext *lc = &s->HEVClc; int merge_idx = 0; struct MvField current_mv = {{{ 0 }}}; int min_pu_width = s->sps->min_pu_width; MvField *tab_mvf = s->ref->tab_mvf; RefPicList *refPicList = s->ref->refPicList; HEVCFrame *ref0, *ref1; int tmpstride = MAX_PB_SIZE; uint8_t *dst0 = POS(0, x0, y0); uint8_t *dst1 = POS(1, x0, y0); uint8_t *dst2 = POS(2, x0, y0); int log2_min_cb_size = s->sps->log2_min_cb_size; int min_cb_width = s->sps->min_cb_width; int x_cb = x0 >> log2_min_cb_size; int y_cb = y0 >> log2_min_cb_size; int x_pu, y_pu; int i, j; int skip_flag = SAMPLE_CTB(s->skip_flag, x_cb, y_cb); if (!skip_flag) lc->pu.merge_flag = ff_hevc_merge_flag_decode(s); if (skip_flag || lc->pu.merge_flag) { if (s->sh.max_num_merge_cand > 1) merge_idx = ff_hevc_merge_idx_decode(s); else merge_idx = 0; ff_hevc_luma_mv_merge_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, partIdx, merge_idx, &current_mv); } else { enum InterPredIdc inter_pred_idc = PRED_L0; int mvp_flag; ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH); if (s->sh.slice_type == B_SLICE) inter_pred_idc = ff_hevc_inter_pred_idc_decode(s, nPbW, nPbH); if (inter_pred_idc != PRED_L1) { if (s->sh.nb_refs[L0]) { current_mv.ref_idx[0]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L0]); } current_mv.pred_flag[0] = 1; hls_mvd_coding(s, x0, y0, 0); mvp_flag = ff_hevc_mvp_lx_flag_decode(s); ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, partIdx, merge_idx, &current_mv, mvp_flag, 0); current_mv.mv[0].x += lc->pu.mvd.x; current_mv.mv[0].y += lc->pu.mvd.y; } if (inter_pred_idc != PRED_L0) { if (s->sh.nb_refs[L1]) { current_mv.ref_idx[1]= ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L1]); } if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) { AV_ZERO32(&lc->pu.mvd); } else { hls_mvd_coding(s, x0, y0, 1); } current_mv.pred_flag[1] = 1; mvp_flag = ff_hevc_mvp_lx_flag_decode(s); ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size, partIdx, merge_idx, &current_mv, mvp_flag, 1); current_mv.mv[1].x += lc->pu.mvd.x; current_mv.mv[1].y += lc->pu.mvd.y; } } x_pu = x0 >> s->sps->log2_min_pu_size; y_pu = y0 >> s->sps->log2_min_pu_size; for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++) for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++) tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; if (current_mv.pred_flag[0]) { ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; if (!ref0) return; hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH); } if (current_mv.pred_flag[1]) { ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; if (!ref1) return; hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH); } if (current_mv.pred_flag[0] && !current_mv.pred_flag[1]) { DECLARE_ALIGNED(16, int16_t, tmp[MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]); luma_mc(s, tmp, tmpstride, ref0->frame, &current_mv.mv[0], x0, y0, nPbW, nPbH); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l0[current_mv.ref_idx[0]], s->sh.luma_offset_l0[current_mv.ref_idx[0]], dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH); } else { s->hevcdsp.put_unweighted_pred(dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH); } chroma_mc(s, tmp, tmp2, tmpstride, ref0->frame, &current_mv.mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0], dst1, s->frame->linesize[1], tmp, tmpstride, nPbW / 2, nPbH / 2); s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1], dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW / 2, nPbH / 2); } else { s->hevcdsp.put_unweighted_pred(dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2); s->hevcdsp.put_unweighted_pred(dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2); } } else if (!current_mv.pred_flag[0] && current_mv.pred_flag[1]) { DECLARE_ALIGNED(16, int16_t, tmp [MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]); if (!ref1) return; luma_mc(s, tmp, tmpstride, ref1->frame, &current_mv.mv[1], x0, y0, nPbW, nPbH); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l1[current_mv.ref_idx[1]], s->sh.luma_offset_l1[current_mv.ref_idx[1]], dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH); } else { s->hevcdsp.put_unweighted_pred(dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH); } chroma_mc(s, tmp, tmp2, tmpstride, ref1->frame, &current_mv.mv[1], x0/2, y0/2, nPbW/2, nPbH/2); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0], dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2); s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1], dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2); } else { s->hevcdsp.put_unweighted_pred(dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2); s->hevcdsp.put_unweighted_pred(dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2); } } else if (current_mv.pred_flag[0] && current_mv.pred_flag[1]) { DECLARE_ALIGNED(16, int16_t, tmp [MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp3[MAX_PB_SIZE * MAX_PB_SIZE]); DECLARE_ALIGNED(16, int16_t, tmp4[MAX_PB_SIZE * MAX_PB_SIZE]); HEVCFrame *ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; HEVCFrame *ref1 = refPicList[1].ref[current_mv.ref_idx[1]]; if (!ref0 || !ref1) return; luma_mc(s, tmp, tmpstride, ref0->frame, &current_mv.mv[0], x0, y0, nPbW, nPbH); luma_mc(s, tmp2, tmpstride, ref1->frame, &current_mv.mv[1], x0, y0, nPbW, nPbH); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred_avg(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l0[current_mv.ref_idx[0]], s->sh.luma_weight_l1[current_mv.ref_idx[1]], s->sh.luma_offset_l0[current_mv.ref_idx[0]], s->sh.luma_offset_l1[current_mv.ref_idx[1]], dst0, s->frame->linesize[0], tmp, tmp2, tmpstride, nPbW, nPbH); } else { s->hevcdsp.put_weighted_pred_avg(dst0, s->frame->linesize[0], tmp, tmp2, tmpstride, nPbW, nPbH); } chroma_mc(s, tmp, tmp2, tmpstride, ref0->frame, &current_mv.mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2); chroma_mc(s, tmp3, tmp4, tmpstride, ref1->frame, &current_mv.mv[1], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2); if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred_avg(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0], dst1, s->frame->linesize[1], tmp, tmp3, tmpstride, nPbW / 2, nPbH / 2); s->hevcdsp.weighted_pred_avg(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1], dst2, s->frame->linesize[2], tmp2, tmp4, tmpstride, nPbW / 2, nPbH / 2); } else { s->hevcdsp.put_weighted_pred_avg(dst1, s->frame->linesize[1], tmp, tmp3, tmpstride, nPbW/2, nPbH/2); s->hevcdsp.put_weighted_pred_avg(dst2, s->frame->linesize[2], tmp2, tmp4, tmpstride, nPbW/2, nPbH/2); } } }
false
FFmpeg
8b573ddda75980f724f779ff75aacc2ff81d9e0e
468
static void select_soundhw (const char *optarg) { struct soundhw *c; if (*optarg == '?') { show_valid_cards: printf ("Valid sound card names (comma separated):\n"); for (c = soundhw; c->name; ++c) { printf ("%-11s %s\n", c->name, c->descr); } printf ("\n-soundhw all will enable all of the above\n"); exit (*optarg != '?'); } else { size_t l; const char *p; char *e; int bad_card = 0; if (!strcmp (optarg, "all")) { for (c = soundhw; c->name; ++c) { c->enabled = 1; } return; } p = optarg; while (*p) { e = strchr (p, ','); l = !e ? strlen (p) : (size_t) (e - p); for (c = soundhw; c->name; ++c) { if (!strncmp (c->name, p, l) && !c->name[l]) { c->enabled = 1; break; } } if (!c->name) { if (l > 80) { fprintf (stderr, "Unknown sound card name (too big to show)\n"); } else { fprintf (stderr, "Unknown sound card name `%.*s'\n", (int) l, p); } bad_card = 1; } p += l + (e != NULL); } if (bad_card) goto show_valid_cards; } }
false
qemu
ad96090a01d848df67d70c5259ed8aa321fa8716
469
void ide_bus_reset(IDEBus *bus) { bus->unit = 0; bus->cmd = 0; ide_reset(&bus->ifs[0]); ide_reset(&bus->ifs[1]); ide_clear_hob(bus); /* pending async DMA */ if (bus->dma->aiocb) { #ifdef DEBUG_AIO printf("aio_cancel\n"); #endif bdrv_aio_cancel(bus->dma->aiocb); bus->dma->aiocb = NULL; } /* reset dma provider too */ if (bus->dma->ops->reset) { bus->dma->ops->reset(bus->dma); } }
false
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
470
if_start(void) { struct mbuf *ifm, *ifqt; DEBUG_CALL("if_start"); if (if_queued == 0) return; /* Nothing to do */ again: /* check if we can really output */ if (!slirp_can_output()) return; /* * See which queue to get next packet from * If there's something in the fastq, select it immediately */ if (if_fastq.ifq_next != &if_fastq) { ifm = if_fastq.ifq_next; } else { /* Nothing on fastq, see if next_m is valid */ if (next_m != &if_batchq) ifm = next_m; else ifm = if_batchq.ifq_next; /* Set which packet to send on next iteration */ next_m = ifm->ifq_next; } /* Remove it from the queue */ ifqt = ifm->ifq_prev; remque(ifm); --if_queued; /* If there are more packets for this session, re-queue them */ if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) { insque(ifm->ifs_next, ifqt); ifs_remque(ifm); } /* Update so_queued */ if (ifm->ifq_so) { if (--ifm->ifq_so->so_queued == 0) /* If there's no more queued, reset nqueued */ ifm->ifq_so->so_nqueued = 0; } /* Encapsulate the packet for sending */ if_encap(ifm->m_data, ifm->m_len); m_free(ifm); if (if_queued) goto again; }
false
qemu
242acf3af4605adce933906bdc053b2414181ec7
471
MacIONVRAMState *macio_nvram_init (target_phys_addr_t size, unsigned int it_shift) { MacIONVRAMState *s; s = g_malloc0(sizeof(MacIONVRAMState)); s->data = g_malloc0(size); s->size = size; s->it_shift = it_shift; memory_region_init_io(&s->mem, &macio_nvram_ops, s, "macio-nvram", size << it_shift); vmstate_register(NULL, -1, &vmstate_macio_nvram, s); qemu_register_reset(macio_nvram_reset, s); return s; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
472
static void cmd646_data_write(void *opaque, target_phys_addr_t addr, uint64_t data, unsigned size) { CMD646BAR *cmd646bar = opaque; if (size == 1) { ide_ioport_write(cmd646bar->bus, addr, data); } else if (addr == 0) { if (size == 2) { ide_data_writew(cmd646bar->bus, addr, data); } else { ide_data_writel(cmd646bar->bus, addr, data); } } }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
473
static uint64_t kvm_apic_mem_read(void *opaque, target_phys_addr_t addr, unsigned size) { return ~(uint64_t)0; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
475
static uint64_t bonito_cop_readl(void *opaque, target_phys_addr_t addr, unsigned size) { uint32_t val; PCIBonitoState *s = opaque; val = ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)]; return val; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
476
size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt, size_t iov_off, int fillc, size_t size) { size_t iovec_off, buf_off; unsigned int i; iovec_off = 0; buf_off = 0; for (i = 0; i < iov_cnt && size; i++) { if (iov_off < (iovec_off + iov[i].iov_len)) { size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size); memset(iov[i].iov_base + (iov_off - iovec_off), fillc, len); buf_off += len; iov_off += len; size -= len; } iovec_off += iov[i].iov_len; } return buf_off; }
false
qemu
2278a69e7020d86a8c73a28474e7709d3e7d5081
477
static int img_open_password(BlockBackend *blk, const char *filename, int flags, bool quiet) { BlockDriverState *bs; char password[256]; bs = blk_bs(blk); if (bdrv_is_encrypted(bs) && !(flags & BDRV_O_NO_IO)) { qprintf(quiet, "Disk image '%s' is encrypted.\n", filename); if (qemu_read_password(password, sizeof(password)) < 0) { error_report("No password given"); return -1; } if (bdrv_set_key(bs, password) < 0) { error_report("invalid password"); return -1; } } return 0; }
false
qemu
4ef130fca87b7a8c77e1af9ca967f28b683811d7
478
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) { const char *codec_name; AVCodec *p; char buf1[32]; int bitrate; AVRational display_aspect_ratio; if (encode) p = avcodec_find_encoder(enc->codec_id); else p = avcodec_find_decoder(enc->codec_id); if (p) { codec_name = p->name; if (!encode && enc->codec_id == CODEC_ID_MP3) { if (enc->sub_id == 2) codec_name = "mp2"; else if (enc->sub_id == 1) codec_name = "mp1"; } } else if (enc->codec_id == CODEC_ID_MPEG2TS) { /* fake mpeg2 transport stream codec (currently not registered) */ codec_name = "mpeg2ts"; } else if (enc->codec_name[0] != '\0') { codec_name = enc->codec_name; } else { /* output avi tags */ if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF) && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){ snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X", enc->codec_tag & 0xff, (enc->codec_tag >> 8) & 0xff, (enc->codec_tag >> 16) & 0xff, (enc->codec_tag >> 24) & 0xff, enc->codec_tag); } else { snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); } codec_name = buf1; } switch(enc->codec_type) { case CODEC_TYPE_VIDEO: snprintf(buf, buf_size, "Video: %s%s", codec_name, enc->mb_decision ? " (hq)" : ""); if (enc->pix_fmt != PIX_FMT_NONE) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s", avcodec_get_pix_fmt_name(enc->pix_fmt)); } if (enc->width) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %dx%d", enc->width, enc->height); if (enc->sample_aspect_ratio.num) { av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, enc->width*enc->sample_aspect_ratio.num, enc->height*enc->sample_aspect_ratio.den, 1024*1024); snprintf(buf + strlen(buf), buf_size - strlen(buf), " [PAR %d:%d DAR %d:%d]", enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } if(av_log_get_level() >= AV_LOG_DEBUG){ int g= ff_gcd(enc->time_base.num, enc->time_base.den); snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d/%d", enc->time_base.num/g, enc->time_base.den/g); } } if (encode) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", q=%d-%d", enc->qmin, enc->qmax); } bitrate = enc->bit_rate; break; case CODEC_TYPE_AUDIO: snprintf(buf, buf_size, "Audio: %s", codec_name); if (enc->sample_rate) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d Hz", enc->sample_rate); } av_strlcat(buf, ", ", buf_size); avcodec_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout); if (enc->sample_fmt != SAMPLE_FMT_NONE) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt)); } /* for PCM codecs, compute bitrate directly */ switch(enc->codec_id) { case CODEC_ID_PCM_F64BE: case CODEC_ID_PCM_F64LE: bitrate = enc->sample_rate * enc->channels * 64; break; case CODEC_ID_PCM_S32LE: case CODEC_ID_PCM_S32BE: case CODEC_ID_PCM_U32LE: case CODEC_ID_PCM_U32BE: case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_F32LE: bitrate = enc->sample_rate * enc->channels * 32; break; case CODEC_ID_PCM_S24LE: case CODEC_ID_PCM_S24BE: case CODEC_ID_PCM_U24LE: case CODEC_ID_PCM_U24BE: case CODEC_ID_PCM_S24DAUD: bitrate = enc->sample_rate * enc->channels * 24; break; case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16LE_PLANAR: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16BE: bitrate = enc->sample_rate * enc->channels * 16; break; case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: case CODEC_ID_PCM_ZORK: bitrate = enc->sample_rate * enc->channels * 8; break; default: bitrate = enc->bit_rate; break; } break; case CODEC_TYPE_DATA: snprintf(buf, buf_size, "Data: %s", codec_name); bitrate = enc->bit_rate; break; case CODEC_TYPE_SUBTITLE: snprintf(buf, buf_size, "Subtitle: %s", codec_name); bitrate = enc->bit_rate; break; case CODEC_TYPE_ATTACHMENT: snprintf(buf, buf_size, "Attachment: %s", codec_name); bitrate = enc->bit_rate; break; default: snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); return; } if (encode) { if (enc->flags & CODEC_FLAG_PASS1) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", pass 1"); if (enc->flags & CODEC_FLAG_PASS2) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", pass 2"); } if (bitrate != 0) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d kb/s", bitrate / 1000); } }
false
FFmpeg
c9b3c0c740ac912c835ccb7179afc2c5da8d5d23
479
static int transcode_init(OutputFile *output_files, int nb_output_files, InputFile *input_files, int nb_input_files) { int ret = 0, i, j; AVFormatContext *os; AVCodecContext *codec, *icodec; OutputStream *ost; InputStream *ist; char error[1024]; int want_sdp = 1; /* init framerate emulation */ for (i = 0; i < nb_input_files; i++) { InputFile *ifile = &input_files[i]; if (ifile->rate_emu) for (j = 0; j < ifile->nb_streams; j++) input_streams[j + ifile->ist_index].start = av_gettime(); } /* output stream init */ for(i=0;i<nb_output_files;i++) { os = output_files[i].ctx; if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(os, i, os->filename, 1); fprintf(stderr, "Output file #%d does not contain any stream\n", i); return AVERROR(EINVAL); } } /* for each output stream, we compute the right encoding parameters */ for (i = 0; i < nb_output_streams; i++) { ost = &output_streams[i]; os = output_files[ost->file_index].ctx; ist = &input_streams[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; ost->st->disposition = ist->st->disposition; codec->bits_per_raw_sample= icodec->bits_per_raw_sample; codec->chroma_sample_location = icodec->chroma_sample_location; if (ost->st->stream_copy) { uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; if (extra_size > INT_MAX) { return AVERROR(EINVAL); } /* if stream_copy is selected, no need to decode or encode */ codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; if(!codec->codec_tag){ if( !os->oformat->codec_tag || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) codec->codec_tag = icodec->codec_tag; } codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; codec->extradata= av_mallocz(extra_size); if (!codec->extradata) { return AVERROR(ENOMEM); } memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); codec->extradata_size= icodec->extradata_size; if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){ codec->time_base = icodec->time_base; codec->time_base.num *= icodec->ticks_per_frame; av_reduce(&codec->time_base.num, &codec->time_base.den, codec->time_base.num, codec->time_base.den, INT_MAX); }else codec->time_base = ist->st->time_base; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(audio_volume != 256) { fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); exit_program(1); } codec->channel_layout = icodec->channel_layout; codec->sample_rate = icodec->sample_rate; codec->channels = icodec->channels; codec->frame_size = icodec->frame_size; codec->audio_service_type = icodec->audio_service_type; codec->block_align= icodec->block_align; if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) codec->block_align= 0; if(codec->codec_id == CODEC_ID_AC3) codec->block_align= 0; break; case AVMEDIA_TYPE_VIDEO: codec->pix_fmt = icodec->pix_fmt; codec->width = icodec->width; codec->height = icodec->height; codec->has_b_frames = icodec->has_b_frames; if (!codec->sample_aspect_ratio.num) { codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : ist->st->codec->sample_aspect_ratio.num ? ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; } break; case AVMEDIA_TYPE_SUBTITLE: codec->width = icodec->width; codec->height = icodec->height; break; case AVMEDIA_TYPE_DATA: break; default: abort(); } } else { if (!ost->enc) ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: ost->fifo= av_fifo_alloc(1024); if (!ost->fifo) { return AVERROR(ENOMEM); } ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); if (!codec->sample_rate) { codec->sample_rate = icodec->sample_rate; if (icodec->lowres) codec->sample_rate >>= icodec->lowres; } choose_sample_rate(ost->st, ost->enc); codec->time_base = (AVRational){1, codec->sample_rate}; if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) codec->sample_fmt = icodec->sample_fmt; choose_sample_fmt(ost->st, ost->enc); if (!codec->channels) codec->channels = icodec->channels; codec->channel_layout = icodec->channel_layout; if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) codec->channel_layout = 0; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; ost->encoding_needed = 1; ost->resample_sample_fmt = icodec->sample_fmt; ost->resample_sample_rate = icodec->sample_rate; ost->resample_channels = icodec->channels; break; case AVMEDIA_TYPE_VIDEO: if (codec->pix_fmt == PIX_FMT_NONE) codec->pix_fmt = icodec->pix_fmt; choose_pixel_fmt(ost->st, ost->enc); if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); exit_program(1); } if (!codec->width || !codec->height) { codec->width = icodec->width; codec->height = icodec->height; } ost->video_resample = codec->width != icodec->width || codec->height != icodec->height || codec->pix_fmt != icodec->pix_fmt; if (ost->video_resample) { #if !CONFIG_AVFILTER avcodec_get_frame_defaults(&ost->pict_tmp); if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, codec->width, codec->height)) { fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); exit_program(1); } ost->img_resample_ctx = sws_getContext( icodec->width, icodec->height, icodec->pix_fmt, codec->width, codec->height, codec->pix_fmt, ost->sws_flags, NULL, NULL, NULL); if (ost->img_resample_ctx == NULL) { fprintf(stderr, "Cannot get resampling context\n"); exit_program(1); } #endif codec->bits_per_raw_sample= 0; } ost->resample_height = icodec->height; ost->resample_width = icodec->width; ost->resample_pix_fmt= icodec->pix_fmt; ost->encoding_needed = 1; ist->decoding_needed = 1; if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; if (ost->enc && ost->enc->supported_framerates && !force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { fprintf(stderr, "Error opening filters!\n"); exit(1); } #endif break; case AVMEDIA_TYPE_SUBTITLE: ost->encoding_needed = 1; ist->decoding_needed = 1; break; default: abort(); break; } /* two pass mode */ if (ost->encoding_needed && (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { char logfilename[1024]; FILE *f; snprintf(logfilename, sizeof(logfilename), "%s-%d.log", pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, i); if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(logfilename, "wb"); if (!f) { fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); exit_program(1); } ost->logfile = f; } else { char *logbuffer; size_t logbuffer_size; if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); exit_program(1); } codec->stats_in = logbuffer; } } } if(codec->codec_type == AVMEDIA_TYPE_VIDEO){ int size= codec->width * codec->height; bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200); } } if (!bit_buffer) bit_buffer = av_malloc(bit_buffer_size); if (!bit_buffer) { fprintf(stderr, "Cannot allocate %d bytes output buffer\n", bit_buffer_size); return AVERROR(ENOMEM); } /* open each encoder */ for (i = 0; i < nb_output_streams; i++) { ost = &output_streams[i]; if (ost->encoding_needed) { AVCodec *codec = ost->enc; AVCodecContext *dec = input_streams[ost->source_index].st->codec; if (!codec) { snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d", ost->st->codec->codec_id, ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } if (dec->subtitle_header) { ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); if (!ost->st->codec->subtitle_header) { ret = AVERROR(ENOMEM); goto dump_format; } memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); ost->st->codec->subtitle_header_size = dec->subtitle_header_size; } if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) { snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ost->st->codec, 1); assert_avoptions(ost->opts); if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\n"); extra_size += ost->st->codec->extradata_size; } } /* init input streams */ for (i = 0; i < nb_input_streams; i++) if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0) goto dump_format; /* open files and write file headers */ for (i = 0; i < nb_output_files; i++) { os = output_files[i].ctx; if (avformat_write_header(os, &output_files[i].opts) < 0) { snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); ret = AVERROR(EINVAL); goto dump_format; } assert_avoptions(output_files[i].opts); if (strcmp(os->oformat->name, "rtp")) { want_sdp = 0; } } dump_format: /* dump the file output parameters - cannot be done before in case of stream copy */ for(i=0;i<nb_output_files;i++) { av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1); } /* dump the stream mapping */ if (verbose >= 0) { fprintf(stderr, "Stream mapping:\n"); for (i = 0; i < nb_output_streams;i ++) { ost = &output_streams[i]; fprintf(stderr, " Stream #%d.%d -> #%d.%d", input_streams[ost->source_index].file_index, input_streams[ost->source_index].st->index, ost->file_index, ost->index); if (ost->sync_ist != &input_streams[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); if (ost->st->stream_copy) fprintf(stderr, " (copy)"); else fprintf(stderr, " (%s -> %s)", input_streams[ost->source_index].dec ? input_streams[ost->source_index].dec->name : "?", ost->enc ? ost->enc->name : "?"); fprintf(stderr, "\n"); } } if (ret) { fprintf(stderr, "%s\n", error); return ret; } if (want_sdp) { print_sdp(output_files, nb_output_files); } return 0; }
false
FFmpeg
2c474ddbc5b90541ea4a65961490b6469d12529f
480
static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) { LavfiContext *lavfi = avctx->priv_data; double min_pts = DBL_MAX; int stream_idx, min_pts_sink_idx = 0; AVFrame *frame = lavfi->decoded_frame; AVPicture pict; AVDictionary *frame_metadata; int ret, i; int size = 0; if (lavfi->subcc_packet.size) { *pkt = lavfi->subcc_packet; av_init_packet(&lavfi->subcc_packet); lavfi->subcc_packet.size = 0; lavfi->subcc_packet.data = NULL; return pkt->size; } /* iterate through all the graph sinks. Select the sink with the * minimum PTS */ for (i = 0; i < lavfi->nb_sinks; i++) { AVRational tb = lavfi->sinks[i]->inputs[0]->time_base; double d; int ret; if (lavfi->sink_eof[i]) continue; ret = av_buffersink_get_frame_flags(lavfi->sinks[i], frame, AV_BUFFERSINK_FLAG_PEEK); if (ret == AVERROR_EOF) { av_dlog(avctx, "EOF sink_idx:%d\n", i); lavfi->sink_eof[i] = 1; continue; } else if (ret < 0) return ret; d = av_rescale_q_rnd(frame->pts, tb, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); av_dlog(avctx, "sink_idx:%d time:%f\n", i, d); av_frame_unref(frame); if (d < min_pts) { min_pts = d; min_pts_sink_idx = i; } } if (min_pts == DBL_MAX) return AVERROR_EOF; av_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx); av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0); stream_idx = lavfi->sink_stream_map[min_pts_sink_idx]; if (frame->width /* FIXME best way of testing a video */) { size = avpicture_get_size(frame->format, frame->width, frame->height); if ((ret = av_new_packet(pkt, size)) < 0) return ret; memcpy(pict.data, frame->data, 4*sizeof(frame->data[0])); memcpy(pict.linesize, frame->linesize, 4*sizeof(frame->linesize[0])); avpicture_layout(&pict, frame->format, frame->width, frame->height, pkt->data, size); } else if (av_frame_get_channels(frame) /* FIXME test audio */) { size = frame->nb_samples * av_get_bytes_per_sample(frame->format) * av_frame_get_channels(frame); if ((ret = av_new_packet(pkt, size)) < 0) return ret; memcpy(pkt->data, frame->data[0], size); } frame_metadata = av_frame_get_metadata(frame); if (frame_metadata) { uint8_t *metadata; AVDictionaryEntry *e = NULL; AVBPrint meta_buf; av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED); while ((e = av_dict_get(frame_metadata, "", e, AV_DICT_IGNORE_SUFFIX))) { av_bprintf(&meta_buf, "%s", e->key); av_bprint_chars(&meta_buf, '\0', 1); av_bprintf(&meta_buf, "%s", e->value); av_bprint_chars(&meta_buf, '\0', 1); } if (!av_bprint_is_complete(&meta_buf) || !(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, meta_buf.len))) { av_bprint_finalize(&meta_buf, NULL); return AVERROR(ENOMEM); } memcpy(metadata, meta_buf.str, meta_buf.len); av_bprint_finalize(&meta_buf, NULL); } if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) { av_frame_unref(frame); av_packet_unref(pkt); return ret; } pkt->stream_index = stream_idx; pkt->pts = frame->pts; pkt->pos = av_frame_get_pkt_pos(frame); pkt->size = size; av_frame_unref(frame); return size; }
false
FFmpeg
229843aa359ae0c9519977d7fa952688db63f559
481
static void iothread_complete(UserCreatable *obj, Error **errp) { IOThread *iothread = IOTHREAD(obj); iothread->stopping = false; iothread->ctx = aio_context_new(); iothread->thread_id = -1; qemu_mutex_init(&iothread->init_done_lock); qemu_cond_init(&iothread->init_done_cond); /* This assumes we are called from a thread with useful CPU affinity for us * to inherit. */ qemu_thread_create(&iothread->thread, "iothread", iothread_run, iothread, QEMU_THREAD_JOINABLE); /* Wait for initialization to complete */ qemu_mutex_lock(&iothread->init_done_lock); while (iothread->thread_id == -1) { qemu_cond_wait(&iothread->init_done_cond, &iothread->init_done_lock); } qemu_mutex_unlock(&iothread->init_done_lock); }
true
qemu
2f78e491d7b46542158ce0b8132ee4e05bc0ade4
482
static void gen_tlbre_440(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); #else if (unlikely(ctx->pr)) { gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; } switch (rB(ctx->opcode)) { case 0: case 1: case 2: { TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, t0, cpu_gpr[rA(ctx->opcode)]); tcg_temp_free_i32(t0); } break; default: gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); break; } #endif }
true
qemu
9b2fadda3e0196ffd485adde4fe9cdd6fae35300
483
target_ulong helper_evpe(target_ulong arg1) { // TODO arg1 = 0; // rt = arg1 return arg1; }
true
qemu
9ed5726c043958359b0f1fa44ab3e4f25f9d9a47
484
void helper_ldmxcsr(CPUX86State *env, uint32_t val) { env->mxcsr = val; update_sse_status(env); }
true
qemu
4e47e39ab0ded72c0af174131ecf49d588d66c12
485
void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){ const int w2= (width+1)>>1; IDWTELEM temp[width >> 1]; const int w_l= (width>>1); const int w_r= w2 - 1; int i; { // Lift 0 IDWTELEM * const ref = b + w2 - 1; i = 1; b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS); asm volatile( "pcmpeqw %%mm7, %%mm7 \n\t" "psllw $15, %%mm7 \n\t" "psrlw $14, %%mm7 \n\t" ::); for(; i<w_l-7; i+=8){ asm volatile( "movq (%1), %%mm2 \n\t" "movq 8(%1), %%mm6 \n\t" "paddw 2(%1), %%mm2 \n\t" "paddw 10(%1), %%mm6 \n\t" "movq %%mm2, %%mm0 \n\t" "movq %%mm6, %%mm4 \n\t" "psraw $1, %%mm2 \n\t" "psraw $1, %%mm6 \n\t" "paddw %%mm0, %%mm2 \n\t" "paddw %%mm4, %%mm6 \n\t" "paddw %%mm7, %%mm2 \n\t" "paddw %%mm7, %%mm6 \n\t" "psraw $2, %%mm2 \n\t" "psraw $2, %%mm6 \n\t" "movq (%0), %%mm0 \n\t" "movq 8(%0), %%mm4 \n\t" "psubw %%mm2, %%mm0 \n\t" "psubw %%mm6, %%mm4 \n\t" "movq %%mm0, (%0) \n\t" "movq %%mm4, 8(%0) \n\t" :: "r"(&b[i]), "r"(&ref[i]) : "memory" ); } snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS); } { // Lift 1 IDWTELEM * const dst = b+w2; i = 0; for(; i<w_r-7; i+=8){ asm volatile( "movq (%1), %%mm2 \n\t" "movq 8(%1), %%mm6 \n\t" "paddw 2(%1), %%mm2 \n\t" "paddw 10(%1), %%mm6 \n\t" "movq (%0), %%mm0 \n\t" "movq 8(%0), %%mm4 \n\t" "psubw %%mm2, %%mm0 \n\t" "psubw %%mm6, %%mm4 \n\t" "movq %%mm0, (%0) \n\t" "movq %%mm4, 8(%0) \n\t" :: "r"(&dst[i]), "r"(&b[i]) : "memory" ); } snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS); } { // Lift 2 IDWTELEM * const ref = b+w2 - 1; i = 1; b[0] = b[0] + (((2 * ref[1] + W_BO) + 4 * b[0]) >> W_BS); asm volatile( "psllw $2, %%mm7 \n\t" ::); for(; i<w_l-7; i+=8){ asm volatile( "movq (%1), %%mm0 \n\t" "movq 8(%1), %%mm4 \n\t" "paddw 2(%1), %%mm0 \n\t" "paddw 10(%1), %%mm4 \n\t" "paddw %%mm7, %%mm0 \n\t" "paddw %%mm7, %%mm4 \n\t" "psraw $2, %%mm0 \n\t" "psraw $2, %%mm4 \n\t" "movq (%0), %%mm1 \n\t" "movq 8(%0), %%mm5 \n\t" "paddw %%mm1, %%mm0 \n\t" "paddw %%mm5, %%mm4 \n\t" "psraw $2, %%mm0 \n\t" "psraw $2, %%mm4 \n\t" "paddw %%mm1, %%mm0 \n\t" "paddw %%mm5, %%mm4 \n\t" "movq %%mm0, (%0) \n\t" "movq %%mm4, 8(%0) \n\t" :: "r"(&b[i]), "r"(&ref[i]) : "memory" ); } snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l); } { // Lift 3 IDWTELEM * const src = b+w2; i = 0; for(; i<w_r-7; i+=8){ asm volatile( "movq 2(%1), %%mm2 \n\t" "movq 10(%1), %%mm6 \n\t" "paddw (%1), %%mm2 \n\t" "paddw 8(%1), %%mm6 \n\t" "movq (%0), %%mm0 \n\t" "movq 8(%0), %%mm4 \n\t" "paddw %%mm2, %%mm0 \n\t" "paddw %%mm6, %%mm4 \n\t" "psraw $1, %%mm2 \n\t" "psraw $1, %%mm6 \n\t" "paddw %%mm0, %%mm2 \n\t" "paddw %%mm4, %%mm6 \n\t" "movq %%mm2, (%2) \n\t" "movq %%mm6, 8(%2) \n\t" :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i]) : "memory" ); } snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS); } { snow_interleave_line_header(&i, width, b, temp); for (; (i & 0x1E) != 0x1E; i-=2){ b[i+1] = temp[i>>1]; b[i] = b[i>>1]; } for (i-=30; i>=0; i-=32){ asm volatile( "movq (%1), %%mm0 \n\t" "movq 8(%1), %%mm2 \n\t" "movq 16(%1), %%mm4 \n\t" "movq 24(%1), %%mm6 \n\t" "movq (%1), %%mm1 \n\t" "movq 8(%1), %%mm3 \n\t" "movq 16(%1), %%mm5 \n\t" "movq 24(%1), %%mm7 \n\t" "punpcklwd (%2), %%mm0 \n\t" "punpcklwd 8(%2), %%mm2 \n\t" "punpcklwd 16(%2), %%mm4 \n\t" "punpcklwd 24(%2), %%mm6 \n\t" "movq %%mm0, (%0) \n\t" "movq %%mm2, 16(%0) \n\t" "movq %%mm4, 32(%0) \n\t" "movq %%mm6, 48(%0) \n\t" "punpckhwd (%2), %%mm1 \n\t" "punpckhwd 8(%2), %%mm3 \n\t" "punpckhwd 16(%2), %%mm5 \n\t" "punpckhwd 24(%2), %%mm7 \n\t" "movq %%mm1, 8(%0) \n\t" "movq %%mm3, 24(%0) \n\t" "movq %%mm5, 40(%0) \n\t" "movq %%mm7, 56(%0) \n\t" :: "r"(&b[i]), "r"(&b[i>>1]), "r"(&temp[i>>1]) : "memory" ); } } }
true
FFmpeg
629750290f6122a72e68c34cf94f521a90def2ef
486
static int net_dump_init(VLANState *vlan, const char *device, const char *name, const char *filename, int len) { struct pcap_file_hdr hdr; DumpState *s; s = qemu_malloc(sizeof(DumpState)); s->fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644); if (s->fd < 0) { qemu_error("-net dump: can't open %s\n", filename); return -1; } s->pcap_caplen = len; hdr.magic = PCAP_MAGIC; hdr.version_major = 2; hdr.version_minor = 4; hdr.thiszone = 0; hdr.sigfigs = 0; hdr.snaplen = s->pcap_caplen; hdr.linktype = 1; if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { qemu_error("-net dump write error: %s\n", strerror(errno)); close(s->fd); qemu_free(s); return -1; } s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP, vlan, NULL, device, name, NULL, dump_receive, NULL, NULL, net_dump_cleanup, s); snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str), "dump to %s (len=%d)", filename, len); return 0; }
true
qemu
731d5856cbb9c160fe02b90cd3cf354ea4f52f34
487
void check_values (eq2_param_t *par) { /* yuck! floating point comparisons... */ if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) { par->adjust = NULL; } #if HAVE_MMX && HAVE_6REGS else if (par->g == 1.0 && ff_gCpuCaps.hasMMX) { par->adjust = &affine_1d_MMX; } #endif else { par->adjust = &apply_lut; } }
false
FFmpeg
70205f1799252c3363a5bb5ea7ea5df090f2c88f
488
static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s) { unsigned char B; int x, y; /* copy block from 2 frames ago using a motion vector; need 1 more byte */ CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); B = *s->stream_ptr++; if (B < 56) { x = 8 + (B % 7); y = B / 7; } else { x = -14 + ((B - 56) % 29); y = 8 + ((B - 56) / 29); } debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); return copy_from(s, &s->second_last_frame, x, y); }
false
FFmpeg
dcfb0cad687ec89d3c7fe21a014c58f283050283
489
static int input_get_buffer(AVCodecContext *codec, AVFrame *pic) { AVFilterContext *ctx = codec->opaque; AVFilterBufferRef *ref; int perms = AV_PERM_WRITE; int i, w, h, stride[4]; unsigned edge; if(av_image_check_size(w, h, 0, codec)) return -1; if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES) perms |= AV_PERM_NEG_LINESIZES; if(pic->buffer_hints & FF_BUFFER_HINTS_VALID) { if(pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ; if(pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE; if(pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) perms |= AV_PERM_REUSE2; } if(pic->reference) perms |= AV_PERM_READ | AV_PERM_PRESERVE; w = codec->width; h = codec->height; avcodec_align_dimensions2(codec, &w, &h, stride); edge = codec->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width(); w += edge << 1; h += edge << 1; if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], perms, w, h))) return -1; ref->video->w = codec->width; ref->video->h = codec->height; for(i = 0; i < 4; i ++) { unsigned hshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0; unsigned vshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0; if (ref->data[i]) { ref->data[i] += (edge >> hshift) + ((edge * ref->linesize[i]) >> vshift); } pic->data[i] = ref->data[i]; pic->linesize[i] = ref->linesize[i]; } pic->opaque = ref; pic->age = INT_MAX; pic->type = FF_BUFFER_TYPE_USER; pic->reordered_opaque = codec->reordered_opaque; if(codec->pkt) pic->pkt_pts = codec->pkt->pts; else pic->pkt_pts = AV_NOPTS_VALUE; return 0; }
false
FFmpeg
9f8008a9815ed5ee8846de2bb97c980ddb7b2485
492
static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { BdrvTrackedRequest *req; int64_t cluster_sector_num; int cluster_nb_sectors; bool retry; /* If we touch the same cluster it counts as an overlap. This guarantees * that allocating writes will be serialized and not race with each other * for the same cluster. For example, in copy-on-read it ensures that the * CoR read and write operations are atomic and guest writes cannot * interleave between them. round_to_clusters(bs, sector_num, nb_sectors, &cluster_sector_num, &cluster_nb_sectors); do { retry = false; QLIST_FOREACH(req, &bs->tracked_requests, list) { if (tracked_request_overlaps(req, cluster_sector_num, cluster_nb_sectors)) { qemu_co_queue_wait(&req->wait_queue); retry = true; break; } } } while (retry); }
true
qemu
5f8b6491f20732e0a31e64bbf75b62def579e044
493
static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model, const char *name, int fd, int is_connected) { struct sockaddr_in saddr; int newfd; socklen_t saddr_len; VLANClientState *nc; NetSocketState *s; /* fd passed: multicast: "learn" dgram_dst address from bound address and save it * Because this may be "shared" socket from a "master" process, datagrams would be recv() * by ONLY ONE process: we must "clone" this dgram socket --jjo */ if (is_connected) { if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) { /* must be bound */ if (saddr.sin_addr.s_addr == 0) { fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, " "cannot setup multicast dst addr\n", fd); return NULL; } /* clone dgram socket */ newfd = net_socket_mcast_create(&saddr, NULL); if (newfd < 0) { /* error already reported by net_socket_mcast_create() */ close(fd); return NULL; } /* clone newfd to fd, close newfd */ dup2(newfd, fd); close(newfd); } else { fprintf(stderr, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n", fd, strerror(errno)); return NULL; } } nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (%s mcast=%s:%d)", fd, is_connected ? "cloned" : "", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s); /* mcast: save bound address as dst */ if (is_connected) s->dgram_dst=saddr; return s; }
true
qemu
e5d1fca0f20babbe355957b9ba536fe6187691cc
494
int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) { return hbitmap_iter_next(&iter->hbi); }
false
qemu
f798184cfdcb7f92a38c5f717d675bd75e1fd3ac
495
static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) { if (s->RxBufAddr + size > s->RxBufferSize) { int wrapped = MOD2(s->RxBufAddr + size, s->RxBufferSize); /* write packet data */ if (wrapped && s->RxBufferSize < 65536 && !rtl8139_RxWrap(s)) { DEBUG_PRINT((">>> RTL8139: rx packet wrapped in buffer at %d\n", size-wrapped)); if (size > wrapped) { cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, buf, size-wrapped ); } /* reset buffer pointer */ s->RxBufAddr = 0; cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, buf + (size-wrapped), wrapped ); s->RxBufAddr = wrapped; return; } } /* non-wrapping path or overwrapping enabled */ cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, buf, size ); s->RxBufAddr += size; }
false
qemu
ccf1d14a1e37abe1f0da162c00a8941963b47a4c
496
int ppc_hash32_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw, int mmu_idx) { struct mmu_ctx_hash32 ctx; int access_type; int ret = 0; if (rw == 2) { /* code access */ rw = 0; access_type = ACCESS_CODE; } else { /* data access */ access_type = env->access_type; } ret = ppc_hash32_get_physical_address(env, &ctx, address, rw, access_type); if (ret == 0) { tlb_set_page(env, address & TARGET_PAGE_MASK, ctx.raddr & TARGET_PAGE_MASK, ctx.prot, mmu_idx, TARGET_PAGE_SIZE); ret = 0; } else if (ret < 0) { LOG_MMU_STATE(env); if (access_type == ACCESS_CODE) { switch (ret) { case -1: /* No matches in page tables or TLB */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x40000000; break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x08000000; break; case -3: /* No execute protection violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x10000000; break; case -4: /* Direct store exception */ /* No code fetch is allowed in direct-store areas */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x10000000; break; } } else { switch (ret) { case -1: /* No matches in page tables or TLB */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x42000000; } else { env->spr[SPR_DSISR] = 0x40000000; } break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x0A000000; } else { env->spr[SPR_DSISR] = 0x08000000; } break; case -4: /* Direct store exception */ switch (access_type) { case ACCESS_FLOAT: /* Floating point load/store */ env->exception_index = POWERPC_EXCP_ALIGN; env->error_code = POWERPC_EXCP_ALIGN_FP; env->spr[SPR_DAR] = address; break; case ACCESS_RES: /* lwarx, ldarx or stwcx. */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x06000000; } else { env->spr[SPR_DSISR] = 0x04000000; } break; case ACCESS_EXT: /* eciwx or ecowx */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x06100000; } else { env->spr[SPR_DSISR] = 0x04100000; } break; default: printf("DSI: invalid exception (%d)\n", ret); env->exception_index = POWERPC_EXCP_PROGRAM; env->error_code = POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL; env->spr[SPR_DAR] = address; break; } break; } } #if 0 printf("%s: set exception to %d %02x\n", __func__, env->exception, env->error_code); #endif ret = 1; } return ret; }
false
qemu
91cda45b69e45a089f9989979a65db3f710c9925