project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
FFmpeg | a99c273a3f91c3fd616b718c34a5848411ce0258 | 1 | static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
{
if (cid != ctx->cid) {
int index;
if ((index = ff_dnxhd_get_cid_table(cid)) < 0) {
av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %d\n", cid);
return -1;
}
if (ff_dnxhd_cid_table[index].bit_depth != ctx->bit_depth) {
av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n", ff_dnxhd_cid_table[index].bit_depth, ctx->bit_depth);
return AVERROR_INVALIDDATA;
}
ctx->cid_table = &ff_dnxhd_cid_table[index];
ff_free_vlc(&ctx->ac_vlc);
ff_free_vlc(&ctx->dc_vlc);
ff_free_vlc(&ctx->run_vlc);
init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257,
ctx->cid_table->ac_bits, 1, 1,
ctx->cid_table->ac_codes, 2, 2, 0);
init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->bit_depth + 4,
ctx->cid_table->dc_bits, 1, 1,
ctx->cid_table->dc_codes, 1, 1, 0);
init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62,
ctx->cid_table->run_bits, 1, 1,
ctx->cid_table->run_codes, 2, 2, 0);
ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct);
ctx->cid = cid;
}
return 0;
}
| 13,216 |
FFmpeg | c4ce8709676a6f0b41761093b0da08de72799ba9 | 1 | static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid) {
AVCodecContext *vcodec = vstream->codec;
switch(flv_codecid) {
case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break;
case FLV_CODECID_REALH263: vcodec->codec_id = CODEC_ID_H263 ; break; // Really mean it this time
case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break;
case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break;
case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ;
case FLV_CODECID_VP6A :
if(flv_codecid == FLV_CODECID_VP6A)
vcodec->codec_id = CODEC_ID_VP6A;
if(vcodec->extradata_size != 1) {
vcodec->extradata_size = 1;
vcodec->extradata = av_malloc(1);
}
vcodec->extradata[0] = avio_r8(s->pb);
return 1; // 1 byte body size adjustment for flv_read_packet()
case FLV_CODECID_H264:
vcodec->codec_id = CODEC_ID_H264;
return 3; // not 4, reading packet type will consume one byte
case FLV_CODECID_MPEG4:
vcodec->codec_id = CODEC_ID_MPEG4;
return 3;
default:
av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid);
vcodec->codec_tag = flv_codecid;
}
return 0;
}
| 13,217 |
FFmpeg | a70c27e813346a11e5fff3d329ecba82fb76826a | 1 | static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd)
{
int i, j;
uint8_t tmp[8*11], *tptr;
int m, r;
m = (mode & 3);
r = rnd;
src -= stride;
tptr = tmp;
for(j = 0; j < 11; j++) {
for(i = 0; i < 8; i++)
tptr[i] = vc1_mspel_filter(src + i, 1, m, r);
src += stride;
tptr += 8;
}
r = 1 - rnd;
m = (mode >> 2) & 3;
tptr = tmp + 8;
for(j = 0; j < 8; j++) {
for(i = 0; i < 8; i++)
dst[i] = vc1_mspel_filter(tptr + i, 8, m, r);
dst += stride;
tptr += 8;
}
}
| 13,218 |
FFmpeg | 1a3d142f1f1e65f554cba84d8a515684ecb390d0 | 1 | static av_cold int bfi_decode_init(AVCodecContext *avctx)
{
BFIContext *bfi = avctx->priv_data;
avctx->pix_fmt = AV_PIX_FMT_PAL8;
bfi->dst = av_mallocz(avctx->width * avctx->height);
return 0;
} | 13,219 |
qemu | c508277335e3b6b20cf18e6ea3a35c1fa835c64a | 1 | static void vmxnet3_set_events(VMXNET3State *s, uint32_t val)
{
uint32_t events;
VMW_CBPRN("Setting events: 0x%x", val);
events = VMXNET3_READ_DRV_SHARED32(s->drv_shmem, ecr) | val;
VMXNET3_WRITE_DRV_SHARED32(s->drv_shmem, ecr, events);
}
| 13,220 |
qemu | e04fb07fd1676e9facd7f3f878c1bbe03bccd26b | 1 | static int qemu_rbd_send_pipe(BDRVRBDState *s, RADOSCB *rcb)
{
int ret = 0;
while (1) {
fd_set wfd;
int fd = s->fds[RBD_FD_WRITE];
/* send the op pointer to the qemu thread that is responsible
for the aio/op completion. Must do it in a qemu thread context */
ret = write(fd, (void *)&rcb, sizeof(rcb));
if (ret >= 0) {
break;
}
if (errno == EINTR) {
continue;
}
if (errno != EAGAIN) {
break;
}
FD_ZERO(&wfd);
FD_SET(fd, &wfd);
do {
ret = select(fd + 1, NULL, &wfd, NULL, NULL);
} while (ret < 0 && errno == EINTR);
}
return ret;
}
| 13,221 |
qemu | e23a1b33b53d25510320b26d9f154e19c6c99725 | 1 | static void tcx_init(target_phys_addr_t addr, int vram_size, int width,
int height, int depth)
{
DeviceState *dev;
SysBusDevice *s;
dev = qdev_create(NULL, "SUNW,tcx");
qdev_prop_set_taddr(dev, "addr", addr);
qdev_prop_set_uint32(dev, "vram_size", vram_size);
qdev_prop_set_uint16(dev, "width", width);
qdev_prop_set_uint16(dev, "height", height);
qdev_prop_set_uint16(dev, "depth", depth);
qdev_init(dev);
s = sysbus_from_qdev(dev);
/* 8-bit plane */
sysbus_mmio_map(s, 0, addr + 0x00800000ULL);
/* DAC */
sysbus_mmio_map(s, 1, addr + 0x00200000ULL);
/* TEC (dummy) */
sysbus_mmio_map(s, 2, addr + 0x00700000ULL);
/* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
sysbus_mmio_map(s, 3, addr + 0x00301000ULL);
if (depth == 24) {
/* 24-bit plane */
sysbus_mmio_map(s, 4, addr + 0x02000000ULL);
/* Control plane */
sysbus_mmio_map(s, 5, addr + 0x0a000000ULL);
} else {
/* THC 8 bit (dummy) */
sysbus_mmio_map(s, 4, addr + 0x00300000ULL);
}
}
| 13,222 |
qemu | 94a8d39afd8ccfdbf578af04c3385fdb5f545af1 | 1 | int kvm_init_vcpu(CPUState *env)
{
KVMState *s = kvm_state;
long mmap_size;
int ret;
DPRINTF("kvm_init_vcpu\n");
ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index);
if (ret < 0) {
DPRINTF("kvm_create_vcpu failed\n");
goto err;
}
env->kvm_fd = ret;
env->kvm_state = s;
mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
if (mmap_size < 0) {
DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
goto err;
}
env->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
env->kvm_fd, 0);
if (env->kvm_run == MAP_FAILED) {
ret = -errno;
DPRINTF("mmap'ing vcpu state failed\n");
goto err;
}
#ifdef KVM_CAP_COALESCED_MMIO
if (s->coalesced_mmio && !s->coalesced_mmio_ring) {
s->coalesced_mmio_ring =
(void *)env->kvm_run + s->coalesced_mmio * PAGE_SIZE;
}
#endif
ret = kvm_arch_init_vcpu(env);
if (ret == 0) {
qemu_register_reset(kvm_reset_vcpu, env);
kvm_arch_reset_vcpu(env);
}
err:
return ret;
}
| 13,224 |
FFmpeg | c3ab0004ae4dffc32494ae84dd15cfaa909a7884 | 1 | static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
{
#if COMPILE_TEMPLATE_MMX
assert(src1==src2);
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
#else
int i;
assert(src1==src2);
for (i=0; i<width; i++) {
int r= src1[3*i + 0];
int g= src1[3*i + 1];
int b= src1[3*i + 2];
dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
}
#endif
}
| 13,226 |
qemu | c87826a878be05208c3906eb9d5e1f37cff5e98e | 1 | int net_init_tap(const NetClientOptions *opts, const char *name,
NetClientState *peer)
{
const NetdevTapOptions *tap;
int fd, vnet_hdr = 0, i = 0, queues;
/* for the no-fd, no-helper case */
const char *script = NULL; /* suppress wrong "uninit'd use" gcc warning */
const char *downscript = NULL;
const char *vhostfdname;
char ifname[128];
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
tap = opts->tap;
queues = tap->has_queues ? tap->queues : 1;
vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
/* QEMU vlans does not support multiqueue tap, in this case peer is set.
* For -netdev, peer is always NULL. */
if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) {
error_report("Multiqueue tap cannot be used with QEMU vlans");
return -1;
}
if (tap->has_fd) {
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
tap->has_fds) {
error_report("ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, and fds= are invalid with fd=");
return -1;
}
fd = monitor_handle_fd_param(cur_mon, tap->fd);
if (fd == -1) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
vnet_hdr = tap_probe_vnet_hdr(fd);
if (net_init_tap_one(tap, peer, "tap", name, NULL,
script, downscript,
vhostfdname, vnet_hdr, fd)) {
return -1;
}
} else if (tap->has_fds) {
char *fds[MAX_TAP_QUEUES];
char *vhost_fds[MAX_TAP_QUEUES];
int nfds, nvhosts;
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
tap->has_fd) {
error_report("ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, and fd= are invalid with fds=");
return -1;
}
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
if (nfds != nvhosts) {
error_report("The number of fds passed does not match the "
"number of vhostfds passed");
return -1;
}
}
for (i = 0; i < nfds; i++) {
fd = monitor_handle_fd_param(cur_mon, fds[i]);
if (fd == -1) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
if (i == 0) {
vnet_hdr = tap_probe_vnet_hdr(fd);
} else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
error_report("vnet_hdr not consistent across given tap fds");
return -1;
}
if (net_init_tap_one(tap, peer, "tap", name, ifname,
script, downscript,
tap->has_vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd)) {
return -1;
}
}
} else if (tap->has_helper) {
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_queues || tap->has_fds) {
error_report("ifname=, script=, downscript=, and vnet_hdr= "
"queues=, and fds= are invalid with helper=");
return -1;
}
fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE);
if (fd == -1) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
vnet_hdr = tap_probe_vnet_hdr(fd);
if (net_init_tap_one(tap, peer, "bridge", name, ifname,
script, downscript, vhostfdname,
vnet_hdr, fd)) {
return -1;
}
} else {
script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
downscript = tap->has_downscript ? tap->downscript :
DEFAULT_NETWORK_DOWN_SCRIPT;
if (tap->has_ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
ifname[0] = '\0';
}
for (i = 0; i < queues; i++) {
fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
ifname, sizeof ifname, queues > 1);
if (fd == -1) {
return -1;
}
if (queues > 1 && i == 0 && !tap->has_ifname) {
if (tap_fd_get_ifname(fd, ifname)) {
error_report("Fail to get ifname");
return -1;
}
}
if (net_init_tap_one(tap, peer, "tap", name, ifname,
i >= 1 ? "no" : script,
i >= 1 ? "no" : downscript,
vhostfdname, vnet_hdr, fd)) {
return -1;
}
}
}
return 0;
}
| 13,227 |
qemu | c5a49c63fa26e8825ad101dfe86339ae4c216539 | 1 | static void spr_read_decr(DisasContext *ctx, int gprn, int sprn)
{
if (ctx->tb->cflags & CF_USE_ICOUNT) {
gen_io_start();
}
gen_helper_load_decr(cpu_gpr[gprn], cpu_env);
if (ctx->tb->cflags & CF_USE_ICOUNT) {
gen_io_end();
gen_stop_exception(ctx);
}
}
| 13,228 |
FFmpeg | 0852648301ad968bc7d79d000400e2b973bbb59a | 1 | static double get_scene_score(AVFilterContext *ctx, AVFilterBufferRef *picref)
{
double ret = 0;
SelectContext *select = ctx->priv;
AVFilterBufferRef *prev_picref = select->prev_picref;
if (prev_picref &&
picref->video->h == prev_picref->video->h &&
picref->video->w == prev_picref->video->w &&
picref->linesize[0] == prev_picref->linesize[0]) {
int x, y;
int64_t sad = 0;
double mafd, diff;
uint8_t *p1 = picref->data[0];
uint8_t *p2 = prev_picref->data[0];
const int linesize = picref->linesize[0];
for (y = 0; y < picref->video->h; y += 8)
for (x = 0; x < linesize; x += 8)
sad += select->c.sad[1](select,
p1 + y * linesize + x,
p2 + y * linesize + x,
linesize, 8);
emms_c();
mafd = sad / (picref->video->h * picref->video->w * 3);
diff = fabs(mafd - select->prev_mafd);
ret = av_clipf(FFMIN(mafd, diff) / 100., 0, 1);
select->prev_mafd = mafd;
avfilter_unref_buffer(prev_picref);
}
select->prev_picref = avfilter_ref_buffer(picref, ~0);
return ret;
}
| 13,229 |
qemu | 0b8b8753e4d94901627b3e86431230f2319215c4 | 1 | static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr,
void *data, unsigned int *wlen, unsigned int *rlen)
{
Coroutine *co;
SheepdogReqCo srco = {
.sockfd = sockfd,
.aio_context = aio_context,
.hdr = hdr,
.data = data,
.wlen = wlen,
.rlen = rlen,
.ret = 0,
.finished = false,
};
if (qemu_in_coroutine()) {
do_co_req(&srco);
} else {
co = qemu_coroutine_create(do_co_req);
qemu_coroutine_enter(co, &srco);
while (!srco.finished) {
aio_poll(aio_context, true);
}
}
return srco.ret;
}
| 13,231 |
qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 | 1 | static void gen_mtsrin(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
#else
TCGv t0;
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
return;
}
t0 = tcg_temp_new();
tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
tcg_gen_andi_tl(t0, t0, 0xF);
gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
tcg_temp_free(t0);
#endif
}
| 13,232 |
qemu | f7c40aa1e7feb50bc4d4bc171fa811bdd9a93e51 | 1 | void s390_pci_iommu_enable(S390PCIBusDevice *pbdev)
{
uint64_t size = pbdev->pal - pbdev->pba + 1;
memory_region_init_iommu(&pbdev->iommu_mr, OBJECT(&pbdev->mr),
&s390_iommu_ops, "iommu-s390", size);
memory_region_add_subregion(&pbdev->mr, pbdev->pba, &pbdev->iommu_mr);
pbdev->iommu_enabled = true;
}
| 13,233 |
qemu | 2fd5d864099dd38b43b595e9e3375dad2f76049b | 1 | strdup(str)
const char *str;
{
char *bptr;
bptr = (char *)malloc(strlen(str)+1);
strcpy(bptr, str);
return bptr;
}
| 13,234 |
qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 | 1 | static void gen_tlbli_6xx(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
#else
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
return;
}
gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
#endif
}
| 13,235 |
qemu | d510c5cf343eabd4d3a301f5730af724747b7055 | 1 | QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
int permit_abbrev)
{
const char *firstname;
char value[1024], *id = NULL;
const char *p;
QemuOpts *opts;
assert(!permit_abbrev || list->implied_opt_name);
firstname = permit_abbrev ? list->implied_opt_name : NULL;
if (strncmp(params, "id=", 3) == 0) {
get_opt_value(value, sizeof(value), params+3);
id = qemu_strdup(value);
} else if ((p = strstr(params, ",id=")) != NULL) {
get_opt_value(value, sizeof(value), p+4);
id = qemu_strdup(value);
}
opts = qemu_opts_create(list, id, 1);
if (opts == NULL)
return NULL;
if (qemu_opts_do_parse(opts, params, firstname) != 0) {
qemu_opts_del(opts);
return NULL;
}
return opts;
}
| 13,237 |
qemu | 6f2d8978728c48ca46f5c01835438508aace5c64 | 1 | static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
target_ulong eaddr, int rw, int type)
{
target_phys_addr_t sdr, hash, mask, sdr_mask, htab_mask;
target_ulong sr, vsid, vsid_mask, pgidx, page_mask;
#if defined(TARGET_PPC64)
int attr;
#endif
int ds, vsid_sh, sdr_sh, pr;
int ret, ret2;
pr = msr_pr;
#if defined(TARGET_PPC64)
if (env->mmu_model == POWERPC_MMU_64B) {
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "Check SLBs\n");
}
#endif
ret = slb_lookup(env, eaddr, &vsid, &page_mask, &attr);
if (ret < 0)
return ret;
ctx->key = ((attr & 0x40) && (pr != 0)) ||
((attr & 0x80) && (pr == 0)) ? 1 : 0;
ds = 0;
ctx->nx = attr & 0x20 ? 1 : 0;
vsid_mask = 0x00003FFFFFFFFF80ULL;
vsid_sh = 7;
sdr_sh = 18;
sdr_mask = 0x3FF80;
} else
#endif /* defined(TARGET_PPC64) */
{
sr = env->sr[eaddr >> 28];
page_mask = 0x0FFFFFFF;
ctx->key = (((sr & 0x20000000) && (pr != 0)) ||
((sr & 0x40000000) && (pr == 0))) ? 1 : 0;
ds = sr & 0x80000000 ? 1 : 0;
ctx->nx = sr & 0x10000000 ? 1 : 0;
vsid = sr & 0x00FFFFFF;
vsid_mask = 0x01FFFFC0;
vsid_sh = 6;
sdr_sh = 16;
sdr_mask = 0xFFC0;
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "Check segment v=0x" ADDRX " %d 0x" ADDRX
" nip=0x" ADDRX " lr=0x" ADDRX
" ir=%d dr=%d pr=%d %d t=%d\n",
eaddr, (int)(eaddr >> 28), sr, env->nip,
env->lr, (int)msr_ir, (int)msr_dr, pr != 0 ? 1 : 0,
rw, type);
}
#endif
}
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "pte segment: key=%d ds %d nx %d vsid " ADDRX "\n",
ctx->key, ds, ctx->nx, vsid);
}
#endif
ret = -1;
if (!ds) {
/* Check if instruction fetch is allowed, if needed */
if (type != ACCESS_CODE || ctx->nx == 0) {
/* Page address translation */
/* Primary table address */
sdr = env->sdr1;
pgidx = (eaddr & page_mask) >> TARGET_PAGE_BITS;
#if defined(TARGET_PPC64)
if (env->mmu_model == POWERPC_MMU_64B) {
htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F));
/* XXX: this is false for 1 TB segments */
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
} else
#endif
{
htab_mask = sdr & 0x000001FF;
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
}
mask = (htab_mask << sdr_sh) | sdr_mask;
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX " mask "
PADDRX " " ADDRX "\n", sdr, sdr_sh, hash, mask,
page_mask);
}
#endif
ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask);
/* Secondary table address */
hash = (~hash) & vsid_mask;
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX " mask "
PADDRX "\n", sdr, sdr_sh, hash, mask);
}
#endif
ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask);
#if defined(TARGET_PPC64)
if (env->mmu_model == POWERPC_MMU_64B) {
/* Only 5 bits of the page index are used in the AVPN */
ctx->ptem = (vsid << 12) | ((pgidx >> 4) & 0x0F80);
} else
#endif
{
ctx->ptem = (vsid << 7) | (pgidx >> 10);
}
/* Initialize real address with an invalid value */
ctx->raddr = (target_ulong)-1;
if (unlikely(env->mmu_model == POWERPC_MMU_SOFT_6xx ||
env->mmu_model == POWERPC_MMU_SOFT_74xx)) {
/* Software TLB search */
ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type);
} else {
#if defined (DEBUG_MMU)
if (loglevel != 0) {
fprintf(logfile, "0 sdr1=0x" PADDRX " vsid=0x%06x "
"api=0x%04x hash=0x%07x pg_addr=0x" PADDRX "\n",
sdr, (uint32_t)vsid, (uint32_t)pgidx,
(uint32_t)hash, ctx->pg_addr[0]);
}
#endif
/* Primary table lookup */
ret = find_pte(env, ctx, 0, rw, type);
if (ret < 0) {
/* Secondary table lookup */
#if defined (DEBUG_MMU)
if (eaddr != 0xEFFFFFFF && loglevel != 0) {
fprintf(logfile,
"1 sdr1=0x" PADDRX " vsid=0x%06x api=0x%04x "
"hash=0x%05x pg_addr=0x" PADDRX "\n",
sdr, (uint32_t)vsid, (uint32_t)pgidx,
(uint32_t)hash, ctx->pg_addr[1]);
}
#endif
ret2 = find_pte(env, ctx, 1, rw, type);
if (ret2 != -1)
ret = ret2;
}
}
#if defined (DUMP_PAGE_TABLES)
if (loglevel != 0) {
target_phys_addr_t curaddr;
uint32_t a0, a1, a2, a3;
fprintf(logfile,
"Page table: " PADDRX " len " PADDRX "\n",
sdr, mask + 0x80);
for (curaddr = sdr; curaddr < (sdr + mask + 0x80);
curaddr += 16) {
a0 = ldl_phys(curaddr);
a1 = ldl_phys(curaddr + 4);
a2 = ldl_phys(curaddr + 8);
a3 = ldl_phys(curaddr + 12);
if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) {
fprintf(logfile,
PADDRX ": %08x %08x %08x %08x\n",
curaddr, a0, a1, a2, a3);
}
}
}
#endif
} else {
#if defined (DEBUG_MMU)
if (loglevel != 0)
fprintf(logfile, "No access allowed\n");
#endif
ret = -3;
}
} else {
#if defined (DEBUG_MMU)
if (loglevel != 0)
fprintf(logfile, "direct store...\n");
#endif
/* Direct-store segment : absolutely *BUGGY* for now */
switch (type) {
case ACCESS_INT:
/* Integer load/store : only access allowed */
break;
case ACCESS_CODE:
/* No code fetch is allowed in direct-store areas */
return -4;
case ACCESS_FLOAT:
/* Floating point load/store */
return -4;
case ACCESS_RES:
/* lwarx, ldarx or srwcx. */
return -4;
case ACCESS_CACHE:
/* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
/* Should make the instruction do no-op.
* As it already do no-op, it's quite easy :-)
*/
ctx->raddr = eaddr;
return 0;
case ACCESS_EXT:
/* eciwx or ecowx */
return -4;
default:
if (logfile) {
fprintf(logfile, "ERROR: instruction should not need "
"address translation\n");
}
return -4;
}
if ((rw == 1 || ctx->key != 1) && (rw == 0 || ctx->key != 0)) {
ctx->raddr = eaddr;
ret = 2;
} else {
ret = -2;
}
}
return ret;
}
| 13,238 |
FFmpeg | 5a4eb6aa275e4c1b80e1e125a7901903e35219f2 | 1 | AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame,
int perms)
{
AVFilterBufferRef *samplesref =
avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
frame->nb_samples, frame->format,
av_frame_get_channel_layout(frame));
if (!samplesref)
return NULL;
if (avfilter_copy_frame_props(samplesref, frame) < 0) {
samplesref->buf->data[0] = NULL;
avfilter_unref_bufferp(&samplesref);
}
return samplesref;
}
| 13,239 |
FFmpeg | 65e0a7c473f23f1833538ffecf53c81fe500b5e4 | 1 | int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
{
Wmv2Context *const w = (Wmv2Context *) s;
if (s->pict_type == AV_PICTURE_TYPE_I) {
if (w->j_type_bit)
w->j_type = get_bits1(&s->gb);
else
w->j_type = 0; // FIXME check
if (!w->j_type) {
if (w->per_mb_rl_bit)
s->per_mb_rl_table = get_bits1(&s->gb);
else
s->per_mb_rl_table = 0;
if (!s->per_mb_rl_table) {
s->rl_chroma_table_index = decode012(&s->gb);
s->rl_table_index = decode012(&s->gb);
}
s->dc_table_index = get_bits1(&s->gb);
}
s->inter_intra_pred = 0;
s->no_rounding = 1;
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG,
"qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
s->qscale, s->rl_chroma_table_index, s->rl_table_index,
s->dc_table_index, s->per_mb_rl_table, w->j_type);
}
} else {
int cbp_index;
w->j_type = 0;
parse_mb_skip(w);
cbp_index = decode012(&s->gb);
w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
if (w->mspel_bit)
s->mspel = get_bits1(&s->gb);
else
s->mspel = 0; // FIXME check
if (w->abt_flag) {
w->per_mb_abt = get_bits1(&s->gb) ^ 1;
if (!w->per_mb_abt)
w->abt_type = decode012(&s->gb);
}
if (w->per_mb_rl_bit)
s->per_mb_rl_table = get_bits1(&s->gb);
else
s->per_mb_rl_table = 0;
if (!s->per_mb_rl_table) {
s->rl_table_index = decode012(&s->gb);
s->rl_chroma_table_index = s->rl_table_index;
}
s->dc_table_index = get_bits1(&s->gb);
s->mv_table_index = get_bits1(&s->gb);
s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && s->bit_rate <= II_BITRATE);
s->no_rounding ^= 1;
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG,
"rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d "
"per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
s->rl_table_index, s->rl_chroma_table_index,
s->dc_table_index, s->mv_table_index,
s->per_mb_rl_table, s->qscale, s->mspel,
w->per_mb_abt, w->abt_type, w->cbp_table_index,
s->inter_intra_pred);
}
}
s->esc3_level_length = 0;
s->esc3_run_length = 0;
s->picture_number++; // FIXME ?
if (w->j_type) {
ff_intrax8_decode_picture(&w->x8, &s->current_picture,
&s->gb, &s->mb_x, &s->mb_y,
2 * s->qscale, (s->qscale - 1) | 1,
s->loop_filter, s->low_delay);
ff_er_add_slice(&w->s.er, 0, 0,
(w->s.mb_x >> 1) - 1, (w->s.mb_y >> 1) - 1,
ER_MB_END);
return 1;
}
return 0;
}
| 13,240 |
FFmpeg | bfa0f96586fe2c257cfa574ffb991da493a54da1 | 1 | static void vp8_decode_flush_impl(AVCodecContext *avctx, int force, int is_close)
{
VP8Context *s = avctx->priv_data;
int i;
if (!avctx->is_copy || force) {
for (i = 0; i < 5; i++)
if (s->frames[i].data[0])
vp8_release_frame(s, &s->frames[i], is_close);
}
memset(s->framep, 0, sizeof(s->framep));
free_buffers(s);
s->maps_are_invalid = 1;
}
| 13,241 |
qemu | ab51b1d568e02c80b1abf9016bda3a86dc1db389 | 1 | static CharDriverState *qemu_chr_open_stdio(QemuOpts *opts)
{
CharDriverState *chr;
if (stdio_nb_clients >= STDIO_MAX_CLIENTS) {
if (stdio_nb_clients == 0) {
old_fd0_flags = fcntl(0, F_GETFL);
tcgetattr (0, &oldtty);
fcntl(0, F_SETFL, O_NONBLOCK);
atexit(term_exit);
chr = qemu_chr_open_fd(0, 1);
chr->chr_close = qemu_chr_close_stdio;
chr->chr_set_echo = qemu_chr_set_echo_stdio;
qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr);
stdio_nb_clients++;
stdio_allow_signal = qemu_opt_get_bool(opts, "signal",
display_type != DT_NOGRAPHIC);
qemu_chr_fe_set_echo(chr, false);
return chr;
| 13,242 |
FFmpeg | c31b81216619e6b3d986ce63c82357993e10e8e9 | 1 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
{
LclContext * const c = (LclContext *)avctx->priv_data;
unsigned char *encoded = (unsigned char *)buf;
int pixel_ptr;
int row, col;
unsigned char *outptr;
unsigned int width = avctx->width; // Real image width
unsigned int height = avctx->height; // Real image height
unsigned int mszh_dlen;
unsigned char yq, y1q, uq, vq;
int uqvq;
unsigned int mthread_inlen, mthread_outlen;
#ifdef CONFIG_ZLIB
int zret; // Zlib return code
#endif
int len = buf_size;
/* no supplementary picture */
if (buf_size == 0)
return 0;
if(c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
c->pic.reference = 0;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
if(avctx->get_buffer(avctx, &c->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
outptr = c->pic.data[0]; // Output image pointer
/* Decompress frame */
switch (avctx->codec_id) {
case CODEC_ID_MSZH:
switch (c->compression) {
case COMP_MSZH:
if (c->flags & FLAG_MULTITHREAD) {
mthread_inlen = *((unsigned int*)encoded);
mthread_outlen = *((unsigned int*)(encoded+4));
mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf);
if (mthread_outlen != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n",
mthread_outlen, mszh_dlen);
}
mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen,
c->decomp_buf + mthread_outlen);
if ((c->decomp_size - mthread_outlen) != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n",
c->decomp_size - mthread_outlen, mszh_dlen);
}
encoded = c->decomp_buf;
len = c->decomp_size;
} else {
mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf);
if (c->decomp_size != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n",
c->decomp_size, mszh_dlen);
}
encoded = c->decomp_buf;
len = mszh_dlen;
}
break;
case COMP_MSZH_NOCOMP:
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
return -1;
}
break;
case CODEC_ID_ZLIB:
#ifdef CONFIG_ZLIB
/* Using the original dll with normal compression (-1) and RGB format
* gives a file with ZLIB fourcc, but frame is really uncompressed.
* To be sure that's true check also frame size */
if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) &&
(len == width * height * 3))
break;
zret = inflateReset(&(c->zstream));
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
return -1;
}
if (c->flags & FLAG_MULTITHREAD) {
mthread_inlen = *((unsigned int*)encoded);
mthread_outlen = *((unsigned int*)(encoded+4));
c->zstream.next_in = encoded + 8;
c->zstream.avail_in = mthread_inlen;
c->zstream.next_out = c->decomp_buf;
c->zstream.avail_out = mthread_outlen;
zret = inflate(&(c->zstream), Z_FINISH);
if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret);
return -1;
}
if (mthread_outlen != (unsigned int)(c->zstream.total_out)) {
av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n",
mthread_outlen, c->zstream.total_out);
}
zret = inflateReset(&(c->zstream));
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret);
return -1;
}
c->zstream.next_in = encoded + 8 + mthread_inlen;
c->zstream.avail_in = len - mthread_inlen;
c->zstream.next_out = c->decomp_buf + mthread_outlen;
c->zstream.avail_out = mthread_outlen;
zret = inflate(&(c->zstream), Z_FINISH);
if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret);
return -1;
}
if ((c->decomp_size - mthread_outlen) != (unsigned int)(c->zstream.total_out)) {
av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n",
c->decomp_size - mthread_outlen, c->zstream.total_out);
}
} else {
c->zstream.next_in = encoded;
c->zstream.avail_in = len;
c->zstream.next_out = c->decomp_buf;
c->zstream.avail_out = c->decomp_size;
zret = inflate(&(c->zstream), Z_FINISH);
if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
return -1;
}
if (c->decomp_size != (unsigned int)(c->zstream.total_out)) {
av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n",
c->decomp_size, c->zstream.total_out);
}
}
encoded = c->decomp_buf;
len = c->decomp_size;;
#else
av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
return -1;
#endif
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
return -1;
}
/* Apply PNG filter */
if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) {
switch (c->imgtype) {
case IMGTYPE_YUV111:
case IMGTYPE_RGB24:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 3;
yq = encoded[pixel_ptr++];
uqvq = encoded[pixel_ptr++];
uqvq+=(encoded[pixel_ptr++] << 8);
for (col = 1; col < width; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
encoded[pixel_ptr+1] = (uqvq) & 0xff;
encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
pixel_ptr += 3;
}
}
break;
case IMGTYPE_YUV422:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 2;
yq = uq = vq =0;
for (col = 0; col < width/4; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
pixel_ptr += 8;
}
}
break;
case IMGTYPE_YUV411:
for (row = 0; row < height; row++) {
pixel_ptr = row * width / 2 * 3;
yq = uq = vq =0;
for (col = 0; col < width/4; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
pixel_ptr += 6;
}
}
break;
case IMGTYPE_YUV211:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 2;
yq = uq = vq =0;
for (col = 0; col < width/2; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
pixel_ptr += 4;
}
}
break;
case IMGTYPE_YUV420:
for (row = 0; row < height/2; row++) {
pixel_ptr = row * width * 3;
yq = y1q = uq = vq =0;
for (col = 0; col < width/2; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
pixel_ptr += 6;
}
}
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
return -1;
}
}
/* Convert colorspace */
switch (c->imgtype) {
case IMGTYPE_YUV111:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
for (col = 0; col < width; col++) {
outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]);
outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]);
outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]);
encoded += 3;
}
}
break;
case IMGTYPE_YUV422:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
for (col = 0; col < width/4; col++) {
outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]);
outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]);
outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]);
outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]);
outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]);
outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]);
outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]);
outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]);
outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]);
outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]);
encoded += 8;
}
}
break;
case IMGTYPE_RGB24:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
for (col = 0; col < width; col++) {
outptr[pixel_ptr++] = encoded[0];
outptr[pixel_ptr++] = encoded[1];
outptr[pixel_ptr++] = encoded[2];
encoded += 3;
}
}
break;
case IMGTYPE_YUV411:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
for (col = 0; col < width/4; col++) {
outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]);
outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]);
outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]);
outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]);
outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]);
outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]);
outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]);
outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]);
outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]);
encoded += 6;
}
}
break;
case IMGTYPE_YUV211:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
for (col = 0; col < width/2; col++) {
outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]);
outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]);
outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]);
outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]);
outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]);
outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]);
encoded += 4;
}
}
break;
case IMGTYPE_YUV420:
for (row = height / 2 - 1; row >= 0; row--) {
pixel_ptr = 2 * row * c->pic.linesize[0];
for (col = 0; col < width/2; col++) {
outptr[pixel_ptr] = get_b(encoded[0], encoded[4]);
outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]);
outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]);
outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]);
outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]);
outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]);
outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]);
outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]);
outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]);
outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]);
outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]);
outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]);
pixel_ptr += 6;
encoded += 6;
}
}
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
return -1;
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
| 13,243 |
qemu | 1eb3fc0a0b61b5d22adee2a9add3162a6c03a47e | 1 | static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,
bool last_stage)
{
int tmppages, pages = 0;
size_t pagesize_bits =
qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS;
do {
tmppages = ram_save_target_page(rs, pss, last_stage);
if (tmppages < 0) {
return tmppages;
}
pages += tmppages;
pss->page++;
} while (pss->page & (pagesize_bits - 1));
/* The offset we leave with is the last one we looked at */
pss->page--;
return pages;
}
| 13,244 |
qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | 1 | static int qemu_rdma_exchange_recv(RDMAContext *rdma, RDMAControlHeader *head,
int expecting)
{
RDMAControlHeader ready = {
.len = 0,
.type = RDMA_CONTROL_READY,
.repeat = 1,
};
int ret;
/*
* Inform the source that we're ready to receive a message.
*/
ret = qemu_rdma_post_send_control(rdma, NULL, &ready);
if (ret < 0) {
fprintf(stderr, "Failed to send control buffer!\n");
return ret;
}
/*
* Block and wait for the message.
*/
ret = qemu_rdma_exchange_get_response(rdma, head,
expecting, RDMA_WRID_READY);
if (ret < 0) {
return ret;
}
qemu_rdma_move_header(rdma, RDMA_WRID_READY, head);
/*
* Post a new RECV work request to replace the one we just consumed.
*/
ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);
if (ret) {
fprintf(stderr, "rdma migration: error posting second control recv!");
return ret;
}
return 0;
}
| 13,245 |
qemu | 48f4ba671bbb3dd212002d57b72a23375f51619b | 1 | static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
{
switch (le32_to_cpu(ext->cmd.type)) {
case QXL_CMD_SURFACE:
{
QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
if (!cmd) {
uint32_t id = le32_to_cpu(cmd->surface_id);
if (id >= qxl->ssd.num_surfaces) {
qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE id %d >= %d", id,
qxl->ssd.num_surfaces);
qemu_mutex_lock(&qxl->track_lock);
if (cmd->type == QXL_SURFACE_CMD_CREATE) {
qxl->guest_surfaces.cmds[id] = ext->cmd.data;
qxl->guest_surfaces.count++;
if (qxl->guest_surfaces.max < qxl->guest_surfaces.count)
qxl->guest_surfaces.max = qxl->guest_surfaces.count;
if (cmd->type == QXL_SURFACE_CMD_DESTROY) {
qxl->guest_surfaces.cmds[id] = 0;
qxl->guest_surfaces.count--;
qemu_mutex_unlock(&qxl->track_lock);
break;
case QXL_CMD_CURSOR:
{
QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
if (!cmd) {
if (cmd->type == QXL_CURSOR_SET) {
qemu_mutex_lock(&qxl->track_lock);
qxl->guest_cursor = ext->cmd.data;
qemu_mutex_unlock(&qxl->track_lock);
break;
return 0;
| 13,246 |
qemu | 40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4 | 1 | int tcp_fconnect(struct socket *so)
{
Slirp *slirp = so->slirp;
int ret=0;
DEBUG_CALL("tcp_fconnect");
DEBUG_ARG("so = %lx", (long )so);
if( (ret=so->s=socket(AF_INET,SOCK_STREAM,0)) >= 0) {
int opt, s=so->s;
struct sockaddr_in addr;
fd_nonblock(s);
opt = 1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(opt ));
opt = 1;
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt ));
addr.sin_family = AF_INET;
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
slirp->vnetwork_addr.s_addr) {
/* It's an alias */
if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
if (get_dns_addr(&addr.sin_addr) < 0)
addr.sin_addr = loopback_addr;
} else {
addr.sin_addr = loopback_addr;
}
} else
addr.sin_addr = so->so_faddr;
addr.sin_port = so->so_fport;
DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, "
"addr.sin_addr.s_addr=%.16s\n",
ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)));
/* We don't care what port we get */
ret = connect(s,(struct sockaddr *)&addr,sizeof (addr));
/*
* If it's not in progress, it failed, so we just return 0,
* without clearing SS_NOFDREF
*/
soisfconnecting(so);
}
return(ret);
}
| 13,247 |
qemu | 42d43d35d907579179a39c924d169da924786f65 | 1 | static void cloop_close(BlockDriverState *bs)
{
BDRVCloopState *s = bs->opaque;
if (s->n_blocks > 0) {
g_free(s->offsets);
}
g_free(s->compressed_block);
g_free(s->uncompressed_block);
inflateEnd(&s->zstream);
}
| 13,249 |
FFmpeg | c16e99e3b3c02edcf33245468731d414eab97dac | 0 | PROTO4(_pack_2ch_)
PROTO4(_pack_6ch_)
PROTO4(_pack_8ch_)
PROTO4(_unpack_2ch_)
PROTO4(_unpack_6ch_)
av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac,
enum AVSampleFormat out_fmt,
enum AVSampleFormat in_fmt,
int channels){
int mm_flags = av_get_cpu_flags();
ac->simd_f= NULL;
//FIXME add memcpy case
#define MULTI_CAPS_FUNC(flag, cap) \
if (EXTERNAL_##flag(mm_flags)) {\
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16P)\
ac->simd_f = ff_int16_to_int32_a_ ## cap;\
if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32P)\
ac->simd_f = ff_int32_to_int16_a_ ## cap;\
}
MULTI_CAPS_FUNC(MMX, mmx)
MULTI_CAPS_FUNC(SSE2, sse2)
if(EXTERNAL_MMX(mm_flags)) {
if(channels == 6) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_6ch_float_to_float_a_mmx;
}
}
if(EXTERNAL_SSE(mm_flags)) {
if(channels == 6) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_6ch_float_to_float_a_sse;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_6ch_float_to_float_a_sse;
}
}
if(EXTERNAL_SSE2(mm_flags)) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16P)
ac->simd_f = ff_int16_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_float_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_float_to_int16_a_sse2;
if(channels == 2) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P)
ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P)
ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_2ch_int32_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_int16_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_2ch_int32_to_int16_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P)
ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_2ch_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
ac->simd_f = ff_unpack_2ch_float_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLT)
ac->simd_f = ff_unpack_2ch_float_to_int16_a_sse2;
}
if(channels == 6) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_6ch_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_6ch_float_to_int32_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_6ch_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
ac->simd_f = ff_unpack_6ch_float_to_int32_a_sse2;
}
if(channels == 8) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_8ch_float_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_8ch_int32_to_float_a_sse2;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_8ch_float_to_int32_a_sse2;
}
}
if(EXTERNAL_SSSE3(mm_flags)) {
if(channels == 2) {
if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_int16_a_ssse3;
if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_int32_a_ssse3;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
ac->simd_f = ff_unpack_2ch_int16_to_float_a_ssse3;
}
}
if(EXTERNAL_AVX(mm_flags)) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_int32_to_float_a_avx;
if(channels == 6) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_6ch_float_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_6ch_int32_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_6ch_float_to_int32_a_avx;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_6ch_float_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
ac->simd_f = ff_unpack_6ch_int32_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
ac->simd_f = ff_unpack_6ch_float_to_int32_a_avx;
}
if(channels == 8) {
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_8ch_float_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
ac->simd_f = ff_pack_8ch_int32_to_float_a_avx;
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_pack_8ch_float_to_int32_a_avx;
}
}
if(EXTERNAL_AVX2(mm_flags)) {
if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP)
ac->simd_f = ff_float_to_int32_a_avx2;
}
}
| 13,251 |
FFmpeg | fd542b6f2026f1aa163882ee0283958598a97c31 | 0 | int ff_unlock_avcodec(const AVCodec *codec)
{
_Bool exp = 1;
if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
return 0;
av_assert0(atomic_compare_exchange_strong(&ff_avcodec_locked, &exp, 0));
atomic_fetch_add(&entangled_thread_counter, -1);
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE))
return -1;
}
return 0;
}
| 13,252 |
FFmpeg | 25a6666f6c07c6ac8449a63d7fbce0dfd29c54cd | 0 | static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
ivi_mc_func mc, int mv_x, int mv_y,
int *prev_dc, int is_intra, int mc_type,
uint32_t quant, int offs,
AVCodecContext *avctx)
{
const uint16_t *base_tab = is_intra ? band->intra_base : band->inter_base;
RVMapDesc *rvmap = band->rv_map;
uint8_t col_flags[8];
int32_t trvec[64];
uint32_t sym = 0, lo, hi, q;
int pos, run, val;
int blk_size = band->blk_size;
int num_coeffs = blk_size * blk_size;
int col_mask = blk_size - 1;
int scan_pos = -1;
int min_size = band->pitch * (band->transform_size - 1) +
band->transform_size;
int buf_size = band->pitch * band->aheight - offs;
if (min_size > buf_size)
return AVERROR_INVALIDDATA;
if (!band->scan) {
av_log(avctx, AV_LOG_ERROR, "Scan pattern is not set.\n");
return AVERROR_INVALIDDATA;
}
/* zero transform vector */
memset(trvec, 0, num_coeffs * sizeof(trvec[0]));
/* zero column flags */
memset(col_flags, 0, sizeof(col_flags));
while (scan_pos <= num_coeffs) {
sym = get_vlc2(gb, band->blk_vlc.tab->table,
IVI_VLC_BITS, 1);
if (sym == rvmap->eob_sym)
break; /* End of block */
/* Escape - run/val explicitly coded using 3 vlc codes */
if (sym == rvmap->esc_sym) {
run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
/* merge them and convert into signed val */
val = IVI_TOSIGNED((hi << 6) | lo);
} else {
if (sym >= 256U) {
av_log(avctx, AV_LOG_ERROR, "Invalid sym encountered: %d.\n", sym);
return AVERROR_INVALIDDATA;
}
run = rvmap->runtab[sym];
val = rvmap->valtab[sym];
}
/* de-zigzag and dequantize */
scan_pos += run;
if (scan_pos >= num_coeffs || scan_pos < 0)
break;
pos = band->scan[scan_pos];
if (!val)
av_dlog(avctx, "Val = 0 encountered!\n");
q = (base_tab[pos] * quant) >> 9;
if (q > 1)
val = val * q + FFSIGN(val) * (((q ^ 1) - 1) >> 1);
trvec[pos] = val;
/* track columns containing non-zero coeffs */
col_flags[pos & col_mask] |= !!val;
}
if (scan_pos < 0 || scan_pos >= num_coeffs && sym != rvmap->eob_sym)
return AVERROR_INVALIDDATA; /* corrupt block data */
/* undoing DC coeff prediction for intra-blocks */
if (is_intra && band->is_2d_trans) {
*prev_dc += trvec[0];
trvec[0] = *prev_dc;
col_flags[0] |= !!*prev_dc;
}
/* apply inverse transform */
band->inv_transform(trvec, band->buf + offs,
band->pitch, col_flags);
/* apply motion compensation */
if (!is_intra)
return ivi_mc(mc, band->buf, band->ref_buf, offs, mv_x, mv_y,
band->pitch, mc_type);
return 0;
}
| 13,253 |
qemu | b72981b910097b31f4d0b9c111a2d2cfd9ee585b | 1 | static void continue_send(IPMIBmcExtern *ibe)
{
if (ibe->outlen == 0) {
goto check_reset;
}
send:
ibe->outpos += qemu_chr_fe_write(ibe->chr, ibe->outbuf + ibe->outpos,
ibe->outlen - ibe->outpos);
if (ibe->outpos < ibe->outlen) {
/* Not fully transmitted, try again in a 10ms */
timer_mod_ns(ibe->extern_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 10000000);
} else {
/* Sent */
ibe->outlen = 0;
ibe->outpos = 0;
if (!ibe->sending_cmd) {
ibe->waiting_rsp = true;
} else {
ibe->sending_cmd = false;
}
check_reset:
if (ibe->connected && ibe->send_reset) {
/* Send the reset */
ibe->outbuf[0] = VM_CMD_RESET;
ibe->outbuf[1] = VM_CMD_CHAR;
ibe->outlen = 2;
ibe->outpos = 0;
ibe->send_reset = false;
ibe->sending_cmd = true;
goto send;
}
if (ibe->waiting_rsp) {
/* Make sure we get a response within 4 seconds. */
timer_mod_ns(ibe->extern_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 4000000000ULL);
}
}
return;
}
| 13,254 |
qemu | 8be487d8f184f2f721cabeac559fb7a6cba18c95 | 1 | static void sdhci_do_adma(SDHCIState *s)
{
unsigned int n, begin, length;
const uint16_t block_size = s->blksize & 0x0fff;
ADMADescr dscr;
int i;
for (i = 0; i < SDHC_ADMA_DESCS_PER_DELAY; ++i) {
s->admaerr &= ~SDHC_ADMAERR_LENGTH_MISMATCH;
get_adma_description(s, &dscr);
DPRINT_L2("ADMA loop: addr=" TARGET_FMT_plx ", len=%d, attr=%x\n",
dscr.addr, dscr.length, dscr.attr);
if ((dscr.attr & SDHC_ADMA_ATTR_VALID) == 0) {
/* Indicate that error occurred in ST_FDS state */
s->admaerr &= ~SDHC_ADMAERR_STATE_MASK;
s->admaerr |= SDHC_ADMAERR_STATE_ST_FDS;
/* Generate ADMA error interrupt */
if (s->errintstsen & SDHC_EISEN_ADMAERR) {
s->errintsts |= SDHC_EIS_ADMAERR;
s->norintsts |= SDHC_NIS_ERR;
}
sdhci_update_irq(s);
return;
}
length = dscr.length ? dscr.length : 65536;
switch (dscr.attr & SDHC_ADMA_ATTR_ACT_MASK) {
case SDHC_ADMA_ATTR_ACT_TRAN: /* data transfer */
if (s->trnmod & SDHC_TRNS_READ) {
while (length) {
if (s->data_count == 0) {
for (n = 0; n < block_size; n++) {
s->fifo_buffer[n] = sdbus_read_data(&s->sdbus);
}
}
begin = s->data_count;
if ((length + begin) < block_size) {
s->data_count = length + begin;
length = 0;
} else {
s->data_count = block_size;
length -= block_size - begin;
}
dma_memory_write(&address_space_memory, dscr.addr,
&s->fifo_buffer[begin],
s->data_count - begin);
dscr.addr += s->data_count - begin;
if (s->data_count == block_size) {
s->data_count = 0;
if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {
s->blkcnt--;
if (s->blkcnt == 0) {
break;
}
}
}
}
} else {
while (length) {
begin = s->data_count;
if ((length + begin) < block_size) {
s->data_count = length + begin;
length = 0;
} else {
s->data_count = block_size;
length -= block_size - begin;
}
dma_memory_read(&address_space_memory, dscr.addr,
&s->fifo_buffer[begin],
s->data_count - begin);
dscr.addr += s->data_count - begin;
if (s->data_count == block_size) {
for (n = 0; n < block_size; n++) {
sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);
}
s->data_count = 0;
if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {
s->blkcnt--;
if (s->blkcnt == 0) {
break;
}
}
}
}
}
s->admasysaddr += dscr.incr;
break;
case SDHC_ADMA_ATTR_ACT_LINK: /* link to next descriptor table */
s->admasysaddr = dscr.addr;
DPRINT_L1("ADMA link: admasysaddr=0x%" PRIx64 "\n",
s->admasysaddr);
break;
default:
s->admasysaddr += dscr.incr;
break;
}
if (dscr.attr & SDHC_ADMA_ATTR_INT) {
DPRINT_L1("ADMA interrupt: admasysaddr=0x%" PRIx64 "\n",
s->admasysaddr);
if (s->norintstsen & SDHC_NISEN_DMA) {
s->norintsts |= SDHC_NIS_DMA;
}
sdhci_update_irq(s);
}
/* ADMA transfer terminates if blkcnt == 0 or by END attribute */
if (((s->trnmod & SDHC_TRNS_BLK_CNT_EN) &&
(s->blkcnt == 0)) || (dscr.attr & SDHC_ADMA_ATTR_END)) {
DPRINT_L2("ADMA transfer completed\n");
if (length || ((dscr.attr & SDHC_ADMA_ATTR_END) &&
(s->trnmod & SDHC_TRNS_BLK_CNT_EN) &&
s->blkcnt != 0)) {
ERRPRINT("SD/MMC host ADMA length mismatch\n");
s->admaerr |= SDHC_ADMAERR_LENGTH_MISMATCH |
SDHC_ADMAERR_STATE_ST_TFR;
if (s->errintstsen & SDHC_EISEN_ADMAERR) {
ERRPRINT("Set ADMA error flag\n");
s->errintsts |= SDHC_EIS_ADMAERR;
s->norintsts |= SDHC_NIS_ERR;
}
sdhci_update_irq(s);
}
sdhci_end_transfer(s);
return;
}
}
/* we have unfinished business - reschedule to continue ADMA */
timer_mod(s->transfer_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + SDHC_TRANSFER_DELAY);
}
| 13,255 |
qemu | aef4acb6616ab7fb5c105660aa8a2cee4e250e75 | 1 | static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,
uint64_t cluster_offset, int n_start, int n_end)
{
BDRVQcowState *s = bs->opaque;
int n, ret;
void *buf;
/*
* If this is the last cluster and it is only partially used, we must only
* copy until the end of the image, or bdrv_check_request will fail for the
* bdrv_read/write calls below.
*/
if (start_sect + n_end > bs->total_sectors) {
n_end = bs->total_sectors - start_sect;
}
n = n_end - n_start;
if (n <= 0) {
return 0;
}
buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE);
BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
ret = bdrv_read(bs, start_sect + n_start, buf, n);
if (ret < 0) {
goto out;
}
if (s->crypt_method) {
qcow2_encrypt_sectors(s, start_sect + n_start,
buf, buf, n, 1,
&s->aes_encrypt_key);
}
BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, buf, n);
if (ret < 0) {
goto out;
}
ret = 0;
out:
qemu_vfree(buf);
return ret;
}
| 13,256 |
qemu | 3b39d734141a71296d08af3d4c32f872fafd782e | 1 | void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
vaddr addr, unsigned size,
MMUAccessType access_type,
int mmu_idx, MemTxAttrs attrs,
MemTxResult response, uintptr_t retaddr)
{
ARMCPU *cpu = ARM_CPU(cs);
ARMMMUFaultInfo fi = {};
/* now we have a real cpu fault */
cpu_restore_state(cs, retaddr);
/* The EA bit in syndromes and fault status registers is an
* IMPDEF classification of external aborts. ARM implementations
* usually use this to indicate AXI bus Decode error (0) or
* Slave error (1); in QEMU we follow that.
*/
fi.ea = (response != MEMTX_DECODE_ERROR);
fi.type = ARMFault_SyncExternal;
deliver_fault(cpu, addr, access_type, mmu_idx, &fi);
}
| 13,257 |
FFmpeg | 2240e2078d53d3cfce8ff1dda64e58fa72038602 | 1 | static int truemotion1_decode_header(TrueMotion1Context *s)
{
int i, ret;
int width_shift = 0;
int new_pix_fmt;
struct frame_header header;
uint8_t header_buffer[128] = { 0 }; /* logical maximum size of the header */
const uint8_t *sel_vector_table;
header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
if (s->buf[0] < 0x10)
{
av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]);
/* unscramble the header bytes with a XOR operation */
for (i = 1; i < header.header_size; i++)
header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
header.compression = header_buffer[0];
header.deltaset = header_buffer[1];
header.vectable = header_buffer[2];
header.ysize = AV_RL16(&header_buffer[3]);
header.xsize = AV_RL16(&header_buffer[5]);
header.checksum = AV_RL16(&header_buffer[7]);
header.version = header_buffer[9];
header.header_type = header_buffer[10];
header.flags = header_buffer[11];
header.control = header_buffer[12];
/* Version 2 */
if (header.version >= 2)
{
if (header.header_type > 3)
{
av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type);
} else if ((header.header_type == 2) || (header.header_type == 3)) {
s->flags = header.flags;
if (!(s->flags & FLAG_INTERFRAME))
s->flags |= FLAG_KEYFRAME;
} else
s->flags = FLAG_KEYFRAME;
} else /* Version 1 */
s->flags = FLAG_KEYFRAME;
if (s->flags & FLAG_SPRITE) {
avpriv_request_sample(s->avctx, "Frame with sprite");
/* FIXME header.width, height, xoffset and yoffset aren't initialized */
return AVERROR_PATCHWELCOME;
} else {
s->w = header.xsize;
s->h = header.ysize;
if (header.header_type < 2) {
if ((s->w < 213) && (s->h >= 176))
{
s->flags |= FLAG_INTERPOLATED;
avpriv_request_sample(s->avctx, "Interpolated frame");
if (header.compression >= 17) {
av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression);
if ((header.deltaset != s->last_deltaset) ||
(header.vectable != s->last_vectable))
select_delta_tables(s, header.deltaset);
if ((header.compression & 1) && header.header_type)
sel_vector_table = pc_tbl2;
else {
if (header.vectable > 0 && header.vectable < 4)
sel_vector_table = tables[header.vectable - 1];
else {
av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable);
if (compression_types[header.compression].algorithm == ALGO_RGB24H) {
new_pix_fmt = AV_PIX_FMT_RGB32;
width_shift = 1;
} else
new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well
s->w >>= width_shift;
if (s->w != s->avctx->width || s->h != s->avctx->height ||
new_pix_fmt != s->avctx->pix_fmt) {
av_frame_unref(s->frame);
s->avctx->sample_aspect_ratio = (AVRational){ 1 << width_shift, 1 };
s->avctx->pix_fmt = new_pix_fmt;
if ((ret = ff_set_dimensions(s->avctx, s->w, s->h)) < 0)
return ret;
av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int));
/* There is 1 change bit per 4 pixels, so each change byte represents
* 32 pixels; divide width by 4 to obtain the number of change bits and
* then round up to the nearest byte. */
s->mb_change_bits_row_size = ((s->avctx->width >> (2 - width_shift)) + 7) >> 3;
if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable))
{
if (compression_types[header.compression].algorithm == ALGO_RGB24H)
gen_vector_table24(s, sel_vector_table);
else
if (s->avctx->pix_fmt == AV_PIX_FMT_RGB555)
gen_vector_table15(s, sel_vector_table);
else
gen_vector_table16(s, sel_vector_table);
/* set up pointers to the other key data chunks */
s->mb_change_bits = s->buf + header.header_size;
if (s->flags & FLAG_KEYFRAME) {
/* no change bits specified for a keyframe; only index bytes */
s->index_stream = s->mb_change_bits;
} else {
/* one change bit per 4x4 block */
s->index_stream = s->mb_change_bits +
(s->mb_change_bits_row_size * (s->avctx->height >> 2));
s->index_stream_size = s->size - (s->index_stream - s->buf);
s->last_deltaset = header.deltaset;
s->last_vectable = header.vectable;
s->compression = header.compression;
s->block_width = compression_types[header.compression].block_width;
s->block_height = compression_types[header.compression].block_height;
s->block_type = compression_types[header.compression].block_type;
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "tables: %d / %d c:%d %dx%d t:%d %s%s%s%s\n",
s->last_deltaset, s->last_vectable, s->compression, s->block_width,
s->block_height, s->block_type,
s->flags & FLAG_KEYFRAME ? " KEY" : "",
s->flags & FLAG_INTERFRAME ? " INTER" : "",
s->flags & FLAG_SPRITE ? " SPRITE" : "",
s->flags & FLAG_INTERPOLATED ? " INTERPOL" : "");
return header.header_size; | 13,258 |
FFmpeg | 4de4308d2aa3bfaa286ab566caf087d523cf9a85 | 1 | static av_always_inline void RENAME(decode_line)(FFV1Context *s, int w,
TYPE *sample[2],
int plane_index, int bits)
{
PlaneContext *const p = &s->plane[plane_index];
RangeCoder *const c = &s->c;
int x;
int run_count = 0;
int run_mode = 0;
int run_index = s->run_index;
if (s->slice_coding_mode == 1) {
int i;
for (x = 0; x < w; x++) {
int v = 0;
for (i=0; i<bits; i++) {
uint8_t state = 128;
v += v + get_rac(c, &state);
}
sample[1][x] = v;
}
return;
}
for (x = 0; x < w; x++) {
int diff, context, sign;
context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
if (context < 0) {
context = -context;
sign = 1;
} else
sign = 0;
av_assert2(context < p->context_count);
if (s->ac != AC_GOLOMB_RICE) {
diff = get_symbol_inline(c, p->state[context], 1);
} else {
if (context == 0 && run_mode == 0)
run_mode = 1;
if (run_mode) {
if (run_count == 0 && run_mode == 1) {
if (get_bits1(&s->gb)) {
run_count = 1 << ff_log2_run[run_index];
if (x + run_count <= w)
run_index++;
} else {
if (ff_log2_run[run_index])
run_count = get_bits(&s->gb, ff_log2_run[run_index]);
else
run_count = 0;
if (run_index)
run_index--;
run_mode = 2;
}
}
run_count--;
if (run_count < 0) {
run_mode = 0;
run_count = 0;
diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
bits);
if (diff >= 0)
diff++;
} else
diff = 0;
} else
diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
run_count, run_index, run_mode, x, get_bits_count(&s->gb));
}
if (sign)
diff = -diff;
sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
}
s->run_index = run_index;
}
| 13,259 |
qemu | 5b7d7dfd198f06ec5edd0c857291c5035c5c060f | 1 | static int bochs_open(BlockDriverState *bs, int flags)
{
BDRVBochsState *s = bs->opaque;
int i;
struct bochs_header bochs;
struct bochs_header_v1 header_v1;
bs->read_only = 1; // no write support yet
if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) {
goto fail;
}
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))) {
return -EMEDIUMTYPE;
}
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);
if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
s->catalog_size * 4) != s->catalog_size * 4)
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:
return -1;
}
| 13,260 |
qemu | 868d585aced5457218b3443398d08594d9c3ba6d | 1 | static void set_alarm (m48t59_t *NVRAM, struct tm *tm)
{
NVRAM->alarm = mktime(tm);
if (NVRAM->alrm_timer != NULL) {
qemu_del_timer(NVRAM->alrm_timer);
NVRAM->alrm_timer = NULL;
}
if (NVRAM->alarm - time(NULL) > 0)
qemu_mod_timer(NVRAM->alrm_timer, NVRAM->alarm * 1000);
}
| 13,261 |
qemu | bf8d492405feaee2c1685b3b9d5e03228ed3e47f | 1 | static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
hc->root_bus_path = i440fx_pcihost_root_bus_path;
dc->realize = i440fx_pcihost_realize;
dc->fw_name = "pci";
dc->props = i440fx_props;
} | 13,262 |
FFmpeg | 636ced8e1dc8248a1353b416240b93d70ad03edb | 1 | static void init_parse_context(OptionParseContext *octx,
const OptionGroupDef *groups, int nb_groups)
{
static const OptionGroupDef global_group = { "global" };
int i;
memset(octx, 0, sizeof(*octx));
octx->nb_groups = nb_groups;
octx->groups = av_mallocz(sizeof(*octx->groups) * octx->nb_groups);
if (!octx->groups)
exit(1);
for (i = 0; i < octx->nb_groups; i++)
octx->groups[i].group_def = &groups[i];
octx->global_opts.group_def = &global_group;
octx->global_opts.arg = "";
init_opts();
}
| 13,263 |
FFmpeg | 9afb7061f938831248942050cfdb449e014ed427 | 1 | int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size)
{
AVIOContext *pb = s->pb;
uint32_t layout_tag, bitmap, num_descr, label_mask;
int i;
if (size < 12)
return AVERROR_INVALIDDATA;
layout_tag = avio_rb32(pb);
bitmap = avio_rb32(pb);
num_descr = avio_rb32(pb);
av_dlog(s, "chan: layout=%u bitmap=%u num_descr=%u\n",
layout_tag, bitmap, num_descr);
if (size < 12ULL + num_descr * 20ULL)
return 0;
label_mask = 0;
for (i = 0; i < num_descr; i++) {
uint32_t label;
label = avio_rb32(pb); // mChannelLabel
avio_rb32(pb); // mChannelFlags
avio_rl32(pb); // mCoordinates[0]
avio_rl32(pb); // mCoordinates[1]
avio_rl32(pb); // mCoordinates[2]
if (layout_tag == 0) {
uint32_t mask_incr = mov_get_channel_label(label);
if (mask_incr == 0) {
label_mask = 0;
break;
}
label_mask |= mask_incr;
}
}
if (layout_tag == 0)
st->codec->channel_layout = label_mask;
else
st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
return 0;
}
| 13,264 |
qemu | e5bfd64050e81774b6bf71ab5dd064f7bcef0c4c | 1 | void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,
uint32_t ramsize,
const char *initrd_filename,
const char *dtb_filename,
void (*machine_cpu_reset)(MicroBlazeCPU *))
{
QemuOpts *machine_opts;
const char *kernel_filename;
const char *kernel_cmdline;
const char *dtb_arg;
machine_opts = qemu_get_machine_opts();
kernel_filename = qemu_opt_get(machine_opts, "kernel");
kernel_cmdline = qemu_opt_get(machine_opts, "append");
dtb_arg = qemu_opt_get(machine_opts, "dtb");
if (dtb_arg) { /* Preference a -dtb argument */
dtb_filename = dtb_arg;
} else { /* default to pcbios dtb as passed by machine_init */
dtb_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_filename);
}
boot_info.machine_cpu_reset = machine_cpu_reset;
qemu_register_reset(main_cpu_reset, cpu);
if (kernel_filename) {
int kernel_size;
uint64_t entry, low, high;
uint32_t base32;
int big_endian = 0;
#ifdef TARGET_WORDS_BIGENDIAN
big_endian = 1;
#endif
/* Boots a kernel elf binary. */
kernel_size = load_elf(kernel_filename, NULL, NULL,
&entry, &low, &high,
big_endian, ELF_MACHINE, 0);
base32 = entry;
if (base32 == 0xc0000000) {
kernel_size = load_elf(kernel_filename, translate_kernel_address,
NULL, &entry, NULL, NULL,
big_endian, ELF_MACHINE, 0);
}
/* Always boot into physical ram. */
boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff);
/* If it wasn't an ELF image, try an u-boot image. */
if (kernel_size < 0) {
hwaddr uentry, loadaddr;
kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0);
boot_info.bootstrap_pc = uentry;
high = (loadaddr + kernel_size + 3) & ~3;
}
/* Not an ELF image nor an u-boot image, try a RAW image. */
if (kernel_size < 0) {
kernel_size = load_image_targphys(kernel_filename, ddr_base,
ram_size);
boot_info.bootstrap_pc = ddr_base;
high = (ddr_base + kernel_size + 3) & ~3;
}
if (initrd_filename) {
int initrd_size;
uint32_t initrd_offset;
high = ROUND_UP(high + kernel_size, 4);
boot_info.initrd_start = high;
initrd_offset = boot_info.initrd_start - ddr_base;
initrd_size = load_ramdisk(initrd_filename,
boot_info.initrd_start,
ram_size - initrd_offset);
if (initrd_size < 0) {
initrd_size = load_image_targphys(initrd_filename,
boot_info.initrd_start,
ram_size - initrd_offset);
}
if (initrd_size < 0) {
error_report("qemu: could not load initrd '%s'\n",
initrd_filename);
exit(EXIT_FAILURE);
}
boot_info.initrd_end = boot_info.initrd_start + initrd_size;
high = ROUND_UP(high + initrd_size, 4);
}
boot_info.cmdline = high + 4096;
if (kernel_cmdline && strlen(kernel_cmdline)) {
pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline);
}
/* Provide a device-tree. */
boot_info.fdt = boot_info.cmdline + 4096;
microblaze_load_dtb(boot_info.fdt, ram_size,
boot_info.initrd_start,
boot_info.initrd_end,
kernel_cmdline,
dtb_filename);
}
}
| 13,265 |
qemu | 92e926e1e37aea7e1632535b6611ed4f62414af1 | 1 | static int kvm_ppc_register_host_cpu_type(void)
{
TypeInfo type_info = {
.name = TYPE_HOST_POWERPC_CPU,
.class_init = kvmppc_host_cpu_class_init,
};
PowerPCCPUClass *pvr_pcc;
DeviceClass *dc;
int i;
pvr_pcc = kvm_ppc_get_host_cpu_class();
if (pvr_pcc == NULL) {
return -1;
}
type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
type_register(&type_info);
#if defined(TARGET_PPC64)
type_info.name = g_strdup_printf("%s-"TYPE_SPAPR_CPU_CORE, "host");
type_info.parent = TYPE_SPAPR_CPU_CORE,
type_info.instance_size = sizeof(sPAPRCPUCore);
type_info.instance_init = NULL;
type_info.class_init = spapr_cpu_core_class_init;
type_info.class_data = (void *) "host";
type_register(&type_info);
g_free((void *)type_info.name);
#endif
/*
* Update generic CPU family class alias (e.g. on a POWER8NVL host,
* we want "POWER8" to be a "family" alias that points to the current
* host CPU type, too)
*/
dc = DEVICE_CLASS(ppc_cpu_get_family_class(pvr_pcc));
for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
if (strcmp(ppc_cpu_aliases[i].alias, dc->desc) == 0) {
ObjectClass *oc = OBJECT_CLASS(pvr_pcc);
char *suffix;
ppc_cpu_aliases[i].model = g_strdup(object_class_get_name(oc));
suffix = strstr(ppc_cpu_aliases[i].model, "-"TYPE_POWERPC_CPU);
if (suffix) {
*suffix = 0;
}
ppc_cpu_aliases[i].oc = oc;
break;
}
}
return 0;
}
| 13,266 |
FFmpeg | bd0739804640939fea4fb6f1f625b82432d46947 | 1 | static int av_encode(AVFormatContext **output_files,
int nb_output_files,
AVFormatContext **input_files,
int nb_input_files,
AVStreamMap *stream_maps, int nb_stream_maps)
{
int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, pts_set;
AVFormatContext *is, *os;
AVCodecContext *codec, *icodec;
AVOutputStream *ost, **ost_table = NULL;
AVInputStream *ist, **ist_table = NULL;
AVInputFile *file_table;
AVFormatContext *stream_no_data;
int key;
file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile));
if (!file_table)
goto fail;
/* input stream init */
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
file_table[i].ist_index = j;
file_table[i].nb_streams = is->nb_streams;
j += is->nb_streams;
nb_istreams = j;
ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
if (!ist_table)
goto fail;
for(i=0;i<nb_istreams;i++) {
ist = av_mallocz(sizeof(AVInputStream));
if (!ist)
goto fail;
ist_table[i] = ist;
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
for(k=0;k<is->nb_streams;k++) {
ist = ist_table[j++];
ist->st = is->streams[k];
ist->file_index = i;
ist->index = k;
ist->discard = 1; /* the stream is discarded by default
(changed later) */
if (ist->st->codec.rate_emu) {
ist->start = av_gettime();
ist->frame = 0;
/* output stream init */
nb_ostreams = 0;
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
nb_ostreams += os->nb_streams;
if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
fprintf(stderr, "Number of stream maps must match number of output streams\n");
/* Sanity check the mapping args -- do the input files & streams exist? */
for(i=0;i<nb_stream_maps;i++) {
int fi = stream_maps[i].file_index;
int si = stream_maps[i].stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
si < 0 || si > file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
if (!ost_table)
goto fail;
for(i=0;i<nb_ostreams;i++) {
ost = av_mallocz(sizeof(AVOutputStream));
if (!ost)
goto fail;
ost_table[i] = ost;
n = 0;
for(k=0;k<nb_output_files;k++) {
os = output_files[k];
for(i=0;i<os->nb_streams;i++) {
int found;
ost = ost_table[n++];
ost->file_index = k;
ost->index = i;
ost->st = os->streams[i];
if (nb_stream_maps > 0) {
ost->source_index = file_table[stream_maps[n-1].file_index].ist_index +
stream_maps[n-1].stream_index;
} else {
/* get corresponding input stream index : we select the first one with the right type */
found = 0;
for(j=0;j<nb_istreams;j++) {
ist = ist_table[j];
if (ist->discard &&
ist->st->codec.codec_type == ost->st->codec.codec_type) {
ost->source_index = j;
found = 1;
if (!found) {
/* try again and reuse existing stream */
for(j=0;j<nb_istreams;j++) {
ist = ist_table[j];
if (ist->st->codec.codec_type == ost->st->codec.codec_type) {
ost->source_index = j;
found = 1;
if (!found) {
fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
ist = ist_table[ost->source_index];
ist->discard = 0;
/* for each output stream, we compute the right encoding parameters */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
ist = ist_table[ost->source_index];
codec = &ost->st->codec;
icodec = &ist->st->codec;
if (ost->st->stream_copy) {
/* if stream_copy is selected, no need to decode or encode */
codec->codec_id = icodec->codec_id;
codec->codec_type = icodec->codec_type;
codec->codec_tag = icodec->codec_tag;
codec->bit_rate = icodec->bit_rate;
switch(codec->codec_type) {
case CODEC_TYPE_AUDIO:
codec->sample_rate = icodec->sample_rate;
codec->channels = icodec->channels;
break;
case CODEC_TYPE_VIDEO:
codec->frame_rate = icodec->frame_rate;
codec->frame_rate_base = icodec->frame_rate_base;
codec->width = icodec->width;
codec->height = icodec->height;
break;
default:
av_abort();
} else {
switch(codec->codec_type) {
case CODEC_TYPE_AUDIO:
if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
goto fail;
if (codec->channels == icodec->channels &&
codec->sample_rate == icodec->sample_rate) {
ost->audio_resample = 0;
} else {
if (codec->channels != icodec->channels &&
icodec->codec_id == CODEC_ID_AC3) {
/* Special case for 5:1 AC3 input */
/* and mono or stereo output */
/* Request specific number of channels */
icodec->channels = codec->channels;
if (codec->sample_rate == icodec->sample_rate)
ost->audio_resample = 0;
else {
ost->audio_resample = 1;
ost->resample = audio_resample_init(codec->channels, icodec->channels,
codec->sample_rate,
icodec->sample_rate);
/* Request specific number of channels */
icodec->channels = codec->channels;
} else {
ost->audio_resample = 1;
ost->resample = audio_resample_init(codec->channels, icodec->channels,
codec->sample_rate,
icodec->sample_rate);
ist->decoding_needed = 1;
ost->encoding_needed = 1;
break;
case CODEC_TYPE_VIDEO:
if (codec->width == icodec->width &&
codec->height == icodec->height &&
frame_topBand == 0 &&
frame_bottomBand == 0 &&
frame_leftBand == 0 &&
frame_rightBand == 0)
{
ost->video_resample = 0;
ost->video_crop = 0;
} else if ((codec->width == icodec->width -
(frame_leftBand + frame_rightBand)) &&
(codec->height == icodec->height -
(frame_topBand + frame_bottomBand)))
{
ost->video_resample = 0;
ost->video_crop = 1;
ost->topBand = frame_topBand;
ost->leftBand = frame_leftBand;
} else {
uint8_t *buf;
ost->video_resample = 1;
ost->video_crop = 0; // cropping is handled as part of resample
buf = av_malloc((codec->width * codec->height * 3) / 2);
if (!buf)
goto fail;
ost->pict_tmp.data[0] = buf;
ost->pict_tmp.data[1] = ost->pict_tmp.data[0] + (codec->width * codec->height);
ost->pict_tmp.data[2] = ost->pict_tmp.data[1] + (codec->width * codec->height) / 4;
ost->pict_tmp.linesize[0] = codec->width;
ost->pict_tmp.linesize[1] = codec->width / 2;
ost->pict_tmp.linesize[2] = codec->width / 2;
ost->img_resample_ctx = img_resample_full_init(
ost->st->codec.width, ost->st->codec.height,
ist->st->codec.width, ist->st->codec.height,
frame_topBand, frame_bottomBand,
frame_leftBand, frame_rightBand);
ost->encoding_needed = 1;
ist->decoding_needed = 1;
break;
default:
av_abort();
/* two pass mode */
if (ost->encoding_needed &&
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
char logfilename[1024];
FILE *f;
int size;
char *logbuffer;
snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
pass_logfilename ?
pass_logfilename : DEFAULT_PASS_LOGFILENAME, i);
if (codec->flags & CODEC_FLAG_PASS1) {
f = fopen(logfilename, "w");
if (!f) {
perror(logfilename);
ost->logfile = f;
} else {
/* read the log file */
f = fopen(logfilename, "r");
if (!f) {
perror(logfilename);
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
logbuffer = av_malloc(size + 1);
if (!logbuffer) {
fprintf(stderr, "Could not allocate log buffer\n");
fread(logbuffer, 1, size, f);
fclose(f);
logbuffer[size] = '\0';
codec->stats_in = logbuffer;
/* dump the file output parameters - cannot be done before in case
of stream copy */
for(i=0;i<nb_output_files;i++) {
dump_format(output_files[i], i, output_files[i]->filename, 1);
/* dump the stream mapping */
fprintf(stderr, "Stream mapping:\n");
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
fprintf(stderr, " Stream #%d.%d -> #%d.%d\n",
ist_table[ost->source_index]->file_index,
ist_table[ost->source_index]->index,
ost->file_index,
ost->index);
/* open each encoder */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->encoding_needed) {
AVCodec *codec;
codec = avcodec_find_encoder(ost->st->codec.codec_id);
if (!codec) {
fprintf(stderr, "Unsupported codec for output stream #%d.%d\n",
if (avcodec_open(&ost->st->codec, codec) < 0) {
fprintf(stderr, "Error while opening codec for stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
/* open each decoder */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
AVCodec *codec;
codec = avcodec_find_decoder(ist->st->codec.codec_id);
if (!codec) {
fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n",
ist->st->codec.codec_id, ist->file_index, ist->index);
if (avcodec_open(&ist->st->codec, codec) < 0) {
fprintf(stderr, "Error while opening codec for input stream #%d.%d\n",
ist->file_index, ist->index);
//if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO)
// ist->st->codec.flags |= CODEC_FLAG_REPEAT_FIELD;
ist->frame_decoded = 1;
/* init pts */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
/* compute buffer size max (should use a complete heuristic) */
for(i=0;i<nb_input_files;i++) {
file_table[i].buffer_size_max = 2048;
/* open files and write file headers */
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
if (av_write_header(os) < 0) {
fprintf(stderr, "Could not write header for output file #%d (incorrect codec paramters ?)\n", i);
ret = -EINVAL;
goto fail;
#ifndef CONFIG_WIN32
if (!do_play) {
fprintf(stderr, "Press [q] to stop encoding\n");
} else {
fprintf(stderr, "Press [q] to stop playing\n");
#endif
term_init();
stream_no_data = 0;
key = -1;
for(;;) {
int file_index, ist_index;
AVPacket pkt;
uint8_t *ptr;
int len;
uint8_t *data_buf;
int data_size, got_picture;
AVPicture picture;
short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
void *buffer_to_free;
double pts_min;
redo:
/* if 'q' pressed, exits */
if (key) {
/* read_key() returns 0 on EOF */
key = read_key();
if (key == 'q')
break;
/* select the stream that we must read now by looking at the
smallest output pts */
file_index = -1;
pts_min = 1e10;
for(i=0;i<nb_ostreams;i++) {
double pts;
ost = ost_table[i];
os = output_files[ost->file_index];
ist = ist_table[ost->source_index];
pts = (double)ost->st->pts.val * os->pts_num / os->pts_den;
if (!file_table[ist->file_index].eof_reached &&
pts < pts_min) {
pts_min = pts;
file_index = ist->file_index;
/* if none, if is finished */
if (file_index < 0) {
break;
/* finish if recording time exhausted */
if (recording_time > 0 && pts_min >= (recording_time / 1000000.0))
break;
/* read a packet from it and output it in the fifo */
is = input_files[file_index];
if (av_read_packet(is, &pkt) < 0) {
file_table[file_index].eof_reached = 1;
continue;
if (!pkt.size) {
stream_no_data = is;
} else {
stream_no_data = 0;
if (do_hex_dump) {
printf("stream #%d, size=%d:\n", pkt.stream_index, pkt.size);
av_hex_dump(pkt.data, pkt.size);
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
if (pkt.stream_index >= file_table[file_index].nb_streams)
goto discard_packet;
ist_index = file_table[file_index].ist_index + pkt.stream_index;
ist = ist_table[ist_index];
if (ist->discard)
goto discard_packet;
// printf("read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
len = pkt.size;
ptr = pkt.data;
pts_set = 0;
while (len > 0) {
int64_t ipts;
ipts = AV_NOPTS_VALUE;
/* decode the packet if needed */
data_buf = NULL; /* fail safe */
data_size = 0;
if (ist->decoding_needed) {
/* NOTE1: we only take into account the PTS if a new
frame has begun (MPEG semantics) */
/* NOTE2: even if the fraction is not initialized,
av_frac_set can be used to set the integer part */
if (ist->frame_decoded &&
pkt.pts != AV_NOPTS_VALUE &&
!pts_set) {
ipts = pkt.pts;
ist->frame_decoded = 0;
pts_set = 1;
switch(ist->st->codec.codec_type) {
case CODEC_TYPE_AUDIO:
/* XXX: could avoid copy if PCM 16 bits with same
endianness as CPU */
ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size,
ptr, len);
if (ret < 0)
goto fail_decode;
/* Some bug in mpeg audio decoder gives */
/* data_size < 0, it seems they are overflows */
if (data_size <= 0) {
/* no audio frame */
ptr += ret;
len -= ret;
continue;
data_buf = (uint8_t *)samples;
break;
case CODEC_TYPE_VIDEO:
{
AVFrame big_picture;
data_size = (ist->st->codec.width * ist->st->codec.height * 3) / 2;
ret = avcodec_decode_video(&ist->st->codec,
&big_picture, &got_picture, ptr, len);
picture= *(AVPicture*)&big_picture;
ist->st->quality= big_picture.quality;
if (ret < 0) {
fail_decode:
fprintf(stderr, "Error while decoding stream #%d.%d\n",
ist->file_index, ist->index);
av_free_packet(&pkt);
goto redo;
if (!got_picture) {
/* no picture yet */
ptr += ret;
len -= ret;
continue;
break;
default:
goto fail_decode;
} else {
data_buf = ptr;
data_size = len;
ret = len;
ptr += ret;
len -= ret;
buffer_to_free = 0;
if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) {
pre_process_video_frame(ist, &picture, &buffer_to_free);
ist->frame_decoded = 1;
/* frame rate emulation */
if (ist->st->codec.rate_emu) {
int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.frame_rate_base, 1000000, ist->st->codec.frame_rate);
int64_t now = av_gettime() - ist->start;
if (pts > now)
usleep(pts - now);
ist->frame++;
#if 0
/* mpeg PTS deordering : if it is a P or I frame, the PTS
is the one of the next displayed one */
/* XXX: add mpeg4 too ? */
if (ist->st->codec.codec_id == CODEC_ID_MPEG1VIDEO) {
if (ist->st->codec.pict_type != B_TYPE) {
int64_t tmp;
tmp = ist->last_ip_pts;
ist->last_ip_pts = ist->frac_pts.val;
ist->frac_pts.val = tmp;
#endif
/* transcode raw format, encode packets and output them */
for(i=0;i<nb_ostreams;i++) {
int frame_size;
ost = ost_table[i];
if (ost->source_index == ist_index) {
os = output_files[ost->file_index];
if (ipts != AV_NOPTS_VALUE) {
#if 0
printf("%d: got pts=%f %f\n",
i, pkt.pts / 90000.0,
(ipts - ost->st->pts.val) / 90000.0);
#endif
/* set the input output pts pairs */
ost->sync_ipts = (double)ipts * is->pts_num /
is->pts_den;
/* XXX: take into account the various fifos,
in particular for audio */
ost->sync_opts = ost->st->pts.val;
//printf("ipts=%lld sync_ipts=%f sync_opts=%lld pts.val=%lld pkt.pts=%lld\n", ipts, ost->sync_ipts, ost->sync_opts, ost->st->pts.val, pkt.pts);
} else {
//printf("pts.val=%lld\n", ost->st->pts.val);
ost->sync_ipts = AV_NOPTS_VALUE;
if (ost->encoding_needed) {
switch(ost->st->codec.codec_type) {
case CODEC_TYPE_AUDIO:
do_audio_out(os, ost, ist, data_buf, data_size);
break;
case CODEC_TYPE_VIDEO:
/* find an audio stream for synchro */
{
int i;
AVOutputStream *audio_sync, *ost1;
audio_sync = NULL;
for(i=0;i<nb_ostreams;i++) {
ost1 = ost_table[i];
if (ost1->file_index == ost->file_index &&
ost1->st->codec.codec_type == CODEC_TYPE_AUDIO) {
audio_sync = ost1;
break;
do_video_out(os, ost, ist, &picture, &frame_size, audio_sync);
if (do_vstats && frame_size)
do_video_stats(os, ost, frame_size);
break;
default:
av_abort();
} else {
AVFrame avframe;
/* no reencoding needed : output the packet directly */
/* force the input stream PTS */
memset(&avframe, 0, sizeof(AVFrame));
ost->st->codec.coded_frame= &avframe;
avframe.key_frame = pkt.flags & PKT_FLAG_KEY;
av_write_frame(os, ost->index, data_buf, data_size);
ost->st->codec.frame_number++;
ost->frame_number++;
av_free(buffer_to_free);
ipts = AV_NOPTS_VALUE;
discard_packet:
av_free_packet(&pkt);
/* dump report by using the output first video and audio streams */
print_report(output_files, ost_table, nb_ostreams, 0);
term_exit();
/* dump report by using the first video and audio streams */
print_report(output_files, ost_table, nb_ostreams, 1);
/* close each encoder */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->encoding_needed) {
av_freep(&ost->st->codec.stats_in);
avcodec_close(&ost->st->codec);
/* close each decoder */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
avcodec_close(&ist->st->codec);
/* write the trailer if needed and close file */
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
av_write_trailer(os);
/* finished ! */
ret = 0;
fail1:
av_free(file_table);
if (ist_table) {
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
av_free(ist);
av_free(ist_table);
if (ost_table) {
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost) {
if (ost->logfile) {
fclose(ost->logfile);
ost->logfile = NULL;
fifo_free(&ost->fifo); /* works even if fifo is not
initialized but set to zero */
av_free(ost->pict_tmp.data[0]);
if (ost->video_resample)
img_resample_close(ost->img_resample_ctx);
if (ost->audio_resample)
audio_resample_close(ost->resample);
av_free(ost);
av_free(ost_table);
return ret;
fail:
ret = -ENOMEM;
goto fail1; | 13,267 |
FFmpeg | d62030ffcaf14dd801918fe26e670d68fdc21984 | 1 | static void RENAME(mix8to2)(SAMPLE **out, const SAMPLE **in, COEFF *coeffp, integer len){
int i;
for(i=0; i<len; i++) {
INTER t = in[2][i]*coeffp[0*8+2] + in[3][i]*coeffp[0*8+3];
out[0][i] = R(t + in[0][i]*(INTER)coeffp[0*8+0] + in[4][i]*(INTER)coeffp[0*8+4] + in[6][i]*(INTER)coeffp[0*8+6]);
out[1][i] = R(t + in[1][i]*(INTER)coeffp[1*8+1] + in[5][i]*(INTER)coeffp[1*8+5] + in[7][i]*(INTER)coeffp[1*8+7]);
}
}
| 13,269 |
qemu | 27ef9cb0e77eda46618ea084adffa63ebde5be80 | 1 | static CharDriverState *qemu_chr_open_pp_fd(int fd,
ChardevCommon *backend,
Error **errp)
{
CharDriverState *chr;
ParallelCharDriver *drv;
if (ioctl(fd, PPCLAIM) < 0) {
error_setg_errno(errp, errno, "not a parallel port");
close(fd);
return NULL;
}
drv = g_new0(ParallelCharDriver, 1);
drv->fd = fd;
drv->mode = IEEE1284_MODE_COMPAT;
chr = qemu_chr_alloc(backend, errp);
if (!chr) {
return NULL;
}
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
chr->chr_close = pp_close;
chr->opaque = drv;
return chr;
}
| 13,271 |
qemu | 069d89b8a8dc5a9af4733bca14763b45bbb2546f | 1 | static void pprint_data(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
{
struct iovec *sg = get_sg(pdu, rx);
size_t offset = *offsetp;
unsigned int count;
int32_t size;
int total, i, j;
ssize_t len;
if (rx) {
count = pdu->elem.in_num;
} else
count = pdu->elem.out_num;
}
| 13,272 |
FFmpeg | 50833c9f7b4e1922197a8955669f8ab3589c8cef | 1 | static void put_audio_specific_config(AVCodecContext *avctx)
{
PutBitContext pb;
AACEncContext *s = avctx->priv_data;
init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8);
put_bits(&pb, 5, 2); //object type - AAC-LC
put_bits(&pb, 4, s->samplerate_index); //sample rate index
put_bits(&pb, 4, s->channels);
//GASpecificConfig
put_bits(&pb, 1, 0); //frame length - 1024 samples
put_bits(&pb, 1, 0); //does not depend on core coder
put_bits(&pb, 1, 0); //is not extension
//Explicitly Mark SBR absent
put_bits(&pb, 11, 0x2b7); //sync extension
put_bits(&pb, 5, AOT_SBR);
put_bits(&pb, 1, 0);
flush_put_bits(&pb);
}
| 13,274 |
qemu | 1e9b65bb1bad51735cab6c861c29b592dccabf0e | 1 | static void error_setv(Error **errp, ErrorClass err_class,
const char *fmt, va_list ap)
{
Error *err;
int saved_errno = errno;
if (errp == NULL) {
return;
}
assert(*errp == NULL);
err = g_malloc0(sizeof(*err));
err->msg = g_strdup_vprintf(fmt, ap);
err->err_class = err_class;
if (errp == &error_abort) {
error_report_err(err);
abort();
}
*errp = err;
errno = saved_errno;
}
| 13,275 |
qemu | b25f23e7dbc6bc0dcda010222a4f178669d1aedc | 1 | static QObject *qdict_get_obj(const QDict *qdict, const char *key, QType type)
{
QObject *obj;
obj = qdict_get(qdict, key);
assert(obj != NULL);
assert(qobject_type(obj) == type);
return obj;
}
| 13,276 |
FFmpeg | 220b24c7c97dc033ceab1510549f66d0e7b52ef1 | 1 | static av_cold int libschroedinger_encode_init(AVCodecContext *avctx)
{
SchroEncoderParams *p_schro_params = avctx->priv_data;
SchroVideoFormatEnum preset;
/* Initialize the libraries that libschroedinger depends on. */
schro_init();
/* Create an encoder object. */
p_schro_params->encoder = schro_encoder_new();
if (!p_schro_params->encoder) {
av_log(avctx, AV_LOG_ERROR,
"Unrecoverable Error: schro_encoder_new failed. ");
return -1;
}
/* Initialize the format. */
preset = ff_get_schro_video_format_preset(avctx);
p_schro_params->format =
schro_encoder_get_video_format(p_schro_params->encoder);
schro_video_format_set_std_video_format(p_schro_params->format, preset);
p_schro_params->format->width = avctx->width;
p_schro_params->format->height = avctx->height;
if (set_chroma_format(avctx) == -1)
return -1;
if (avctx->color_primaries == AVCOL_PRI_BT709) {
p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
} else if (avctx->color_primaries == AVCOL_PRI_BT470BG) {
p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
} else if (avctx->color_primaries == AVCOL_PRI_SMPTE170M) {
p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
}
if (avctx->colorspace == AVCOL_SPC_BT709) {
p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
} else if (avctx->colorspace == AVCOL_SPC_BT470BG) {
p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
}
if (avctx->color_trc == AVCOL_TRC_BT709) {
p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
}
if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
&p_schro_params->frame_format) == -1) {
av_log(avctx, AV_LOG_ERROR,
"This codec currently supports only planar YUV 4:2:0, 4:2:2"
" and 4:4:4 formats.\n");
return -1;
}
p_schro_params->format->frame_rate_numerator = avctx->time_base.den;
p_schro_params->format->frame_rate_denominator = avctx->time_base.num;
p_schro_params->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
avctx->width,
avctx->height, 1);
if (!avctx->gop_size) {
schro_encoder_setting_set_double(p_schro_params->encoder,
"gop_structure",
SCHRO_ENCODER_GOP_INTRA_ONLY);
#if FF_API_CODER_TYPE
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->coder_type != FF_CODER_TYPE_VLC)
p_schro_params->noarith = 0;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
schro_encoder_setting_set_double(p_schro_params->encoder,
"enable_noarith",
p_schro_params->noarith);
} else {
schro_encoder_setting_set_double(p_schro_params->encoder,
"au_distance", avctx->gop_size);
avctx->has_b_frames = 1;
p_schro_params->dts = -1;
}
/* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
if (!avctx->global_quality) {
/* lossless coding */
schro_encoder_setting_set_double(p_schro_params->encoder,
"rate_control",
SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
} else {
int quality;
schro_encoder_setting_set_double(p_schro_params->encoder,
"rate_control",
SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
quality = avctx->global_quality / FF_QP2LAMBDA;
if (quality > 10)
quality = 10;
schro_encoder_setting_set_double(p_schro_params->encoder,
"quality", quality);
}
} else {
schro_encoder_setting_set_double(p_schro_params->encoder,
"rate_control",
SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);
schro_encoder_setting_set_double(p_schro_params->encoder,
"bitrate", avctx->bit_rate);
}
if (avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)
/* All material can be coded as interlaced or progressive
irrespective of the type of source material. */
schro_encoder_setting_set_double(p_schro_params->encoder,
"interlaced_coding", 1);
schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop",
!(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP));
/* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
* and libdirac support other bit-depth data. */
schro_video_format_set_std_signal_range(p_schro_params->format,
SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
/* Set the encoder format. */
schro_encoder_set_video_format(p_schro_params->encoder,
p_schro_params->format);
/* Set the debug level. */
schro_debug_set_level(avctx->debug);
schro_encoder_start(p_schro_params->encoder);
/* Initialize the encoded frame queue. */
ff_schro_queue_init(&p_schro_params->enc_frame_queue);
return 0;
}
| 13,277 |
FFmpeg | 02d6d053396626ff5b3390e48a9933e0d4164b28 | 1 | static int dca_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int channel_mask;
int channel_layout;
int lfe_samples;
int num_core_channels = 0;
int i, ret;
float **samples_flt;
float *src_chan;
float *dst_chan;
DCAContext *s = avctx->priv_data;
int core_ss_end;
int channels, full_channels;
float scale;
int achan;
int chset;
int mask;
int lavc;
int posn;
int j, k;
int endch;
s->xch_present = 0;
s->dca_buffer_size = ff_dca_convert_bitstream(buf, buf_size, s->dca_buffer,
DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);
if (s->dca_buffer_size == AVERROR_INVALIDDATA) {
av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
}
init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
if ((ret = dca_parse_frame_header(s)) < 0) {
//seems like the frame is corrupt, try with the next one
return ret;
}
//set AVCodec values with parsed data
avctx->sample_rate = s->sample_rate;
avctx->bit_rate = s->bit_rate;
s->profile = FF_PROFILE_DTS;
for (i = 0; i < (s->sample_blocks / 8); i++) {
if ((ret = dca_decode_block(s, 0, i))) {
av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
return ret;
}
}
/* record number of core channels incase less than max channels are requested */
num_core_channels = s->prim_channels;
if (s->ext_coding)
s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
else
s->core_ext_mask = 0;
core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
/* only scan for extensions if ext_descr was unknown or indicated a
* supported XCh extension */
if (s->core_ext_mask < 0 || s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) {
/* if ext_descr was unknown, clear s->core_ext_mask so that the
* extensions scan can fill it up */
s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
/* extensions start at 32-bit boundaries into bitstream */
skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
while (core_ss_end - get_bits_count(&s->gb) >= 32) {
uint32_t bits = get_bits_long(&s->gb, 32);
switch (bits) {
case 0x5a5a5a5a: {
int ext_amode, xch_fsize;
s->xch_base_channel = s->prim_channels;
/* validate sync word using XCHFSIZE field */
xch_fsize = show_bits(&s->gb, 10);
if ((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) &&
(s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1))
continue;
/* skip length-to-end-of-frame field for the moment */
skip_bits(&s->gb, 10);
s->core_ext_mask |= DCA_EXT_XCH;
/* extension amode(number of channels in extension) should be 1 */
/* AFAIK XCh is not used for more channels */
if ((ext_amode = get_bits(&s->gb, 4)) != 1) {
av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not"
" supported!\n", ext_amode);
continue;
}
if (s->xch_base_channel < 2) {
av_log_ask_for_sample(avctx, "XCh with fewer than 2 base channels is not supported\n");
continue;
}
/* much like core primary audio coding header */
dca_parse_audio_coding_header(s, s->xch_base_channel, 0);
for (i = 0; i < (s->sample_blocks / 8); i++)
if ((ret = dca_decode_block(s, s->xch_base_channel, i))) {
av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n");
continue;
}
s->xch_present = 1;
break;
}
case 0x47004a03:
/* XXCh: extended channels */
/* usually found either in core or HD part in DTS-HD HRA streams,
* but not in DTS-ES which contains XCh extensions instead */
s->core_ext_mask |= DCA_EXT_XXCH;
dca_xxch_decode_frame(s);
break;
case 0x1d95f262: {
int fsize96 = show_bits(&s->gb, 12) + 1;
if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96)
continue;
av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n",
get_bits_count(&s->gb));
skip_bits(&s->gb, 12);
av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96);
av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4));
s->core_ext_mask |= DCA_EXT_X96;
break;
}
}
skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
}
} else {
/* no supported extensions, skip the rest of the core substream */
skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));
}
if (s->core_ext_mask & DCA_EXT_X96)
s->profile = FF_PROFILE_DTS_96_24;
else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))
s->profile = FF_PROFILE_DTS_ES;
/* check for ExSS (HD part) */
if (s->dca_buffer_size - s->frame_size > 32 &&
get_bits_long(&s->gb, 32) == DCA_HD_MARKER)
dca_exss_parse_header(s);
avctx->profile = s->profile;
full_channels = channels = s->prim_channels + !!s->lfe;
/* If we have XXCH then the channel layout is managed differently */
/* note that XLL will also have another way to do things */
if (!(s->core_ext_mask & DCA_EXT_XXCH)
|| (s->core_ext_mask & DCA_EXT_XXCH && avctx->request_channels > 0
&& avctx->request_channels
< num_core_channels + !!s->lfe + s->xxch_chset_nch[0]))
{ /* xxx should also do MA extensions */
if (s->amode < 16) {
avctx->channel_layout = dca_core_channel_layout[s->amode];
if (s->xch_present && (!avctx->request_channels ||
avctx->request_channels
> num_core_channels + !!s->lfe)) {
avctx->channel_layout |= AV_CH_BACK_CENTER;
if (s->lfe) {
avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
s->channel_order_tab = dca_channel_reorder_lfe_xch[s->amode];
} else {
s->channel_order_tab = dca_channel_reorder_nolfe_xch[s->amode];
}
} else {
channels = num_core_channels + !!s->lfe;
s->xch_present = 0; /* disable further xch processing */
if (s->lfe) {
avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
s->channel_order_tab = dca_channel_reorder_lfe[s->amode];
} else
s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
}
if (channels > !!s->lfe &&
s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
if (av_get_channel_layout_nb_channels(avctx->channel_layout) != channels) {
av_log(avctx, AV_LOG_ERROR, "Number of channels %d mismatches layout %d\n", channels, av_get_channel_layout_nb_channels(avctx->channel_layout));
}
if (avctx->request_channels == 2 && s->prim_channels > 2) {
channels = 2;
s->output = DCA_STEREO;
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
}
else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
s->channel_order_tab = dca_channel_order_native;
}
s->lfe_index = dca_lfe_index[s->amode];
} else {
av_log(avctx, AV_LOG_ERROR,
"Non standard configuration %d !\n", s->amode);
}
s->xxch_dmix_embedded = 0;
} else {
/* we only get here if an XXCH channel set can be added to the mix */
channel_mask = s->xxch_core_spkmask;
if (avctx->request_channels > 0
&& avctx->request_channels < s->prim_channels) {
channels = num_core_channels + !!s->lfe;
for (i = 0; i < s->xxch_chset && channels + s->xxch_chset_nch[i]
<= avctx->request_channels; i++) {
channels += s->xxch_chset_nch[i];
channel_mask |= s->xxch_spk_masks[i];
}
} else {
channels = s->prim_channels + !!s->lfe;
for (i = 0; i < s->xxch_chset; i++) {
channel_mask |= s->xxch_spk_masks[i];
}
}
/* Given the DTS spec'ed channel mask, generate an avcodec version */
channel_layout = 0;
for (i = 0; i < s->xxch_nbits_spk_mask; ++i) {
if (channel_mask & (1 << i)) {
channel_layout |= map_xxch_to_native[i];
}
}
/* make sure that we have managed to get equivelant dts/avcodec channel
* masks in some sense -- unfortunately some channels could overlap */
if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
av_log(avctx, AV_LOG_DEBUG,
"DTS-XXCH: Inconsistant avcodec/dts channel layouts\n");
}
avctx->channel_layout = channel_layout;
if (!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)) {
/* Estimate DTS --> avcodec ordering table */
for (chset = -1, j = 0; chset < s->xxch_chset; ++chset) {
mask = chset >= 0 ? s->xxch_spk_masks[chset]
: s->xxch_core_spkmask;
for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
if (mask & ~(DCA_XXCH_LFE1 | DCA_XXCH_LFE2) & (1 << i)) {
lavc = map_xxch_to_native[i];
posn = av_popcount(channel_layout & (lavc - 1));
s->xxch_order_tab[j++] = posn;
}
}
}
s->lfe_index = av_popcount(channel_layout & (AV_CH_LOW_FREQUENCY-1));
} else { /* native ordering */
for (i = 0; i < channels; i++)
s->xxch_order_tab[i] = i;
s->lfe_index = channels - 1;
}
s->channel_order_tab = s->xxch_order_tab;
}
if (avctx->channels != channels) {
if (avctx->channels)
av_log(avctx, AV_LOG_INFO, "Number of channels changed in DCA decoder (%d -> %d)\n", avctx->channels, channels);
avctx->channels = channels;
}
/* get output buffer */
s->frame.nb_samples = 256 * (s->sample_blocks / 8);
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
samples_flt = (float **) s->frame.extended_data;
/* allocate buffer for extra channels if downmixing */
if (avctx->channels < full_channels) {
ret = av_samples_get_buffer_size(NULL, full_channels - channels,
s->frame.nb_samples,
avctx->sample_fmt, 0);
if (ret < 0)
return ret;
av_fast_malloc(&s->extra_channels_buffer,
&s->extra_channels_buffer_size, ret);
if (!s->extra_channels_buffer)
return AVERROR(ENOMEM);
ret = av_samples_fill_arrays((uint8_t **)s->extra_channels, NULL,
s->extra_channels_buffer,
full_channels - channels,
s->frame.nb_samples, avctx->sample_fmt, 0);
if (ret < 0)
return ret;
}
/* filter to get final output */
for (i = 0; i < (s->sample_blocks / 8); i++) {
int ch;
for (ch = 0; ch < channels; ch++)
s->samples_chanptr[ch] = samples_flt[ch] + i * 256;
for (; ch < full_channels; ch++)
s->samples_chanptr[ch] = s->extra_channels[ch - channels] + i * 256;
dca_filter_channels(s, i);
/* If this was marked as a DTS-ES stream we need to subtract back- */
/* channel from SL & SR to remove matrixed back-channel signal */
if ((s->source_pcm_res & 1) && s->xch_present) {
float *back_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel]];
float *lt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 2]];
float *rt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 1]];
s->fdsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);
s->fdsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);
}
/* If stream contains XXCH, we might need to undo an embedded downmix */
if (s->xxch_dmix_embedded) {
/* Loop over channel sets in turn */
ch = num_core_channels;
for (chset = 0; chset < s->xxch_chset; chset++) {
endch = ch + s->xxch_chset_nch[chset];
mask = s->xxch_dmix_embedded;
/* undo downmix */
for (j = ch; j < endch; j++) {
if (mask & (1 << j)) { /* this channel has been mixed-out */
src_chan = s->samples_chanptr[s->channel_order_tab[j]];
for (k = 0; k < endch; k++) {
achan = s->channel_order_tab[k];
scale = s->xxch_dmix_coeff[j][k];
if (scale != 0.0) {
dst_chan = s->samples_chanptr[achan];
s->fdsp.vector_fmac_scalar(dst_chan, src_chan,
-scale, 256);
}
}
}
}
/* if a downmix has been embedded then undo the pre-scaling */
if ((mask & (1 << ch)) && s->xxch_dmix_sf[chset] != 1.0f) {
scale = s->xxch_dmix_sf[chset];
for (j = 0; j < ch; j++) {
src_chan = s->samples_chanptr[s->channel_order_tab[j]];
for (k = 0; k < 256; k++)
src_chan[k] *= scale;
}
/* LFE channel is always part of core, scale if it exists */
if (s->lfe) {
src_chan = s->samples_chanptr[s->lfe_index];
for (k = 0; k < 256; k++)
src_chan[k] *= scale;
}
}
ch = endch;
}
}
}
/* update lfe history */
lfe_samples = 2 * s->lfe * (s->sample_blocks / 8);
for (i = 0; i < 2 * s->lfe * 4; i++)
s->lfe_data[i] = s->lfe_data[i + lfe_samples];
*got_frame_ptr = 1;
*(AVFrame *) data = s->frame;
return buf_size;
} | 13,279 |
FFmpeg | 9c2216976907336dfae0e8e38a4d70ca2465a92c | 1 | static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
const uint8_t *src, int size, int lines)
{
int c, line, pixels, code, ret;
const uint8_t *ssrc = src;
int width = ((s->width * s->bpp) + 7) >> 3;
if (size <= 0)
return AVERROR_INVALIDDATA;
if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
#if CONFIG_ZLIB
return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
#else
av_log(s->avctx, AV_LOG_ERROR,
"zlib support not enabled, "
"deflate compression not supported\n");
return AVERROR(ENOSYS);
#endif
}
if (s->compr == TIFF_LZW) {
if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
return ret;
}
}
if (s->compr == TIFF_CCITT_RLE ||
s->compr == TIFF_G3 ||
s->compr == TIFF_G4) {
return tiff_unpack_fax(s, dst, stride, src, size, lines);
}
for (line = 0; line < lines; line++) {
if (src - ssrc > size) {
av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
return AVERROR_INVALIDDATA;
}
switch (s->compr) {
case TIFF_RAW:
if (ssrc + size - src < width)
return AVERROR_INVALIDDATA;
if (!s->fill_order) {
memcpy(dst, src, width);
} else {
int i;
for (i = 0; i < width; i++)
dst[i] = ff_reverse[src[i]];
}
src += width;
break;
case TIFF_PACKBITS:
for (pixels = 0; pixels < width;) {
code = (int8_t) *src++;
if (code >= 0) {
code++;
if (pixels + code > width) {
av_log(s->avctx, AV_LOG_ERROR,
"Copy went out of bounds\n");
return AVERROR_INVALIDDATA;
}
memcpy(dst + pixels, src, code);
src += code;
pixels += code;
} else if (code != -128) { // -127..-1
code = (-code) + 1;
if (pixels + code > width) {
av_log(s->avctx, AV_LOG_ERROR,
"Run went out of bounds\n");
return AVERROR_INVALIDDATA;
}
c = *src++;
memset(dst + pixels, c, code);
pixels += code;
}
}
break;
case TIFF_LZW:
pixels = ff_lzw_decode(s->lzw, dst, width);
if (pixels < width) {
av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
pixels, width);
return AVERROR_INVALIDDATA;
}
break;
}
dst += stride;
}
return 0;
}
| 13,280 |
FFmpeg | e7d4a2a721ae863488f6a3814f9dcdbc6e8f5166 | 1 | AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
AVBitStreamFilter *bsf= first_bitstream_filter;
while(bsf){
if(!strcmp(name, bsf->name)){
AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
bsfc->filter= bsf;
bsfc->priv_data= av_mallocz(bsf->priv_data_size);
return bsfc;
}
bsf= bsf->next;
}
return NULL;
}
| 13,281 |
FFmpeg | 1181d93231e9b807965724587d363c1cfd5a1d0d | 0 | void ff_avg_h264_qpel8_mc22_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_mid_and_aver_dst_8w_msa(src - (2 * stride) - 2,
stride, dst, stride, 8);
}
| 13,283 |
FFmpeg | 0058584580b87feb47898e60e4b80c7f425882ad | 0 | static int ac3_decode_init(AVCodecContext *avctx)
{
AC3DecodeContext *ctx = avctx->priv_data;
ac3_common_init();
ff_mdct_init(&ctx->imdct_ctx_256, 8, 1);
ff_mdct_init(&ctx->imdct_ctx_512, 9, 1);
ctx->samples = av_mallocz(6 * 256 * sizeof (float));
if (!ctx->samples) {
av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory for samples\n");
return -1;
}
dither_seed(&ctx->state, 0);
return 0;
}
| 13,284 |
FFmpeg | d6604b29ef544793479d7fb4e05ef6622bb3e534 | 0 | static av_cold int flashsv_encode_init(AVCodecContext *avctx)
{
FlashSVContext *s = avctx->priv_data;
s->avctx = avctx;
if (avctx->width > 4095 || avctx->height > 4095) {
av_log(avctx, AV_LOG_ERROR,
"Input dimensions too large, input must be max 4096x4096 !\n");
return AVERROR_INVALIDDATA;
}
// Needed if zlib unused or init aborted before deflateInit
memset(&s->zstream, 0, sizeof(z_stream));
s->last_key_frame = 0;
s->image_width = avctx->width;
s->image_height = avctx->height;
s->tmpblock = av_mallocz(3 * 256 * 256);
s->encbuffer = av_mallocz(s->image_width * s->image_height * 3);
if (!s->tmpblock || !s->encbuffer) {
av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
return AVERROR(ENOMEM);
}
avctx->coded_frame = av_frame_alloc();
if (!avctx->coded_frame) {
flashsv_encode_end(avctx);
return AVERROR(ENOMEM);
}
return 0;
}
| 13,285 |
FFmpeg | 03037a4aad8b92c00ef2f115605ad20fc4410fe5 | 0 | static int subtitle_thread(void *arg)
{
VideoState *is = arg;
Frame *sp;
int got_subtitle;
double pts;
int i;
for (;;) {
if (!(sp = frame_queue_peek_writable(&is->subpq)))
return 0;
if ((got_subtitle = decoder_decode_frame(&is->subdec, NULL, &sp->sub)) < 0)
break;
pts = 0;
if (got_subtitle && sp->sub.format == 0) {
if (sp->sub.pts != AV_NOPTS_VALUE)
pts = sp->sub.pts / (double)AV_TIME_BASE;
sp->pts = pts;
sp->serial = is->subdec.pkt_serial;
for (i = 0; i < sp->sub.num_rects; i++)
{
int in_w = sp->sub.rects[i]->w;
int in_h = sp->sub.rects[i]->h;
int subw = is->subdec.avctx->width ? is->subdec.avctx->width : is->viddec_width;
int subh = is->subdec.avctx->height ? is->subdec.avctx->height : is->viddec_height;
int out_w = is->viddec_width ? in_w * is->viddec_width / subw : in_w;
int out_h = is->viddec_height ? in_h * is->viddec_height / subh : in_h;
AVPicture newpic;
//can not use avpicture_alloc as it is not compatible with avsubtitle_free()
av_image_fill_linesizes(newpic.linesize, AV_PIX_FMT_YUVA420P, out_w);
newpic.data[0] = av_malloc(newpic.linesize[0] * out_h);
newpic.data[3] = av_malloc(newpic.linesize[3] * out_h);
newpic.data[1] = av_malloc(newpic.linesize[1] * ((out_h+1)/2));
newpic.data[2] = av_malloc(newpic.linesize[2] * ((out_h+1)/2));
is->sub_convert_ctx = sws_getCachedContext(is->sub_convert_ctx,
in_w, in_h, AV_PIX_FMT_PAL8, out_w, out_h,
AV_PIX_FMT_YUVA420P, sws_flags, NULL, NULL, NULL);
if (!is->sub_convert_ctx || !newpic.data[0] || !newpic.data[3] ||
!newpic.data[1] || !newpic.data[2]
) {
av_log(NULL, AV_LOG_FATAL, "Cannot initialize the sub conversion context\n");
exit(1);
}
sws_scale(is->sub_convert_ctx,
(void*)sp->sub.rects[i]->pict.data, sp->sub.rects[i]->pict.linesize,
0, in_h, newpic.data, newpic.linesize);
av_free(sp->sub.rects[i]->pict.data[0]);
av_free(sp->sub.rects[i]->pict.data[1]);
sp->sub.rects[i]->pict = newpic;
sp->sub.rects[i]->w = out_w;
sp->sub.rects[i]->h = out_h;
sp->sub.rects[i]->x = sp->sub.rects[i]->x * out_w / in_w;
sp->sub.rects[i]->y = sp->sub.rects[i]->y * out_h / in_h;
}
/* now we can update the picture count */
frame_queue_push(&is->subpq);
} else if (got_subtitle) {
avsubtitle_free(&sp->sub);
}
}
return 0;
}
| 13,286 |
FFmpeg | 57835fc1aeaf0b3bbc0816b123a931ea39de758b | 0 | static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset)
{
uint8_t *prev, *cur;
int blk, blocks, t, blk2;
int blocktypes = 0;
int x, y, a, b;
int pattype, pattern;
const int width = c->avctx->width;
uint8_t *pstart = c->prev_frame;
uint8_t *pend = c->prev_frame + width*c->avctx->height;
prev = c->prev_frame + offset;
cur = c->frame;
blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);
blk2 = 0;
for(blk = 0; blk < blocks; blk++){
if(!(blk & 3))
blocktypes = bytestream_get_byte(&buf);
switch(blocktypes & 0xC0){
case 0x00: //skip
for(y = 0; y < 4; y++)
if(check_line(prev + y*width, pstart, pend))
memcpy(cur + y*width, prev + y*width, 4);
else
memset(cur + y*width, 0, 4);
break;
case 0x40:
t = bytestream_get_byte(&buf);
if(!t){ //raw block
for(y = 0; y < 4; y++)
memcpy(cur + y*width, buf + y*4, 4);
buf += 16;
}else{ // motion compensation
x = ((t & 0xF)^8) - 8;
y = ((t >> 4) ^8) - 8;
t = x + y*width;
for(y = 0; y < 4; y++)
if(check_line(prev + t + y*width, pstart, pend))
memcpy(cur + y*width, prev + t + y*width, 4);
else
memset(cur + y*width, 0, 4);
}
break;
case 0x80: // fill
t = bytestream_get_byte(&buf);
for(y = 0; y < 4; y++)
memset(cur + y*width, t, 4);
break;
case 0xC0: // pattern fill
t = bytestream_get_byte(&buf);
pattype = t >> 6;
pattern = vb_patterns[t & 0x3F];
switch(pattype){
case 0:
a = bytestream_get_byte(&buf);
b = bytestream_get_byte(&buf);
for(y = 0; y < 4; y++)
for(x = 0; x < 4; x++, pattern >>= 1)
cur[x + y*width] = (pattern & 1) ? b : a;
break;
case 1:
pattern = ~pattern;
case 2:
a = bytestream_get_byte(&buf);
for(y = 0; y < 4; y++)
for(x = 0; x < 4; x++, pattern >>= 1)
if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))
cur[x + y*width] = prev[x + y*width];
else
cur[x + y*width] = a;
break;
case 3:
av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk);
return -1;
}
break;
}
blocktypes <<= 2;
cur += 4;
prev += 4;
blk2++;
if(blk2 == (width >> 2)){
blk2 = 0;
cur += width * 3;
prev += width * 3;
}
}
return 0;
}
| 13,287 |
FFmpeg | 5e53486545726987ab4482321d4dcf7e23e7652f | 0 | static void pre_calc_cosmod(DCAContext * s)
{
int i, j, k;
static int cosmod_inited = 0;
if(cosmod_inited) return;
for (j = 0, k = 0; k < 16; k++)
for (i = 0; i < 16; i++)
cos_mod[j++] = cos((2 * i + 1) * (2 * k + 1) * M_PI / 64);
for (k = 0; k < 16; k++)
for (i = 0; i < 16; i++)
cos_mod[j++] = cos((i) * (2 * k + 1) * M_PI / 32);
for (k = 0; k < 16; k++)
cos_mod[j++] = 0.25 / (2 * cos((2 * k + 1) * M_PI / 128));
for (k = 0; k < 16; k++)
cos_mod[j++] = -0.25 / (2.0 * sin((2 * k + 1) * M_PI / 128));
cosmod_inited = 1;
}
| 13,288 |
FFmpeg | d04fdff1617dd2bc1e24b940b6ed590d3188522b | 0 | static int RENAME(dct_quantize)(MpegEncContext *s,
DCTELEM *block, int n,
int qscale, int *overflow)
{
int level=0, last_non_zero_p1, q; //=0 is cuz gcc says uninitalized ...
const uint16_t *qmat, *bias;
static __align8 int16_t temp_block[64];
//s->fdct (block);
ff_fdct_mmx (block); //cant be anything else ...
if (s->mb_intra) {
int dummy;
if (n < 4)
q = s->y_dc_scale;
else
q = s->c_dc_scale;
/* note: block[0] is assumed to be positive */
if (!s->h263_aic) {
#if 1
asm volatile (
"imul %%ecx \n\t"
: "=d" (level), "=a"(dummy)
: "a" ((block[0]>>2) + q), "c" (inverse[q<<1])
);
#else
asm volatile (
"xorl %%edx, %%edx \n\t"
"divw %%cx \n\t"
"movzwl %%ax, %%eax \n\t"
: "=a" (level)
: "a" ((block[0]>>2) + q), "c" (q<<1)
: "%edx"
);
#endif
} else
/* For AIC we skip quant/dequant of INTRADC */
level = (block[0] + 4)>>3;
block[0]=0; //avoid fake overflow
// temp_block[0] = (block[0] + (q >> 1)) / q;
last_non_zero_p1 = 1;
bias = s->q_intra_matrix16_bias[qscale];
qmat = s->q_intra_matrix16[qscale];
} else {
last_non_zero_p1 = 0;
bias = s->q_inter_matrix16_bias[qscale];
qmat = s->q_inter_matrix16[qscale];
}
if(s->out_format == FMT_H263 && s->mpeg_quant==0){
/* PROLOGUE */
asm volatile(
"movd %%eax, %%mm3 \n\t" // last_non_zero_p1
SPREADW(%%mm3)
"pxor %%mm7, %%mm7 \n\t" // 0
"pxor %%mm4, %%mm4 \n\t" // 0
"movq (%1), %%mm5 \n\t" // qmat[0]
"pxor %%mm6, %%mm6 \n\t"
"psubw (%2), %%mm6 \n\t" // -bias[0]
"movl $-128, %%eax \n\t"
: "+a" (last_non_zero_p1)
: "r" (qmat), "r" (bias)
);
/* CORE */
asm volatile(
".balign 16 \n\t"
"1: \n\t"
"pxor %%mm1, %%mm1 \n\t" // 0
"movq (%1, %%eax), %%mm0 \n\t" // block[i]
"pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00
"pxor %%mm1, %%mm0 \n\t"
"psubw %%mm1, %%mm0 \n\t" // ABS(block[i])
"psubusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0]
"pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
"por %%mm0, %%mm4 \n\t"
"pxor %%mm1, %%mm0 \n\t"
"psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
"movq %%mm0, (%3, %%eax) \n\t"
"pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00
"movq (%2, %%eax), %%mm1 \n\t"
"movq %%mm7, (%1, %%eax) \n\t" // 0
"pandn %%mm1, %%mm0 \n\t"
PMAXW(%%mm0, %%mm3)
"addl $8, %%eax \n\t"
" js 1b \n\t"
: "+a" (last_non_zero_p1)
: "r" (block+64), "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
);
/* EPILOGUE */
asm volatile(
"movq %%mm3, %%mm0 \n\t"
"psrlq $32, %%mm3 \n\t"
PMAXW(%%mm0, %%mm3)
"movq %%mm3, %%mm0 \n\t"
"psrlq $16, %%mm3 \n\t"
PMAXW(%%mm0, %%mm3)
"movd %%mm3, %%eax \n\t"
"movzbl %%al, %%eax \n\t" // last_non_zero_p1
"movd %2, %%mm1 \n\t" // max_qcoeff
SPREADW(%%mm1)
"psubusw %%mm1, %%mm4 \n\t"
"packuswb %%mm4, %%mm4 \n\t"
"movd %%mm4, %1 \n\t" // *overflow
: "+a" (last_non_zero_p1), "=r" (*overflow)
: "r" (s->max_qcoeff)
);
}else{ // FMT_H263
asm volatile(
"pushl %%ebp \n\t"
"pushl %%ebx \n\t"
"movl %0, %%ebp \n\t"
"movl (%%ebp), %%ebx \n\t"
"movd %%ebx, %%mm3 \n\t" // last_non_zero_p1
SPREADW(%%mm3)
"pxor %%mm7, %%mm7 \n\t" // 0
"pxor %%mm4, %%mm4 \n\t" // 0
"movl $-128, %%ebx \n\t"
".balign 16 \n\t"
"1: \n\t"
"pxor %%mm1, %%mm1 \n\t" // 0
"movq (%1, %%ebx), %%mm0 \n\t" // block[i]
"pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00
"pxor %%mm1, %%mm0 \n\t"
"psubw %%mm1, %%mm0 \n\t" // ABS(block[i])
"movq (%3, %%ebx), %%mm6 \n\t" // bias[0]
"paddusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0]
"movq (%2, %%ebx), %%mm5 \n\t" // qmat[i]
"pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16
"por %%mm0, %%mm4 \n\t"
"pxor %%mm1, %%mm0 \n\t"
"psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
"movq %%mm0, (%5, %%ebx) \n\t"
"pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00
"movq (%4, %%ebx), %%mm1 \n\t"
"movq %%mm7, (%1, %%ebx) \n\t" // 0
"pandn %%mm1, %%mm0 \n\t"
PMAXW(%%mm0, %%mm3)
"addl $8, %%ebx \n\t"
" js 1b \n\t"
"movq %%mm3, %%mm0 \n\t"
"psrlq $32, %%mm3 \n\t"
PMAXW(%%mm0, %%mm3)
"movq %%mm3, %%mm0 \n\t"
"psrlq $16, %%mm3 \n\t"
PMAXW(%%mm0, %%mm3)
"movd %%mm3, %%ebx \n\t"
"movzbl %%bl, %%ebx \n\t" // last_non_zero_p1
"movl %%ebx, (%%ebp) \n\t"
"popl %%ebx \n\t"
"popl %%ebp \n\t"
:
: "m" (last_non_zero_p1),
"r" (block+64), "r" (qmat+64), "r" (bias+64),
"r" (inv_zigzag_direct16+64), "r" (temp_block+64)
);
// note the asm is split cuz gcc doesnt like that many operands ...
asm volatile(
"movd %1, %%mm1 \n\t" // max_qcoeff
SPREADW(%%mm1)
"psubusw %%mm1, %%mm4 \n\t"
"packuswb %%mm4, %%mm4 \n\t"
"movd %%mm4, %0 \n\t" // *overflow
: "=r" (*overflow)
: "r" (s->max_qcoeff)
);
}
if(s->mb_intra) block[0]= level;
else block[0]= temp_block[0];
if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){
if(last_non_zero_p1 <= 1) goto end;
block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
block[0x20] = temp_block[0x10];
if(last_non_zero_p1 <= 4) goto end;
block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
block[0x09] = temp_block[0x03];
if(last_non_zero_p1 <= 7) goto end;
block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
if(last_non_zero_p1 <= 11) goto end;
block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
block[0x0C] = temp_block[0x05];
if(last_non_zero_p1 <= 16) goto end;
block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
if(last_non_zero_p1 <= 24) goto end;
block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
if(last_non_zero_p1 <= 32) goto end;
block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
if(last_non_zero_p1 <= 40) goto end;
block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
if(last_non_zero_p1 <= 48) goto end;
block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
if(last_non_zero_p1 <= 56) goto end;
block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
}else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){
if(last_non_zero_p1 <= 1) goto end;
block[0x04] = temp_block[0x01];
block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
if(last_non_zero_p1 <= 4) goto end;
block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
block[0x05] = temp_block[0x03];
if(last_non_zero_p1 <= 7) goto end;
block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
if(last_non_zero_p1 <= 11) goto end;
block[0x1C] = temp_block[0x19];
block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
if(last_non_zero_p1 <= 16) goto end;
block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
if(last_non_zero_p1 <= 24) goto end;
block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
if(last_non_zero_p1 <= 32) goto end;
block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
if(last_non_zero_p1 <= 40) goto end;
block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
if(last_non_zero_p1 <= 48) goto end;
block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
if(last_non_zero_p1 <= 56) goto end;
block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
}else{
if(last_non_zero_p1 <= 1) goto end;
block[0x01] = temp_block[0x01];
block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
if(last_non_zero_p1 <= 4) goto end;
block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
block[0x03] = temp_block[0x03];
if(last_non_zero_p1 <= 7) goto end;
block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
if(last_non_zero_p1 <= 11) goto end;
block[0x19] = temp_block[0x19];
block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
if(last_non_zero_p1 <= 16) goto end;
block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
if(last_non_zero_p1 <= 24) goto end;
block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
if(last_non_zero_p1 <= 32) goto end;
block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
if(last_non_zero_p1 <= 40) goto end;
block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
if(last_non_zero_p1 <= 48) goto end;
block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
if(last_non_zero_p1 <= 56) goto end;
block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
}
end:
/*
for(i=0; i<last_non_zero_p1; i++)
{
int j= zigzag_direct_noperm[i];
block[block_permute_op(j)]= temp_block[j];
}
*/
return last_non_zero_p1 - 1;
}
| 13,289 |
FFmpeg | c23acbaed40101c677dfcfbbfe0d2c230a8e8f44 | 1 | void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
/* read the pixels */
for(i=0;i<8;i++) {
pixels[0] = cm[block[0]];
pixels[1] = cm[block[1]];
pixels[2] = cm[block[2]];
pixels[3] = cm[block[3]];
pixels[4] = cm[block[4]];
pixels[5] = cm[block[5]];
pixels[6] = cm[block[6]];
pixels[7] = cm[block[7]];
pixels += line_size;
block += 8;
}
}
| 13,290 |
FFmpeg | b8659d94b76c9b90c0aff3c5c01bfd2be6324e93 | 1 | int has_altivec(void)
{
#ifdef __AMIGAOS4__
ULONG result = 0;
extern struct ExecIFace *IExec;
IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
if (result == VECTORTYPE_ALTIVEC) return 1;
#elif __APPLE__
int sels[2] = {CTL_HW, HW_VECTORUNIT};
int has_vu = 0;
size_t len = sizeof(has_vu);
int err;
err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
if (err == 0) return (has_vu != 0);
#else
// since we were compiled for altivec, just assume we have it
// until someone comes up with a proper way (not involving signal hacks).
#endif /* __AMIGAOS4__ */
} | 13,292 |
FFmpeg | 889afca369ef3a939c68592ef2b1a1756667ce21 | 1 | static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size,
int keyframe)
{
GetBitContext gb;
PutBitContext pb;
AACADTSHeaderInfo hdr;
AACBSFContext *ctx = bsfc->priv_data;
init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8);
*poutbuf = (uint8_t*) buf;
*poutbuf_size = buf_size;
if (avctx->extradata)
if (show_bits(&gb, 12) != 0xfff)
return 0;
if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
return -1;
}
if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
avpriv_report_missing_feature(avctx,
"Multiple RDBs per frame with CRC");
return AVERROR_PATCHWELCOME;
}
buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
if (!ctx->first_frame_done) {
int pce_size = 0;
uint8_t pce_data[MAX_PCE_SIZE];
if (!hdr.chan_config) {
init_get_bits(&gb, buf, buf_size * 8);
if (get_bits(&gb, 3) != 5) {
avpriv_report_missing_feature(avctx,
"PCE-based channel configuration "
"without PCE as first syntax "
"element");
return AVERROR_PATCHWELCOME;
}
init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
pce_size = avpriv_copy_pce_data(&pb, &gb)/8;
flush_put_bits(&pb);
buf_size -= get_bits_count(&gb)/8;
buf += get_bits_count(&gb)/8;
}
avctx->extradata_size = 2 + pce_size;
avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
put_bits(&pb, 5, hdr.object_type);
put_bits(&pb, 4, hdr.sampling_index);
put_bits(&pb, 4, hdr.chan_config);
put_bits(&pb, 1, 0); //frame length - 1024 samples
put_bits(&pb, 1, 0); //does not depend on core coder
put_bits(&pb, 1, 0); //is not extension
flush_put_bits(&pb);
if (pce_size) {
memcpy(avctx->extradata + 2, pce_data, pce_size);
}
ctx->first_frame_done = 1;
}
*poutbuf = (uint8_t*) buf;
*poutbuf_size = buf_size;
return 0;
} | 13,294 |
FFmpeg | 09302a897d1990b1338f049fcd29638d736b8823 | 1 | static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *buf_end){
unsigned char *frame0_end = s->last_frame.data[0] + s->avctx->width*s->last_frame.linesize[0];
int num_mvs;
int num_blocks_raw;
int num_blocks_packed;
int vector_bits;
int i,j,x,y;
GetBitContext gb;
int mvbits;
const unsigned char *blocks_raw;
if(buf+12>buf_end)
return -1;
num_mvs = AV_RL16(&buf[0]);
num_blocks_raw = AV_RL16(&buf[2]);
num_blocks_packed = AV_RL16(&buf[4]);
vector_bits = AV_RL16(&buf[6]);
buf += 12;
/* allocate codebook buffers as neccessary */
if (num_mvs > s->num_mvs) {
s->mv_codebook = av_realloc(s->mv_codebook, num_mvs*2*sizeof(int));
s->num_mvs = num_mvs;
}
if (num_blocks_packed > s->num_blocks_packed) {
s->block_codebook = av_realloc(s->block_codebook, num_blocks_packed*16*sizeof(unsigned char));
s->num_blocks_packed = num_blocks_packed;
}
/* read motion vectors */
mvbits = (num_mvs*2*10+31) & ~31;
if (buf+(mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed>buf_end)
return -1;
init_get_bits(&gb, buf, mvbits);
for (i=0; i<num_mvs; i++) {
s->mv_codebook[i][0] = get_sbits(&gb, 10);
s->mv_codebook[i][1] = get_sbits(&gb, 10);
}
buf += mvbits>>3;
/* note ptr to uncompressed blocks */
blocks_raw = buf;
buf += num_blocks_raw*16;
/* read compressed blocks */
init_get_bits(&gb, buf, (buf_end-buf)<<3);
for (i=0; i<num_blocks_packed; i++) {
int tmp[4];
for(j=0; j<4; j++)
tmp[j] = get_bits(&gb, 8);
for(j=0; j<16; j++)
s->block_codebook[i][15-j] = tmp[get_bits(&gb, 2)];
}
if (get_bits_left(&gb) < vector_bits *
(s->avctx->height/4) * (s->avctx->width/4))
return -1;
/* read vectors and build frame */
for(y=0; y<s->avctx->height/4; y++)
for(x=0; x<s->avctx->width/4; x++) {
unsigned int vector = get_bits(&gb, vector_bits);
const unsigned char *src;
int src_stride;
if (vector < num_mvs) {
src = s->last_frame.data[0] +
(y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] +
x*4 + s->mv_codebook[vector][0];
src_stride = s->last_frame.linesize[0];
if (src+3*src_stride+3>=frame0_end)
continue;
}else{
int offset = vector - num_mvs;
if (offset<num_blocks_raw)
src = blocks_raw + 16*offset;
else if (offset-num_blocks_raw<num_blocks_packed)
src = s->block_codebook[offset-num_blocks_raw];
else
continue;
src_stride = 4;
}
for(j=0; j<4; j++)
for(i=0; i<4; i++)
s->frame.data[0][ (y*4+j)*s->frame.linesize[0] + (x*4+i) ] =
src[j*src_stride + i];
}
return 0;
}
| 13,295 |
qemu | 6516367fc0803d079384e0ad370856ac328bef30 | 1 | static void generic_loader_realize(DeviceState *dev, Error **errp)
{
GenericLoaderState *s = GENERIC_LOADER(dev);
hwaddr entry;
int big_endian;
int size = 0;
s->set_pc = false;
/* Perform some error checking on the user's options */
if (s->data || s->data_len || s->data_be) {
/* User is loading memory values */
if (s->file) {
error_setg(errp, "Specifying a file is not supported when loading "
"memory values");
return;
} else if (s->force_raw) {
error_setg(errp, "Specifying force-raw is not supported when "
"loading memory values");
return;
} else if (!s->data_len) {
/* We can't check for !data here as a value of 0 is still valid. */
error_setg(errp, "Both data and data-len must be specified");
return;
} else if (s->data_len > 8) {
error_setg(errp, "data-len cannot be greater then 8 bytes");
return;
}
} else if (s->file || s->force_raw) {
/* User is loading an image */
if (s->data || s->data_len || s->data_be) {
error_setg(errp, "data can not be specified when loading an "
"image");
return;
}
/* The user specified a file, only set the PC if they also specified
* a CPU to use.
*/
if (s->cpu_num != CPU_NONE) {
s->set_pc = true;
}
} else if (s->addr) {
/* User is setting the PC */
if (s->data || s->data_len || s->data_be) {
error_setg(errp, "data can not be specified when setting a "
"program counter");
return;
} else if (!s->cpu_num) {
error_setg(errp, "cpu_num must be specified when setting a "
"program counter");
return;
}
s->set_pc = true;
} else {
/* Did the user specify anything? */
error_setg(errp, "please include valid arguments");
return;
}
qemu_register_reset(generic_loader_reset, dev);
if (s->cpu_num != CPU_NONE) {
s->cpu = qemu_get_cpu(s->cpu_num);
if (!s->cpu) {
error_setg(errp, "Specified boot CPU#%d is nonexistent",
s->cpu_num);
return;
}
} else {
s->cpu = first_cpu;
}
#ifdef TARGET_WORDS_BIGENDIAN
big_endian = 1;
#else
big_endian = 0;
#endif
if (s->file) {
if (!s->force_raw) {
size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL,
big_endian, 0, 0, 0, s->cpu->as);
if (size < 0) {
size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
s->cpu->as);
}
}
if (size < 0 || s->force_raw) {
/* Default to the maximum size being the machine's ram size */
size = load_image_targphys_as(s->file, s->addr, ram_size,
s->cpu->as);
} else {
s->addr = entry;
}
if (size < 0) {
error_setg(errp, "Cannot load specified image %s", s->file);
return;
}
}
/* Convert the data endiannes */
if (s->data_be) {
s->data = cpu_to_be64(s->data);
} else {
s->data = cpu_to_le64(s->data);
}
}
| 13,296 |
FFmpeg | d1adad3cca407f493c3637e20ecd4f7124e69212 | 0 | static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
const uint8_t *src, long width)
{
#if COMPILE_TEMPLATE_MMX
__asm__ volatile(
"movq "MANGLE(bm01010101)", %%mm4 \n\t"
"mov %0, %%"REG_a" \n\t"
"1: \n\t"
"movq (%1, %%"REG_a",2), %%mm0 \n\t"
"movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
"movq %%mm0, %%mm2 \n\t"
"movq %%mm1, %%mm3 \n\t"
"pand %%mm4, %%mm0 \n\t"
"pand %%mm4, %%mm1 \n\t"
"psrlw $8, %%mm2 \n\t"
"psrlw $8, %%mm3 \n\t"
"packuswb %%mm1, %%mm0 \n\t"
"packuswb %%mm3, %%mm2 \n\t"
"movq %%mm0, (%2, %%"REG_a") \n\t"
"movq %%mm2, (%3, %%"REG_a") \n\t"
"add $8, %%"REG_a" \n\t"
" js 1b \n\t"
: : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst1+width), "r" (dst2+width)
: "%"REG_a
);
#else
int i;
for (i = 0; i < width; i++) {
dst1[i] = src[2*i+0];
dst2[i] = src[2*i+1];
}
#endif
}
| 13,297 |
FFmpeg | 5e53486545726987ab4482321d4dcf7e23e7652f | 0 | static int mpc7_decode_init(AVCodecContext * avctx)
{
int i, j;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
uint8_t buf[16];
static int vlc_inited = 0;
if(avctx->extradata_size < 16){
av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
return -1;
}
memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
av_init_random(0xDEADBEEF, &c->rnd);
dsputil_init(&c->dsp, avctx);
c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);
ff_mpc_init();
init_get_bits(&gb, buf, 128);
c->IS = get_bits1(&gb);
c->MSS = get_bits1(&gb);
c->maxbands = get_bits(&gb, 6);
if(c->maxbands >= BANDS){
av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands);
return -1;
}
skip_bits(&gb, 88);
c->gapless = get_bits1(&gb);
c->lastframelen = get_bits(&gb, 11);
av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);
c->frames_to_skip = 0;
if(vlc_inited) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
&mpc7_scfi[1], 2, 1,
&mpc7_scfi[0], 2, 1, INIT_VLC_USE_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n");
return -1;
}
if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
&mpc7_dscf[1], 2, 1,
&mpc7_dscf[0], 2, 1, INIT_VLC_USE_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n");
return -1;
}
if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
&mpc7_hdr[1], 2, 1,
&mpc7_hdr[0], 2, 1, INIT_VLC_USE_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n");
return -1;
}
for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){
for(j = 0; j < 2; j++){
if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],
&mpc7_quant_vlc[i][j][1], 4, 2,
&mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j);
return -1;
}
}
}
vlc_inited = 1;
return 0;
}
| 13,298 |
FFmpeg | 28f9ab7029bd1a02f659995919f899f84ee7361b | 0 | void ff_vp3_idct_altivec(DCTELEM block[64])
{
IDCT_START
IDCT_1D(NOP, NOP)
TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
IDCT_1D(ADD8, SHIFT4)
vec_st(b0, 0x00, block);
vec_st(b1, 0x10, block);
vec_st(b2, 0x20, block);
vec_st(b3, 0x30, block);
vec_st(b4, 0x40, block);
vec_st(b5, 0x50, block);
vec_st(b6, 0x60, block);
vec_st(b7, 0x70, block);
}
| 13,299 |
FFmpeg | 2d015d3bf9fed59c65a3819a35fedbb8b7dde623 | 0 | static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
MOVStreamContext *sc;
unsigned int i, j, entries, ctts_count = 0;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
sc = st->priv_data;
avio_r8(pb); /* version */
avio_rb24(pb); /* flags */
entries = avio_rb32(pb);
av_log(c->fc, AV_LOG_TRACE, "track[%u].ctts.entries = %u\n", c->fc->nb_streams - 1, entries);
if (!entries)
return 0;
if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
return AVERROR_INVALIDDATA;
av_freep(&sc->ctts_data);
sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data));
if (!sc->ctts_data)
return AVERROR(ENOMEM);
for (i = 0; i < entries && !pb->eof_reached; i++) {
int count =avio_rb32(pb);
int duration =avio_rb32(pb);
if (count <= 0) {
av_log(c->fc, AV_LOG_TRACE,
"ignoring CTTS entry with count=%d duration=%d\n",
count, duration);
continue;
}
/* Expand entries such that we have a 1-1 mapping with samples. */
for (j = 0; j < count; j++)
add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, 1, duration);
av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
count, duration);
if (FFNABS(duration) < -(1<<28) && i+2<entries) {
av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");
av_freep(&sc->ctts_data);
sc->ctts_count = 0;
return 0;
}
if (i+2<entries)
mov_update_dts_shift(sc, duration);
}
sc->ctts_count = ctts_count;
if (pb->eof_reached)
return AVERROR_EOF;
av_log(c->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift);
return 0;
}
| 13,300 |
qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 | 1 | static void gen_mfsrin(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
#else
TCGv t0;
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
return;
}
t0 = tcg_temp_new();
tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
tcg_gen_andi_tl(t0, t0, 0xF);
gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
tcg_temp_free(t0);
#endif
}
| 13,301 |
qemu | 79761c6681f0d1cc1c027116fcb4382d41ed3ece | 1 | void qemu_sem_wait(QemuSemaphore *sem)
{
#if defined(__APPLE__) || defined(__NetBSD__)
pthread_mutex_lock(&sem->lock);
--sem->count;
while (sem->count < 0) {
pthread_cond_wait(&sem->cond, &sem->lock);
}
pthread_mutex_unlock(&sem->lock);
#else
int rc;
do {
rc = sem_wait(&sem->sem);
} while (rc == -1 && errno == EINTR);
if (rc < 0) {
error_exit(errno, __func__);
}
#endif
}
| 13,304 |
FFmpeg | c5f4c0fd5c791ba97eb266cc30ae2172c10feb20 | 0 | static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
{
int isv34, tlen, unsync;
char tag[5];
int64_t next, end = avio_tell(s->pb) + len;
int taghdrlen;
const char *reason = NULL;
AVIOContext pb;
unsigned char *buffer = NULL;
int buffer_size = 0;
switch (version) {
case 2:
if (flags & 0x40) {
reason = "compression";
goto error;
}
isv34 = 0;
taghdrlen = 6;
break;
case 3:
case 4:
isv34 = 1;
taghdrlen = 10;
break;
default:
reason = "version";
goto error;
}
unsync = flags & 0x80;
if (isv34 && flags & 0x40) /* Extended header present, just skip over it */
avio_skip(s->pb, get_size(s->pb, 4));
while (len >= taghdrlen) {
unsigned int tflags;
int tunsync = 0;
if (isv34) {
avio_read(s->pb, tag, 4);
tag[4] = 0;
if(version==3){
tlen = avio_rb32(s->pb);
}else
tlen = get_size(s->pb, 4);
tflags = avio_rb16(s->pb);
tunsync = tflags & ID3v2_FLAG_UNSYNCH;
} else {
avio_read(s->pb, tag, 3);
tag[3] = 0;
tlen = avio_rb24(s->pb);
}
len -= taghdrlen + tlen;
if (len < 0)
break;
next = avio_tell(s->pb) + tlen;
if (tflags & ID3v2_FLAG_DATALEN) {
avio_rb32(s->pb);
tlen -= 4;
}
if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {
av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);
avio_skip(s->pb, tlen);
} else if (tag[0] == 'T') {
if (unsync || tunsync) {
int i, j;
av_fast_malloc(&buffer, &buffer_size, tlen);
for (i = 0, j = 0; i < tlen; i++, j++) {
buffer[j] = avio_r8(s->pb);
if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) {
/* Unsynchronised byte, skip it */
j--;
}
}
ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
read_ttag(s, &pb, j, tag);
} else {
read_ttag(s, s->pb, tlen, tag);
}
}
else if (!tag[0]) {
if (tag[1])
av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");
avio_skip(s->pb, tlen);
break;
}
/* Skip to end of tag */
avio_seek(s->pb, next, SEEK_SET);
}
if (version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */
end += 10;
error:
if (reason)
av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
avio_seek(s->pb, end, SEEK_SET);
av_free(buffer);
return;
}
| 13,305 |
FFmpeg | 6e42e6c4b410dbef8b593c2d796a5dad95f89ee4 | 1 | void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
{
long i;
/*
writes 1 byte o much and might cause alignment issues on some architectures?
for(i=0; i<num_pixels; i++)
((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
*/
for(i=0; i<num_pixels; i++)
{
//FIXME slow?
dst[0]= palette[ src[i]*4+2 ];
dst[1]= palette[ src[i]*4+1 ];
dst[2]= palette[ src[i]*4+0 ];
dst+= 3;
}
}
| 13,306 |
qemu | c485cf9c9277ca9b3d5227c99a13c374e812f42b | 1 | static int m25p80_init(SSISlave *ss)
{
DriveInfo *dinfo;
Flash *s = M25P80(ss);
M25P80Class *mc = M25P80_GET_CLASS(s);
s->pi = mc->pi;
s->size = s->pi->sector_size * s->pi->n_sectors;
s->dirty_page = -1;
s->storage = blk_blockalign(s->blk, s->size);
/* FIXME use a qdev drive property instead of drive_get_next() */
dinfo = drive_get_next(IF_MTD);
if (dinfo) {
DB_PRINT_L(0, "Binding to IF_MTD drive\n");
s->blk = blk_by_legacy_dinfo(dinfo);
blk_attach_dev_nofail(s->blk, s);
/* FIXME: Move to late init */
if (blk_read(s->blk, 0, s->storage,
DIV_ROUND_UP(s->size, BDRV_SECTOR_SIZE))) {
fprintf(stderr, "Failed to initialize SPI flash!\n");
return 1;
}
} else {
DB_PRINT_L(0, "No BDRV - binding to RAM\n");
memset(s->storage, 0xFF, s->size);
}
return 0;
}
| 13,308 |
qemu | a15fcc3cf69ee3d408f60d6cc316488d2b0249b4 | 1 | void visit_start_list(Visitor *v, const char *name, GenericList **list,
size_t size, Error **errp)
{
Error *err = NULL;
assert(!list || size >= sizeof(GenericList));
v->start_list(v, name, list, size, &err);
if (list && v->type == VISITOR_INPUT) {
assert(!(err && *list));
}
error_propagate(errp, err);
}
| 13,309 |
qemu | 403e633126b7a781ecd48a29e3355770d46bbf1a | 1 | static unsigned __stdcall win32_start_routine(void *arg)
{
struct QemuThreadData data = *(struct QemuThreadData *) arg;
QemuThread *thread = data.thread;
free(arg);
TlsSetValue(qemu_thread_tls_index, thread);
/*
* Use DuplicateHandle instead of assigning thread->thread in the
* creating thread to avoid races. It's simpler this way than with
* synchronization.
*/
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &thread->thread,
0, FALSE, DUPLICATE_SAME_ACCESS);
qemu_thread_exit(data.start_routine(data.arg));
abort();
}
| 13,310 |
FFmpeg | 6a63ff19b6a7fe3bc32c7fb4a62fca8f65786432 | 0 | static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
{
AVStream *st = c->fc->streams[c->fc->nb_streams-1];
MOVStreamContext *sc = st->priv_data;
unsigned int i, entries;
get_byte(pb); /* version */
get_be24(pb); /* flags */
entries = get_be32(pb);
dprintf(c->fc, "keyframe_count = %d\n", entries);
if(entries >= UINT_MAX / sizeof(int))
return -1;
sc->keyframes = av_malloc(entries * sizeof(int));
if (!sc->keyframes)
return AVERROR(ENOMEM);
sc->keyframe_count = entries;
for(i=0; i<entries; i++) {
sc->keyframes[i] = get_be32(pb);
//dprintf(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
}
return 0;
}
| 13,312 |
FFmpeg | 6e0723470bea258ceb72ee4c4916cf8f80337f92 | 1 | static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band,
float *bits, float lambda)
{
int i, b = 0;
uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 };
const int band_size = ff_celt_freq_range[band] << f->size;
float buf[176 * 2], lowband_scratch[176], norm1[176], norm2[176];
float dist, cost, err_x = 0.0f, err_y = 0.0f;
float *X = buf;
float *X_orig = f->block[0].coeffs + (ff_celt_freq_bands[band] << f->size);
float *Y = (f->channels == 2) ? &buf[176] : NULL;
float *Y_orig = f->block[1].coeffs + (ff_celt_freq_bands[band] << f->size);
OPUS_RC_CHECKPOINT_SPAWN(rc);
memcpy(X, X_orig, band_size*sizeof(float));
if (Y)
memcpy(Y, Y_orig, band_size*sizeof(float));
f->remaining2 = ((f->framebits << 3) - f->anticollapse_needed) - opus_rc_tell_frac(rc) - 1;
if (band <= f->coded_bands - 1) {
int curr_balance = f->remaining / FFMIN(3, f->coded_bands - band);
b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[band] + curr_balance), 14);
}
if (f->dual_stereo) {
pvq->encode_band(pvq, f, rc, band, X, NULL, band_size, b / 2, f->blocks, NULL,
f->size, norm1, 0, 1.0f, lowband_scratch, cm[0]);
pvq->encode_band(pvq, f, rc, band, Y, NULL, band_size, b / 2, f->blocks, NULL,
f->size, norm2, 0, 1.0f, lowband_scratch, cm[1]);
} else {
pvq->encode_band(pvq, f, rc, band, X, Y, band_size, b, f->blocks, NULL, f->size,
norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]);
}
for (i = 0; i < band_size; i++) {
err_x += (X[i] - X_orig[i])*(X[i] - X_orig[i]);
err_y += (Y[i] - Y_orig[i])*(Y[i] - Y_orig[i]);
}
dist = sqrtf(err_x) + sqrtf(err_y);
cost = OPUS_RC_CHECKPOINT_BITS(rc)/8.0f;
*bits += cost;
OPUS_RC_CHECKPOINT_ROLLBACK(rc);
return lambda*dist*cost;
}
| 13,313 |
FFmpeg | c7b08bc0a71f9e54e0d5036a8195648b41bd3933 | 1 | static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
{
AVStream *st = s->streams[0]; // video stream
R3DContext *r3d = s->priv_data;
int frame_num;
if (!st->codec->time_base.num || !st->time_base.den)
return -1;
frame_num = sample_time*st->codec->time_base.den/
((int64_t)st->codec->time_base.num*st->time_base.den);
av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
frame_num, sample_time);
if (frame_num < r3d->video_offsets_count) {
avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET);
} else {
av_log(s, AV_LOG_ERROR, "could not seek to frame %d\n", frame_num);
return -1;
}
return 0;
}
| 13,314 |
qemu | e23a1b33b53d25510320b26d9f154e19c6c99725 | 1 | m48t59_t *m48t59_init (qemu_irq IRQ, target_phys_addr_t mem_base,
uint32_t io_base, uint16_t size,
int type)
{
DeviceState *dev;
SysBusDevice *s;
M48t59SysBusState *d;
dev = qdev_create(NULL, "m48t59");
qdev_prop_set_uint32(dev, "type", type);
qdev_prop_set_uint32(dev, "size", size);
qdev_prop_set_uint32(dev, "io_base", io_base);
qdev_init(dev);
s = sysbus_from_qdev(dev);
sysbus_connect_irq(s, 0, IRQ);
if (io_base != 0) {
register_ioport_read(io_base, 0x04, 1, NVRAM_readb, s);
register_ioport_write(io_base, 0x04, 1, NVRAM_writeb, s);
}
if (mem_base != 0) {
sysbus_mmio_map(s, 0, mem_base);
}
d = FROM_SYSBUS(M48t59SysBusState, s);
return &d->state;
}
| 13,315 |
FFmpeg | c871244306f92fecaaed8a97f47ba54d46eb0cd5 | 1 | static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
const int data_size, AVCodecContext *avctx)
{
int hdr_size, width, height, flags;
int version;
const uint8_t *ptr;
hdr_size = AV_RB16(buf);
av_dlog(avctx, "header size %d\n", hdr_size);
if (hdr_size > data_size) {
av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n");
version = AV_RB16(buf + 2);
av_dlog(avctx, "%.4s version %d\n", buf+4, version);
if (version > 1) {
av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version);
width = AV_RB16(buf + 8);
height = AV_RB16(buf + 10);
if (width != avctx->width || height != avctx->height) {
av_log(avctx, AV_LOG_ERROR, "picture resolution change: %dx%d -> %dx%d\n",
avctx->width, avctx->height, width, height);
ctx->frame_type = (buf[12] >> 2) & 3;
av_dlog(avctx, "frame type %d\n", ctx->frame_type);
if (ctx->frame_type == 0) {
ctx->scan = ctx->progressive_scan; // permuted
} else {
ctx->scan = ctx->interlaced_scan; // permuted
ctx->frame.interlaced_frame = 1;
ctx->frame.top_field_first = ctx->frame_type == 1;
avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV422P10;
ptr = buf + 20;
flags = buf[19];
av_dlog(avctx, "flags %x\n", flags);
if (flags & 2) {
permute(ctx->qmat_luma, ctx->prodsp.idct_permutation, ptr);
ptr += 64;
} else {
memset(ctx->qmat_luma, 4, 64);
if (flags & 1) {
permute(ctx->qmat_chroma, ctx->prodsp.idct_permutation, ptr);
} else {
memset(ctx->qmat_chroma, 4, 64);
return hdr_size;
| 13,317 |
FFmpeg | 0b54f3c0878a3acaa9142e4f24942e762d97e350 | 1 | static inline int GetCode(GifState * s)
{
int c, sizbuf;
uint8_t *ptr;
while (s->bbits < s->cursize) {
ptr = s->pbuf;
if (ptr >= s->ebuf) {
if (!s->eob_reached) {
sizbuf = get_byte(s->f);
s->ebuf = s->buf + sizbuf;
s->pbuf = s->buf;
if (sizbuf > 0) {
get_buffer(s->f, s->buf, sizbuf);
} else {
s->eob_reached = 1;
}
}
ptr = s->pbuf;
}
s->bbuf |= ptr[0] << s->bbits;
ptr++;
s->pbuf = ptr;
s->bbits += 8;
}
c = s->bbuf & s->curmask;
s->bbuf >>= s->cursize;
s->bbits -= s->cursize;
return c;
}
| 13,318 |
FFmpeg | 1ac5abb1d062b6ca983d494068bb9fd30390a941 | 1 | static void filter(SPPContext *p, uint8_t *dst, uint8_t *src,
int dst_linesize, int src_linesize, int width, int height,
const uint8_t *qp_table, int qp_stride, int is_luma, int sample_bytes)
{
int x, y, i;
const int count = 1 << p->log2_count;
const int linesize = is_luma ? p->temp_linesize : FFALIGN(width+16, 16);
DECLARE_ALIGNED(16, uint64_t, block_align)[32];
int16_t *block = (int16_t *)block_align;
int16_t *block2 = (int16_t *)(block_align + 16);
uint16_t *psrc16 = (uint16_t*)p->src;
for (y = 0; y < height; y++) {
int index = 8 + 8*linesize + y*linesize;
memcpy(p->src + index*sample_bytes, src + y*src_linesize, width*sample_bytes);
if (sample_bytes == 1) {
for (x = 0; x < 8; x++) {
p->src[index - x - 1] = p->src[index + x ];
p->src[index + width + x ] = p->src[index + width - x - 1];
}
} else {
for (x = 0; x < 8; x++) {
psrc16[index - x - 1] = psrc16[index + x ];
psrc16[index + width + x ] = psrc16[index + width - x - 1];
}
}
}
for (y = 0; y < 8; y++) {
memcpy(p->src + ( 7-y)*linesize * sample_bytes, p->src + ( y+8)*linesize * sample_bytes, linesize * sample_bytes);
memcpy(p->src + (height+8+y)*linesize * sample_bytes, p->src + (height-y+7)*linesize * sample_bytes, linesize * sample_bytes);
}
for (y = 0; y < height + 8; y += 8) {
memset(p->temp + (8 + y) * linesize, 0, 8 * linesize * sizeof(*p->temp));
for (x = 0; x < width + 8; x += 8) {
int qp;
if (p->qp) {
qp = p->qp;
} else{
const int qps = 3 + is_luma;
qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride];
qp = FFMAX(1, norm_qscale(qp, p->qscale_type));
}
for (i = 0; i < count; i++) {
const int x1 = x + offset[i + count - 1][0];
const int y1 = y + offset[i + count - 1][1];
const int index = x1 + y1*linesize;
p->dct->get_pixels(block, p->src + sample_bytes*index, sample_bytes*linesize);
p->dct->fdct(block);
p->requantize(block2, block, qp, p->dct->idct_permutation);
p->dct->idct(block2);
add_block(p->temp + index, linesize, block2);
}
}
if (y) {
if (sample_bytes == 1) {
p->store_slice(dst + (y - 8) * dst_linesize, p->temp + 8 + y*linesize,
dst_linesize, linesize, width,
FFMIN(8, height + 8 - y), MAX_LEVEL - p->log2_count,
ldither);
} else {
store_slice16_c((uint16_t*)(dst + (y - 8) * dst_linesize), p->temp + 8 + y*linesize,
dst_linesize/2, linesize, width,
FFMIN(8, height + 8 - y), MAX_LEVEL - p->log2_count,
ldither);
}
}
}
}
| 13,319 |
FFmpeg | bfa0f96586fe2c257cfa574ffb991da493a54da1 | 1 | static int vp8_alloc_frame(VP8Context *s, AVFrame *f)
{
int ret;
if ((ret = ff_thread_get_buffer(s->avctx, f)) < 0)
return ret;
if (!s->maps_are_invalid && s->num_maps_to_be_freed) {
f->ref_index[0] = s->segmentation_maps[--s->num_maps_to_be_freed];
} else if (!(f->ref_index[0] = av_mallocz(s->mb_width * s->mb_height))) {
ff_thread_release_buffer(s->avctx, f);
return AVERROR(ENOMEM);
}
return 0;
}
| 13,320 |
FFmpeg | 99a520000d376d60cd30fae97bfaaf13d50ee26c | 1 | static int64_t read_ts(const char *s)
{
int hh, mm, ss, ms;
if (sscanf(s, "%u:%u:%u.%u", &hh, &mm, &ss, &ms) == 4) return (hh*3600 + mm*60 + ss) * 1000 + ms;
if (sscanf(s, "%u:%u.%u", &mm, &ss, &ms) == 3) return ( mm*60 + ss) * 1000 + ms;
return AV_NOPTS_VALUE;
}
| 13,321 |
qemu | 049a9f7b946fe1d3ff97127f8905881dbb78cb00 | 1 | static void i82374_init(I82374State *s)
{
DMA_init(1, NULL);
memset(s->commands, 0, sizeof(s->commands));
}
| 13,322 |
qemu | 17268d54be2e15b0d8ccfc4102bc48c84299b027 | 1 | static void qxl_destroy_primary(PCIQXLDevice *d)
{
if (d->mode == QXL_MODE_UNDEFINED) {
return;
}
dprint(d, 1, "%s\n", __FUNCTION__);
d->mode = QXL_MODE_UNDEFINED;
d->ssd.worker->destroy_primary_surface(d->ssd.worker, 0);
} | 13,323 |
qemu | e23a1b33b53d25510320b26d9f154e19c6c99725 | 1 | void isa_ne2000_init(int base, int irq, NICInfo *nd)
{
ISADevice *dev;
qemu_check_nic_model(nd, "ne2k_isa");
dev = isa_create("ne2k_isa");
dev->qdev.nd = nd; /* hack alert */
qdev_prop_set_uint32(&dev->qdev, "iobase", base);
qdev_prop_set_uint32(&dev->qdev, "irq", irq);
qdev_init(&dev->qdev);
}
| 13,325 |
FFmpeg | 2d15588124ab1d4c0612cab66f02a716f1509211 | 1 | static int allocate_buffers(ShortenContext *s)
{
int i, chan, err;
for (chan = 0; chan < s->channels; chan++) {
if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
return AVERROR_INVALIDDATA;
}
if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) ||
s->blocksize + s->nwrap <= (unsigned)s->nwrap) {
av_log(s->avctx, AV_LOG_ERROR,
"s->blocksize + s->nwrap too large\n");
return AVERROR_INVALIDDATA;
}
if ((err = av_reallocp_array(&s->offset[chan],
sizeof(int32_t),
FFMAX(1, s->nmean))) < 0)
return err;
if ((err = av_reallocp_array(&s->decoded_base[chan], (s->blocksize + s->nwrap),
sizeof(s->decoded_base[0][0]))) < 0)
return err;
for (i = 0; i < s->nwrap; i++)
s->decoded_base[chan][i] = 0;
s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
}
if ((err = av_reallocp_array(&s->coeffs, s->nwrap, sizeof(*s->coeffs))) < 0)
return err;
return 0;
}
| 13,326 |
FFmpeg | 3ab9a2a5577d445252724af4067d2a7c8a378efa | 1 | static av_always_inline int rv40_loop_filter_strength(uint8_t *src,
int step, int stride,
int beta, int beta2,
int edge,
int *p1, int *q1)
{
int sum_p1p0 = 0, sum_q1q0 = 0, sum_p1p2 = 0, sum_q1q2 = 0;
int strong0 = 0, strong1 = 0;
uint8_t *ptr;
int i;
for (i = 0, ptr = src; i < 4; i++, ptr += stride) {
sum_p1p0 += ptr[-2*step] - ptr[-1*step];
sum_q1q0 += ptr[ 1*step] - ptr[ 0*step];
}
*p1 = FFABS(sum_p1p0) < (beta << 2);
*q1 = FFABS(sum_q1q0) < (beta << 2);
if(!*p1 && !*q1)
return 0;
if (!edge)
return 0;
for (i = 0, ptr = src; i < 4; i++, ptr += stride) {
sum_p1p2 += ptr[-2*step] - ptr[-3*step];
sum_q1q2 += ptr[ 1*step] - ptr[ 2*step];
}
strong0 = *p1 && (FFABS(sum_p1p2) < beta2);
strong1 = *q1 && (FFABS(sum_q1q2) < beta2);
return strong0 && strong1;
}
| 13,327 |
FFmpeg | 32be264cea542b4dc721b10092bf1dfe511a28ee | 1 | static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce,
int win, int group_len, const float lambda)
{
BandCodingPath path[120][CB_TOT_ALL];
int w, swb, cb, start, size;
int i, j;
const int max_sfb = sce->ics.max_sfb;
const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
const int run_esc = (1 << run_bits) - 1;
int idx, ppos, count;
int stackrun[120], stackcb[120], stack_len;
float next_minrd = INFINITY;
int next_mincb = 0;
abs_pow34_v(s->scoefs, sce->coeffs, 1024);
start = win*128;
for (cb = 0; cb < CB_TOT_ALL; cb++) {
path[0][cb].cost = 0.0f;
path[0][cb].prev_idx = -1;
path[0][cb].run = 0;
}
for (swb = 0; swb < max_sfb; swb++) {
size = sce->ics.swb_sizes[swb];
if (sce->zeroes[win*16 + swb]) {
for (cb = 0; cb < CB_TOT_ALL; cb++) {
path[swb+1][cb].prev_idx = cb;
path[swb+1][cb].cost = path[swb][cb].cost;
path[swb+1][cb].run = path[swb][cb].run + 1;
}
} else {
float minrd = next_minrd;
int mincb = next_mincb;
next_minrd = INFINITY;
next_mincb = 0;
for (cb = 0; cb < CB_TOT_ALL; cb++) {
float cost_stay_here, cost_get_here;
float rd = 0.0f;
if (cb >= 12 && sce->band_type[win*16+swb] < aac_cb_out_map[cb] ||
cb < aac_cb_in_map[sce->band_type[win*16+swb]] && sce->band_type[win*16+swb] > aac_cb_out_map[cb]) {
path[swb+1][cb].prev_idx = -1;
path[swb+1][cb].cost = INFINITY;
path[swb+1][cb].run = path[swb][cb].run + 1;
continue;
}
for (w = 0; w < group_len; w++) {
FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(win+w)*16+swb];
rd += quantize_band_cost(s, sce->coeffs + start + w*128,
s->scoefs + start + w*128, size,
sce->sf_idx[(win+w)*16+swb], aac_cb_out_map[cb],
lambda / band->threshold, INFINITY, NULL, 0);
}
cost_stay_here = path[swb][cb].cost + rd;
cost_get_here = minrd + rd + run_bits + 4;
if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
!= run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
cost_stay_here += run_bits;
if (cost_get_here < cost_stay_here) {
path[swb+1][cb].prev_idx = mincb;
path[swb+1][cb].cost = cost_get_here;
path[swb+1][cb].run = 1;
} else {
path[swb+1][cb].prev_idx = cb;
path[swb+1][cb].cost = cost_stay_here;
path[swb+1][cb].run = path[swb][cb].run + 1;
}
if (path[swb+1][cb].cost < next_minrd) {
next_minrd = path[swb+1][cb].cost;
next_mincb = cb;
}
}
}
start += sce->ics.swb_sizes[swb];
}
//convert resulting path from backward-linked list
stack_len = 0;
idx = 0;
for (cb = 1; cb < CB_TOT_ALL; cb++)
if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
idx = cb;
ppos = max_sfb;
while (ppos > 0) {
av_assert1(idx >= 0);
cb = idx;
stackrun[stack_len] = path[ppos][cb].run;
stackcb [stack_len] = cb;
idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
ppos -= path[ppos][cb].run;
stack_len++;
}
//perform actual band info encoding
start = 0;
for (i = stack_len - 1; i >= 0; i--) {
cb = aac_cb_out_map[stackcb[i]];
put_bits(&s->pb, 4, cb);
count = stackrun[i];
memset(sce->zeroes + win*16 + start, !cb, count);
//XXX: memset when band_type is also uint8_t
for (j = 0; j < count; j++) {
sce->band_type[win*16 + start] = cb;
start++;
}
while (count >= run_esc) {
put_bits(&s->pb, run_bits, run_esc);
count -= run_esc;
}
put_bits(&s->pb, run_bits, count);
}
}
| 13,328 |
FFmpeg | 773eb74babe07bc5c97c32aa564efc40e2d4b00c | 1 | callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
{
AVFormatContext *s = priv_data;
struct dshow_ctx *ctx = s->priv_data;
AVPacketList **ppktl, *pktl_next;
// dump_videohdr(s, vdhdr);
WaitForSingleObject(ctx->mutex, INFINITE);
if(shall_we_drop(s, index))
goto fail;
pktl_next = av_mallocz(sizeof(AVPacketList));
if(!pktl_next)
goto fail;
if(av_new_packet(&pktl_next->pkt, buf_size) < 0) {
av_free(pktl_next);
goto fail;
}
pktl_next->pkt.stream_index = index;
pktl_next->pkt.pts = time;
memcpy(pktl_next->pkt.data, buf, buf_size);
for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);
*ppktl = pktl_next;
ctx->curbufsize[index] += buf_size;
SetEvent(ctx->event[1]);
ReleaseMutex(ctx->mutex);
return;
fail:
ReleaseMutex(ctx->mutex);
return;
}
| 13,329 |
qemu | 089da572b956ef0f8f5b8d5917358e07892a77c2 | 1 | void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
{
size_t sz = strlen(value) + 1;
return fw_cfg_add_bytes(s, key, (uint8_t *)g_memdup(value, sz), sz);
}
| 13,330 |
qemu | 4da97120d51a4383aa96d741a2b837f8c4bbcd0b | 1 | static void ide_flush_cache(IDEState *s)
{
if (s->blk == NULL) {
ide_flush_cb(s, 0);
return;
}
s->status |= BUSY_STAT;
ide_set_retry(s);
block_acct_start(blk_get_stats(s->blk), &s->acct, 0, BLOCK_ACCT_FLUSH);
s->pio_aiocb = blk_aio_flush(s->blk, ide_flush_cb, s);
}
| 13,331 |
qemu | 2aae2b8e0abd58e76d616bcbe93c6966d06d0188 | 1 | void helper_st_asi(target_ulong addr, target_ulong val, int asi, int size)
{
#ifdef DEBUG_ASI
dump_asi("write", addr, asi, size, val);
#endif
asi &= 0xff;
if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
|| ((env->def->features & CPU_FEATURE_HYPV)
&& asi >= 0x30 && asi < 0x80
&& !(env->hpstate & HS_PRIV)))
raise_exception(TT_PRIV_ACT);
helper_check_align(addr, size - 1);
/* Convert to little endian */
switch (asi) {
case 0x0c: // Nucleus Little Endian (LE)
case 0x18: // As if user primary LE
case 0x19: // As if user secondary LE
case 0x1c: // Bypass LE
case 0x1d: // Bypass, non-cacheable LE
case 0x88: // Primary LE
case 0x89: // Secondary LE
switch(size) {
case 2:
val = bswap16(val);
break;
case 4:
val = bswap32(val);
break;
case 8:
val = bswap64(val);
break;
default:
break;
}
default:
break;
}
switch(asi) {
case 0x10: // As if user primary
case 0x11: // As if user secondary
case 0x18: // As if user primary LE
case 0x19: // As if user secondary LE
case 0x80: // Primary
case 0x81: // Secondary
case 0x88: // Primary LE
case 0x89: // Secondary LE
case 0xe2: // UA2007 Primary block init
case 0xe3: // UA2007 Secondary block init
if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
if ((env->def->features & CPU_FEATURE_HYPV)
&& env->hpstate & HS_PRIV) {
switch(size) {
case 1:
stb_hypv(addr, val);
break;
case 2:
stw_hypv(addr, val);
break;
case 4:
stl_hypv(addr, val);
break;
case 8:
default:
stq_hypv(addr, val);
break;
}
} else {
/* secondary space access has lowest asi bit equal to 1 */
if (asi & 1) {
switch(size) {
case 1:
stb_kernel_secondary(addr, val);
break;
case 2:
stw_kernel_secondary(addr, val);
break;
case 4:
stl_kernel_secondary(addr, val);
break;
case 8:
default:
stq_kernel_secondary(addr, val);
break;
}
} else {
switch(size) {
case 1:
stb_kernel(addr, val);
break;
case 2:
stw_kernel(addr, val);
break;
case 4:
stl_kernel(addr, val);
break;
case 8:
default:
stq_kernel(addr, val);
break;
}
}
}
} else {
/* secondary space access has lowest asi bit equal to 1 */
if (asi & 1) {
switch(size) {
case 1:
stb_user_secondary(addr, val);
break;
case 2:
stw_user_secondary(addr, val);
break;
case 4:
stl_user_secondary(addr, val);
break;
case 8:
default:
stq_user_secondary(addr, val);
break;
}
} else {
switch(size) {
case 1:
stb_user(addr, val);
break;
case 2:
stw_user(addr, val);
break;
case 4:
stl_user(addr, val);
break;
case 8:
default:
stq_user(addr, val);
break;
}
}
}
break;
case 0x14: // Bypass
case 0x15: // Bypass, non-cacheable
case 0x1c: // Bypass LE
case 0x1d: // Bypass, non-cacheable LE
{
switch(size) {
case 1:
stb_phys(addr, val);
break;
case 2:
stw_phys(addr, val);
break;
case 4:
stl_phys(addr, val);
break;
case 8:
default:
stq_phys(addr, val);
break;
}
}
return;
case 0x24: // Nucleus quad LDD 128 bit atomic
case 0x2c: // Nucleus quad LDD 128 bit atomic LE
// Only ldda allowed
raise_exception(TT_ILL_INSN);
return;
case 0x04: // Nucleus
case 0x0c: // Nucleus Little Endian (LE)
{
switch(size) {
case 1:
stb_nucleus(addr, val);
break;
case 2:
stw_nucleus(addr, val);
break;
case 4:
stl_nucleus(addr, val);
break;
default:
case 8:
stq_nucleus(addr, val);
break;
}
break;
}
case 0x4a: // UPA config
// XXX
return;
case 0x45: // LSU
{
uint64_t oldreg;
oldreg = env->lsu;
env->lsu = val & (DMMU_E | IMMU_E);
// Mappings generated during D/I MMU disabled mode are
// invalid in normal mode
if (oldreg != env->lsu) {
DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
oldreg, env->lsu);
#ifdef DEBUG_MMU
dump_mmu(env);
#endif
tlb_flush(env, 1);
}
return;
}
case 0x50: // I-MMU regs
{
int reg = (addr >> 3) & 0xf;
uint64_t oldreg;
oldreg = env->immuregs[reg];
switch(reg) {
case 0: // RO
return;
case 1: // Not in I-MMU
case 2:
return;
case 3: // SFSR
if ((val & 1) == 0)
val = 0; // Clear SFSR
env->immu.sfsr = val;
break;
case 4: // RO
return;
case 5: // TSB access
DPRINTF_MMU("immu TSB write: 0x%016" PRIx64 " -> 0x%016"
PRIx64 "\n", env->immu.tsb, val);
env->immu.tsb = val;
break;
case 6: // Tag access
env->immu.tag_access = val;
break;
case 7:
case 8:
return;
default:
break;
}
if (oldreg != env->immuregs[reg]) {
DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
}
#ifdef DEBUG_MMU
dump_mmu(env);
#endif
return;
}
case 0x54: // I-MMU data in
replace_tlb_1bit_lru(env->itlb, env->immu.tag_access, val, "immu", env);
return;
case 0x55: // I-MMU data access
{
// TODO: auto demap
unsigned int i = (addr >> 3) & 0x3f;
replace_tlb_entry(&env->itlb[i], env->immu.tag_access, val, env);
#ifdef DEBUG_MMU
DPRINTF_MMU("immu data access replaced entry [%i]\n", i);
dump_mmu(env);
#endif
return;
}
case 0x57: // I-MMU demap
demap_tlb(env->itlb, addr, "immu", env);
return;
case 0x58: // D-MMU regs
{
int reg = (addr >> 3) & 0xf;
uint64_t oldreg;
oldreg = env->dmmuregs[reg];
switch(reg) {
case 0: // RO
case 4:
return;
case 3: // SFSR
if ((val & 1) == 0) {
val = 0; // Clear SFSR, Fault address
env->dmmu.sfar = 0;
}
env->dmmu.sfsr = val;
break;
case 1: // Primary context
env->dmmu.mmu_primary_context = val;
break;
case 2: // Secondary context
env->dmmu.mmu_secondary_context = val;
break;
case 5: // TSB access
DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64 " -> 0x%016"
PRIx64 "\n", env->dmmu.tsb, val);
env->dmmu.tsb = val;
break;
case 6: // Tag access
env->dmmu.tag_access = val;
break;
case 7: // Virtual Watchpoint
case 8: // Physical Watchpoint
default:
env->dmmuregs[reg] = val;
break;
}
if (oldreg != env->dmmuregs[reg]) {
DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
}
#ifdef DEBUG_MMU
dump_mmu(env);
#endif
return;
}
case 0x5c: // D-MMU data in
replace_tlb_1bit_lru(env->dtlb, env->dmmu.tag_access, val, "dmmu", env);
return;
case 0x5d: // D-MMU data access
{
unsigned int i = (addr >> 3) & 0x3f;
replace_tlb_entry(&env->dtlb[i], env->dmmu.tag_access, val, env);
#ifdef DEBUG_MMU
DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i);
dump_mmu(env);
#endif
return;
}
case 0x5f: // D-MMU demap
demap_tlb(env->dtlb, addr, "dmmu", env);
return;
case 0x49: // Interrupt data receive
// XXX
return;
case 0x46: // D-cache data
case 0x47: // D-cache tag access
case 0x4b: // E-cache error enable
case 0x4c: // E-cache asynchronous fault status
case 0x4d: // E-cache asynchronous fault address
case 0x4e: // E-cache tag data
case 0x66: // I-cache instruction access
case 0x67: // I-cache tag access
case 0x6e: // I-cache predecode
case 0x6f: // I-cache LRU etc.
case 0x76: // E-cache tag
case 0x7e: // E-cache tag
return;
case 0x51: // I-MMU 8k TSB pointer, RO
case 0x52: // I-MMU 64k TSB pointer, RO
case 0x56: // I-MMU tag read, RO
case 0x59: // D-MMU 8k TSB pointer, RO
case 0x5a: // D-MMU 64k TSB pointer, RO
case 0x5b: // D-MMU data pointer, RO
case 0x5e: // D-MMU tag read, RO
case 0x48: // Interrupt dispatch, RO
case 0x7f: // Incoming interrupt vector, RO
case 0x82: // Primary no-fault, RO
case 0x83: // Secondary no-fault, RO
case 0x8a: // Primary no-fault LE, RO
case 0x8b: // Secondary no-fault LE, RO
default:
do_unassigned_access(addr, 1, 0, 1, size);
return;
}
}
| 13,332 |
FFmpeg | 55188278169c3a1838334d7aa47a1f7a40741690 | 1 | static int xan_decode_frame_type0(AVCodecContext *avctx, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
XanContext *s = avctx->priv_data;
uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer;
unsigned chroma_off, corr_off;
int cur, last, size;
int i, j;
int ret;
corr_off = AV_RL32(buf + 8);
chroma_off = AV_RL32(buf + 4);
if ((ret = xan_decode_chroma(avctx, avpkt)) != 0)
return ret;
size = avpkt->size - 4;
if (corr_off >= avpkt->size) {
av_log(avctx, AV_LOG_WARNING, "Ignoring invalid correction block position\n");
corr_off = 0;
}
if (corr_off)
size = corr_off;
if (chroma_off)
size = FFMIN(size, chroma_off);
ret = xan_unpack_luma(buf + 12, size, src, s->buffer_size >> 1);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Luma decoding failed\n");
return ret;
}
ybuf = s->y_buffer;
last = *src++;
ybuf[0] = last << 1;
for (j = 1; j < avctx->width - 1; j += 2) {
cur = (last + *src++) & 0x1F;
ybuf[j] = last + cur;
ybuf[j+1] = cur << 1;
last = cur;
}
ybuf[j] = last << 1;
prev_buf = ybuf;
ybuf += avctx->width;
for (i = 1; i < avctx->height; i++) {
last = ((prev_buf[0] >> 1) + *src++) & 0x1F;
ybuf[0] = last << 1;
for (j = 1; j < avctx->width - 1; j += 2) {
cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F;
ybuf[j] = last + cur;
ybuf[j+1] = cur << 1;
last = cur;
}
ybuf[j] = last << 1;
prev_buf = ybuf;
ybuf += avctx->width;
}
if (corr_off) {
int corr_end, dec_size;
corr_end = avpkt->size;
if (chroma_off > corr_off)
corr_end = chroma_off;
dec_size = xan_unpack(s->scratch_buffer, s->buffer_size,
avpkt->data + 8 + corr_off,
corr_end - corr_off);
if (dec_size < 0)
dec_size = 0;
for (i = 0; i < dec_size; i++)
s->y_buffer[i*2+1] = (s->y_buffer[i*2+1] + (s->scratch_buffer[i] << 1)) & 0x3F;
}
src = s->y_buffer;
ybuf = s->pic.data[0];
for (j = 0; j < avctx->height; j++) {
for (i = 0; i < avctx->width; i++)
ybuf[i] = (src[i] << 2) | (src[i] >> 3);
src += avctx->width;
ybuf += s->pic.linesize[0];
}
return 0;
}
| 13,333 |
qemu | 2209401fa73e176ed093167b8f60aba797f25d49 | 1 | static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
DeviceState *dev = DEVICE(obj);
Error *local_err = NULL;
Property *prop = opaque;
CharBackend *be = qdev_get_prop_ptr(dev, prop);
CharDriverState *s;
char *str;
if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
return;
}
visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
if (!*str) {
g_free(str);
be->chr = NULL;
return;
}
s = qemu_chr_find(str);
g_free(str);
if (s == NULL) {
error_setg(errp, "Property '%s.%s' can't find value '%s'",
object_get_typename(obj), prop->name, str);
return;
}
if (!qemu_chr_fe_init(be, s, errp)) {
error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
object_get_typename(obj), prop->name, str);
return;
}
}
| 13,335 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.