id
int32 0
27.3k
| func
stringlengths 26
142k
| target
bool 2
classes | project
stringclasses 2
values | commit_id
stringlengths 40
40
|
---|---|---|---|---|
24,369 | void ff_init_elbg(int *points, int dim, int numpoints, int *codebook,
int numCB, int max_steps, int *closest_cb,
AVLFG *rand_state)
{
int i, k;
if (numpoints > 24*numCB) {
/* ELBG is very costly for a big number of points. So if we have a lot
of them, get a good initial codebook to save on iterations */
int *temp_points = av_malloc(dim*(numpoints/8)*sizeof(int));
for (i=0; i<numpoints/8; i++) {
k = (i*BIG_PRIME) % numpoints;
memcpy(temp_points + i*dim, points + k*dim, dim*sizeof(int));
}
ff_init_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);
ff_do_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);
av_free(temp_points);
} else // If not, initialize the codebook with random positions
for (i=0; i < numCB; i++)
memcpy(codebook + i*dim, points + ((i*BIG_PRIME)%numpoints)*dim,
dim*sizeof(int));
}
| false | FFmpeg | ae2d41ec875965ce4ab9fdd88a5e8ba57cada67a |
24,370 | av_cold void ff_lpc_init_x86(LPCContext *c)
{
#if HAVE_SSE2_INLINE
int cpu_flags = av_get_cpu_flags();
if (INLINE_SSE2(cpu_flags) && (cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
c->lpc_apply_welch_window = lpc_apply_welch_window_sse2;
c->lpc_compute_autocorr = lpc_compute_autocorr_sse2;
}
#endif /* HAVE_SSE2_INLINE */
}
| false | FFmpeg | 7fb758cd8ed08e4a37f10e25003953d13c68b8cd |
24,372 | int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
size= RAW_SAMPLES*s->streams[0]->codec->block_align;
if (size <= 0)
return AVERROR(EINVAL);
ret= av_get_packet(s->pb, pkt, size);
pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
if (ret < 0)
return ret;
return ret;
}
| false | FFmpeg | 4d09bc98974d4602d71e71520535457a53d44222 |
24,373 | static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
MpegEncContext * const s = &h->s;
int mba_xy, mbb_xy;
int ctx = 0;
if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches?
int mb_xy = mb_x + (mb_y&~1)*s->mb_stride;
mba_xy = mb_xy - 1;
if( (mb_y&1)
&& h->slice_table[mba_xy] == h->slice_num
&& MB_FIELD == !!IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) )
mba_xy += s->mb_stride;
if( MB_FIELD ){
mbb_xy = mb_xy - s->mb_stride;
if( !(mb_y&1)
&& h->slice_table[mbb_xy] == h->slice_num
&& IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) )
mbb_xy -= s->mb_stride;
}else
mbb_xy = mb_x + (mb_y-1)*s->mb_stride;
}else{
int mb_xy = mb_x + mb_y*s->mb_stride;
mba_xy = mb_xy - 1;
mbb_xy = mb_xy - s->mb_stride;
}
if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ))
ctx++;
if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ))
ctx++;
if( h->slice_type == B_TYPE )
ctx += 13;
return get_cabac( &h->cabac, &h->cabac_state[11+ctx] );
}
| false | FFmpeg | 851ded8918c977d8160c6617b69604f758cabf50 |
24,374 | static int handle_packets(AVFormatContext *s, int nb_packets)
{
MpegTSContext *ts = s->priv_data;
ByteIOContext *pb = &s->pb;
uint8_t packet[TS_FEC_PACKET_SIZE];
int packet_num, len;
ts->stop_parse = 0;
packet_num = 0;
for(;;) {
if (ts->stop_parse)
break;
packet_num++;
if (nb_packets != 0 && packet_num >= nb_packets)
break;
len = get_buffer(pb, packet, ts->raw_packet_size);
if (len != ts->raw_packet_size)
return AVERROR_IO;
/* check paquet sync byte */
/* XXX: accept to resync ? */
if (packet[0] != 0x47)
return AVERROR_INVALIDDATA;
handle_packet(s, packet);
}
return 0;
}
| false | FFmpeg | ec23a47286a9be0ca67b78f4d8b9d87220c18286 |
24,376 | QTestState *qtest_init(const char *extra_args)
{
QTestState *s;
int sock, qmpsock, i;
gchar *socket_path;
gchar *qmp_socket_path;
gchar *command;
const char *qemu_binary;
struct sigaction sigact;
qemu_binary = getenv("QTEST_QEMU_BINARY");
g_assert(qemu_binary != NULL);
s = g_malloc(sizeof(*s));
socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
sock = init_socket(socket_path);
qmpsock = init_socket(qmp_socket_path);
/* Catch SIGABRT to clean up on g_assert() failure */
sigact = (struct sigaction){
.sa_handler = sigabrt_handler,
.sa_flags = SA_RESETHAND,
};
sigemptyset(&sigact.sa_mask);
sigaction(SIGABRT, &sigact, &s->sigact_old);
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
command = g_strdup_printf("exec %s "
"-qtest unix:%s,nowait "
"-qtest-log /dev/null "
"-qmp unix:%s,nowait "
"-machine accel=qtest "
"-display none "
"%s", qemu_binary, socket_path,
qmp_socket_path,
extra_args ?: "");
execlp("/bin/sh", "sh", "-c", command, NULL);
exit(1);
}
s->fd = socket_accept(sock);
s->qmp_fd = socket_accept(qmpsock);
unlink(socket_path);
unlink(qmp_socket_path);
g_free(socket_path);
g_free(qmp_socket_path);
s->rx = g_string_new("");
for (i = 0; i < MAX_IRQ; i++) {
s->irq_level[i] = false;
}
/* Read the QMP greeting and then do the handshake */
qtest_qmp_discard_response(s, "");
qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
if (getenv("QTEST_STOP")) {
kill(s->qemu_pid, SIGSTOP);
}
return s;
}
| true | qemu | f8762027a33e2f5d0915c56a904962b1481f75c1 |
24,377 | static void qxl_init_ramsize(PCIQXLDevice *qxl)
{
/* vga mode framebuffer / primary surface (bar 0, first part) */
if (qxl->vgamem_size_mb < 8) {
qxl->vgamem_size_mb = 8;
qxl->vgamem_size = qxl->vgamem_size_mb * 1024 * 1024;
/* vga ram (bar 0, total) */
if (qxl->ram_size_mb != -1) {
qxl->vga.vram_size = qxl->ram_size_mb * 1024 * 1024;
if (qxl->vga.vram_size < qxl->vgamem_size * 2) {
qxl->vga.vram_size = qxl->vgamem_size * 2;
/* vram32 (surfaces, 32bit, bar 1) */
if (qxl->vram32_size_mb != -1) {
qxl->vram32_size = qxl->vram32_size_mb * 1024 * 1024;
if (qxl->vram32_size < 4096) {
qxl->vram32_size = 4096;
/* vram (surfaces, 64bit, bar 4+5) */
if (qxl->vram_size_mb != -1) {
qxl->vram_size = qxl->vram_size_mb * 1024 * 1024;
if (qxl->vram_size < qxl->vram32_size) {
qxl->vram_size = qxl->vram32_size;
if (qxl->revision == 1) {
qxl->vram32_size = 4096;
qxl->vram_size = 4096;
qxl->vgamem_size = msb_mask(qxl->vgamem_size * 2 - 1);
qxl->vga.vram_size = msb_mask(qxl->vga.vram_size * 2 - 1);
qxl->vram32_size = msb_mask(qxl->vram32_size * 2 - 1);
qxl->vram_size = msb_mask(qxl->vram_size * 2 - 1);
| true | qemu | 876d516311c1538a7d29f2abec48b7cda0645eea |
24,378 | static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,
int layno, uint8_t *expn, int numgbits)
{
int bandno, cblkny, cblknx, cblkno, ret;
if (!(ret = get_bits(s, 1))){
j2k_flush(s);
return 0;
} else if (ret < 0)
return ret;
for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno;
J2kPrec *prec = band->prec + precno;
int pos = 0;
if (band->coord[0][0] == band->coord[0][1]
|| band->coord[1][0] == band->coord[1][1])
continue;
for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)
for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){
J2kCblk *cblk = band->cblk + cblkno;
int incl, newpasses, llen;
if (cblk->npasses)
incl = get_bits(s, 1);
else
incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno;
if (!incl)
continue;
else if (incl < 0)
return incl;
if (!cblk->npasses)
cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100);
if ((newpasses = getnpasses(s)) < 0)
return newpasses;
if ((llen = getlblockinc(s)) < 0)
return llen;
cblk->lblock += llen;
if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)
return ret;
cblk->lengthinc = ret;
cblk->npasses += newpasses;
}
}
j2k_flush(s);
if (codsty->csty & J2K_CSTY_EPH) {
if (AV_RB16(s->buf) == J2K_EPH) {
s->buf += 2;
} else {
av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");
}
}
for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno;
int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
int xi;
for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){
J2kCblk *cblk = band->cblk + yi * cblknw + xi;
if (s->buf_end - s->buf < cblk->lengthinc)
return AVERROR(EINVAL);
bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
cblk->length += cblk->lengthinc;
cblk->lengthinc = 0;
}
}
}
return 0;
}
| true | FFmpeg | ddfa3751c092feaf1e080f66587024689dfe603c |
24,380 | static SoftFloat sbr_sum_square_c(int (*x)[2], int n)
{
SoftFloat ret;
uint64_t accu = 0, round;
int i, nz;
unsigned u;
for (i = 0; i < n; i += 2) {
// Larger values are inavlid and could cause overflows of accu.
av_assert2(FFABS(x[i + 0][0]) >> 29 == 0);
accu += (int64_t)x[i + 0][0] * x[i + 0][0];
av_assert2(FFABS(x[i + 0][1]) >> 29 == 0);
accu += (int64_t)x[i + 0][1] * x[i + 0][1];
av_assert2(FFABS(x[i + 1][0]) >> 29 == 0);
accu += (int64_t)x[i + 1][0] * x[i + 1][0];
av_assert2(FFABS(x[i + 1][1]) >> 29 == 0);
accu += (int64_t)x[i + 1][1] * x[i + 1][1];
}
u = accu >> 32;
if (u == 0) {
nz = 1;
} else {
nz = -1;
while (u < 0x80000000U) {
u <<= 1;
nz++;
}
nz = 32 - nz;
}
round = 1ULL << (nz-1);
u = ((accu + round) >> nz);
u >>= 1;
ret = av_int2sf(u, 15 - nz);
return ret;
}
| true | FFmpeg | b315a3cf42a15358ab38279723f3c93406a66f6a |
24,381 | int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t end_addr)
{
return kvm_dirty_pages_log_change(phys_addr, end_addr,
0,
KVM_MEM_LOG_DIRTY_PAGES);
}
| true | qemu | d3f8d37fe2d0c24ec8bac9c94d5b0e2dc09c0d2a |
24,382 | int qemu_strtoll(const char *nptr, const char **endptr, int base,
int64_t *result)
{
char *p;
int err = 0;
if (!nptr) {
if (endptr) {
*endptr = nptr;
}
err = -EINVAL;
} else {
errno = 0;
*result = strtoll(nptr, &p, base);
err = check_strtox_error(endptr, p, errno);
}
return err;
}
| true | qemu | 47d4be12c3997343e436c6cca89aefbbbeb70863 |
24,383 | static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
SOFAlizerContext *s = ctx->priv;
ThreadData *td = arg;
AVFrame *in = td->in, *out = td->out;
int offset = jobnr;
int *write = &td->write[jobnr];
const int *const delay = td->delay[jobnr];
const float *const ir = td->ir[jobnr];
int *n_clippings = &td->n_clippings[jobnr];
float *ringbuffer = td->ringbuffer[jobnr];
float *temp_src = td->temp_src[jobnr];
const int n_samples = s->sofa.n_samples; /* length of one IR */
const float *src = (const float *)in->data[0]; /* get pointer to audio input buffer */
float *dst = (float *)out->data[0]; /* get pointer to audio output buffer */
const int in_channels = s->n_conv; /* number of input channels */
/* ring buffer length is: longest IR plus max. delay -> next power of 2 */
const int buffer_length = s->buffer_length;
/* -1 for AND instead of MODULO (applied to powers of 2): */
const uint32_t modulo = (uint32_t)buffer_length - 1;
float *buffer[16]; /* holds ringbuffer for each input channel */
int wr = *write;
int read;
int i, l;
dst += offset;
for (l = 0; l < in_channels; l++) {
/* get starting address of ringbuffer for each input channel */
buffer[l] = ringbuffer + l * buffer_length;
}
for (i = 0; i < in->nb_samples; i++) {
const float *temp_ir = ir; /* using same set of IRs for each sample */
*dst = 0;
for (l = 0; l < in_channels; l++) {
/* write current input sample to ringbuffer (for each channel) */
*(buffer[l] + wr) = src[l];
}
/* loop goes through all channels to be convolved */
for (l = 0; l < in_channels; l++) {
const float *const bptr = buffer[l];
if (l == s->lfe_channel) {
/* LFE is an input channel but requires no convolution */
/* apply gain to LFE signal and add to output buffer */
*dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
temp_ir += n_samples;
continue;
}
/* current read position in ringbuffer: input sample write position
* - delay for l-th ch. + diff. betw. IR length and buffer length
* (mod buffer length) */
read = (wr - *(delay + l) - (n_samples - 1) + buffer_length) & modulo;
if (read + n_samples < buffer_length) {
memcpy(temp_src, bptr + read, n_samples * sizeof(*temp_src));
} else {
int len = FFMIN(n_samples - (read % n_samples), buffer_length - read);
memcpy(temp_src, bptr + read, len * sizeof(*temp_src));
memcpy(temp_src + len, bptr, (n_samples - len) * sizeof(*temp_src));
}
/* multiply signal and IR, and add up the results */
dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, n_samples);
temp_ir += n_samples;
}
/* clippings counter */
if (fabs(*dst) > 1)
*n_clippings += 1;
/* move output buffer pointer by +2 to get to next sample of processed channel: */
dst += 2;
src += in_channels;
wr = (wr + 1) & modulo; /* update ringbuffer write position */
}
*write = wr; /* remember write position in ringbuffer for next call */
return 0;
}
| true | FFmpeg | 21234c835d2d003d390d462b6e1b2622e7b02c39 |
24,385 | int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
{
char *param, buffer[128], tmp[128];
int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0;
SrtStack stack[16];
int closing_brace_missing = 0;
stack[0].tag[0] = 0;
strcpy(stack[0].param[PARAM_SIZE], "{\\fs}");
strcpy(stack[0].param[PARAM_COLOR], "{\\c}");
strcpy(stack[0].param[PARAM_FACE], "{\\fn}");
for (; !end && *in; in++) {
switch (*in) {
case '\r':
break;
case '\n':
if (line_start) {
end = 1;
break;
}
rstrip_spaces_buf(dst);
av_bprintf(dst, "\\N");
line_start = 1;
break;
case ' ':
if (!line_start)
av_bprint_chars(dst, *in, 1);
break;
case '{':
handle_open_brace(dst, &in, &an, &closing_brace_missing);
break;
case '<':
tag_close = in[1] == '/';
len = 0;
if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) {
const char *tagname = buffer;
while (*tagname == ' ')
tagname++;
if ((param = strchr(tagname, ' ')))
*param++ = 0;
if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
( tag_close && sptr > 0 && !av_strcasecmp(stack[sptr-1].tag, tagname))) {
int i, j, unknown = 0;
in += len + tag_close;
if (!tag_close)
memset(stack+sptr, 0, sizeof(*stack));
if (!av_strcasecmp(tagname, "font")) {
if (tag_close) {
for (i=PARAM_NUMBER-1; i>=0; i--)
if (stack[sptr-1].param[i][0])
for (j=sptr-2; j>=0; j--)
if (stack[j].param[i][0]) {
av_bprintf(dst, "%s", stack[j].param[i]);
break;
}
} else {
while (param) {
if (!av_strncasecmp(param, "size=", 5)) {
unsigned font_size;
param += 5 + (param[5] == '"');
if (sscanf(param, "%u", &font_size) == 1) {
snprintf(stack[sptr].param[PARAM_SIZE],
sizeof(stack[0].param[PARAM_SIZE]),
"{\\fs%u}", font_size);
}
} else if (!av_strncasecmp(param, "color=", 6)) {
param += 6 + (param[6] == '"');
snprintf(stack[sptr].param[PARAM_COLOR],
sizeof(stack[0].param[PARAM_COLOR]),
"{\\c&H%X&}",
html_color_parse(log_ctx, param));
} else if (!av_strncasecmp(param, "face=", 5)) {
param += 5 + (param[5] == '"');
len = strcspn(param,
param[-1] == '"' ? "\"" :" ");
av_strlcpy(tmp, param,
FFMIN(sizeof(tmp), len+1));
param += len;
snprintf(stack[sptr].param[PARAM_FACE],
sizeof(stack[0].param[PARAM_FACE]),
"{\\fn%s}", tmp);
}
if ((param = strchr(param, ' ')))
param++;
}
for (i=0; i<PARAM_NUMBER; i++)
if (stack[sptr].param[i][0])
av_bprintf(dst, "%s", stack[sptr].param[i]);
}
} else if (tagname[0] && !tagname[1] && av_stristr("bisu", tagname)) {
av_bprintf(dst, "{\\%c%d}", (char)av_tolower(tagname[0]), !tag_close);
} else if (!av_strcasecmp(tagname, "br")) {
av_bprintf(dst, "\\N");
} else {
unknown = 1;
snprintf(tmp, sizeof(tmp), "</%s>", tagname);
}
if (tag_close) {
sptr--;
} else if (unknown && !strstr(in, tmp)) {
in -= len + tag_close;
av_bprint_chars(dst, *in, 1);
} else
av_strlcpy(stack[sptr++].tag, tagname,
sizeof(stack[0].tag));
break;
}
}
default:
av_bprint_chars(dst, *in, 1);
break;
}
if (*in != ' ' && *in != '\r' && *in != '\n')
line_start = 0;
}
if (!av_bprint_is_complete(dst))
return AVERROR(ENOMEM);
while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2))
dst->len -= 2;
dst->str[dst->len] = 0;
rstrip_spaces_buf(dst);
return 0;
}
| true | FFmpeg | c61715e2c505c15a5cfc9eab18b4311a6504055a |
24,386 | void qemu_mutex_destroy(QemuMutex *mutex)
{
assert(mutex->owner == 0);
DeleteCriticalSection(&mutex->lock);
}
| true | qemu | 12f8def0e02232d7c6416ad9b66640f973c531d1 |
24,387 | static int usb_host_handle_iso_data(USBHostDevice *s, USBPacket *p, int in)
{
AsyncURB *aurb;
int i, j, ret, max_packet_size, offset, len = 0;
max_packet_size = get_max_packet_size(s, p->devep);
if (max_packet_size == 0)
return USB_RET_NAK;
aurb = get_iso_urb(s, p->devep);
if (!aurb) {
aurb = usb_host_alloc_iso(s, p->devep, in);
}
i = get_iso_urb_idx(s, p->devep);
j = aurb[i].iso_frame_idx;
if (j >= 0 && j < ISO_FRAME_DESC_PER_URB) {
if (in) {
/* Check urb status */
if (aurb[i].urb.status) {
len = urb_status_to_usb_ret(aurb[i].urb.status);
/* Move to the next urb */
aurb[i].iso_frame_idx = ISO_FRAME_DESC_PER_URB - 1;
/* Check frame status */
} else if (aurb[i].urb.iso_frame_desc[j].status) {
len = urb_status_to_usb_ret(
aurb[i].urb.iso_frame_desc[j].status);
/* Check the frame fits */
} else if (aurb[i].urb.iso_frame_desc[j].actual_length > p->len) {
printf("husb: received iso data is larger then packet\n");
len = USB_RET_NAK;
/* All good copy data over */
} else {
len = aurb[i].urb.iso_frame_desc[j].actual_length;
memcpy(p->data,
aurb[i].urb.buffer +
j * aurb[i].urb.iso_frame_desc[0].length,
len);
}
} else {
len = p->len;
offset = (j == 0) ? 0 : get_iso_buffer_used(s, p->devep);
/* Check the frame fits */
if (len > max_packet_size) {
printf("husb: send iso data is larger then max packet size\n");
return USB_RET_NAK;
}
/* All good copy data over */
memcpy(aurb[i].urb.buffer + offset, p->data, len);
aurb[i].urb.iso_frame_desc[j].length = len;
offset += len;
set_iso_buffer_used(s, p->devep, offset);
/* Start the stream once we have buffered enough data */
if (!is_iso_started(s, p->devep) && i == 1 && j == 8) {
set_iso_started(s, p->devep);
}
}
aurb[i].iso_frame_idx++;
if (aurb[i].iso_frame_idx == ISO_FRAME_DESC_PER_URB) {
i = (i + 1) % s->iso_urb_count;
set_iso_urb_idx(s, p->devep, i);
}
} else {
if (in) {
set_iso_started(s, p->devep);
} else {
DPRINTF("hubs: iso out error no free buffer, dropping packet\n");
}
}
if (is_iso_started(s, p->devep)) {
/* (Re)-submit all fully consumed / filled urbs */
for (i = 0; i < s->iso_urb_count; i++) {
if (aurb[i].iso_frame_idx == ISO_FRAME_DESC_PER_URB) {
ret = ioctl(s->fd, USBDEVFS_SUBMITURB, &aurb[i]);
if (ret < 0) {
printf("husb error submitting iso urb %d: %d\n", i, errno);
if (!in || len == 0) {
switch(errno) {
case ETIMEDOUT:
len = USB_RET_NAK;
break;
case EPIPE:
default:
len = USB_RET_STALL;
}
}
break;
}
aurb[i].iso_frame_idx = -1;
change_iso_inflight(s, p->devep, +1);
}
}
}
return len;
}
| true | qemu | 4f4321c11ff6e98583846bfd6f0e81954924b003 |
24,388 | static void pcie_pci_bridge_realize(PCIDevice *d, Error **errp)
{
PCIBridge *br = PCI_BRIDGE(d);
PCIEPCIBridge *pcie_br = PCIE_PCI_BRIDGE_DEV(d);
int rc, pos;
pci_bridge_initfn(d, TYPE_PCI_BUS);
d->config[PCI_INTERRUPT_PIN] = 0x1;
memory_region_init(&pcie_br->shpc_bar, OBJECT(d), "shpc-bar",
shpc_bar_size(d));
rc = shpc_init(d, &br->sec_bus, &pcie_br->shpc_bar, 0, errp);
if (rc) {
goto error;
}
rc = pcie_cap_init(d, 0, PCI_EXP_TYPE_PCI_BRIDGE, 0, errp);
if (rc < 0) {
goto cap_error;
}
pos = pci_add_capability(d, PCI_CAP_ID_PM, 0, PCI_PM_SIZEOF, errp);
if (pos < 0) {
goto pm_error;
}
d->exp.pm_cap = pos;
pci_set_word(d->config + pos + PCI_PM_PMC, 0x3);
pcie_cap_arifwd_init(d);
pcie_cap_deverr_init(d);
rc = pcie_aer_init(d, PCI_ERR_VER, 0x100, PCI_ERR_SIZEOF, errp);
if (rc < 0) {
goto aer_error;
}
if (pcie_br->msi != ON_OFF_AUTO_OFF) {
rc = msi_init(d, 0, 1, true, true, errp);
if (rc < 0) {
goto msi_error;
}
}
pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_64, &pcie_br->shpc_bar);
return;
msi_error:
pcie_aer_exit(d);
aer_error:
pm_error:
pcie_cap_exit(d);
cap_error:
shpc_free(d);
error:
pci_bridge_exitfn(d);
}
| true | qemu | d659d94013390238961fac741572306c95496bf5 |
24,389 | static int qcrypto_cipher_init_aes(QCryptoCipher *cipher,
const uint8_t *key, size_t nkey,
Error **errp)
{
QCryptoCipherBuiltin *ctxt;
if (cipher->mode != QCRYPTO_CIPHER_MODE_CBC &&
cipher->mode != QCRYPTO_CIPHER_MODE_ECB) {
error_setg(errp, "Unsupported cipher mode %d", cipher->mode);
return -1;
}
ctxt = g_new0(QCryptoCipherBuiltin, 1);
if (AES_set_encrypt_key(key, nkey * 8, &ctxt->state.aes.encrypt_key) != 0) {
error_setg(errp, "Failed to set encryption key");
goto error;
}
if (AES_set_decrypt_key(key, nkey * 8, &ctxt->state.aes.decrypt_key) != 0) {
error_setg(errp, "Failed to set decryption key");
goto error;
}
ctxt->free = qcrypto_cipher_free_aes;
ctxt->setiv = qcrypto_cipher_setiv_aes;
ctxt->encrypt = qcrypto_cipher_encrypt_aes;
ctxt->decrypt = qcrypto_cipher_decrypt_aes;
cipher->opaque = ctxt;
return 0;
error:
g_free(ctxt);
return -1;
} | true | qemu | 3a661f1eabf7e8db66e28489884d9b54aacb94ea |
24,390 | static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid)
{
MXFContext *mxf = arg;
MXFPartition *partition;
UID op;
uint64_t footer_partition;
if (mxf->partitions_count+1 >= UINT_MAX / sizeof(*mxf->partitions))
return AVERROR(ENOMEM);
mxf->partitions = av_realloc(mxf->partitions, (mxf->partitions_count + 1) * sizeof(*mxf->partitions));
if (!mxf->partitions)
return AVERROR(ENOMEM);
if (mxf->parsing_backward) {
/* insert the new partition pack in the middle
* this makes the entries in mxf->partitions sorted by offset */
memmove(&mxf->partitions[mxf->last_forward_partition+1],
&mxf->partitions[mxf->last_forward_partition],
(mxf->partitions_count - mxf->last_forward_partition)*sizeof(*mxf->partitions));
partition = mxf->current_partition = &mxf->partitions[mxf->last_forward_partition];
} else {
mxf->last_forward_partition++;
partition = mxf->current_partition = &mxf->partitions[mxf->partitions_count];
}
memset(partition, 0, sizeof(*partition));
mxf->partitions_count++;
switch(uid[13]) {
case 2:
partition->type = Header;
break;
case 3:
partition->type = BodyPartition;
break;
case 4:
partition->type = Footer;
break;
default:
av_log(mxf->fc, AV_LOG_ERROR, "unknown partition type %i\n", uid[13]);
return AVERROR_INVALIDDATA;
}
/* consider both footers to be closed (there is only Footer and CompleteFooter) */
partition->closed = partition->type == Footer || !(uid[14] & 1);
partition->complete = uid[14] > 2;
avio_skip(pb, 8);
partition->this_partition = avio_rb64(pb);
partition->previous_partition = avio_rb64(pb);
footer_partition = avio_rb64(pb);
avio_skip(pb, 16);
partition->index_sid = avio_rb32(pb);
avio_skip(pb, 8);
partition->body_sid = avio_rb32(pb);
avio_read(pb, op, sizeof(UID));
/* some files don'thave FooterPartition set in every partition */
if (footer_partition) {
if (mxf->footer_partition && mxf->footer_partition != footer_partition) {
av_log(mxf->fc, AV_LOG_ERROR, "inconsistent FooterPartition value: %li != %li\n",
mxf->footer_partition, footer_partition);
} else {
mxf->footer_partition = footer_partition;
}
}
av_dlog(mxf->fc, "PartitionPack: ThisPartition = 0x%lx, PreviousPartition = 0x%lx, "
"FooterPartition = 0x%lx, IndexSID = %i, BodySID = %i\n",
partition->this_partition,
partition->previous_partition, footer_partition,
partition->index_sid, partition->body_sid);
if (op[12] == 1 && op[13] == 1) mxf->op = OP1a;
else if (op[12] == 1 && op[13] == 2) mxf->op = OP1b;
else if (op[12] == 1 && op[13] == 3) mxf->op = OP1c;
else if (op[12] == 2 && op[13] == 1) mxf->op = OP2a;
else if (op[12] == 2 && op[13] == 2) mxf->op = OP2b;
else if (op[12] == 2 && op[13] == 3) mxf->op = OP2c;
else if (op[12] == 3 && op[13] == 1) mxf->op = OP3a;
else if (op[12] == 3 && op[13] == 2) mxf->op = OP3b;
else if (op[12] == 3 && op[13] == 3) mxf->op = OP3c;
else if (op[12] == 0x10) mxf->op = OPAtom;
else
av_log(mxf->fc, AV_LOG_ERROR, "unknown operational pattern: %02xh %02xh\n", op[12], op[13]);
return 0;
}
| true | FFmpeg | fd34dbea58e097609ff09cf7dcc59f74930195d3 |
24,391 | static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, int stride2, int w, int h){
int x,y;
uint64_t ssd=0;
//printf("%d %d\n", w, h);
for(y=0; y<h; y++){
for(x=0; x<w; x++){
int d= src1[x + y*stride1] - src2[x + y*stride2];
ssd+= d*d;
//printf("%d", abs(src1[x + y*stride1] - src2[x + y*stride2])/26 );
}
//printf("\n");
}
return ssd;
}
| true | FFmpeg | 221b804f3491638ecf2eec1302c669ad2d9ec799 |
24,393 | static inline void test_server_connect(TestServer *server)
{
test_server_create_chr(server, ",reconnect=1");
}
| true | qemu | 20784087eb875e22cf0021989e61716304b63c84 |
24,394 | static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_stream_id)
{
MpegMuxContext *s = ctx->priv_data;
int size, i, private_stream_coded, id;
PutBitContext pb;
init_put_bits(&pb, buf, 128);
put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
put_bits(&pb, 16, 0);
put_bits(&pb, 1, 1);
put_bits(&pb, 22, s->mux_rate); /* maximum bit rate of the multiplexed stream */
put_bits(&pb, 1, 1); /* marker */
if (s->is_vcd && only_for_stream_id==VIDEO_ID) {
/* This header applies only to the video stream (see VCD standard p. IV-7)*/
put_bits(&pb, 6, 0);
} else
put_bits(&pb, 6, s->audio_bound);
if (s->is_vcd) {
/* see VCD standard, p. IV-7*/
put_bits(&pb, 1, 0);
put_bits(&pb, 1, 1);
} else {
put_bits(&pb, 1, 0); /* variable bitrate*/
put_bits(&pb, 1, 0); /* non constrainted bit stream */
}
if (s->is_vcd || s->is_dvd) {
/* see VCD standard p IV-7 */
put_bits(&pb, 1, 1); /* audio locked */
put_bits(&pb, 1, 1); /* video locked */
} else {
put_bits(&pb, 1, 0); /* audio locked */
put_bits(&pb, 1, 0); /* video locked */
}
put_bits(&pb, 1, 1); /* marker */
if (s->is_vcd && only_for_stream_id==AUDIO_ID) {
/* This header applies only to the audio stream (see VCD standard p. IV-7)*/
put_bits(&pb, 5, 0);
} else
put_bits(&pb, 5, s->video_bound);
if (s->is_dvd) {
put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */
put_bits(&pb, 7, 0x7f); /* reserved byte */
} else
put_bits(&pb, 8, 0xff); /* reserved byte */
/* DVD-Video Stream_bound entries
id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1)
id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0)
id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1)
id (0xBF) private stream 2, NAV packs, set to 2x1024. */
if (s->is_dvd) {
int P_STD_max_video = 0;
int P_STD_max_mpeg_audio = 0;
int P_STD_max_mpeg_PS1 = 0;
for(i=0;i<ctx->nb_streams;i++) {
StreamInfo *stream = ctx->streams[i]->priv_data;
id = stream->id;
if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) {
P_STD_max_mpeg_PS1 = stream->max_buffer_size;
} else if (id >= 0xc0 && id <= 0xc7 && stream->max_buffer_size > P_STD_max_mpeg_audio) {
P_STD_max_mpeg_audio = stream->max_buffer_size;
} else if (id == 0xe0 && stream->max_buffer_size > P_STD_max_video) {
P_STD_max_video = stream->max_buffer_size;
}
}
/* video */
put_bits(&pb, 8, 0xb9); /* stream ID */
put_bits(&pb, 2, 3);
put_bits(&pb, 1, 1);
put_bits(&pb, 13, P_STD_max_video / 1024);
/* audio */
if (P_STD_max_mpeg_audio == 0)
P_STD_max_mpeg_audio = 4096;
put_bits(&pb, 8, 0xb8); /* stream ID */
put_bits(&pb, 2, 3);
put_bits(&pb, 1, 0);
put_bits(&pb, 13, P_STD_max_mpeg_audio / 128);
/* private stream 1 */
put_bits(&pb, 8, 0xbd); /* stream ID */
put_bits(&pb, 2, 3);
put_bits(&pb, 1, 0);
put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128);
/* private stream 2 */
put_bits(&pb, 8, 0xbf); /* stream ID */
put_bits(&pb, 2, 3);
put_bits(&pb, 1, 1);
put_bits(&pb, 13, 2);
}
else {
/* audio stream info */
private_stream_coded = 0;
for(i=0;i<ctx->nb_streams;i++) {
StreamInfo *stream = ctx->streams[i]->priv_data;
/* For VCDs, only include the stream info for the stream
that the pack which contains this system belongs to.
(see VCD standard p. IV-7) */
if ( !s->is_vcd || stream->id==only_for_stream_id
|| only_for_stream_id==0) {
id = stream->id;
if (id < 0xc0) {
/* special case for private streams (AC-3 uses that) */
if (private_stream_coded)
continue;
private_stream_coded = 1;
id = 0xbd;
}
put_bits(&pb, 8, id); /* stream ID */
put_bits(&pb, 2, 3);
if (id < 0xe0) {
/* audio */
put_bits(&pb, 1, 0);
put_bits(&pb, 13, stream->max_buffer_size / 128);
} else {
/* video */
put_bits(&pb, 1, 1);
put_bits(&pb, 13, stream->max_buffer_size / 1024);
}
}
}
}
flush_put_bits(&pb);
size = put_bits_ptr(&pb) - pb.buf;
/* patch packet size */
buf[4] = (size - 6) >> 8;
buf[5] = (size - 6) & 0xff;
return size;
}
| false | FFmpeg | 24dc7776ff4452764d0365b12d0728153f879cf8 |
24,395 | static int standard_decode_i_mbs(VC9Context *v)
{
int x, y, ac_pred, cbpcy;
/* Select ttmb table depending on pq */
if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0];
else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1];
else v->ttmb_vlc = &vc9_ttmb_vlc[2];
for (y=0; y<v->height_mb; y++)
{
for (x=0; x<v->width_mb; x++)
{
cbpcy = get_vlc2(&v->gb, vc9_cbpcy_i_vlc.table,
VC9_CBPCY_I_VLC_BITS, 2);
ac_pred = get_bits(&v->gb, 1);
//Decode blocks from that mb wrt cbpcy
}
}
return 0;
}
| false | FFmpeg | e5540b3fd30367ce3cc33b2f34a04b660dbc4b38 |
24,396 | static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
{
int dc = (block[0] + 32) >> 6;
int y;
__asm__ volatile(
"movd %0, %%mm0 \n\t"
"pshufw $0, %%mm0, %%mm0 \n\t"
"pxor %%mm1, %%mm1 \n\t"
"psubw %%mm0, %%mm1 \n\t"
"packuswb %%mm0, %%mm0 \n\t"
"packuswb %%mm1, %%mm1 \n\t"
::"r"(dc)
);
for(y=2; y--; dst += 4*stride){
__asm__ volatile(
"movq %0, %%mm2 \n\t"
"movq %1, %%mm3 \n\t"
"movq %2, %%mm4 \n\t"
"movq %3, %%mm5 \n\t"
"paddusb %%mm0, %%mm2 \n\t"
"paddusb %%mm0, %%mm3 \n\t"
"paddusb %%mm0, %%mm4 \n\t"
"paddusb %%mm0, %%mm5 \n\t"
"psubusb %%mm1, %%mm2 \n\t"
"psubusb %%mm1, %%mm3 \n\t"
"psubusb %%mm1, %%mm4 \n\t"
"psubusb %%mm1, %%mm5 \n\t"
"movq %%mm2, %0 \n\t"
"movq %%mm3, %1 \n\t"
"movq %%mm4, %2 \n\t"
"movq %%mm5, %3 \n\t"
:"+m"(*(uint64_t*)(dst+0*stride)),
"+m"(*(uint64_t*)(dst+1*stride)),
"+m"(*(uint64_t*)(dst+2*stride)),
"+m"(*(uint64_t*)(dst+3*stride))
);
}
}
| false | FFmpeg | 1d16a1cf99488f16492b1bb48e023f4da8377e07 |
24,397 | static int movie_get_frame(AVFilterLink *outlink)
{
MovieContext *movie = outlink->src->priv;
AVPacket pkt;
int ret, frame_decoded;
AVStream *st = movie->format_ctx->streams[movie->stream_index];
if (movie->is_done == 1)
return 0;
while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) {
// Is this a packet from the video stream?
if (pkt.stream_index == movie->stream_index) {
avcodec_decode_video2(movie->codec_ctx, movie->frame, &frame_decoded, &pkt);
if (frame_decoded) {
/* FIXME: avoid the memcpy */
movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE |
AV_PERM_REUSE2, outlink->w, outlink->h);
av_image_copy(movie->picref->data, movie->picref->linesize,
(void*)movie->frame->data, movie->frame->linesize,
movie->picref->format, outlink->w, outlink->h);
avfilter_copy_frame_props(movie->picref, movie->frame);
/* FIXME: use a PTS correction mechanism as that in
* ffplay.c when some API will be available for that */
/* use pkt_dts if pkt_pts is not available */
movie->picref->pts = movie->frame->pkt_pts == AV_NOPTS_VALUE ?
movie->frame->pkt_dts : movie->frame->pkt_pts;
if (!movie->frame->sample_aspect_ratio.num)
movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio;
av_dlog(outlink->src,
"movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n",
movie->file_name, movie->picref->pts,
(double)movie->picref->pts * av_q2d(st->time_base),
movie->picref->pos,
movie->picref->video->sample_aspect_ratio.num,
movie->picref->video->sample_aspect_ratio.den);
// We got it. Free the packet since we are returning
av_free_packet(&pkt);
return 0;
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&pkt);
}
// On multi-frame source we should stop the mixing process when
// the movie source does not have more frames
if (ret == AVERROR_EOF)
movie->is_done = 1;
return ret;
}
| false | FFmpeg | d19d52d4a11547cc70bcbc3a2f8b83ccd24bb951 |
24,399 | static void do_io_interrupt(CPUS390XState *env)
{
S390CPU *cpu = s390_env_get_cpu(env);
LowCore *lowcore;
IOIntQueue *q;
uint8_t isc;
int disable = 1;
int found = 0;
if (!(env->psw.mask & PSW_MASK_IO)) {
cpu_abort(CPU(cpu), "I/O int w/o I/O mask\n");
}
for (isc = 0; isc < ARRAY_SIZE(env->io_index); isc++) {
uint64_t isc_bits;
if (env->io_index[isc] < 0) {
continue;
}
if (env->io_index[isc] > MAX_IO_QUEUE) {
cpu_abort(CPU(cpu), "I/O queue overrun for isc %d: %d\n",
isc, env->io_index[isc]);
}
q = &env->io_queue[env->io_index[isc]][isc];
isc_bits = ISC_TO_ISC_BITS(IO_INT_WORD_ISC(q->word));
if (!(env->cregs[6] & isc_bits)) {
disable = 0;
continue;
}
if (!found) {
uint64_t mask, addr;
found = 1;
lowcore = cpu_map_lowcore(env);
lowcore->subchannel_id = cpu_to_be16(q->id);
lowcore->subchannel_nr = cpu_to_be16(q->nr);
lowcore->io_int_parm = cpu_to_be32(q->parm);
lowcore->io_int_word = cpu_to_be32(q->word);
lowcore->io_old_psw.mask = cpu_to_be64(get_psw_mask(env));
lowcore->io_old_psw.addr = cpu_to_be64(env->psw.addr);
mask = be64_to_cpu(lowcore->io_new_psw.mask);
addr = be64_to_cpu(lowcore->io_new_psw.addr);
cpu_unmap_lowcore(lowcore);
env->io_index[isc]--;
DPRINTF("%s: %" PRIx64 " %" PRIx64 "\n", __func__,
env->psw.mask, env->psw.addr);
load_psw(env, mask, addr);
}
if (env->io_index[isc] >= 0) {
disable = 0;
}
continue;
}
if (disable) {
env->pending_int &= ~INTERRUPT_IO;
}
}
| true | qemu | 1a71992376792a0d11ea27688bd1a21cdffd1826 |
24,401 | static int rtp_new_av_stream(HTTPContext *c,
int stream_index, struct sockaddr_in *dest_addr,
HTTPContext *rtsp_c)
{
AVFormatContext *ctx;
AVStream *st;
char *ipaddr;
URLContext *h = NULL;
uint8_t *dummy_buf;
int max_packet_size;
/* now we can open the relevant output stream */
ctx = avformat_alloc_context();
if (!ctx)
return -1;
ctx->oformat = av_guess_format("rtp", NULL, NULL);
st = av_mallocz(sizeof(AVStream));
if (!st)
goto fail;
st->codec= avcodec_alloc_context();
ctx->nb_streams = 1;
ctx->streams[0] = st;
if (!c->stream->feed ||
c->stream->feed == c->stream)
memcpy(st, c->stream->streams[stream_index], sizeof(AVStream));
else
memcpy(st,
c->stream->feed->streams[c->stream->feed_streams[stream_index]],
sizeof(AVStream));
st->priv_data = NULL;
/* build destination RTP address */
ipaddr = inet_ntoa(dest_addr->sin_addr);
switch(c->rtp_protocol) {
case RTSP_LOWER_TRANSPORT_UDP:
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
/* RTP/UDP case */
/* XXX: also pass as parameter to function ? */
if (c->stream->is_multicast) {
int ttl;
ttl = c->stream->multicast_ttl;
if (!ttl)
ttl = 16;
snprintf(ctx->filename, sizeof(ctx->filename),
"rtp://%s:%d?multicast=1&ttl=%d",
ipaddr, ntohs(dest_addr->sin_port), ttl);
} else {
snprintf(ctx->filename, sizeof(ctx->filename),
"rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
}
if (url_open(&h, ctx->filename, URL_WRONLY) < 0)
goto fail;
c->rtp_handles[stream_index] = h;
max_packet_size = url_get_max_packet_size(h);
break;
case RTSP_LOWER_TRANSPORT_TCP:
/* RTP/TCP case */
c->rtsp_c = rtsp_c;
max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;
break;
default:
goto fail;
}
http_log("%s:%d - - \"PLAY %s/streamid=%d %s\"\n",
ipaddr, ntohs(dest_addr->sin_port),
c->stream->filename, stream_index, c->protocol);
/* normally, no packets should be output here, but the packet size may be checked */
if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) {
/* XXX: close stream */
goto fail;
}
av_set_parameters(ctx, NULL);
if (av_write_header(ctx) < 0) {
fail:
if (h)
url_close(h);
av_free(ctx);
return -1;
}
url_close_dyn_buf(ctx->pb, &dummy_buf);
av_free(dummy_buf);
c->rtp_ctx[stream_index] = ctx;
return 0;
}
| true | FFmpeg | 9cc9a155100d4364ad02d50e89b313ec94195102 |
24,402 | void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp)
{
unix_nonblocking_connect(path, unix_wait_for_connect, s, errp);
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 |
24,403 | static void *mptsas_load_request(QEMUFile *f, SCSIRequest *sreq)
{
SCSIBus *bus = sreq->bus;
MPTSASState *s = container_of(bus, MPTSASState, bus);
PCIDevice *pci = PCI_DEVICE(s);
MPTSASRequest *req;
int i, n;
req = g_new(MPTSASRequest, 1);
qemu_get_buffer(f, (unsigned char *)&req->scsi_io, sizeof(req->scsi_io));
n = qemu_get_be32(f);
/* TODO: add a way for SCSIBusInfo's load_request to fail,
* and fail migration instead of asserting here.
* When we do, we might be able to re-enable NDEBUG below.
*/
#ifdef NDEBUG
#error building with NDEBUG is not supported
#endif
assert(n >= 0);
pci_dma_sglist_init(&req->qsg, pci, n);
for (i = 0; i < n; i++) {
uint64_t base = qemu_get_be64(f);
uint64_t len = qemu_get_be64(f);
qemu_sglist_add(&req->qsg, base, len);
}
scsi_req_ref(sreq);
req->sreq = sreq;
req->dev = s;
return req;
}
| true | qemu | 262a69f4282e44426c7a132138581d400053e0a1 |
24,404 | static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
DVBSubContext *ctx = avctx->priv_data;
const uint8_t *buf_end = buf + buf_size;
int i, clut_id;
int version;
DVBSubCLUT *clut;
int entry_id, depth , full_range;
int y, cr, cb, alpha;
int r, g, b, r_add, g_add, b_add;
ff_dlog(avctx, "DVB clut packet:\n");
for (i=0; i < buf_size; i++) {
ff_dlog(avctx, "%02x ", buf[i]);
if (i % 16 == 15)
ff_dlog(avctx, "\n");
}
if (i % 16)
ff_dlog(avctx, "\n");
clut_id = *buf++;
version = ((*buf)>>4)&15;
buf += 1;
clut = get_clut(ctx, clut_id);
if (!clut) {
clut = av_malloc(sizeof(DVBSubCLUT));
if (!clut)
return AVERROR(ENOMEM);
memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
clut->id = clut_id;
clut->version = -1;
clut->next = ctx->clut_list;
ctx->clut_list = clut;
}
if (clut->version != version) {
clut->version = version;
while (buf + 4 < buf_end) {
entry_id = *buf++;
depth = (*buf) & 0xe0;
if (depth == 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
}
full_range = (*buf++) & 1;
if (full_range) {
y = *buf++;
cr = *buf++;
cb = *buf++;
alpha = *buf++;
} else {
y = buf[0] & 0xfc;
cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
cb = (buf[1] << 2) & 0xf0;
alpha = (buf[1] << 6) & 0xc0;
buf += 2;
}
if (y == 0)
alpha = 0xff;
YUV_TO_RGB1_CCIR(cb, cr);
YUV_TO_RGB2_CCIR(r, g, b, y);
ff_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) {
ff_dlog(avctx, "More than one bit level marked: %x\n", depth);
if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL)
return AVERROR_INVALIDDATA;
}
if (depth & 0x80)
clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
else if (depth & 0x40)
clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
else if (depth & 0x20)
clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
}
}
return 0;
}
| true | FFmpeg | 8a69f2602fea04b7ebae2db16f2581e8ff5ee0cd |
24,405 | VLANClientState *qemu_new_vlan_client(VLANState *vlan,
IOReadHandler *fd_read, void *opaque)
{
VLANClientState *vc, **pvc;
vc = qemu_mallocz(sizeof(VLANClientState));
if (!vc)
return NULL;
vc->fd_read = fd_read;
vc->opaque = opaque;
vc->vlan = vlan;
vc->next = NULL;
pvc = &vlan->first_client;
while (*pvc != NULL)
pvc = &(*pvc)->next;
*pvc = vc;
return vc;
}
| true | qemu | d861b05ea30e6ac177de9b679da96194ebe21afc |
24,406 | static void unterminated_escape(void)
{
QObject *obj = qobject_from_json("\"abc\\\"", NULL);
g_assert(obj == NULL);
}
| true | qemu | aec4b054ea36c53c8b887da99f20010133b84378 |
24,407 | struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,
hwaddr base,
qemu_irq irq, qemu_irq drq)
{
int cs;
struct omap_gpmc_s *s = (struct omap_gpmc_s *)
g_malloc0(sizeof(struct omap_gpmc_s));
memory_region_init_io(&s->iomem, NULL, &omap_gpmc_ops, s, "omap-gpmc", 0x1000);
memory_region_add_subregion(get_system_memory(), base, &s->iomem);
s->irq = irq;
s->drq = drq;
s->accept_256 = cpu_is_omap3630(mpu);
s->revision = cpu_class_omap3(mpu) ? 0x50 : 0x20;
s->lastirq = 0;
omap_gpmc_reset(s);
/* We have to register a different IO memory handler for each
* chip select region in case a NAND device is mapped there. We
* make the region the worst-case size of 256MB and rely on the
* container memory region in cs_map to chop it down to the actual
* guest-requested size.
*/
for (cs = 0; cs < 8; cs++) {
memory_region_init_io(&s->cs_file[cs].nandiomem, NULL,
&omap_nand_ops,
&s->cs_file[cs],
"omap-nand",
256 * 1024 * 1024);
}
memory_region_init_io(&s->prefetch.iomem, NULL, &omap_prefetch_ops, s,
"omap-gpmc-prefetch", 256 * 1024 * 1024);
return s;
}
| true | qemu | b45c03f585ea9bb1af76c73e82195418c294919d |
24,408 | bool trace_backend_init(const char *events, const char *file)
{
GThread *thread;
if (!g_thread_supported()) {
g_thread_init(NULL);
}
trace_available_cond = g_cond_new();
trace_empty_cond = g_cond_new();
thread = trace_thread_create(writeout_thread);
if (!thread) {
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
return false;
}
atexit(st_flush_trace_buffer);
trace_backend_init_events(events);
st_set_trace_file(file);
return true;
} | true | qemu | 42ed3727536ccf80c87942b3f04e7378fe90f107 |
24,409 | static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
int mvn, int r_x, int r_y, uint8_t* is_intra)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
int A[2], B[2], C[2];
int px, py;
int a_valid = 0, b_valid = 0, c_valid = 0;
int field_a, field_b, field_c; // 0: same, 1: opposit
int total_valid, num_samefield, num_oppfield;
int pos_c, pos_b, n_adj;
wrap = s->b8_stride;
xy = s->block_index[n];
if (s->mb_intra) {
s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = 0;
s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = 0;
s->current_picture.f.motion_val[1][xy][0] = 0;
s->current_picture.f.motion_val[1][xy][1] = 0;
if (mvn == 1) { /* duplicate motion data for 1-MV block */
s->current_picture.f.motion_val[0][xy + 1][0] = 0;
s->current_picture.f.motion_val[0][xy + 1][1] = 0;
s->current_picture.f.motion_val[0][xy + wrap][0] = 0;
s->current_picture.f.motion_val[0][xy + wrap][1] = 0;
s->current_picture.f.motion_val[0][xy + wrap + 1][0] = 0;
s->current_picture.f.motion_val[0][xy + wrap + 1][1] = 0;
v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
s->current_picture.f.motion_val[1][xy + 1][0] = 0;
s->current_picture.f.motion_val[1][xy + 1][1] = 0;
s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
s->current_picture.f.motion_val[1][xy + wrap][1] = 0;
s->current_picture.f.motion_val[1][xy + wrap + 1][0] = 0;
s->current_picture.f.motion_val[1][xy + wrap + 1][1] = 0;
}
return;
}
off = ((n == 0) || (n == 1)) ? 1 : -1;
/* predict A */
if (s->mb_x || (n == 1) || (n == 3)) {
if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
|| (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
A[0] = s->current_picture.f.motion_val[0][xy - 1][0];
A[1] = s->current_picture.f.motion_val[0][xy - 1][1];
a_valid = 1;
} else { // current block has frame mv and cand. has field MV (so average)
A[0] = (s->current_picture.f.motion_val[0][xy - 1][0]
+ s->current_picture.f.motion_val[0][xy - 1 + off * wrap][0] + 1) >> 1;
A[1] = (s->current_picture.f.motion_val[0][xy - 1][1]
+ s->current_picture.f.motion_val[0][xy - 1 + off * wrap][1] + 1) >> 1;
a_valid = 1;
}
if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
a_valid = 0;
A[0] = A[1] = 0;
}
} else
A[0] = A[1] = 0;
/* Predict B and C */
B[0] = B[1] = C[0] = C[1] = 0;
if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
if (!s->first_slice_line) {
if (!v->is_intra[s->mb_x - s->mb_stride]) {
b_valid = 1;
n_adj = n | 2;
pos_b = s->block_index[n_adj] - 2 * wrap;
if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
n_adj = (n & 2) | (n & 1);
}
B[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][0];
B[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][1];
if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
B[0] = (B[0] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
B[1] = (B[1] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
}
}
if (s->mb_width > 1) {
if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
c_valid = 1;
n_adj = 2;
pos_c = s->block_index[2] - 2 * wrap + 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n & 2;
}
C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][0];
C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
C[1] = (1 + C[1] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
}
if (s->mb_x == s->mb_width - 1) {
if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
c_valid = 1;
n_adj = 3;
pos_c = s->block_index[3] - 2 * wrap - 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n | 1;
}
C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][0];
C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
C[1] = (1 + C[1] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
}
} else
c_valid = 0;
}
}
}
}
} else {
pos_b = s->block_index[1];
b_valid = 1;
B[0] = s->current_picture.f.motion_val[0][pos_b][0];
B[1] = s->current_picture.f.motion_val[0][pos_b][1];
pos_c = s->block_index[0];
c_valid = 1;
C[0] = s->current_picture.f.motion_val[0][pos_c][0];
C[1] = s->current_picture.f.motion_val[0][pos_c][1];
}
total_valid = a_valid + b_valid + c_valid;
// check if predictor A is out of bounds
if (!s->mb_x && !(n == 1 || n == 3)) {
A[0] = A[1] = 0;
}
// check if predictor B is out of bounds
if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
B[0] = B[1] = C[0] = C[1] = 0;
}
if (!v->blk_mv_type[xy]) {
if (s->mb_width == 1) {
px = B[0];
py = B[1];
} else {
if (total_valid >= 2) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (total_valid) {
if (a_valid) { px = A[0]; py = A[1]; }
if (b_valid) { px = B[0]; py = B[1]; }
if (c_valid) { px = C[0]; py = C[1]; }
} else
px = py = 0;
}
} else {
if (a_valid)
field_a = (A[1] & 4) ? 1 : 0;
else
field_a = 0;
if (b_valid)
field_b = (B[1] & 4) ? 1 : 0;
else
field_b = 0;
if (c_valid)
field_c = (C[1] & 4) ? 1 : 0;
else
field_c = 0;
num_oppfield = field_a + field_b + field_c;
num_samefield = total_valid - num_oppfield;
if (total_valid == 3) {
if ((num_samefield == 3) || (num_oppfield == 3)) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (num_samefield >= num_oppfield) {
/* take one MV from same field set depending on priority
the check for B may not be necessary */
px = !field_a ? A[0] : B[0];
py = !field_a ? A[1] : B[1];
} else {
px = field_a ? A[0] : B[0];
py = field_a ? A[1] : B[1];
}
} else if (total_valid == 2) {
if (num_samefield >= num_oppfield) {
if (!field_a && a_valid) {
px = A[0];
py = A[1];
} else if (!field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
} else px = py = 0;
} else {
if (field_a && a_valid) {
px = A[0];
py = A[1];
} else if (field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
} else px = py = 0;
}
} else if (total_valid == 1) {
px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
} else
px = py = 0;
}
/* store MV using signed modulus of MV range defined in 4.11 */
s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
if (mvn == 1) { /* duplicate motion data for 1-MV block */
s->current_picture.f.motion_val[0][xy + 1 ][0] = s->current_picture.f.motion_val[0][xy][0];
s->current_picture.f.motion_val[0][xy + 1 ][1] = s->current_picture.f.motion_val[0][xy][1];
s->current_picture.f.motion_val[0][xy + wrap ][0] = s->current_picture.f.motion_val[0][xy][0];
s->current_picture.f.motion_val[0][xy + wrap ][1] = s->current_picture.f.motion_val[0][xy][1];
s->current_picture.f.motion_val[0][xy + wrap + 1][0] = s->current_picture.f.motion_val[0][xy][0];
s->current_picture.f.motion_val[0][xy + wrap + 1][1] = s->current_picture.f.motion_val[0][xy][1];
} else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
s->current_picture.f.motion_val[0][xy + 1][0] = s->current_picture.f.motion_val[0][xy][0];
s->current_picture.f.motion_val[0][xy + 1][1] = s->current_picture.f.motion_val[0][xy][1];
s->mv[0][n + 1][0] = s->mv[0][n][0];
s->mv[0][n + 1][1] = s->mv[0][n][1];
}
}
| true | FFmpeg | 6136b989f658fff68e2b758db583f04358d3d412 |
24,411 | ip_reass(register struct ip *ip, register struct ipq *fp)
{
register struct mbuf *m = dtom(ip);
register struct ipasfrag *q;
int hlen = ip->ip_hl << 2;
int i, next;
DEBUG_CALL("ip_reass");
DEBUG_ARG("ip = %lx", (long)ip);
DEBUG_ARG("fp = %lx", (long)fp);
DEBUG_ARG("m = %lx", (long)m);
/*
* Presence of header sizes in mbufs
* would confuse code below.
* Fragment m_data is concatenated.
*/
m->m_data += hlen;
m->m_len -= hlen;
/*
* If first fragment to arrive, create a reassembly queue.
*/
if (fp == 0) {
struct mbuf *t;
if ((t = m_get()) == NULL) goto dropfrag;
fp = mtod(t, struct ipq *);
insque(&fp->ip_link, &ipq.ip_link);
fp->ipq_ttl = IPFRAGTTL;
fp->ipq_p = ip->ip_p;
fp->ipq_id = ip->ip_id;
fp->frag_link.next = fp->frag_link.prev = &fp->frag_link;
fp->ipq_src = ip->ip_src;
fp->ipq_dst = ip->ip_dst;
q = (struct ipasfrag *)fp;
goto insert;
}
/*
* Find a segment which begins after this one does.
*/
for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link;
q = q->ipf_next)
if (q->ipf_off > ip->ip_off)
break;
/*
* If there is a preceding segment, it may provide some of
* our data already. If so, drop the data from the incoming
* segment. If it provides all of our data, drop us.
*/
if (q->ipf_prev != &fp->frag_link) {
struct ipasfrag *pq = q->ipf_prev;
i = pq->ipf_off + pq->ipf_len - ip->ip_off;
if (i > 0) {
if (i >= ip->ip_len)
goto dropfrag;
m_adj(dtom(ip), i);
ip->ip_off += i;
ip->ip_len -= i;
}
}
/*
* While we overlap succeeding segments trim them or,
* if they are completely covered, dequeue them.
*/
while (q != (struct ipasfrag*)&fp->frag_link &&
ip->ip_off + ip->ip_len > q->ipf_off) {
i = (ip->ip_off + ip->ip_len) - q->ipf_off;
if (i < q->ipf_len) {
q->ipf_len -= i;
q->ipf_off += i;
m_adj(dtom(q), i);
break;
}
q = q->ipf_next;
m_freem(dtom(q->ipf_prev));
ip_deq(q->ipf_prev);
}
insert:
/*
* Stick new segment in its place;
* check for complete reassembly.
*/
ip_enq(iptofrag(ip), q->ipf_prev);
next = 0;
for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link;
q = q->ipf_next) {
if (q->ipf_off != next)
return (0);
next += q->ipf_len;
}
if (((struct ipasfrag *)(q->ipf_prev))->ipf_tos & 1)
return (0);
/*
* Reassembly is complete; concatenate fragments.
*/
q = fp->frag_link.next;
m = dtom(q);
q = (struct ipasfrag *) q->ipf_next;
while (q != (struct ipasfrag*)&fp->frag_link) {
struct mbuf *t = dtom(q);
q = (struct ipasfrag *) q->ipf_next;
m_cat(m, t);
}
/*
* Create header for new ip packet by
* modifying header of first packet;
* dequeue and discard fragment reassembly header.
* Make header visible.
*/
q = fp->frag_link.next;
/*
* If the fragments concatenated to an mbuf that's
* bigger than the total size of the fragment, then and
* m_ext buffer was alloced. But fp->ipq_next points to
* the old buffer (in the mbuf), so we must point ip
* into the new buffer.
*/
if (m->m_flags & M_EXT) {
int delta;
delta = (char *)ip - m->m_dat;
q = (struct ipasfrag *)(m->m_ext + delta);
}
/* DEBUG_ARG("ip = %lx", (long)ip);
* ip=(struct ipasfrag *)m->m_data; */
ip = fragtoip(q);
ip->ip_len = next;
ip->ip_tos &= ~1;
ip->ip_src = fp->ipq_src;
ip->ip_dst = fp->ipq_dst;
remque(&fp->ip_link);
(void) m_free(dtom(fp));
m->m_len += (ip->ip_hl << 2);
m->m_data -= (ip->ip_hl << 2);
return ip;
dropfrag:
STAT(ipstat.ips_fragdropped++);
m_freem(m);
return (0);
}
| true | qemu | f2ba730e89b420903257e543c1bb7f7d945ba36a |
24,412 | static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t **buf)
{
int width=s->logical_width;
int i;
signed char rlecode;
/* We will use it to compute the best bulk copy sequence */
unsigned int bulkcount;
/* This will be the number of pixels equal to the preivous frame one's
* starting from the ith pixel */
unsigned int skipcount;
/* This will be the number of consecutive equal pixels in the current
* frame, starting from the ith one also */
unsigned int repeatcount;
/* The cost of the three different possibilities */
int total_bulk_cost;
int total_skip_cost;
int total_repeat_cost;
int temp_cost;
int j;
uint8_t *this_line = p-> data[0] + line*p-> linesize[0] +
(width - 1)*s->pixel_size;
uint8_t *prev_line = s->previous_frame.data[0] + line*s->previous_frame.linesize[0] +
(width - 1)*s->pixel_size;
s->length_table[width] = 0;
skipcount = 0;
for (i = width - 1; i >= 0; i--) {
if (!s->frame.key_frame && !memcmp(this_line, prev_line, s->pixel_size))
skipcount = FFMIN(skipcount + 1, MAX_RLE_SKIP);
else
skipcount = 0;
total_skip_cost = s->length_table[i + skipcount] + 2;
s->skip_table[i] = skipcount;
if (i < width - 1 && !memcmp(this_line, this_line + s->pixel_size, s->pixel_size))
repeatcount = FFMIN(repeatcount + 1, MAX_RLE_REPEAT);
else
repeatcount = 1;
total_repeat_cost = s->length_table[i + repeatcount] + 1 + s->pixel_size;
/* skip code is free for the first pixel, it costs one byte for repeat and bulk copy
* so let's make it aware */
if (i == 0) {
total_skip_cost--;
total_repeat_cost++;
}
if (repeatcount > 1 && (skipcount == 0 || total_repeat_cost < total_skip_cost)) {
/* repeat is the best */
s->length_table[i] = total_repeat_cost;
s->rlecode_table[i] = -repeatcount;
}
else if (skipcount > 0) {
/* skip is the best choice here */
s->length_table[i] = total_skip_cost;
s->rlecode_table[i] = 0;
}
else {
/* We cannot do neither skip nor repeat
* thus we search for the best bulk copy to do */
int limit = FFMIN(width - i, MAX_RLE_BULK);
temp_cost = 1 + s->pixel_size + !i;
total_bulk_cost = INT_MAX;
for (j = 1; j <= limit; j++) {
if (s->length_table[i + j] + temp_cost < total_bulk_cost) {
/* We have found a better bulk copy ... */
total_bulk_cost = s->length_table[i + j] + temp_cost;
bulkcount = j;
}
temp_cost += s->pixel_size;
}
s->length_table[i] = total_bulk_cost;
s->rlecode_table[i] = bulkcount;
}
this_line -= s->pixel_size;
prev_line -= s->pixel_size;
}
/* Good ! Now we have the best sequence for this line, let's output it */
/* We do a special case for the first pixel so that we avoid testing it in
* the whole loop */
i=0;
this_line = p-> data[0] + line*p->linesize[0];
if (s->rlecode_table[0] == 0) {
bytestream_put_byte(buf, s->skip_table[0] + 1);
i += s->skip_table[0];
}
else bytestream_put_byte(buf, 1);
while (i < width) {
rlecode = s->rlecode_table[i];
bytestream_put_byte(buf, rlecode);
if (rlecode == 0) {
/* Write a skip sequence */
bytestream_put_byte(buf, s->skip_table[i] + 1);
i += s->skip_table[i];
}
else if (rlecode > 0) {
/* bulk copy */
if (s->avctx->pix_fmt == PIX_FMT_GRAY8) {
int j;
// QT grayscale colorspace has 0=white and 255=black, we will
// ignore the palette that is included in the AVFrame because
// PIX_FMT_GRAY8 has defined color mapping
for (j = 0; j < rlecode*s->pixel_size; ++j)
bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff);
} else {
bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size);
}
i += rlecode;
}
else {
/* repeat the bits */
if (s->avctx->pix_fmt == PIX_FMT_GRAY8) {
int j;
// QT grayscale colorspace has 0=white and 255=black, ...
for (j = 0; j < s->pixel_size; ++j)
bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff);
} else {
bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size);
}
i -= rlecode;
}
}
bytestream_put_byte(buf, -1); // end RLE line
}
| true | FFmpeg | 8b18288c08fd450601251700eb42d9efbef89803 |
24,413 | static void rv34_idct_add_c(uint8_t *dst, ptrdiff_t stride, DCTELEM *block){
int temp[16];
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int i;
rv34_row_transform(temp, block);
memset(block, 0, 16*sizeof(DCTELEM));
for(i = 0; i < 4; i++){
const int z0 = 13*(temp[4*0+i] + temp[4*2+i]) + 0x200;
const int z1 = 13*(temp[4*0+i] - temp[4*2+i]) + 0x200;
const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
dst[0] = cm[ dst[0] + ( (z0 + z3) >> 10 ) ];
dst[1] = cm[ dst[1] + ( (z1 + z2) >> 10 ) ];
dst[2] = cm[ dst[2] + ( (z1 - z2) >> 10 ) ];
dst[3] = cm[ dst[3] + ( (z0 - z3) >> 10 ) ];
dst += stride;
}
}
| true | FFmpeg | c23acbaed40101c677dfcfbbfe0d2c230a8e8f44 |
24,414 | int ff_lpc_calc_coefs(DSPContext *s,
const int32_t *samples, int blocksize, int min_order,
int max_order, int precision,
int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc,
int omethod, int max_shift, int zero_shift)
{
double autoc[MAX_LPC_ORDER+1];
double ref[MAX_LPC_ORDER];
double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER];
int i, j, pass;
int opt_order;
assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && use_lpc > 0);
if(use_lpc == 1){
s->flac_compute_autocorr(samples, blocksize, max_order, autoc);
compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);
for(i=0; i<max_order; i++)
ref[i] = fabs(lpc[i][i]);
}else{
LLSModel m[2];
double var[MAX_LPC_ORDER+1], weight;
for(pass=0; pass<use_lpc-1; pass++){
av_init_lls(&m[pass&1], max_order);
weight=0;
for(i=max_order; i<blocksize; i++){
for(j=0; j<=max_order; j++)
var[j]= samples[i-j];
if(pass){
double eval, inv, rinv;
eval= av_evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);
eval= (512>>pass) + fabs(eval - var[0]);
inv = 1/eval;
rinv = sqrt(inv);
for(j=0; j<=max_order; j++)
var[j] *= rinv;
weight += inv;
}else
weight++;
av_update_lls(&m[pass&1], var, 1.0);
}
av_solve_lls(&m[pass&1], 0.001, 0);
}
for(i=0; i<max_order; i++){
for(j=0; j<max_order; j++)
lpc[i][j]=-m[(pass-1)&1].coeff[i][j];
ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000;
}
for(i=max_order-1; i>0; i--)
ref[i] = ref[i-1] - ref[i];
}
opt_order = max_order;
if(omethod == ORDER_METHOD_EST) {
opt_order = estimate_best_order(ref, min_order, max_order);
i = opt_order-1;
quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);
} else {
for(i=min_order-1; i<max_order; i++) {
quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);
}
}
return opt_order;
}
| true | FFmpeg | 3cfe88194a6ea8c720dfc85239d03c659473bcc3 |
24,416 | av_cold void ff_cavsdsp_init_x86(CAVSDSPContext *c, AVCodecContext *avctx)
{
av_unused int cpu_flags = av_get_cpu_flags();
cavsdsp_init_mmx(c, avctx);
#if HAVE_AMD3DNOW_INLINE
if (INLINE_AMD3DNOW(cpu_flags))
cavsdsp_init_3dnow(c, avctx);
#endif /* HAVE_AMD3DNOW_INLINE */
#if HAVE_MMXEXT_INLINE
if (INLINE_MMXEXT(cpu_flags)) {
DSPFUNC(put, 0, 16, mmxext);
DSPFUNC(put, 1, 8, mmxext);
DSPFUNC(avg, 0, 16, mmxext);
DSPFUNC(avg, 1, 8, mmxext);
}
#endif
#if HAVE_MMX_EXTERNAL
if (EXTERNAL_MMXEXT(cpu_flags)) {
c->avg_cavs_qpel_pixels_tab[0][0] = avg_cavs_qpel16_mc00_mmxext;
c->avg_cavs_qpel_pixels_tab[1][0] = avg_cavs_qpel8_mc00_mmxext;
}
#endif
#if HAVE_SSE2_EXTERNAL
if (EXTERNAL_SSE2(cpu_flags)) {
c->put_cavs_qpel_pixels_tab[0][0] = put_cavs_qpel16_mc00_sse2;
c->avg_cavs_qpel_pixels_tab[0][0] = avg_cavs_qpel16_mc00_sse2;
}
#endif
}
| true | FFmpeg | 835d9f299cf6b3704989a7b3eccfa1c2ec6866d9 |
24,417 | static bool object_create_initial(const char *type)
{
if (g_str_equal(type, "rng-egd")) {
/*
* return false for concrete netfilters since
* they depend on netdevs already existing
if (g_str_equal(type, "filter-buffer") ||
g_str_equal(type, "filter-dump") ||
g_str_equal(type, "filter-mirror") ||
g_str_equal(type, "filter-redirector")) {
return true; | true | qemu | 6546d0dba6c211c1a3eac1252a4f50a0c151a08a |
24,418 | static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVBochsState *s = bs->opaque;
int i;
struct bochs_header bochs;
struct bochs_header_v1 header_v1;
int ret;
bs->read_only = 1; // no write support yet
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
if (ret < 0) {
return ret;
}
if (strcmp(bochs.magic, HEADER_MAGIC) ||
strcmp(bochs.type, REDOLOG_TYPE) ||
strcmp(bochs.subtype, GROWING_TYPE) ||
((le32_to_cpu(bochs.version) != HEADER_VERSION) &&
(le32_to_cpu(bochs.version) != HEADER_V1))) {
error_setg(errp, "Image not in Bochs format");
return -EINVAL;
}
if (le32_to_cpu(bochs.version) == HEADER_V1) {
memcpy(&header_v1, &bochs, sizeof(bochs));
bs->total_sectors = le64_to_cpu(header_v1.extra.redolog.disk) / 512;
} else {
bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512;
}
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
s->catalog_bitmap = g_malloc(s->catalog_size * 4);
ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
s->catalog_size * 4);
if (ret < 0) {
goto fail;
}
for (i = 0; i < s->catalog_size; i++)
le32_to_cpus(&s->catalog_bitmap[i]);
s->data_offset = le32_to_cpu(bochs.header) + (s->catalog_size * 4);
s->bitmap_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.bitmap) - 1) / 512;
s->extent_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.extent) - 1) / 512;
s->extent_size = le32_to_cpu(bochs.extra.redolog.extent);
qemu_co_mutex_init(&s->lock);
return 0;
fail:
g_free(s->catalog_bitmap);
return ret;
}
| true | qemu | 3dd8a6763bcc50dfc3de8da9279b741c0dea9fb1 |
24,419 | static int svq3_decode_frame (AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size) {
MpegEncContext *const s = avctx->priv_data;
H264Context *const h = avctx->priv_data;
int m, mb_type;
unsigned char *extradata;
unsigned int size;
s->flags = avctx->flags;
s->flags2 = avctx->flags2;
s->unrestricted_mv = 1;
if (!s->context_initialized) {
s->width = avctx->width;
s->height = avctx->height;
h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c;
h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c;
h->halfpel_flag = 1;
h->thirdpel_flag = 1;
h->unknown_svq3_flag = 0;
h->chroma_qp = 4;
if (MPV_common_init (s) < 0)
return -1;
h->b_stride = 4*s->mb_width;
alloc_tables (h);
/* prowl for the "SEQH" marker in the extradata */
extradata = (unsigned char *)avctx->extradata;
for (m = 0; m < avctx->extradata_size; m++) {
if (!memcmp (extradata, "SEQH", 4))
break;
extradata++;
}
/* if a match was found, parse the extra data */
if (extradata && !memcmp (extradata, "SEQH", 4)) {
GetBitContext gb;
size = AV_RB32(&extradata[4]);
init_get_bits (&gb, extradata + 8, size*8);
/* 'frame size code' and optional 'width, height' */
if (get_bits (&gb, 3) == 7) {
get_bits (&gb, 12);
get_bits (&gb, 12);
}
h->halfpel_flag = get_bits1 (&gb);
h->thirdpel_flag = get_bits1 (&gb);
/* unknown fields */
get_bits1 (&gb);
get_bits1 (&gb);
get_bits1 (&gb);
get_bits1 (&gb);
s->low_delay = get_bits1 (&gb);
/* unknown field */
get_bits1 (&gb);
while (get_bits1 (&gb)) {
get_bits (&gb, 8);
}
h->unknown_svq3_flag = get_bits1 (&gb);
avctx->has_b_frames = !s->low_delay;
}
}
/* special case for last picture */
if (buf_size == 0) {
if (s->next_picture_ptr && !s->low_delay) {
*(AVFrame *) data = *(AVFrame *) &s->next_picture;
*data_size = sizeof(AVFrame);
}
return 0;
}
init_get_bits (&s->gb, buf, 8*buf_size);
s->mb_x = s->mb_y = 0;
if (svq3_decode_slice_header (h))
return -1;
s->pict_type = h->slice_type;
s->picture_number = h->slice_num;
if(avctx->debug&FF_DEBUG_PICT_INFO){
av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d\n",
av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag,
s->adaptive_quant, s->qscale
);
}
/* for hurry_up==5 */
s->current_picture.pict_type = s->pict_type;
s->current_picture.key_frame = (s->pict_type == I_TYPE);
/* skip b frames if we dont have reference frames */
if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0;
/* skip b frames if we are in a hurry */
if (avctx->hurry_up && s->pict_type == B_TYPE) return 0;
/* skip everything if we are in a hurry >= 5 */
if (avctx->hurry_up >= 5) return 0;
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
|| avctx->skip_frame >= AVDISCARD_ALL)
return 0;
if (s->next_p_frame_damaged) {
if (s->pict_type == B_TYPE)
return 0;
else
s->next_p_frame_damaged = 0;
}
frame_start (h);
if (s->pict_type == B_TYPE) {
h->frame_num_offset = (h->slice_num - h->prev_frame_num);
if (h->frame_num_offset < 0) {
h->frame_num_offset += 256;
}
if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
return -1;
}
} else {
h->prev_frame_num = h->frame_num;
h->frame_num = h->slice_num;
h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
if (h->prev_frame_num_offset < 0) {
h->prev_frame_num_offset += 256;
}
}
for(m=0; m<2; m++){
int i;
for(i=0; i<4; i++){
int j;
for(j=-1; j<4; j++)
h->ref_cache[m][scan8[0] + 8*i + j]= 1;
h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
}
}
for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
((get_bits_count(&s->gb) & 7) == 0 || show_bits (&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb));
s->gb.size_in_bits = 8*buf_size;
if (svq3_decode_slice_header (h))
return -1;
/* TODO: support s->mb_skip_run */
}
mb_type = svq3_get_ue_golomb (&s->gb);
if (s->pict_type == I_TYPE) {
mb_type += 8;
} else if (s->pict_type == B_TYPE && mb_type >= 4) {
mb_type += 4;
}
if (mb_type > 33 || svq3_decode_mb (h, mb_type)) {
av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
return -1;
}
if (mb_type != 0) {
hl_decode_mb (h);
}
if (s->pict_type != B_TYPE && !s->low_delay) {
s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
(s->pict_type == P_TYPE && mb_type < 8) ? (mb_type - 1) : -1;
}
}
ff_draw_horiz_band(s, 16*s->mb_y, 16);
}
MPV_frame_end(s);
if (s->pict_type == B_TYPE || s->low_delay) {
*(AVFrame *) data = *(AVFrame *) &s->current_picture;
} else {
*(AVFrame *) data = *(AVFrame *) &s->last_picture;
}
avctx->frame_number = s->picture_number - 1;
/* dont output the last pic after seeking */
if (s->last_picture_ptr || s->low_delay) {
*data_size = sizeof(AVFrame);
}
return buf_size;
}
| true | FFmpeg | 0c74098b1c4cc566ee0af19374b03d1e425dd1f0 |
24,420 | static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
const CPUSH4State *env)
{
int i;
for (i = 0; i < 16; i++) {
(*regs[i]) = tswapreg(env->gregs[i]);
}
(*regs)[TARGET_REG_PC] = tswapreg(env->pc);
(*regs)[TARGET_REG_PR] = tswapreg(env->pr);
(*regs)[TARGET_REG_SR] = tswapreg(env->sr);
(*regs)[TARGET_REG_GBR] = tswapreg(env->gbr);
(*regs)[TARGET_REG_MACH] = tswapreg(env->mach);
(*regs)[TARGET_REG_MACL] = tswapreg(env->macl);
(*regs)[TARGET_REG_SYSCALL] = 0; /* FIXME */
}
| true | qemu | 72cd500b725fd9a3bbefeb468d54c192fdc28318 |
24,421 | static int vorbis_parse_id_hdr(vorbis_context *vc){
GetBitContext *gb=&vc->gb;
uint_fast8_t bl0, bl1;
if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') ||
(get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') ||
(get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) {
av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
return 1;
}
vc->version=get_bits_long(gb, 32); //FIXME check 0
vc->audio_channels=get_bits(gb, 8); //FIXME check >0
vc->audio_samplerate=get_bits_long(gb, 32); //FIXME check >0
vc->bitrate_maximum=get_bits_long(gb, 32);
vc->bitrate_nominal=get_bits_long(gb, 32);
vc->bitrate_minimum=get_bits_long(gb, 32);
bl0=get_bits(gb, 4);
bl1=get_bits(gb, 4);
vc->blocksize[0]=(1<<bl0);
vc->blocksize[1]=(1<<bl1);
if (bl0>13 || bl0<6 || bl1>13 || bl1<6 || bl1<bl0) {
av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
return 3;
}
// output format int16
if (vc->blocksize[1]/2 * vc->audio_channels * 2 >
AVCODEC_MAX_AUDIO_FRAME_SIZE) {
av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
"output packets too large.\n");
return 4;
}
vc->win[0]=ff_vorbis_vwin[bl0-6];
vc->win[1]=ff_vorbis_vwin[bl1-6];
if(vc->exp_bias){
int i, j;
for(j=0; j<2; j++){
float *win = av_malloc(vc->blocksize[j]/2 * sizeof(float));
for(i=0; i<vc->blocksize[j]/2; i++)
win[i] = vc->win[j][i] * (1<<15);
vc->win[j] = win;
}
}
if ((get_bits1(gb)) == 0) {
av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
return 2;
}
vc->channel_residues=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
vc->channel_floors=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
vc->saved=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
vc->ret=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
vc->buf=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
vc->buf_tmp=(float *)av_malloc(vc->blocksize[1] * sizeof(float));
vc->saved_start=0;
ff_mdct_init(&vc->mdct[0], bl0, 1);
ff_mdct_init(&vc->mdct[1], bl1, 1);
AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ",
vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
/*
BLK=vc->blocksize[0];
for(i=0;i<BLK/2;++i) {
vc->win[0][i]=sin(0.5*3.14159265358*(sin(((float)i+0.5)/(float)BLK*3.14159265358))*(sin(((float)i+0.5)/(float)BLK*3.14159265358)));
}
*/
return 0;
}
| false | FFmpeg | 90901860c21468d6e9ae437c2bacb099c7bd3acf |
24,422 | static void tcg_out_ld (TCGContext *s, TCGType type, int ret, int arg1,
tcg_target_long arg2)
{
if (type == TCG_TYPE_I32)
tcg_out_ldst (s, ret, arg1, arg2, LWZ, LWZX);
else
tcg_out_ldst (s, ret, arg1, arg2, LD, LDX);
}
| true | qemu | 828808f5ece20fd606218e000139799921c89d93 |
24,423 | void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
{
uint64_t *copy;
copy = g_malloc(sizeof(value));
*copy = cpu_to_le64(value);
fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
}
| true | qemu | 089da572b956ef0f8f5b8d5917358e07892a77c2 |
24,425 | static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
int is_connected)
{
NetSocketState *s;
s = qemu_mallocz(sizeof(NetSocketState));
if (!s)
return NULL;
s->fd = fd;
s->vc = qemu_new_vlan_client(vlan,
net_socket_receive, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"socket: fd=%d", fd);
if (is_connected) {
net_socket_connect(s);
} else {
qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
}
return s;
}
| true | qemu | d861b05ea30e6ac177de9b679da96194ebe21afc |
24,427 | static int add_string_metadata(int count, const char *name,
TiffContext *s)
{
char *value;
if (bytestream2_get_bytes_left(&s->gb) < count)
return AVERROR_INVALIDDATA;
value = av_malloc(count + 1);
if (!value)
return AVERROR(ENOMEM);
bytestream2_get_bufferu(&s->gb, value, count);
value[count] = 0;
av_dict_set(&s->picture.metadata, name, value, AV_DICT_DONT_STRDUP_VAL);
return 0;
}
| false | FFmpeg | b16830840eb9bdec88fce2aebb38a582e093ab6b |
24,428 | static int idcin_read_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
IdcinDemuxContext *idcin = s->priv_data;
AVStream *st;
unsigned int width, height;
unsigned int sample_rate, bytes_per_sample, channels;
int ret;
/* get the 5 header parameters */
width = avio_rl32(pb);
height = avio_rl32(pb);
sample_rate = avio_rl32(pb);
bytes_per_sample = avio_rl32(pb);
channels = avio_rl32(pb);
if (s->pb->eof_reached) {
av_log(s, AV_LOG_ERROR, "incomplete header\n");
return s->pb->error ? s->pb->error : AVERROR_EOF;
}
if (av_image_check_size(width, height, 0, s) < 0)
return AVERROR_INVALIDDATA;
if (sample_rate > 0) {
if (sample_rate < 14 || sample_rate > INT_MAX) {
av_log(s, AV_LOG_ERROR, "invalid sample rate: %u\n", sample_rate);
return AVERROR_INVALIDDATA;
}
if (bytes_per_sample < 1 || bytes_per_sample > 2) {
av_log(s, AV_LOG_ERROR, "invalid bytes per sample: %u\n",
bytes_per_sample);
return AVERROR_INVALIDDATA;
}
if (channels < 1 || channels > 2) {
av_log(s, AV_LOG_ERROR, "invalid channels: %u\n", channels);
return AVERROR_INVALIDDATA;
}
idcin->audio_present = 1;
} else {
/* if sample rate is 0, assume no audio */
idcin->audio_present = 0;
}
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
avpriv_set_pts_info(st, 33, 1, IDCIN_FPS);
st->start_time = 0;
idcin->video_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_IDCIN;
st->codec->codec_tag = 0; /* no fourcc */
st->codec->width = width;
st->codec->height = height;
/* load up the Huffman tables into extradata */
st->codec->extradata_size = HUFFMAN_TABLE_SIZE;
st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE);
ret = avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE);
if (ret < 0) {
return ret;
} else if (ret != HUFFMAN_TABLE_SIZE) {
av_log(s, AV_LOG_ERROR, "incomplete header\n");
return AVERROR(EIO);
}
if (idcin->audio_present) {
idcin->audio_present = 1;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
avpriv_set_pts_info(st, 63, 1, sample_rate);
st->start_time = 0;
idcin->audio_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = 1;
st->codec->channels = channels;
st->codec->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO;
st->codec->sample_rate = sample_rate;
st->codec->bits_per_coded_sample = bytes_per_sample * 8;
st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels;
st->codec->block_align = idcin->block_align = bytes_per_sample * channels;
if (bytes_per_sample == 1)
st->codec->codec_id = AV_CODEC_ID_PCM_U8;
else
st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
if (sample_rate % 14 != 0) {
idcin->audio_chunk_size1 = (sample_rate / 14) *
bytes_per_sample * channels;
idcin->audio_chunk_size2 = (sample_rate / 14 + 1) *
bytes_per_sample * channels;
} else {
idcin->audio_chunk_size1 = idcin->audio_chunk_size2 =
(sample_rate / 14) * bytes_per_sample * channels;
}
idcin->current_audio_chunk = 0;
}
idcin->next_chunk_is_video = 1;
idcin->first_pkt_pos = avio_tell(s->pb);
return 0;
}
| false | FFmpeg | 16e0416fa47ca391214ad20d162240e5d492bf0e |
24,429 | static int decode_profile_tier_level(GetBitContext *gb, AVCodecContext *avctx,
PTLCommon *ptl)
{
int i;
if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 16 + 16 + 12)
return -1;
ptl->profile_space = get_bits(gb, 2);
ptl->tier_flag = get_bits1(gb);
ptl->profile_idc = get_bits(gb, 5);
if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN)
av_log(avctx, AV_LOG_DEBUG, "Main profile bitstream\n");
else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_10)
av_log(avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n");
else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_STILL_PICTURE)
av_log(avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
else if (ptl->profile_idc == FF_PROFILE_HEVC_REXT)
av_log(avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
else
av_log(avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc);
for (i = 0; i < 32; i++)
ptl->profile_compatibility_flag[i] = get_bits1(gb);
ptl->progressive_source_flag = get_bits1(gb);
ptl->interlaced_source_flag = get_bits1(gb);
ptl->non_packed_constraint_flag = get_bits1(gb);
ptl->frame_only_constraint_flag = get_bits1(gb);
skip_bits(gb, 16); // XXX_reserved_zero_44bits[0..15]
skip_bits(gb, 16); // XXX_reserved_zero_44bits[16..31]
skip_bits(gb, 12); // XXX_reserved_zero_44bits[32..43]
return 0;
}
| false | FFmpeg | f85cc3bf12236e974403667610b39b802b8651d6 |
24,431 | int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset)
{
struct {
LBRChunk lfe;
LBRChunk tonal;
LBRChunk tonal_grp[5];
LBRChunk grid1[DCA_LBR_CHANNELS / 2];
LBRChunk hr_grid[DCA_LBR_CHANNELS / 2];
LBRChunk ts1[DCA_LBR_CHANNELS / 2];
LBRChunk ts2[DCA_LBR_CHANNELS / 2];
} chunk = { };
GetByteContext gb;
int i, ch, sb, sf, ret, group, chunk_id, chunk_len;
bytestream2_init(&gb, data + asset->lbr_offset, asset->lbr_size);
// LBR sync word
if (bytestream2_get_be32(&gb) != DCA_SYNCWORD_LBR) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid LBR sync word\n");
return AVERROR_INVALIDDATA;
}
// LBR header type
switch (bytestream2_get_byte(&gb)) {
case LBR_HEADER_SYNC_ONLY:
if (!s->sample_rate) {
av_log(s->avctx, AV_LOG_ERROR, "LBR decoder not initialized\n");
return AVERROR_INVALIDDATA;
}
break;
case LBR_HEADER_DECODER_INIT:
if ((ret = parse_decoder_init(s, &gb)) < 0) {
s->sample_rate = 0;
return ret;
}
break;
default:
av_log(s->avctx, AV_LOG_ERROR, "Invalid LBR header type\n");
return AVERROR_INVALIDDATA;
}
// LBR frame chunk header
chunk_id = bytestream2_get_byte(&gb);
chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
if (chunk_len > bytestream2_get_bytes_left(&gb)) {
chunk_len = bytestream2_get_bytes_left(&gb);
av_log(s->avctx, AV_LOG_WARNING, "LBR frame chunk was truncated\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;
}
bytestream2_init(&gb, gb.buffer, chunk_len);
switch (chunk_id & 0x7f) {
case LBR_CHUNK_FRAME:
if (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL)) {
int checksum = bytestream2_get_be16(&gb);
uint16_t res = chunk_id;
res += (chunk_len >> 8) & 0xff;
res += chunk_len & 0xff;
for (i = 0; i < chunk_len - 2; i++)
res += gb.buffer[i];
if (checksum != res) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid LBR checksum\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;
}
} else {
bytestream2_skip(&gb, 2);
}
break;
case LBR_CHUNK_FRAME_NO_CSUM:
break;
default:
av_log(s->avctx, AV_LOG_ERROR, "Invalid LBR frame chunk ID\n");
return AVERROR_INVALIDDATA;
}
// Clear current frame
memset(s->quant_levels, 0, sizeof(s->quant_levels));
memset(s->sb_indices, 0xff, sizeof(s->sb_indices));
memset(s->sec_ch_sbms, 0, sizeof(s->sec_ch_sbms));
memset(s->sec_ch_lrms, 0, sizeof(s->sec_ch_lrms));
memset(s->ch_pres, 0, sizeof(s->ch_pres));
memset(s->grid_1_scf, 0, sizeof(s->grid_1_scf));
memset(s->grid_2_scf, 0, sizeof(s->grid_2_scf));
memset(s->grid_3_avg, 0, sizeof(s->grid_3_avg));
memset(s->grid_3_scf, 0, sizeof(s->grid_3_scf));
memset(s->grid_3_pres, 0, sizeof(s->grid_3_pres));
memset(s->tonal_scf, 0, sizeof(s->tonal_scf));
memset(s->lfe_data, 0, sizeof(s->lfe_data));
s->part_stereo_pres = 0;
s->framenum = (s->framenum + 1) & 31;
for (ch = 0; ch < s->nchannels; ch++) {
for (sb = 0; sb < s->nsubbands / 4; sb++) {
s->part_stereo[ch][sb][0] = s->part_stereo[ch][sb][4];
s->part_stereo[ch][sb][4] = 16;
}
}
memset(s->lpc_coeff[s->framenum & 1], 0, sizeof(s->lpc_coeff[0]));
for (group = 0; group < 5; group++) {
for (sf = 0; sf < 1 << group; sf++) {
int sf_idx = ((s->framenum << group) + sf) & 31;
s->tonal_bounds[group][sf_idx][0] =
s->tonal_bounds[group][sf_idx][1] = s->ntones;
}
}
// Parse chunk headers
while (bytestream2_get_bytes_left(&gb) > 0) {
chunk_id = bytestream2_get_byte(&gb);
chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
chunk_id &= 0x7f;
if (chunk_len > bytestream2_get_bytes_left(&gb)) {
chunk_len = bytestream2_get_bytes_left(&gb);
av_log(s->avctx, AV_LOG_WARNING, "LBR chunk %#x was truncated\n", chunk_id);
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;
}
switch (chunk_id) {
case LBR_CHUNK_LFE:
chunk.lfe.len = chunk_len;
chunk.lfe.data = gb.buffer;
break;
case LBR_CHUNK_SCF:
case LBR_CHUNK_TONAL:
case LBR_CHUNK_TONAL_SCF:
chunk.tonal.id = chunk_id;
chunk.tonal.len = chunk_len;
chunk.tonal.data = gb.buffer;
break;
case LBR_CHUNK_TONAL_GRP_1:
case LBR_CHUNK_TONAL_GRP_2:
case LBR_CHUNK_TONAL_GRP_3:
case LBR_CHUNK_TONAL_GRP_4:
case LBR_CHUNK_TONAL_GRP_5:
i = LBR_CHUNK_TONAL_GRP_5 - chunk_id;
chunk.tonal_grp[i].id = i;
chunk.tonal_grp[i].len = chunk_len;
chunk.tonal_grp[i].data = gb.buffer;
break;
case LBR_CHUNK_TONAL_SCF_GRP_1:
case LBR_CHUNK_TONAL_SCF_GRP_2:
case LBR_CHUNK_TONAL_SCF_GRP_3:
case LBR_CHUNK_TONAL_SCF_GRP_4:
case LBR_CHUNK_TONAL_SCF_GRP_5:
i = LBR_CHUNK_TONAL_SCF_GRP_5 - chunk_id;
chunk.tonal_grp[i].id = i;
chunk.tonal_grp[i].len = chunk_len;
chunk.tonal_grp[i].data = gb.buffer;
break;
case LBR_CHUNK_RES_GRID_LR:
case LBR_CHUNK_RES_GRID_LR + 1:
case LBR_CHUNK_RES_GRID_LR + 2:
i = chunk_id - LBR_CHUNK_RES_GRID_LR;
chunk.grid1[i].len = chunk_len;
chunk.grid1[i].data = gb.buffer;
break;
case LBR_CHUNK_RES_GRID_HR:
case LBR_CHUNK_RES_GRID_HR + 1:
case LBR_CHUNK_RES_GRID_HR + 2:
i = chunk_id - LBR_CHUNK_RES_GRID_HR;
chunk.hr_grid[i].len = chunk_len;
chunk.hr_grid[i].data = gb.buffer;
break;
case LBR_CHUNK_RES_TS_1:
case LBR_CHUNK_RES_TS_1 + 1:
case LBR_CHUNK_RES_TS_1 + 2:
i = chunk_id - LBR_CHUNK_RES_TS_1;
chunk.ts1[i].len = chunk_len;
chunk.ts1[i].data = gb.buffer;
break;
case LBR_CHUNK_RES_TS_2:
case LBR_CHUNK_RES_TS_2 + 1:
case LBR_CHUNK_RES_TS_2 + 2:
i = chunk_id - LBR_CHUNK_RES_TS_2;
chunk.ts2[i].len = chunk_len;
chunk.ts2[i].data = gb.buffer;
break;
}
bytestream2_skip(&gb, chunk_len);
}
// Parse the chunks
ret = parse_lfe_chunk(s, &chunk.lfe);
ret |= parse_tonal_chunk(s, &chunk.tonal);
for (i = 0; i < 5; i++)
ret |= parse_tonal_group(s, &chunk.tonal_grp[i]);
for (i = 0; i < (s->nchannels + 1) / 2; i++) {
int ch1 = i * 2;
int ch2 = FFMIN(ch1 + 1, s->nchannels - 1);
if (parse_grid_1_chunk (s, &chunk.grid1 [i], ch1, ch2) < 0 ||
parse_high_res_grid(s, &chunk.hr_grid[i], ch1, ch2) < 0) {
ret = -1;
continue;
}
// TS chunks depend on both grids. TS_2 depends on TS_1.
if (!chunk.grid1[i].len || !chunk.hr_grid[i].len || !chunk.ts1[i].len)
continue;
if (parse_ts1_chunk(s, &chunk.ts1[i], ch1, ch2) < 0 ||
parse_ts2_chunk(s, &chunk.ts2[i], ch1, ch2) < 0) {
ret = -1;
continue;
}
}
if (ret < 0 && (s->avctx->err_recognition & AV_EF_EXPLODE))
return AVERROR_INVALIDDATA;
return 0;
}
| false | FFmpeg | 27506aceda8115f82f89691a4441d62a8cf24a6e |
24,432 | static av_cold int wmv2_decode_init(AVCodecContext *avctx)
{
Wmv2Context *const w = avctx->priv_data;
int ret;
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
return ret;
ff_wmv2_common_init(w);
return ff_intrax8_common_init(&w->x8, &w->s.idsp, &w->s);
}
| false | FFmpeg | 1eaae7abb8f208fefb4e8b9e983e61b2499206a3 |
24,434 | static int amovie_get_samples(AVFilterLink *outlink)
{
MovieContext *movie = outlink->src->priv;
AVPacket pkt;
int ret, got_frame = 0;
if (!movie->pkt.size && movie->is_done == 1)
return AVERROR_EOF;
/* check for another frame, in case the previous one was completely consumed */
if (!movie->pkt.size) {
while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) {
// Is this a packet from the selected stream?
if (pkt.stream_index != movie->stream_index) {
av_free_packet(&pkt);
continue;
} else {
movie->pkt0 = movie->pkt = pkt;
break;
}
}
if (ret == AVERROR_EOF) {
movie->is_done = 1;
return ret;
}
}
/* decode and update the movie pkt */
avcodec_get_frame_defaults(movie->frame);
ret = avcodec_decode_audio4(movie->codec_ctx, movie->frame, &got_frame, &movie->pkt);
if (ret < 0) {
movie->pkt.size = 0;
return ret;
}
movie->pkt.data += ret;
movie->pkt.size -= ret;
/* wrap the decoded data in a samplesref */
if (got_frame) {
int nb_samples = movie->frame->nb_samples;
int data_size =
av_samples_get_buffer_size(NULL, movie->codec_ctx->channels,
nb_samples, movie->codec_ctx->sample_fmt, 1);
if (data_size < 0)
return data_size;
movie->samplesref =
ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
memcpy(movie->samplesref->data[0], movie->frame->data[0], data_size);
movie->samplesref->pts = movie->pkt.pts;
movie->samplesref->pos = movie->pkt.pos;
movie->samplesref->audio->sample_rate = movie->codec_ctx->sample_rate;
}
// We got it. Free the packet since we are returning
if (movie->pkt.size <= 0)
av_free_packet(&movie->pkt0);
return 0;
}
| false | FFmpeg | ac726a4f0cd2fb8619b478af51312a4282215f0e |
24,435 | static int h264_init_context(AVCodecContext *avctx, H264Context *h)
{
int i;
h->avctx = avctx;
h->picture_structure = PICT_FRAME;
h->slice_context_count = 1;
h->workaround_bugs = avctx->workaround_bugs;
h->flags = avctx->flags;
h->prev_poc_msb = 1 << 16;
h->x264_build = -1;
h->recovery_frame = -1;
h->frame_recovered = 0;
h->next_outputed_poc = INT_MIN;
for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
h->last_pocs[i] = INT_MIN;
ff_h264_reset_sei(h);
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? H264_MAX_THREADS : 1;
h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));
if (!h->slice_ctx) {
h->nb_slice_ctx = 0;
return AVERROR(ENOMEM);
}
for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
h->DPB[i].f = av_frame_alloc();
if (!h->DPB[i].f)
return AVERROR(ENOMEM);
}
h->cur_pic.f = av_frame_alloc();
if (!h->cur_pic.f)
return AVERROR(ENOMEM);
for (i = 0; i < h->nb_slice_ctx; i++)
h->slice_ctx[i].h264 = h;
return 0;
}
| false | FFmpeg | c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8 |
24,436 | static uint32_t nvic_readl(NVICState *s, uint32_t offset)
{
ARMCPU *cpu = s->cpu;
uint32_t val;
switch (offset) {
case 4: /* Interrupt Control Type. */
return ((s->num_irq - NVIC_FIRST_IRQ) / 32) - 1;
case 0xd00: /* CPUID Base. */
return cpu->midr;
case 0xd04: /* Interrupt Control State. */
/* VECTACTIVE */
val = cpu->env.v7m.exception;
/* VECTPENDING */
val |= (s->vectpending & 0xff) << 12;
/* ISRPENDING - set if any external IRQ is pending */
if (nvic_isrpending(s)) {
val |= (1 << 22);
}
/* RETTOBASE - set if only one handler is active */
if (nvic_rettobase(s)) {
val |= (1 << 11);
}
/* PENDSTSET */
if (s->vectors[ARMV7M_EXCP_SYSTICK].pending) {
val |= (1 << 26);
}
/* PENDSVSET */
if (s->vectors[ARMV7M_EXCP_PENDSV].pending) {
val |= (1 << 28);
}
/* NMIPENDSET */
if (s->vectors[ARMV7M_EXCP_NMI].pending) {
val |= (1 << 31);
}
/* ISRPREEMPT not implemented */
return val;
case 0xd08: /* Vector Table Offset. */
return cpu->env.v7m.vecbase;
case 0xd0c: /* Application Interrupt/Reset Control. */
return 0xfa050000 | (s->prigroup << 8);
case 0xd10: /* System Control. */
/* TODO: Implement SLEEPONEXIT. */
return 0;
case 0xd14: /* Configuration Control. */
return cpu->env.v7m.ccr;
case 0xd24: /* System Handler Status. */
val = 0;
if (s->vectors[ARMV7M_EXCP_MEM].active) {
val |= (1 << 0);
}
if (s->vectors[ARMV7M_EXCP_BUS].active) {
val |= (1 << 1);
}
if (s->vectors[ARMV7M_EXCP_USAGE].active) {
val |= (1 << 3);
}
if (s->vectors[ARMV7M_EXCP_SVC].active) {
val |= (1 << 7);
}
if (s->vectors[ARMV7M_EXCP_DEBUG].active) {
val |= (1 << 8);
}
if (s->vectors[ARMV7M_EXCP_PENDSV].active) {
val |= (1 << 10);
}
if (s->vectors[ARMV7M_EXCP_SYSTICK].active) {
val |= (1 << 11);
}
if (s->vectors[ARMV7M_EXCP_USAGE].pending) {
val |= (1 << 12);
}
if (s->vectors[ARMV7M_EXCP_MEM].pending) {
val |= (1 << 13);
}
if (s->vectors[ARMV7M_EXCP_BUS].pending) {
val |= (1 << 14);
}
if (s->vectors[ARMV7M_EXCP_SVC].pending) {
val |= (1 << 15);
}
if (s->vectors[ARMV7M_EXCP_MEM].enabled) {
val |= (1 << 16);
}
if (s->vectors[ARMV7M_EXCP_BUS].enabled) {
val |= (1 << 17);
}
if (s->vectors[ARMV7M_EXCP_USAGE].enabled) {
val |= (1 << 18);
}
return val;
case 0xd28: /* Configurable Fault Status. */
return cpu->env.v7m.cfsr;
case 0xd2c: /* Hard Fault Status. */
return cpu->env.v7m.hfsr;
case 0xd30: /* Debug Fault Status. */
return cpu->env.v7m.dfsr;
case 0xd34: /* MMFAR MemManage Fault Address */
return cpu->env.v7m.mmfar;
case 0xd38: /* Bus Fault Address. */
return cpu->env.v7m.bfar;
case 0xd3c: /* Aux Fault Status. */
/* TODO: Implement fault status registers. */
qemu_log_mask(LOG_UNIMP,
"Aux Fault status registers unimplemented\n");
return 0;
case 0xd40: /* PFR0. */
return 0x00000030;
case 0xd44: /* PRF1. */
return 0x00000200;
case 0xd48: /* DFR0. */
return 0x00100000;
case 0xd4c: /* AFR0. */
return 0x00000000;
case 0xd50: /* MMFR0. */
return 0x00000030;
case 0xd54: /* MMFR1. */
return 0x00000000;
case 0xd58: /* MMFR2. */
return 0x00000000;
case 0xd5c: /* MMFR3. */
return 0x00000000;
case 0xd60: /* ISAR0. */
return 0x01141110;
case 0xd64: /* ISAR1. */
return 0x02111000;
case 0xd68: /* ISAR2. */
return 0x21112231;
case 0xd6c: /* ISAR3. */
return 0x01111110;
case 0xd70: /* ISAR4. */
return 0x01310102;
/* TODO: Implement debug registers. */
case 0xd90: /* MPU_TYPE */
/* Unified MPU; if the MPU is not present this value is zero */
return cpu->pmsav7_dregion << 8;
break;
case 0xd94: /* MPU_CTRL */
return cpu->env.v7m.mpu_ctrl;
case 0xd98: /* MPU_RNR */
return cpu->env.pmsav7.rnr;
case 0xd9c: /* MPU_RBAR */
case 0xda4: /* MPU_RBAR_A1 */
case 0xdac: /* MPU_RBAR_A2 */
case 0xdb4: /* MPU_RBAR_A3 */
{
int region = cpu->env.pmsav7.rnr;
if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
/* PMSAv8M handling of the aliases is different from v7M:
* aliases A1, A2, A3 override the low two bits of the region
* number in MPU_RNR, and there is no 'region' field in the
* RBAR register.
*/
int aliasno = (offset - 0xd9c) / 8; /* 0..3 */
if (aliasno) {
region = deposit32(region, 0, 2, aliasno);
}
if (region >= cpu->pmsav7_dregion) {
return 0;
}
return cpu->env.pmsav8.rbar[region];
}
if (region >= cpu->pmsav7_dregion) {
return 0;
}
return (cpu->env.pmsav7.drbar[region] & 0x1f) | (region & 0xf);
}
case 0xda0: /* MPU_RASR (v7M), MPU_RLAR (v8M) */
case 0xda8: /* MPU_RASR_A1 (v7M), MPU_RLAR_A1 (v8M) */
case 0xdb0: /* MPU_RASR_A2 (v7M), MPU_RLAR_A2 (v8M) */
case 0xdb8: /* MPU_RASR_A3 (v7M), MPU_RLAR_A3 (v8M) */
{
int region = cpu->env.pmsav7.rnr;
if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
/* PMSAv8M handling of the aliases is different from v7M:
* aliases A1, A2, A3 override the low two bits of the region
* number in MPU_RNR.
*/
int aliasno = (offset - 0xda0) / 8; /* 0..3 */
if (aliasno) {
region = deposit32(region, 0, 2, aliasno);
}
if (region >= cpu->pmsav7_dregion) {
return 0;
}
return cpu->env.pmsav8.rlar[region];
}
if (region >= cpu->pmsav7_dregion) {
return 0;
}
return ((cpu->env.pmsav7.dracr[region] & 0xffff) << 16) |
(cpu->env.pmsav7.drsr[region] & 0xffff);
}
case 0xdc0: /* MPU_MAIR0 */
if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) {
goto bad_offset;
}
return cpu->env.pmsav8.mair0;
case 0xdc4: /* MPU_MAIR1 */
if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) {
goto bad_offset;
}
return cpu->env.pmsav8.mair1;
default:
bad_offset:
qemu_log_mask(LOG_GUEST_ERROR, "NVIC: Bad read offset 0x%x\n", offset);
return 0;
}
}
| false | qemu | 45db7ba681ede57113a67499840e69ee586bcdf2 |
24,437 | static void parse_cmdline(const char *cmdline,
int *pnb_args, char **args)
{
const char *p;
int nb_args, ret;
char buf[1024];
p = cmdline;
nb_args = 0;
for(;;) {
while (qemu_isspace(*p))
p++;
if (*p == '\0')
break;
if (nb_args >= MAX_ARGS)
break;
ret = get_str(buf, sizeof(buf), &p);
args[nb_args] = g_strdup(buf);
nb_args++;
if (ret < 0)
break;
}
*pnb_args = nb_args;
}
| false | qemu | f5438c0500bb22c97b30987d2e0eab953416c7c5 |
24,438 | void portio_list_destroy(PortioList *piolist)
{
g_free(piolist->regions);
g_free(piolist->aliases);
}
| false | qemu | b40acf99bef69fa8ab0f9092ff162fde945eec12 |
24,439 | INLINE flag extractFloat32Sign( float32 a )
{
return a>>31;
}
| false | qemu | f090c9d4ad5812fb92843d6470a1111c15190c4c |
24,440 | static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
const char *name, FsCred *credp)
{
int retval;
V9fsString fullname;
v9fs_string_init(&fullname);
v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
retval = v9fs_request(fs_ctx->private, T_MKNOD, NULL, "sdqdd",
&fullname, credp->fc_mode, credp->fc_rdev,
credp->fc_uid, credp->fc_gid);
v9fs_string_free(&fullname);
if (retval < 0) {
errno = -retval;
retval = -1;
}
return retval;
}
| false | qemu | 494a8ebe713055d3946183f4b395f85a18b43e9e |
24,441 | static bool memory_region_get_may_overlap(Object *obj, Error **errp)
{
MemoryRegion *mr = MEMORY_REGION(obj);
return mr->may_overlap;
}
| false | qemu | b61359781958759317ee6fd1a45b59be0b7dbbe1 |
24,443 | static void DBDMA_run (DBDMA_channel *ch)
{
int channel;
for (channel = 0; channel < DBDMA_CHANNELS; channel++, ch++) {
uint32_t status = be32_to_cpu(ch->regs[DBDMA_STATUS]);
if (!ch->processing && (status & RUN) && (status & ACTIVE))
channel_run(ch);
}
}
| false | qemu | ad674e53b5cce265fadafbde2c6a4f190345cd00 |
24,444 | void helper_fstoq(CPUSPARCState *env, float32 src)
{
clear_float_exceptions(env);
QT0 = float32_to_float128(src, &env->fp_status);
check_ieee_exceptions(env);
}
| false | qemu | 7385aed20db5d83979f683b9d0048674411e963c |
24,445 | static void process_incoming_migration_bh(void *opaque)
{
Error *local_err = NULL;
MigrationIncomingState *mis = opaque;
/* Make sure all file formats flush their mutable metadata.
* If we get an error here, just don't restart the VM yet. */
bdrv_invalidate_cache_all(&local_err);
if (!local_err) {
blk_resume_after_migration(&local_err);
}
if (local_err) {
error_report_err(local_err);
local_err = NULL;
autostart = false;
}
/*
* This must happen after all error conditions are dealt with and
* we're sure the VM is going to be running on this host.
*/
qemu_announce_self();
/* If global state section was not received or we are in running
state, we need to obey autostart. Any other state is set with
runstate_set. */
if (!global_state_received() ||
global_state_get_runstate() == RUN_STATE_RUNNING) {
if (autostart) {
vm_start();
} else {
runstate_set(RUN_STATE_PAUSED);
}
} else {
runstate_set(global_state_get_runstate());
}
migrate_decompress_threads_join();
/*
* This must happen after any state changes since as soon as an external
* observer sees this event they might start to prod at the VM assuming
* it's ready to use.
*/
migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
MIGRATION_STATUS_COMPLETED);
qemu_bh_delete(mis->bh);
migration_incoming_state_destroy();
}
| false | qemu | 4417ab7adf1613799054be5afedf810fc2524ee8 |
24,446 | int float64_lt_quiet( float64 a, float64 b STATUS_PARAM )
{
flag aSign, bSign;
if ( ( ( extractFloat64Exp( a ) == 0x7FF ) && extractFloat64Frac( a ) )
|| ( ( extractFloat64Exp( b ) == 0x7FF ) && extractFloat64Frac( b ) )
) {
if ( float64_is_signaling_nan( a ) || float64_is_signaling_nan( b ) ) {
float_raise( float_flag_invalid STATUS_VAR);
}
return 0;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
if ( aSign != bSign ) return aSign && ( (bits64) ( ( a | b )<<1 ) != 0 );
return ( a != b ) && ( aSign ^ ( a < b ) );
}
| false | qemu | f090c9d4ad5812fb92843d6470a1111c15190c4c |
24,447 | static void machine_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
QEMUMachine *qm = data;
mc->name = qm->name;
mc->desc = qm->desc;
mc->init = qm->init;
mc->kvm_type = qm->kvm_type;
mc->block_default_type = qm->block_default_type;
mc->max_cpus = qm->max_cpus;
mc->no_sdcard = qm->no_sdcard;
mc->has_dynamic_sysbus = qm->has_dynamic_sysbus;
mc->is_default = qm->is_default;
mc->default_machine_opts = qm->default_machine_opts;
mc->default_boot_order = qm->default_boot_order;
}
| false | qemu | 076b35b5a56bca57c4aa41044ed304fe9c45d6c5 |
24,449 | int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev)
{
struct kvm_irq_routing_entry kroute = {};
int virq;
MSIMessage msg = {0, 0};
if (dev) {
msg = pci_get_msi_message(dev, vector);
}
if (kvm_gsi_direct_mapping()) {
return kvm_arch_msi_data_to_gsi(msg.data);
}
if (!kvm_gsi_routing_enabled()) {
return -ENOSYS;
}
virq = kvm_irqchip_get_virq(s);
if (virq < 0) {
return virq;
}
kroute.gsi = virq;
kroute.type = KVM_IRQ_ROUTING_MSI;
kroute.flags = 0;
kroute.u.msi.address_lo = (uint32_t)msg.address;
kroute.u.msi.address_hi = msg.address >> 32;
kroute.u.msi.data = le32_to_cpu(msg.data);
if (kvm_msi_devid_required()) {
kroute.flags = KVM_MSI_VALID_DEVID;
kroute.u.msi.devid = pci_requester_id(dev);
}
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data, dev)) {
kvm_irqchip_release_virq(s, virq);
return -EINVAL;
}
trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A",
vector, virq);
kvm_add_routing_entry(s, &kroute);
kvm_arch_add_msi_route_post(&kroute, vector, dev);
kvm_irqchip_commit_routes(s);
return virq;
}
| false | qemu | 88c725c78e87eecb061f882177c7a6a2ac1059ad |
24,450 | gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb,
int search_pc)
{
CPUState *cs = CPU(cpu);
CPUTriCoreState *env = &cpu->env;
DisasContext ctx;
target_ulong pc_start;
int num_insns;
uint16_t *gen_opc_end;
if (search_pc) {
qemu_log("search pc %d\n", search_pc);
}
num_insns = 0;
pc_start = tb->pc;
gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
ctx.pc = pc_start;
ctx.saved_pc = -1;
ctx.tb = tb;
ctx.singlestep_enabled = cs->singlestep_enabled;
ctx.bstate = BS_NONE;
ctx.mem_idx = cpu_mmu_index(env);
tcg_clear_temp_count();
gen_tb_start();
while (ctx.bstate == BS_NONE) {
ctx.opcode = cpu_ldl_code(env, ctx.pc);
decode_opc(env, &ctx, 0);
num_insns++;
if (tcg_ctx.gen_opc_ptr >= gen_opc_end) {
gen_save_pc(ctx.next_pc);
tcg_gen_exit_tb(0);
break;
}
if (singlestep) {
gen_save_pc(ctx.next_pc);
tcg_gen_exit_tb(0);
break;
}
ctx.pc = ctx.next_pc;
}
gen_tb_end(tb, num_insns);
*tcg_ctx.gen_opc_ptr = INDEX_op_end;
if (search_pc) {
printf("done_generating search pc\n");
} else {
tb->size = ctx.pc - pc_start;
tb->icount = num_insns;
}
if (tcg_check_temp_count()) {
printf("LEAK at %08x\n", env->PC);
}
#ifdef DEBUG_DISAS
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
qemu_log("IN: %s\n", lookup_symbol(pc_start));
log_target_disas(env, pc_start, ctx.pc - pc_start, 0);
qemu_log("\n");
}
#endif
}
| false | qemu | cd42d5b23691ad73edfd6dbcfc935a960a9c5a65 |
24,451 | static int raw_pread_aligned(BlockDriverState *bs, int64_t offset,
uint8_t *buf, int count)
{
BDRVRawState *s = bs->opaque;
int ret;
ret = fd_open(bs);
if (ret < 0)
return ret;
ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
/* Allow reads beyond the end (needed for pwrite) */
if ((ret == 0) && bs->growable) {
int64_t size = raw_getlength(bs);
if (offset >= size) {
memset(buf, 0, count);
ret = count;
goto label__raw_read__success;
}
}
DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
"] read failed %d : %d = %s\n",
s->fd, bs->filename, offset, buf, count,
bs->total_sectors, ret, errno, strerror(errno));
/* Try harder for CDrom. */
if (bs->type == BDRV_TYPE_CDROM) {
ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
"] retry read failed %d : %d = %s\n",
s->fd, bs->filename, offset, buf, count,
bs->total_sectors, ret, errno, strerror(errno));
}
label__raw_read__success:
return (ret < 0) ? -errno : ret;
}
| false | qemu | 65d21bc73bda6515fd9b4ff5b2e90454f7a0b419 |
24,452 | static void tcg_out_qemu_st_slow_path (TCGContext *s, TCGLabelQemuLdst *label)
{
int s_bits;
int ir;
int opc = label->opc;
int mem_index = label->mem_index;
int data_reg = label->datalo_reg;
int data_reg2 = label->datahi_reg;
int addr_reg = label->addrlo_reg;
uint8_t *raddr = label->raddr;
uint8_t **label_ptr = &label->label_ptr[0];
s_bits = opc & 3;
/* resolve label address */
reloc_pc14 (label_ptr[0], (tcg_target_long) s->code_ptr);
/* slow path */
ir = 3;
tcg_out_mov (s, TCG_TYPE_I32, ir++, TCG_AREG0);
#if TARGET_LONG_BITS == 32
tcg_out_mov (s, TCG_TYPE_I32, ir++, addr_reg);
#else
#ifdef TCG_TARGET_CALL_ALIGN_ARGS
ir |= 1;
#endif
tcg_out_mov (s, TCG_TYPE_I32, ir++, label->addrhi_reg);
tcg_out_mov (s, TCG_TYPE_I32, ir++, addr_reg);
#endif
switch (opc) {
case 0:
tcg_out32 (s, (RLWINM
| RA (ir)
| RS (data_reg)
| SH (0)
| MB (24)
| ME (31)));
break;
case 1:
tcg_out32 (s, (RLWINM
| RA (ir)
| RS (data_reg)
| SH (0)
| MB (16)
| ME (31)));
break;
case 2:
tcg_out_mov (s, TCG_TYPE_I32, ir, data_reg);
break;
case 3:
#ifdef TCG_TARGET_CALL_ALIGN_ARGS
ir |= 1;
#endif
tcg_out_mov (s, TCG_TYPE_I32, ir++, data_reg2);
tcg_out_mov (s, TCG_TYPE_I32, ir, data_reg);
break;
}
ir++;
tcg_out_movi (s, TCG_TYPE_I32, ir, mem_index);
tcg_out_call (s, (tcg_target_long) qemu_st_helpers[opc], 1);
tcg_out32 (s, B | 8);
tcg_out32 (s, (tcg_target_long) raddr);
tcg_out_b (s, 0, (tcg_target_long) raddr);
}
| false | qemu | c878da3b27ceeed953c9f9a1eb002d59e9dcb4c6 |
24,453 | static int mpegaudio_parse(AVCodecParserContext *s1,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
MpegAudioParseContext *s = s1->priv_data;
int len, ret, sr;
uint32_t header;
const uint8_t *buf_ptr;
*poutbuf = NULL;
*poutbuf_size = 0;
buf_ptr = buf;
while (buf_size > 0) {
len = s->inbuf_ptr - s->inbuf;
if (s->frame_size == 0) {
/* special case for next header for first frame in free
format case (XXX: find a simpler method) */
if (s->free_format_next_header != 0) {
AV_WB32(s->inbuf, s->free_format_next_header);
s->inbuf_ptr = s->inbuf + 4;
s->free_format_next_header = 0;
goto got_header;
}
/* no header seen : find one. We need at least MPA_HEADER_SIZE
bytes to parse it */
len = FFMIN(MPA_HEADER_SIZE - len, buf_size);
if (len > 0) {
memcpy(s->inbuf_ptr, buf_ptr, len);
buf_ptr += len;
buf_size -= len;
s->inbuf_ptr += len;
}
if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
got_header:
header = AV_RB32(s->inbuf);
ret = ff_mpa_decode_header(avctx, header, &sr);
if (ret < 0) {
s->header_count= -2;
/* no sync found : move by one byte (inefficient, but simple!) */
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
s->inbuf_ptr--;
dprintf(avctx, "skip %x\n", header);
/* reset free format frame size to give a chance
to get a new bitrate */
s->free_format_frame_size = 0;
} else {
if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
s->header_count= -3;
s->header= header;
s->header_count++;
s->frame_size = ret;
#if 0
/* free format: prepare to compute frame size */
if (ff_mpegaudio_decode_header(s, header) == 1) {
s->frame_size = -1;
}
#endif
if(s->header_count > 1)
avctx->sample_rate= sr;
}
}
} else
#if 0
if (s->frame_size == -1) {
/* free format : find next sync to compute frame size */
len = MPA_MAX_CODED_FRAME_SIZE - len;
if (len > buf_size)
len = buf_size;
if (len == 0) {
/* frame too long: resync */
s->frame_size = 0;
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
s->inbuf_ptr--;
} else {
uint8_t *p, *pend;
uint32_t header1;
int padding;
memcpy(s->inbuf_ptr, buf_ptr, len);
/* check for header */
p = s->inbuf_ptr - 3;
pend = s->inbuf_ptr + len - 4;
while (p <= pend) {
header = AV_RB32(p);
header1 = AV_RB32(s->inbuf);
/* check with high probability that we have a
valid header */
if ((header & SAME_HEADER_MASK) ==
(header1 & SAME_HEADER_MASK)) {
/* header found: update pointers */
len = (p + 4) - s->inbuf_ptr;
buf_ptr += len;
buf_size -= len;
s->inbuf_ptr = p;
/* compute frame size */
s->free_format_next_header = header;
s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
padding = (header1 >> 9) & 1;
if (s->layer == 1)
s->free_format_frame_size -= padding * 4;
else
s->free_format_frame_size -= padding;
dprintf(avctx, "free frame size=%d padding=%d\n",
s->free_format_frame_size, padding);
ff_mpegaudio_decode_header(s, header1);
goto next_data;
}
p++;
}
/* not found: simply increase pointers */
buf_ptr += len;
s->inbuf_ptr += len;
buf_size -= len;
}
} else
#endif
if (len < s->frame_size) {
if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
len = FFMIN(s->frame_size - len, buf_size);
memcpy(s->inbuf_ptr, buf_ptr, len);
buf_ptr += len;
s->inbuf_ptr += len;
buf_size -= len;
}
if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf
&& buf_size + buf_ptr - buf >= s->frame_size){
if(s->header_count > 0){
*poutbuf = buf;
*poutbuf_size = s->frame_size;
}
buf_ptr = buf + s->frame_size;
s->inbuf_ptr = s->inbuf;
s->frame_size = 0;
break;
}
// next_data:
if (s->frame_size > 0 &&
(s->inbuf_ptr - s->inbuf) >= s->frame_size) {
if(s->header_count > 0){
*poutbuf = s->inbuf;
*poutbuf_size = s->inbuf_ptr - s->inbuf;
}
s->inbuf_ptr = s->inbuf;
s->frame_size = 0;
break;
}
}
return buf_ptr - buf;
}
| false | FFmpeg | c96bd21227e594856f8fd0610fd213b002056383 |
24,454 | int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
int32_t ag, uint32_t ap)
{
AVReplayGain *replaygain;
if (tg == INT32_MIN && ag == INT32_MIN)
return 0;
replaygain = (AVReplayGain*)ff_stream_new_side_data(st, AV_PKT_DATA_REPLAYGAIN,
sizeof(*replaygain));
if (!replaygain)
return AVERROR(ENOMEM);
replaygain->track_gain = tg;
replaygain->track_peak = tp;
replaygain->album_gain = ag;
replaygain->album_peak = ap;
return 0;
}
| false | FFmpeg | 7f4ec4364bc4a73036660c1c6a3c4801db524e9e |
24,455 | static void dead_tmp(TCGv tmp)
{
int i;
num_temps--;
i = num_temps;
if (GET_TCGV(temps[i]) == GET_TCGV(tmp))
return;
/* Shuffle this temp to the last slot. */
while (GET_TCGV(temps[i]) != GET_TCGV(tmp))
i--;
while (i < num_temps) {
temps[i] = temps[i + 1];
i++;
}
temps[i] = tmp;
}
| false | qemu | a7812ae412311d7d47f8aa85656faadac9d64b56 |
24,456 | pvscsi_update_irq_status(PVSCSIState *s)
{
PCIDevice *d = PCI_DEVICE(s);
bool should_raise = s->reg_interrupt_enabled & s->reg_interrupt_status;
trace_pvscsi_update_irq_level(should_raise, s->reg_interrupt_enabled,
s->reg_interrupt_status);
if (s->msi_used && msi_enabled(d)) {
if (should_raise) {
trace_pvscsi_update_irq_msi();
msi_notify(d, PVSCSI_VECTOR_COMPLETION);
}
return;
}
pci_set_irq(d, !!should_raise);
}
| false | qemu | 269fe4c3ab0cf29329317eb868f8ec90ac761b41 |
24,457 | static inline void check_io(CPUX86State *env, int addr, int size)
{
int io_offset, val, mask;
/* TSS must be a valid 32 bit one */
if (!(env->tr.flags & DESC_P_MASK) ||
((env->tr.flags >> DESC_TYPE_SHIFT) & 0xf) != 9 ||
env->tr.limit < 103) {
goto fail;
}
io_offset = cpu_lduw_kernel(env, env->tr.base + 0x66);
io_offset += (addr >> 3);
/* Note: the check needs two bytes */
if ((io_offset + 1) > env->tr.limit) {
goto fail;
}
val = cpu_lduw_kernel(env, env->tr.base + io_offset);
val >>= (addr & 7);
mask = (1 << size) - 1;
/* all bits must be zero to allow the I/O */
if ((val & mask) != 0) {
fail:
raise_exception_err(env, EXCP0D_GPF, 0);
}
}
| false | qemu | 81cf8d8adc64203567e03326c13ea4abec9fe5df |
24,458 | void page_set_flags(target_ulong start, target_ulong end, int flags)
{
PageDesc *p;
target_ulong addr;
/* mmap_lock should already be held. */
start = start & TARGET_PAGE_MASK;
end = TARGET_PAGE_ALIGN(end);
if (flags & PAGE_WRITE)
flags |= PAGE_WRITE_ORG;
for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
p = page_find_alloc(addr >> TARGET_PAGE_BITS);
/* We may be called for host regions that are outside guest
address space. */
if (!p)
return;
/* if the write protection is set, then we invalidate the code
inside */
if (!(p->flags & PAGE_WRITE) &&
(flags & PAGE_WRITE) &&
p->first_tb) {
tb_invalidate_phys_page(addr, 0, NULL);
}
p->flags = flags;
}
}
| false | qemu | 376a790970de7e84170ee9360b6ff53ecfa4a1be |
24,459 | static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
int parse_extradata)
{
AVCodecContext *const avctx = h->avctx;
H264SliceContext *sl;
int buf_index;
unsigned context_count;
int next_avc;
int nals_needed = 0; ///< number of NALs that need decoding before the next frame thread starts
int nal_index;
int idr_cleared=0;
int ret = 0;
h->nal_unit_type= 0;
if(!h->slice_context_count)
h->slice_context_count= 1;
h->max_contexts = h->slice_context_count;
if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS)) {
h->current_slice = 0;
if (!h->first_field)
h->cur_pic_ptr = NULL;
ff_h264_reset_sei(h);
if (h->nal_length_size == 4) {
if (buf_size > 8 && AV_RB32(buf) == 1 && AV_RB32(buf+5) > (unsigned)buf_size) {
h->is_avc = 0;
}else if(buf_size > 3 && AV_RB32(buf) > 1 && AV_RB32(buf) <= (unsigned)buf_size)
h->is_avc = 1;
if (avctx->active_thread_type & FF_THREAD_FRAME)
nals_needed = get_last_needed_nal(h, buf, buf_size);
{
buf_index = 0;
next_avc = h->is_avc ? 0 : buf_size;
nal_index = 0;
for (;;) {
int consumed;
int dst_length;
int bit_length;
const uint8_t *ptr;
int nalsize = 0;
int err;
if (buf_index >= next_avc) {
nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
if (nalsize < 0)
break;
next_avc = buf_index + nalsize;
} else {
buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
if (buf_index >= buf_size)
break;
if (buf_index >= next_avc)
continue;
sl = &h->slice_ctx[context_count];
ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length,
&consumed, next_avc - buf_index);
if (!ptr || dst_length < 0) {
ret = -1;
bit_length = get_bit_length(h, buf, ptr, dst_length,
buf_index + consumed, next_avc);
if (h->avctx->debug & FF_DEBUG_STARTCODE)
av_log(h->avctx, AV_LOG_DEBUG,
"NAL %d/%d at %d/%d length %d\n",
h->nal_unit_type, h->nal_ref_idc, buf_index, buf_size, dst_length);
if (h->is_avc && (nalsize != consumed) && nalsize)
av_log(h->avctx, AV_LOG_DEBUG,
"AVC: Consumed only %d bytes instead of %d\n",
consumed, nalsize);
buf_index += consumed;
nal_index++;
if (avctx->skip_frame >= AVDISCARD_NONREF &&
h->nal_ref_idc == 0 &&
h->nal_unit_type != NAL_SEI)
continue;
again:
if ( (!(avctx->active_thread_type & FF_THREAD_FRAME) || nals_needed >= nal_index)
&& !h->current_slice)
h->au_pps_id = -1;
/* Ignore per frame NAL unit type during extradata
* parsing. Decoding slices is not possible in codec init
* with frame-mt */
if (parse_extradata) {
switch (h->nal_unit_type) {
case NAL_IDR_SLICE:
case NAL_SLICE:
case NAL_DPA:
case NAL_DPB:
case NAL_DPC:
av_log(h->avctx, AV_LOG_WARNING,
"Ignoring NAL %d in global header/extradata\n",
h->nal_unit_type);
// fall through to next case
case NAL_AUXILIARY_SLICE:
h->nal_unit_type = NAL_FF_IGNORE;
err = 0;
switch (h->nal_unit_type) {
case NAL_IDR_SLICE:
if ((ptr[0] & 0xFC) == 0x98) {
av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n");
h->next_outputed_poc = INT_MIN;
ret = -1;
if (h->nal_unit_type != NAL_IDR_SLICE) {
av_log(h->avctx, AV_LOG_ERROR,
"Invalid mix of idr and non-idr slices\n");
ret = -1;
if(!idr_cleared) {
if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) {
av_log(h, AV_LOG_ERROR, "invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n");
ret = AVERROR_INVALIDDATA;
idr(h); // FIXME ensure we don't lose some frames if there is reordering
idr_cleared = 1;
h->has_recovery_point = 1;
case NAL_SLICE:
init_get_bits(&sl->gb, ptr, bit_length);
if ((err = ff_h264_decode_slice_header(h, sl)))
break;
if (h->sei_recovery_frame_cnt >= 0) {
if (h->frame_num != h->sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I)
h->valid_recovery_point = 1;
if ( h->recovery_frame < 0
|| ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt) {
h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
((1 << h->sps.log2_max_frame_num) - 1);
if (!h->valid_recovery_point)
h->recovery_frame = h->frame_num;
h->cur_pic_ptr->f.key_frame |=
(h->nal_unit_type == NAL_IDR_SLICE);
if (h->nal_unit_type == NAL_IDR_SLICE ||
h->recovery_frame == h->frame_num) {
h->recovery_frame = -1;
h->cur_pic_ptr->recovered = 1;
// If we have an IDR, all frames after it in decoded order are
// "recovered".
if (h->nal_unit_type == NAL_IDR_SLICE)
h->frame_recovered |= FRAME_RECOVERED_IDR;
h->frame_recovered |= 3*!!(avctx->flags2 & CODEC_FLAG2_SHOW_ALL);
h->frame_recovered |= 3*!!(avctx->flags & CODEC_FLAG_OUTPUT_CORRUPT);
#if 1
h->cur_pic_ptr->recovered |= h->frame_recovered;
#else
h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);
#endif
if (h->current_slice == 1) {
if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS))
decode_postinit(h, nal_index >= nals_needed);
if (h->avctx->hwaccel &&
(ret = h->avctx->hwaccel->start_frame(h->avctx, buf, buf_size)) < 0)
if (CONFIG_H264_VDPAU_DECODER &&
h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
ff_vdpau_h264_picture_start(h);
if (sl->redundant_pic_count == 0) {
if (avctx->hwaccel) {
ret = avctx->hwaccel->decode_slice(avctx,
&buf[buf_index - consumed],
consumed);
if (ret < 0)
} else if (CONFIG_H264_VDPAU_DECODER &&
h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {
ff_vdpau_add_data_chunk(h->cur_pic_ptr->f.data[0],
start_code,
sizeof(start_code));
ff_vdpau_add_data_chunk(h->cur_pic_ptr->f.data[0],
&buf[buf_index - consumed],
consumed);
} else
context_count++;
break;
case NAL_DPA:
case NAL_DPB:
case NAL_DPC:
avpriv_request_sample(avctx, "data partitioning");
ret = AVERROR(ENOSYS);
break;
case NAL_SEI:
init_get_bits(&h->gb, ptr, bit_length);
ret = ff_h264_decode_sei(h);
break;
case NAL_SPS:
init_get_bits(&h->gb, ptr, bit_length);
if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? nalsize : 1)) {
av_log(h->avctx, AV_LOG_DEBUG,
"SPS decoding failure, trying again with the complete NAL\n");
if (h->is_avc)
av_assert0(next_avc - buf_index + consumed == nalsize);
if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
break;
init_get_bits(&h->gb, &buf[buf_index + 1 - consumed],
8*(next_avc - buf_index + consumed - 1));
ff_h264_decode_seq_parameter_set(h);
break;
case NAL_PPS:
init_get_bits(&h->gb, ptr, bit_length);
ret = ff_h264_decode_picture_parameter_set(h, bit_length);
break;
case NAL_AUD:
case NAL_END_SEQUENCE:
case NAL_END_STREAM:
case NAL_FILLER_DATA:
case NAL_SPS_EXT:
case NAL_AUXILIARY_SLICE:
break;
case NAL_FF_IGNORE:
break;
default:
av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
h->nal_unit_type, bit_length);
if (context_count == h->max_contexts) {
ret = ff_h264_execute_decode_slices(h, context_count);
if (err < 0 || err == SLICE_SKIPED) {
if (err < 0)
av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n");
sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;
} else if (err == SLICE_SINGLETHREAD) {
/* Slice could not be decoded in parallel mode, restart. Note
* that rbsp_buffer is not transferred, but since we no longer
* run in parallel mode this should not be an issue. */
sl = &h->slice_ctx[0];
goto again;
if (context_count) {
ret = ff_h264_execute_decode_slices(h, context_count);
ret = 0;
end:
/* clean up */
if (h->cur_pic_ptr && !h->droppable) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
h->picture_structure == PICT_BOTTOM_FIELD);
return (ret < 0) ? ret : buf_index;
| true | FFmpeg | c4b2017ba66e1623da9f527704c61c86a6e74844 |
24,460 | static int check_tag(AVIOContext *s, int offset, unsigned int len)
{
char tag[4];
if (len > 4 ||
avio_seek(s, offset, SEEK_SET) < 0 ||
avio_read(s, tag, len) < len)
return -1;
else if (!AV_RB32(tag) || is_tag(tag, len))
return 1;
return 0;
}
| true | FFmpeg | 0382c94f13b4b20456b7259e90b170dc020419b8 |
24,461 | static void fw_cfg_bootsplash(FWCfgState *s)
{
int boot_splash_time = -1;
const char *boot_splash_filename = NULL;
char *p;
char *filename, *file_data;
int file_size;
int file_type = -1;
const char *temp;
/* get user configuration */
QemuOptsList *plist = qemu_find_opts("boot-opts");
QemuOpts *opts = QTAILQ_FIRST(&plist->head);
if (opts != NULL) {
temp = qemu_opt_get(opts, "splash");
if (temp != NULL) {
boot_splash_filename = temp;
}
temp = qemu_opt_get(opts, "splash-time");
if (temp != NULL) {
p = (char *)temp;
boot_splash_time = strtol(p, (char **)&p, 10);
}
}
/* insert splash time if user configurated */
if (boot_splash_time >= 0) {
/* validate the input */
if (boot_splash_time > 0xffff) {
error_report("splash time is big than 65535, force it to 65535.");
boot_splash_time = 0xffff;
}
/* use little endian format */
qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
}
/* insert splash file if user configurated */
if (boot_splash_filename != NULL) {
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
if (filename == NULL) {
error_report("failed to find file '%s'.", boot_splash_filename);
return;
}
/* loading file data */
file_data = read_splashfile(filename, &file_size, &file_type);
if (file_data == NULL) {
g_free(filename);
return;
}
if (boot_splash_filedata != NULL) {
g_free(boot_splash_filedata);
}
boot_splash_filedata = (uint8_t *)file_data;
boot_splash_filedata_size = file_size;
/* insert data */
if (file_type == JPG_FILE) {
fw_cfg_add_file(s, "bootsplash.jpg",
boot_splash_filedata, boot_splash_filedata_size);
} else {
fw_cfg_add_file(s, "bootsplash.bmp",
boot_splash_filedata, boot_splash_filedata_size);
}
g_free(filename);
}
}
| true | qemu | d09acb9b5ef0bb4fa94d3d459919a6ebaf8804bc |
24,462 | static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
{
ssize_t nbytes;
char *buf;
if (!(aiocb->aio_type & QEMU_AIO_MISALIGNED)) {
/*
* If there is just a single buffer, and it is properly aligned
* we can just use plain pread/pwrite without any problems.
*/
if (aiocb->aio_niov == 1) {
return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base);
}
/*
* We have more than one iovec, and all are properly aligned.
*
* Try preadv/pwritev first and fall back to linearizing the
* buffer if it's not supported.
*/
if (preadv_present) {
nbytes = handle_aiocb_rw_vector(aiocb);
if (nbytes == aiocb->aio_nbytes ||
(nbytes < 0 && nbytes != -ENOSYS)) {
return nbytes;
}
preadv_present = false;
}
/*
* XXX(hch): short read/write. no easy way to handle the reminder
* using these interfaces. For now retry using plain
* pread/pwrite?
*/
}
/*
* Ok, we have to do it the hard way, copy all segments into
* a single aligned buffer.
*/
buf = qemu_blockalign(aiocb->bs, aiocb->aio_nbytes);
if (aiocb->aio_type & QEMU_AIO_WRITE) {
char *p = buf;
int i;
for (i = 0; i < aiocb->aio_niov; ++i) {
memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_len);
p += aiocb->aio_iov[i].iov_len;
}
assert(p - buf == aiocb->aio_nbytes);
}
nbytes = handle_aiocb_rw_linear(aiocb, buf);
if (!(aiocb->aio_type & QEMU_AIO_WRITE)) {
char *p = buf;
size_t count = aiocb->aio_nbytes, copy;
int i;
for (i = 0; i < aiocb->aio_niov && count; ++i) {
copy = count;
if (copy > aiocb->aio_iov[i].iov_len) {
copy = aiocb->aio_iov[i].iov_len;
}
memcpy(aiocb->aio_iov[i].iov_base, p, copy);
assert(count >= copy);
p += copy;
count -= copy;
}
assert(count == 0);
}
qemu_vfree(buf);
return nbytes;
}
| true | qemu | 50d4a858e62b1d864227d13f07d2c79c118d046a |
24,463 | static inline void set_txint(ChannelState *s)
{
s->txint = 1;
if (!s->rxint_under_svc) {
s->txint_under_svc = 1;
if (s->chn == chn_a) {
s->rregs[R_INTR] |= INTR_TXINTA;
if (s->wregs[W_MINTR] & MINTR_STATUSHI)
s->otherchn->rregs[R_IVEC] = IVEC_HITXINTA;
else
s->otherchn->rregs[R_IVEC] = IVEC_LOTXINTA;
} else {
s->rregs[R_IVEC] = IVEC_TXINTB;
s->otherchn->rregs[R_INTR] |= INTR_TXINTB;
}
escc_update_irq(s);
}
}
| true | qemu | f53671c054ba0b5d5b10e2a7294786fa2f73479e |
24,464 | static int rm_probe(AVProbeData *p)
{
/* check file header */
if (p->buf_size <= 32)
return 0;
if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
p->buf[2] == 'M' && p->buf[3] == 'F' &&
p->buf[4] == 0 && p->buf[5] == 0) ||
(p->buf[0] == '.' && p->buf[1] == 'r' &&
p->buf[2] == 'a' && p->buf[3] == 0xfd))
return AVPROBE_SCORE_MAX;
else
return 0;
}
| false | FFmpeg | 87e8788680e16c51f6048af26f3f7830c35207a5 |
24,465 | static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
{
int count = ffio_read_varlen(bc);
int skip_start = 0;
int skip_end = 0;
int channels = 0;
int64_t channel_layout = 0;
int sample_rate = 0;
int width = 0;
int height = 0;
int i;
for (i=0; i<count; i++) {
uint8_t name[256], str_value[256], type_str[256];
int value;
if (avio_tell(bc) >= maxpos)
return AVERROR_INVALIDDATA;
get_str(bc, name, sizeof(name));
value = get_s(bc);
if (value == -1) {
get_str(bc, str_value, sizeof(str_value));
av_log(s, AV_LOG_WARNING, "Unknown string %s / %s\n", name, str_value);
} else if (value == -2) {
uint8_t *dst = NULL;
int64_t v64, value_len;
get_str(bc, type_str, sizeof(type_str));
value_len = ffio_read_varlen(bc);
if (avio_tell(bc) + value_len >= maxpos)
return AVERROR_INVALIDDATA;
if (!strcmp(name, "Palette")) {
dst = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, value_len);
} else if (!strcmp(name, "Extradata")) {
dst = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, value_len);
} else if (sscanf(name, "CodecSpecificSide%"SCNd64"", &v64) == 1) {
dst = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, value_len + 8);
if(!dst)
return AVERROR(ENOMEM);
AV_WB64(dst, v64);
dst += 8;
} else if (!strcmp(name, "ChannelLayout") && value_len == 8) {
channel_layout = avio_rl64(bc);
continue;
} else {
av_log(s, AV_LOG_WARNING, "Unknown data %s / %s\n", name, type_str);
avio_skip(bc, value_len);
continue;
}
if(!dst)
return AVERROR(ENOMEM);
avio_read(bc, dst, value_len);
} else if (value == -3) {
value = get_s(bc);
} else if (value == -4) {
value = ffio_read_varlen(bc);
} else if (value < -4) {
get_s(bc);
} else {
if (!strcmp(name, "SkipStart")) {
skip_start = value;
} else if (!strcmp(name, "SkipEnd")) {
skip_end = value;
} else if (!strcmp(name, "Channels")) {
channels = value;
} else if (!strcmp(name, "SampleRate")) {
sample_rate = value;
} else if (!strcmp(name, "Width")) {
width = value;
} else if (!strcmp(name, "Height")) {
height = value;
} else {
av_log(s, AV_LOG_WARNING, "Unknown integer %s\n", name);
}
}
}
if (channels || channel_layout || sample_rate || width || height) {
uint8_t *dst = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, 28);
if (!dst)
return AVERROR(ENOMEM);
bytestream_put_le32(&dst,
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT*(!!channels) +
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT*(!!channel_layout) +
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE*(!!sample_rate) +
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS*(!!(width|height))
);
if (channels)
bytestream_put_le32(&dst, channels);
if (channel_layout)
bytestream_put_le64(&dst, channel_layout);
if (sample_rate)
bytestream_put_le32(&dst, sample_rate);
if (width || height){
bytestream_put_le32(&dst, width);
bytestream_put_le32(&dst, height);
}
}
if (skip_start || skip_end) {
uint8_t *dst = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
if (!dst)
return AVERROR(ENOMEM);
AV_WL32(dst, skip_start);
AV_WL32(dst+4, skip_end);
}
return 0;
}
| false | FFmpeg | bb23a15df507440deb0dcf25099d321d0f73dc28 |
24,466 | static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
const float *la, int channel, int prev_type)
{
AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
AacPsyChannel *pch = &pctx->ch[channel];
int grouping = 0;
int uselongblock = 1;
int attacks[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
float clippings[AAC_NUM_BLOCKS_SHORT];
int i;
FFPsyWindowInfo wi = { { 0 } };
if (la) {
float hpfsmpl[AAC_BLOCK_SIZE_LONG];
float const *pf = hpfsmpl;
float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN);
int att_sum = 0;
/* LAME comment: apply high pass filter of fs/4 */
psy_hp_filter(firbuf, hpfsmpl, psy_fir_coeffs);
/* Calculate the energies of each sub-shortblock */
for (i = 0; i < PSY_LAME_NUM_SUBBLOCKS; i++) {
energy_subshort[i] = pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS)];
assert(pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)] > 0);
attack_intensity[i] = energy_subshort[i] / pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)];
energy_short[0] += energy_subshort[i];
}
for (i = 0; i < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; i++) {
float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS);
float p = 1.0f;
for (; pf < pfe; pf++)
p = FFMAX(p, fabsf(*pf));
pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
/* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
* Obviously the 3 and 2 have some significance, or this would be just [i + 1]
* (which is what we use here). What the 3 stands for is ambiguous, as it is both
* number of short blocks, and the number of sub-short blocks.
* It seems that LAME is comparing each sub-block to sub-block + 1 in the
* previous block.
*/
if (p > energy_subshort[i + 1])
p = p / energy_subshort[i + 1];
else if (energy_subshort[i + 1] > p * 10.0f)
p = energy_subshort[i + 1] / (p * 10.0f);
else
p = 0.0;
attack_intensity[i + PSY_LAME_NUM_SUBBLOCKS] = p;
}
/* compare energy between sub-short blocks */
for (i = 0; i < (AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS; i++)
if (!attacks[i / PSY_LAME_NUM_SUBBLOCKS])
if (attack_intensity[i] > pch->attack_threshold)
attacks[i / PSY_LAME_NUM_SUBBLOCKS] = (i % PSY_LAME_NUM_SUBBLOCKS) + 1;
/* should have energy change between short blocks, in order to avoid periodic signals */
/* Good samples to show the effect are Trumpet test songs */
/* GB: tuned (1) to avoid too many short blocks for test sample TRUMPET */
/* RH: tuned (2) to let enough short blocks through for test sample FSOL and SNAPS */
for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++) {
float const u = energy_short[i - 1];
float const v = energy_short[i];
float const m = FFMAX(u, v);
if (m < 40000) { /* (2) */
if (u < 1.7f * v && v < 1.7f * u) { /* (1) */
if (i == 1 && attacks[0] < attacks[i])
attacks[0] = 0;
attacks[i] = 0;
}
}
att_sum += attacks[i];
}
if (attacks[0] <= pch->prev_attack)
attacks[0] = 0;
att_sum += attacks[0];
/* 3 below indicates the previous attack happened in the last sub-block of the previous sequence */
if (pch->prev_attack == 3 || att_sum) {
uselongblock = 0;
for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++)
if (attacks[i] && attacks[i-1])
attacks[i] = 0;
}
} else {
/* We have no lookahead info, so just use same type as the previous sequence. */
uselongblock = !(prev_type == EIGHT_SHORT_SEQUENCE);
}
lame_apply_block_type(pch, &wi, uselongblock);
/* Calculate input sample maximums and evaluate clipping risk */
if (audio) {
for (i = 0; i < AAC_NUM_BLOCKS_SHORT; i++) {
const float *wbuf = audio + i * AAC_BLOCK_SIZE_SHORT;
float max = 0;
int j;
for (j = 0; j < AAC_BLOCK_SIZE_SHORT; j++)
max = FFMAX(max, fabsf(wbuf[j]));
clippings[i] = max;
}
} else {
for (i = 0; i < 8; i++)
clippings[i] = 0;
}
wi.window_type[1] = prev_type;
if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) {
float clipping = 0.0f;
wi.num_windows = 1;
wi.grouping[0] = 1;
if (wi.window_type[0] == LONG_START_SEQUENCE)
wi.window_shape = 0;
else
wi.window_shape = 1;
for (i = 0; i < 8; i++)
clipping = FFMAX(clipping, clippings[i]);
wi.clipping[0] = clipping;
} else {
int lastgrp = 0;
wi.num_windows = 8;
wi.window_shape = 0;
for (i = 0; i < 8; i++) {
if (!((pch->next_grouping >> i) & 1))
lastgrp = i;
wi.grouping[lastgrp]++;
}
for (i = 0; i < 8; i += wi.grouping[i]) {
int w;
float clipping = 0.0f;
for (w = 0; w < wi.grouping[i]; w++)
clipping = FFMAX(clipping, clippings[i+w]);
for (w = 0; w < wi.grouping[i]; w++)
wi.clipping[i+w] = clipping;
}
}
/* Determine grouping, based on the location of the first attack, and save for
* the next frame.
* FIXME: Move this to analysis.
* TODO: Tune groupings depending on attack location
* TODO: Handle more than one attack in a group
*/
for (i = 0; i < 9; i++) {
if (attacks[i]) {
grouping = i;
break;
}
}
pch->next_grouping = window_grouping[grouping];
pch->prev_attack = attacks[8];
return wi;
}
| false | FFmpeg | 8005b6de4f88c9e3739a3a4ceda4288804788df9 |
24,467 | static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
long width, long height,
long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
{
long y;
const long chromWidth= width>>1;
for(y=0; y<height; y++)
{
#ifdef HAVE_MMX
//FIXME handle 2 lines a once (fewer prefetch, reuse some chrom, but very likely limited by mem anyway)
asm volatile(
"xor %%"REG_a", %%"REG_a" \n\t"
ASMALIGN16
"1: \n\t"
PREFETCH" 32(%1, %%"REG_a", 2) \n\t"
PREFETCH" 32(%2, %%"REG_a") \n\t"
PREFETCH" 32(%3, %%"REG_a") \n\t"
"movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0)
"movq %%mm0, %%mm2 \n\t" // U(0)
"movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0)
"punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0)
"punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8)
"movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0)
"movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8)
"movq %%mm3, %%mm4 \n\t" // Y(0)
"movq %%mm5, %%mm6 \n\t" // Y(8)
"punpcklbw %%mm0, %%mm3 \n\t" // YUYV YUYV(0)
"punpckhbw %%mm0, %%mm4 \n\t" // YUYV YUYV(4)
"punpcklbw %%mm2, %%mm5 \n\t" // YUYV YUYV(8)
"punpckhbw %%mm2, %%mm6 \n\t" // YUYV YUYV(12)
MOVNTQ" %%mm3, (%0, %%"REG_a", 4)\n\t"
MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4)\n\t"
MOVNTQ" %%mm5, 16(%0, %%"REG_a", 4)\n\t"
MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4)\n\t"
"add $8, %%"REG_a" \n\t"
"cmp %4, %%"REG_a" \n\t"
" jb 1b \n\t"
::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth)
: "%"REG_a
);
#else
#if defined ARCH_ALPHA && defined HAVE_MVI
#define pl2yuy2(n) \
y1 = yc[n]; \
y2 = yc2[n]; \
u = uc[n]; \
v = vc[n]; \
asm("unpkbw %1, %0" : "=r"(y1) : "r"(y1)); \
asm("unpkbw %1, %0" : "=r"(y2) : "r"(y2)); \
asm("unpkbl %1, %0" : "=r"(u) : "r"(u)); \
asm("unpkbl %1, %0" : "=r"(v) : "r"(v)); \
yuv1 = (u << 8) + (v << 24); \
yuv2 = yuv1 + y2; \
yuv1 += y1; \
qdst[n] = yuv1; \
qdst2[n] = yuv2;
int i;
uint64_t *qdst = (uint64_t *) dst;
uint64_t *qdst2 = (uint64_t *) (dst + dstStride);
const uint32_t *yc = (uint32_t *) ysrc;
const uint32_t *yc2 = (uint32_t *) (ysrc + lumStride);
const uint16_t *uc = (uint16_t*) usrc, *vc = (uint16_t*) vsrc;
for(i = 0; i < chromWidth; i += 8){
uint64_t y1, y2, yuv1, yuv2;
uint64_t u, v;
/* Prefetch */
asm("ldq $31,64(%0)" :: "r"(yc));
asm("ldq $31,64(%0)" :: "r"(yc2));
asm("ldq $31,64(%0)" :: "r"(uc));
asm("ldq $31,64(%0)" :: "r"(vc));
pl2yuy2(0);
pl2yuy2(1);
pl2yuy2(2);
pl2yuy2(3);
yc += 4;
yc2 += 4;
uc += 4;
vc += 4;
qdst += 4;
qdst2 += 4;
}
y++;
ysrc += lumStride;
dst += dstStride;
#elif __WORDSIZE >= 64
int i;
uint64_t *ldst = (uint64_t *) dst;
const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
for(i = 0; i < chromWidth; i += 2){
uint64_t k, l;
k = yc[0] + (uc[0] << 8) +
(yc[1] << 16) + (vc[0] << 24);
l = yc[2] + (uc[1] << 8) +
(yc[3] << 16) + (vc[1] << 24);
*ldst++ = k + (l << 32);
yc += 4;
uc += 2;
vc += 2;
}
#else
int i, *idst = (int32_t *) dst;
const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
for(i = 0; i < chromWidth; i++){
#ifdef WORDS_BIGENDIAN
*idst++ = (yc[0] << 24)+ (uc[0] << 16) +
(yc[1] << 8) + (vc[0] << 0);
#else
*idst++ = yc[0] + (uc[0] << 8) +
(yc[1] << 16) + (vc[0] << 24);
#endif
yc += 2;
uc++;
vc++;
}
#endif
#endif
if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
{
usrc += chromStride;
vsrc += chromStride;
}
ysrc += lumStride;
dst += dstStride;
}
#ifdef HAVE_MMX
asm( EMMS" \n\t"
SFENCE" \n\t"
:::"memory");
#endif
}
| false | FFmpeg | 4bff9ef9d0781c4de228bf1f85634d2706fc589b |
24,468 | static int ass_get_duration(const uint8_t *p)
{
int sh, sm, ss, sc, eh, em, es, ec;
uint64_t start, end;
if (sscanf(p, "%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
&sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
return 0;
start = 3600000 * sh + 60000 * sm + 1000 * ss + 10 * sc;
end = 3600000 * eh + 60000 * em + 1000 * es + 10 * ec;
return end - start;
}
| false | FFmpeg | 69c1fe7c9c9bc85eebfc02c6a19caf7e88cd74ff |
24,470 | static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
struct msghdr *msgh)
{
struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
abi_long msg_controllen;
abi_ulong target_cmsg_addr;
struct target_cmsghdr *target_cmsg, *target_cmsg_start;
socklen_t space = 0;
msg_controllen = tswapal(target_msgh->msg_controllen);
if (msg_controllen < sizeof (struct target_cmsghdr))
goto the_end;
target_cmsg_addr = tswapal(target_msgh->msg_control);
target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0);
target_cmsg_start = target_cmsg;
if (!target_cmsg)
return -TARGET_EFAULT;
while (cmsg && target_cmsg) {
void *data = CMSG_DATA(cmsg);
void *target_data = TARGET_CMSG_DATA(target_cmsg);
int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr));
int tgt_len, tgt_space;
/* We never copy a half-header but may copy half-data;
* this is Linux's behaviour in put_cmsg(). Note that
* truncation here is a guest problem (which we report
* to the guest via the CTRUNC bit), unlike truncation
* in target_to_host_cmsg, which is a QEMU bug.
*/
if (msg_controllen < sizeof(struct cmsghdr)) {
target_msgh->msg_flags |= tswap32(MSG_CTRUNC);
break;
}
if (cmsg->cmsg_level == SOL_SOCKET) {
target_cmsg->cmsg_level = tswap32(TARGET_SOL_SOCKET);
} else {
target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
}
target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
tgt_len = TARGET_CMSG_LEN(len);
/* Payload types which need a different size of payload on
* the target must adjust tgt_len here.
*/
switch (cmsg->cmsg_level) {
case SOL_SOCKET:
switch (cmsg->cmsg_type) {
case SO_TIMESTAMP:
tgt_len = sizeof(struct target_timeval);
break;
default:
break;
}
default:
break;
}
if (msg_controllen < tgt_len) {
target_msgh->msg_flags |= tswap32(MSG_CTRUNC);
tgt_len = msg_controllen;
}
/* We must now copy-and-convert len bytes of payload
* into tgt_len bytes of destination space. Bear in mind
* that in both source and destination we may be dealing
* with a truncated value!
*/
switch (cmsg->cmsg_level) {
case SOL_SOCKET:
switch (cmsg->cmsg_type) {
case SCM_RIGHTS:
{
int *fd = (int *)data;
int *target_fd = (int *)target_data;
int i, numfds = tgt_len / sizeof(int);
for (i = 0; i < numfds; i++) {
__put_user(fd[i], target_fd + i);
}
break;
}
case SO_TIMESTAMP:
{
struct timeval *tv = (struct timeval *)data;
struct target_timeval *target_tv =
(struct target_timeval *)target_data;
if (len != sizeof(struct timeval) ||
tgt_len != sizeof(struct target_timeval)) {
goto unimplemented;
}
/* copy struct timeval to target */
__put_user(tv->tv_sec, &target_tv->tv_sec);
__put_user(tv->tv_usec, &target_tv->tv_usec);
break;
}
case SCM_CREDENTIALS:
{
struct ucred *cred = (struct ucred *)data;
struct target_ucred *target_cred =
(struct target_ucred *)target_data;
__put_user(cred->pid, &target_cred->pid);
__put_user(cred->uid, &target_cred->uid);
__put_user(cred->gid, &target_cred->gid);
break;
}
default:
goto unimplemented;
}
break;
case SOL_IP:
switch (cmsg->cmsg_type) {
case IP_TTL:
{
uint32_t *v = (uint32_t *)data;
uint32_t *t_int = (uint32_t *)target_data;
__put_user(*v, t_int);
break;
}
case IP_RECVERR:
{
struct errhdr_t {
struct sock_extended_err ee;
struct sockaddr_in offender;
};
struct errhdr_t *errh = (struct errhdr_t *)data;
struct errhdr_t *target_errh =
(struct errhdr_t *)target_data;
__put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
__put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
__put_user(errh->ee.ee_type, &target_errh->ee.ee_type);
__put_user(errh->ee.ee_code, &target_errh->ee.ee_code);
__put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad);
__put_user(errh->ee.ee_info, &target_errh->ee.ee_info);
__put_user(errh->ee.ee_data, &target_errh->ee.ee_data);
host_to_target_sockaddr((unsigned long) &target_errh->offender,
(void *) &errh->offender, sizeof(errh->offender));
break;
}
default:
goto unimplemented;
}
break;
case SOL_IPV6:
switch (cmsg->cmsg_type) {
case IPV6_HOPLIMIT:
{
uint32_t *v = (uint32_t *)data;
uint32_t *t_int = (uint32_t *)target_data;
__put_user(*v, t_int);
break;
}
case IPV6_RECVERR:
{
struct errhdr6_t {
struct sock_extended_err ee;
struct sockaddr_in6 offender;
};
struct errhdr6_t *errh = (struct errhdr6_t *)data;
struct errhdr6_t *target_errh =
(struct errhdr6_t *)target_data;
__put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
__put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
__put_user(errh->ee.ee_type, &target_errh->ee.ee_type);
__put_user(errh->ee.ee_code, &target_errh->ee.ee_code);
__put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad);
__put_user(errh->ee.ee_info, &target_errh->ee.ee_info);
__put_user(errh->ee.ee_data, &target_errh->ee.ee_data);
host_to_target_sockaddr((unsigned long) &target_errh->offender,
(void *) &errh->offender, sizeof(errh->offender));
break;
}
default:
goto unimplemented;
}
break;
default:
unimplemented:
gemu_log("Unsupported ancillary data: %d/%d\n",
cmsg->cmsg_level, cmsg->cmsg_type);
memcpy(target_data, data, MIN(len, tgt_len));
if (tgt_len > len) {
memset(target_data + len, 0, tgt_len - len);
}
}
target_cmsg->cmsg_len = tswapal(tgt_len);
tgt_space = TARGET_CMSG_SPACE(len);
if (msg_controllen < tgt_space) {
tgt_space = msg_controllen;
}
msg_controllen -= tgt_space;
space += tgt_space;
cmsg = CMSG_NXTHDR(msgh, cmsg);
target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg,
target_cmsg_start);
}
unlock_user(target_cmsg, target_cmsg_addr, space);
the_end:
target_msgh->msg_controllen = tswapal(space);
return 0;
}
| true | qemu | 7174970a94df10ee84143edc7c94a2472d654604 |
24,473 | static void ib700_pc_init(PCIBus *unused)
{
register_savevm("ib700_wdt", -1, 0, ib700_save, ib700_load, NULL);
register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, NULL);
register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, NULL);
}
| true | qemu | 09aaa1602f9381c0e0fb539390b1793e51bdfc7b |
24,474 | static int vscsi_srp_indirect_data(VSCSIState *s, vscsi_req *req,
uint8_t *buf, uint32_t len)
{
struct srp_direct_buf *td = &req->ind_desc->table_desc;
struct srp_direct_buf *md = req->cur_desc;
int rc = 0;
uint32_t llen, total = 0;
dprintf("VSCSI: indirect segment 0x%x bytes, td va=0x%llx len=0x%x\n",
len, (unsigned long long)td->va, td->len);
/* While we have data ... */
while (len) {
/* If we have a descriptor but it's empty, go fetch a new one */
if (md && md->len == 0) {
/* More local available, use one */
if (req->local_desc) {
md = ++req->cur_desc;
--req->local_desc;
--req->total_desc;
td->va += sizeof(struct srp_direct_buf);
} else {
md = req->cur_desc = NULL;
}
}
/* No descriptor at hand, fetch one */
if (!md) {
if (!req->total_desc) {
dprintf("VSCSI: Out of descriptors !\n");
break;
}
md = req->cur_desc = &req->ext_desc;
dprintf("VSCSI: Reading desc from 0x%llx\n",
(unsigned long long)td->va);
rc = spapr_tce_dma_read(&s->vdev, td->va, md,
sizeof(struct srp_direct_buf));
if (rc) {
dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", rc);
break;
}
vscsi_swap_desc(md);
td->va += sizeof(struct srp_direct_buf);
--req->total_desc;
}
dprintf("VSCSI: [desc va=0x%llx,len=0x%x] remaining=0x%x\n",
(unsigned long long)md->va, md->len, len);
/* Perform transfer */
llen = MIN(len, md->len);
if (req->writing) { /* writing = to device = reading from memory */
rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen);
} else {
rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen);
}
if (rc) {
dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", req->writing, rc);
break;
}
dprintf("VSCSI: data: %02x %02x %02x %02x...\n",
buf[0], buf[1], buf[2], buf[3]);
len -= llen;
buf += llen;
total += llen;
md->va += llen;
md->len -= llen;
}
return rc ? -1 : total;
}
| true | qemu | ad0ebb91cd8b5fdc4a583b03645677771f420a46 |
24,475 | static int decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
BinkAudioContext *s = avctx->priv_data;
AVFrame *frame = data;
GetBitContext *gb = &s->gb;
int ret, consumed = 0;
if (!get_bits_left(gb)) {
uint8_t *buf;
/* handle end-of-stream */
if (!avpkt->size) {
*got_frame_ptr = 0;
return 0;
}
if (avpkt->size < 4) {
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
buf = av_realloc(s->packet_buffer, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!buf)
return AVERROR(ENOMEM);
s->packet_buffer = buf;
memcpy(s->packet_buffer, avpkt->data, avpkt->size);
if ((ret = init_get_bits8(gb, s->packet_buffer, avpkt->size)) < 0)
return ret;
consumed = avpkt->size;
/* skip reported size */
skip_bits_long(gb, 32);
}
/* get output buffer */
frame->nb_samples = s->frame_len;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
if (decode_block(s, (float **)frame->extended_data,
avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) {
av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
return AVERROR_INVALIDDATA;
}
get_bits_align32(gb);
frame->nb_samples = s->block_size / avctx->channels;
*got_frame_ptr = 1;
return consumed;
} | true | FFmpeg | 07728a111583be6865b7ce2adea705af9d207588 |
24,476 | static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
uint8_t *state= &h->cabac_state[ctx_base];
int mb_type;
if(intra_slice){
MpegEncContext * const s = &h->s;
const int mba_xy = h->left_mb_xy[0];
const int mbb_xy = h->top_mb_xy;
int ctx=0;
if( h->slice_table[mba_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mba_xy] ) )
ctx++;
if( h->slice_table[mbb_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mbb_xy] ) )
ctx++;
if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 )
return 0; /* I4x4 */
state += 2;
}else{
if( get_cabac_noinline( &h->cabac, state ) == 0 )
return 0; /* I4x4 */
}
if( get_cabac_terminate( &h->cabac ) )
return 25; /* PCM */
mb_type = 1; /* I16x16 */
mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */
if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */
mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] );
mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] );
mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] );
return mb_type;
}
| false | FFmpeg | 5806e8cd1f60c67d936fa44dd4421428489503f5 |
24,477 | static int decode_p_picture_header(VC9Context *v)
{
/* INTERFRM, FRMCNT, RANGEREDFRM read in caller */
int lowquant, pqindex;
pqindex = get_bits(&v->gb, 5);
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = pquant_table[0][pqindex];
else
{
v->pq = pquant_table[v->quantizer_mode-1][pqindex];
}
if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits(&v->gb, 1);
av_log(v->avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n",
v->pq, v->halfpq);
if (v->extended_mv == 1) v->mvrange = get_prefix(&v->gb, 0, 3);
#if HAS_ADVANCED_PROFILE
if (v->profile > PROFILE_MAIN)
{
if (v->postprocflag) v->postproc = get_bits(&v->gb, 1);
}
else
#endif
if (v->multires) v->respic = get_bits(&v->gb, 2);
lowquant = (v->pquantizer>12) ? 0 : 1;
v->mv_mode = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 4)];
if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
{
v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 3)];
v->lumscale = get_bits(&v->gb, 6);
v->lumshift = get_bits(&v->gb, 6);
}
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV)
|| v->mv_mode == MV_PMODE_MIXED_MV)
{
if (bitplane_decoding(v->mv_type_mb_plane, v->width_mb,
v->height_mb, v) < 0)
return -1;
}
if (bitplane_decoding(v->skip_mb_plane, v->width_mb,
v->height_mb, v) < 0)
return -1;
/* Hopefully this is correct for P frames */
v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)];
v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)];
if (v->dquant)
{
av_log(v->avctx, AV_LOG_INFO, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
if (v->vstransform)
{
v->ttmbf = get_bits(&v->gb, 1);
if (v->ttmbf)
{
v->ttfrm = get_bits(&v->gb, 2);
av_log(v->avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
(v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
}
}
/* Epilog should be done in caller */
return 0;
}
| false | FFmpeg | e5540b3fd30367ce3cc33b2f34a04b660dbc4b38 |
24,479 | void ff_avg_h264_qpel8_mc12_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_midh_qrt_and_aver_dst_8w_msa(src - (2 * stride) - 2,
stride, dst, stride, 8, 0);
}
| false | FFmpeg | 72dbc610be3272ba36603f78a39cc2d2d8fe0cc3 |
24,480 | static void sbr_hf_assemble(float Y[2][38][64][2], const float X_high[64][40][2],
SpectralBandReplication *sbr, SBRData *ch_data,
const int e_a[2])
{
int e, i, j, m;
const int h_SL = 4 * !sbr->bs_smoothing_mode;
const int kx = sbr->kx[1];
const int m_max = sbr->m[1];
static const float h_smooth[5] = {
0.33333333333333,
0.30150283239582,
0.21816949906249,
0.11516383427084,
0.03183050093751,
};
static const int8_t phi[2][4] = {
{ 1, 0, -1, 0}, // real
{ 0, 1, 0, -1}, // imaginary
};
float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp;
int indexnoise = ch_data->f_indexnoise;
int indexsine = ch_data->f_indexsine;
memcpy(Y[0], Y[1], sizeof(Y[0]));
if (sbr->reset) {
for (i = 0; i < h_SL; i++) {
memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0]));
memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0]));
}
} else if (h_SL) {
memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0]));
memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0]));
}
for (e = 0; e < ch_data->bs_num_env; e++) {
for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
memcpy(g_temp[h_SL + i], sbr->gain[e], m_max * sizeof(sbr->gain[0][0]));
memcpy(q_temp[h_SL + i], sbr->q_m[e], m_max * sizeof(sbr->q_m[0][0]));
}
}
for (e = 0; e < ch_data->bs_num_env; e++) {
for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
int phi_sign = (1 - 2*(kx & 1));
if (h_SL && e != e_a[0] && e != e_a[1]) {
for (m = 0; m < m_max; m++) {
const int idx1 = i + h_SL;
float g_filt = 0.0f;
for (j = 0; j <= h_SL; j++)
g_filt += g_temp[idx1 - j][m] * h_smooth[j];
Y[1][i][m + kx][0] =
X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt;
Y[1][i][m + kx][1] =
X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt;
}
} else {
for (m = 0; m < m_max; m++) {
const float g_filt = g_temp[i + h_SL][m];
Y[1][i][m + kx][0] =
X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt;
Y[1][i][m + kx][1] =
X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt;
}
}
if (e != e_a[0] && e != e_a[1]) {
for (m = 0; m < m_max; m++) {
indexnoise = (indexnoise + 1) & 0x1ff;
if (sbr->s_m[e][m]) {
Y[1][i][m + kx][0] +=
sbr->s_m[e][m] * phi[0][indexsine];
Y[1][i][m + kx][1] +=
sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign);
} else {
float q_filt;
if (h_SL) {
const int idx1 = i + h_SL;
q_filt = 0.0f;
for (j = 0; j <= h_SL; j++)
q_filt += q_temp[idx1 - j][m] * h_smooth[j];
} else {
q_filt = q_temp[i][m];
}
Y[1][i][m + kx][0] +=
q_filt * sbr_noise_table[indexnoise][0];
Y[1][i][m + kx][1] +=
q_filt * sbr_noise_table[indexnoise][1];
}
phi_sign = -phi_sign;
}
} else {
indexnoise = (indexnoise + m_max) & 0x1ff;
for (m = 0; m < m_max; m++) {
Y[1][i][m + kx][0] +=
sbr->s_m[e][m] * phi[0][indexsine];
Y[1][i][m + kx][1] +=
sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign);
phi_sign = -phi_sign;
}
}
indexsine = (indexsine + 1) & 3;
}
}
ch_data->f_indexnoise = indexnoise;
ch_data->f_indexsine = indexsine;
}
| false | FFmpeg | aac46e088d67a390489af686b846dea4987d8ffb |
24,481 | int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
{
const SPS *sps = h->ps.sps;
const int max_frame_num = 1 << sps->log2_max_frame_num;
int field_poc[2];
h->frame_num_offset = h->prev_frame_num_offset;
if (h->frame_num < h->prev_frame_num)
h->frame_num_offset += max_frame_num;
if (sps->poc_type == 0) {
const int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
if (h->poc_lsb < h->prev_poc_lsb &&
h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb / 2)
h->poc_msb = h->prev_poc_msb + max_poc_lsb;
else if (h->poc_lsb > h->prev_poc_lsb &&
h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb / 2)
h->poc_msb = h->prev_poc_msb - max_poc_lsb;
else
h->poc_msb = h->prev_poc_msb;
field_poc[0] =
field_poc[1] = h->poc_msb + h->poc_lsb;
if (h->picture_structure == PICT_FRAME)
field_poc[1] += h->delta_poc_bottom;
} else if (sps->poc_type == 1) {
int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
int i;
if (sps->poc_cycle_length != 0)
abs_frame_num = h->frame_num_offset + h->frame_num;
else
abs_frame_num = 0;
if (h->nal_ref_idc == 0 && abs_frame_num > 0)
abs_frame_num--;
expected_delta_per_poc_cycle = 0;
for (i = 0; i < sps->poc_cycle_length; i++)
// FIXME integrate during sps parse
expected_delta_per_poc_cycle += sps->offset_for_ref_frame[i];
if (abs_frame_num > 0) {
int poc_cycle_cnt = (abs_frame_num - 1) / sps->poc_cycle_length;
int frame_num_in_poc_cycle = (abs_frame_num - 1) % sps->poc_cycle_length;
expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
for (i = 0; i <= frame_num_in_poc_cycle; i++)
expectedpoc = expectedpoc + sps->offset_for_ref_frame[i];
} else
expectedpoc = 0;
if (h->nal_ref_idc == 0)
expectedpoc = expectedpoc + sps->offset_for_non_ref_pic;
field_poc[0] = expectedpoc + h->delta_poc[0];
field_poc[1] = field_poc[0] + sps->offset_for_top_to_bottom_field;
if (h->picture_structure == PICT_FRAME)
field_poc[1] += h->delta_poc[1];
} else {
int poc = 2 * (h->frame_num_offset + h->frame_num);
if (!h->nal_ref_idc)
poc--;
field_poc[0] = poc;
field_poc[1] = poc;
}
if (h->picture_structure != PICT_BOTTOM_FIELD)
pic_field_poc[0] = field_poc[0];
if (h->picture_structure != PICT_TOP_FIELD)
pic_field_poc[1] = field_poc[1];
*pic_poc = FFMIN(pic_field_poc[0], pic_field_poc[1]);
return 0;
}
| false | FFmpeg | c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8 |
24,482 | static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
int64_t speed, int64_t granularity,
int64_t buf_size,
BlockdevOnError on_source_error,
BlockdevOnError on_target_error,
BlockDriverCompletionFunc *cb,
void *opaque, Error **errp,
const BlockJobDriver *driver,
bool is_none_mode, BlockDriverState *base)
{
MirrorBlockJob *s;
if (granularity == 0) {
/* Choose the default granularity based on the target file's cluster
* size, clamped between 4k and 64k. */
BlockDriverInfo bdi;
if (bdrv_get_info(target, &bdi) >= 0 && bdi.cluster_size != 0) {
granularity = MAX(4096, bdi.cluster_size);
granularity = MIN(65536, granularity);
} else {
granularity = 65536;
}
}
assert ((granularity & (granularity - 1)) == 0);
if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
!bdrv_iostatus_is_enabled(bs)) {
error_set(errp, QERR_INVALID_PARAMETER, "on-source-error");
return;
}
s = block_job_create(driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
}
s->on_source_error = on_source_error;
s->on_target_error = on_target_error;
s->target = target;
s->is_none_mode = is_none_mode;
s->base = base;
s->granularity = granularity;
s->buf_size = MAX(buf_size, granularity);
s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity);
bdrv_set_enable_write_cache(s->target, true);
bdrv_set_on_error(s->target, on_target_error, on_target_error);
bdrv_iostatus_enable(s->target);
s->common.co = qemu_coroutine_create(mirror_run);
trace_mirror_start(bs, s, s->common.co, opaque);
qemu_coroutine_enter(s->common.co, s);
}
| true | qemu | b8afb520e479e693c227aa39c2fb7670743e104f |
24,487 | static int sdp_parse_rtpmap(AVFormatContext *s,
AVStream *st, RTSPStream *rtsp_st,
int payload_type, const char *p)
{
AVCodecContext *codec = st->codec;
char buf[256];
int i;
AVCodec *c;
const char *c_name;
/* See if we can handle this kind of payload.
* The space should normally not be there but some Real streams or
* particular servers ("RealServer Version 6.1.3.970", see issue 1658)
* have a trailing space. */
get_word_sep(buf, sizeof(buf), "/ ", &p);
if (payload_type < RTP_PT_PRIVATE) {
/* We are in a standard case
* (from http://www.iana.org/assignments/rtp-parameters). */
codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type);
}
if (codec->codec_id == AV_CODEC_ID_NONE) {
RTPDynamicProtocolHandler *handler =
ff_rtp_handler_find_by_name(buf, codec->codec_type);
init_rtp_handler(handler, rtsp_st, st);
/* If no dynamic handler was found, check with the list of standard
* allocated types, if such a stream for some reason happens to
* use a private payload type. This isn't handled in rtpdec.c, since
* the format name from the rtpmap line never is passed into rtpdec. */
if (!rtsp_st->dynamic_handler)
codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type);
}
c = avcodec_find_decoder(codec->codec_id);
if (c && c->name)
c_name = c->name;
else
c_name = "(null)";
get_word_sep(buf, sizeof(buf), "/", &p);
i = atoi(buf);
switch (codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name);
codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE;
codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS;
if (i > 0) {
codec->sample_rate = i;
avpriv_set_pts_info(st, 32, 1, codec->sample_rate);
get_word_sep(buf, sizeof(buf), "/", &p);
i = atoi(buf);
if (i > 0)
codec->channels = i;
}
av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n",
codec->sample_rate);
av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n",
codec->channels);
break;
case AVMEDIA_TYPE_VIDEO:
av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name);
if (i > 0)
avpriv_set_pts_info(st, 32, 1, i);
break;
default:
break;
}
if (rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->init)
rtsp_st->dynamic_handler->init(s, st->index,
rtsp_st->dynamic_protocol_context);
return 0;
}
| true | FFmpeg | 078d43e23a7a3d64aafee8a58b380d3e139b3020 |
24,489 | void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
{
const int high_bit_depth = avctx->bits_per_raw_sample > 8;
// Common optimizations whether AltiVec is available or not
c->prefetch = prefetch_ppc;
if (!high_bit_depth) {
switch (check_dcbzl_effect()) {
case 32:
c->clear_blocks = clear_blocks_dcbz32_ppc;
break;
case 128:
c->clear_blocks = clear_blocks_dcbz128_ppc;
break;
default:
break;
}
}
#if HAVE_ALTIVEC
if(CONFIG_H264_DECODER) ff_dsputil_h264_init_ppc(c, avctx);
if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
ff_dsputil_init_altivec(c, avctx);
ff_float_init_altivec(c, avctx);
ff_int_init_altivec(c, avctx);
c->gmc1 = ff_gmc1_altivec;
#if CONFIG_ENCODERS
if (avctx->bits_per_raw_sample <= 8 &&
(avctx->dct_algo == FF_DCT_AUTO ||
avctx->dct_algo == FF_DCT_ALTIVEC)) {
c->fdct = ff_fdct_altivec;
}
#endif //CONFIG_ENCODERS
if (avctx->bits_per_raw_sample <= 8) {
if ((avctx->idct_algo == FF_IDCT_AUTO) ||
(avctx->idct_algo == FF_IDCT_ALTIVEC)) {
c->idct_put = ff_idct_put_altivec;
c->idct_add = ff_idct_add_altivec;
c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
}else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
avctx->idct_algo==FF_IDCT_VP3){
c->idct_put = ff_vp3_idct_put_altivec;
c->idct_add = ff_vp3_idct_add_altivec;
c->idct = ff_vp3_idct_altivec;
c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
}
}
}
#endif /* HAVE_ALTIVEC */
}
| false | FFmpeg | 28f9ab7029bd1a02f659995919f899f84ee7361b |
24,490 | bool hbitmap_get(const HBitmap *hb, uint64_t item)
{
/* Compute position and bit in the last layer. */
uint64_t pos = item >> hb->granularity;
unsigned long bit = 1UL << (pos & (BITS_PER_LONG - 1));
return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
} | true | qemu | 0e321191224c8cd137eef41da3257e096965c3d6 |
24,491 | static int ffm_is_avail_data(AVFormatContext *s, int size)
{
FFMContext *ffm = s->priv_data;
int64_t pos, avail_size;
int len;
len = ffm->packet_end - ffm->packet_ptr;
if (size <= len)
return 1;
pos = avio_tell(s->pb);
if (!ffm->write_index) {
if (pos == ffm->file_size)
return AVERROR_EOF;
avail_size = ffm->file_size - pos;
} else {
if (pos == ffm->write_index) {
/* exactly at the end of stream */
if (ffm->server_attached)
return AVERROR(EAGAIN);
else
return AVERROR_INVALIDDATA;
} else if (pos < ffm->write_index) {
avail_size = ffm->write_index - pos;
} else {
avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
}
}
avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
if (size <= avail_size)
return 1;
else if (ffm->server_attached)
return AVERROR(EAGAIN);
else
return AVERROR_INVALIDDATA;
}
| true | FFmpeg | f6e1c96730ebbcebbd0341329d51d3d3a36b4fa1 |
24,492 | int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
{
int arch = !!(key & FW_CFG_ARCH_LOCAL);
key &= FW_CFG_ENTRY_MASK;
if (key >= FW_CFG_MAX_ENTRY)
return 0;
s->entries[arch][key].data = data;
s->entries[arch][key].len = len;
return 1;
}
| true | qemu | 4cad3867b6df2c0826ae508a9fe15dd0b9d8936a |
Subsets and Splits