project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
qemu | 81f194dd69756677cc36ff0827bf970f0f048914 | 0 | static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
{
PowerPCCPU *cpu = POWERPC_CPU(dev);
CPUPPCState *env = &cpu->env;
int i;
for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
if (env->opcodes[i] != &invalid_handler) {
g_free(env->opcodes[i]);
}
}
}
| 15,194 |
qemu | a2db2a1edd06a50b8a862c654cf993368cf9f1d9 | 0 | static void xen_exit_notifier(Notifier *n, void *data)
{
XenIOState *state = container_of(n, XenIOState, exit);
xc_evtchn_close(state->xce_handle);
xs_daemon_close(state->xenstore);
}
| 15,195 |
FFmpeg | bcd7bf7eeb09a395cc01698842d1b8be9af483fc | 0 | static void avc_loopfilter_cb_or_cr_inter_edge_ver_msa(uint8_t *data,
uint8_t bs0, uint8_t bs1,
uint8_t bs2, uint8_t bs3,
uint8_t tc0, uint8_t tc1,
uint8_t tc2, uint8_t tc3,
uint8_t alpha_in,
uint8_t beta_in,
uint32_t img_width)
{
uint8_t *src;
uint16_t out0, out1, out2, out3;
v16u8 alpha, beta;
v16u8 p0_asub_q0, p1_asub_p0, q1_asub_q0;
v16u8 is_less_than, is_less_than_beta, is_less_than_alpha;
v16u8 p0, q0;
v8i16 p0_r = { 0 };
v8i16 q0_r = { 0 };
v16u8 p1_org, p0_org, q0_org, q1_org;
v8i16 p1_org_r, p0_org_r, q0_org_r, q1_org_r;
v16u8 is_bs_greater_than0;
v8i16 tc_r, negate_tc_r;
v16i8 negate_tc, sign_negate_tc;
v16i8 zero = { 0 };
v16u8 row0, row1, row2, row3, row4, row5, row6, row7;
v8i16 tmp1, tmp_vec, bs = { 0 };
v8i16 tc = { 0 };
tmp_vec = (v8i16) __msa_fill_b(bs0);
bs = __msa_insve_h(bs, 0, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(bs1);
bs = __msa_insve_h(bs, 1, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(bs2);
bs = __msa_insve_h(bs, 2, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(bs3);
bs = __msa_insve_h(bs, 3, tmp_vec);
if (!__msa_test_bz_v((v16u8) bs)) {
tmp_vec = (v8i16) __msa_fill_b(tc0);
tc = __msa_insve_h(tc, 0, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(tc1);
tc = __msa_insve_h(tc, 1, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(tc2);
tc = __msa_insve_h(tc, 2, tmp_vec);
tmp_vec = (v8i16) __msa_fill_b(tc3);
tc = __msa_insve_h(tc, 3, tmp_vec);
is_bs_greater_than0 = (v16u8) (zero < (v16i8) bs);
LOAD_8VECS_UB((data - 2), img_width,
row0, row1, row2, row3, row4, row5, row6, row7);
TRANSPOSE8x4_B_UB(row0, row1, row2, row3,
row4, row5, row6, row7,
p1_org, p0_org, q0_org, q1_org);
p0_asub_q0 = __msa_asub_u_b(p0_org, q0_org);
p1_asub_p0 = __msa_asub_u_b(p1_org, p0_org);
q1_asub_q0 = __msa_asub_u_b(q1_org, q0_org);
alpha = (v16u8) __msa_fill_b(alpha_in);
beta = (v16u8) __msa_fill_b(beta_in);
is_less_than_alpha = (p0_asub_q0 < alpha);
is_less_than_beta = (p1_asub_p0 < beta);
is_less_than = is_less_than_beta & is_less_than_alpha;
is_less_than_beta = (q1_asub_q0 < beta);
is_less_than = is_less_than_beta & is_less_than;
is_less_than = is_bs_greater_than0 & is_less_than;
is_less_than = (v16u8) __msa_ilvr_d((v2i64) zero, (v2i64) is_less_than);
if (!__msa_test_bz_v(is_less_than)) {
p1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p1_org);
p0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p0_org);
q0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q0_org);
q1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q1_org);
negate_tc = zero - (v16i8) tc;
sign_negate_tc = __msa_clti_s_b(negate_tc, 0);
negate_tc_r = (v8i16) __msa_ilvr_b(sign_negate_tc, negate_tc);
tc_r = (v8i16) __msa_ilvr_b(zero, (v16i8) tc);
AVC_LOOP_FILTER_P0Q0(q0_org_r, p0_org_r, p1_org_r, q1_org_r,
negate_tc_r, tc_r, p0_r, q0_r);
p0 = (v16u8) __msa_pckev_b(zero, (v16i8) p0_r);
q0 = (v16u8) __msa_pckev_b(zero, (v16i8) q0_r);
p0_org = __msa_bmnz_v(p0_org, p0, is_less_than);
q0_org = __msa_bmnz_v(q0_org, q0, is_less_than);
tmp1 = (v8i16) __msa_ilvr_b((v16i8) q0_org, (v16i8) p0_org);
src = data - 1;
out0 = __msa_copy_u_h(tmp1, 0);
out1 = __msa_copy_u_h(tmp1, 1);
out2 = __msa_copy_u_h(tmp1, 2);
out3 = __msa_copy_u_h(tmp1, 3);
STORE_HWORD(src, out0);
src += img_width;
STORE_HWORD(src, out1);
src += img_width;
STORE_HWORD(src, out2);
src += img_width;
STORE_HWORD(src, out3);
out0 = __msa_copy_u_h(tmp1, 4);
out1 = __msa_copy_u_h(tmp1, 5);
out2 = __msa_copy_u_h(tmp1, 6);
out3 = __msa_copy_u_h(tmp1, 7);
src += img_width;
STORE_HWORD(src, out0);
src += img_width;
STORE_HWORD(src, out1);
src += img_width;
STORE_HWORD(src, out2);
src += img_width;
STORE_HWORD(src, out3);
}
}
}
| 15,196 |
FFmpeg | f98c3ec5c68d14d7c93c2f9775be4583f7905554 | 0 | static int mov_write_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
MOVMuxContext *mov = s->priv_data;
AVDictionaryEntry *t, *global_tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
int i, ret, hint_track = 0, tmcd_track = 0;
mov->fc = s;
/* Default mode == MP4 */
mov->mode = MODE_MP4;
if (s->oformat) {
if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3GP|MODE_3G2;
else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD;
else if (!strcmp("ismv",s->oformat->name)) mov->mode = MODE_ISM;
else if (!strcmp("f4v", s->oformat->name)) mov->mode = MODE_F4V;
}
if (s->flags & AVFMT_FLAG_BITEXACT)
mov->exact = 1;
if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
mov->flags |= FF_MOV_FLAG_EMPTY_MOOV;
/* Set the FRAGMENT flag if any of the fragmentation methods are
* enabled. */
if (mov->max_fragment_duration || mov->max_fragment_size ||
mov->flags & (FF_MOV_FLAG_EMPTY_MOOV |
FF_MOV_FLAG_FRAG_KEYFRAME |
FF_MOV_FLAG_FRAG_CUSTOM))
mov->flags |= FF_MOV_FLAG_FRAGMENT;
/* Set other implicit flags immediately */
if (mov->mode == MODE_ISM)
mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF |
FF_MOV_FLAG_FRAGMENT;
if (mov->flags & FF_MOV_FLAG_DASH)
mov->flags |= FF_MOV_FLAG_FRAGMENT | FF_MOV_FLAG_EMPTY_MOOV |
FF_MOV_FLAG_DEFAULT_BASE_MOOF;
if (mov->flags & FF_MOV_FLAG_FASTSTART) {
mov->reserved_moov_size = -1;
}
if (mov->use_editlist < 0) {
mov->use_editlist = 1;
if (mov->flags & FF_MOV_FLAG_FRAGMENT &&
!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
// If we can avoid needing an edit list by shifting the
// tracks, prefer that over (trying to) write edit lists
// in fragmented output.
if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO ||
s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)
mov->use_editlist = 0;
}
}
if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV &&
!(mov->flags & FF_MOV_FLAG_DELAY_MOOV) && mov->use_editlist)
av_log(s, AV_LOG_WARNING, "No meaningful edit list will be written when using empty_moov without delay_moov\n");
if (!mov->use_editlist && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO)
s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_ZERO;
/* Clear the omit_tfhd_offset flag if default_base_moof is set;
* if the latter is set that's enough and omit_tfhd_offset doesn't
* add anything extra on top of that. */
if (mov->flags & FF_MOV_FLAG_OMIT_TFHD_OFFSET &&
mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF)
mov->flags &= ~FF_MOV_FLAG_OMIT_TFHD_OFFSET;
if (mov->frag_interleave &&
mov->flags & (FF_MOV_FLAG_OMIT_TFHD_OFFSET | FF_MOV_FLAG_SEPARATE_MOOF)) {
av_log(s, AV_LOG_ERROR,
"Sample interleaving in fragments is mutually exclusive with "
"omit_tfhd_offset and separate_moof\n");
return AVERROR(EINVAL);
}
/* Non-seekable output is ok if using fragmentation. If ism_lookahead
* is enabled, we don't support non-seekable output at all. */
if (!s->pb->seekable &&
(!(mov->flags & FF_MOV_FLAG_FRAGMENT) || mov->ism_lookahead)) {
av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
return AVERROR(EINVAL);
}
if (!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
if ((ret = mov_write_identification(pb, s)) < 0)
return ret;
}
mov->nb_streams = s->nb_streams;
if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters)
mov->chapter_track = mov->nb_streams++;
if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
/* Add hint tracks for each audio and video stream */
hint_track = mov->nb_streams;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
mov->nb_streams++;
}
}
}
if (mov->mode == MODE_MOV) {
tmcd_track = mov->nb_streams;
/* +1 tmcd track for each video stream with a timecode */
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
(global_tcr || av_dict_get(st->metadata, "timecode", NULL, 0)))
mov->nb_meta_tmcd++;
}
/* check if there is already a tmcd track to remux */
if (mov->nb_meta_tmcd) {
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (st->codec->codec_tag == MKTAG('t','m','c','d')) {
av_log(s, AV_LOG_WARNING, "You requested a copy of the original timecode track "
"so timecode metadata are now ignored\n");
mov->nb_meta_tmcd = 0;
}
}
}
mov->nb_streams += mov->nb_meta_tmcd;
}
// Reserve an extra stream for chapters for the case where chapters
// are written in the trailer
mov->tracks = av_mallocz_array((mov->nb_streams + 1), sizeof(*mov->tracks));
if (!mov->tracks)
return AVERROR(ENOMEM);
for (i = 0; i < s->nb_streams; i++) {
AVStream *st= s->streams[i];
MOVTrack *track= &mov->tracks[i];
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0);
track->st = st;
track->enc = st->codec;
track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV);
if (track->language < 0)
track->language = 0;
track->mode = mov->mode;
track->tag = mov_find_codec_tag(s, track);
if (!track->tag) {
av_log(s, AV_LOG_ERROR, "Could not find tag for codec %s in stream #%d, "
"codec not currently supported in container\n",
avcodec_get_name(st->codec->codec_id), i);
ret = AVERROR(EINVAL);
goto error;
}
/* If hinting of this track is enabled by a later hint track,
* this is updated. */
track->hint_track = -1;
track->start_dts = AV_NOPTS_VALUE;
track->start_cts = AV_NOPTS_VALUE;
track->end_pts = AV_NOPTS_VALUE;
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') ||
track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') ||
track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) {
if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) {
av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n");
ret = AVERROR(EINVAL);
goto error;
}
track->height = track->tag >> 24 == 'n' ? 486 : 576;
}
if (mov->video_track_timescale) {
track->timescale = mov->video_track_timescale;
} else {
track->timescale = st->time_base.den;
while(track->timescale < 10000)
track->timescale *= 2;
}
if (st->codec->width > 65535 || st->codec->height > 65535) {
av_log(s, AV_LOG_ERROR, "Resolution %dx%d too large for mov/mp4\n", st->codec->width, st->codec->height);
ret = AVERROR(EINVAL);
goto error;
}
if (track->mode == MODE_MOV && track->timescale > 100000)
av_log(s, AV_LOG_WARNING,
"WARNING codec timebase is very high. If duration is too long,\n"
"file may not be playable by quicktime. Specify a shorter timebase\n"
"or choose different container.\n");
} else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
track->timescale = st->codec->sample_rate;
if (!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) {
av_log(s, AV_LOG_WARNING, "track %d: codec frame size is not set\n", i);
track->audio_vbr = 1;
}else if (st->codec->codec_id == AV_CODEC_ID_ADPCM_MS ||
st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV ||
st->codec->codec_id == AV_CODEC_ID_ILBC){
if (!st->codec->block_align) {
av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i);
ret = AVERROR(EINVAL);
goto error;
}
track->sample_size = st->codec->block_align;
}else if (st->codec->frame_size > 1){ /* assume compressed audio */
track->audio_vbr = 1;
}else{
track->sample_size = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
}
if (st->codec->codec_id == AV_CODEC_ID_ILBC ||
st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_QT) {
track->audio_vbr = 1;
}
if (track->mode != MODE_MOV &&
track->enc->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) {
if (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL) {
av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not standard, to mux anyway set strict to -1\n",
i, track->enc->sample_rate);
ret = AVERROR(EINVAL);
goto error;
} else {
av_log(s, AV_LOG_WARNING, "track %d: muxing mp3 at %dhz is not standard in MP4\n",
i, track->enc->sample_rate);
}
}
} else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
track->timescale = st->time_base.den;
} else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) {
track->timescale = st->time_base.den;
} else {
track->timescale = MOV_TIMESCALE;
}
if (!track->height)
track->height = st->codec->height;
/* The ism specific timescale isn't mandatory, but is assumed by
* some tools, such as mp4split. */
if (mov->mode == MODE_ISM)
track->timescale = 10000000;
avpriv_set_pts_info(st, 64, 1, track->timescale);
/* copy extradata if it exists */
if (st->codec->extradata_size) {
if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE)
mov_create_dvd_sub_decoder_specific_info(track, st);
else if (!TAG_IS_AVCI(track->tag) && st->codec->codec_id != AV_CODEC_ID_DNXHD) {
track->vos_len = st->codec->extradata_size;
track->vos_data = av_malloc(track->vos_len);
if (!track->vos_data) {
ret = AVERROR(ENOMEM);
goto error;
}
memcpy(track->vos_data, st->codec->extradata, track->vos_len);
}
}
}
for (i = 0; i < s->nb_streams; i++) {
int j;
AVStream *st= s->streams[i];
MOVTrack *track= &mov->tracks[i];
if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO ||
track->enc->channel_layout != AV_CH_LAYOUT_MONO)
continue;
for (j = 0; j < s->nb_streams; j++) {
AVStream *stj= s->streams[j];
MOVTrack *trackj= &mov->tracks[j];
if (j == i)
continue;
if (stj->codec->codec_type != AVMEDIA_TYPE_AUDIO ||
trackj->enc->channel_layout != AV_CH_LAYOUT_MONO ||
trackj->language != track->language ||
trackj->tag != track->tag
)
continue;
track->multichannel_as_mono++;
}
}
enable_tracks(s);
if (mov->reserved_moov_size){
mov->reserved_moov_pos= avio_tell(pb);
if (mov->reserved_moov_size > 0)
avio_skip(pb, mov->reserved_moov_size);
}
if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
/* If no fragmentation options have been set, set a default. */
if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME |
FF_MOV_FLAG_FRAG_CUSTOM)) &&
!mov->max_fragment_duration && !mov->max_fragment_size)
mov->flags |= FF_MOV_FLAG_FRAG_KEYFRAME;
} else {
if (mov->flags & FF_MOV_FLAG_FASTSTART)
mov->reserved_moov_pos = avio_tell(pb);
mov_write_mdat_tag(pb, mov);
}
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
mov->time = ff_iso8601_to_unix_time(t->value);
if (mov->time)
mov->time += 0x7C25B080; // 1970 based -> 1904 based
if (mov->chapter_track)
if ((ret = mov_create_chapter_track(s, mov->chapter_track)) < 0)
goto error;
if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
/* Initialize the hint tracks for each audio and video stream */
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if ((ret = ff_mov_init_hinting(s, hint_track, i)) < 0)
goto error;
hint_track++;
}
}
}
if (mov->nb_meta_tmcd) {
/* Initialize the tmcd tracks */
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
t = global_tcr;
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (!t)
t = av_dict_get(st->metadata, "timecode", NULL, 0);
if (!t)
continue;
if ((ret = mov_create_timecode_track(s, tmcd_track, i, t->value)) < 0)
goto error;
tmcd_track++;
}
}
}
avio_flush(pb);
if (mov->flags & FF_MOV_FLAG_ISML)
mov_write_isml_manifest(pb, mov);
if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV &&
!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
return ret;
mov->moov_written = 1;
if (mov->flags & FF_MOV_FLAG_FASTSTART)
mov->reserved_moov_pos = avio_tell(pb);
}
return 0;
error:
mov_free(s);
return ret;
}
| 15,197 |
FFmpeg | c2657633187e325a439e3297fd9ccd0522ab2e39 | 1 | static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
{
ALSSpecificConfig *sconf = &ctx->sconf;
AVCodecContext *avctx = ctx->avctx;
GetBitContext *gb = &ctx->gb;
unsigned int div_blocks[32]; ///< block sizes.
unsigned int c;
unsigned int js_blocks[2];
uint32_t bs_info = 0;
int ret;
// skip the size of the ra unit if present in the frame
if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame)
skip_bits_long(gb, 32);
if (sconf->mc_coding && sconf->joint_stereo) {
ctx->js_switch = get_bits1(gb);
align_get_bits(gb);
if (!sconf->mc_coding || ctx->js_switch) {
int independent_bs = !sconf->joint_stereo;
for (c = 0; c < avctx->channels; c++) {
js_blocks[0] = 0;
js_blocks[1] = 0;
get_block_sizes(ctx, div_blocks, &bs_info);
// if joint_stereo and block_switching is set, independent decoding
// is signaled via the first bit of bs_info
if (sconf->joint_stereo && sconf->block_switching)
if (bs_info >> 31)
independent_bs = 2;
// if this is the last channel, it has to be decoded independently
if (c == avctx->channels - 1)
independent_bs = 1;
if (independent_bs) {
ret = decode_blocks_ind(ctx, ra_frame, c,
div_blocks, js_blocks);
if (ret < 0)
return ret;
independent_bs--;
} else {
ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks);
if (ret < 0)
return ret;
c++;
// store carryover raw samples
memmove(ctx->raw_samples[c] - sconf->max_order,
ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
sizeof(*ctx->raw_samples[c]) * sconf->max_order);
} else { // multi-channel coding
ALSBlockData bd = { 0 };
int b, ret;
int *reverted_channels = ctx->reverted_channels;
unsigned int offset = 0;
for (c = 0; c < avctx->channels; c++)
if (ctx->chan_data[c] < ctx->chan_data_buffer) {
av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
bd.ra_block = ra_frame;
bd.prev_raw_samples = ctx->prev_raw_samples;
get_block_sizes(ctx, div_blocks, &bs_info);
for (b = 0; b < ctx->num_blocks; b++) {
bd.block_length = div_blocks[b];
if (bd.block_length <= 0) {
av_log(ctx->avctx, AV_LOG_WARNING,
"Invalid block length %u in channel data!\n",
bd.block_length);
continue;
for (c = 0; c < avctx->channels; c++) {
bd.const_block = ctx->const_block + c;
bd.shift_lsbs = ctx->shift_lsbs + c;
bd.opt_order = ctx->opt_order + c;
bd.store_prev_samples = ctx->store_prev_samples + c;
bd.use_ltp = ctx->use_ltp + c;
bd.ltp_lag = ctx->ltp_lag + c;
bd.ltp_gain = ctx->ltp_gain[c];
bd.lpc_cof = ctx->lpc_cof[c];
bd.quant_cof = ctx->quant_cof[c];
bd.raw_samples = ctx->raw_samples[c] + offset;
bd.raw_other = NULL;
if ((ret = read_block(ctx, &bd)) < 0)
return ret;
if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0)
return ret;
for (c = 0; c < avctx->channels; c++) {
ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
reverted_channels, offset, c);
if (ret < 0)
return ret;
for (c = 0; c < avctx->channels; c++) {
bd.const_block = ctx->const_block + c;
bd.shift_lsbs = ctx->shift_lsbs + c;
bd.opt_order = ctx->opt_order + c;
bd.store_prev_samples = ctx->store_prev_samples + c;
bd.use_ltp = ctx->use_ltp + c;
bd.ltp_lag = ctx->ltp_lag + c;
bd.ltp_gain = ctx->ltp_gain[c];
bd.lpc_cof = ctx->lpc_cof[c];
bd.quant_cof = ctx->quant_cof[c];
bd.raw_samples = ctx->raw_samples[c] + offset;
if ((ret = decode_block(ctx, &bd)) < 0)
return ret;
memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
offset += div_blocks[b];
bd.ra_block = 0;
// store carryover raw samples
for (c = 0; c < avctx->channels; c++)
memmove(ctx->raw_samples[c] - sconf->max_order,
ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
sizeof(*ctx->raw_samples[c]) * sconf->max_order);
// TODO: read_diff_float_data
return 0; | 15,199 |
FFmpeg | 1b9ca38d9d06d319fffd61d27e4eb385d6572ba8 | 1 | int swr_resample(AVResampleContext *c, short *dst, const short *src, int *consumed, int src_size, int dst_size, int update_ctx){
int dst_index, i;
int index= c->index;
int frac= c->frac;
int dst_incr_frac= c->dst_incr % c->src_incr;
int dst_incr= c->dst_incr / c->src_incr;
int compensation_distance= c->compensation_distance;
if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){
int64_t index2= ((int64_t)index)<<32;
int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr);
for(dst_index=0; dst_index < dst_size; dst_index++){
dst[dst_index] = src[index2>>32];
index2 += incr;
}
frac += dst_index * dst_incr_frac;
index += dst_index * dst_incr;
index += frac / c->src_incr;
frac %= c->src_incr;
}else{
for(dst_index=0; dst_index < dst_size; dst_index++){
FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
int sample_index= index >> c->phase_shift;
FELEM2 val=0;
if(sample_index < 0){
for(i=0; i<c->filter_length; i++)
val += src[FFABS(sample_index + i) % src_size] * filter[i];
}else if(sample_index + c->filter_length > src_size){
break;
}else if(c->linear){
FELEM2 v2=0;
for(i=0; i<c->filter_length; i++){
val += src[sample_index + i] * (FELEM2)filter[i];
v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
}
val+=(v2-val)*(FELEML)frac / c->src_incr;
}else{
for(i=0; i<c->filter_length; i++){
val += src[sample_index + i] * (FELEM2)filter[i];
}
}
#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
dst[dst_index] = av_clip_int16(lrintf(val));
#else
val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
#endif
frac += dst_incr_frac;
index += dst_incr;
if(frac >= c->src_incr){
frac -= c->src_incr;
index++;
}
if(dst_index + 1 == compensation_distance){
compensation_distance= 0;
dst_incr_frac= c->ideal_dst_incr % c->src_incr;
dst_incr= c->ideal_dst_incr / c->src_incr;
}
}
}
*consumed= FFMAX(index, 0) >> c->phase_shift;
if(index>=0) index &= c->phase_mask;
if(compensation_distance){
compensation_distance -= dst_index;
assert(compensation_distance > 0);
}
if(update_ctx){
c->frac= frac;
c->index= index;
c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
c->compensation_distance= compensation_distance;
}
#if 0
if(update_ctx && !c->compensation_distance){
#undef rand
av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
}
#endif
return dst_index;
}
| 15,200 |
qemu | f8ed85ac992c48814d916d5df4d44f9a971c5de4 | 1 | static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
{
STM32F205State *s = STM32F205_SOC(dev_soc);
DeviceState *syscfgdev, *usartdev, *timerdev;
SysBusDevice *syscfgbusdev, *usartbusdev, *timerbusdev;
qemu_irq *pic;
Error *err = NULL;
int i;
MemoryRegion *system_memory = get_system_memory();
MemoryRegion *sram = g_new(MemoryRegion, 1);
MemoryRegion *flash = g_new(MemoryRegion, 1);
MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
memory_region_init_ram(flash, NULL, "STM32F205.flash", FLASH_SIZE,
&error_abort);
memory_region_init_alias(flash_alias, NULL, "STM32F205.flash.alias",
flash, 0, FLASH_SIZE);
vmstate_register_ram_global(flash);
memory_region_set_readonly(flash, true);
memory_region_set_readonly(flash_alias, true);
memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash);
memory_region_add_subregion(system_memory, 0, flash_alias);
memory_region_init_ram(sram, NULL, "STM32F205.sram", SRAM_SIZE,
&error_abort);
vmstate_register_ram_global(sram);
memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram);
pic = armv7m_init(get_system_memory(), FLASH_SIZE, 96,
s->kernel_filename, s->cpu_model);
/* System configuration controller */
syscfgdev = DEVICE(&s->syscfg);
object_property_set_bool(OBJECT(&s->syscfg), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
syscfgbusdev = SYS_BUS_DEVICE(syscfgdev);
sysbus_mmio_map(syscfgbusdev, 0, 0x40013800);
sysbus_connect_irq(syscfgbusdev, 0, pic[71]);
/* Attach UART (uses USART registers) and USART controllers */
for (i = 0; i < STM_NUM_USARTS; i++) {
usartdev = DEVICE(&(s->usart[i]));
object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
usartbusdev = SYS_BUS_DEVICE(usartdev);
sysbus_mmio_map(usartbusdev, 0, usart_addr[i]);
sysbus_connect_irq(usartbusdev, 0, pic[usart_irq[i]]);
}
/* Timer 2 to 5 */
for (i = 0; i < STM_NUM_TIMERS; i++) {
timerdev = DEVICE(&(s->timer[i]));
qdev_prop_set_uint64(timerdev, "clock-frequency", 1000000000);
object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
timerbusdev = SYS_BUS_DEVICE(timerdev);
sysbus_mmio_map(timerbusdev, 0, timer_addr[i]);
sysbus_connect_irq(timerbusdev, 0, pic[timer_irq[i]]);
}
}
| 15,202 |
FFmpeg | 92e483f8ed70d88d4f64337f65bae212502735d4 | 1 | static int cmp_int(const void *p1, const void *p2)
{
int left = *(const int *)p1;
int right = *(const int *)p2;
return ((left > right) - (left < right));
}
| 15,203 |
FFmpeg | dba5b06ead6bbec8fd1207d778240188182c8361 | 1 | static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
{
const CodecMime *mime = ff_id3v2_mime_tags;
enum CodecID id = CODEC_ID_NONE;
uint8_t mimetype[64], *desc = NULL, *data = NULL;
AVIOContext *pb = NULL;
AVStream *st;
int type, width, height;
int len, ret = 0;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL);
if (!pb)
return AVERROR(ENOMEM);
/* read the picture type */
type = avio_rb32(pb);
if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type);
ret = AVERROR_INVALIDDATA;
goto fail;
}
/* picture mimetype */
len = avio_rb32(pb);
if (len <= 0 ||
avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) {
av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached "
"picture.\n");
ret = AVERROR_INVALIDDATA;
goto fail;
}
mimetype[len] = 0;
while (mime->id != CODEC_ID_NONE) {
if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
id = mime->id;
break;
}
mime++;
}
if (id == CODEC_ID_NONE) {
av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
mimetype);
ret = AVERROR_INVALIDDATA;
goto fail;
}
/* picture description */
len = avio_rb32(pb);
if (len > 0) {
if (!(desc = av_malloc(len + 1))) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (avio_read(pb, desc, len) != len) {
ret = AVERROR(EIO);
goto fail;
}
desc[len] = 0;
}
/* picture metadata */
width = avio_rb32(pb);
height = avio_rb32(pb);
avio_skip(pb, 8);
/* picture data */
len = avio_rb32(pb);
if (len <= 0) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
if (!(data = av_malloc(len))) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (avio_read(pb, data, len) != len) {
ret = AVERROR(EIO);
goto fail;
}
av_init_packet(&st->attached_pic);
st->attached_pic.data = data;
st->attached_pic.size = len;
st->attached_pic.destruct = av_destruct_packet;
st->attached_pic.stream_index = st->index;
st->attached_pic.flags |= AV_PKT_FLAG_KEY;
st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = id;
st->codec->width = width;
st->codec->height = height;
av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
if (desc)
av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
av_freep(&pb);
return 0;
fail:
av_freep(&desc);
av_freep(&data);
av_freep(&pb);
return ret;
}
| 15,205 |
qemu | 82a41186941c419afde977f477f19c545b40c1c5 | 1 | void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, Error **errp)
{
error_setg(errp, "AioContext polling is not implemented on Windows");
}
| 15,207 |
qemu | 1e356fc14beaa3ece6c0e961bd479af58be3198b | 1 | static void host_memory_backend_set_prealloc(Object *obj, bool value,
Error **errp)
{
Error *local_err = NULL;
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
if (backend->force_prealloc) {
if (value) {
error_setg(errp,
"remove -mem-prealloc to use the prealloc property");
return;
}
}
if (!memory_region_size(&backend->mr)) {
backend->prealloc = value;
return;
}
if (value && !backend->prealloc) {
int fd = memory_region_get_fd(&backend->mr);
void *ptr = memory_region_get_ram_ptr(&backend->mr);
uint64_t sz = memory_region_size(&backend->mr);
os_mem_prealloc(fd, ptr, sz, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
backend->prealloc = true;
}
}
| 15,208 |
FFmpeg | 4d7c71c36467331f1e0c0f17af9f371d33308a9c | 1 | void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
{
AVPacketList **next_point, *this_pktl;
this_pktl = av_mallocz(sizeof(AVPacketList));
this_pktl->pkt= *pkt;
pkt->destruct= NULL; // do not free original but only the copy
av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory
if(s->streams[pkt->stream_index]->last_in_packet_buffer){
next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
}else
next_point = &s->packet_buffer;
if(*next_point){
if(compare(s, &s->packet_buffer_end->pkt, pkt)){
while(!compare(s, &(*next_point)->pkt, pkt)){
next_point= &(*next_point)->next;
}
goto next_non_null;
}else{
next_point = &(s->packet_buffer_end->next);
}
}
assert(!*next_point);
s->packet_buffer_end= this_pktl;
next_non_null:
this_pktl->next= *next_point;
s->streams[pkt->stream_index]->last_in_packet_buffer=
*next_point= this_pktl;
}
| 15,210 |
qemu | ac97393dc7c4761af6104fb8fca5f600899f687b | 1 | static void read_partition(uint8_t *p, struct partition_record *r)
{
r->bootable = p[0];
r->start_head = p[1];
r->start_cylinder = p[3] | ((p[2] << 2) & 0x0300);
r->start_sector = p[2] & 0x3f;
r->system = p[4];
r->end_head = p[5];
r->end_cylinder = p[7] | ((p[6] << 2) & 0x300);
r->end_sector = p[6] & 0x3f;
r->start_sector_abs = p[8] | p[9] << 8 | p[10] << 16 | p[11] << 24;
r->nb_sectors_abs = p[12] | p[13] << 8 | p[14] << 16 | p[15] << 24;
}
| 15,211 |
FFmpeg | 5a5c1b244281c3edcffca322b0c664ed620b1e24 | 1 | static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
{
AVFrame *frame = data;
DxaDecContext * const c = avctx->priv_data;
uint8_t *outptr, *srcptr, *tmpptr;
unsigned long dsize;
int i, j, compr, ret;
int stride;
int pc = 0;
GetByteContext gb;
bytestream2_init(&gb, avpkt->data, avpkt->size);
/* make the palette available on the way out */
if (bytestream2_peek_le32(&gb) == MKTAG('C','M','A','P')) {
bytestream2_skip(&gb, 4);
for(i = 0; i < 256; i++){
c->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&gb);
}
pc = 1;
}
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
memcpy(frame->data[1], c->pal, AVPALETTE_SIZE);
frame->palette_has_changed = pc;
outptr = frame->data[0];
srcptr = c->decomp_buf;
tmpptr = c->prev->data[0];
stride = frame->linesize[0];
if (bytestream2_get_le32(&gb) == MKTAG('N','U','L','L'))
compr = -1;
else
compr = bytestream2_get_byte(&gb);
dsize = c->dsize;
if (compr != 4 && compr != -1) {
bytestream2_skip(&gb, 4);
if (uncompress(c->decomp_buf, &dsize, avpkt->data + bytestream2_tell(&gb),
bytestream2_get_bytes_left(&gb)) != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
return AVERROR_UNKNOWN;
}
memset(c->decomp_buf + dsize, 0, DECOMP_BUF_PADDING);
}
if (avctx->debug & FF_DEBUG_PICT_INFO)
av_log(avctx, AV_LOG_DEBUG, "compr:%2d, dsize:%d\n", compr, (int)dsize);
switch(compr){
case -1:
frame->key_frame = 0;
frame->pict_type = AV_PICTURE_TYPE_P;
if (c->prev->data[0])
memcpy(frame->data[0], c->prev->data[0], frame->linesize[0] * avctx->height);
else{ // Should happen only when first frame is 'NULL'
memset(frame->data[0], 0, frame->linesize[0] * avctx->height);
frame->key_frame = 1;
frame->pict_type = AV_PICTURE_TYPE_I;
}
break;
case 2:
case 4:
frame->key_frame = 1;
frame->pict_type = AV_PICTURE_TYPE_I;
for (j = 0; j < avctx->height; j++) {
memcpy(outptr, srcptr, avctx->width);
outptr += stride;
srcptr += avctx->width;
}
break;
case 3:
case 5:
if (!tmpptr) {
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
if (!(avctx->flags2 & CODEC_FLAG2_SHOW_ALL))
return AVERROR_INVALIDDATA;
}
frame->key_frame = 0;
frame->pict_type = AV_PICTURE_TYPE_P;
for (j = 0; j < avctx->height; j++) {
if(tmpptr){
for(i = 0; i < avctx->width; i++)
outptr[i] = srcptr[i] ^ tmpptr[i];
tmpptr += stride;
}else
memcpy(outptr, srcptr, avctx->width);
outptr += stride;
srcptr += avctx->width;
}
break;
case 12: // ScummVM coding
case 13:
frame->key_frame = 0;
frame->pict_type = AV_PICTURE_TYPE_P;
if (!c->prev->data[0]) {
av_log(avctx, AV_LOG_ERROR, "Missing reference frame\n");
return AVERROR_INVALIDDATA;
}
decode_13(avctx, c, frame->data[0], frame->linesize[0], srcptr, c->prev->data[0]);
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", compr);
return AVERROR_INVALIDDATA;
}
av_frame_unref(c->prev);
if ((ret = av_frame_ref(c->prev, frame)) < 0)
return ret;
*got_frame = 1;
/* always report that the buffer was completely consumed */
return avpkt->size;
}
| 15,212 |
qemu | b8e23926c568f2e963af39028b71c472e3023793 | 1 | static void virtio_gpu_resource_destroy(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res)
{
pixman_image_unref(res->image);
QTAILQ_REMOVE(&g->reslist, res, next);
g->hostmem -= res->hostmem;
g_free(res);
} | 15,213 |
qemu | 874adf45dbfbae2810423527d777ba37bc5ca974 | 1 | void virtio_save(VirtIODevice *vdev, QEMUFile *f)
{
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t guest_features_lo = (vdev->guest_features & 0xffffffff);
int i;
if (k->save_config) {
k->save_config(qbus->parent, f);
}
qemu_put_8s(f, &vdev->status);
qemu_put_8s(f, &vdev->isr);
qemu_put_be16s(f, &vdev->queue_sel);
qemu_put_be32s(f, &guest_features_lo);
qemu_put_be32(f, vdev->config_len);
qemu_put_buffer(f, vdev->config, vdev->config_len);
for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
if (vdev->vq[i].vring.num == 0)
break;
}
qemu_put_be32(f, i);
for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
if (vdev->vq[i].vring.num == 0)
break;
qemu_put_be32(f, vdev->vq[i].vring.num);
if (k->has_variable_vring_alignment) {
qemu_put_be32(f, vdev->vq[i].vring.align);
}
/* XXX virtio-1 devices */
qemu_put_be64(f, vdev->vq[i].vring.desc);
qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
if (k->save_queue) {
k->save_queue(qbus->parent, i, f);
}
}
if (vdc->save != NULL) {
vdc->save(vdev, f);
}
if (vdc->vmsd) {
vmstate_save_state(f, vdc->vmsd, vdev, NULL);
}
/* Subsections */
vmstate_save_state(f, &vmstate_virtio, vdev, NULL);
}
| 15,214 |
qemu | 392808b49b6aee066d0c1d200e72fc3dc11c9d0f | 1 | static void virtio_blk_dma_restart_cb(void *opaque, int running,
RunState state)
{
VirtIOBlock *s = opaque;
if (!running)
return;
if (!s->bh) {
s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
qemu_bh_schedule(s->bh);
}
}
| 15,215 |
FFmpeg | 2f3b028c7117e03267ea7f88d0d612e70f1afc06 | 1 | static char *json_escape_str(const char *s)
{
static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
char *ret, *p;
int i, len = 0;
// compute the length of the escaped string
for (i = 0; s[i]; i++) {
if (strchr(json_escape, s[i])) len += 2; // simple escape
else if ((unsigned char)s[i] < 32) len += 6; // handle non-printable chars
else len += 1; // char copy
}
p = ret = av_malloc(len + 1);
if (!p)
return NULL;
for (i = 0; s[i]; i++) {
char *q = strchr(json_escape, s[i]);
if (q) {
*p++ = '\\';
*p++ = json_subst[q - json_escape];
} else if ((unsigned char)s[i] < 32) {
snprintf(p, 7, "\\u00%02x", s[i] & 0xff);
p += 6;
} else {
*p++ = s[i];
}
}
*p = 0;
return ret;
}
| 15,216 |
FFmpeg | 8108551a5c4c4c9696582c73d000f94b12cd95a5 | 0 | static int gif_image_write_header(ByteIOContext *pb,
int width, int height, uint32_t *palette)
{
int i;
unsigned int v;
put_tag(pb, "GIF");
put_tag(pb, "89a");
put_le16(pb, width);
put_le16(pb, height);
put_byte(pb, 0xf7); /* flags: global clut, 256 entries */
put_byte(pb, 0x1f); /* background color index */
put_byte(pb, 0); /* aspect ratio */
/* the global palette */
if (!palette) {
put_buffer(pb, (unsigned char *)gif_clut, 216*3);
for(i=0;i<((256-216)*3);i++)
put_byte(pb, 0);
} else {
for(i=0;i<256;i++) {
v = palette[i];
put_byte(pb, (v >> 16) & 0xff);
put_byte(pb, (v >> 8) & 0xff);
put_byte(pb, (v) & 0xff);
}
}
/* application extension header */
/* XXX: not really sure what to put in here... */
#ifdef GIF_ADD_APP_HEADER
put_byte(pb, 0x21);
put_byte(pb, 0xff);
put_byte(pb, 0x0b);
put_tag(pb, "NETSCAPE2.0");
put_byte(pb, 0x03);
put_byte(pb, 0x01);
put_byte(pb, 0x00);
put_byte(pb, 0x00);
#endif
return 0;
}
| 15,218 |
FFmpeg | 0f64b6cd22411f574cbc75cab3b6db7dba023ed6 | 0 | static int rscc_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
RsccContext *ctx = avctx->priv_data;
GetByteContext *gbc = &ctx->gbc;
GetByteContext tiles_gbc;
AVFrame *frame = data;
const uint8_t *pixels, *raw;
uint8_t *inflated_tiles = NULL;
int tiles_nb, packed_size, pixel_size = 0;
int i, ret = 0;
bytestream2_init(gbc, avpkt->data, avpkt->size);
/* Size check */
if (bytestream2_get_bytes_left(gbc) < 12) {
av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
return AVERROR_INVALIDDATA;
}
/* Read number of tiles, and allocate the array */
tiles_nb = bytestream2_get_le16(gbc);
av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
tiles_nb * sizeof(*ctx->tiles));
if (!ctx->tiles) {
ret = AVERROR(ENOMEM);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Frame with %d tiles.\n", tiles_nb);
/* When there are more than 5 tiles, they are packed together with
* a size header. When that size does not match the number of tiles
* times the tile size, it means it needs to be inflated as well */
if (tiles_nb > 5) {
uLongf packed_tiles_size;
if (tiles_nb < 32)
packed_tiles_size = bytestream2_get_byte(gbc);
else
packed_tiles_size = bytestream2_get_le16(gbc);
ff_dlog(avctx, "packed tiles of size %lu.\n", packed_tiles_size);
/* If necessary, uncompress tiles, and hijack the bytestream reader */
if (packed_tiles_size != tiles_nb * TILE_SIZE) {
uLongf length = tiles_nb * TILE_SIZE;
inflated_tiles = av_malloc(length);
if (!inflated_tiles) {
ret = AVERROR(ENOMEM);
goto end;
}
ret = uncompress(inflated_tiles, &length,
gbc->buffer, packed_tiles_size);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Tile deflate error %d.\n", ret);
ret = AVERROR_UNKNOWN;
goto end;
}
/* Skip the compressed tile section in the main byte reader,
* and point it to read the newly uncompressed data */
bytestream2_skip(gbc, packed_tiles_size);
bytestream2_init(&tiles_gbc, inflated_tiles, length);
gbc = &tiles_gbc;
}
}
/* Fill in array of tiles, keeping track of how many pixels are updated */
for (i = 0; i < tiles_nb; i++) {
ctx->tiles[i].x = bytestream2_get_le16(gbc);
ctx->tiles[i].w = bytestream2_get_le16(gbc);
ctx->tiles[i].y = bytestream2_get_le16(gbc);
ctx->tiles[i].h = bytestream2_get_le16(gbc);
pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * ctx->component_size;
ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
if (ctx->tiles[i].w == 0 || ctx->tiles[i].h == 0) {
av_log(avctx, AV_LOG_ERROR,
"invalid tile %d at (%d.%d) with size %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
ret = AVERROR_INVALIDDATA;
goto end;
} else if (ctx->tiles[i].x + ctx->tiles[i].w > avctx->width ||
ctx->tiles[i].y + ctx->tiles[i].h > avctx->height) {
av_log(avctx, AV_LOG_ERROR,
"out of bounds tile %d at (%d.%d) with size %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
ret = AVERROR_INVALIDDATA;
goto end;
}
}
/* Reset the reader in case it had been modified before */
gbc = &ctx->gbc;
/* Extract how much pixel data the tiles contain */
if (pixel_size < 0x100)
packed_size = bytestream2_get_byte(gbc);
else if (pixel_size < 0x10000)
packed_size = bytestream2_get_le16(gbc);
else if (pixel_size < 0x1000000)
packed_size = bytestream2_get_le24(gbc);
else
packed_size = bytestream2_get_le32(gbc);
ff_dlog(avctx, "pixel_size %d packed_size %d.\n", pixel_size, packed_size);
if (packed_size < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid tile size %d\n", packed_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
/* Get pixels buffer, it may be deflated or just raw */
if (pixel_size == packed_size) {
if (bytestream2_get_bytes_left(gbc) < pixel_size) {
av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", pixel_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
pixels = gbc->buffer;
} else {
uLongf len = ctx->inflated_size;
if (bytestream2_get_bytes_left(gbc) < packed_size) {
av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", packed_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
ret = uncompress(ctx->inflated_buf, &len, gbc->buffer, packed_size);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Pixel deflate error %d.\n", ret);
ret = AVERROR_UNKNOWN;
goto end;
}
pixels = ctx->inflated_buf;
}
/* Allocate when needed */
ret = ff_reget_buffer(avctx, ctx->reference);
if (ret < 0)
goto end;
/* Pointer to actual pixels, will be updated when data is consumed */
raw = pixels;
for (i = 0; i < tiles_nb; i++) {
uint8_t *dst = ctx->reference->data[0] + ctx->reference->linesize[0] *
(avctx->height - ctx->tiles[i].y - 1) +
ctx->tiles[i].x * ctx->component_size;
av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
raw, ctx->tiles[i].w * ctx->component_size,
ctx->tiles[i].w * ctx->component_size,
ctx->tiles[i].h);
raw += ctx->tiles[i].w * ctx->component_size * ctx->tiles[i].h;
}
/* Frame is ready to be output */
ret = av_frame_ref(frame, ctx->reference);
if (ret < 0)
goto end;
/* Keyframe when the number of pixels updated matches the whole surface */
if (pixel_size == ctx->inflated_size) {
frame->pict_type = AV_PICTURE_TYPE_I;
frame->key_frame = 1;
} else {
frame->pict_type = AV_PICTURE_TYPE_P;
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
const uint8_t *pal = av_packet_get_side_data(avpkt,
AV_PKT_DATA_PALETTE,
NULL);
if (pal) {
frame->palette_has_changed = 1;
memcpy(ctx->pal, pal, AVPALETTE_SIZE);
}
memcpy (frame->data[1], ctx->pal, AVPALETTE_SIZE);
}
*got_frame = 1;
end:
av_free(inflated_tiles);
return ret;
}
| 15,220 |
FFmpeg | 7c9d2ad45f4e46ad2c3b2e93051efbe1e0d0529e | 0 | static int parse_frame_header(DCACoreDecoder *s)
{
DCACoreFrameHeader h = { 0 };
int err = avpriv_dca_parse_core_frame_header(&s->gb, &h);
if (err < 0) {
switch (err) {
case DCA_PARSE_ERROR_DEFICIT_SAMPLES:
av_log(s->avctx, AV_LOG_ERROR, "Deficit samples are not supported\n");
return h.normal_frame ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
case DCA_PARSE_ERROR_PCM_BLOCKS:
av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of PCM sample blocks (%d)\n", h.npcmblocks);
return (h.npcmblocks < 6 || h.normal_frame) ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
case DCA_PARSE_ERROR_FRAME_SIZE:
av_log(s->avctx, AV_LOG_ERROR, "Invalid core frame size (%d bytes)\n", h.frame_size);
return AVERROR_INVALIDDATA;
case DCA_PARSE_ERROR_AMODE:
av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel arrangement (%d)\n", h.audio_mode);
return AVERROR_PATCHWELCOME;
case DCA_PARSE_ERROR_SAMPLE_RATE:
av_log(s->avctx, AV_LOG_ERROR, "Invalid core audio sampling frequency\n");
return AVERROR_INVALIDDATA;
case DCA_PARSE_ERROR_RESERVED_BIT:
av_log(s->avctx, AV_LOG_ERROR, "Reserved bit set\n");
return AVERROR_INVALIDDATA;
case DCA_PARSE_ERROR_LFE_FLAG:
av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects flag\n");
return AVERROR_INVALIDDATA;
case DCA_PARSE_ERROR_PCM_RES:
av_log(s->avctx, AV_LOG_ERROR, "Invalid source PCM resolution\n");
return AVERROR_INVALIDDATA;
default:
av_log(s->avctx, AV_LOG_ERROR, "Unknown core frame header error\n");
return AVERROR_INVALIDDATA;
}
}
s->crc_present = h.crc_present;
s->npcmblocks = h.npcmblocks;
s->frame_size = h.frame_size;
s->audio_mode = h.audio_mode;
s->sample_rate = avpriv_dca_sample_rates[h.sr_code];
s->bit_rate = ff_dca_bit_rates[h.br_code];
s->drc_present = h.drc_present;
s->ts_present = h.ts_present;
s->aux_present = h.aux_present;
s->ext_audio_type = h.ext_audio_type;
s->ext_audio_present = h.ext_audio_present;
s->sync_ssf = h.sync_ssf;
s->lfe_present = h.lfe_present;
s->predictor_history = h.predictor_history;
s->filter_perfect = h.filter_perfect;
s->source_pcm_res = ff_dca_bits_per_sample[h.pcmr_code];
s->es_format = h.pcmr_code & 1;
s->sumdiff_front = h.sumdiff_front;
s->sumdiff_surround = h.sumdiff_surround;
return 0;
}
| 15,221 |
FFmpeg | 56ee3f9de7b9f6090d599a27d33a392890a2f7b8 | 0 | static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx)
{
OutputFile *of = output_files[ost->file_index];
AVFilterGraph *graph = (*last_filter)->graph;
AVFilterContext *ctx;
const AVFilter *trim;
const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim";
char filter_name[128];
int ret = 0;
if (of->recording_time == INT64_MAX && !of->start_time)
return 0;
trim = avfilter_get_by_name(name);
if (!trim) {
av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
"recording time.\n", name);
return AVERROR_FILTER_NOT_FOUND;
}
snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d",
name, ost->file_index, ost->index);
ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
if (!ctx)
return AVERROR(ENOMEM);
if (of->recording_time != INT64_MAX) {
ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
AV_OPT_SEARCH_CHILDREN);
}
if (ret >= 0 && of->start_time) {
ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,
AV_OPT_SEARCH_CHILDREN);
}
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
return ret;
}
ret = avfilter_init_str(ctx, NULL);
if (ret < 0)
return ret;
ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
if (ret < 0)
return ret;
*last_filter = ctx;
*pad_idx = 0;
return 0;
}
| 15,223 |
FFmpeg | 1ec83d9a9e472f485897ac92bad9631d551a8c5b | 0 | static int add_doubles_metadata(const uint8_t **buf, int count,
const char *name, const char *sep,
TiffContext *s)
{
char *ap;
int i;
double *dp = av_malloc(count * sizeof(double));
if (!dp)
return AVERROR(ENOMEM);
for (i = 0; i < count; i++)
dp[i] = tget_double(buf, s->le);
ap = doubles2str(dp, count, sep);
av_freep(&dp);
if (!ap)
return AVERROR(ENOMEM);
av_dict_set(&s->picture.metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
return 0;
}
| 15,224 |
qemu | 441692ddd8321d5e0f09b163e86410e578d87236 | 1 | static inline int onenand_load_spare(OneNANDState *s, int sec, int secn,
void *dest)
{
uint8_t buf[512];
if (s->blk_cur) {
if (blk_read(s->blk_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) {
return 1;
}
memcpy(dest, buf + ((sec & 31) << 4), secn << 4);
} else if (sec + secn > s->secs_cur) {
return 1;
} else {
memcpy(dest, s->current + (s->secs_cur << 9) + (sec << 4), secn << 4);
}
return 0;
}
| 15,228 |
FFmpeg | d4be08e0c9fc9ed2862e952a489ef6a8943b5e5d | 1 | X264_init(AVCodecContext *avctx)
{
X264Context *x4 = avctx->priv_data;
x264_param_default(&x4->params);
x4->params.pf_log = X264_log;
x4->params.p_log_private = avctx;
x4->params.i_keyint_max = avctx->gop_size;
x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
if(avctx->flags & CODEC_FLAG_PASS2) x4->params.rc.b_stat_read = 1;
else{
if(avctx->crf){
x4->params.rc.i_rc_method = X264_RC_CRF;
x4->params.rc.f_rf_constant = avctx->crf;
}else if(avctx->cqp > -1){
x4->params.rc.i_rc_method = X264_RC_CQP;
x4->params.rc.i_qp_constant = avctx->cqp;
}
}
// if neither crf nor cqp modes are selected we have to enable the RC
// we do it this way because we cannot check if the bitrate has been set
if(!(avctx->crf || (avctx->cqp > -1))) x4->params.rc.i_rc_method = X264_RC_ABR;
x4->params.i_bframe = avctx->max_b_frames;
x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
x4->params.b_bframe_adaptive = avctx->b_frame_strategy;
x4->params.i_bframe_bias = avctx->bframebias;
x4->params.b_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID;
avctx->has_b_frames= avctx->flags2 & CODEC_FLAG2_BPYRAMID ? 2 : !!avctx->max_b_frames;
x4->params.i_keyint_min = avctx->keyint_min;
if(x4->params.i_keyint_min > x4->params.i_keyint_max)
x4->params.i_keyint_min = x4->params.i_keyint_max;
x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
x4->params.rc.i_qp_min = avctx->qmin;
x4->params.rc.i_qp_max = avctx->qmax;
x4->params.rc.i_qp_step = avctx->max_qdiff;
x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
x4->params.rc.f_complexity_blur = avctx->complexityblur;
x4->params.i_frame_reference = avctx->refs;
x4->params.i_width = avctx->width;
x4->params.i_height = avctx->height;
x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
x4->params.i_fps_num = avctx->time_base.den;
x4->params.i_fps_den = avctx->time_base.num;
x4->params.analyse.inter = 0;
if(avctx->partitions){
if(avctx->partitions & X264_PART_I4X4)
x4->params.analyse.inter |= X264_ANALYSE_I4x4;
if(avctx->partitions & X264_PART_I8X8)
x4->params.analyse.inter |= X264_ANALYSE_I8x8;
if(avctx->partitions & X264_PART_P8X8)
x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
if(avctx->partitions & X264_PART_P4X4)
x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
if(avctx->partitions & X264_PART_B8X8)
x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
}
x4->params.analyse.i_direct_mv_pred = avctx->directpred;
x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
if(avctx->me_method == ME_EPZS)
x4->params.analyse.i_me_method = X264_ME_DIA;
else if(avctx->me_method == ME_HEX)
x4->params.analyse.i_me_method = X264_ME_HEX;
else if(avctx->me_method == ME_UMH)
x4->params.analyse.i_me_method = X264_ME_UMH;
else if(avctx->me_method == ME_FULL)
x4->params.analyse.i_me_method = X264_ME_ESA;
else if(avctx->me_method == ME_TESA)
x4->params.analyse.i_me_method = X264_ME_TESA;
else x4->params.analyse.i_me_method = X264_ME_HEX;
x4->params.analyse.i_me_range = avctx->me_range;
x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
x4->params.analyse.b_bidir_me = avctx->bidir_refine > 0;
x4->params.analyse.b_bframe_rdo = avctx->flags2 & CODEC_FLAG2_BRDO;
x4->params.analyse.b_mixed_references =
avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
x4->params.analyse.i_trellis = avctx->trellis;
x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
if(avctx->level > 0) x4->params.i_level_idc = avctx->level;
x4->params.rc.f_rate_tolerance =
(float)avctx->bit_rate_tolerance/avctx->bit_rate;
if((avctx->rc_buffer_size != 0) &&
(avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)){
x4->params.rc.f_vbv_buffer_init =
(float)avctx->rc_initial_buffer_occupancy/avctx->rc_buffer_size;
}
else x4->params.rc.f_vbv_buffer_init = 0.9;
x4->params.rc.f_ip_factor = 1/fabs(avctx->i_quant_factor);
x4->params.rc.f_pb_factor = avctx->b_quant_factor;
x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
x4->params.rc.psz_rc_eq = avctx->rc_eq;
x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
x4->params.i_log_level = X264_LOG_DEBUG;
x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
x4->params.i_threads = avctx->thread_count;
x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){
x4->params.b_repeat_headers = 0;
}
x4->enc = x264_encoder_open(&x4->params);
if(!x4->enc)
return -1;
avctx->coded_frame = &x4->out_pic;
if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){
x264_nal_t *nal;
int nnal, i, s = 0;
x264_encoder_headers(x4->enc, &nal, &nnal);
/* 5 bytes NAL header + worst case escaping */
for(i = 0; i < nnal; i++)
s += 5 + nal[i].i_payload * 4 / 3;
avctx->extradata = av_malloc(s);
avctx->extradata_size = encode_nals(avctx->extradata, s, nal, nnal);
}
return 0;
}
| 15,229 |
FFmpeg | 8b830ee9a26d47b138f12a82085cdb372f407f1e | 1 | int configure_filtergraph(FilterGraph *fg)
{
AVFilterInOut *inputs, *outputs, *cur;
int ret, i, simple = !fg->graph_desc;
const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
fg->graph_desc;
avfilter_graph_free(&fg->graph);
if (!(fg->graph = avfilter_graph_alloc()))
return AVERROR(ENOMEM);
if (simple) {
OutputStream *ost = fg->outputs[0]->ost;
char args[512];
AVDictionaryEntry *e = NULL;
snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
fg->graph->scale_sws_opts = av_strdup(args);
args[0] = '\0';
while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
AV_DICT_IGNORE_SUFFIX))) {
av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
}
if (strlen(args))
args[strlen(args) - 1] = '\0';
fg->graph->resample_lavr_opts = av_strdup(args);
}
if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
return ret;
if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' does not have "
"exactly one input and output.\n", graph_desc);
return AVERROR(EINVAL);
}
for (cur = inputs, i = 0; cur; cur = cur->next, i++)
if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0)
return ret;
avfilter_inout_free(&inputs);
for (cur = outputs, i = 0; cur; cur = cur->next, i++)
configure_output_filter(fg, fg->outputs[i], cur);
avfilter_inout_free(&outputs);
if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
return ret;
return 0;
}
| 15,230 |
FFmpeg | 065ee1ec325ed7d34acf13d0bf319c1c6b457e21 | 1 | inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2,
int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
int32_t *mmx2FilterPos)
{
if(srcFormat==IMGFMT_YUY2)
{
RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_UYVY)
{
RENAME(uyvyToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_BGR32)
{
RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_BGR24)
{
RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_BGR16)
{
RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_BGR15)
{
RENAME(bgr15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_RGB32)
{
RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(srcFormat==IMGFMT_RGB24)
{
RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if(isGray(srcFormat))
{
return;
}
#ifdef HAVE_MMX
// use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one)
if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
#else
if(!(flags&SWS_FAST_BILINEAR))
#endif
{
RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
}
else // Fast Bilinear upscale / crap downscale
{
#if defined(ARCH_X86) || defined(ARCH_X86_64)
#ifdef HAVE_MMX2
int i;
if(canMMX2BeUsed)
{
asm volatile(
"pxor %%mm7, %%mm7 \n\t"
"mov %0, %%"REG_c" \n\t"
"mov %1, %%"REG_D" \n\t"
"mov %2, %%"REG_d" \n\t"
"mov %3, %%"REG_b" \n\t"
"xor %%"REG_a", %%"REG_a" \n\t" // i
PREFETCH" (%%"REG_c") \n\t"
PREFETCH" 32(%%"REG_c") \n\t"
PREFETCH" 64(%%"REG_c") \n\t"
#ifdef ARCH_X86_64
#define FUNNY_UV_CODE \
"movl (%%"REG_b"), %%esi \n\t"\
"call *%4 \n\t"\
"movl (%%"REG_b", %%"REG_a"), %%esi\n\t"\
"add %%"REG_S", %%"REG_c" \n\t"\
"add %%"REG_a", %%"REG_D" \n\t"\
"xor %%"REG_a", %%"REG_a" \n\t"\
#else
#define FUNNY_UV_CODE \
"movl (%%"REG_b"), %%esi \n\t"\
"call *%4 \n\t"\
"addl (%%"REG_b", %%"REG_a"), %%"REG_c"\n\t"\
"add %%"REG_a", %%"REG_D" \n\t"\
"xor %%"REG_a", %%"REG_a" \n\t"\
#endif
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
"xor %%"REG_a", %%"REG_a" \n\t" // i
"mov %5, %%"REG_c" \n\t" // src
"mov %1, %%"REG_D" \n\t" // buf1
"add $4096, %%"REG_D" \n\t"
PREFETCH" (%%"REG_c") \n\t"
PREFETCH" 32(%%"REG_c") \n\t"
PREFETCH" 64(%%"REG_c") \n\t"
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
:: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos),
"m" (funnyUVCode), "m" (src2)
: "%"REG_a, "%"REG_b, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
);
for(i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
{
// printf("%d %d %d\n", dstWidth, i, srcW);
dst[i] = src1[srcW-1]*128;
dst[i+2048] = src2[srcW-1]*128;
}
}
else
{
#endif
long xInc_shr16 = (long) (xInc >> 16);
int xInc_mask = xInc & 0xffff;
asm volatile(
"xor %%"REG_a", %%"REG_a" \n\t" // i
"xor %%"REG_b", %%"REG_b" \n\t" // xx
"xorl %%ecx, %%ecx \n\t" // 2*xalpha
ASMALIGN16
"1: \n\t"
"mov %0, %%"REG_S" \n\t"
"movzbl (%%"REG_S", %%"REG_b"), %%edi \n\t" //src[xx]
"movzbl 1(%%"REG_S", %%"REG_b"), %%esi \n\t" //src[xx+1]
"subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
"imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
"shll $16, %%edi \n\t"
"addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
"mov %1, %%"REG_D" \n\t"
"shrl $9, %%esi \n\t"
"movw %%si, (%%"REG_D", %%"REG_a", 2)\n\t"
"movzbl (%5, %%"REG_b"), %%edi \n\t" //src[xx]
"movzbl 1(%5, %%"REG_b"), %%esi \n\t" //src[xx+1]
"subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
"imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
"shll $16, %%edi \n\t"
"addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
"mov %1, %%"REG_D" \n\t"
"shrl $9, %%esi \n\t"
"movw %%si, 4096(%%"REG_D", %%"REG_a", 2)\n\t"
"addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
"adc %3, %%"REG_b" \n\t" //xx+= xInc>>8 + carry
"add $1, %%"REG_a" \n\t"
"cmp %2, %%"REG_a" \n\t"
" jb 1b \n\t"
/* GCC-3.3 makes MPlayer crash on IA-32 machines when using "g" operand here,
which is needed to support GCC-4.0 */
#if defined(ARCH_X86_64) && ((__GNUC__ > 3) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 4))
:: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
#else
:: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
#endif
"r" (src2)
: "%"REG_a, "%"REG_b, "%ecx", "%"REG_D, "%esi"
);
#ifdef HAVE_MMX2
} //if MMX2 can't be used
#endif
#else
int i;
unsigned int xpos=0;
for(i=0;i<dstWidth;i++)
{
register unsigned int xx=xpos>>16;
register unsigned int xalpha=(xpos&0xFFFF)>>9;
dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
/* slower
dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
*/
xpos+=xInc;
}
#endif
}
}
| 15,231 |
qemu | 3e36aba757f76673007a80b3cd56a4062c2e3462 | 1 | static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
void *value, size_t size, int flags)
{
char *buffer;
int ret;
if (strncmp(name, "user.virtfs.", 12) == 0) {
/*
* Don't allow fetch of user.virtfs namesapce
* in case of mapped security
*/
errno = EACCES;
return -1;
}
buffer = rpath(ctx, path);
ret = lsetxattr(buffer, name, value, size, flags);
g_free(buffer);
return ret;
}
| 15,232 |
qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 | 1 | static void gen_tlbiva(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
#else
TCGv t0;
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
return;
}
t0 = tcg_temp_new();
gen_addr_reg_index(ctx, t0);
gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]);
tcg_temp_free(t0);
#endif
}
| 15,233 |
FFmpeg | d574e22659bd51cdf16723a204fef65a9e783f1d | 0 | static void hdcd_reset(hdcd_state_t *state, unsigned rate)
{
int i;
state->window = 0;
state->readahead = 32;
state->arg = 0;
state->control = 0;
state->running_gain = 0;
state->sustain = 0;
state->sustain_reset = rate * 10;
state->code_counterA = 0;
state->code_counterA_almost = 0;
state->code_counterB = 0;
state->code_counterB_checkfails = 0;
state->code_counterC = 0;
state->code_counterC_unmatched = 0;
state->count_peak_extend = 0;
state->count_transient_filter = 0;
for(i = 0; i < 16; i++) state->gain_counts[i] = 0;
state->max_gain = 0;
state->count_sustain_expired = -1;
}
| 15,234 |
FFmpeg | 4982130d5a7babcb4b2e208fca2c745de7e10658 | 0 | static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
{
AResampleContext *aresample = inlink->dst->priv;
const int n_in = insamplesref->nb_samples;
int64_t delay;
int n_out = n_in * aresample->ratio + 32;
AVFilterLink *const outlink = inlink->dst->outputs[0];
AVFrame *outsamplesref;
int ret;
delay = swr_get_delay(aresample->swr, outlink->sample_rate);
if (delay > 0)
n_out += FFMIN(delay, FFMAX(4096, n_out));
outsamplesref = ff_get_audio_buffer(outlink, n_out);
if(!outsamplesref)
return AVERROR(ENOMEM);
av_frame_copy_props(outsamplesref, insamplesref);
outsamplesref->format = outlink->format;
av_frame_set_channels(outsamplesref, outlink->channels);
outsamplesref->channel_layout = outlink->channel_layout;
outsamplesref->sample_rate = outlink->sample_rate;
if(insamplesref->pts != AV_NOPTS_VALUE) {
int64_t inpts = av_rescale(insamplesref->pts, inlink->time_base.num * (int64_t)outlink->sample_rate * inlink->sample_rate, inlink->time_base.den);
int64_t outpts= swr_next_pts(aresample->swr, inpts);
aresample->next_pts =
outsamplesref->pts = ROUNDED_DIV(outpts, inlink->sample_rate);
} else {
outsamplesref->pts = AV_NOPTS_VALUE;
}
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out,
(void *)insamplesref->extended_data, n_in);
if (n_out <= 0) {
av_frame_free(&outsamplesref);
av_frame_free(&insamplesref);
return 0;
}
aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers
outsamplesref->nb_samples = n_out;
ret = ff_filter_frame(outlink, outsamplesref);
aresample->req_fullfilled= 1;
av_frame_free(&insamplesref);
return ret;
}
| 15,235 |
FFmpeg | 6e249466cc6bd5b17d6e8cbd9a84a636cc92fd60 | 0 | int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MOVMuxContext *mov = s->priv_data;
AVIOContext *pb = s->pb;
MOVTrack *trk = &mov->tracks[pkt->stream_index];
AVCodecContext *enc = trk->enc;
unsigned int samples_in_chunk = 0;
int size = pkt->size, ret = 0;
uint8_t *reformatted_data = NULL;
if (trk->entry) {
int64_t duration = pkt->dts - trk->cluster[trk->entry - 1].dts;
if (duration < 0 || duration > INT_MAX) {
av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" / timestamp: %"PRId64" is out of range for mov/mp4 format\n",
duration, pkt->dts
);
pkt->dts = trk->cluster[trk->entry - 1].dts + 1;
pkt->pts = AV_NOPTS_VALUE;
}
if (pkt->duration < 0) {
av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" is invalid\n", pkt->duration);
return AVERROR(EINVAL);
}
}
if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
int ret;
if (mov->moov_written || mov->flags & FF_MOV_FLAG_EMPTY_MOOV) {
if (mov->frag_interleave && mov->fragments > 0) {
if (trk->entry - trk->entries_flushed >= mov->frag_interleave) {
if ((ret = mov_flush_fragment_interleaving(s, trk)) < 0)
return ret;
}
}
if (!trk->mdat_buf) {
if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0)
return ret;
}
pb = trk->mdat_buf;
} else {
if (!mov->mdat_buf) {
if ((ret = avio_open_dyn_buf(&mov->mdat_buf)) < 0)
return ret;
}
pb = mov->mdat_buf;
}
}
if (enc->codec_id == AV_CODEC_ID_AMR_NB) {
/* We must find out how many AMR blocks there are in one packet */
static const uint16_t packed_size[16] =
{13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
int len = 0;
while (len < size && samples_in_chunk < 100) {
len += packed_size[(pkt->data[len] >> 3) & 0x0F];
samples_in_chunk++;
}
if (samples_in_chunk > 1) {
av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n");
return -1;
}
} else if (enc->codec_id == AV_CODEC_ID_ADPCM_MS ||
enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
samples_in_chunk = enc->frame_size;
} else if (trk->sample_size)
samples_in_chunk = size / trk->sample_size;
else
samples_in_chunk = 1;
/* copy extradata if it exists */
if (trk->vos_len == 0 && enc->extradata_size > 0 &&
!TAG_IS_AVCI(trk->tag) &&
(enc->codec_id != AV_CODEC_ID_DNXHD)) {
trk->vos_len = enc->extradata_size;
trk->vos_data = av_malloc(trk->vos_len);
if (!trk->vos_data) {
ret = AVERROR(ENOMEM);
goto err;
}
memcpy(trk->vos_data, enc->extradata, trk->vos_len);
}
if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
(AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
if (!s->streams[pkt->stream_index]->nb_frames) {
av_log(s, AV_LOG_ERROR, "Malformed AAC bitstream detected: "
"use the audio bitstream filter 'aac_adtstoasc' to fix it "
"('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
return -1;
}
av_log(s, AV_LOG_WARNING, "aac bitstream error\n");
}
if (enc->codec_id == AV_CODEC_ID_H264 && trk->vos_len > 0 && *(uint8_t *)trk->vos_data != 1 && !TAG_IS_AVCI(trk->tag)) {
/* from x264 or from bytestream h264 */
/* nal reformating needed */
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) {
ff_avc_parse_nal_units_buf(pkt->data, &reformatted_data,
&size);
avio_write(pb, reformatted_data, size);
} else {
if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) {
size = ff_mov_cenc_avc_parse_nal_units(&trk->cenc, pb, pkt->data, size);
if (size < 0) {
ret = size;
goto err;
}
} else {
size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
}
}
} else if (enc->codec_id == AV_CODEC_ID_HEVC && trk->vos_len > 6 &&
(AV_RB24(trk->vos_data) == 1 || AV_RB32(trk->vos_data) == 1)) {
/* extradata is Annex B, assume the bitstream is too and convert it */
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) {
ff_hevc_annexb2mp4_buf(pkt->data, &reformatted_data, &size, 0, NULL);
avio_write(pb, reformatted_data, size);
} else {
size = ff_hevc_annexb2mp4(pb, pkt->data, pkt->size, 0, NULL);
}
#if CONFIG_AC3_PARSER
} else if (enc->codec_id == AV_CODEC_ID_EAC3) {
size = handle_eac3(mov, pkt, trk);
if (size < 0)
return size;
else if (!size)
goto end;
avio_write(pb, pkt->data, size);
#endif
} else {
if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) {
if (enc->codec_id == AV_CODEC_ID_H264 && enc->extradata_size > 4) {
int nal_size_length = (enc->extradata[4] & 0x3) + 1;
ret = ff_mov_cenc_avc_write_nal_units(s, &trk->cenc, nal_size_length, pb, pkt->data, size);
} else {
ret = ff_mov_cenc_write_packet(&trk->cenc, pb, pkt->data, size);
}
if (ret) {
goto err;
}
} else {
avio_write(pb, pkt->data, size);
}
}
if ((enc->codec_id == AV_CODEC_ID_DNXHD ||
enc->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) {
/* copy frame to create needed atoms */
trk->vos_len = size;
trk->vos_data = av_malloc(size);
if (!trk->vos_data) {
ret = AVERROR(ENOMEM);
goto err;
}
memcpy(trk->vos_data, pkt->data, size);
}
if (trk->entry >= trk->cluster_capacity) {
unsigned new_capacity = 2 * (trk->entry + MOV_INDEX_CLUSTER_SIZE);
if (av_reallocp_array(&trk->cluster, new_capacity,
sizeof(*trk->cluster))) {
ret = AVERROR(ENOMEM);
goto err;
}
trk->cluster_capacity = new_capacity;
}
trk->cluster[trk->entry].pos = avio_tell(pb) - size;
trk->cluster[trk->entry].samples_in_chunk = samples_in_chunk;
trk->cluster[trk->entry].chunkNum = 0;
trk->cluster[trk->entry].size = size;
trk->cluster[trk->entry].entries = samples_in_chunk;
trk->cluster[trk->entry].dts = pkt->dts;
if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) {
if (!trk->frag_discont) {
/* First packet of a new fragment. We already wrote the duration
* of the last packet of the previous fragment based on track_duration,
* which might not exactly match our dts. Therefore adjust the dts
* of this packet to be what the previous packets duration implies. */
trk->cluster[trk->entry].dts = trk->start_dts + trk->track_duration;
/* We also may have written the pts and the corresponding duration
* in sidx/tfrf/tfxd tags; make sure the sidx pts and duration match up with
* the next fragment. This means the cts of the first sample must
* be the same in all fragments. */
if ((mov->flags & FF_MOV_FLAG_DASH && !(mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)) ||
mov->mode == MODE_ISM)
pkt->pts = pkt->dts + trk->end_pts - trk->cluster[trk->entry].dts;
} else {
/* New fragment, but discontinuous from previous fragments.
* Pretend the duration sum of the earlier fragments is
* pkt->dts - trk->start_dts. */
trk->frag_start = pkt->dts - trk->start_dts;
trk->end_pts = AV_NOPTS_VALUE;
trk->frag_discont = 0;
}
}
if (!trk->entry && trk->start_dts == AV_NOPTS_VALUE && !mov->use_editlist &&
s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
/* Not using edit lists and shifting the first track to start from zero.
* If the other streams start from a later timestamp, we won't be able
* to signal the difference in starting time without an edit list.
* Thus move the timestamp for this first sample to 0, increasing
* its duration instead. */
trk->cluster[trk->entry].dts = trk->start_dts = 0;
}
if (trk->start_dts == AV_NOPTS_VALUE) {
trk->start_dts = pkt->dts;
if (trk->frag_discont) {
if (mov->use_editlist) {
/* Pretend the whole stream started at pts=0, with earlier fragments
* already written. If the stream started at pts=0, the duration sum
* of earlier fragments would have been pkt->pts. */
trk->frag_start = pkt->pts;
trk->start_dts = pkt->dts - pkt->pts;
} else {
/* Pretend the whole stream started at dts=0, with earlier fragments
* already written, with a duration summing up to pkt->dts. */
trk->frag_start = pkt->dts;
trk->start_dts = 0;
}
trk->frag_discont = 0;
} else if (pkt->dts && mov->moov_written)
av_log(s, AV_LOG_WARNING,
"Track %d starts with a nonzero dts %"PRId64", while the moov "
"already has been written. Set the delay_moov flag to handle "
"this case.\n",
pkt->stream_index, pkt->dts);
}
trk->track_duration = pkt->dts - trk->start_dts + pkt->duration;
trk->last_sample_is_subtitle_end = 0;
if (pkt->pts == AV_NOPTS_VALUE) {
av_log(s, AV_LOG_WARNING, "pts has no value\n");
pkt->pts = pkt->dts;
}
if (pkt->dts != pkt->pts)
trk->flags |= MOV_TRACK_CTTS;
trk->cluster[trk->entry].cts = pkt->pts - pkt->dts;
trk->cluster[trk->entry].flags = 0;
if (trk->start_cts == AV_NOPTS_VALUE)
trk->start_cts = pkt->pts - pkt->dts;
if (trk->end_pts == AV_NOPTS_VALUE)
trk->end_pts = trk->cluster[trk->entry].dts +
trk->cluster[trk->entry].cts + pkt->duration;
else
trk->end_pts = FFMAX(trk->end_pts, trk->cluster[trk->entry].dts +
trk->cluster[trk->entry].cts +
pkt->duration);
if (enc->codec_id == AV_CODEC_ID_VC1) {
mov_parse_vc1_frame(pkt, trk);
} else if (pkt->flags & AV_PKT_FLAG_KEY) {
if (mov->mode == MODE_MOV && enc->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
trk->entry > 0) { // force sync sample for the first key frame
mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags);
if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE)
trk->flags |= MOV_TRACK_STPS;
} else {
trk->cluster[trk->entry].flags = MOV_SYNC_SAMPLE;
}
if (trk->cluster[trk->entry].flags & MOV_SYNC_SAMPLE)
trk->has_keyframes++;
}
trk->entry++;
trk->sample_count += samples_in_chunk;
mov->mdat_size += size;
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
reformatted_data, size);
end:
err:
av_free(reformatted_data);
return ret;
}
| 15,236 |
FFmpeg | 851ded8918c977d8160c6617b69604f758cabf50 | 0 | static int decode_cabac_mb_chroma_pre_mode( H264Context *h) {
const int mba_xy = h->left_mb_xy[0];
const int mbb_xy = h->top_mb_xy;
int ctx = 0;
/* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */
if( h->slice_table[mba_xy] == h->slice_num && h->chroma_pred_mode_table[mba_xy] != 0 )
ctx++;
if( h->slice_table[mbb_xy] == h->slice_num && h->chroma_pred_mode_table[mbb_xy] != 0 )
ctx++;
if( get_cabac( &h->cabac, &h->cabac_state[64+ctx] ) == 0 )
return 0;
if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 )
return 1;
if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 )
return 2;
else
return 3;
}
| 15,237 |
FFmpeg | b7c96769c52a312c6f6abe43f5d8c83701118a0b | 0 | static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
AacPsyContext *pctx;
float bark;
int i, j, g, start;
float prev, minscale, minath;
ctx->model_priv_data = av_mallocz(sizeof(AacPsyContext));
pctx = (AacPsyContext*) ctx->model_priv_data;
minath = ath(3410, ATH_ADD);
for (j = 0; j < 2; j++) {
AacPsyCoeffs *coeffs = &pctx->psy_coef[j];
float line_to_frequency = ctx->avctx->sample_rate / (j ? 256.f : 2048.0f);
i = 0;
prev = 0.0;
for (g = 0; g < ctx->num_bands[j]; g++) {
i += ctx->bands[j][g];
bark = calc_bark((i-1) * line_to_frequency);
coeffs->barks[g] = (bark + prev) / 2.0;
prev = bark;
}
for (g = 0; g < ctx->num_bands[j] - 1; g++) {
coeffs->spread_low[g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_LOW);
coeffs->spread_hi [g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_HI);
}
start = 0;
for (g = 0; g < ctx->num_bands[j]; g++) {
minscale = ath(start * line_to_frequency, ATH_ADD);
for (i = 1; i < ctx->bands[j][g]; i++)
minscale = FFMIN(minscale, ath((start + i) * line_to_frequency, ATH_ADD));
coeffs->ath[g] = minscale - minath;
start += ctx->bands[j][g];
}
}
pctx->ch = av_mallocz(sizeof(AacPsyChannel) * ctx->avctx->channels);
lame_window_init(pctx, ctx->avctx);
return 0;
}
| 15,238 |
qemu | 34779e8c3991f7fcd74b2045478abcef67dbeb15 | 1 | static void test_tco_second_timeout_reset(void)
{
TestData td;
const uint16_t ticks = TCO_SECS_TO_TICKS(16);
QDict *ad;
td.args = "-watchdog-action reset";
td.noreboot = false;
test_init(&td);
stop_tco(&td);
clear_tco_status(&td);
reset_on_second_timeout(true);
set_tco_timeout(&td, TCO_SECS_TO_TICKS(16));
load_tco(&td);
start_tco(&td);
clock_step(ticks * TCO_TICK_NSEC * 2);
ad = get_watchdog_action();
g_assert(!strcmp(qdict_get_str(ad, "action"), "reset"));
QDECREF(ad);
stop_tco(&td);
qtest_end();
}
| 15,240 |
qemu | b4ba67d9a702507793c2724e56f98e9b0f7be02b | 1 | static void e1000e_macreg_write(e1000e_device *d, uint32_t reg, uint32_t val)
{
qpci_io_writel(d->pci_dev, d->mac_regs + reg, val);
}
| 15,241 |
qemu | e907746266721f305d67bc0718795fedee2e824c | 1 | static void fdctrl_handle_drive_specification_command(FDCtrl *fdctrl, int direction)
{
FDrive *cur_drv = get_cur_drv(fdctrl);
if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) {
/* Command parameters done */
if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x40) {
fdctrl->fifo[0] = fdctrl->fifo[1];
fdctrl->fifo[2] = 0;
fdctrl->fifo[3] = 0;
fdctrl_set_fifo(fdctrl, 4);
} else {
fdctrl_reset_fifo(fdctrl);
}
} else if (fdctrl->data_len > 7) {
/* ERROR */
fdctrl->fifo[0] = 0x80 |
(cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
fdctrl_set_fifo(fdctrl, 1);
}
}
| 15,242 |
qemu | 4d1628e832dfc6ec02b0d196f6cc250aaa7bf3b3 | 1 | uint64_t helper_addqv(CPUAlphaState *env, uint64_t op1, uint64_t op2)
{
uint64_t tmp = op1;
op1 += op2;
if (unlikely((tmp ^ op2 ^ (-1ULL)) & (tmp ^ op1) & (1ULL << 63))) {
arith_excp(env, GETPC(), EXC_M_IOV, 0);
}
return op1;
}
| 15,243 |
qemu | 3e831b40e015ba34dfb55ff11f767001839425ff | 1 | pvscsi_on_cmd_setup_msg_ring(PVSCSIState *s)
{
PVSCSICmdDescSetupMsgRing *rc =
(PVSCSICmdDescSetupMsgRing *) s->curr_cmd_data;
trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_MSG_RING");
if (!s->use_msg) {
return PVSCSI_COMMAND_PROCESSING_FAILED;
}
if (s->rings_info_valid) {
pvscsi_ring_init_msg(&s->rings, rc);
s->msg_ring_info_valid = TRUE;
}
return sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t);
}
| 15,244 |
qemu | 6d0b908a628a7086fa855c68b217cc1e2a5c4c19 | 1 | dispatcher_wait(Dispatcher *dispr, uint32_t timeout)
{
struct timeval tv;
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
fd_set fdset = dispr->fdset;
/* wait until some of sockets become readable. */
int rc = select(dispr->max_sock + 1, &fdset, 0, 0, &tv);
if (rc == -1) {
vubr_die("select");
}
/* Timeout */
if (rc == 0) {
return 0;
}
/* Now call callback for every ready socket. */
int sock;
for (sock = 0; sock < dispr->max_sock + 1; sock++)
if (FD_ISSET(sock, &fdset)) {
Event *e = &dispr->events[sock];
e->callback(sock, e->ctx);
}
return 0;
}
| 15,246 |
qemu | 9ac228e02cf16202547e7025ef300369e0db7781 | 1 | int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res)
{
if (bs->drv->bdrv_check == NULL) {
return -ENOTSUP;
}
memset(res, 0, sizeof(*res));
res->corruptions = bs->drv->bdrv_check(bs);
return res->corruptions < 0 ? res->corruptions : 0;
}
| 15,247 |
FFmpeg | 8fd8a48263ff1437f9d02d7e78dc63efb9b5ed3a | 1 | static int nsv_parse_NSVf_header(AVFormatContext *s)
{
NSVContext *nsv = s->priv_data;
AVIOContext *pb = s->pb;
unsigned int av_unused file_size;
unsigned int size;
int64_t duration;
int strings_size;
int table_entries;
int table_entries_used;
av_dlog(s, "%s()\n", __FUNCTION__);
nsv->state = NSV_UNSYNC; /* in case we fail */
size = avio_rl32(pb);
if (size < 28)
return -1;
nsv->NSVf_end = size;
//s->file_size = (uint32_t)avio_rl32(pb);
file_size = (uint32_t)avio_rl32(pb);
av_dlog(s, "NSV NSVf chunk_size %u\n", size);
av_dlog(s, "NSV NSVf file_size %u\n", file_size);
nsv->duration = duration = avio_rl32(pb); /* in ms */
av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration);
// XXX: store it in AVStreams
strings_size = avio_rl32(pb);
table_entries = avio_rl32(pb);
table_entries_used = avio_rl32(pb);
av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
strings_size, table_entries, table_entries_used);
if (pb->eof_reached)
return -1;
av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb));
if (strings_size > 0) {
char *strings; /* last byte will be '\0' to play safe with str*() */
char *p, *endp;
char *token, *value;
char quote;
p = strings = av_mallocz(strings_size + 1);
endp = strings + strings_size;
avio_read(pb, strings, strings_size);
while (p < endp) {
while (*p == ' ')
p++; /* strip out spaces */
if (p >= endp-2)
break;
token = p;
p = strchr(p, '=');
if (!p || p >= endp-2)
break;
*p++ = '\0';
quote = *p++;
value = p;
p = strchr(p, quote);
if (!p || p >= endp)
break;
*p++ = '\0';
av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value);
av_dict_set(&s->metadata, token, value, 0);
}
av_free(strings);
}
if (pb->eof_reached)
return -1;
av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb));
if (table_entries_used > 0) {
int i;
nsv->index_entries = table_entries_used;
if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t))
return -1;
nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t));
for(i=0;i<table_entries_used;i++)
nsv->nsvs_file_offset[i] = avio_rl32(pb) + size;
if(table_entries > table_entries_used &&
avio_rl32(pb) == MKTAG('T','O','C','2')) {
nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t));
for(i=0;i<table_entries_used;i++) {
nsv->nsvs_timestamps[i] = avio_rl32(pb);
}
}
}
av_dlog(s, "NSV got index; filepos %"PRId64"\n", avio_tell(pb));
#ifdef DEBUG_DUMP_INDEX
#define V(v) ((v<0x20 || v > 127)?'.':v)
/* dump index */
av_dlog(s, "NSV %d INDEX ENTRIES:\n", table_entries);
av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries);
for (i = 0; i < table_entries; i++) {
unsigned char b[8];
avio_seek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);
avio_read(pb, b, 8);
av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
"%c%c%c%c%c%c%c%c\n",
nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i],
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) );
}
//avio_seek(pb, size, SEEK_SET); /* go back to end of header */
#undef V
#endif
avio_seek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */
if (pb->eof_reached)
return -1;
nsv->state = NSV_HAS_READ_NSVF;
return 0;
}
| 15,248 |
FFmpeg | 55a727383bab266b757b642aabaa2b066c14e7c7 | 0 | static int flac_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
const uint8_t *buf, int buf_size)
{
FLACContext *s = avctx->priv_data;
int tmp = 0, i, j = 0, input_buf_size = 0;
int16_t *samples_16 = data;
int32_t *samples_32 = data;
int alloc_data_size= *data_size;
*data_size=0;
if (s->max_framesize == 0) {
s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header
s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
}
if (1 && s->max_framesize) { //FIXME truncated
if (s->bitstream_size < 4 || AV_RL32(s->bitstream) != MKTAG('f','L','a','C'))
buf_size= FFMIN(buf_size, s->max_framesize - FFMIN(s->bitstream_size, s->max_framesize));
input_buf_size= buf_size;
if (s->bitstream_size + buf_size < buf_size || s->bitstream_index + s->bitstream_size + buf_size < s->bitstream_index)
return -1;
if (s->allocated_bitstream_size < s->bitstream_size + buf_size)
s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size);
if (s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size) {
memmove(s->bitstream, &s->bitstream[s->bitstream_index],
s->bitstream_size);
s->bitstream_index=0;
}
memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size],
buf, buf_size);
buf= &s->bitstream[s->bitstream_index];
buf_size += s->bitstream_size;
s->bitstream_size= buf_size;
if (buf_size < s->max_framesize && input_buf_size) {
return input_buf_size;
}
}
init_get_bits(&s->gb, buf, buf_size*8);
if (metadata_parse(s))
goto end;
tmp = show_bits(&s->gb, 16);
if ((tmp & 0xFFFE) != 0xFFF8) {
av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n");
while (get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8)
skip_bits(&s->gb, 8);
goto end; // we may not have enough bits left to decode a frame, so try next time
}
skip_bits(&s->gb, 16);
if (decode_frame(s, alloc_data_size) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
s->bitstream_size=0;
s->bitstream_index=0;
return -1;
}
#define DECORRELATE(left, right)\
assert(s->channels == 2);\
for (i = 0; i < s->blocksize; i++) {\
int a= s->decoded[0][i];\
int b= s->decoded[1][i];\
if (s->is32) {\
*samples_32++ = (left) << s->sample_shift;\
*samples_32++ = (right) << s->sample_shift;\
} else {\
*samples_16++ = (left) << s->sample_shift;\
*samples_16++ = (right) << s->sample_shift;\
}\
}\
break;
switch (s->decorrelation) {
case INDEPENDENT:
for (j = 0; j < s->blocksize; j++) {
for (i = 0; i < s->channels; i++) {
if (s->is32)
*samples_32++ = s->decoded[i][j] << s->sample_shift;
else
*samples_16++ = s->decoded[i][j] << s->sample_shift;
}
}
break;
case LEFT_SIDE:
DECORRELATE(a,a-b)
case RIGHT_SIDE:
DECORRELATE(a+b,b)
case MID_SIDE:
DECORRELATE( (a-=b>>1) + b, a)
}
*data_size = s->blocksize * s->channels * (s->is32 ? 4 : 2);
end:
i= (get_bits_count(&s->gb)+7)/8;
if (i > buf_size) {
av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
s->bitstream_size=0;
s->bitstream_index=0;
return -1;
}
if (s->bitstream_size) {
s->bitstream_index += i;
s->bitstream_size -= i;
return input_buf_size;
} else
return i;
}
| 15,250 |
FFmpeg | 47c93657249f1a4bc8a7aaf2f9f3a33510bee38c | 0 | static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
CFHDContext *s = avctx->priv_data;
GetByteContext gb;
ThreadFrame frame = { .f = data };
AVFrame *pic = data;
int ret = 0, i, j, planes, plane, got_buffer = 0;
int16_t *coeff_data;
s->coded_format = AV_PIX_FMT_YUV422P10;
init_frame_defaults(s);
planes = av_pix_fmt_count_planes(s->coded_format);
bytestream2_init(&gb, avpkt->data, avpkt->size);
while (bytestream2_get_bytes_left(&gb) > 4) {
/* Bit weird but implement the tag parsing as the spec says */
uint16_t tagu = bytestream2_get_be16(&gb);
int16_t tag = (int16_t)tagu;
int8_t tag8 = (int8_t)(tagu >> 8);
uint16_t abstag = abs(tag);
int8_t abs_tag8 = abs(tag8);
uint16_t data = bytestream2_get_be16(&gb);
if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data);
} else if (tag == 20) {
av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data);
s->coded_width = data;
} else if (tag == 21) {
av_log(avctx, AV_LOG_DEBUG, "Height %"PRIu16"\n", data);
s->coded_height = data;
} else if (tag == 101) {
av_log(avctx, AV_LOG_DEBUG, "Bits per component: %"PRIu16"\n", data);
if (data < 1 || data > 31) {
av_log(avctx, AV_LOG_ERROR, "Bits per component %d is invalid\n", data);
ret = AVERROR(EINVAL);
break;
}
s->bpc = data;
} else if (tag == 12) {
av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16"\n", data);
s->channel_cnt = data;
if (data > 4) {
av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
ret = AVERROR_PATCHWELCOME;
break;
}
} else if (tag == 14) {
av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16"\n", data);
if (data != SUBBAND_COUNT) {
av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is unsupported\n", data);
ret = AVERROR_PATCHWELCOME;
break;
}
} else if (tag == 62) {
s->channel_num = data;
av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16"\n", data);
if (s->channel_num >= planes) {
av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
ret = AVERROR(EINVAL);
break;
}
init_plane_defaults(s);
} else if (tag == 48) {
if (s->subband_num != 0 && data == 1) // hack
s->level++;
av_log(avctx, AV_LOG_DEBUG, "Subband number %"PRIu16"\n", data);
s->subband_num = data;
if (s->level >= DWT_LEVELS) {
av_log(avctx, AV_LOG_ERROR, "Invalid level\n");
ret = AVERROR(EINVAL);
break;
}
if (s->subband_num > 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid subband number\n");
ret = AVERROR(EINVAL);
break;
}
} else if (tag == 51) {
av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16"\n", data);
s->subband_num_actual = data;
if (s->subband_num_actual >= 10) {
av_log(avctx, AV_LOG_ERROR, "Invalid subband number actual\n");
ret = AVERROR(EINVAL);
break;
}
} else if (tag == 35)
av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16"\n", data);
else if (tag == 53) {
s->quantisation = data;
av_log(avctx, AV_LOG_DEBUG, "Quantisation: %"PRIu16"\n", data);
} else if (tag == 109) {
s->prescale_shift[0] = (data >> 0) & 0x7;
s->prescale_shift[1] = (data >> 3) & 0x7;
s->prescale_shift[2] = (data >> 6) & 0x7;
av_log(avctx, AV_LOG_DEBUG, "Prescale shift (VC-5): %x\n", data);
} else if (tag == 27) {
av_log(avctx, AV_LOG_DEBUG, "Lowpass width %"PRIu16"\n", data);
if (data < 3 || data > s->plane[s->channel_num].band[0][0].a_width) {
av_log(avctx, AV_LOG_ERROR, "Invalid lowpass width\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[0][0].width = data;
s->plane[s->channel_num].band[0][0].stride = data;
} else if (tag == 28) {
av_log(avctx, AV_LOG_DEBUG, "Lowpass height %"PRIu16"\n", data);
if (data < 3 || data > s->plane[s->channel_num].band[0][0].height) {
av_log(avctx, AV_LOG_ERROR, "Invalid lowpass height\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[0][0].height = data;
} else if (tag == 1)
av_log(avctx, AV_LOG_DEBUG, "Sample type? %"PRIu16"\n", data);
else if (tag == 10) {
if (data != 0) {
avpriv_report_missing_feature(avctx, "Transform type of %"PRIu16, data);
ret = AVERROR_PATCHWELCOME;
break;
}
av_log(avctx, AV_LOG_DEBUG, "Transform-type? %"PRIu16"\n", data);
} else if (abstag >= 0x4000 && abstag <= 0x40ff) {
av_log(avctx, AV_LOG_DEBUG, "Small chunk length %d %s\n", data * 4, tag < 0 ? "optional" : "required");
bytestream2_skipu(&gb, data * 4);
} else if (tag == 23) {
av_log(avctx, AV_LOG_DEBUG, "Skip frame\n");
avpriv_report_missing_feature(avctx, "Skip frame");
ret = AVERROR_PATCHWELCOME;
break;
} else if (tag == 2) {
av_log(avctx, AV_LOG_DEBUG, "tag=2 header - skipping %i tag/value pairs\n", data);
if (data > bytestream2_get_bytes_left(&gb) / 4) {
av_log(avctx, AV_LOG_ERROR, "too many tag/value pairs (%d)\n", data);
ret = AVERROR_INVALIDDATA;
break;
}
for (i = 0; i < data; i++) {
uint16_t tag2 = bytestream2_get_be16(&gb);
uint16_t val2 = bytestream2_get_be16(&gb);
av_log(avctx, AV_LOG_DEBUG, "Tag/Value = %x %x\n", tag2, val2);
}
} else if (tag == 41) {
av_log(avctx, AV_LOG_DEBUG, "Highpass width %i channel %i level %i subband %i\n", data, s->channel_num, s->level, s->subband_num);
if (data < 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid highpass width\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
} else if (tag == 42) {
av_log(avctx, AV_LOG_DEBUG, "Highpass height %i\n", data);
if (data < 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid highpass height\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
} else if (tag == 49) {
av_log(avctx, AV_LOG_DEBUG, "Highpass width2 %i\n", data);
if (data < 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid highpass width2\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
} else if (tag == 50) {
av_log(avctx, AV_LOG_DEBUG, "Highpass height2 %i\n", data);
if (data < 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid highpass height2\n");
ret = AVERROR(EINVAL);
break;
}
s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
} else if (tag == 71) {
s->codebook = data;
av_log(avctx, AV_LOG_DEBUG, "Codebook %i\n", s->codebook);
} else if (tag == 72) {
s->codebook = data;
av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i\n", s->codebook);
} else if (tag == 70) {
av_log(avctx, AV_LOG_DEBUG, "Subsampling or bit-depth flag? %i\n", data);
if (!(data == 10 || data == 12)) {
av_log(avctx, AV_LOG_ERROR, "Invalid bits per channel\n");
ret = AVERROR(EINVAL);
break;
}
s->bpc = data;
} else if (tag == 84) {
av_log(avctx, AV_LOG_DEBUG, "Sample format? %i\n", data);
if (data == 1)
s->coded_format = AV_PIX_FMT_YUV422P10;
else if (data == 3)
s->coded_format = AV_PIX_FMT_GBRP12;
else if (data == 4)
s->coded_format = AV_PIX_FMT_GBRAP12;
else {
avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16, data);
ret = AVERROR_PATCHWELCOME;
break;
}
planes = av_pix_fmt_count_planes(s->coded_format);
} else
av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x\n", tag, data);
/* Some kind of end of header tag */
if (tag == 4 && data == 0x1a4a && s->coded_width && s->coded_height &&
s->coded_format != AV_PIX_FMT_NONE) {
if (s->a_width != s->coded_width || s->a_height != s->coded_height ||
s->a_format != s->coded_format) {
free_buffers(avctx);
if ((ret = alloc_buffers(avctx)) < 0) {
free_buffers(avctx);
return ret;
}
}
ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height);
if (ret < 0)
return ret;
frame.f->width =
frame.f->height = 0;
if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
return ret;
s->coded_width = 0;
s->coded_height = 0;
s->coded_format = AV_PIX_FMT_NONE;
got_buffer = 1;
}
coeff_data = s->plane[s->channel_num].subband[s->subband_num_actual];
/* Lowpass coefficients */
if (tag == 4 && data == 0xf0f && s->a_width && s->a_height) {
int lowpass_height = s->plane[s->channel_num].band[0][0].height;
int lowpass_width = s->plane[s->channel_num].band[0][0].width;
int lowpass_a_height = s->plane[s->channel_num].band[0][0].a_height;
int lowpass_a_width = s->plane[s->channel_num].band[0][0].a_width;
if (!got_buffer) {
av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
ret = AVERROR(EINVAL);
goto end;
}
if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
lowpass_a_width * lowpass_a_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
av_log(avctx, AV_LOG_ERROR, "Too many lowpass coefficients\n");
ret = AVERROR(EINVAL);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Start of lowpass coeffs component %d height:%d, width:%d\n", s->channel_num, lowpass_height, lowpass_width);
for (i = 0; i < lowpass_height; i++) {
for (j = 0; j < lowpass_width; j++)
coeff_data[j] = bytestream2_get_be16u(&gb);
coeff_data += lowpass_width;
}
/* Align to mod-4 position to continue reading tags */
bytestream2_seek(&gb, bytestream2_tell(&gb) & 3, SEEK_CUR);
/* Copy last line of coefficients if odd height */
if (lowpass_height & 1) {
memcpy(&coeff_data[lowpass_height * lowpass_width],
&coeff_data[(lowpass_height - 1) * lowpass_width],
lowpass_width * sizeof(*coeff_data));
}
av_log(avctx, AV_LOG_DEBUG, "Lowpass coefficients %d\n", lowpass_width * lowpass_height);
}
if (tag == 55 && s->subband_num_actual != 255 && s->a_width && s->a_height) {
int highpass_height = s->plane[s->channel_num].band[s->level][s->subband_num].height;
int highpass_width = s->plane[s->channel_num].band[s->level][s->subband_num].width;
int highpass_a_width = s->plane[s->channel_num].band[s->level][s->subband_num].a_width;
int highpass_a_height = s->plane[s->channel_num].band[s->level][s->subband_num].a_height;
int highpass_stride = s->plane[s->channel_num].band[s->level][s->subband_num].stride;
int expected;
int a_expected = highpass_a_height * highpass_a_width;
int level, run, coeff;
int count = 0, bytes;
if (!got_buffer) {
av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
ret = AVERROR(EINVAL);
goto end;
}
if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
av_log(avctx, AV_LOG_ERROR, "Too many highpass coefficients\n");
ret = AVERROR(EINVAL);
goto end;
}
expected = highpass_height * highpass_stride;
av_log(avctx, AV_LOG_DEBUG, "Start subband coeffs plane %i level %i codebook %i expected %i\n", s->channel_num, s->level, s->codebook, expected);
init_get_bits(&s->gb, gb.buffer, bytestream2_get_bytes_left(&gb) * 8);
{
OPEN_READER(re, &s->gb);
if (!s->codebook) {
while (1) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, s->table_9_rl_vlc,
VLC_BITS, 3, 1);
/* escape */
if (level == 64)
break;
count += run;
if (count > expected)
break;
coeff = dequant_and_decompand(level, s->quantisation);
for (i = 0; i < run; i++)
*coeff_data++ = coeff;
}
} else {
while (1) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, s->table_18_rl_vlc,
VLC_BITS, 3, 1);
/* escape */
if (level == 255 && run == 2)
break;
count += run;
if (count > expected)
break;
coeff = dequant_and_decompand(level, s->quantisation);
for (i = 0; i < run; i++)
*coeff_data++ = coeff;
}
}
CLOSE_READER(re, &s->gb);
}
if (count > expected) {
av_log(avctx, AV_LOG_ERROR, "Escape codeword not found, probably corrupt data\n");
ret = AVERROR(EINVAL);
goto end;
}
bytes = FFALIGN(FF_CEIL_RSHIFT(get_bits_count(&s->gb), 3), 4);
if (bytes > bytestream2_get_bytes_left(&gb)) {
av_log(avctx, AV_LOG_ERROR, "Bitstream overread error\n");
ret = AVERROR(EINVAL);
goto end;
} else
bytestream2_seek(&gb, bytes, SEEK_CUR);
av_log(avctx, AV_LOG_DEBUG, "End subband coeffs %i extra %i\n", count, count - expected);
s->codebook = 0;
/* Copy last line of coefficients if odd height */
if (highpass_height & 1) {
memcpy(&coeff_data[highpass_height * highpass_stride],
&coeff_data[(highpass_height - 1) * highpass_stride],
highpass_stride * sizeof(*coeff_data));
}
}
}
if (!s->a_width || !s->a_height || s->a_format == AV_PIX_FMT_NONE ||
s->coded_width || s->coded_height || s->coded_format != AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "Invalid dimensions\n");
ret = AVERROR(EINVAL);
goto end;
}
if (!got_buffer) {
av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
ret = AVERROR(EINVAL);
goto end;
}
planes = av_pix_fmt_count_planes(avctx->pix_fmt);
for (plane = 0; plane < planes && !ret; plane++) {
/* level 1 */
int lowpass_height = s->plane[plane].band[0][0].height;
int lowpass_width = s->plane[plane].band[0][0].width;
int highpass_stride = s->plane[plane].band[0][1].stride;
int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
int16_t *low, *high, *output, *dst;
if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
!highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width) {
av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
ret = AVERROR(EINVAL);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[2];
output = s->plane[plane].l_h[0];
for (i = 0; i < lowpass_width; i++) {
vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
low = s->plane[plane].subband[1];
high = s->plane[plane].subband[3];
output = s->plane[plane].l_h[1];
for (i = 0; i < lowpass_width; i++) {
// note the stride of "low" is highpass_stride
vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
low = s->plane[plane].l_h[0];
high = s->plane[plane].l_h[1];
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
horiz_filter(output, low, high, lowpass_width);
low += lowpass_width;
high += lowpass_width;
output += lowpass_width * 2;
}
if (s->bpc == 12) {
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
output += lowpass_width * 2;
}
}
/* level 2 */
lowpass_height = s->plane[plane].band[1][1].height;
lowpass_width = s->plane[plane].band[1][1].width;
highpass_stride = s->plane[plane].band[1][1].stride;
if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
!highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width) {
av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
ret = AVERROR(EINVAL);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[5];
output = s->plane[plane].l_h[3];
for (i = 0; i < lowpass_width; i++) {
vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
low = s->plane[plane].subband[4];
high = s->plane[plane].subband[6];
output = s->plane[plane].l_h[4];
for (i = 0; i < lowpass_width; i++) {
vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
low = s->plane[plane].l_h[3];
high = s->plane[plane].l_h[4];
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
horiz_filter(output, low, high, lowpass_width);
low += lowpass_width;
high += lowpass_width;
output += lowpass_width * 2;
}
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
output += lowpass_width * 2;
}
/* level 3 */
lowpass_height = s->plane[plane].band[2][1].height;
lowpass_width = s->plane[plane].band[2][1].width;
highpass_stride = s->plane[plane].band[2][1].stride;
if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width ||
!highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width) {
av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
ret = AVERROR(EINVAL);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[8];
output = s->plane[plane].l_h[6];
for (i = 0; i < lowpass_width; i++) {
vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
low = s->plane[plane].subband[7];
high = s->plane[plane].subband[9];
output = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_width; i++) {
vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
low++;
high++;
output++;
}
dst = (int16_t *)pic->data[act_plane];
low = s->plane[plane].l_h[6];
high = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height * 2; i++) {
horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
low += lowpass_width;
high += lowpass_width;
dst += pic->linesize[act_plane] / 2;
}
}
end:
if (ret < 0)
return ret;
*got_frame = 1;
return avpkt->size;
}
| 15,251 |
FFmpeg | 6a786b15c34765ec00be3cd808dafbb041fd5881 | 0 | static void vc1_inv_trans_8x8_altivec(DCTELEM block[64])
{
vector signed short src0, src1, src2, src3, src4, src5, src6, src7;
vector signed int s0, s1, s2, s3, s4, s5, s6, s7;
vector signed int s8, s9, sA, sB, sC, sD, sE, sF;
vector signed int t0, t1, t2, t3, t4, t5, t6, t7;
const vector signed int vec_64 = vec_sl(vec_splat_s32(4), vec_splat_u32(4));
const vector unsigned int vec_7 = vec_splat_u32(7);
const vector unsigned int vec_4 = vec_splat_u32(4);
const vector signed int vec_4s = vec_splat_s32(4);
const vector unsigned int vec_3 = vec_splat_u32(3);
const vector unsigned int vec_2 = vec_splat_u32(2);
const vector signed int vec_1s = vec_splat_s32(1);
const vector unsigned int vec_1 = vec_splat_u32(1);
src0 = vec_ld( 0, block);
src1 = vec_ld( 16, block);
src2 = vec_ld( 32, block);
src3 = vec_ld( 48, block);
src4 = vec_ld( 64, block);
src5 = vec_ld( 80, block);
src6 = vec_ld( 96, block);
src7 = vec_ld(112, block);
s0 = vec_unpackl(src0);
s1 = vec_unpackl(src1);
s2 = vec_unpackl(src2);
s3 = vec_unpackl(src3);
s4 = vec_unpackl(src4);
s5 = vec_unpackl(src5);
s6 = vec_unpackl(src6);
s7 = vec_unpackl(src7);
s8 = vec_unpackh(src0);
s9 = vec_unpackh(src1);
sA = vec_unpackh(src2);
sB = vec_unpackh(src3);
sC = vec_unpackh(src4);
sD = vec_unpackh(src5);
sE = vec_unpackh(src6);
sF = vec_unpackh(src7);
STEP8(s0, s1, s2, s3, s4, s5, s6, s7, vec_4s);
SHIFT_HOR8(s0, s1, s2, s3, s4, s5, s6, s7);
STEP8(s8, s9, sA, sB, sC, sD, sE, sF, vec_4s);
SHIFT_HOR8(s8, s9, sA, sB, sC, sD, sE, sF);
src0 = vec_pack(s8, s0);
src1 = vec_pack(s9, s1);
src2 = vec_pack(sA, s2);
src3 = vec_pack(sB, s3);
src4 = vec_pack(sC, s4);
src5 = vec_pack(sD, s5);
src6 = vec_pack(sE, s6);
src7 = vec_pack(sF, s7);
TRANSPOSE8(src0, src1, src2, src3, src4, src5, src6, src7);
s0 = vec_unpackl(src0);
s1 = vec_unpackl(src1);
s2 = vec_unpackl(src2);
s3 = vec_unpackl(src3);
s4 = vec_unpackl(src4);
s5 = vec_unpackl(src5);
s6 = vec_unpackl(src6);
s7 = vec_unpackl(src7);
s8 = vec_unpackh(src0);
s9 = vec_unpackh(src1);
sA = vec_unpackh(src2);
sB = vec_unpackh(src3);
sC = vec_unpackh(src4);
sD = vec_unpackh(src5);
sE = vec_unpackh(src6);
sF = vec_unpackh(src7);
STEP8(s0, s1, s2, s3, s4, s5, s6, s7, vec_64);
SHIFT_VERT8(s0, s1, s2, s3, s4, s5, s6, s7);
STEP8(s8, s9, sA, sB, sC, sD, sE, sF, vec_64);
SHIFT_VERT8(s8, s9, sA, sB, sC, sD, sE, sF);
src0 = vec_pack(s8, s0);
src1 = vec_pack(s9, s1);
src2 = vec_pack(sA, s2);
src3 = vec_pack(sB, s3);
src4 = vec_pack(sC, s4);
src5 = vec_pack(sD, s5);
src6 = vec_pack(sE, s6);
src7 = vec_pack(sF, s7);
vec_st(src0, 0, block);
vec_st(src1, 16, block);
vec_st(src2, 32, block);
vec_st(src3, 48, block);
vec_st(src4, 64, block);
vec_st(src5, 80, block);
vec_st(src6, 96, block);
vec_st(src7,112, block);
}
| 15,253 |
FFmpeg | e2742d6ad69595fd2af36adf0883e37701307f52 | 1 | static int decode_tilehdr(WmallDecodeCtx *s)
{
uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /* flag indicating if a channel contains the current subframe */
int channels_for_cur_subframe = s->num_channels; /* number of channels that contain the current subframe */
int fixed_channel_layout = 0; /* flag indicating that all channels use the same subfra2me offsets and sizes */
int min_channel_len = 0; /* smallest sum of samples (channels with this length will be processed first) */
int c, tile_aligned;
/* reset tiling information */
for (c = 0; c < s->num_channels; c++)
s->channel[c].num_subframes = 0;
tile_aligned = get_bits1(&s->gb);
if (s->max_num_subframes == 1 || tile_aligned)
fixed_channel_layout = 1;
/* loop until the frame data is split between the subframes */
do {
int subframe_len, in_use = 0;
/* check which channels contain the subframe */
for (c = 0; c < s->num_channels; c++) {
if (num_samples[c] == min_channel_len) {
if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
(min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {
contains_subframe[c] = in_use = 1;
} else {
if (get_bits1(&s->gb))
contains_subframe[c] = in_use = 1;
}
} else
contains_subframe[c] = 0;
}
if (!in_use) {
av_log(s->avctx, AV_LOG_ERROR,
"Found empty subframe\n");
return AVERROR_INVALIDDATA;
}
/* get subframe length, subframe_len == 0 is not allowed */
if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
return AVERROR_INVALIDDATA;
/* add subframes to the individual channels and find new min_channel_len */
min_channel_len += subframe_len;
for (c = 0; c < s->num_channels; c++) {
WmallChannelCtx *chan = &s->channel[c];
if (contains_subframe[c]) {
if (chan->num_subframes >= MAX_SUBFRAMES) {
av_log(s->avctx, AV_LOG_ERROR,
"broken frame: num subframes > 31\n");
return AVERROR_INVALIDDATA;
}
chan->subframe_len[chan->num_subframes] = subframe_len;
num_samples[c] += subframe_len;
++chan->num_subframes;
if (num_samples[c] > s->samples_per_frame) {
av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
"channel len(%d) > samples_per_frame(%d)\n",
num_samples[c], s->samples_per_frame);
return AVERROR_INVALIDDATA;
}
} else if (num_samples[c] <= min_channel_len) {
if (num_samples[c] < min_channel_len) {
channels_for_cur_subframe = 0;
min_channel_len = num_samples[c];
}
++channels_for_cur_subframe;
}
}
} while (min_channel_len < s->samples_per_frame);
for (c = 0; c < s->num_channels; c++) {
int i, offset = 0;
for (i = 0; i < s->channel[c].num_subframes; i++) {
s->channel[c].subframe_offsets[i] = offset;
offset += s->channel[c].subframe_len[i];
}
}
return 0;
}
| 15,254 |
qemu | 6ab3fc32ea640026726bc5f9f4db622d0954fb8a | 1 | uart_write(void *opaque, hwaddr addr,
uint64_t val64, unsigned int size)
{
XilinxUARTLite *s = opaque;
uint32_t value = val64;
unsigned char ch = value;
addr >>= 2;
switch (addr)
{
case R_STATUS:
hw_error("write to UART STATUS?\n");
break;
case R_CTRL:
if (value & CONTROL_RST_RX) {
s->rx_fifo_pos = 0;
s->rx_fifo_len = 0;
}
s->regs[addr] = value;
break;
case R_TX:
if (s->chr)
qemu_chr_fe_write(s->chr, &ch, 1);
s->regs[addr] = value;
/* hax. */
s->regs[R_STATUS] |= STATUS_IE;
break;
default:
DUART(printf("%s addr=%x v=%x\n", __func__, addr, value));
if (addr < ARRAY_SIZE(s->regs))
s->regs[addr] = value;
break;
}
uart_update_status(s);
uart_update_irq(s);
}
| 15,255 |
qemu | 8190483196148f765c65785876f7b893d64b6cdd | 1 | static CharDriverState *net_vhost_parse_chardev(const NetdevVhostUserOptions *opts)
{
CharDriverState *chr = qemu_chr_find(opts->chardev);
VhostUserChardevProps props;
if (chr == NULL) {
error_report("chardev \"%s\" not found", opts->chardev);
return NULL;
}
/* inspect chardev opts */
memset(&props, 0, sizeof(props));
if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, NULL)) {
return NULL;
}
if (!props.is_socket || !props.is_unix) {
error_report("chardev \"%s\" is not a unix socket",
opts->chardev);
return NULL;
}
qemu_chr_fe_claim_no_fail(chr);
return chr;
}
| 15,256 |
FFmpeg | 7effbee66cf457c62f795d9b9ed3a1110b364b89 | 1 | static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
// AVStream *st = s->streams[0];
size= MP3_PACKET_SIZE;
ret= av_get_packet(s->pb, pkt, size);
pkt->stream_index = 0;
if (ret <= 0) {
if(ret<0)
return ret;
return AVERROR_EOF;
}
if (ret > ID3v1_TAG_SIZE &&
memcmp(&pkt->data[ret - ID3v1_TAG_SIZE], "TAG", 3) == 0)
ret -= ID3v1_TAG_SIZE;
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret;
return ret;
} | 15,257 |
FFmpeg | 15ee419b7abaf17f8c662c145fe93d3dbf43282b | 1 | static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AVFrame *const p = data;
int compressed, xmin, ymin, xmax, ymax;
unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x,
bytes_per_scanline;
uint8_t *ptr;
const uint8_t *buf_end = buf + buf_size;
const uint8_t *bufstart = buf;
uint8_t *scanline;
int ret = -1;
if (buf[0] != 0x0a || buf[1] > 5) {
av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n");
return AVERROR_INVALIDDATA;
}
compressed = buf[2];
xmin = AV_RL16(buf + 4);
ymin = AV_RL16(buf + 6);
xmax = AV_RL16(buf + 8);
ymax = AV_RL16(buf + 10);
if (xmax < xmin || ymax < ymin) {
av_log(avctx, AV_LOG_ERROR, "invalid image dimensions\n");
return AVERROR_INVALIDDATA;
}
w = xmax - xmin + 1;
h = ymax - ymin + 1;
bits_per_pixel = buf[3];
bytes_per_line = AV_RL16(buf + 66);
nplanes = buf[65];
bytes_per_scanline = nplanes * bytes_per_line;
if (bytes_per_scanline < (w * bits_per_pixel * nplanes + 7) / 8 ||
(!compressed && bytes_per_scanline > buf_size / h)) {
av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n");
return AVERROR_INVALIDDATA;
}
switch ((nplanes << 8) + bits_per_pixel) {
case 0x0308:
avctx->pix_fmt = AV_PIX_FMT_RGB24;
break;
case 0x0108:
case 0x0104:
case 0x0102:
case 0x0101:
case 0x0401:
case 0x0301:
case 0x0201:
avctx->pix_fmt = AV_PIX_FMT_PAL8;
break;
default:
av_log(avctx, AV_LOG_ERROR, "invalid PCX file\n");
return AVERROR_INVALIDDATA;
}
buf += 128;
if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
return ret;
if ((ret = ff_get_buffer(avctx, p, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
p->pict_type = AV_PICTURE_TYPE_I;
ptr = p->data[0];
stride = p->linesize[0];
scanline = av_malloc(bytes_per_scanline);
if (!scanline)
return AVERROR(ENOMEM);
if (nplanes == 3 && bits_per_pixel == 8) {
for (y = 0; y < h; y++) {
buf = pcx_rle_decode(buf, buf_end,
scanline, bytes_per_scanline, compressed);
for (x = 0; x < w; x++) {
ptr[3 * x] = scanline[x];
ptr[3 * x + 1] = scanline[x + bytes_per_line];
ptr[3 * x + 2] = scanline[x + (bytes_per_line << 1)];
}
ptr += stride;
}
} else if (nplanes == 1 && bits_per_pixel == 8) {
const uint8_t *palstart = bufstart + buf_size - 769;
if (buf_size < 769) {
av_log(avctx, AV_LOG_ERROR, "File is too short\n");
ret = avctx->err_recognition & AV_EF_EXPLODE ?
AVERROR_INVALIDDATA : buf_size;
goto end;
}
for (y = 0; y < h; y++, ptr += stride) {
buf = pcx_rle_decode(buf, buf_end,
scanline, bytes_per_scanline, compressed);
memcpy(ptr, scanline, w);
}
if (buf != palstart) {
av_log(avctx, AV_LOG_WARNING, "image data possibly corrupted\n");
buf = palstart;
}
if (*buf++ != 12) {
av_log(avctx, AV_LOG_ERROR, "expected palette after image data\n");
ret = avctx->err_recognition & AV_EF_EXPLODE ?
AVERROR_INVALIDDATA : buf_size;
goto end;
}
} else if (nplanes == 1) { /* all packed formats, max. 16 colors */
GetBitContext s;
for (y = 0; y < h; y++) {
init_get_bits(&s, scanline, bytes_per_scanline << 3);
buf = pcx_rle_decode(buf, buf_end,
scanline, bytes_per_scanline, compressed);
for (x = 0; x < w; x++)
ptr[x] = get_bits(&s, bits_per_pixel);
ptr += stride;
}
} else { /* planar, 4, 8 or 16 colors */
int i;
for (y = 0; y < h; y++) {
buf = pcx_rle_decode(buf, buf_end,
scanline, bytes_per_scanline, compressed);
for (x = 0; x < w; x++) {
int m = 0x80 >> (x & 7), v = 0;
for (i = nplanes - 1; i >= 0; i--) {
v <<= 1;
v += !!(scanline[i * bytes_per_line + (x >> 3)] & m);
}
ptr[x] = v;
}
ptr += stride;
}
}
if (nplanes == 1 && bits_per_pixel == 8) {
pcx_palette(&buf, (uint32_t *)p->data[1], 256);
} else if (bits_per_pixel < 8) {
const uint8_t *palette = bufstart + 16;
pcx_palette(&palette, (uint32_t *)p->data[1], 16);
}
*got_frame = 1;
ret = buf - bufstart;
end:
av_free(scanline);
return ret;
}
| 15,259 |
FFmpeg | bda5b6627a558cf10c4d09eeff264289a1370cc1 | 0 | static int mkv_write_trailer(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *pb = s->pb;
int64_t currentpos, cuespos;
int ret;
// check if we have an audio packet cached
if (mkv->cur_audio_pkt.size > 0) {
ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
mkv->cur_audio_pkt.size = 0;
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret);
return ret;
}
}
if (mkv->dyn_bc) {
end_ebml_master(mkv->dyn_bc, mkv->cluster);
mkv_flush_dynbuf(s);
} else if (mkv->cluster_pos) {
end_ebml_master(pb, mkv->cluster);
}
if (pb->seekable) {
if (mkv->cues->num_entries) {
cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES, cuespos);
if (ret < 0) return ret;
}
mkv_write_seekhead(pb, mkv->main_seekhead);
// update the duration
av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
currentpos = avio_tell(pb);
avio_seek(pb, mkv->duration_offset, SEEK_SET);
put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration);
avio_seek(pb, currentpos, SEEK_SET);
}
end_ebml_master(pb, mkv->segment);
av_free(mkv->tracks);
av_freep(&mkv->cues->entries);
av_freep(&mkv->cues);
av_destruct_packet(&mkv->cur_audio_pkt);
avio_flush(pb);
return 0;
}
| 15,261 |
FFmpeg | f19af812a32c1398d48c3550d11dbc6aafbb2bfc | 1 | int is_adx(const unsigned char *buf,size_t bufsize)
{
int offset;
if (buf[0]!=0x80) return 0;
offset = (read_long(buf)^0x80000000)+4;
if (bufsize<offset || memcmp(buf+offset-6,"(c)CRI",6)) return 0;
return offset;
}
| 15,263 |
qemu | 2b21233061696feed434317a70e0a8b74f956ec8 | 1 | rfc3986_parse_port(URI *uri, const char **str)
{
const char *cur = *str;
if (ISA_DIGIT(cur)) {
if (uri != NULL)
uri->port = 0;
while (ISA_DIGIT(cur)) {
if (uri != NULL)
uri->port = uri->port * 10 + (*cur - '0');
cur++;
}
*str = cur;
return(0);
}
return(1);
}
| 15,265 |
FFmpeg | 0ecca7a49f8e254c12a3a1de048d738bfbb614c6 | 1 | static void encode_422_bitstream(HYuvContext *s, int count){
int i;
count/=2;
if(s->flags&CODEC_FLAG_PASS1){
for(i=0; i<count; i++){
s->stats[0][ s->temp[0][2*i ] ]++;
s->stats[1][ s->temp[1][ i ] ]++;
s->stats[0][ s->temp[0][2*i+1] ]++;
s->stats[2][ s->temp[2][ i ] ]++;
}
}else if(s->context){
for(i=0; i<count; i++){
s->stats[0][ s->temp[0][2*i ] ]++;
put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
s->stats[1][ s->temp[1][ i ] ]++;
put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
s->stats[0][ s->temp[0][2*i+1] ]++;
put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
s->stats[2][ s->temp[2][ i ] ]++;
put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
}
}else{
for(i=0; i<count; i++){
put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
}
}
}
| 15,266 |
qemu | 4f4321c11ff6e98583846bfd6f0e81954924b003 | 1 | static int usb_net_handle_dataout(USBNetState *s, USBPacket *p)
{
int ret = p->len;
int sz = sizeof(s->out_buf) - s->out_ptr;
struct rndis_packet_msg_type *msg =
(struct rndis_packet_msg_type *) s->out_buf;
uint32_t len;
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data out len %u\n", p->len);
{
int i;
fprintf(stderr, ":");
for (i = 0; i < p->len; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", p->data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
if (sz > ret)
sz = ret;
memcpy(&s->out_buf[s->out_ptr], p->data, sz);
s->out_ptr += sz;
if (!is_rndis(s)) {
if (ret < 64) {
qemu_send_packet(&s->nic->nc, s->out_buf, s->out_ptr);
s->out_ptr = 0;
}
return ret;
}
len = le32_to_cpu(msg->MessageLength);
if (s->out_ptr < 8 || s->out_ptr < len)
return ret;
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
if (offs + size <= len)
qemu_send_packet(&s->nic->nc, s->out_buf + offs, size);
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
return ret;
}
| 15,267 |
qemu | c5a49c63fa26e8825ad101dfe86339ae4c216539 | 1 | static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
{
int32_t disp21, disp16, disp12 __attribute__((unused));
uint16_t fn11;
uint8_t opc, ra, rb, rc, fpfn, fn7, lit;
bool islit, real_islit;
TCGv va, vb, vc, tmp, tmp2;
TCGv_i32 t32;
DisasJumpType ret;
/* Decode all instruction fields */
opc = extract32(insn, 26, 6);
ra = extract32(insn, 21, 5);
rb = extract32(insn, 16, 5);
rc = extract32(insn, 0, 5);
real_islit = islit = extract32(insn, 12, 1);
lit = extract32(insn, 13, 8);
disp21 = sextract32(insn, 0, 21);
disp16 = sextract32(insn, 0, 16);
disp12 = sextract32(insn, 0, 12);
fn11 = extract32(insn, 5, 11);
fpfn = extract32(insn, 5, 6);
fn7 = extract32(insn, 5, 7);
if (rb == 31 && !islit) {
islit = true;
lit = 0;
}
ret = DISAS_NEXT;
switch (opc) {
case 0x00:
/* CALL_PAL */
ret = gen_call_pal(ctx, insn & 0x03ffffff);
break;
case 0x01:
/* OPC01 */
goto invalid_opc;
case 0x02:
/* OPC02 */
goto invalid_opc;
case 0x03:
/* OPC03 */
goto invalid_opc;
case 0x04:
/* OPC04 */
goto invalid_opc;
case 0x05:
/* OPC05 */
goto invalid_opc;
case 0x06:
/* OPC06 */
goto invalid_opc;
case 0x07:
/* OPC07 */
goto invalid_opc;
case 0x09:
/* LDAH */
disp16 = (uint32_t)disp16 << 16;
/* fall through */
case 0x08:
/* LDA */
va = dest_gpr(ctx, ra);
/* It's worth special-casing immediate loads. */
if (rb == 31) {
tcg_gen_movi_i64(va, disp16);
} else {
tcg_gen_addi_i64(va, load_gpr(ctx, rb), disp16);
}
break;
case 0x0A:
/* LDBU */
REQUIRE_AMASK(BWX);
gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
break;
case 0x0B:
/* LDQ_U */
gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
break;
case 0x0C:
/* LDWU */
REQUIRE_AMASK(BWX);
gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
break;
case 0x0D:
/* STW */
REQUIRE_AMASK(BWX);
gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
break;
case 0x0E:
/* STB */
REQUIRE_AMASK(BWX);
gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0);
break;
case 0x0F:
/* STQ_U */
gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1);
break;
case 0x10:
vc = dest_gpr(ctx, rc);
vb = load_gpr_lit(ctx, rb, lit, islit);
if (ra == 31) {
if (fn7 == 0x00) {
/* Special case ADDL as SEXTL. */
tcg_gen_ext32s_i64(vc, vb);
break;
}
if (fn7 == 0x29) {
/* Special case SUBQ as NEGQ. */
tcg_gen_neg_i64(vc, vb);
break;
}
}
va = load_gpr(ctx, ra);
switch (fn7) {
case 0x00:
/* ADDL */
tcg_gen_add_i64(vc, va, vb);
tcg_gen_ext32s_i64(vc, vc);
break;
case 0x02:
/* S4ADDL */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 2);
tcg_gen_add_i64(tmp, tmp, vb);
tcg_gen_ext32s_i64(vc, tmp);
tcg_temp_free(tmp);
break;
case 0x09:
/* SUBL */
tcg_gen_sub_i64(vc, va, vb);
tcg_gen_ext32s_i64(vc, vc);
break;
case 0x0B:
/* S4SUBL */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 2);
tcg_gen_sub_i64(tmp, tmp, vb);
tcg_gen_ext32s_i64(vc, tmp);
tcg_temp_free(tmp);
break;
case 0x0F:
/* CMPBGE */
if (ra == 31) {
/* Special case 0 >= X as X == 0. */
gen_helper_cmpbe0(vc, vb);
} else {
gen_helper_cmpbge(vc, va, vb);
}
break;
case 0x12:
/* S8ADDL */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 3);
tcg_gen_add_i64(tmp, tmp, vb);
tcg_gen_ext32s_i64(vc, tmp);
tcg_temp_free(tmp);
break;
case 0x1B:
/* S8SUBL */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 3);
tcg_gen_sub_i64(tmp, tmp, vb);
tcg_gen_ext32s_i64(vc, tmp);
tcg_temp_free(tmp);
break;
case 0x1D:
/* CMPULT */
tcg_gen_setcond_i64(TCG_COND_LTU, vc, va, vb);
break;
case 0x20:
/* ADDQ */
tcg_gen_add_i64(vc, va, vb);
break;
case 0x22:
/* S4ADDQ */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 2);
tcg_gen_add_i64(vc, tmp, vb);
tcg_temp_free(tmp);
break;
case 0x29:
/* SUBQ */
tcg_gen_sub_i64(vc, va, vb);
break;
case 0x2B:
/* S4SUBQ */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 2);
tcg_gen_sub_i64(vc, tmp, vb);
tcg_temp_free(tmp);
break;
case 0x2D:
/* CMPEQ */
tcg_gen_setcond_i64(TCG_COND_EQ, vc, va, vb);
break;
case 0x32:
/* S8ADDQ */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 3);
tcg_gen_add_i64(vc, tmp, vb);
tcg_temp_free(tmp);
break;
case 0x3B:
/* S8SUBQ */
tmp = tcg_temp_new();
tcg_gen_shli_i64(tmp, va, 3);
tcg_gen_sub_i64(vc, tmp, vb);
tcg_temp_free(tmp);
break;
case 0x3D:
/* CMPULE */
tcg_gen_setcond_i64(TCG_COND_LEU, vc, va, vb);
break;
case 0x40:
/* ADDL/V */
tmp = tcg_temp_new();
tcg_gen_ext32s_i64(tmp, va);
tcg_gen_ext32s_i64(vc, vb);
tcg_gen_add_i64(tmp, tmp, vc);
tcg_gen_ext32s_i64(vc, tmp);
gen_helper_check_overflow(cpu_env, vc, tmp);
tcg_temp_free(tmp);
break;
case 0x49:
/* SUBL/V */
tmp = tcg_temp_new();
tcg_gen_ext32s_i64(tmp, va);
tcg_gen_ext32s_i64(vc, vb);
tcg_gen_sub_i64(tmp, tmp, vc);
tcg_gen_ext32s_i64(vc, tmp);
gen_helper_check_overflow(cpu_env, vc, tmp);
tcg_temp_free(tmp);
break;
case 0x4D:
/* CMPLT */
tcg_gen_setcond_i64(TCG_COND_LT, vc, va, vb);
break;
case 0x60:
/* ADDQ/V */
tmp = tcg_temp_new();
tmp2 = tcg_temp_new();
tcg_gen_eqv_i64(tmp, va, vb);
tcg_gen_mov_i64(tmp2, va);
tcg_gen_add_i64(vc, va, vb);
tcg_gen_xor_i64(tmp2, tmp2, vc);
tcg_gen_and_i64(tmp, tmp, tmp2);
tcg_gen_shri_i64(tmp, tmp, 63);
tcg_gen_movi_i64(tmp2, 0);
gen_helper_check_overflow(cpu_env, tmp, tmp2);
tcg_temp_free(tmp);
tcg_temp_free(tmp2);
break;
case 0x69:
/* SUBQ/V */
tmp = tcg_temp_new();
tmp2 = tcg_temp_new();
tcg_gen_xor_i64(tmp, va, vb);
tcg_gen_mov_i64(tmp2, va);
tcg_gen_sub_i64(vc, va, vb);
tcg_gen_xor_i64(tmp2, tmp2, vc);
tcg_gen_and_i64(tmp, tmp, tmp2);
tcg_gen_shri_i64(tmp, tmp, 63);
tcg_gen_movi_i64(tmp2, 0);
gen_helper_check_overflow(cpu_env, tmp, tmp2);
tcg_temp_free(tmp);
tcg_temp_free(tmp2);
break;
case 0x6D:
/* CMPLE */
tcg_gen_setcond_i64(TCG_COND_LE, vc, va, vb);
break;
default:
goto invalid_opc;
}
break;
case 0x11:
if (fn7 == 0x20) {
if (rc == 31) {
/* Special case BIS as NOP. */
break;
}
if (ra == 31) {
/* Special case BIS as MOV. */
vc = dest_gpr(ctx, rc);
if (islit) {
tcg_gen_movi_i64(vc, lit);
} else {
tcg_gen_mov_i64(vc, load_gpr(ctx, rb));
}
break;
}
}
vc = dest_gpr(ctx, rc);
vb = load_gpr_lit(ctx, rb, lit, islit);
if (fn7 == 0x28 && ra == 31) {
/* Special case ORNOT as NOT. */
tcg_gen_not_i64(vc, vb);
break;
}
va = load_gpr(ctx, ra);
switch (fn7) {
case 0x00:
/* AND */
tcg_gen_and_i64(vc, va, vb);
break;
case 0x08:
/* BIC */
tcg_gen_andc_i64(vc, va, vb);
break;
case 0x14:
/* CMOVLBS */
tmp = tcg_temp_new();
tcg_gen_andi_i64(tmp, va, 1);
tcg_gen_movcond_i64(TCG_COND_NE, vc, tmp, load_zero(ctx),
vb, load_gpr(ctx, rc));
tcg_temp_free(tmp);
break;
case 0x16:
/* CMOVLBC */
tmp = tcg_temp_new();
tcg_gen_andi_i64(tmp, va, 1);
tcg_gen_movcond_i64(TCG_COND_EQ, vc, tmp, load_zero(ctx),
vb, load_gpr(ctx, rc));
tcg_temp_free(tmp);
break;
case 0x20:
/* BIS */
tcg_gen_or_i64(vc, va, vb);
break;
case 0x24:
/* CMOVEQ */
tcg_gen_movcond_i64(TCG_COND_EQ, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x26:
/* CMOVNE */
tcg_gen_movcond_i64(TCG_COND_NE, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x28:
/* ORNOT */
tcg_gen_orc_i64(vc, va, vb);
break;
case 0x40:
/* XOR */
tcg_gen_xor_i64(vc, va, vb);
break;
case 0x44:
/* CMOVLT */
tcg_gen_movcond_i64(TCG_COND_LT, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x46:
/* CMOVGE */
tcg_gen_movcond_i64(TCG_COND_GE, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x48:
/* EQV */
tcg_gen_eqv_i64(vc, va, vb);
break;
case 0x61:
/* AMASK */
REQUIRE_REG_31(ra);
tcg_gen_andi_i64(vc, vb, ~ctx->amask);
break;
case 0x64:
/* CMOVLE */
tcg_gen_movcond_i64(TCG_COND_LE, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x66:
/* CMOVGT */
tcg_gen_movcond_i64(TCG_COND_GT, vc, va, load_zero(ctx),
vb, load_gpr(ctx, rc));
break;
case 0x6C:
/* IMPLVER */
REQUIRE_REG_31(ra);
tcg_gen_movi_i64(vc, ctx->implver);
break;
default:
goto invalid_opc;
}
break;
case 0x12:
vc = dest_gpr(ctx, rc);
va = load_gpr(ctx, ra);
switch (fn7) {
case 0x02:
/* MSKBL */
gen_msk_l(ctx, vc, va, rb, islit, lit, 0x01);
break;
case 0x06:
/* EXTBL */
gen_ext_l(ctx, vc, va, rb, islit, lit, 0x01);
break;
case 0x0B:
/* INSBL */
gen_ins_l(ctx, vc, va, rb, islit, lit, 0x01);
break;
case 0x12:
/* MSKWL */
gen_msk_l(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x16:
/* EXTWL */
gen_ext_l(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x1B:
/* INSWL */
gen_ins_l(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x22:
/* MSKLL */
gen_msk_l(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x26:
/* EXTLL */
gen_ext_l(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x2B:
/* INSLL */
gen_ins_l(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x30:
/* ZAP */
if (islit) {
gen_zapnoti(vc, va, ~lit);
} else {
gen_helper_zap(vc, va, load_gpr(ctx, rb));
}
break;
case 0x31:
/* ZAPNOT */
if (islit) {
gen_zapnoti(vc, va, lit);
} else {
gen_helper_zapnot(vc, va, load_gpr(ctx, rb));
}
break;
case 0x32:
/* MSKQL */
gen_msk_l(ctx, vc, va, rb, islit, lit, 0xff);
break;
case 0x34:
/* SRL */
if (islit) {
tcg_gen_shri_i64(vc, va, lit & 0x3f);
} else {
tmp = tcg_temp_new();
vb = load_gpr(ctx, rb);
tcg_gen_andi_i64(tmp, vb, 0x3f);
tcg_gen_shr_i64(vc, va, tmp);
tcg_temp_free(tmp);
}
break;
case 0x36:
/* EXTQL */
gen_ext_l(ctx, vc, va, rb, islit, lit, 0xff);
break;
case 0x39:
/* SLL */
if (islit) {
tcg_gen_shli_i64(vc, va, lit & 0x3f);
} else {
tmp = tcg_temp_new();
vb = load_gpr(ctx, rb);
tcg_gen_andi_i64(tmp, vb, 0x3f);
tcg_gen_shl_i64(vc, va, tmp);
tcg_temp_free(tmp);
}
break;
case 0x3B:
/* INSQL */
gen_ins_l(ctx, vc, va, rb, islit, lit, 0xff);
break;
case 0x3C:
/* SRA */
if (islit) {
tcg_gen_sari_i64(vc, va, lit & 0x3f);
} else {
tmp = tcg_temp_new();
vb = load_gpr(ctx, rb);
tcg_gen_andi_i64(tmp, vb, 0x3f);
tcg_gen_sar_i64(vc, va, tmp);
tcg_temp_free(tmp);
}
break;
case 0x52:
/* MSKWH */
gen_msk_h(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x57:
/* INSWH */
gen_ins_h(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x5A:
/* EXTWH */
gen_ext_h(ctx, vc, va, rb, islit, lit, 0x03);
break;
case 0x62:
/* MSKLH */
gen_msk_h(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x67:
/* INSLH */
gen_ins_h(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x6A:
/* EXTLH */
gen_ext_h(ctx, vc, va, rb, islit, lit, 0x0f);
break;
case 0x72:
/* MSKQH */
gen_msk_h(ctx, vc, va, rb, islit, lit, 0xff);
break;
case 0x77:
/* INSQH */
gen_ins_h(ctx, vc, va, rb, islit, lit, 0xff);
break;
case 0x7A:
/* EXTQH */
gen_ext_h(ctx, vc, va, rb, islit, lit, 0xff);
break;
default:
goto invalid_opc;
}
break;
case 0x13:
vc = dest_gpr(ctx, rc);
vb = load_gpr_lit(ctx, rb, lit, islit);
va = load_gpr(ctx, ra);
switch (fn7) {
case 0x00:
/* MULL */
tcg_gen_mul_i64(vc, va, vb);
tcg_gen_ext32s_i64(vc, vc);
break;
case 0x20:
/* MULQ */
tcg_gen_mul_i64(vc, va, vb);
break;
case 0x30:
/* UMULH */
tmp = tcg_temp_new();
tcg_gen_mulu2_i64(tmp, vc, va, vb);
tcg_temp_free(tmp);
break;
case 0x40:
/* MULL/V */
tmp = tcg_temp_new();
tcg_gen_ext32s_i64(tmp, va);
tcg_gen_ext32s_i64(vc, vb);
tcg_gen_mul_i64(tmp, tmp, vc);
tcg_gen_ext32s_i64(vc, tmp);
gen_helper_check_overflow(cpu_env, vc, tmp);
tcg_temp_free(tmp);
break;
case 0x60:
/* MULQ/V */
tmp = tcg_temp_new();
tmp2 = tcg_temp_new();
tcg_gen_muls2_i64(vc, tmp, va, vb);
tcg_gen_sari_i64(tmp2, vc, 63);
gen_helper_check_overflow(cpu_env, tmp, tmp2);
tcg_temp_free(tmp);
tcg_temp_free(tmp2);
break;
default:
goto invalid_opc;
}
break;
case 0x14:
REQUIRE_AMASK(FIX);
vc = dest_fpr(ctx, rc);
switch (fpfn) { /* fn11 & 0x3F */
case 0x04:
/* ITOFS */
REQUIRE_REG_31(rb);
t32 = tcg_temp_new_i32();
va = load_gpr(ctx, ra);
tcg_gen_extrl_i64_i32(t32, va);
gen_helper_memory_to_s(vc, t32);
tcg_temp_free_i32(t32);
break;
case 0x0A:
/* SQRTF */
REQUIRE_REG_31(ra);
vb = load_fpr(ctx, rb);
gen_helper_sqrtf(vc, cpu_env, vb);
break;
case 0x0B:
/* SQRTS */
REQUIRE_REG_31(ra);
gen_sqrts(ctx, rb, rc, fn11);
break;
case 0x14:
/* ITOFF */
REQUIRE_REG_31(rb);
t32 = tcg_temp_new_i32();
va = load_gpr(ctx, ra);
tcg_gen_extrl_i64_i32(t32, va);
gen_helper_memory_to_f(vc, t32);
tcg_temp_free_i32(t32);
break;
case 0x24:
/* ITOFT */
REQUIRE_REG_31(rb);
va = load_gpr(ctx, ra);
tcg_gen_mov_i64(vc, va);
break;
case 0x2A:
/* SQRTG */
REQUIRE_REG_31(ra);
vb = load_fpr(ctx, rb);
gen_helper_sqrtg(vc, cpu_env, vb);
break;
case 0x02B:
/* SQRTT */
REQUIRE_REG_31(ra);
gen_sqrtt(ctx, rb, rc, fn11);
break;
default:
goto invalid_opc;
}
break;
case 0x15:
/* VAX floating point */
/* XXX: rounding mode and trap are ignored (!) */
vc = dest_fpr(ctx, rc);
vb = load_fpr(ctx, rb);
va = load_fpr(ctx, ra);
switch (fpfn) { /* fn11 & 0x3F */
case 0x00:
/* ADDF */
gen_helper_addf(vc, cpu_env, va, vb);
break;
case 0x01:
/* SUBF */
gen_helper_subf(vc, cpu_env, va, vb);
break;
case 0x02:
/* MULF */
gen_helper_mulf(vc, cpu_env, va, vb);
break;
case 0x03:
/* DIVF */
gen_helper_divf(vc, cpu_env, va, vb);
break;
case 0x1E:
/* CVTDG -- TODO */
REQUIRE_REG_31(ra);
goto invalid_opc;
case 0x20:
/* ADDG */
gen_helper_addg(vc, cpu_env, va, vb);
break;
case 0x21:
/* SUBG */
gen_helper_subg(vc, cpu_env, va, vb);
break;
case 0x22:
/* MULG */
gen_helper_mulg(vc, cpu_env, va, vb);
break;
case 0x23:
/* DIVG */
gen_helper_divg(vc, cpu_env, va, vb);
break;
case 0x25:
/* CMPGEQ */
gen_helper_cmpgeq(vc, cpu_env, va, vb);
break;
case 0x26:
/* CMPGLT */
gen_helper_cmpglt(vc, cpu_env, va, vb);
break;
case 0x27:
/* CMPGLE */
gen_helper_cmpgle(vc, cpu_env, va, vb);
break;
case 0x2C:
/* CVTGF */
REQUIRE_REG_31(ra);
gen_helper_cvtgf(vc, cpu_env, vb);
break;
case 0x2D:
/* CVTGD -- TODO */
REQUIRE_REG_31(ra);
goto invalid_opc;
case 0x2F:
/* CVTGQ */
REQUIRE_REG_31(ra);
gen_helper_cvtgq(vc, cpu_env, vb);
break;
case 0x3C:
/* CVTQF */
REQUIRE_REG_31(ra);
gen_helper_cvtqf(vc, cpu_env, vb);
break;
case 0x3E:
/* CVTQG */
REQUIRE_REG_31(ra);
gen_helper_cvtqg(vc, cpu_env, vb);
break;
default:
goto invalid_opc;
}
break;
case 0x16:
/* IEEE floating-point */
switch (fpfn) { /* fn11 & 0x3F */
case 0x00:
/* ADDS */
gen_adds(ctx, ra, rb, rc, fn11);
break;
case 0x01:
/* SUBS */
gen_subs(ctx, ra, rb, rc, fn11);
break;
case 0x02:
/* MULS */
gen_muls(ctx, ra, rb, rc, fn11);
break;
case 0x03:
/* DIVS */
gen_divs(ctx, ra, rb, rc, fn11);
break;
case 0x20:
/* ADDT */
gen_addt(ctx, ra, rb, rc, fn11);
break;
case 0x21:
/* SUBT */
gen_subt(ctx, ra, rb, rc, fn11);
break;
case 0x22:
/* MULT */
gen_mult(ctx, ra, rb, rc, fn11);
break;
case 0x23:
/* DIVT */
gen_divt(ctx, ra, rb, rc, fn11);
break;
case 0x24:
/* CMPTUN */
gen_cmptun(ctx, ra, rb, rc, fn11);
break;
case 0x25:
/* CMPTEQ */
gen_cmpteq(ctx, ra, rb, rc, fn11);
break;
case 0x26:
/* CMPTLT */
gen_cmptlt(ctx, ra, rb, rc, fn11);
break;
case 0x27:
/* CMPTLE */
gen_cmptle(ctx, ra, rb, rc, fn11);
break;
case 0x2C:
REQUIRE_REG_31(ra);
if (fn11 == 0x2AC || fn11 == 0x6AC) {
/* CVTST */
gen_cvtst(ctx, rb, rc, fn11);
} else {
/* CVTTS */
gen_cvtts(ctx, rb, rc, fn11);
}
break;
case 0x2F:
/* CVTTQ */
REQUIRE_REG_31(ra);
gen_cvttq(ctx, rb, rc, fn11);
break;
case 0x3C:
/* CVTQS */
REQUIRE_REG_31(ra);
gen_cvtqs(ctx, rb, rc, fn11);
break;
case 0x3E:
/* CVTQT */
REQUIRE_REG_31(ra);
gen_cvtqt(ctx, rb, rc, fn11);
break;
default:
goto invalid_opc;
}
break;
case 0x17:
switch (fn11) {
case 0x010:
/* CVTLQ */
REQUIRE_REG_31(ra);
vc = dest_fpr(ctx, rc);
vb = load_fpr(ctx, rb);
gen_cvtlq(vc, vb);
break;
case 0x020:
/* CPYS */
if (rc == 31) {
/* Special case CPYS as FNOP. */
} else {
vc = dest_fpr(ctx, rc);
va = load_fpr(ctx, ra);
if (ra == rb) {
/* Special case CPYS as FMOV. */
tcg_gen_mov_i64(vc, va);
} else {
vb = load_fpr(ctx, rb);
gen_cpy_mask(vc, va, vb, 0, 0x8000000000000000ULL);
}
}
break;
case 0x021:
/* CPYSN */
vc = dest_fpr(ctx, rc);
vb = load_fpr(ctx, rb);
va = load_fpr(ctx, ra);
gen_cpy_mask(vc, va, vb, 1, 0x8000000000000000ULL);
break;
case 0x022:
/* CPYSE */
vc = dest_fpr(ctx, rc);
vb = load_fpr(ctx, rb);
va = load_fpr(ctx, ra);
gen_cpy_mask(vc, va, vb, 0, 0xFFF0000000000000ULL);
break;
case 0x024:
/* MT_FPCR */
va = load_fpr(ctx, ra);
gen_helper_store_fpcr(cpu_env, va);
if (ctx->tb_rm == QUAL_RM_D) {
/* Re-do the copy of the rounding mode to fp_status
the next time we use dynamic rounding. */
ctx->tb_rm = -1;
}
break;
case 0x025:
/* MF_FPCR */
va = dest_fpr(ctx, ra);
gen_helper_load_fpcr(va, cpu_env);
break;
case 0x02A:
/* FCMOVEQ */
gen_fcmov(ctx, TCG_COND_EQ, ra, rb, rc);
break;
case 0x02B:
/* FCMOVNE */
gen_fcmov(ctx, TCG_COND_NE, ra, rb, rc);
break;
case 0x02C:
/* FCMOVLT */
gen_fcmov(ctx, TCG_COND_LT, ra, rb, rc);
break;
case 0x02D:
/* FCMOVGE */
gen_fcmov(ctx, TCG_COND_GE, ra, rb, rc);
break;
case 0x02E:
/* FCMOVLE */
gen_fcmov(ctx, TCG_COND_LE, ra, rb, rc);
break;
case 0x02F:
/* FCMOVGT */
gen_fcmov(ctx, TCG_COND_GT, ra, rb, rc);
break;
case 0x030: /* CVTQL */
case 0x130: /* CVTQL/V */
case 0x530: /* CVTQL/SV */
REQUIRE_REG_31(ra);
vc = dest_fpr(ctx, rc);
vb = load_fpr(ctx, rb);
gen_helper_cvtql(vc, cpu_env, vb);
gen_fp_exc_raise(rc, fn11);
break;
default:
goto invalid_opc;
}
break;
case 0x18:
switch ((uint16_t)disp16) {
case 0x0000:
/* TRAPB */
/* No-op. */
break;
case 0x0400:
/* EXCB */
/* No-op. */
break;
case 0x4000:
/* MB */
tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
break;
case 0x4400:
/* WMB */
tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
break;
case 0x8000:
/* FETCH */
/* No-op */
break;
case 0xA000:
/* FETCH_M */
/* No-op */
break;
case 0xC000:
/* RPCC */
va = dest_gpr(ctx, ra);
if (ctx->base.tb->cflags & CF_USE_ICOUNT) {
gen_io_start();
gen_helper_load_pcc(va, cpu_env);
gen_io_end();
ret = DISAS_PC_STALE;
} else {
gen_helper_load_pcc(va, cpu_env);
}
break;
case 0xE000:
/* RC */
gen_rx(ctx, ra, 0);
break;
case 0xE800:
/* ECB */
break;
case 0xF000:
/* RS */
gen_rx(ctx, ra, 1);
break;
case 0xF800:
/* WH64 */
/* No-op */
break;
case 0xFC00:
/* WH64EN */
/* No-op */
break;
default:
goto invalid_opc;
}
break;
case 0x19:
/* HW_MFPR (PALcode) */
#ifndef CONFIG_USER_ONLY
REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE);
va = dest_gpr(ctx, ra);
ret = gen_mfpr(ctx, va, insn & 0xffff);
break;
#else
goto invalid_opc;
#endif
case 0x1A:
/* JMP, JSR, RET, JSR_COROUTINE. These only differ by the branch
prediction stack action, which of course we don't implement. */
vb = load_gpr(ctx, rb);
tcg_gen_andi_i64(cpu_pc, vb, ~3);
if (ra != 31) {
tcg_gen_movi_i64(ctx->ir[ra], ctx->base.pc_next);
}
ret = DISAS_PC_UPDATED;
break;
case 0x1B:
/* HW_LD (PALcode) */
#ifndef CONFIG_USER_ONLY
REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE);
{
TCGv addr = tcg_temp_new();
vb = load_gpr(ctx, rb);
va = dest_gpr(ctx, ra);
tcg_gen_addi_i64(addr, vb, disp12);
switch ((insn >> 12) & 0xF) {
case 0x0:
/* Longword physical access (hw_ldl/p) */
tcg_gen_qemu_ld_i64(va, addr, MMU_PHYS_IDX, MO_LESL);
break;
case 0x1:
/* Quadword physical access (hw_ldq/p) */
tcg_gen_qemu_ld_i64(va, addr, MMU_PHYS_IDX, MO_LEQ);
break;
case 0x2:
/* Longword physical access with lock (hw_ldl_l/p) */
gen_qemu_ldl_l(va, addr, MMU_PHYS_IDX);
break;
case 0x3:
/* Quadword physical access with lock (hw_ldq_l/p) */
gen_qemu_ldq_l(va, addr, MMU_PHYS_IDX);
break;
case 0x4:
/* Longword virtual PTE fetch (hw_ldl/v) */
goto invalid_opc;
case 0x5:
/* Quadword virtual PTE fetch (hw_ldq/v) */
goto invalid_opc;
break;
case 0x6:
/* Invalid */
goto invalid_opc;
case 0x7:
/* Invaliid */
goto invalid_opc;
case 0x8:
/* Longword virtual access (hw_ldl) */
goto invalid_opc;
case 0x9:
/* Quadword virtual access (hw_ldq) */
goto invalid_opc;
case 0xA:
/* Longword virtual access with protection check (hw_ldl/w) */
tcg_gen_qemu_ld_i64(va, addr, MMU_KERNEL_IDX, MO_LESL);
break;
case 0xB:
/* Quadword virtual access with protection check (hw_ldq/w) */
tcg_gen_qemu_ld_i64(va, addr, MMU_KERNEL_IDX, MO_LEQ);
break;
case 0xC:
/* Longword virtual access with alt access mode (hw_ldl/a)*/
goto invalid_opc;
case 0xD:
/* Quadword virtual access with alt access mode (hw_ldq/a) */
goto invalid_opc;
case 0xE:
/* Longword virtual access with alternate access mode and
protection checks (hw_ldl/wa) */
tcg_gen_qemu_ld_i64(va, addr, MMU_USER_IDX, MO_LESL);
break;
case 0xF:
/* Quadword virtual access with alternate access mode and
protection checks (hw_ldq/wa) */
tcg_gen_qemu_ld_i64(va, addr, MMU_USER_IDX, MO_LEQ);
break;
}
tcg_temp_free(addr);
break;
}
#else
goto invalid_opc;
#endif
case 0x1C:
vc = dest_gpr(ctx, rc);
if (fn7 == 0x70) {
/* FTOIT */
REQUIRE_AMASK(FIX);
REQUIRE_REG_31(rb);
va = load_fpr(ctx, ra);
tcg_gen_mov_i64(vc, va);
break;
} else if (fn7 == 0x78) {
/* FTOIS */
REQUIRE_AMASK(FIX);
REQUIRE_REG_31(rb);
t32 = tcg_temp_new_i32();
va = load_fpr(ctx, ra);
gen_helper_s_to_memory(t32, va);
tcg_gen_ext_i32_i64(vc, t32);
tcg_temp_free_i32(t32);
break;
}
vb = load_gpr_lit(ctx, rb, lit, islit);
switch (fn7) {
case 0x00:
/* SEXTB */
REQUIRE_AMASK(BWX);
REQUIRE_REG_31(ra);
tcg_gen_ext8s_i64(vc, vb);
break;
case 0x01:
/* SEXTW */
REQUIRE_AMASK(BWX);
REQUIRE_REG_31(ra);
tcg_gen_ext16s_i64(vc, vb);
break;
case 0x30:
/* CTPOP */
REQUIRE_AMASK(CIX);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
tcg_gen_ctpop_i64(vc, vb);
break;
case 0x31:
/* PERR */
REQUIRE_AMASK(MVI);
REQUIRE_NO_LIT;
va = load_gpr(ctx, ra);
gen_helper_perr(vc, va, vb);
break;
case 0x32:
/* CTLZ */
REQUIRE_AMASK(CIX);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
tcg_gen_clzi_i64(vc, vb, 64);
break;
case 0x33:
/* CTTZ */
REQUIRE_AMASK(CIX);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
tcg_gen_ctzi_i64(vc, vb, 64);
break;
case 0x34:
/* UNPKBW */
REQUIRE_AMASK(MVI);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
gen_helper_unpkbw(vc, vb);
break;
case 0x35:
/* UNPKBL */
REQUIRE_AMASK(MVI);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
gen_helper_unpkbl(vc, vb);
break;
case 0x36:
/* PKWB */
REQUIRE_AMASK(MVI);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
gen_helper_pkwb(vc, vb);
break;
case 0x37:
/* PKLB */
REQUIRE_AMASK(MVI);
REQUIRE_REG_31(ra);
REQUIRE_NO_LIT;
gen_helper_pklb(vc, vb);
break;
case 0x38:
/* MINSB8 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_minsb8(vc, va, vb);
break;
case 0x39:
/* MINSW4 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_minsw4(vc, va, vb);
break;
case 0x3A:
/* MINUB8 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_minub8(vc, va, vb);
break;
case 0x3B:
/* MINUW4 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_minuw4(vc, va, vb);
break;
case 0x3C:
/* MAXUB8 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_maxub8(vc, va, vb);
break;
case 0x3D:
/* MAXUW4 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_maxuw4(vc, va, vb);
break;
case 0x3E:
/* MAXSB8 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_maxsb8(vc, va, vb);
break;
case 0x3F:
/* MAXSW4 */
REQUIRE_AMASK(MVI);
va = load_gpr(ctx, ra);
gen_helper_maxsw4(vc, va, vb);
break;
default:
goto invalid_opc;
}
break;
case 0x1D:
/* HW_MTPR (PALcode) */
#ifndef CONFIG_USER_ONLY
REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE);
vb = load_gpr(ctx, rb);
ret = gen_mtpr(ctx, vb, insn & 0xffff);
break;
#else
goto invalid_opc;
#endif
case 0x1E:
/* HW_RET (PALcode) */
#ifndef CONFIG_USER_ONLY
REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE);
if (rb == 31) {
/* Pre-EV6 CPUs interpreted this as HW_REI, loading the return
address from EXC_ADDR. This turns out to be useful for our
emulation PALcode, so continue to accept it. */
ctx->lit = vb = tcg_temp_new();
tcg_gen_ld_i64(vb, cpu_env, offsetof(CPUAlphaState, exc_addr));
} else {
vb = load_gpr(ctx, rb);
}
tcg_gen_movi_i64(cpu_lock_addr, -1);
tmp = tcg_temp_new();
tcg_gen_movi_i64(tmp, 0);
st_flag_byte(tmp, ENV_FLAG_RX_SHIFT);
tcg_gen_andi_i64(tmp, vb, 1);
st_flag_byte(tmp, ENV_FLAG_PAL_SHIFT);
tcg_temp_free(tmp);
tcg_gen_andi_i64(cpu_pc, vb, ~3);
/* Allow interrupts to be recognized right away. */
ret = DISAS_PC_UPDATED_NOCHAIN;
break;
#else
goto invalid_opc;
#endif
case 0x1F:
/* HW_ST (PALcode) */
#ifndef CONFIG_USER_ONLY
REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE);
{
switch ((insn >> 12) & 0xF) {
case 0x0:
/* Longword physical access */
va = load_gpr(ctx, ra);
vb = load_gpr(ctx, rb);
tmp = tcg_temp_new();
tcg_gen_addi_i64(tmp, vb, disp12);
tcg_gen_qemu_st_i64(va, tmp, MMU_PHYS_IDX, MO_LESL);
tcg_temp_free(tmp);
break;
case 0x1:
/* Quadword physical access */
va = load_gpr(ctx, ra);
vb = load_gpr(ctx, rb);
tmp = tcg_temp_new();
tcg_gen_addi_i64(tmp, vb, disp12);
tcg_gen_qemu_st_i64(va, tmp, MMU_PHYS_IDX, MO_LEQ);
tcg_temp_free(tmp);
break;
case 0x2:
/* Longword physical access with lock */
ret = gen_store_conditional(ctx, ra, rb, disp12,
MMU_PHYS_IDX, MO_LESL);
break;
case 0x3:
/* Quadword physical access with lock */
ret = gen_store_conditional(ctx, ra, rb, disp12,
MMU_PHYS_IDX, MO_LEQ);
break;
case 0x4:
/* Longword virtual access */
goto invalid_opc;
case 0x5:
/* Quadword virtual access */
goto invalid_opc;
case 0x6:
/* Invalid */
goto invalid_opc;
case 0x7:
/* Invalid */
goto invalid_opc;
case 0x8:
/* Invalid */
goto invalid_opc;
case 0x9:
/* Invalid */
goto invalid_opc;
case 0xA:
/* Invalid */
goto invalid_opc;
case 0xB:
/* Invalid */
goto invalid_opc;
case 0xC:
/* Longword virtual access with alternate access mode */
goto invalid_opc;
case 0xD:
/* Quadword virtual access with alternate access mode */
goto invalid_opc;
case 0xE:
/* Invalid */
goto invalid_opc;
case 0xF:
/* Invalid */
goto invalid_opc;
}
break;
}
#else
goto invalid_opc;
#endif
case 0x20:
/* LDF */
gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
break;
case 0x21:
/* LDG */
gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
break;
case 0x22:
/* LDS */
gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
break;
case 0x23:
/* LDT */
gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
break;
case 0x24:
/* STF */
gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0);
break;
case 0x25:
/* STG */
gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0);
break;
case 0x26:
/* STS */
gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0);
break;
case 0x27:
/* STT */
gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0);
break;
case 0x28:
/* LDL */
gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
break;
case 0x29:
/* LDQ */
gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
break;
case 0x2A:
/* LDL_L */
gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
break;
case 0x2B:
/* LDQ_L */
gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
break;
case 0x2C:
/* STL */
gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0);
break;
case 0x2D:
/* STQ */
gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0);
break;
case 0x2E:
/* STL_C */
ret = gen_store_conditional(ctx, ra, rb, disp16,
ctx->mem_idx, MO_LESL);
break;
case 0x2F:
/* STQ_C */
ret = gen_store_conditional(ctx, ra, rb, disp16,
ctx->mem_idx, MO_LEQ);
break;
case 0x30:
/* BR */
ret = gen_bdirect(ctx, ra, disp21);
break;
case 0x31: /* FBEQ */
ret = gen_fbcond(ctx, TCG_COND_EQ, ra, disp21);
break;
case 0x32: /* FBLT */
ret = gen_fbcond(ctx, TCG_COND_LT, ra, disp21);
break;
case 0x33: /* FBLE */
ret = gen_fbcond(ctx, TCG_COND_LE, ra, disp21);
break;
case 0x34:
/* BSR */
ret = gen_bdirect(ctx, ra, disp21);
break;
case 0x35: /* FBNE */
ret = gen_fbcond(ctx, TCG_COND_NE, ra, disp21);
break;
case 0x36: /* FBGE */
ret = gen_fbcond(ctx, TCG_COND_GE, ra, disp21);
break;
case 0x37: /* FBGT */
ret = gen_fbcond(ctx, TCG_COND_GT, ra, disp21);
break;
case 0x38:
/* BLBC */
ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1);
break;
case 0x39:
/* BEQ */
ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0);
break;
case 0x3A:
/* BLT */
ret = gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0);
break;
case 0x3B:
/* BLE */
ret = gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0);
break;
case 0x3C:
/* BLBS */
ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1);
break;
case 0x3D:
/* BNE */
ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0);
break;
case 0x3E:
/* BGE */
ret = gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0);
break;
case 0x3F:
/* BGT */
ret = gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0);
break;
invalid_opc:
ret = gen_invalid(ctx);
break;
}
return ret;
}
| 15,268 |
qemu | f3c75d42adbba553eaf218a832d4fbea32c8f7b8 | 1 | static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
target_ulong opcode, target_ulong *args)
{
CPUPPCState *env = &cpu->env;
target_ulong flags = args[0];
target_ulong pte_index = args[1];
target_ulong avpn = args[2];
hwaddr hpte;
target_ulong v, r, rb;
if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
return H_PARAMETER;
}
hpte = pte_index * HASH_PTE_SIZE_64;
v = ppc_hash64_load_hpte0(env, hpte);
r = ppc_hash64_load_hpte1(env, hpte);
if ((v & HPTE64_V_VALID) == 0 ||
((flags & H_AVPN) && (v & ~0x7fULL) != avpn)) {
return H_NOT_FOUND;
}
r &= ~(HPTE64_R_PP0 | HPTE64_R_PP | HPTE64_R_N |
HPTE64_R_KEY_HI | HPTE64_R_KEY_LO);
r |= (flags << 55) & HPTE64_R_PP0;
r |= (flags << 48) & HPTE64_R_KEY_HI;
r |= flags & (HPTE64_R_PP | HPTE64_R_N | HPTE64_R_KEY_LO);
rb = compute_tlbie_rb(v, r, pte_index);
ppc_hash64_store_hpte0(env, hpte, (v & ~HPTE64_V_VALID) | HPTE64_V_HPTE_DIRTY);
ppc_tlb_invalidate_one(env, rb);
ppc_hash64_store_hpte1(env, hpte, r);
/* Don't need a memory barrier, due to qemu's global lock */
ppc_hash64_store_hpte0(env, hpte, v | HPTE64_V_HPTE_DIRTY);
return H_SUCCESS;
}
| 15,269 |
qemu | d9bce9d99f4656ae0b0127f7472db9067b8f84ab | 1 | void do_op_602_mfrom (void)
{
if (likely(T0 < 602)) {
#ifdef USE_MFROM_ROM_TABLE
#include "mfrom_table.c"
T0 = mfrom_ROM_table[T0];
#else
double d;
/* Extremly decomposed:
* -T0 / 256
* T0 = 256 * log10(10 + 1.0) + 0.5
*/
d = T0;
d = float64_div(d, 256, &env->fp_status);
d = float64_chs(d);
d = exp10(d); // XXX: use float emulation function
d = float64_add(d, 1.0, &env->fp_status);
d = log10(d); // XXX: use float emulation function
d = float64_mul(d, 256, &env->fp_status);
d = float64_add(d, 0.5, &env->fp_status);
T0 = float64_round_to_int(d, &env->fp_status);
#endif
} else {
T0 = 0;
}
}
| 15,270 |
FFmpeg | 9bd854b1ff342f82efa6d2ad4e8fefddce5fa731 | 1 | static int mpc8_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MPCContext *c = avctx->priv_data;
GetBitContext gb2, *gb = &gb2;
int i, j, k, ch, cnt, res, t;
Band *bands = c->bands;
int off, out_size;
int maxband, keyframe;
int last[2];
out_size = MPC_FRAME_SIZE * 2 * avctx->channels;
if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
return AVERROR(EINVAL);
}
keyframe = c->cur_frame == 0;
if(keyframe){
memset(c->Q, 0, sizeof(c->Q));
c->last_bits_used = 0;
}
init_get_bits(gb, buf, buf_size * 8);
skip_bits(gb, c->last_bits_used & 7);
if(keyframe)
maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1);
else{
maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2);
if(maxband > 32) maxband -= 33;
}
c->last_max_band = maxband;
/* read subband indexes */
if(maxband){
last[0] = last[1] = 0;
for(i = maxband - 1; i >= 0; i--){
for(ch = 0; ch < 2; ch++){
last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch];
if(last[ch] > 15) last[ch] -= 17;
bands[i].res[ch] = last[ch];
}
}
if(c->MSS){
int mask;
cnt = 0;
for(i = 0; i < maxband; i++)
if(bands[i].res[0] || bands[i].res[1])
cnt++;
t = mpc8_get_mod_golomb(gb, cnt);
mask = mpc8_get_mask(gb, cnt, t);
for(i = maxband - 1; i >= 0; i--)
if(bands[i].res[0] || bands[i].res[1]){
bands[i].msf = mask & 1;
mask >>= 1;
}
}
}
for(i = maxband; i < c->maxbands; i++)
bands[i].res[0] = bands[i].res[1] = 0;
if(keyframe){
for(i = 0; i < 32; i++)
c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1;
}
for(i = 0; i < maxband; i++){
if(bands[i].res[0] || bands[i].res[1]){
cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1;
if(cnt >= 0){
t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1);
if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt);
if(bands[i].res[1]) bands[i].scfi[1] = t & 3;
}
}
}
for(i = 0; i < maxband; i++){
for(ch = 0; ch < 2; ch++){
if(!bands[i].res[ch]) continue;
if(c->oldDSCF[ch][i]){
bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6;
c->oldDSCF[ch][i] = 0;
}else{
t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2);
if(t == 64)
t += get_bits(gb, 6);
bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6;
}
for(j = 0; j < 2; j++){
if((bands[i].scfi[ch] << j) & 2)
bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j];
else{
t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2);
if(t == 31)
t = 64 + get_bits(gb, 6);
bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6;
}
}
}
}
for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){
for(ch = 0; ch < 2; ch++){
res = bands[i].res[ch];
switch(res){
case -1:
for(j = 0; j < SAMPLES_PER_BAND; j++)
c->Q[ch][off + j] = (av_lfg_get(&c->rnd) & 0x3FC) - 510;
break;
case 0:
break;
case 1:
for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){
cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2);
t = mpc8_get_mask(gb, 18, cnt);
for(k = 0; k < SAMPLES_PER_BAND / 2; k++, t <<= 1)
c->Q[ch][off + j + k] = (t & 0x20000) ? (get_bits1(gb) << 1) - 1 : 0;
}
break;
case 2:
cnt = 6;//2*mpc8_thres[res]
for(j = 0; j < SAMPLES_PER_BAND; j += 3){
t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2);
c->Q[ch][off + j + 0] = mpc8_idx50[t];
c->Q[ch][off + j + 1] = mpc8_idx51[t];
c->Q[ch][off + j + 2] = mpc8_idx52[t];
cnt = (cnt >> 1) + mpc8_huffq2[t];
}
break;
case 3:
case 4:
for(j = 0; j < SAMPLES_PER_BAND; j += 2){
t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2) + q3_offsets[res - 3];
c->Q[ch][off + j + 1] = t >> 4;
c->Q[ch][off + j + 0] = (t & 8) ? (t & 0xF) - 16 : (t & 0xF);
}
break;
case 5:
case 6:
case 7:
case 8:
cnt = 2 * mpc8_thres[res];
for(j = 0; j < SAMPLES_PER_BAND; j++){
t = get_vlc2(gb, quant_vlc[res - 5][cnt > mpc8_thres[res]].table, quant_vlc[res - 5][cnt > mpc8_thres[res]].bits, 2) + quant_offsets[res - 5];
c->Q[ch][off + j] = t;
cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]);
}
break;
default:
for(j = 0; j < SAMPLES_PER_BAND; j++){
c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2);
if(res != 9){
c->Q[ch][off + j] <<= res - 9;
c->Q[ch][off + j] |= get_bits(gb, res - 9);
}
c->Q[ch][off + j] -= (1 << (res - 2)) - 1;
}
}
}
}
ff_mpc_dequantize_and_synth(c, maxband, data, avctx->channels);
c->cur_frame++;
c->last_bits_used = get_bits_count(gb);
if(c->cur_frame >= c->frames)
c->cur_frame = 0;
*data_size = out_size;
return c->cur_frame ? c->last_bits_used >> 3 : buf_size;
} | 15,271 |
qemu | f3e4ce4af336f2ea306fa0f40ec1a5149864ca8c | 1 | static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
{
BackupBlockJob *s = container_of(job, BackupBlockJob, common);
if (speed < 0) {
error_setg(errp, QERR_INVALID_PARAMETER, "speed");
return;
}
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
}
| 15,272 |
qemu | 33876dfad64bc481f59c5e9ccf60db78624c4b93 | 1 | static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
struct XenDevOps *ops)
{
struct XenDevice *xendev;
char *dom0;
xendev = xen_be_find_xendev(type, dom, dev);
if (xendev) {
return xendev;
}
/* init new xendev */
xendev = g_malloc0(ops->size);
xendev->type = type;
xendev->dom = dom;
xendev->dev = dev;
xendev->ops = ops;
dom0 = xs_get_domain_path(xenstore, 0);
snprintf(xendev->be, sizeof(xendev->be), "%s/backend/%s/%d/%d",
dom0, xendev->type, xendev->dom, xendev->dev);
snprintf(xendev->name, sizeof(xendev->name), "%s-%d",
xendev->type, xendev->dev);
free(dom0);
xendev->debug = debug;
xendev->local_port = -1;
xendev->evtchndev = xen_xc_evtchn_open(NULL, 0);
if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
xen_be_printf(NULL, 0, "can't open evtchn device\n");
g_free(xendev);
return NULL;
}
fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
xendev->gnttabdev = xen_xc_gnttab_open(NULL, 0);
if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
xen_be_printf(NULL, 0, "can't open gnttab device\n");
xc_evtchn_close(xendev->evtchndev);
g_free(xendev);
return NULL;
}
} else {
xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
}
QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
if (xendev->ops->alloc) {
xendev->ops->alloc(xendev);
}
return xendev;
}
| 15,273 |
FFmpeg | 0c800b27611cadd64f46fd1bbd9dc8bb87fe168b | 1 | int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
AVPacket *avpkt,
const AVFrame *frame,
int *got_packet_ptr)
{
AVFrame *extended_frame = NULL;
AVFrame *padded_frame = NULL;
int ret;
AVPacket user_pkt = *avpkt;
int needs_realloc = !user_pkt.data;
*got_packet_ptr = 0;
if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
av_free_packet(avpkt);
av_init_packet(avpkt);
return 0;
}
/* ensure that extended_data is properly set */
if (frame && !frame->extended_data) {
if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
avctx->channels > AV_NUM_DATA_POINTERS) {
av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
"with more than %d channels, but extended_data is not set.\n",
AV_NUM_DATA_POINTERS);
return AVERROR(EINVAL);
}
av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
extended_frame = av_frame_alloc();
if (!extended_frame)
return AVERROR(ENOMEM);
memcpy(extended_frame, frame, sizeof(AVFrame));
extended_frame->extended_data = extended_frame->data;
frame = extended_frame;
}
/* extract audio service type metadata */
if (frame) {
AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
if (sd && sd->size >= sizeof(enum AVAudioServiceType))
avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
}
/* check for valid frame size */
if (frame) {
if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
if (frame->nb_samples > avctx->frame_size) {
av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
ret = AVERROR(EINVAL);
goto end;
}
} else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
if (frame->nb_samples < avctx->frame_size &&
!avctx->internal->last_audio_frame) {
ret = pad_last_frame(avctx, &padded_frame, frame);
if (ret < 0)
goto end;
frame = padded_frame;
avctx->internal->last_audio_frame = 1;
}
if (frame->nb_samples != avctx->frame_size) {
av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
ret = AVERROR(EINVAL);
goto end;
}
}
}
ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
if (!ret) {
if (*got_packet_ptr) {
if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
if (avpkt->pts == AV_NOPTS_VALUE)
avpkt->pts = frame->pts;
if (!avpkt->duration)
avpkt->duration = ff_samples_to_time_base(avctx,
frame->nb_samples);
}
avpkt->dts = avpkt->pts;
} else {
avpkt->size = 0;
}
}
if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
needs_realloc = 0;
if (user_pkt.data) {
if (user_pkt.size >= avpkt->size) {
memcpy(user_pkt.data, avpkt->data, avpkt->size);
} else {
av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
avpkt->size = user_pkt.size;
ret = -1;
}
avpkt->buf = user_pkt.buf;
avpkt->data = user_pkt.data;
#if FF_API_DESTRUCT_PACKET
FF_DISABLE_DEPRECATION_WARNINGS
avpkt->destruct = user_pkt.destruct;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
} else {
if (av_dup_packet(avpkt) < 0) {
ret = AVERROR(ENOMEM);
}
}
}
if (!ret) {
if (needs_realloc && avpkt->data) {
ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
if (ret >= 0)
avpkt->data = avpkt->buf->data;
}
avctx->frame_number++;
}
if (ret < 0 || !*got_packet_ptr) {
av_free_packet(avpkt);
av_init_packet(avpkt);
goto end;
}
/* NOTE: if we add any audio encoders which output non-keyframe packets,
* this needs to be moved to the encoders, but for now we can do it
* here to simplify things */
avpkt->flags |= AV_PKT_FLAG_KEY;
end:
av_frame_free(&padded_frame);
av_free(extended_frame);
#if FF_API_AUDIOENC_DELAY
avctx->delay = avctx->initial_padding;
#endif
return ret;
} | 15,274 |
FFmpeg | 2b31a9c613f95383d5106f8c1cbcee8eb291090f | 1 | static int iff_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
IffDemuxContext *iff = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st = s->streams[0];
int ret;
int64_t pos = avio_tell(pb);
if (pos >= iff->body_end)
return AVERROR_EOF;
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (st->codec->codec_tag == ID_MAUD) {
ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codec->block_align));
} else {
ret = av_get_packet(pb, pkt, iff->body_size);
}
} else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
uint8_t *buf;
if (av_new_packet(pkt, iff->body_size + 2) < 0) {
return AVERROR(ENOMEM);
}
buf = pkt->data;
bytestream_put_be16(&buf, 2);
ret = avio_read(pb, buf, iff->body_size);
} else {
av_assert0(0);
}
if (pos == iff->body_pos)
pkt->flags |= AV_PKT_FLAG_KEY;
if (ret < 0)
return ret;
pkt->stream_index = 0;
return ret;
} | 15,275 |
qemu | f897bf751fbd95e4015b95d202c706548586813a | 1 | static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
VirtIOBlockReq *req = s->rq;
while (req) {
qemu_put_sbyte(f, 1);
qemu_put_buffer(f, (unsigned char *)req->elem,
sizeof(VirtQueueElement));
req = req->next;
}
qemu_put_sbyte(f, 0);
}
| 15,276 |
FFmpeg | 2da0d70d5eebe42f9fcd27ee554419ebe2a5da06 | 1 | static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
uint8_t *dest, long dstW, long dstY)
{
#ifdef HAVE_MMX
long dummy=0;
if(c->flags & SWS_ACCURATE_RND){
switch(c->dstFormat){
case PIX_FMT_RGB32:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
WRITEBGR32(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR24:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
"lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
"add %4, %%"REG_c" \n\t"
WRITEBGR24(%%REGc, %5, %%REGa)
:: "r" (&c->redDither),
"m" (dummy), "m" (dummy), "m" (dummy),
"r" (dest), "m" (dstW)
: "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
);
return;
case PIX_FMT_BGR555:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g5Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR15(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR565:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g6Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR16(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_YUYV422:
YSCALEYUV2PACKEDX_ACCURATE
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
"psraw $3, %%mm3 \n\t"
"psraw $3, %%mm4 \n\t"
"psraw $3, %%mm1 \n\t"
"psraw $3, %%mm7 \n\t"
WRITEYUY2(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
}
}else{
switch(c->dstFormat)
{
case PIX_FMT_RGB32:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
WRITEBGR32(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR24:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
"lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
"add %4, %%"REG_c" \n\t"
WRITEBGR24(%%REGc, %5, %%REGa)
:: "r" (&c->redDither),
"m" (dummy), "m" (dummy), "m" (dummy),
"r" (dest), "m" (dstW)
: "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
);
return;
case PIX_FMT_BGR555:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g5Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR15(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR565:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g6Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR16(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_YUYV422:
YSCALEYUV2PACKEDX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
"psraw $3, %%mm3 \n\t"
"psraw $3, %%mm4 \n\t"
"psraw $3, %%mm1 \n\t"
"psraw $3, %%mm7 \n\t"
WRITEYUY2(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
}
}
#endif
#ifdef HAVE_ALTIVEC
/* The following list of supported dstFormat values should
match what's found in the body of altivec_yuv2packedX() */
if(c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA ||
c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 ||
c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB)
altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, dstW, dstY);
else
#endif
yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, dstW, dstY);
}
| 15,277 |
qemu | 3a330134b3effa3494051763b38f12a24715d53a | 1 | static void virtio_net_save(QEMUFile *f, void *opaque)
{
VirtIONet *n = opaque;
virtio_save(&n->vdev, f);
qemu_put_buffer(f, n->mac, ETH_ALEN);
qemu_put_be32(f, n->tx_timer_active);
qemu_put_be32(f, n->mergeable_rx_bufs);
qemu_put_be16(f, n->status);
qemu_put_byte(f, n->promisc);
qemu_put_byte(f, n->allmulti);
qemu_put_be32(f, n->mac_table.in_use);
qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
qemu_put_be32(f, 0); /* vnet-hdr placeholder */
qemu_put_byte(f, n->mac_table.multi_overflow);
qemu_put_byte(f, n->mac_table.uni_overflow);
qemu_put_byte(f, n->alluni);
qemu_put_byte(f, n->nomulti);
qemu_put_byte(f, n->nouni);
qemu_put_byte(f, n->nobcast);
}
| 15,278 |
FFmpeg | 29112db8c0f65886e69cbbd6f4e5c44d2d14d238 | 1 | static int set_palette(AVFrame * frame, const uint8_t * palette_buffer, int buf_size)
{
uint32_t * palette = (uint32_t *)frame->data[1];
int a;
if (buf_size < 256*3)
return AVERROR_INVALIDDATA;
for(a = 0; a < 256; a++){
palette[a] = AV_RB24(&palette_buffer[a * 3]) * 4;
}
frame->palette_has_changed = 1;
return 256*3;
}
| 15,280 |
FFmpeg | 4d388c0cd05dd4de545e8ea333ab4de7d67ad12d | 1 | static int build_def_list(Picture *def, Picture **in, int len, int is_long, int sel)
{
int i[2] = { 0 };
int index = 0;
while (i[0] < len || i[1] < len) {
while (i[0] < len && !(in[i[0]] && (in[i[0]]->reference & sel)))
i[0]++;
while (i[1] < len && !(in[i[1]] && (in[i[1]]->reference & (sel ^ 3))))
i[1]++;
if (i[0] < len) {
in[i[0]]->pic_id = is_long ? i[0] : in[i[0]]->frame_num;
split_field_copy(&def[index++], in[i[0]++], sel, 1);
}
if (i[1] < len) {
in[i[1]]->pic_id = is_long ? i[1] : in[i[1]]->frame_num;
split_field_copy(&def[index++], in[i[1]++], sel ^ 3, 0);
}
}
return index;
}
| 15,281 |
qemu | 21ef45d71221b4577330fe3aacfb06afad91ad46 | 1 | static void vnc_init_timer(VncDisplay *vd)
{
vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) {
vd->timer = qemu_new_timer_ms(rt_clock, vnc_refresh, vd);
vnc_dpy_resize(dcl, vd->ds);
vnc_refresh(vd);
}
}
| 15,282 |
FFmpeg | bcaf64b605442e1622d16da89d4ec0e7730b8a8c | 0 | static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
int n, i, ch, st, pkt_size, ret;
const int16_t *samples;
int16_t **samples_p;
uint8_t *dst;
ADPCMEncodeContext *c = avctx->priv_data;
uint8_t *buf;
samples = (const int16_t *)frame->data[0];
samples_p = (int16_t **)frame->extended_data;
st = avctx->channels == 2;
if (avctx->codec_id == AV_CODEC_ID_ADPCM_SWF)
pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8;
else
pkt_size = avctx->block_align;
if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)))
return ret;
dst = avpkt->data;
switch(avctx->codec->id) {
case AV_CODEC_ID_ADPCM_IMA_WAV:
{
int blocks, j;
blocks = (frame->nb_samples - 1) / 8;
for (ch = 0; ch < avctx->channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
status->prev_sample = samples_p[ch][0];
/* status->step_index = 0;
XXX: not sure how to init the state machine */
bytestream_put_le16(&dst, status->prev_sample);
*dst++ = status->step_index;
*dst++ = 0; /* unknown */
}
/* stereo: 4 bytes (8 samples) for left, 4 bytes for right */
if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, avctx->channels * blocks * 8, error);
for (ch = 0; ch < avctx->channels; ch++) {
adpcm_compress_trellis(avctx, &samples_p[ch][1],
buf + ch * blocks * 8, &c->status[ch],
blocks * 8, 1);
}
for (i = 0; i < blocks; i++) {
for (ch = 0; ch < avctx->channels; ch++) {
uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
for (j = 0; j < 8; j += 2)
*dst++ = buf1[j] | (buf1[j + 1] << 4);
}
}
av_free(buf);
} else {
for (i = 0; i < blocks; i++) {
for (ch = 0; ch < avctx->channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
const int16_t *smp = &samples_p[ch][1 + i * 8];
for (j = 0; j < 8; j += 2) {
uint8_t v = adpcm_ima_compress_sample(status, smp[j ]);
v |= adpcm_ima_compress_sample(status, smp[j + 1]) << 4;
*dst++ = v;
}
}
}
}
break;
}
case AV_CODEC_ID_ADPCM_IMA_QT:
{
PutBitContext pb;
init_put_bits(&pb, dst, pkt_size * 8);
for (ch = 0; ch < avctx->channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7);
put_bits(&pb, 7, status->step_index);
if (avctx->trellis > 0) {
uint8_t buf[64];
adpcm_compress_trellis(avctx, &samples_p[ch][1], buf, status,
64, 1);
for (i = 0; i < 64; i++)
put_bits(&pb, 4, buf[i ^ 1]);
} else {
for (i = 0; i < 64; i += 2) {
int t1, t2;
t1 = adpcm_ima_qt_compress_sample(status, samples_p[ch][i ]);
t2 = adpcm_ima_qt_compress_sample(status, samples_p[ch][i + 1]);
put_bits(&pb, 4, t2);
put_bits(&pb, 4, t1);
}
}
}
flush_put_bits(&pb);
break;
}
case AV_CODEC_ID_ADPCM_SWF:
{
PutBitContext pb;
init_put_bits(&pb, dst, pkt_size * 8);
n = frame->nb_samples - 1;
// store AdpcmCodeSize
put_bits(&pb, 2, 2); // set 4-bit flash adpcm format
// init the encoder state
for (i = 0; i < avctx->channels; i++) {
// clip step so it fits 6 bits
c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63);
put_sbits(&pb, 16, samples[i]);
put_bits(&pb, 6, c->status[i].step_index);
c->status[i].prev_sample = samples[i];
}
if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error);
adpcm_compress_trellis(avctx, samples + avctx->channels, buf,
&c->status[0], n, avctx->channels);
if (avctx->channels == 2)
adpcm_compress_trellis(avctx, samples + avctx->channels + 1,
buf + n, &c->status[1], n,
avctx->channels);
for (i = 0; i < n; i++) {
put_bits(&pb, 4, buf[i]);
if (avctx->channels == 2)
put_bits(&pb, 4, buf[n + i]);
}
av_free(buf);
} else {
for (i = 1; i < frame->nb_samples; i++) {
put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0],
samples[avctx->channels * i]));
if (avctx->channels == 2)
put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1],
samples[2 * i + 1]));
}
}
flush_put_bits(&pb);
break;
}
case AV_CODEC_ID_ADPCM_MS:
for (i = 0; i < avctx->channels; i++) {
int predictor = 0;
*dst++ = predictor;
c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor];
c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor];
}
for (i = 0; i < avctx->channels; i++) {
if (c->status[i].idelta < 16)
c->status[i].idelta = 16;
bytestream_put_le16(&dst, c->status[i].idelta);
}
for (i = 0; i < avctx->channels; i++)
c->status[i].sample2= *samples++;
for (i = 0; i < avctx->channels; i++) {
c->status[i].sample1 = *samples++;
bytestream_put_le16(&dst, c->status[i].sample1);
}
for (i = 0; i < avctx->channels; i++)
bytestream_put_le16(&dst, c->status[i].sample2);
if (avctx->trellis > 0) {
n = avctx->block_align - 7 * avctx->channels;
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error);
if (avctx->channels == 1) {
adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
avctx->channels);
for (i = 0; i < n; i += 2)
*dst++ = (buf[i] << 4) | buf[i + 1];
} else {
adpcm_compress_trellis(avctx, samples, buf,
&c->status[0], n, avctx->channels);
adpcm_compress_trellis(avctx, samples + 1, buf + n,
&c->status[1], n, avctx->channels);
for (i = 0; i < n; i++)
*dst++ = (buf[i] << 4) | buf[n + i];
}
av_free(buf);
} else {
for (i = 7 * avctx->channels; i < avctx->block_align; i++) {
int nibble;
nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4;
nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++);
*dst++ = nibble;
}
}
break;
case AV_CODEC_ID_ADPCM_YAMAHA:
n = frame->nb_samples / 2;
if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 2, error);
n *= 2;
if (avctx->channels == 1) {
adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
avctx->channels);
for (i = 0; i < n; i += 2)
*dst++ = buf[i] | (buf[i + 1] << 4);
} else {
adpcm_compress_trellis(avctx, samples, buf,
&c->status[0], n, avctx->channels);
adpcm_compress_trellis(avctx, samples + 1, buf + n,
&c->status[1], n, avctx->channels);
for (i = 0; i < n; i++)
*dst++ = buf[i] | (buf[n + i] << 4);
}
av_free(buf);
} else
for (n *= avctx->channels; n > 0; n--) {
int nibble;
nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
*dst++ = nibble;
}
break;
default:
return AVERROR(EINVAL);
}
avpkt->size = pkt_size;
*got_packet_ptr = 1;
return 0;
error:
return AVERROR(ENOMEM);
}
| 15,283 |
qemu | 632314c49ce20ee9c974f07544d9125fbbbfbe1b | 1 | static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,
TranslationBlock *tb,
int search_pc)
{
struct DisasContext ctx, *dc = &ctx;
uint16_t *gen_opc_end;
uint32_t pc_start;
int j, k;
uint32_t next_page_start;
int num_insns;
int max_insns;
qemu_log_try_set_file(stderr);
pc_start = tb->pc;
dc->tb = tb;
gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
dc->is_jmp = DISAS_NEXT;
dc->ppc = pc_start;
dc->pc = pc_start;
dc->flags = cpu->env.cpucfgr;
dc->mem_idx = cpu_mmu_index(&cpu->env);
dc->synced_flags = dc->tb_flags = tb->flags;
dc->delayed_branch = !!(dc->tb_flags & D_FLAG);
dc->singlestep_enabled = cpu->env.singlestep_enabled;
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
qemu_log("-----------------------------------------\n");
log_cpu_state(&cpu->env, 0);
}
next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
k = -1;
num_insns = 0;
max_insns = tb->cflags & CF_COUNT_MASK;
if (max_insns == 0) {
max_insns = CF_COUNT_MASK;
}
gen_icount_start();
do {
check_breakpoint(cpu, dc);
if (search_pc) {
j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
if (k < j) {
k++;
while (k < j) {
tcg_ctx.gen_opc_instr_start[k++] = 0;
}
}
tcg_ctx.gen_opc_pc[k] = dc->pc;
tcg_ctx.gen_opc_instr_start[k] = 1;
tcg_ctx.gen_opc_icount[k] = num_insns;
}
if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
tcg_gen_debug_insn_start(dc->pc);
}
if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {
gen_io_start();
}
dc->ppc = dc->pc - 4;
dc->npc = dc->pc + 4;
tcg_gen_movi_tl(cpu_ppc, dc->ppc);
tcg_gen_movi_tl(cpu_npc, dc->npc);
disas_openrisc_insn(dc, cpu);
dc->pc = dc->npc;
num_insns++;
/* delay slot */
if (dc->delayed_branch) {
dc->delayed_branch--;
if (!dc->delayed_branch) {
dc->tb_flags &= ~D_FLAG;
gen_sync_flags(dc);
tcg_gen_mov_tl(cpu_pc, jmp_pc);
tcg_gen_mov_tl(cpu_npc, jmp_pc);
tcg_gen_movi_tl(jmp_pc, 0);
tcg_gen_exit_tb(0);
dc->is_jmp = DISAS_JUMP;
break;
}
}
} while (!dc->is_jmp
&& tcg_ctx.gen_opc_ptr < gen_opc_end
&& !cpu->env.singlestep_enabled
&& !singlestep
&& (dc->pc < next_page_start)
&& num_insns < max_insns);
if (tb->cflags & CF_LAST_IO) {
gen_io_end();
}
if (dc->is_jmp == DISAS_NEXT) {
dc->is_jmp = DISAS_UPDATE;
tcg_gen_movi_tl(cpu_pc, dc->pc);
}
if (unlikely(cpu->env.singlestep_enabled)) {
if (dc->is_jmp == DISAS_NEXT) {
tcg_gen_movi_tl(cpu_pc, dc->pc);
}
gen_exception(dc, EXCP_DEBUG);
} else {
switch (dc->is_jmp) {
case DISAS_NEXT:
gen_goto_tb(dc, 0, dc->pc);
break;
default:
case DISAS_JUMP:
break;
case DISAS_UPDATE:
/* indicate that the hash table must be used
to find the next TB */
tcg_gen_exit_tb(0);
break;
case DISAS_TB_JUMP:
/* nothing more to generate */
break;
}
}
gen_icount_end(tb, num_insns);
*tcg_ctx.gen_opc_ptr = INDEX_op_end;
if (search_pc) {
j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
k++;
while (k <= j) {
tcg_ctx.gen_opc_instr_start[k++] = 0;
}
} else {
tb->size = dc->pc - pc_start;
tb->icount = num_insns;
}
#ifdef DEBUG_DISAS
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
qemu_log("\n");
log_target_disas(&cpu->env, pc_start, dc->pc - pc_start, 0);
qemu_log("\nisize=%d osize=%td\n",
dc->pc - pc_start, tcg_ctx.gen_opc_ptr -
tcg_ctx.gen_opc_buf);
}
#endif
}
| 15,284 |
FFmpeg | 803e82276b3716bf6012ec69e8854dae14a4fd2b | 1 | static int ism_write_header(AVFormatContext *s)
{
SmoothStreamingContext *c = s->priv_data;
int ret = 0, i;
AVOutputFormat *oformat;
mkdir(s->filename, 0777);
oformat = av_guess_format("ismv", NULL, NULL);
if (!oformat) {
ret = AVERROR_MUXER_NOT_FOUND;
goto fail;
}
c->streams = av_mallocz(sizeof(*c->streams) * s->nb_streams);
if (!c->streams) {
ret = AVERROR(ENOMEM);
goto fail;
}
for (i = 0; i < s->nb_streams; i++) {
OutputStream *os = &c->streams[i];
AVFormatContext *ctx;
AVStream *st;
AVDictionary *opts = NULL;
char buf[10];
if (!s->streams[i]->codec->bit_rate) {
av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
ret = AVERROR(EINVAL);
goto fail;
}
snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codec->bit_rate);
mkdir(os->dirname, 0777);
ctx = avformat_alloc_context();
if (!ctx) {
ret = AVERROR(ENOMEM);
goto fail;
}
os->ctx = ctx;
ctx->oformat = oformat;
ctx->interrupt_callback = s->interrupt_callback;
if (!(st = avformat_new_stream(ctx, NULL))) {
ret = AVERROR(ENOMEM);
goto fail;
}
avcodec_copy_context(st->codec, s->streams[i]->codec);
st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek);
if (!ctx->pb) {
ret = AVERROR(ENOMEM);
goto fail;
}
snprintf(buf, sizeof(buf), "%d", c->lookahead_count);
av_dict_set(&opts, "ism_lookahead", buf, 0);
av_dict_set(&opts, "movflags", "frag_custom", 0);
if ((ret = avformat_write_header(ctx, &opts)) < 0) {
goto fail;
}
os->ctx_inited = 1;
avio_flush(ctx->pb);
av_dict_free(&opts);
s->streams[i]->time_base = st->time_base;
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
c->has_video = 1;
os->stream_type_tag = "video";
if (st->codec->codec_id == AV_CODEC_ID_H264) {
os->fourcc = "H264";
} else if (st->codec->codec_id == AV_CODEC_ID_VC1) {
os->fourcc = "WVC1";
} else {
av_log(s, AV_LOG_ERROR, "Unsupported video codec\n");
ret = AVERROR(EINVAL);
goto fail;
}
} else {
c->has_audio = 1;
os->stream_type_tag = "audio";
if (st->codec->codec_id == AV_CODEC_ID_AAC) {
os->fourcc = "AACL";
os->audio_tag = 0xff;
} else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) {
os->fourcc = "WMAP";
os->audio_tag = 0x0162;
} else {
av_log(s, AV_LOG_ERROR, "Unsupported audio codec\n");
ret = AVERROR(EINVAL);
goto fail;
}
os->packet_size = st->codec->block_align ? st->codec->block_align : 4;
}
get_private_data(os);
}
if (!c->has_video && c->min_frag_duration <= 0) {
av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration set\n");
ret = AVERROR(EINVAL);
}
ret = write_manifest(s, 0);
fail:
if (ret)
ism_free(s);
return ret;
}
| 15,285 |
FFmpeg | 2d66fc543b01995d6146fc132a778d3e722ca665 | 1 | static void gradfun_filter_line_mmxext(uint8_t *dst, uint8_t *src, uint16_t *dc,
int width, int thresh,
const uint16_t *dithers)
{
intptr_t x;
if (width & 3) {
x = width & ~3;
ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
width = x;
}
x = -width;
__asm__ volatile(
"movd %4, %%mm5 \n"
"pxor %%mm7, %%mm7 \n"
"pshufw $0, %%mm5, %%mm5 \n"
"movq %6, %%mm6 \n"
"movq %5, %%mm4 \n"
"1: \n"
"movd (%2,%0), %%mm0 \n"
"movd (%3,%0), %%mm1 \n"
"punpcklbw %%mm7, %%mm0 \n"
"punpcklwd %%mm1, %%mm1 \n"
"psllw $7, %%mm0 \n"
"pxor %%mm2, %%mm2 \n"
"psubw %%mm0, %%mm1 \n" // delta = dc - pix
"psubw %%mm1, %%mm2 \n"
"pmaxsw %%mm1, %%mm2 \n"
"pmulhuw %%mm5, %%mm2 \n" // m = abs(delta) * thresh >> 16
"psubw %%mm6, %%mm2 \n"
"pminsw %%mm7, %%mm2 \n" // m = -max(0, 127-m)
"pmullw %%mm2, %%mm2 \n"
"paddw %%mm4, %%mm0 \n" // pix += dither
"pmulhw %%mm2, %%mm1 \n"
"psllw $2, %%mm1 \n" // m = m*m*delta >> 14
"paddw %%mm1, %%mm0 \n" // pix += m
"psraw $7, %%mm0 \n"
"packuswb %%mm0, %%mm0 \n"
"movd %%mm0, (%1,%0) \n" // dst = clip(pix>>7)
"add $4, %0 \n"
"jl 1b \n"
"emms \n"
:"+r"(x)
:"r"(dst+width), "r"(src+width), "r"(dc+width/2),
"rm"(thresh), "m"(*dithers), "m"(*pw_7f)
:"memory"
);
}
| 15,286 |
qemu | 18775ff32697ab6e1fd47989673bf1de54d0d942 | 1 | static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *opts)
{
bdrv_refresh_filename(bs->backing->bs);
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
bs->backing->bs->filename);
| 15,287 |
qemu | 40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4 | 1 | static CharDriverState *qemu_chr_open_file_out(QemuOpts *opts)
{
int fd_out;
TFR(fd_out = open(qemu_opt_get(opts, "path"),
O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666));
if (fd_out < 0)
return NULL;
return qemu_chr_open_fd(-1, fd_out);
}
| 15,289 |
FFmpeg | 220b24c7c97dc033ceab1510549f66d0e7b52ef1 | 1 | static SchroBuffer *find_next_parse_unit(SchroParseUnitContext *parse_ctx)
{
SchroBuffer *enc_buf = NULL;
int next_pu_offset = 0;
unsigned char *in_buf;
if (parse_ctx->buf_size < 13 ||
parse_ctx->buf[0] != 'B' ||
parse_ctx->buf[1] != 'B' ||
parse_ctx->buf[2] != 'C' ||
parse_ctx->buf[3] != 'D')
return NULL;
next_pu_offset = (parse_ctx->buf[5] << 24) +
(parse_ctx->buf[6] << 16) +
(parse_ctx->buf[7] << 8) +
parse_ctx->buf[8];
if (next_pu_offset == 0 &&
SCHRO_PARSE_CODE_IS_END_OF_SEQUENCE(parse_ctx->buf[4]))
next_pu_offset = 13;
if (next_pu_offset <= 0 || parse_ctx->buf_size < next_pu_offset)
return NULL;
in_buf = av_malloc(next_pu_offset);
if (!in_buf) {
av_log(parse_ctx, AV_LOG_ERROR, "Unable to allocate input buffer\n");
return NULL;
}
memcpy(in_buf, parse_ctx->buf, next_pu_offset);
enc_buf = schro_buffer_new_with_data(in_buf, next_pu_offset);
enc_buf->free = libschroedinger_decode_buffer_free;
enc_buf->priv = in_buf;
parse_ctx->buf += next_pu_offset;
parse_ctx->buf_size -= next_pu_offset;
return enc_buf;
}
| 15,291 |
FFmpeg | 0ecca7a49f8e254c12a3a1de048d738bfbb614c6 | 1 | static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
int i, mb_x, mb_y;
uint16_t buffer[2048][4];
int left[3], top[3], topleft[3];
const int linesize= s->linesize[0];
const int mask= (1<<s->bits)-1;
for(i=0; i<3; i++){
buffer[0][i]= 1 << (s->bits + point_transform - 1);
}
for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
const int modified_predictor= mb_y ? predictor : 1;
uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
if (s->interlaced && s->bottom_field)
ptr += linesize >> 1;
for(i=0; i<3; i++){
top[i]= left[i]= topleft[i]= buffer[0][i];
}
for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
if (s->restart_interval && !s->restart_count)
s->restart_count = s->restart_interval;
for(i=0;i<3;i++) {
int pred;
topleft[i]= top[i];
top[i]= buffer[mb_x][i];
PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
left[i]=
buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));
}
if (s->restart_interval && !--s->restart_count) {
align_get_bits(&s->gb);
skip_bits(&s->gb, 16); /* skip RSTn */
}
}
if(s->rct){
for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);
ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
}
}else if(s->pegasus_rct){
for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);
ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
}
}else{
for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
ptr[4*mb_x+0] = buffer[mb_x][0];
ptr[4*mb_x+1] = buffer[mb_x][1];
ptr[4*mb_x+2] = buffer[mb_x][2];
}
}
}
return 0;
}
| 15,292 |
FFmpeg | e72f3d10f64f5c65a67aa21dcc79a85ee55e912e | 0 | static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, DCTELEM *block,
int n, int qscale, int *overflow)
{
const uint8_t *scantable= ctx->intra_scantable.scantable;
const int *qmat = ctx->q_intra_matrix[qscale];
int last_non_zero = 0;
ctx->dsp.fdct(block);
// Divide by 4 with rounding, to compensate scaling of DCT coefficients
block[0] = (block[0] + 2) >> 2;
for (int i = 1; i < 64; ++i) {
int j = scantable[i];
int sign = block[j] >> 31;
int level = (block[j] ^ sign) - sign;
level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT;
block[j] = (level ^ sign) - sign;
if (level)
last_non_zero = i;
}
return last_non_zero;
}
| 15,293 |
FFmpeg | 5b4da8a38a5ed211df9504c85ce401c30af86b97 | 0 | static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,
int16_t (*mv_table)[2], int ref_index, int f_code)
{
MotionEstContext * const c= &s->me;
int mx = 0, my = 0, dmin = 0;
int P[10][2];
const int shift= 1+s->quarter_sample;
const int mot_stride = s->mb_stride;
const int mot_xy = mb_y*mot_stride + mb_x;
uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;
int mv_scale;
c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);
c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);
c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);
c->current_mv_penalty= mv_penalty;
get_limits(s, 16*mb_x, 16*mb_y);
if (s->motion_est != FF_ME_ZERO) {
P_LEFT[0] = mv_table[mot_xy - 1][0];
P_LEFT[1] = mv_table[mot_xy - 1][1];
if (P_LEFT[0] > (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift);
/* special case for first line */
if (!s->first_slice_line) {
P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];
P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];
if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift);
if (P_TOPRIGHT[0] < (c->xmin << shift)) P_TOPRIGHT[0] = (c->xmin << shift);
if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift);
P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
}
c->pred_x = P_LEFT[0];
c->pred_y = P_LEFT[1];
if(mv_table == s->b_forw_mv_table){
mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);
}else{
mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);
}
dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);
}
dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);
// s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
mv_table[mot_xy][0]= mx;
mv_table[mot_xy][1]= my;
return dmin;
}
| 15,294 |
FFmpeg | d6604b29ef544793479d7fb4e05ef6622bb3e534 | 0 | static av_cold int XAVS_close(AVCodecContext *avctx)
{
XavsContext *x4 = avctx->priv_data;
av_freep(&avctx->extradata);
av_free(x4->sei);
av_freep(&x4->pts_buffer);
if (x4->enc)
xavs_encoder_close(x4->enc);
av_frame_free(&avctx->coded_frame);
return 0;
}
| 15,295 |
qemu | 7e30e6a6746b417c7e0dbc9af009560fbb63f336 | 1 | int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed)
{
int ret = 0;
VHDXHeader *hdr;
VHDXLogSequence logs = { 0 };
hdr = s->headers[s->curr_header];
*flushed = false;
/* s->log.hdr is freed in vhdx_close() */
if (s->log.hdr == NULL) {
s->log.hdr = qemu_blockalign(bs, sizeof(VHDXLogEntryHeader));
}
s->log.offset = hdr->log_offset;
s->log.length = hdr->log_length;
if (s->log.offset < VHDX_LOG_MIN_SIZE ||
s->log.offset % VHDX_LOG_MIN_SIZE) {
ret = -EINVAL;
goto exit;
}
/* per spec, only log version of 0 is supported */
if (hdr->log_version != 0) {
ret = -EINVAL;
goto exit;
}
/* If either the log guid, or log length is zero,
* then a replay log is not present */
if (guid_eq(hdr->log_guid, zero_guid)) {
goto exit;
}
if (hdr->log_length == 0) {
goto exit;
}
if (hdr->log_length % VHDX_LOG_MIN_SIZE) {
ret = -EINVAL;
goto exit;
}
/* The log is present, we need to find if and where there is an active
* sequence of valid entries present in the log. */
ret = vhdx_log_search(bs, s, &logs);
if (ret < 0) {
goto exit;
}
if (logs.valid) {
/* now flush the log */
ret = vhdx_log_flush(bs, s, &logs);
if (ret < 0) {
goto exit;
}
*flushed = true;
}
exit:
return ret;
}
| 15,297 |
qemu | d4c64800bbe1332328695a551b84ae68590c90fd | 1 | QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
QCryptoCipherMode mode,
const uint8_t *key, size_t nkey,
Error **errp)
{
QCryptoCipher *cipher;
QCryptoCipherNettle *ctx;
uint8_t *rfbkey;
switch (mode) {
case QCRYPTO_CIPHER_MODE_ECB:
case QCRYPTO_CIPHER_MODE_CBC:
case QCRYPTO_CIPHER_MODE_XTS:
case QCRYPTO_CIPHER_MODE_CTR:
break;
default:
error_setg(errp, "Unsupported cipher mode %s",
QCryptoCipherMode_lookup[mode]);
return NULL;
}
if (!qcrypto_cipher_validate_key_length(alg, mode, nkey, errp)) {
return NULL;
}
cipher = g_new0(QCryptoCipher, 1);
cipher->alg = alg;
cipher->mode = mode;
ctx = g_new0(QCryptoCipherNettle, 1);
switch (alg) {
case QCRYPTO_CIPHER_ALG_DES_RFB:
ctx->ctx = g_new0(struct des_ctx, 1);
rfbkey = qcrypto_cipher_munge_des_rfb_key(key, nkey);
des_set_key(ctx->ctx, rfbkey);
g_free(rfbkey);
ctx->alg_encrypt_native = des_encrypt_native;
ctx->alg_decrypt_native = des_decrypt_native;
ctx->alg_encrypt_wrapper = des_encrypt_wrapper;
ctx->alg_decrypt_wrapper = des_decrypt_wrapper;
ctx->blocksize = DES_BLOCK_SIZE;
break;
case QCRYPTO_CIPHER_ALG_AES_128:
case QCRYPTO_CIPHER_ALG_AES_192:
case QCRYPTO_CIPHER_ALG_AES_256:
ctx->ctx = g_new0(QCryptoNettleAES, 1);
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
ctx->ctx_tweak = g_new0(QCryptoNettleAES, 1);
nkey /= 2;
aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx)->enc,
nkey, key);
aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx)->dec,
nkey, key);
aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx_tweak)->enc,
nkey, key + nkey);
aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx_tweak)->dec,
nkey, key + nkey);
} else {
aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx)->enc,
nkey, key);
aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx)->dec,
nkey, key);
}
ctx->alg_encrypt_native = aes_encrypt_native;
ctx->alg_decrypt_native = aes_decrypt_native;
ctx->alg_encrypt_wrapper = aes_encrypt_wrapper;
ctx->alg_decrypt_wrapper = aes_decrypt_wrapper;
ctx->blocksize = AES_BLOCK_SIZE;
break;
case QCRYPTO_CIPHER_ALG_CAST5_128:
ctx->ctx = g_new0(struct cast128_ctx, 1);
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
ctx->ctx_tweak = g_new0(struct cast128_ctx, 1);
nkey /= 2;
cast5_set_key(ctx->ctx, nkey, key);
cast5_set_key(ctx->ctx_tweak, nkey, key + nkey);
} else {
cast5_set_key(ctx->ctx, nkey, key);
}
ctx->alg_encrypt_native = cast128_encrypt_native;
ctx->alg_decrypt_native = cast128_decrypt_native;
ctx->alg_encrypt_wrapper = cast128_encrypt_wrapper;
ctx->alg_decrypt_wrapper = cast128_decrypt_wrapper;
ctx->blocksize = CAST128_BLOCK_SIZE;
break;
case QCRYPTO_CIPHER_ALG_SERPENT_128:
case QCRYPTO_CIPHER_ALG_SERPENT_192:
case QCRYPTO_CIPHER_ALG_SERPENT_256:
ctx->ctx = g_new0(struct serpent_ctx, 1);
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
ctx->ctx_tweak = g_new0(struct serpent_ctx, 1);
nkey /= 2;
serpent_set_key(ctx->ctx, nkey, key);
serpent_set_key(ctx->ctx_tweak, nkey, key + nkey);
} else {
serpent_set_key(ctx->ctx, nkey, key);
}
ctx->alg_encrypt_native = serpent_encrypt_native;
ctx->alg_decrypt_native = serpent_decrypt_native;
ctx->alg_encrypt_wrapper = serpent_encrypt_wrapper;
ctx->alg_decrypt_wrapper = serpent_decrypt_wrapper;
ctx->blocksize = SERPENT_BLOCK_SIZE;
break;
case QCRYPTO_CIPHER_ALG_TWOFISH_128:
case QCRYPTO_CIPHER_ALG_TWOFISH_192:
case QCRYPTO_CIPHER_ALG_TWOFISH_256:
ctx->ctx = g_new0(struct twofish_ctx, 1);
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
ctx->ctx_tweak = g_new0(struct twofish_ctx, 1);
nkey /= 2;
twofish_set_key(ctx->ctx, nkey, key);
twofish_set_key(ctx->ctx_tweak, nkey, key + nkey);
} else {
twofish_set_key(ctx->ctx, nkey, key);
}
ctx->alg_encrypt_native = twofish_encrypt_native;
ctx->alg_decrypt_native = twofish_decrypt_native;
ctx->alg_encrypt_wrapper = twofish_encrypt_wrapper;
ctx->alg_decrypt_wrapper = twofish_decrypt_wrapper;
ctx->blocksize = TWOFISH_BLOCK_SIZE;
break;
default:
error_setg(errp, "Unsupported cipher algorithm %s",
QCryptoCipherAlgorithm_lookup[alg]);
goto error;
}
if (mode == QCRYPTO_CIPHER_MODE_XTS &&
ctx->blocksize != XTS_BLOCK_SIZE) {
error_setg(errp, "Cipher block size %zu must equal XTS block size %d",
ctx->blocksize, XTS_BLOCK_SIZE);
goto error;
}
ctx->iv = g_new0(uint8_t, ctx->blocksize);
cipher->opaque = ctx;
return cipher;
error:
g_free(cipher);
g_free(ctx);
return NULL;
}
| 15,298 |
FFmpeg | da048c6d24729d3bab6ccb0ac340ea129e3e88d5 | 1 | static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track)
{
int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "minf");
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
mov_write_vmhd_tag(pb);
else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
mov_write_smhd_tag(pb);
else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (track->tag == MKTAG('t','e','x','t') || is_clcp_track(track)) {
mov_write_gmhd_tag(pb, track);
} else {
mov_write_nmhd_tag(pb);
}
} else if (track->tag == MKTAG('r','t','p',' ')) {
mov_write_hmhd_tag(pb);
} else if (track->tag == MKTAG('t','m','c','d')) {
mov_write_gmhd_tag(pb, track);
}
if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
mov_write_hdlr_tag(pb, NULL);
mov_write_dinf_tag(pb);
mov_write_stbl_tag(pb, track);
return update_size(pb, pos);
}
| 15,299 |
FFmpeg | 76167140a91c081a0cf9d0abcaa4da18d1bacadb | 1 | static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
{
const AVPixFmtDescriptor *desc;
mfxSession session = NULL;
int iopattern = 0;
mfxVideoParam param = { { 0 } };
int frame_width = avctx->coded_width;
int frame_height = avctx->coded_height;
int ret;
desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
if (!desc)
return AVERROR_BUG;
if (!q->async_fifo) {
q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
(sizeof(mfxSyncPoint*) + sizeof(QSVFrame*)));
if (!q->async_fifo)
return AVERROR(ENOMEM);
}
if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
AVQSVContext *user_ctx = avctx->hwaccel_context;
session = user_ctx->session;
iopattern = user_ctx->iopattern;
q->ext_buffers = user_ctx->ext_buffers;
q->nb_ext_buffers = user_ctx->nb_ext_buffers;
}
if (avctx->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
if (!iopattern) {
if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
}
frame_width = frames_hwctx->surfaces[0].Info.Width;
frame_height = frames_hwctx->surfaces[0].Info.Height;
}
if (!iopattern)
iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
q->iopattern = iopattern;
ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
return ret;
}
ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
if (ret < 0)
return ret;
param.mfx.CodecId = ret;
param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id, avctx->profile);
param.mfx.CodecLevel = avctx->level == FF_LEVEL_UNKNOWN ? MFX_LEVEL_UNKNOWN : avctx->level;
param.mfx.FrameInfo.BitDepthLuma = desc->comp[0].depth;
param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
param.mfx.FrameInfo.Shift = desc->comp[0].depth > 8;
param.mfx.FrameInfo.FourCC = q->fourcc;
param.mfx.FrameInfo.Width = frame_width;
param.mfx.FrameInfo.Height = frame_height;
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
switch (avctx->field_order) {
case AV_FIELD_PROGRESSIVE:
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
break;
case AV_FIELD_TT:
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
break;
case AV_FIELD_BB:
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
break;
default:
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
break;
}
param.IOPattern = q->iopattern;
param.AsyncDepth = q->async_depth;
param.ExtParam = q->ext_buffers;
param.NumExtParam = q->nb_ext_buffers;
ret = MFXVideoDECODE_Init(q->session, ¶m);
if (ret < 0)
return ff_qsv_print_error(avctx, ret,
"Error initializing the MFX video decoder");
q->frame_info = param.mfx.FrameInfo;
return 0;
}
| 15,300 |
FFmpeg | f707a5ebba734597b1ff0810931b55b630077ab3 | 1 | static void ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
const uint8_t *table)
{
int i;
int j;
int out = 0;
int c;
int t;
/* first line contain absolute values, other lines contain deltas */
while (out < width){
c = ir2_get_code(&ctx->gb);
if(c > 0x80) { /* we have a run */
c -= 0x80;
for (i = 0; i < c * 2; i++)
dst[out++] = 0x80;
} else { /* copy two values from table */
dst[out++] = table[c * 2];
dst[out++] = table[(c * 2) + 1];
}
}
dst += stride;
for (j = 1; j < height; j++){
out = 0;
while (out < width){
c = ir2_get_code(&ctx->gb);
if(c > 0x80) { /* we have a skip */
c -= 0x80;
for (i = 0; i < c * 2; i++) {
dst[out] = dst[out - stride];
out++;
}
} else { /* add two deltas from table */
t = dst[out - stride] + (table[c * 2] - 128);
CLAMP_TO_BYTE(t);
dst[out] = t;
out++;
t = dst[out - stride] + (table[(c * 2) + 1] - 128);
CLAMP_TO_BYTE(t);
dst[out] = t;
out++;
}
}
dst += stride;
}
}
| 15,302 |
qemu | 062ba099e01ff1474be98c0a4f3da351efab5d9d | 1 | int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu)
{
if (cap_has_mp_state) {
struct kvm_mp_state mp_state = {
.mp_state =
cpu->powered_off ? KVM_MP_STATE_STOPPED : KVM_MP_STATE_RUNNABLE
};
int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state);
if (ret) {
fprintf(stderr, "%s: failed to set MP_STATE %d/%s\n",
__func__, ret, strerror(-ret));
return -1;
}
}
return 0;
}
| 15,303 |
qemu | 344dc16fae0cb6a011aa5befffc8e7d520b11d5d | 1 | void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx,
bool assign, bool set_handler)
{
if (assign && set_handler) {
aio_set_event_notifier(ctx, &vq->host_notifier, true,
virtio_queue_host_notifier_read);
} else {
aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL);
}
if (!assign) {
/* Test and clear notifier before after disabling event,
* in case poll callback didn't have time to run. */
virtio_queue_host_notifier_read(&vq->host_notifier);
}
}
| 15,304 |
FFmpeg | c3f87f7545d42520921bc448b9fbd7324c574e49 | 1 | av_cold int swr_init(struct SwrContext *s){
int ret;
char l1[1024], l2[1024];
clear_context(s);
if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
return AVERROR(EINVAL);
}
if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt);
return AVERROR(EINVAL);
}
s->out.ch_count = s-> user_out_ch_count;
s-> in.ch_count = s-> user_in_ch_count;
s->used_ch_count = s->user_used_ch_count;
s-> in_ch_layout = s-> user_in_ch_layout;
s->out_ch_layout = s->user_out_ch_layout;
if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) {
av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout);
s->in_ch_layout = 0;
}
if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) {
av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout);
s->out_ch_layout = 0;
}
switch(s->engine){
#if CONFIG_LIBSOXR
case SWR_ENGINE_SOXR: s->resampler = &swri_soxr_resampler; break;
#endif
case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break;
default:
av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n");
return AVERROR(EINVAL);
}
if(!s->used_ch_count)
s->used_ch_count= s->in.ch_count;
if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
s-> in_ch_layout= 0;
}
if(!s-> in_ch_layout)
s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
if(!s->out_ch_layout)
s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
s->rematrix= s->out_ch_layout !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
s->rematrix_custom;
if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_S16P){
s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
}else if( av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
&& av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
&& !s->rematrix
&& s->engine != SWR_ENGINE_SOXR){
s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
}else if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_FLTP){
s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
}else{
av_log(s, AV_LOG_DEBUG, "Using double precision mode\n");
s->int_sample_fmt= AV_SAMPLE_FMT_DBLP;
}
}
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
&&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
&&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
&&s->int_sample_fmt != AV_SAMPLE_FMT_DBLP){
av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT/DBL is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
return AVERROR(EINVAL);
}
set_audiodata_fmt(&s-> in, s-> in_sample_fmt);
set_audiodata_fmt(&s->out, s->out_sample_fmt);
if (s->firstpts_in_samples != AV_NOPTS_VALUE) {
if (!s->async && s->min_compensation >= FLT_MAX/2)
s->async = 1;
s->firstpts =
s->outpts = s->firstpts_in_samples * s->out_sample_rate;
} else
s->firstpts = AV_NOPTS_VALUE;
if (s->async) {
if (s->min_compensation >= FLT_MAX/2)
s->min_compensation = 0.001;
if (s->async > 1.0001) {
s->max_soft_compensation = s->async / (double) s->in_sample_rate;
}
}
if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, s->kaiser_beta, s->precision, s->cheby);
if (!s->resample) {
av_log(s, AV_LOG_ERROR, "Failed to initilaize resampler\n");
return AVERROR(ENOMEM);
}
}else
s->resampler->free(&s->resample);
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
&& s->int_sample_fmt != AV_SAMPLE_FMT_S32P
&& s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
&& s->int_sample_fmt != AV_SAMPLE_FMT_DBLP
&& s->resample){
av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16/s32/flt/dbl\n");
return -1;
}
#define RSC 1 //FIXME finetune
if(!s-> in.ch_count)
s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
if(!s->used_ch_count)
s->used_ch_count= s->in.ch_count;
if(!s->out.ch_count)
s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
if(!s-> in.ch_count){
av_assert0(!s->in_ch_layout);
av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
return -1;
}
av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout);
av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) {
av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count);
return AVERROR(EINVAL);
}
if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) {
av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count);
return AVERROR(EINVAL);
}
if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
"but there is not enough information to do it\n", l1, l2);
return -1;
}
av_assert0(s->used_ch_count);
av_assert0(s->out.ch_count);
s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
s->in_buffer= s->in;
s->silence = s->in;
s->drop_temp= s->out;
if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
return 0;
}
s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt,
s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0);
s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
s->int_sample_fmt, s->out.ch_count, NULL, 0);
if (!s->in_convert || !s->out_convert)
return AVERROR(ENOMEM);
s->postin= s->in;
s->preout= s->out;
s->midbuf= s->in;
if(s->channel_map){
s->postin.ch_count=
s->midbuf.ch_count= s->used_ch_count;
if(s->resample)
s->in_buffer.ch_count= s->used_ch_count;
}
if(!s->resample_first){
s->midbuf.ch_count= s->out.ch_count;
if(s->resample)
s->in_buffer.ch_count = s->out.ch_count;
}
set_audiodata_fmt(&s->postin, s->int_sample_fmt);
set_audiodata_fmt(&s->midbuf, s->int_sample_fmt);
set_audiodata_fmt(&s->preout, s->int_sample_fmt);
if(s->resample){
set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
}
if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
return ret;
if(s->rematrix || s->dither.method)
return swri_rematrix_init(s);
return 0;
}
| 15,305 |
FFmpeg | a52f443714b5c2a40ed272d8445f4c39220a4b69 | 1 | static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num)
{
MpegEncContext *s = &v->s;
int mb_cbp = v->cbp[s->mb_x - s->mb_stride],
block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
mb_is_intra = v->is_intra[s->mb_x - s->mb_stride],
block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
uint8_t *dst;
if (block_num > 3) {
dst = s->dest[block_num - 3];
} else {
dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
}
if (s->mb_y != s->end_mb_y || block_num < 2) {
int16_t (*mv)[2];
int mv_stride;
if (block_num > 3) {
bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4);
bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4);
mv = &v->luma_mv[s->mb_x - s->mb_stride];
mv_stride = s->mb_stride;
} else {
bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
: (v->cbp[s->mb_x] >> ((block_num - 2) * 4));
bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
: (v->is_intra[s->mb_x] >> ((block_num - 2) * 4));
mv_stride = s->b8_stride;
mv = &s->current_picture.motion_val[0][s->block_index[block_num] - 2 * mv_stride];
}
if (bottom_is_intra & 1 || block_is_intra & 1 ||
mv[0][0] != mv[mv_stride][0] || mv[0][1] != mv[mv_stride][1]) {
v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
} else {
idx = ((bottom_cbp >> 2) | block_cbp) & 3;
if (idx == 3) {
v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
} else if (idx) {
if (idx == 1)
v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
else
v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
}
}
}
dst -= 4 * linesize;
ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xF;
if (ttblk == TT_4X4 || ttblk == TT_8X4) {
idx = (block_cbp | (block_cbp >> 2)) & 3;
if (idx == 3) {
v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
} else if (idx) {
if (idx == 1)
v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
else
v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
}
}
}
| 15,306 |
FFmpeg | 0c33ceda91dd646414a2e0ec832bada5acb6b762 | 0 | int main(void)
{
int x = 0;
int i, j;
AVLFG state;
av_lfg_init(&state, 0xdeadbeef);
for (j = 0; j < 10000; j++) {
START_TIMER
for (i = 0; i < 624; i++) {
//av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
x += av_lfg_get(&state);
}
STOP_TIMER("624 calls of av_lfg_get");
}
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
/* BMG usage example */
{
double mean = 1000;
double stddev = 53;
av_lfg_init(&state, 42);
for (i = 0; i < 1000; i += 2) {
double bmg_out[2];
av_bmg_get(&state, bmg_out);
av_log(NULL, AV_LOG_INFO,
"%f\n%f\n",
bmg_out[0] * stddev + mean,
bmg_out[1] * stddev + mean);
}
}
return 0;
}
| 15,307 |
FFmpeg | fb7a2bf6956173eda6f9caceef8599fa4f83500d | 0 | enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
{
while (tags->id != 0) {
if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
&& toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
&& toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
&& toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
return tags->id;
tags++;
}
return CODEC_ID_NONE;
}
| 15,308 |
FFmpeg | 1acd7d594c15aa491729c837ad3519d3469e620a | 0 | static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const int16_t *_block,
ptrdiff_t stride)
{
int i;
pixel *pix = (pixel*)_pix;
const dctcoef *block = (const dctcoef*)_block;
stride >>= sizeof(pixel)-1;
pix -= stride;
for(i=0; i<4; i++){
pixel v = pix[0];
pix[1*stride]= v += block[0];
pix[2*stride]= v += block[4];
pix[3*stride]= v += block[8];
pix[4*stride]= v + block[12];
pix++;
block++;
}
}
| 15,309 |
qemu | 523a59f596a3e62f5a28eb171adba35e71310040 | 1 | static void pci_bridge_cleanup_alias(MemoryRegion *alias,
MemoryRegion *parent_space)
{
memory_region_del_subregion(parent_space, alias);
memory_region_destroy(alias);
}
| 15,310 |
FFmpeg | 4776c61424fa32394e251e9769e1ad2c2fa55598 | 1 | static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
{
const AVHWAccel *hwaccel = avctx->hwaccel;
int override_dimensions = 1;
int ret;
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
if ((ret = av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
return AVERROR(EINVAL);
}
if (frame->width <= 0 || frame->height <= 0) {
frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
override_dimensions = 0;
}
if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
return AVERROR(EINVAL);
}
}
ret = ff_decode_frame_props(avctx, frame);
return ret;
if (hwaccel) {
if (hwaccel->alloc_frame) {
ret = hwaccel->alloc_frame(avctx, frame);
goto end;
}
} else
avctx->sw_pix_fmt = avctx->pix_fmt;
ret = avctx->get_buffer2(avctx, frame, flags);
if (ret >= 0)
validate_avframe_allocation(avctx, frame);
end:
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
!(avctx->codec->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)) {
frame->width = avctx->width;
frame->height = avctx->height;
}
return ret;
} | 15,313 |
qemu | 3a8f2a9ce51036ab2d25bcc31114b5cbb72ab44b | 1 | void pcie_host_mmcfg_init(PCIExpressHost *e, uint32_t size)
{
assert(!(size & (size - 1))); /* power of 2 */
assert(size >= PCIE_MMCFG_SIZE_MIN);
assert(size <= PCIE_MMCFG_SIZE_MAX);
e->size = size;
memory_region_init_io(&e->mmio, OBJECT(e), &pcie_mmcfg_ops, e,
"pcie-mmcfg", e->size);
}
| 15,314 |
qemu | 4e47e39ab0ded72c0af174131ecf49d588d66c12 | 1 | static void update_sse_status(CPUX86State *env)
{
int rnd_type;
/* set rounding mode */
switch (env->mxcsr & SSE_RC_MASK) {
default:
case SSE_RC_NEAR:
rnd_type = float_round_nearest_even;
break;
case SSE_RC_DOWN:
rnd_type = float_round_down;
break;
case SSE_RC_UP:
rnd_type = float_round_up;
break;
case SSE_RC_CHOP:
rnd_type = float_round_to_zero;
break;
}
set_float_rounding_mode(rnd_type, &env->sse_status);
/* set denormals are zero */
set_flush_inputs_to_zero((env->mxcsr & SSE_DAZ) ? 1 : 0, &env->sse_status);
/* set flush to zero */
set_flush_to_zero((env->mxcsr & SSE_FZ) ? 1 : 0, &env->fp_status);
}
| 15,315 |
FFmpeg | b39f872a41b92a31589052c8f914c5b52f206fd0 | 1 | static int adts_aac_probe(AVProbeData *p)
{
int max_frames = 0, first_frames = 0;
int fsize, frames;
uint8_t *buf0 = p->buf;
uint8_t *buf2;
uint8_t *buf;
uint8_t *end = buf0 + p->buf_size - 7;
buf = buf0;
for(; buf < end; buf= buf2+1) {
buf2 = buf;
for(frames = 0; buf2 < end; frames++) {
uint32_t header = AV_RB16(buf2);
if((header&0xFFF6) != 0xFFF0)
break;
fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF;
if(fsize < 7)
break;
buf2 += fsize;
}
max_frames = FFMAX(max_frames, frames);
if(buf == buf0)
first_frames= frames;
}
if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
else if(max_frames>=1) return 1;
else return 0;
} | 15,316 |
qemu | f69a8bde29354493ff8aea64cc9cb3b531d16337 | 1 | static int qio_channel_websock_handshake_read(QIOChannelWebsock *ioc,
Error **errp)
{
char *handshake_end;
ssize_t ret;
/* Typical HTTP headers from novnc are 512 bytes, so limiting
* total header size to 4096 is easily enough. */
size_t want = 4096 - ioc->encinput.offset;
buffer_reserve(&ioc->encinput, want);
ret = qio_channel_read(ioc->master,
(char *)buffer_end(&ioc->encinput), want, errp);
if (ret < 0) {
return -1;
}
ioc->encinput.offset += ret;
handshake_end = g_strstr_len((char *)ioc->encinput.buffer,
ioc->encinput.offset,
QIO_CHANNEL_WEBSOCK_HANDSHAKE_END);
if (!handshake_end) {
if (ioc->encinput.offset >= 4096) {
error_setg(errp,
"End of headers not found in first 4096 bytes");
return -1;
} else {
return 0;
}
}
*handshake_end = '\0';
if (qio_channel_websock_handshake_process(ioc,
(char *)ioc->encinput.buffer,
errp) < 0) {
return -1;
}
buffer_advance(&ioc->encinput,
handshake_end - (char *)ioc->encinput.buffer +
strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END));
return 1;
}
| 15,317 |
FFmpeg | 95891804bf300b266aa5328f1c338c046720e658 | 1 | static int decode_init_mp3on4(AVCodecContext * avctx)
{
MP3On4DecodeContext *s = avctx->priv_data;
MPEG4AudioConfig cfg;
int i;
if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
return -1;
}
avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size);
if (!cfg.chan_config || cfg.chan_config > 7) {
av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
return -1;
}
s->frames = mp3Frames[cfg.chan_config];
s->coff = chan_offset[cfg.chan_config];
avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
avctx->channel_layout = chan_layout[cfg.chan_config];
if (cfg.sample_rate < 16000)
s->syncword = 0xffe00000;
else
s->syncword = 0xfff00000;
/* Init the first mp3 decoder in standard way, so that all tables get builded
* We replace avctx->priv_data with the context of the first decoder so that
* decode_init() does not have to be changed.
* Other decoders will be initialized here copying data from the first context
*/
// Allocate zeroed memory for the first decoder context
s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
// Put decoder context in place to make init_decode() happy
avctx->priv_data = s->mp3decctx[0];
decode_init(avctx);
// Restore mp3on4 context pointer
avctx->priv_data = s;
s->mp3decctx[0]->adu_mode = 1; // Set adu mode
/* Create a separate codec/context for each frame (first is already ok).
* Each frame is 1 or 2 channels - up to 5 frames allowed
*/
for (i = 1; i < s->frames; i++) {
s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
if (!s->mp3decctx[i])
s->mp3decctx[i]->adu_mode = 1;
s->mp3decctx[i]->avctx = avctx;
s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
}
/* Allocate buffer for multi-channel output if needed */
if (s->frames > 1) {
s->decoded_buf = av_malloc(MPA_FRAME_SIZE * MPA_MAX_CHANNELS *
sizeof(*s->decoded_buf));
if (!s->decoded_buf)
}
return 0;
alloc_fail:
decode_close_mp3on4(avctx);
return AVERROR(ENOMEM);
} | 15,318 |
FFmpeg | 5e53486545726987ab4482321d4dcf7e23e7652f | 0 | void avdevice_register_all(void)
{
static int inited;
if (inited)
return;
inited = 1;
/* devices */
REGISTER_MUXDEMUX (AUDIO_BEOS, audio_beos);
REGISTER_DEMUXER (BKTR, bktr);
REGISTER_DEMUXER (DV1394, dv1394);
REGISTER_MUXDEMUX (OSS, oss);
REGISTER_DEMUXER (V4L2, v4l2);
REGISTER_DEMUXER (V4L, v4l);
REGISTER_DEMUXER (X11_GRAB_DEVICE, x11_grab_device);
/* external libraries */
REGISTER_DEMUXER (LIBDC1394, libdc1394);
}
| 15,320 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.