diff --git "a/devign/split/devign_512-1024_test.json" "b/devign/split/devign_512-1024_test.json" new file mode 100644--- /dev/null +++ "b/devign/split/devign_512-1024_test.json" @@ -0,0 +1,3626 @@ +[ + { + "index": 5917, + "code": "void helper_ldda_asi(target_ulong addr, int asi, int rd)\n\n{\n\n if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)\n\n || ((env->def->features & CPU_FEATURE_HYPV)\n\n && asi >= 0x30 && asi < 0x80\n\n && !(env->hpstate & HS_PRIV)))\n\n raise_exception(TT_PRIV_ACT);\n\n\n\n switch (asi) {\n\n case 0x24: // Nucleus quad LDD 128 bit atomic\n\n case 0x2c: // Nucleus quad LDD 128 bit atomic LE\n\n helper_check_align(addr, 0xf);\n\n if (rd == 0) {\n\n env->gregs[1] = ldq_kernel(addr + 8);\n\n if (asi == 0x2c)\n\n bswap64s(&env->gregs[1]);\n\n } else if (rd < 8) {\n\n env->gregs[rd] = ldq_kernel(addr);\n\n env->gregs[rd + 1] = ldq_kernel(addr + 8);\n\n if (asi == 0x2c) {\n\n bswap64s(&env->gregs[rd]);\n\n bswap64s(&env->gregs[rd + 1]);\n\n }\n\n } else {\n\n env->regwptr[rd] = ldq_kernel(addr);\n\n env->regwptr[rd + 1] = ldq_kernel(addr + 8);\n\n if (asi == 0x2c) {\n\n bswap64s(&env->regwptr[rd]);\n\n bswap64s(&env->regwptr[rd + 1]);\n\n }\n\n }\n\n break;\n\n default:\n\n helper_check_align(addr, 0x3);\n\n if (rd == 0)\n\n env->gregs[1] = helper_ld_asi(addr + 4, asi, 4, 0);\n\n else if (rd < 8) {\n\n env->gregs[rd] = helper_ld_asi(addr, asi, 4, 0);\n\n env->gregs[rd + 1] = helper_ld_asi(addr + 4, asi, 4, 0);\n\n } else {\n\n env->regwptr[rd] = helper_ld_asi(addr, asi, 4, 0);\n\n env->regwptr[rd + 1] = helper_ld_asi(addr + 4, asi, 4, 0);\n\n }\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "2aae2b8e0abd58e76d616bcbe93c6966d06d0188", + "length": 551 + }, + { + "index": 12607, + "code": "static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,\n\n AVPacket *pkt) {\n\n\n\n int chunk_type;\n\n\n\n if (s->audio_chunk_offset) {\n\n\n\n\n\n\n\n\n /* adjust for PCM audio by skipping chunk header */\n\n if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) {\n\n s->audio_chunk_offset += 6;\n\n s->audio_chunk_size -= 6;\n\n\n\n\n avio_seek(pb, s->audio_chunk_offset, SEEK_SET);\n\n s->audio_chunk_offset = 0;\n\n\n\n if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))\n\n return CHUNK_EOF;\n\n\n\n pkt->stream_index = s->audio_stream_index;\n\n pkt->pts = s->audio_frame_count;\n\n\n\n /* audio frame maintenance */\n\n if (s->audio_type != CODEC_ID_INTERPLAY_DPCM)\n\n s->audio_frame_count +=\n\n (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8));\n\n else\n\n s->audio_frame_count +=\n\n (s->audio_chunk_size - 6) / s->audio_channels;\n\n\n\n av_dlog(NULL, \"sending audio frame with pts %\"PRId64\" (%d audio frames)\\n\",\n\n pkt->pts, s->audio_frame_count);\n\n\n\n chunk_type = CHUNK_VIDEO;\n\n\n\n } else if (s->decode_map_chunk_offset) {\n\n\n\n /* send both the decode map and the video data together */\n\n\n\n if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size))\n\n return CHUNK_NOMEM;\n\n\n\n if (s->has_palette) {\n\n uint8_t *pal;\n\n\n\n pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,\n\n AVPALETTE_SIZE);\n\n if (pal) {\n\n memcpy(pal, s->palette, AVPALETTE_SIZE);\n\n s->has_palette = 0;\n\n\n\n\n\n pkt->pos= s->decode_map_chunk_offset;\n\n avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET);\n\n s->decode_map_chunk_offset = 0;\n\n\n\n if (avio_read(pb, pkt->data, s->decode_map_chunk_size) !=\n\n s->decode_map_chunk_size) {\n\n av_free_packet(pkt);\n\n return CHUNK_EOF;\n\n\n\n\n avio_seek(pb, s->video_chunk_offset, SEEK_SET);\n\n s->video_chunk_offset = 0;\n\n\n\n if (avio_read(pb, pkt->data + s->decode_map_chunk_size,\n\n s->video_chunk_size) != s->video_chunk_size) {\n\n av_free_packet(pkt);\n\n return CHUNK_EOF;\n\n\n\n\n pkt->stream_index = s->video_stream_index;\n\n pkt->pts = s->video_pts;\n\n\n\n av_dlog(NULL, \"sending video frame with pts %\"PRId64\"\\n\", pkt->pts);\n\n\n\n s->video_pts += s->frame_pts_inc;\n\n\n\n chunk_type = CHUNK_VIDEO;\n\n\n\n } else {\n\n\n\n avio_seek(pb, s->next_chunk_offset, SEEK_SET);\n\n chunk_type = CHUNK_DONE;\n\n\n\n\n\n\n return chunk_type;\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f5be84cfbc9c132a867ae8a8c0e0de26ed1a4e88", + "length": 655 + }, + { + "index": 6687, + "code": "static int usb_host_scan(void *opaque, USBScanFunc *func)\n\n{\n\n FILE *f = 0;\n\n DIR *dir = 0;\n\n int ret = 0;\n\n const char *devices = \"/devices\";\n\n const char *opened = \"husb: opened %s%s\\n\";\n\n const char *fs_type[] = {\"unknown\", \"proc\", \"dev\", \"sys\"};\n\n char devpath[PATH_MAX];\n\n\n\n /* only check the host once */\n\n if (!usb_fs_type) {\n\n f = fopen(USBPROCBUS_PATH \"/devices\", \"r\");\n\n if (f) {\n\n /* devices found in /proc/bus/usb/ */\n\n strcpy(devpath, USBPROCBUS_PATH);\n\n usb_fs_type = USB_FS_PROC;\n\n fclose(f);\n\n dprintf(opened, USBPROCBUS_PATH, devices);\n\n }\n\n /* try additional methods if an access method hasn't been found yet */\n\n f = fopen(USBDEVBUS_PATH \"/devices\", \"r\");\n\n if (!usb_fs_type && f) {\n\n /* devices found in /dev/bus/usb/ */\n\n strcpy(devpath, USBDEVBUS_PATH);\n\n usb_fs_type = USB_FS_DEV;\n\n fclose(f);\n\n dprintf(opened, USBDEVBUS_PATH, devices);\n\n }\n\n dir = opendir(USBSYSBUS_PATH \"/devices\");\n\n if (!usb_fs_type && dir) {\n\n /* devices found in /dev/bus/usb/ (yes - not a mistake!) */\n\n strcpy(devpath, USBDEVBUS_PATH);\n\n usb_fs_type = USB_FS_SYS;\n\n closedir(dir);\n\n dprintf(opened, USBSYSBUS_PATH, devices);\n\n }\n\n if (!usb_fs_type) {\n\n term_printf(\"husb: unable to access USB devices\\n\");\n\n goto the_end;\n\n }\n\n\n\n /* the module setting (used later for opening devices) */\n\n usb_host_device_path = qemu_mallocz(strlen(devpath)+1);\n\n if (usb_host_device_path) {\n\n strcpy(usb_host_device_path, devpath);\n\n term_printf(\"husb: using %s file-system with %s\\n\", fs_type[usb_fs_type], usb_host_device_path);\n\n } else {\n\n /* out of memory? */\n\n perror(\"husb: unable to allocate memory for device path\");\n\n goto the_end;\n\n }\n\n }\n\n\n\n switch (usb_fs_type) {\n\n case USB_FS_PROC:\n\n case USB_FS_DEV:\n\n ret = usb_host_scan_dev(opaque, func);\n\n break;\n\n case USB_FS_SYS:\n\n ret = usb_host_scan_sys(opaque, func);\n\n break;\n\n }\n\n the_end:\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "f16a0db323e1a8c0044696815cceeb98706f2243", + "length": 562 + }, + { + "index": 26698, + "code": "void hmp_savevm(Monitor *mon, const QDict *qdict)\n\n{\n\n BlockDriverState *bs, *bs1;\n\n QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;\n\n int ret;\n\n QEMUFile *f;\n\n int saved_vm_running;\n\n uint64_t vm_state_size;\n\n qemu_timeval tv;\n\n struct tm tm;\n\n const char *name = qdict_get_try_str(qdict, \"name\");\n\n Error *local_err = NULL;\n\n AioContext *aio_context;\n\n\n\n if (!bdrv_all_can_snapshot(&bs)) {\n\n monitor_printf(mon, \"Device '%s' is writable but does not \"\n\n \"support snapshots.\\n\", bdrv_get_device_name(bs));\n\n return;\n\n }\n\n\n\n /* Delete old snapshots of the same name */\n\n if (name && bdrv_all_delete_snapshot(name, &bs1, &local_err) < 0) {\n\n error_reportf_err(local_err,\n\n \"Error while deleting snapshot on device '%s': \",\n\n bdrv_get_device_name(bs1));\n\n return;\n\n }\n\n\n\n bs = bdrv_all_find_vmstate_bs();\n\n if (bs == NULL) {\n\n monitor_printf(mon, \"No block device can accept snapshots\\n\");\n\n return;\n\n }\n\n aio_context = bdrv_get_aio_context(bs);\n\n\n\n saved_vm_running = runstate_is_running();\n\n\n\n ret = global_state_store();\n\n if (ret) {\n\n monitor_printf(mon, \"Error saving global state\\n\");\n\n return;\n\n }\n\n vm_stop(RUN_STATE_SAVE_VM);\n\n\n\n aio_context_acquire(aio_context);\n\n\n\n memset(sn, 0, sizeof(*sn));\n\n\n\n /* fill auxiliary fields */\n\n qemu_gettimeofday(&tv);\n\n sn->date_sec = tv.tv_sec;\n\n sn->date_nsec = tv.tv_usec * 1000;\n\n sn->vm_clock_nsec = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);\n\n\n\n if (name) {\n\n ret = bdrv_snapshot_find(bs, old_sn, name);\n\n if (ret >= 0) {\n\n pstrcpy(sn->name, sizeof(sn->name), old_sn->name);\n\n pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);\n\n } else {\n\n pstrcpy(sn->name, sizeof(sn->name), name);\n\n }\n\n } else {\n\n /* cast below needed for OpenBSD where tv_sec is still 'long' */\n\n localtime_r((const time_t *)&tv.tv_sec, &tm);\n\n strftime(sn->name, sizeof(sn->name), \"vm-%Y%m%d%H%M%S\", &tm);\n\n }\n\n\n\n /* save the VM state */\n\n f = qemu_fopen_bdrv(bs, 1);\n\n if (!f) {\n\n monitor_printf(mon, \"Could not open VM state file\\n\");\n\n goto the_end;\n\n }\n\n ret = qemu_savevm_state(f, &local_err);\n\n vm_state_size = qemu_ftell(f);\n\n qemu_fclose(f);\n\n if (ret < 0) {\n\n error_report_err(local_err);\n\n goto the_end;\n\n }\n\n\n\n ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs);\n\n if (ret < 0) {\n\n monitor_printf(mon, \"Error while creating snapshot on '%s'\\n\",\n\n bdrv_get_device_name(bs));\n\n }\n\n\n\n the_end:\n\n aio_context_release(aio_context);\n\n if (saved_vm_running) {\n\n vm_start();\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ac8c19ba742fcbc3d64a5390b32acc6479edd7e1", + "length": 745 + }, + { + "index": 17908, + "code": "static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)\n\n{\n\n if (pkt->size >= 7 &&\n\n pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&\n\n !strcmp(pkt->data, \"GAB2\") && AV_RL16(pkt->data + 5) == 2) {\n\n uint8_t desc[256];\n\n int score = AVPROBE_SCORE_EXTENSION, ret;\n\n AVIStream *ast = st->priv_data;\n\n AVInputFormat *sub_demuxer;\n\n AVRational time_base;\n\n int size;\n\n AVIOContext *pb = avio_alloc_context(pkt->data + 7,\n\n pkt->size - 7,\n\n 0, NULL, NULL, NULL, NULL);\n\n AVProbeData pd;\n\n unsigned int desc_len = avio_rl32(pb);\n\n\n\n if (desc_len > pb->buf_end - pb->buf_ptr)\n\n goto error;\n\n\n\n ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));\n\n avio_skip(pb, desc_len - ret);\n\n if (*desc)\n\n av_dict_set(&st->metadata, \"title\", desc, 0);\n\n\n\n avio_rl16(pb); /* flags? */\n\n avio_rl32(pb); /* data size */\n\n\n\n size = pb->buf_end - pb->buf_ptr;\n\n pd = (AVProbeData) { .buf = av_mallocz(size + AVPROBE_PADDING_SIZE),\n\n .buf_size = size };\n\n if (!pd.buf)\n\n goto error;\n\n memcpy(pd.buf, pb->buf_ptr, size);\n\n sub_demuxer = av_probe_input_format2(&pd, 1, &score);\n\n av_freep(&pd.buf);\n\n if (!sub_demuxer)\n\n goto error;\n\n\n\n if (!(ast->sub_ctx = avformat_alloc_context()))\n\n goto error;\n\n\n\n ast->sub_ctx->pb = pb;\n\n\n\n av_assert0(!ast->sub_ctx->codec_whitelist && !ast->sub_ctx->format_whitelist);\n\n ast->sub_ctx-> codec_whitelist = av_strdup(s->codec_whitelist);\n\n ast->sub_ctx->format_whitelist = av_strdup(s->format_whitelist);\n\n\n\n if (!avformat_open_input(&ast->sub_ctx, \"\", sub_demuxer, NULL)) {\n\n ff_read_packet(ast->sub_ctx, &ast->sub_pkt);\n\n *st->codec = *ast->sub_ctx->streams[0]->codec;\n\n ast->sub_ctx->streams[0]->codec->extradata = NULL;\n\n time_base = ast->sub_ctx->streams[0]->time_base;\n\n avpriv_set_pts_info(st, 64, time_base.num, time_base.den);\n\n }\n\n ast->sub_buffer = pkt->data;\n\n memset(pkt, 0, sizeof(*pkt));\n\n return 1;\n\n\n\nerror:\n\n av_freep(&pb);\n\n }\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "4641ae352ec587355764ffd5c43dd0d0ebd47654", + "length": 631 + }, + { + "index": 9750, + "code": "static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)\n\n{\n\n uint32_t associativity[] = {cpu_to_be32(0x4), cpu_to_be32(0x0),\n\n cpu_to_be32(0x0), cpu_to_be32(0x0),\n\n cpu_to_be32(0x0)};\n\n char mem_name[32];\n\n hwaddr node0_size, mem_start;\n\n uint64_t mem_reg_property[2];\n\n int i, off;\n\n\n\n /* memory node(s) */\n\n node0_size = (nb_numa_nodes > 1) ? node_mem[0] : ram_size;\n\n\n\n /* RMA */\n\n mem_reg_property[0] = 0;\n\n mem_reg_property[1] = cpu_to_be64(spapr->rma_size);\n\n off = fdt_add_subnode(fdt, 0, \"memory@0\");\n\n _FDT(off);\n\n _FDT((fdt_setprop_string(fdt, off, \"device_type\", \"memory\")));\n\n _FDT((fdt_setprop(fdt, off, \"reg\", mem_reg_property,\n\n sizeof(mem_reg_property))));\n\n _FDT((fdt_setprop(fdt, off, \"ibm,associativity\", associativity,\n\n sizeof(associativity))));\n\n\n\n /* RAM: Node 0 */\n\n if (node0_size > spapr->rma_size) {\n\n mem_reg_property[0] = cpu_to_be64(spapr->rma_size);\n\n mem_reg_property[1] = cpu_to_be64(node0_size - spapr->rma_size);\n\n\n\n sprintf(mem_name, \"memory@\" TARGET_FMT_lx, spapr->rma_size);\n\n off = fdt_add_subnode(fdt, 0, mem_name);\n\n _FDT(off);\n\n _FDT((fdt_setprop_string(fdt, off, \"device_type\", \"memory\")));\n\n _FDT((fdt_setprop(fdt, off, \"reg\", mem_reg_property,\n\n sizeof(mem_reg_property))));\n\n _FDT((fdt_setprop(fdt, off, \"ibm,associativity\", associativity,\n\n sizeof(associativity))));\n\n }\n\n\n\n /* RAM: Node 1 and beyond */\n\n mem_start = node0_size;\n\n for (i = 1; i < nb_numa_nodes; i++) {\n\n mem_reg_property[0] = cpu_to_be64(mem_start);\n\n mem_reg_property[1] = cpu_to_be64(node_mem[i]);\n\n associativity[3] = associativity[4] = cpu_to_be32(i);\n\n sprintf(mem_name, \"memory@\" TARGET_FMT_lx, mem_start);\n\n off = fdt_add_subnode(fdt, 0, mem_name);\n\n _FDT(off);\n\n _FDT((fdt_setprop_string(fdt, off, \"device_type\", \"memory\")));\n\n _FDT((fdt_setprop(fdt, off, \"reg\", mem_reg_property,\n\n sizeof(mem_reg_property))));\n\n _FDT((fdt_setprop(fdt, off, \"ibm,associativity\", associativity,\n\n sizeof(associativity))));\n\n mem_start += node_mem[i];\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "5fe269b16c6dc8f19da3e8c13d4c66958b00d2f0", + "length": 700 + }, + { + "index": 25882, + "code": "static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)\n\n{\n\n MOVQ_BFE(mm6);\n\n __asm__ volatile(\n\n \"lea (%3, %3), %%\"REG_a\" \\n\\t\"\n\n \"movq (%1), %%mm0 \\n\\t\"\n\n \".p2align 3 \\n\\t\"\n\n \"1: \\n\\t\"\n\n \"movq (%1, %3), %%mm1 \\n\\t\"\n\n \"movq (%1, %%\"REG_a\"), %%mm2 \\n\\t\"\n\n PAVGBP(%%mm1, %%mm0, %%mm4, %%mm2, %%mm1, %%mm5)\n\n \"movq (%2), %%mm3 \\n\\t\"\n\n PAVGB_MMX(%%mm3, %%mm4, %%mm0, %%mm6)\n\n \"movq (%2, %3), %%mm3 \\n\\t\"\n\n PAVGB_MMX(%%mm3, %%mm5, %%mm1, %%mm6)\n\n \"movq %%mm0, (%2) \\n\\t\"\n\n \"movq %%mm1, (%2, %3) \\n\\t\"\n\n \"add %%\"REG_a\", %1 \\n\\t\"\n\n \"add %%\"REG_a\", %2 \\n\\t\"\n\n\n\n \"movq (%1, %3), %%mm1 \\n\\t\"\n\n \"movq (%1, %%\"REG_a\"), %%mm0 \\n\\t\"\n\n PAVGBP(%%mm1, %%mm2, %%mm4, %%mm0, %%mm1, %%mm5)\n\n \"movq (%2), %%mm3 \\n\\t\"\n\n PAVGB_MMX(%%mm3, %%mm4, %%mm2, %%mm6)\n\n \"movq (%2, %3), %%mm3 \\n\\t\"\n\n PAVGB_MMX(%%mm3, %%mm5, %%mm1, %%mm6)\n\n \"movq %%mm2, (%2) \\n\\t\"\n\n \"movq %%mm1, (%2, %3) \\n\\t\"\n\n \"add %%\"REG_a\", %1 \\n\\t\"\n\n \"add %%\"REG_a\", %2 \\n\\t\"\n\n\n\n \"subl $4, %0 \\n\\t\"\n\n \"jnz 1b \\n\\t\"\n\n :\"+g\"(h), \"+S\"(pixels), \"+D\"(block)\n\n :\"r\"((x86_reg)line_size)\n\n :REG_a, \"memory\");\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "0493e42eb2f9fbf42d0aee0b48a84f81f19fb7fa", + "length": 611 + }, + { + "index": 5114, + "code": "int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)\n\n{\n\n CPUS390XState *env = &cpu->env;\n\n uint32_t fh;\n\n S390PCIBusDevice *pbdev;\n\n S390PCIIOMMU *iommu;\n\n hwaddr start, end;\n\n IOMMUTLBEntry entry;\n\n MemoryRegion *mr;\n\n\n\n cpu_synchronize_state(CPU(cpu));\n\n\n\n if (env->psw.mask & PSW_MASK_PSTATE) {\n\n program_interrupt(env, PGM_PRIVILEGED, 4);\n\n goto out;\n\n }\n\n\n\n if (r2 & 0x1) {\n\n program_interrupt(env, PGM_SPECIFICATION, 4);\n\n goto out;\n\n }\n\n\n\n fh = env->regs[r1] >> 32;\n\n start = env->regs[r2];\n\n end = start + env->regs[r2 + 1];\n\n\n\n pbdev = s390_pci_find_dev_by_fh(s390_get_phb(), fh);\n\n if (!pbdev) {\n\n DPRINTF(\"rpcit no pci dev\\n\");\n\n setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);\n\n goto out;\n\n }\n\n\n\n switch (pbdev->state) {\n\n case ZPCI_FS_RESERVED:\n\n case ZPCI_FS_STANDBY:\n\n case ZPCI_FS_DISABLED:\n\n case ZPCI_FS_PERMANENT_ERROR:\n\n setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);\n\n return 0;\n\n case ZPCI_FS_ERROR:\n\n setcc(cpu, ZPCI_PCI_LS_ERR);\n\n s390_set_status_code(env, r1, ZPCI_MOD_ST_ERROR_RECOVER);\n\n return 0;\n\n default:\n\n break;\n\n }\n\n\n\n iommu = pbdev->iommu;\n\n if (!iommu->g_iota) {\n\n pbdev->state = ZPCI_FS_ERROR;\n\n setcc(cpu, ZPCI_PCI_LS_ERR);\n\n s390_set_status_code(env, r1, ZPCI_PCI_ST_INSUF_RES);\n\n s390_pci_generate_error_event(ERR_EVENT_INVALAS, pbdev->fh, pbdev->fid,\n\n start, 0);\n\n goto out;\n\n }\n\n\n\n if (end < iommu->pba || start > iommu->pal) {\n\n pbdev->state = ZPCI_FS_ERROR;\n\n setcc(cpu, ZPCI_PCI_LS_ERR);\n\n s390_set_status_code(env, r1, ZPCI_PCI_ST_INSUF_RES);\n\n s390_pci_generate_error_event(ERR_EVENT_OORANGE, pbdev->fh, pbdev->fid,\n\n start, 0);\n\n goto out;\n\n }\n\n\n\n mr = &iommu->iommu_mr;\n\n while (start < end) {\n\n entry = mr->iommu_ops->translate(mr, start, 0);\n\n\n\n if (!entry.translated_addr) {\n\n pbdev->state = ZPCI_FS_ERROR;\n\n setcc(cpu, ZPCI_PCI_LS_ERR);\n\n s390_set_status_code(env, r1, ZPCI_PCI_ST_INSUF_RES);\n\n s390_pci_generate_error_event(ERR_EVENT_SERR, pbdev->fh, pbdev->fid,\n\n start, ERR_EVENT_Q_BIT);\n\n goto out;\n\n }\n\n\n\n memory_region_notify_iommu(mr, entry);\n\n start += entry.addr_mask + 1;\n\n }\n\n\n\n setcc(cpu, ZPCI_PCI_LS_OK);\n\nout:\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "bf55b7afce53718ef96f4e6616da62c0ccac37dd", + "length": 731 + }, + { + "index": 11831, + "code": "static int cow_create(const char *filename, QemuOpts *opts, Error **errp)\n\n{\n\n struct cow_header_v2 cow_header;\n\n struct stat st;\n\n int64_t image_sectors = 0;\n\n char *image_filename = NULL;\n\n Error *local_err = NULL;\n\n int ret;\n\n BlockDriverState *cow_bs = NULL;\n\n\n\n /* Read out options */\n\n image_sectors = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),\n\n BDRV_SECTOR_SIZE);\n\n image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);\n\n\n\n ret = bdrv_create_file(filename, opts, &local_err);\n\n if (ret < 0) {\n\n error_propagate(errp, local_err);\n\n goto exit;\n\n }\n\n\n\n ret = bdrv_open(&cow_bs, filename, NULL, NULL,\n\n BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);\n\n if (ret < 0) {\n\n error_propagate(errp, local_err);\n\n goto exit;\n\n }\n\n\n\n memset(&cow_header, 0, sizeof(cow_header));\n\n cow_header.magic = cpu_to_be32(COW_MAGIC);\n\n cow_header.version = cpu_to_be32(COW_VERSION);\n\n if (image_filename) {\n\n /* Note: if no file, we put a dummy mtime */\n\n cow_header.mtime = cpu_to_be32(0);\n\n\n\n if (stat(image_filename, &st) != 0) {\n\n goto mtime_fail;\n\n }\n\n cow_header.mtime = cpu_to_be32(st.st_mtime);\n\n mtime_fail:\n\n pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file),\n\n image_filename);\n\n }\n\n cow_header.sectorsize = cpu_to_be32(512);\n\n cow_header.size = cpu_to_be64(image_sectors * 512);\n\n ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header));\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\n /* resize to include at least all the bitmap */\n\n ret = bdrv_truncate(cow_bs,\n\n sizeof(cow_header) + ((image_sectors + 7) >> 3));\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\nexit:\n\n g_free(image_filename);\n\n if (cow_bs) {\n\n bdrv_unref(cow_bs);\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "550830f9351291c585c963204ad9127998b1c1ce", + "length": 522 + }, + { + "index": 9929, + "code": "int vhost_dev_init(struct vhost_dev *hdev, void *opaque,\n\n VhostBackendType backend_type, bool force)\n\n{\n\n uint64_t features;\n\n int i, r;\n\n\n\n if (vhost_set_backend_type(hdev, backend_type) < 0) {\n\n close((uintptr_t)opaque);\n\n return -1;\n\n }\n\n\n\n if (hdev->vhost_ops->vhost_backend_init(hdev, opaque) < 0) {\n\n close((uintptr_t)opaque);\n\n return -errno;\n\n }\n\n\n\n r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_OWNER, NULL);\n\n if (r < 0) {\n\n goto fail;\n\n }\n\n\n\n r = hdev->vhost_ops->vhost_call(hdev, VHOST_GET_FEATURES, &features);\n\n if (r < 0) {\n\n goto fail;\n\n }\n\n\n\n for (i = 0; i < hdev->nvqs; ++i) {\n\n r = vhost_virtqueue_init(hdev, hdev->vqs + i, i);\n\n if (r < 0) {\n\n goto fail_vq;\n\n }\n\n }\n\n hdev->features = features;\n\n\n\n hdev->memory_listener = (MemoryListener) {\n\n .begin = vhost_begin,\n\n .commit = vhost_commit,\n\n .region_add = vhost_region_add,\n\n .region_del = vhost_region_del,\n\n .region_nop = vhost_region_nop,\n\n .log_start = vhost_log_start,\n\n .log_stop = vhost_log_stop,\n\n .log_sync = vhost_log_sync,\n\n .log_global_start = vhost_log_global_start,\n\n .log_global_stop = vhost_log_global_stop,\n\n .eventfd_add = vhost_eventfd_add,\n\n .eventfd_del = vhost_eventfd_del,\n\n .priority = 10\n\n };\n\n hdev->migration_blocker = NULL;\n\n if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) {\n\n error_setg(&hdev->migration_blocker,\n\n \"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.\");\n\n migrate_add_blocker(hdev->migration_blocker);\n\n }\n\n hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));\n\n hdev->n_mem_sections = 0;\n\n hdev->mem_sections = NULL;\n\n hdev->log = NULL;\n\n hdev->log_size = 0;\n\n hdev->log_enabled = false;\n\n hdev->started = false;\n\n hdev->memory_changed = false;\n\n memory_listener_register(&hdev->memory_listener, &address_space_memory);\n\n hdev->force = force;\n\n return 0;\n\nfail_vq:\n\n while (--i >= 0) {\n\n vhost_virtqueue_cleanup(hdev->vqs + i);\n\n }\n\nfail:\n\n r = -errno;\n\n hdev->vhost_ops->vhost_backend_cleanup(hdev);\n\n return r;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "1e7398a140f7a6bd9f5a438e7ad0f1ef50990e25", + "length": 650 + }, + { + "index": 4072, + "code": "static int qcow_snapshot_create(BlockDriverState *bs,\n\n QEMUSnapshotInfo *sn_info)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n QCowSnapshot *snapshots1, sn1, *sn = &sn1;\n\n int i, ret;\n\n uint64_t *l1_table = NULL;\n\n\n\n memset(sn, 0, sizeof(*sn));\n\n\n\n if (sn_info->id_str[0] == '\\0') {\n\n /* compute a new id */\n\n find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));\n\n }\n\n\n\n /* check that the ID is unique */\n\n if (find_snapshot_by_id(bs, sn_info->id_str) >= 0)\n\n return -ENOENT;\n\n\n\n sn->id_str = qemu_strdup(sn_info->id_str);\n\n if (!sn->id_str)\n\n goto fail;\n\n sn->name = qemu_strdup(sn_info->name);\n\n if (!sn->name)\n\n goto fail;\n\n sn->vm_state_size = sn_info->vm_state_size;\n\n sn->date_sec = sn_info->date_sec;\n\n sn->date_nsec = sn_info->date_nsec;\n\n sn->vm_clock_nsec = sn_info->vm_clock_nsec;\n\n\n\n ret = update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);\n\n if (ret < 0)\n\n goto fail;\n\n\n\n /* create the L1 table of the snapshot */\n\n sn->l1_table_offset = alloc_clusters(bs, s->l1_size * sizeof(uint64_t));\n\n sn->l1_size = s->l1_size;\n\n\n\n l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));\n\n if (!l1_table)\n\n goto fail;\n\n for(i = 0; i < s->l1_size; i++) {\n\n l1_table[i] = cpu_to_be64(s->l1_table[i]);\n\n }\n\n if (bdrv_pwrite(s->hd, sn->l1_table_offset,\n\n l1_table, s->l1_size * sizeof(uint64_t)) !=\n\n (s->l1_size * sizeof(uint64_t)))\n\n goto fail;\n\n qemu_free(l1_table);\n\n l1_table = NULL;\n\n\n\n snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));\n\n if (!snapshots1)\n\n goto fail;\n\n memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));\n\n\n s->snapshots = snapshots1;\n\n s->snapshots[s->nb_snapshots++] = *sn;\n\n\n\n if (qcow_write_snapshots(bs) < 0)\n\n goto fail;\n\n#ifdef DEBUG_ALLOC\n\n check_refcounts(bs);\n\n#endif\n\n return 0;\n\n fail:\n\n qemu_free(sn->name);\n\n qemu_free(l1_table);\n\n return -1;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "54c16572a03e3c9c5694653361f9bfa3959fcb59", + "length": 620 + }, + { + "index": 24606, + "code": "static void s390_virtio_device_sync(VirtIOS390Device *dev)\n\n{\n\n VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);\n\n ram_addr_t cur_offs;\n\n uint8_t num_vq;\n\n int i;\n\n\n\n virtio_reset(dev->vdev);\n\n\n\n /* Sync dev space */\n\n stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id);\n\n\n\n stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, s390_virtio_device_num_vq(dev));\n\n stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len);\n\n\n\n stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len);\n\n\n\n num_vq = s390_virtio_device_num_vq(dev);\n\n stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq);\n\n\n\n /* Sync virtqueues */\n\n for (i = 0; i < num_vq; i++) {\n\n ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +\n\n (i * VIRTIO_VQCONFIG_LEN);\n\n ram_addr_t vring;\n\n\n\n vring = s390_virtio_next_ring(bus);\n\n virtio_queue_set_addr(dev->vdev, i, vring);\n\n virtio_queue_set_vector(dev->vdev, i, i);\n\n stq_phys(vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);\n\n stw_phys(vq + VIRTIO_VQCONFIG_OFFS_NUM, virtio_queue_get_num(dev->vdev, i));\n\n }\n\n\n\n cur_offs = dev->dev_offs;\n\n cur_offs += VIRTIO_DEV_OFFS_CONFIG;\n\n cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;\n\n\n\n /* Sync feature bitmap */\n\n if (dev->vdev->get_features) {\n\n stl_phys(cur_offs, dev->vdev->get_features(dev->vdev));\n\n }\n\n\n\n dev->feat_offs = cur_offs + dev->feat_len;\n\n cur_offs += dev->feat_len * 2;\n\n\n\n /* Sync config space */\n\n if (dev->vdev->get_config) {\n\n dev->vdev->get_config(dev->vdev, dev->vdev->config);\n\n }\n\n\n\n cpu_physical_memory_rw(cur_offs, dev->vdev->config, dev->vdev->config_len, 1);\n\n cur_offs += dev->vdev->config_len;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "8172539d21a03e982aa7f139ddc1607dc1422045", + "length": 579 + }, + { + "index": 2247, + "code": "static int slirp_guestfwd(SlirpState *s, const char *config_str,\n\n int legacy_format)\n\n{\n\n struct in_addr server = { .s_addr = 0 };\n\n struct GuestFwd *fwd;\n\n const char *p;\n\n char buf[128];\n\n char *end;\n\n int port;\n\n\n\n p = config_str;\n\n if (legacy_format) {\n\n if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {\n\n goto fail_syntax;\n\n }\n\n } else {\n\n if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {\n\n goto fail_syntax;\n\n }\n\n if (strcmp(buf, \"tcp\") && buf[0] != '\\0') {\n\n goto fail_syntax;\n\n }\n\n if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {\n\n goto fail_syntax;\n\n }\n\n if (buf[0] != '\\0' && !inet_aton(buf, &server)) {\n\n goto fail_syntax;\n\n }\n\n if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {\n\n goto fail_syntax;\n\n }\n\n }\n\n port = strtol(buf, &end, 10);\n\n if (*end != '\\0' || port < 1 || port > 65535) {\n\n goto fail_syntax;\n\n }\n\n\n\n fwd = g_malloc(sizeof(struct GuestFwd));\n\n snprintf(buf, sizeof(buf), \"guestfwd.tcp.%d\", port);\n\n\n\n if ((strlen(p) > 4) && !strncmp(p, \"cmd:\", 4)) {\n\n if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) {\n\n error_report(\"conflicting/invalid host:port in guest forwarding \"\n\n \"rule '%s'\", config_str);\n\n g_free(fwd);\n\n return -1;\n\n }\n\n } else {\n\n fwd->hd = qemu_chr_new(buf, p, NULL);\n\n if (!fwd->hd) {\n\n error_report(\"could not open guest forwarding device '%s'\", buf);\n\n g_free(fwd);\n\n return -1;\n\n }\n\n\n\n if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {\n\n error_report(\"conflicting/invalid host:port in guest forwarding \"\n\n \"rule '%s'\", config_str);\n\n g_free(fwd);\n\n return -1;\n\n }\n\n fwd->server = server;\n\n fwd->port = port;\n\n fwd->slirp = s->slirp;\n\n\n\n qemu_chr_fe_claim_no_fail(fwd->hd);\n\n qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,\n\n NULL, fwd);\n\n }\n\n return 0;\n\n\n\n fail_syntax:\n\n error_report(\"invalid guest forwarding rule '%s'\", config_str);\n\n return -1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "7a8919dc29a9f46dcadd950c2aa1acf74f28974d", + "length": 635 + }, + { + "index": 12329, + "code": "void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)\n\n{\n\n TCGOpcode op;\n\n TCGOpDef *def;\n\n const char *ct_str;\n\n int i, nb_args;\n\n\n\n for(;;) {\n\n if (tdefs->op == (TCGOpcode)-1)\n\n break;\n\n op = tdefs->op;\n\n assert((unsigned)op < NB_OPS);\n\n def = &tcg_op_defs[op];\n\n#if defined(CONFIG_DEBUG_TCG)\n\n /* Duplicate entry in op definitions? */\n\n assert(!def->used);\n\n def->used = 1;\n\n#endif\n\n nb_args = def->nb_iargs + def->nb_oargs;\n\n for(i = 0; i < nb_args; i++) {\n\n ct_str = tdefs->args_ct_str[i];\n\n /* Incomplete TCGTargetOpDef entry? */\n\n assert(ct_str != NULL);\n\n tcg_regset_clear(def->args_ct[i].u.regs);\n\n def->args_ct[i].ct = 0;\n\n if (ct_str[0] >= '0' && ct_str[0] <= '9') {\n\n int oarg;\n\n oarg = ct_str[0] - '0';\n\n assert(oarg < def->nb_oargs);\n\n assert(def->args_ct[oarg].ct & TCG_CT_REG);\n\n /* TCG_CT_ALIAS is for the output arguments. The input\n\n argument is tagged with TCG_CT_IALIAS. */\n\n def->args_ct[i] = def->args_ct[oarg];\n\n def->args_ct[oarg].ct = TCG_CT_ALIAS;\n\n def->args_ct[oarg].alias_index = i;\n\n def->args_ct[i].ct |= TCG_CT_IALIAS;\n\n def->args_ct[i].alias_index = oarg;\n\n } else {\n\n for(;;) {\n\n if (*ct_str == '\\0')\n\n break;\n\n switch(*ct_str) {\n\n case 'i':\n\n def->args_ct[i].ct |= TCG_CT_CONST;\n\n ct_str++;\n\n break;\n\n default:\n\n if (target_parse_constraint(&def->args_ct[i], &ct_str) < 0) {\n\n fprintf(stderr, \"Invalid constraint '%s' for arg %d of operation '%s'\\n\",\n\n ct_str, i, def->name);\n\n exit(1);\n\n }\n\n }\n\n }\n\n }\n\n }\n\n\n\n /* TCGTargetOpDef entry with too much information? */\n\n assert(i == TCG_MAX_OP_ARGS || tdefs->args_ct_str[i] == NULL);\n\n\n\n /* sort the constraints (XXX: this is just an heuristic) */\n\n sort_constraints(def, 0, def->nb_oargs);\n\n sort_constraints(def, def->nb_oargs, def->nb_iargs);\n\n\n\n#if 0\n\n {\n\n int i;\n\n\n\n printf(\"%s: sorted=\", def->name);\n\n for(i = 0; i < def->nb_oargs + def->nb_iargs; i++)\n\n printf(\" %d\", def->sorted_args[i]);\n\n printf(\"\\n\");\n\n }\n\n#endif\n\n tdefs++;\n\n }\n\n\n\n#if defined(CONFIG_DEBUG_TCG)\n\n i = 0;\n\n for (op = 0; op < tcg_op_defs_max; op++) {\n\n const TCGOpDef *def = &tcg_op_defs[op];\n\n if (def->flags & TCG_OPF_NOT_PRESENT) {\n\n /* Wrong entry in op definitions? */\n\n if (def->used) {\n\n fprintf(stderr, \"Invalid op definition for %s\\n\", def->name);\n\n i = 1;\n\n }\n\n } else {\n\n /* Missing entry in op definitions? */\n\n if (!def->used) {\n\n fprintf(stderr, \"Missing op definition for %s\\n\", def->name);\n\n i = 1;\n\n }\n\n }\n\n }\n\n if (i == 1) {\n\n tcg_abort();\n\n }\n\n#endif\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "eabb7b91b36b202b4dac2df2d59d698e3aff197a", + "length": 845 + }, + { + "index": 5473, + "code": "static void set_pixel_format(VncState *vs,\n\n\t\t\t int bits_per_pixel, int depth,\n\n\t\t\t int big_endian_flag, int true_color_flag,\n\n\t\t\t int red_max, int green_max, int blue_max,\n\n\t\t\t int red_shift, int green_shift, int blue_shift)\n\n{\n\n int host_big_endian_flag;\n\n\n\n#ifdef WORDS_BIGENDIAN\n\n host_big_endian_flag = 1;\n\n#else\n\n host_big_endian_flag = 0;\n\n#endif\n\n if (!true_color_flag) {\n\n fail:\n\n\tvnc_client_error(vs);\n\n return;\n\n }\n\n if (bits_per_pixel == 32 &&\n\n host_big_endian_flag == big_endian_flag &&\n\n red_max == 0xff && green_max == 0xff && blue_max == 0xff &&\n\n red_shift == 16 && green_shift == 8 && blue_shift == 0) {\n\n vs->depth = 4;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_32;\n\n } else\n\n if (bits_per_pixel == 16 &&\n\n host_big_endian_flag == big_endian_flag &&\n\n red_max == 31 && green_max == 63 && blue_max == 31 &&\n\n red_shift == 11 && green_shift == 5 && blue_shift == 0) {\n\n vs->depth = 2;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_16;\n\n } else\n\n if (bits_per_pixel == 8 &&\n\n red_max == 7 && green_max == 7 && blue_max == 3 &&\n\n red_shift == 5 && green_shift == 2 && blue_shift == 0) {\n\n vs->depth = 1;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_8;\n\n } else\n\n {\n\n /* generic and slower case */\n\n if (bits_per_pixel != 8 &&\n\n bits_per_pixel != 16 &&\n\n bits_per_pixel != 32)\n\n goto fail;\n\n vs->depth = 4;\n\n vs->red_shift = red_shift;\n\n vs->red_max = red_max;\n\n vs->red_shift1 = 24 - compute_nbits(red_max);\n\n vs->green_shift = green_shift;\n\n vs->green_max = green_max;\n\n vs->green_shift1 = 16 - compute_nbits(green_max);\n\n vs->blue_shift = blue_shift;\n\n vs->blue_max = blue_max;\n\n vs->blue_shift1 = 8 - compute_nbits(blue_max);\n\n vs->pix_bpp = bits_per_pixel / 8;\n\n vs->pix_big_endian = big_endian_flag;\n\n vs->write_pixels = vnc_write_pixels_generic;\n\n vs->send_hextile_tile = send_hextile_tile_generic;\n\n }\n\n\n\n vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height);\n\n memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));\n\n memset(vs->old_data, 42, vs->ds->linesize * vs->ds->height);\n\n\n\n vga_hw_invalidate();\n\n vga_hw_update();\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "8bba5c81b1febeb20cdd60f1c18eb0e695cad6d6", + "length": 702 + }, + { + "index": 4039, + "code": "static int init_tile(Jpeg2000DecoderContext *s, int tileno)\n\n{\n\n int compno;\n\n int tilex = tileno % s->numXtiles;\n\n int tiley = tileno / s->numXtiles;\n\n Jpeg2000Tile *tile = s->tile + tileno;\n\n\n\n if (!tile->comp)\n\n return AVERROR(ENOMEM);\n\n\n\n tile->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x);\n\n tile->coord[0][1] = FFMIN((tilex + 1) * s->tile_width + s->tile_offset_x, s->width);\n\n tile->coord[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y);\n\n tile->coord[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);\n\n\n\n for (compno = 0; compno < s->ncomponents; compno++) {\n\n Jpeg2000Component *comp = tile->comp + compno;\n\n Jpeg2000CodingStyle *codsty = tile->codsty + compno;\n\n Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;\n\n int ret; // global bandno\n\n\n\n comp->coord_o[0][0] = tile->coord[0][0];\n\n comp->coord_o[0][1] = tile->coord[0][1];\n\n comp->coord_o[1][0] = tile->coord[1][0];\n\n comp->coord_o[1][1] = tile->coord[1][1];\n\n if (compno) {\n\n comp->coord_o[0][0] /= s->cdx[compno];\n\n comp->coord_o[0][1] /= s->cdx[compno];\n\n comp->coord_o[1][0] /= s->cdy[compno];\n\n comp->coord_o[1][1] /= s->cdy[compno];\n\n }\n\n\n\n comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);\n\n comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);\n\n comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor);\n\n comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor);\n\n\n\n if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,\n\n s->cbps[compno], s->cdx[compno],\n\n s->cdy[compno], s->avctx))\n\n return ret;\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "43492ff3ab68a343c1264801baa1d5a02de10167", + "length": 672 + }, + { + "index": 8506, + "code": "int ff_lpc_calc_coefs(LPCContext *s,\n\n const int32_t *samples, int blocksize, int min_order,\n\n int max_order, int precision,\n\n int32_t coefs[][MAX_LPC_ORDER], int *shift,\n\n enum FFLPCType lpc_type, int lpc_passes,\n\n int omethod, int max_shift, int zero_shift)\n\n{\n\n double autoc[MAX_LPC_ORDER+1];\n\n double ref[MAX_LPC_ORDER];\n\n double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER];\n\n int i, j, pass = 0;\n\n int opt_order;\n\n\n\n av_assert2(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&\n\n lpc_type > FF_LPC_TYPE_FIXED);\n\n\n\n /* reinit LPC context if parameters have changed */\n\n if (blocksize != s->blocksize || max_order != s->max_order ||\n\n lpc_type != s->lpc_type) {\n\n ff_lpc_end(s);\n\n ff_lpc_init(s, blocksize, max_order, lpc_type);\n\n }\n\n\n\n if(lpc_passes <= 0)\n\n lpc_passes = 2;\n\n\n\n if (lpc_type == FF_LPC_TYPE_LEVINSON || (lpc_type == FF_LPC_TYPE_CHOLESKY && lpc_passes > 1)) {\n\n s->lpc_apply_welch_window(samples, blocksize, s->windowed_samples);\n\n\n\n s->lpc_compute_autocorr(s->windowed_samples, blocksize, max_order, autoc);\n\n\n\n compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);\n\n\n\n for(i=0; i>pass) + fabs(eval - var[0]);\n\n inv = 1/eval;\n\n rinv = sqrt(inv);\n\n for(j=0; j<=max_order; j++)\n\n var[j] *= rinv;\n\n weight += inv;\n\n }else\n\n weight++;\n\n\n\n m[pass&1].update_lls(&m[pass&1], var);\n\n }\n\n avpriv_solve_lls(&m[pass&1], 0.001, 0);\n\n }\n\n\n\n for(i=0; i0; i--)\n\n ref[i] = ref[i-1] - ref[i];\n\n }\n\n\n\n opt_order = max_order;\n\n\n\n if(omethod == ORDER_METHOD_EST) {\n\n opt_order = estimate_best_order(ref, min_order, max_order);\n\n i = opt_order-1;\n\n quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);\n\n } else {\n\n for(i=min_order-1; iinterrupt_request;\n\n\n\n if (unlikely(interrupt_request)) {\n\n if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) {\n\n /* Mask out external interrupts for this step. */\n\n interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK;\n\n }\n\n if (interrupt_request & CPU_INTERRUPT_DEBUG) {\n\n cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG;\n\n cpu->exception_index = EXCP_DEBUG;\n\n cpu_loop_exit(cpu);\n\n }\n\n if (replay_mode == REPLAY_MODE_PLAY && !replay_has_interrupt()) {\n\n /* Do nothing */\n\n } else if (interrupt_request & CPU_INTERRUPT_HALT) {\n\n replay_interrupt();\n\n cpu->interrupt_request &= ~CPU_INTERRUPT_HALT;\n\n cpu->halted = 1;\n\n cpu->exception_index = EXCP_HLT;\n\n cpu_loop_exit(cpu);\n\n }\n\n#if defined(TARGET_I386)\n\n else if (interrupt_request & CPU_INTERRUPT_INIT) {\n\n X86CPU *x86_cpu = X86_CPU(cpu);\n\n CPUArchState *env = &x86_cpu->env;\n\n replay_interrupt();\n\n cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0);\n\n do_cpu_init(x86_cpu);\n\n cpu->exception_index = EXCP_HALTED;\n\n cpu_loop_exit(cpu);\n\n }\n\n#else\n\n else if (interrupt_request & CPU_INTERRUPT_RESET) {\n\n replay_interrupt();\n\n cpu_reset(cpu);\n\n cpu_loop_exit(cpu);\n\n }\n\n#endif\n\n /* The target hook has 3 exit conditions:\n\n False when the interrupt isn't processed,\n\n True when it is, and we should restart on a new TB,\n\n and via longjmp via cpu_loop_exit. */\n\n else {\n\n replay_interrupt();\n\n if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {\n\n *last_tb = NULL;\n\n }\n\n /* The target hook may have updated the 'cpu->interrupt_request';\n\n * reload the 'interrupt_request' value */\n\n interrupt_request = cpu->interrupt_request;\n\n }\n\n if (interrupt_request & CPU_INTERRUPT_EXITTB) {\n\n cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB;\n\n /* ensure that no TB jump will be modified as\n\n the program flow was changed */\n\n *last_tb = NULL;\n\n }\n\n }\n\n if (unlikely(atomic_read(&cpu->exit_request) || replay_has_interrupt())) {\n\n atomic_set(&cpu->exit_request, 0);\n\n cpu->exception_index = EXCP_INTERRUPT;\n\n cpu_loop_exit(cpu);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d718b14b8cc2a28dcf48b68c87f16a36d280c36e", + "length": 558 + }, + { + "index": 7447, + "code": "static void generate_new_codebooks(RoqContext *enc, RoqTempdata *tempData)\n\n{\n\n int i,j;\n\n RoqCodebooks *codebooks = &tempData->codebooks;\n\n int max = enc->width*enc->height/16;\n\n uint8_t mb2[3*4];\n\n roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4);\n\n uint8_t *yuvClusters=av_malloc(sizeof(int)*max*6*4);\n\n int *points = av_malloc(max*6*4*sizeof(int));\n\n int bias;\n\n\n\n /* Subsample YUV data */\n\n create_clusters(enc->frame_to_enc, enc->width, enc->height, yuvClusters);\n\n\n\n /* Cast to integer and apply chroma bias */\n\n for (i=0; inumCB4 = MAX_CBS_4x4;\n\n\n\n tempData->closest_cb2 = av_malloc(max*4*sizeof(int));\n\n\n\n /* Create 2x2 codebooks */\n\n generate_codebook(enc, tempData, points, max*4, enc->cb2x2, 2, MAX_CBS_2x2);\n\n\n\n codebooks->numCB2 = MAX_CBS_2x2;\n\n\n\n /* Unpack 2x2 codebook clusters */\n\n for (i=0; inumCB2; i++)\n\n unpack_roq_cell(enc->cb2x2 + i, codebooks->unpacked_cb2 + i*2*2*3);\n\n\n\n /* Index all 4x4 entries to the 2x2 entries, unpack, and enlarge */\n\n for (i=0; inumCB4; i++) {\n\n for (j=0; j<4; j++) {\n\n unpack_roq_cell(&results4[4*i + j], mb2);\n\n index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2,\n\n &enc->cb4x4[i].idx[j], 2);\n\n }\n\n unpack_roq_qcell(codebooks->unpacked_cb2, enc->cb4x4 + i,\n\n codebooks->unpacked_cb4 + i*4*4*3);\n\n enlarge_roq_mb4(codebooks->unpacked_cb4 + i*4*4*3,\n\n codebooks->unpacked_cb4_enlarged + i*8*8*3);\n\n }\n\n\n\n av_free(yuvClusters);\n\n av_free(points);\n\n av_free(results4);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3beb9cbad35218ed1fb3473eeb3cfc97a931bff4", + "length": 625 + }, + { + "index": 11111, + "code": "static int ioreq_runio_qemu_sync(struct ioreq *ioreq)\n\n{\n\n struct XenBlkDev *blkdev = ioreq->blkdev;\n\n int i, rc, len = 0;\n\n off_t pos;\n\n\n\n if (ioreq->req.nr_segments && ioreq_map(ioreq) == -1)\n\n\tgoto err;\n\n if (ioreq->presync)\n\n\tbdrv_flush(blkdev->bs);\n\n\n\n switch (ioreq->req.operation) {\n\n case BLKIF_OP_READ:\n\n\tpos = ioreq->start;\n\n\tfor (i = 0; i < ioreq->v.niov; i++) {\n\n\t rc = bdrv_read(blkdev->bs, pos / BLOCK_SIZE,\n\n\t\t\t ioreq->v.iov[i].iov_base,\n\n\t\t\t ioreq->v.iov[i].iov_len / BLOCK_SIZE);\n\n\t if (rc != 0) {\n\n\t\txen_be_printf(&blkdev->xendev, 0, \"rd I/O error (%p, len %zd)\\n\",\n\n\t\t\t ioreq->v.iov[i].iov_base,\n\n\t\t\t ioreq->v.iov[i].iov_len);\n\n\t\tgoto err;\n\n\t }\n\n\t len += ioreq->v.iov[i].iov_len;\n\n\t pos += ioreq->v.iov[i].iov_len;\n\n\t}\n\n\tbreak;\n\n case BLKIF_OP_WRITE:\n\n case BLKIF_OP_WRITE_BARRIER:\n\n if (!ioreq->req.nr_segments)\n\n break;\n\n\tpos = ioreq->start;\n\n\tfor (i = 0; i < ioreq->v.niov; i++) {\n\n\t rc = bdrv_write(blkdev->bs, pos / BLOCK_SIZE,\n\n\t\t\t ioreq->v.iov[i].iov_base,\n\n\t\t\t ioreq->v.iov[i].iov_len / BLOCK_SIZE);\n\n\t if (rc != 0) {\n\n\t\txen_be_printf(&blkdev->xendev, 0, \"wr I/O error (%p, len %zd)\\n\",\n\n\t\t\t ioreq->v.iov[i].iov_base,\n\n\t\t\t ioreq->v.iov[i].iov_len);\n\n\t\tgoto err;\n\n\t }\n\n\t len += ioreq->v.iov[i].iov_len;\n\n\t pos += ioreq->v.iov[i].iov_len;\n\n\t}\n\n\tbreak;\n\n default:\n\n\t/* unknown operation (shouldn't happen -- parse catches this) */\n\n\tgoto err;\n\n }\n\n\n\n if (ioreq->postsync)\n\n\tbdrv_flush(blkdev->bs);\n\n ioreq->status = BLKIF_RSP_OKAY;\n\n\n\n ioreq_unmap(ioreq);\n\n ioreq_finish(ioreq);\n\n return 0;\n\n\n\nerr:\n\n ioreq->status = BLKIF_RSP_ERROR;\n\n return -1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "f6ec953ca329d4509e5a1a1ff051365fccdbb6b7", + "length": 603 + }, + { + "index": 12514, + "code": "static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)\n\n{\n\n AVStream *stream = fmt_ctx->streams[stream_idx];\n\n AVCodecContext *dec_ctx;\n\n AVCodec *dec;\n\n char val_str[128];\n\n AVRational display_aspect_ratio;\n\n struct print_buf pbuf = {.s = NULL};\n\n\n\n print_section_header(\"stream\");\n\n\n\n print_int(\"index\", stream->index);\n\n\n\n if ((dec_ctx = stream->codec)) {\n\n if ((dec = dec_ctx->codec)) {\n\n print_str(\"codec_name\", dec->name);\n\n print_str(\"codec_long_name\", dec->long_name);\n\n } else {\n\n print_str(\"codec_name\", \"unknown\");\n\n }\n\n\n\n print_str(\"codec_type\", av_x_if_null(av_get_media_type_string(dec_ctx->codec_type), \"unknown\"));\n\n print_fmt(\"codec_time_base\", \"%d/%d\", dec_ctx->time_base.num, dec_ctx->time_base.den);\n\n\n\n /* print AVI/FourCC tag */\n\n av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);\n\n print_str(\"codec_tag_string\", val_str);\n\n print_fmt(\"codec_tag\", \"0x%04x\", dec_ctx->codec_tag);\n\n\n\n switch (dec_ctx->codec_type) {\n\n case AVMEDIA_TYPE_VIDEO:\n\n print_int(\"width\", dec_ctx->width);\n\n print_int(\"height\", dec_ctx->height);\n\n print_int(\"has_b_frames\", dec_ctx->has_b_frames);\n\n if (dec_ctx->sample_aspect_ratio.num) {\n\n print_fmt(\"sample_aspect_ratio\", \"%d:%d\",\n\n dec_ctx->sample_aspect_ratio.num,\n\n dec_ctx->sample_aspect_ratio.den);\n\n av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,\n\n dec_ctx->width * dec_ctx->sample_aspect_ratio.num,\n\n dec_ctx->height * dec_ctx->sample_aspect_ratio.den,\n\n 1024*1024);\n\n print_fmt(\"display_aspect_ratio\", \"%d:%d\",\n\n display_aspect_ratio.num,\n\n display_aspect_ratio.den);\n\n }\n\n print_str(\"pix_fmt\", av_x_if_null(av_get_pix_fmt_name(dec_ctx->pix_fmt), \"unknown\"));\n\n print_int(\"level\", dec_ctx->level);\n\n break;\n\n\n\n case AVMEDIA_TYPE_AUDIO:\n\n print_str(\"sample_fmt\",\n\n av_x_if_null(av_get_sample_fmt_name(dec_ctx->sample_fmt), \"unknown\"));\n\n print_val(\"sample_rate\", dec_ctx->sample_rate, unit_hertz_str);\n\n print_int(\"channels\", dec_ctx->channels);\n\n print_int(\"bits_per_sample\", av_get_bits_per_sample(dec_ctx->codec_id));\n\n break;\n\n }\n\n } else {\n\n print_str(\"codec_type\", \"unknown\");\n\n }\n\n if (dec_ctx->codec && dec_ctx->codec->priv_class) {\n\n const AVOption *opt = NULL;\n\n while (opt = av_opt_next(dec_ctx->priv_data,opt)) {\n\n uint8_t *str;\n\n if (opt->flags) continue;\n\n if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {\n\n print_str(opt->name, str);\n\n av_free(str);\n\n }\n\n }\n\n }\n\n\n\n if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)\n\n print_fmt(\"id\", \"0x%x\", stream->id);\n\n print_fmt(\"r_frame_rate\", \"%d/%d\", stream->r_frame_rate.num, stream->r_frame_rate.den);\n\n print_fmt(\"avg_frame_rate\", \"%d/%d\", stream->avg_frame_rate.num, stream->avg_frame_rate.den);\n\n print_fmt(\"time_base\", \"%d/%d\", stream->time_base.num, stream->time_base.den);\n\n print_time(\"start_time\", stream->start_time, &stream->time_base);\n\n print_time(\"duration\", stream->duration, &stream->time_base);\n\n if (stream->nb_frames)\n\n print_fmt(\"nb_frames\", \"%\"PRId64, stream->nb_frames);\n\n\n\n show_tags(stream->metadata);\n\n\n\n print_section_footer(\"stream\");\n\n av_free(pbuf.s);\n\n fflush(stdout);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "0491a2a07a44f6e5e6f34081835e402c07025fd2", + "length": 903 + }, + { + "index": 3288, + "code": "static void tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,\n\n int s_bits, int tlb_offset)\n\n{\n\n TCGReg base = TCG_AREG0;\n\n\n\n /* Should generate something like the following:\n\n * pre-v7:\n\n * shr tmp, addr_reg, #TARGET_PAGE_BITS (1)\n\n * add r2, env, #off & 0xff00\n\n * and r0, tmp, #(CPU_TLB_SIZE - 1) (2)\n\n * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS (3)\n\n * ldr r0, [r2, #off & 0xff]! (4)\n\n * tst addr_reg, #s_mask\n\n * cmpeq r0, tmp, lsl #TARGET_PAGE_BITS (5)\n\n *\n\n * v7 (not implemented yet):\n\n * ubfx r2, addr_reg, #TARGET_PAGE_BITS, #CPU_TLB_BITS (1)\n\n * movw tmp, #~TARGET_PAGE_MASK & ~s_mask\n\n * movw r0, #off\n\n * add r2, env, r2, lsl #CPU_TLB_ENTRY_BITS (2)\n\n * bic tmp, addr_reg, tmp\n\n * ldr r0, [r2, r0]! (3)\n\n * cmp r0, tmp (4)\n\n */\n\n# if CPU_TLB_BITS > 8\n\n# error\n\n# endif\n\n tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP,\n\n 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS));\n\n\n\n /* We assume that the offset is contained within 16 bits. */\n\n assert((tlb_offset & ~0xffff) == 0);\n\n if (tlb_offset > 0xff) {\n\n tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R2, base,\n\n (24 << 7) | (tlb_offset >> 8));\n\n tlb_offset &= 0xff;\n\n base = TCG_REG_R2;\n\n }\n\n\n\n tcg_out_dat_imm(s, COND_AL, ARITH_AND,\n\n TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1);\n\n tcg_out_dat_reg(s, COND_AL, ARITH_ADD, TCG_REG_R2, base,\n\n TCG_REG_R0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS));\n\n\n\n /* Load the tlb comparator. Use ldrd if needed and available,\n\n but due to how the pointer needs setting up, ldm isn't useful.\n\n Base arm5 doesn't have ldrd, but armv5te does. */\n\n if (use_armv6_instructions && TARGET_LONG_BITS == 64) {\n\n tcg_out_memop_8(s, COND_AL, INSN_LDRD_IMM, TCG_REG_R0,\n\n TCG_REG_R2, tlb_offset, 1, 1);\n\n } else {\n\n tcg_out_memop_12(s, COND_AL, INSN_LDR_IMM, TCG_REG_R0,\n\n TCG_REG_R2, tlb_offset, 1, 1);\n\n if (TARGET_LONG_BITS == 64) {\n\n tcg_out_memop_12(s, COND_AL, INSN_LDR_IMM, TCG_REG_R1,\n\n TCG_REG_R2, 4, 1, 0);\n\n }\n\n }\n\n\n\n /* Check alignment. */\n\n if (s_bits) {\n\n tcg_out_dat_imm(s, COND_AL, ARITH_TST,\n\n 0, addrlo, (1 << s_bits) - 1);\n\n }\n\n\n\n tcg_out_dat_reg(s, (s_bits ? COND_EQ : COND_AL), ARITH_CMP, 0,\n\n TCG_REG_R0, TCG_REG_TMP, SHIFT_IMM_LSL(TARGET_PAGE_BITS));\n\n\n\n if (TARGET_LONG_BITS == 64) {\n\n tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,\n\n TCG_REG_R1, addrhi, SHIFT_IMM_LSL(0));\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "f2488736371ae902f345cf9270d141f0a6797731", + "length": 956 + }, + { + "index": 25177, + "code": "void net_check_clients(void)\n\n{\n\n VLANState *vlan;\n\n VLANClientState *vc;\n\n int i;\n\n\n\n /* Don't warn about the default network setup that you get if\n\n * no command line -net or -netdev options are specified. There\n\n * are two cases that we would otherwise complain about:\n\n * (1) board doesn't support a NIC but the implicit \"-net nic\"\n\n * requested one\n\n * (2) CONFIG_SLIRP not set, in which case the implicit \"-net nic\"\n\n * sets up a nic that isn't connected to anything.\n\n */\n\n if (default_net) {\n\n return;\n\n }\n\n\n\n QTAILQ_FOREACH(vlan, &vlans, next) {\n\n int has_nic = 0, has_host_dev = 0;\n\n\n\n QTAILQ_FOREACH(vc, &vlan->clients, next) {\n\n switch (vc->info->type) {\n\n case NET_CLIENT_OPTIONS_KIND_NIC:\n\n has_nic = 1;\n\n break;\n\n case NET_CLIENT_OPTIONS_KIND_USER:\n\n case NET_CLIENT_OPTIONS_KIND_TAP:\n\n case NET_CLIENT_OPTIONS_KIND_SOCKET:\n\n case NET_CLIENT_OPTIONS_KIND_VDE:\n\n has_host_dev = 1;\n\n break;\n\n default: ;\n\n }\n\n }\n\n if (has_host_dev && !has_nic)\n\n fprintf(stderr, \"Warning: vlan %d with no nics\\n\", vlan->id);\n\n if (has_nic && !has_host_dev)\n\n fprintf(stderr,\n\n \"Warning: vlan %d is not connected to host network\\n\",\n\n vlan->id);\n\n }\n\n QTAILQ_FOREACH(vc, &non_vlan_clients, next) {\n\n if (!vc->peer) {\n\n fprintf(stderr, \"Warning: %s %s has no peer\\n\",\n\n vc->info->type == NET_CLIENT_OPTIONS_KIND_NIC ? \"nic\" : \"netdev\",\n\n vc->name);\n\n }\n\n }\n\n\n\n /* Check that all NICs requested via -net nic actually got created.\n\n * NICs created via -device don't need to be checked here because\n\n * they are always instantiated.\n\n */\n\n for (i = 0; i < MAX_NICS; i++) {\n\n NICInfo *nd = &nd_table[i];\n\n if (nd->used && !nd->instantiated) {\n\n fprintf(stderr, \"Warning: requested NIC (%s, model %s) \"\n\n \"was not created (not supported by this machine?)\\n\",\n\n nd->name ? nd->name : \"anonymous\",\n\n nd->model ? nd->model : \"unspecified\");\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "81017645e45bcb0b4d985e900c501f92f2c6fb60", + "length": 555 + }, + { + "index": 14070, + "code": "static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)\n\n{\n\n VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev);\n\n CcwDevice *ccw_dev = CCW_DEVICE(dev);\n\n CCWDeviceClass *ck = CCW_DEVICE_GET_CLASS(ccw_dev);\n\n DeviceState *parent = DEVICE(ccw_dev);\n\n BusState *qbus = qdev_get_parent_bus(parent);\n\n VirtualCssBus *cbus = VIRTUAL_CSS_BUS(qbus);\n\n SubchDev *sch;\n\n Error *err = NULL;\n\n\n\n sch = css_create_sch(ccw_dev->devno, true, cbus->squash_mcss, errp);\n\n if (!sch) {\n\n return;\n\n }\n\n if (!virtio_ccw_rev_max(dev) && dev->force_revision_1) {\n\n error_setg(&err, \"Invalid value of property max_rev \"\n\n \"(is %d expected >= 1)\", virtio_ccw_rev_max(dev));\n\n goto out_err;\n\n }\n\n\n\n sch->driver_data = dev;\n\n sch->ccw_cb = virtio_ccw_cb;\n\n sch->disable_cb = virtio_sch_disable_cb;\n\n sch->id.reserved = 0xff;\n\n sch->id.cu_type = VIRTIO_CCW_CU_TYPE;\n\n sch->do_subchannel_work = do_subchannel_work_virtual;\n\n ccw_dev->sch = sch;\n\n dev->indicators = NULL;\n\n dev->revision = -1;\n\n css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);\n\n\n\n trace_virtio_ccw_new_device(\n\n sch->cssid, sch->ssid, sch->schid, sch->devno,\n\n ccw_dev->devno.valid ? \"user-configured\" : \"auto-configured\");\n\n\n\n if (!kvm_eventfds_enabled()) {\n\n dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;\n\n }\n\n\n\n if (k->realize) {\n\n k->realize(dev, &err);\n\n if (err) {\n\n goto out_err;\n\n }\n\n }\n\n\n\n ck->realize(ccw_dev, &err);\n\n if (err) {\n\n goto out_err;\n\n }\n\n\n\n return;\n\n\n\nout_err:\n\n error_propagate(errp, err);\n\n css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);\n\n ccw_dev->sch = NULL;\n\n g_free(sch);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "cda3c19ff56d1b567631ce17f7a3bdb47cfa9455", + "length": 550 + }, + { + "index": 17155, + "code": "static void xilinx_spips_write(void *opaque, hwaddr addr,\n\n uint64_t value, unsigned size)\n\n{\n\n int mask = ~0;\n\n int man_start_com = 0;\n\n XilinxSPIPS *s = opaque;\n\n\n\n DB_PRINT(\"addr=\" TARGET_FMT_plx \" = %x\\n\", addr, (unsigned)value);\n\n addr >>= 2;\n\n switch (addr) {\n\n case R_CONFIG:\n\n mask = 0x0002FFFF;\n\n if (value & MAN_START_COM) {\n\n man_start_com = 1;\n\n }\n\n break;\n\n case R_INTR_STATUS:\n\n mask = IXR_ALL;\n\n s->regs[R_INTR_STATUS] &= ~(mask & value);\n\n goto no_reg_update;\n\n case R_INTR_DIS:\n\n mask = IXR_ALL;\n\n s->regs[R_INTR_MASK] &= ~(mask & value);\n\n goto no_reg_update;\n\n case R_INTR_EN:\n\n mask = IXR_ALL;\n\n s->regs[R_INTR_MASK] |= mask & value;\n\n goto no_reg_update;\n\n case R_EN:\n\n mask = 0x1;\n\n break;\n\n case R_SLAVE_IDLE_COUNT:\n\n mask = 0xFF;\n\n break;\n\n case R_RX_DATA:\n\n case R_INTR_MASK:\n\n case R_MOD_ID:\n\n mask = 0;\n\n break;\n\n case R_TX_DATA:\n\n tx_data_bytes(s, (uint32_t)value, s->num_txrx_bytes);\n\n goto no_reg_update;\n\n case R_TXD1:\n\n tx_data_bytes(s, (uint32_t)value, 1);\n\n goto no_reg_update;\n\n case R_TXD2:\n\n tx_data_bytes(s, (uint32_t)value, 2);\n\n goto no_reg_update;\n\n case R_TXD3:\n\n tx_data_bytes(s, (uint32_t)value, 3);\n\n goto no_reg_update;\n\n }\n\n s->regs[addr] = (s->regs[addr] & ~mask) | (value & mask);\n\nno_reg_update:\n\n xilinx_spips_update_cs_lines(s);\n\n if ((man_start_com && s->regs[R_CONFIG] & MAN_START_EN) ||\n\n (fifo8_is_empty(&s->tx_fifo) && s->regs[R_CONFIG] & MAN_START_EN)) {\n\n xilinx_spips_flush_txfifo(s);\n\n }\n\n xilinx_spips_update_cs_lines(s);\n\n xilinx_spips_update_ixr(s);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "2133a5f6b8f8941a6a3734c6c1990656553de76c", + "length": 517 + }, + { + "index": 1321, + "code": "static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)\n\n{\n\n Error *local_err = NULL;\n\n BDRVSheepdogState *s = bs->opaque;\n\n int ret, fd;\n\n uint32_t new_vid;\n\n SheepdogInode *inode;\n\n unsigned int datalen;\n\n\n\n DPRINTF(\"sn_info: name %s id_str %s s: name %s vm_state_size %\" PRId64 \" \"\n\n \"is_snapshot %d\\n\", sn_info->name, sn_info->id_str,\n\n s->name, sn_info->vm_state_size, s->is_snapshot);\n\n\n\n if (s->is_snapshot) {\n\n error_report(\"You can't create a snapshot of a snapshot VDI, \"\n\n \"%s (%\" PRIu32 \").\", s->name, s->inode.vdi_id);\n\n\n\n return -EINVAL;\n\n }\n\n\n\n DPRINTF(\"%s %s\\n\", sn_info->name, sn_info->id_str);\n\n\n\n s->inode.vm_state_size = sn_info->vm_state_size;\n\n s->inode.vm_clock_nsec = sn_info->vm_clock_nsec;\n\n /* It appears that inode.tag does not require a NUL terminator,\n\n * which means this use of strncpy is ok.\n\n */\n\n strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag));\n\n /* we don't need to update entire object */\n\n datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);\n\n\n\n /* refresh inode. */\n\n fd = connect_to_sdog(s, &local_err);\n\n if (fd < 0) {\n\n error_report(\"%s\", error_get_pretty(local_err));;\n\n error_free(local_err);\n\n ret = fd;\n\n goto cleanup;\n\n }\n\n\n\n ret = write_object(fd, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),\n\n s->inode.nr_copies, datalen, 0, false, s->cache_flags);\n\n if (ret < 0) {\n\n error_report(\"failed to write snapshot's inode.\");\n\n goto cleanup;\n\n }\n\n\n\n ret = do_sd_create(s, &new_vid, 1, &local_err);\n\n if (ret < 0) {\n\n error_report(\"%s\", error_get_pretty(local_err));;\n\n error_free(local_err);\n\n error_report(\"failed to create inode for snapshot. %s\",\n\n strerror(errno));\n\n goto cleanup;\n\n }\n\n\n\n inode = (SheepdogInode *)g_malloc(datalen);\n\n\n\n ret = read_object(fd, (char *)inode, vid_to_vdi_oid(new_vid),\n\n s->inode.nr_copies, datalen, 0, s->cache_flags);\n\n\n\n if (ret < 0) {\n\n error_report(\"failed to read new inode info. %s\", strerror(errno));\n\n goto cleanup;\n\n }\n\n\n\n memcpy(&s->inode, inode, datalen);\n\n DPRINTF(\"s->inode: name %s snap_id %x oid %x\\n\",\n\n s->inode.name, s->inode.snap_id, s->inode.vdi_id);\n\n\n\ncleanup:\n\n closesocket(fd);\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "2df5fee2dbd56a9c34afd6d7df6744da2d951ccb", + "length": 668 + }, + { + "index": 9518, + "code": "ssize_t iov_send_recv(int sockfd, struct iovec *iov,\n\n size_t offset, size_t bytes,\n\n bool do_sendv)\n\n{\n\n int iovlen;\n\n ssize_t ret;\n\n size_t diff;\n\n struct iovec *last_iov;\n\n\n\n /* last_iov is inclusive, so count from one. */\n\n iovlen = 1;\n\n last_iov = iov;\n\n bytes += offset;\n\n\n\n while (last_iov->iov_len < bytes) {\n\n bytes -= last_iov->iov_len;\n\n\n\n last_iov++;\n\n iovlen++;\n\n }\n\n\n\n diff = last_iov->iov_len - bytes;\n\n last_iov->iov_len -= diff;\n\n\n\n while (iov->iov_len <= offset) {\n\n offset -= iov->iov_len;\n\n\n\n iov++;\n\n iovlen--;\n\n }\n\n\n\n iov->iov_base = (char *) iov->iov_base + offset;\n\n iov->iov_len -= offset;\n\n\n\n {\n\n#if defined CONFIG_IOVEC && defined CONFIG_POSIX\n\n struct msghdr msg;\n\n memset(&msg, 0, sizeof(msg));\n\n msg.msg_iov = iov;\n\n msg.msg_iovlen = iovlen;\n\n\n\n do {\n\n if (do_sendv) {\n\n ret = sendmsg(sockfd, &msg, 0);\n\n } else {\n\n ret = recvmsg(sockfd, &msg, 0);\n\n }\n\n } while (ret == -1 && errno == EINTR);\n\n#else\n\n struct iovec *p = iov;\n\n ret = 0;\n\n while (iovlen > 0) {\n\n int rc;\n\n if (do_sendv) {\n\n rc = send(sockfd, p->iov_base, p->iov_len, 0);\n\n } else {\n\n rc = qemu_recv(sockfd, p->iov_base, p->iov_len, 0);\n\n }\n\n if (rc == -1) {\n\n if (errno == EINTR) {\n\n continue;\n\n }\n\n if (ret == 0) {\n\n ret = -1;\n\n }\n\n break;\n\n }\n\n if (rc == 0) {\n\n break;\n\n }\n\n ret += rc;\n\n iovlen--, p++;\n\n }\n\n#endif\n\n }\n\n\n\n /* Undo the changes above */\n\n iov->iov_base = (char *) iov->iov_base - offset;\n\n iov->iov_len += offset;\n\n last_iov->iov_len += diff;\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "25e5e4c7e9d5ec3e95c9526d1abaca40ada50ab0", + "length": 512 + }, + { + "index": 22100, + "code": "static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n BDRVRBDState *s = bs->opaque;\n\n char pool[RBD_MAX_POOL_NAME_SIZE];\n\n char snap_buf[RBD_MAX_SNAP_NAME_SIZE];\n\n char conf[RBD_MAX_CONF_SIZE];\n\n char clientname_buf[RBD_MAX_CONF_SIZE];\n\n char *clientname;\n\n QemuOpts *opts;\n\n Error *local_err = NULL;\n\n const char *filename;\n\n int r;\n\n\n\n opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);\n\n qemu_opts_absorb_qdict(opts, options, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n qemu_opts_del(opts);\n\n return -EINVAL;\n\n }\n\n\n\n filename = qemu_opt_get(opts, \"filename\");\n\n\n\n if (qemu_rbd_parsename(filename, pool, sizeof(pool),\n\n snap_buf, sizeof(snap_buf),\n\n s->name, sizeof(s->name),\n\n conf, sizeof(conf), errp) < 0) {\n\n r = -EINVAL;\n\n goto failed_opts;\n\n }\n\n\n\n clientname = qemu_rbd_parse_clientname(conf, clientname_buf);\n\n r = rados_create(&s->cluster, clientname);\n\n if (r < 0) {\n\n error_setg(errp, \"error initializing\");\n\n goto failed_opts;\n\n }\n\n\n\n s->snap = NULL;\n\n if (snap_buf[0] != '\\0') {\n\n s->snap = g_strdup(snap_buf);\n\n }\n\n\n\n /*\n\n * Fallback to more conservative semantics if setting cache\n\n * options fails. Ignore errors from setting rbd_cache because the\n\n * only possible error is that the option does not exist, and\n\n * librbd defaults to no caching. If write through caching cannot\n\n * be set up, fall back to no caching.\n\n */\n\n if (flags & BDRV_O_NOCACHE) {\n\n rados_conf_set(s->cluster, \"rbd_cache\", \"false\");\n\n } else {\n\n rados_conf_set(s->cluster, \"rbd_cache\", \"true\");\n\n }\n\n\n\n if (strstr(conf, \"conf=\") == NULL) {\n\n /* try default location, but ignore failure */\n\n rados_conf_read_file(s->cluster, NULL);\n\n }\n\n\n\n if (conf[0] != '\\0') {\n\n r = qemu_rbd_set_conf(s->cluster, conf, errp);\n\n if (r < 0) {\n\n goto failed_shutdown;\n\n }\n\n }\n\n\n\n r = rados_connect(s->cluster);\n\n if (r < 0) {\n\n error_setg(errp, \"error connecting\");\n\n goto failed_shutdown;\n\n }\n\n\n\n r = rados_ioctx_create(s->cluster, pool, &s->io_ctx);\n\n if (r < 0) {\n\n error_setg(errp, \"error opening pool %s\", pool);\n\n goto failed_shutdown;\n\n }\n\n\n\n r = rbd_open(s->io_ctx, s->name, &s->image, s->snap);\n\n if (r < 0) {\n\n error_setg(errp, \"error reading header from %s\", s->name);\n\n goto failed_open;\n\n }\n\n\n\n bs->read_only = (s->snap != NULL);\n\n\n\n qemu_opts_del(opts);\n\n return 0;\n\n\n\nfailed_open:\n\n rados_ioctx_destroy(s->io_ctx);\n\nfailed_shutdown:\n\n rados_shutdown(s->cluster);\n\n g_free(s->snap);\n\nfailed_opts:\n\n qemu_opts_del(opts);\n\n return r;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "99a3c89d5d538dc6c360e35dffb797cfe06e9cda", + "length": 772 + }, + { + "index": 875, + "code": "static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size)\n\n{\n\n uint16_t flags;\n\n uint8_t type;\n\n\n\n flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);\n\n type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;\n\n\n\n if (type != PCI_EXP_TYPE_ENDPOINT &&\n\n type != PCI_EXP_TYPE_LEG_END &&\n\n type != PCI_EXP_TYPE_RC_END) {\n\n\n\n error_report(\"vfio: Assignment of PCIe type 0x%x \"\n\n \"devices is not currently supported\", type);\n\n return -EINVAL;\n\n }\n\n\n\n if (!pci_bus_is_express(vdev->pdev.bus)) {\n\n /*\n\n * Use express capability as-is on PCI bus. It doesn't make much\n\n * sense to even expose, but some drivers (ex. tg3) depend on it\n\n * and guests don't seem to be particular about it. We'll need\n\n * to revist this or force express devices to express buses if we\n\n * ever expose an IOMMU to the guest.\n\n */\n\n } else if (pci_bus_is_root(vdev->pdev.bus)) {\n\n /*\n\n * On a Root Complex bus Endpoints become Root Complex Integrated\n\n * Endpoints, which changes the type and clears the LNK & LNK2 fields.\n\n */\n\n if (type == PCI_EXP_TYPE_ENDPOINT) {\n\n vfio_add_emulated_word(vdev, pos + PCI_CAP_FLAGS,\n\n PCI_EXP_TYPE_RC_END << 4,\n\n PCI_EXP_FLAGS_TYPE);\n\n\n\n /* Link Capabilities, Status, and Control goes away */\n\n if (size > PCI_EXP_LNKCTL) {\n\n vfio_add_emulated_long(vdev, pos + PCI_EXP_LNKCAP, 0, ~0);\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKCTL, 0, ~0);\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKSTA, 0, ~0);\n\n\n\n#ifndef PCI_EXP_LNKCAP2\n\n#define PCI_EXP_LNKCAP2 44\n\n#endif\n\n#ifndef PCI_EXP_LNKSTA2\n\n#define PCI_EXP_LNKSTA2 50\n\n#endif\n\n /* Link 2 Capabilities, Status, and Control goes away */\n\n if (size > PCI_EXP_LNKCAP2) {\n\n vfio_add_emulated_long(vdev, pos + PCI_EXP_LNKCAP2, 0, ~0);\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKCTL2, 0, ~0);\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKSTA2, 0, ~0);\n\n }\n\n }\n\n\n\n } else if (type == PCI_EXP_TYPE_LEG_END) {\n\n /*\n\n * Legacy endpoints don't belong on the root complex. Windows\n\n * seems to be happier with devices if we skip the capability.\n\n */\n\n return 0;\n\n }\n\n\n\n } else {\n\n /*\n\n * Convert Root Complex Integrated Endpoints to regular endpoints.\n\n * These devices don't support LNK/LNK2 capabilities, so make them up.\n\n */\n\n if (type == PCI_EXP_TYPE_RC_END) {\n\n vfio_add_emulated_word(vdev, pos + PCI_CAP_FLAGS,\n\n PCI_EXP_TYPE_ENDPOINT << 4,\n\n PCI_EXP_FLAGS_TYPE);\n\n vfio_add_emulated_long(vdev, pos + PCI_EXP_LNKCAP,\n\n PCI_EXP_LNK_MLW_1 | PCI_EXP_LNK_LS_25, ~0);\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKCTL, 0, ~0);\n\n }\n\n\n\n /* Mark the Link Status bits as emulated to allow virtual negotiation */\n\n vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKSTA,\n\n pci_get_word(vdev->pdev.config + pos +\n\n PCI_EXP_LNKSTA),\n\n PCI_EXP_LNKCAP_MLW | PCI_EXP_LNKCAP_SLS);\n\n }\n\n\n\n pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size);\n\n if (pos >= 0) {\n\n vdev->pdev.exp.exp_cap = pos;\n\n }\n\n\n\n return pos;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "0282abf078c3353a178ab77a115828ce333181dd", + "length": 906 + }, + { + "index": 13834, + "code": "int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,\n\n int *got_picture_ptr,\n\n const AVPacket *avpkt)\n\n{\n\n int ret;\n\n // copy to ensure we do not change avpkt\n\n AVPacket tmp = *avpkt;\n\n\n\n if (avctx->codec->type != AVMEDIA_TYPE_VIDEO) {\n\n av_log(avctx, AV_LOG_ERROR, \"Invalid media type for video\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n *got_picture_ptr= 0;\n\n if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))\n\n return -1;\n\n\n\n if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){\n\n int did_split = av_packet_split_side_data(&tmp);\n\n apply_param_change(avctx, &tmp);\n\n avctx->pkt = &tmp;\n\n if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)\n\n ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,\n\n &tmp);\n\n else {\n\n ret = avctx->codec->decode(avctx, picture, got_picture_ptr,\n\n &tmp);\n\n picture->pkt_dts= avpkt->dts;\n\n\n\n if(!avctx->has_b_frames){\n\n picture->pkt_pos= avpkt->pos;\n\n }\n\n //FIXME these should be under if(!avctx->has_b_frames)\n\n if (!picture->sample_aspect_ratio.num)\n\n picture->sample_aspect_ratio = avctx->sample_aspect_ratio;\n\n if (!picture->width)\n\n picture->width = avctx->width;\n\n if (!picture->height)\n\n picture->height = avctx->height;\n\n if (picture->format == PIX_FMT_NONE)\n\n picture->format = avctx->pix_fmt;\n\n }\n\n\n\n emms_c(); //needed to avoid an emms_c() call before every return;\n\n\n\n avctx->pkt = NULL;\n\n if (did_split) {\n\n ff_packet_free_side_data(&tmp);\n\n if(ret == tmp.size)\n\n ret = avpkt->size;\n\n }\n\n\n\n if (*got_picture_ptr){\n\n avctx->frame_number++;\n\n picture->best_effort_timestamp = guess_correct_pts(avctx,\n\n picture->pkt_pts,\n\n picture->pkt_dts);\n\n }\n\n }else\n\n ret= 0;\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3cc1a8988112896e302c96f9df8839d983677891", + "length": 539 + }, + { + "index": 19033, + "code": "static int wsvqa_read_header(AVFormatContext *s)\n\n{\n\n WsVqaDemuxContext *wsvqa = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n AVStream *st;\n\n unsigned char *header;\n\n unsigned char scratch[VQA_PREAMBLE_SIZE];\n\n unsigned int chunk_tag;\n\n unsigned int chunk_size;\n\n int fps;\n\n\n\n /* initialize the video decoder stream */\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n st->start_time = 0;\n\n wsvqa->video_stream_index = st->index;\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_id = AV_CODEC_ID_WS_VQA;\n\n st->codec->codec_tag = 0; /* no fourcc */\n\n\n\n /* skip to the start of the VQA header */\n\n avio_seek(pb, 20, SEEK_SET);\n\n\n\n /* the VQA header needs to go to the decoder */\n\n st->codec->extradata_size = VQA_HEADER_SIZE;\n\n st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);\n\n header = (unsigned char *)st->codec->extradata;\n\n if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) !=\n\n VQA_HEADER_SIZE) {\n\n av_free(st->codec->extradata);\n\n return AVERROR(EIO);\n\n }\n\n st->codec->width = AV_RL16(&header[6]);\n\n st->codec->height = AV_RL16(&header[8]);\n\n fps = header[12];\n\n st->nb_frames =\n\n st->duration = AV_RL16(&header[4]);\n\n if (fps < 1 || fps > 30) {\n\n av_log(s, AV_LOG_ERROR, \"invalid fps: %d\\n\", fps);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avpriv_set_pts_info(st, 64, 1, fps);\n\n\n\n wsvqa->version = AV_RL16(&header[ 0]);\n\n wsvqa->sample_rate = AV_RL16(&header[24]);\n\n wsvqa->channels = header[26];\n\n wsvqa->bps = header[27];\n\n wsvqa->audio_stream_index = -1;\n\n\n\n s->ctx_flags |= AVFMTCTX_NOHEADER;\n\n\n\n /* there are 0 or more chunks before the FINF chunk; iterate until\n\n * FINF has been skipped and the file will be ready to be demuxed */\n\n do {\n\n if (avio_read(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE)\n\n return AVERROR(EIO);\n\n chunk_tag = AV_RB32(&scratch[0]);\n\n chunk_size = AV_RB32(&scratch[4]);\n\n\n\n /* catch any unknown header tags, for curiousity */\n\n switch (chunk_tag) {\n\n case CINF_TAG:\n\n case CINH_TAG:\n\n case CIND_TAG:\n\n case PINF_TAG:\n\n case PINH_TAG:\n\n case PIND_TAG:\n\n case FINF_TAG:\n\n case CMDS_TAG:\n\n break;\n\n\n\n default:\n\n av_log (s, AV_LOG_ERROR, \" note: unknown chunk seen (%c%c%c%c)\\n\",\n\n scratch[0], scratch[1],\n\n scratch[2], scratch[3]);\n\n break;\n\n }\n\n\n\n avio_skip(pb, chunk_size);\n\n } while (chunk_tag != FINF_TAG);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e1b0d3a389ff7050c66f43891539200eddf4af15", + "length": 765 + }, + { + "index": 24638, + "code": "static av_cold int j2kenc_init(AVCodecContext *avctx)\n\n{\n\n int i, ret;\n\n Jpeg2000EncoderContext *s = avctx->priv_data;\n\n Jpeg2000CodingStyle *codsty = &s->codsty;\n\n Jpeg2000QuantStyle *qntsty = &s->qntsty;\n\n\n\n s->avctx = avctx;\n\n av_log(s->avctx, AV_LOG_DEBUG, \"init\\n\");\n\n\n\n // defaults:\n\n // TODO: implement setting non-standard precinct size\n\n memset(codsty->log2_prec_widths , 15, sizeof(codsty->log2_prec_widths ));\n\n memset(codsty->log2_prec_heights, 15, sizeof(codsty->log2_prec_heights));\n\n codsty->nreslevels2decode=\n\n codsty->nreslevels = 7;\n\n codsty->log2_cblk_width = 4;\n\n codsty->log2_cblk_height = 4;\n\n codsty->transform = avctx->prediction_method ? FF_DWT53 : FF_DWT97_INT;\n\n\n\n qntsty->nguardbits = 1;\n\n\n\n s->tile_width = 256;\n\n s->tile_height = 256;\n\n\n\n if (codsty->transform == FF_DWT53)\n\n qntsty->quantsty = JPEG2000_QSTY_NONE;\n\n else\n\n qntsty->quantsty = JPEG2000_QSTY_SE;\n\n\n\n s->width = avctx->width;\n\n s->height = avctx->height;\n\n\n\n for (i = 0; i < 3; i++)\n\n s->cbps[i] = 8;\n\n\n\n if (avctx->pix_fmt == AV_PIX_FMT_RGB24){\n\n s->ncomponents = 3;\n\n } else if (avctx->pix_fmt == AV_PIX_FMT_GRAY8){\n\n s->ncomponents = 1;\n\n } else{ // planar YUV\n\n s->planar = 1;\n\n s->ncomponents = 3;\n\n avcodec_get_chroma_sub_sample(avctx->pix_fmt,\n\n s->chroma_shift, s->chroma_shift + 1);\n\n }\n\n\n\n ff_jpeg2000_init_tier1_luts();\n\n ff_mqc_init_context_tables();\n\n init_luts();\n\n\n\n init_quantization(s);\n\n if (ret=init_tiles(s))\n\n return ret;\n\n\n\n av_log(s->avctx, AV_LOG_DEBUG, \"after init\\n\");\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "2580bae54a45d6aaf85ddc5e780389e7e90b2c86", + "length": 552 + }, + { + "index": 16814, + "code": "static int aio_write_f(BlockBackend *blk, int argc, char **argv)\n\n{\n\n int nr_iov, c;\n\n int pattern = 0xcd;\n\n struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);\n\n int flags = 0;\n\n\n\n ctx->blk = blk;\n\n while ((c = getopt(argc, argv, \"CfqP:uz\")) != -1) {\n\n switch (c) {\n\n case 'C':\n\n ctx->Cflag = true;\n\n break;\n\n case 'f':\n\n flags |= BDRV_REQ_FUA;\n\n break;\n\n case 'q':\n\n ctx->qflag = true;\n\n break;\n\n case 'u':\n\n flags |= BDRV_REQ_MAY_UNMAP;\n\n break;\n\n case 'P':\n\n pattern = parse_pattern(optarg);\n\n if (pattern < 0) {\n\n g_free(ctx);\n\n return 0;\n\n }\n\n break;\n\n case 'z':\n\n ctx->zflag = true;\n\n break;\n\n default:\n\n g_free(ctx);\n\n return qemuio_command_usage(&aio_write_cmd);\n\n }\n\n }\n\n\n\n if (optind > argc - 2) {\n\n g_free(ctx);\n\n return qemuio_command_usage(&aio_write_cmd);\n\n }\n\n\n\n if (ctx->zflag && optind != argc - 2) {\n\n printf(\"-z supports only a single length parameter\\n\");\n\n g_free(ctx);\n\n return 0;\n\n }\n\n\n\n if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {\n\n printf(\"-u requires -z to be specified\\n\");\n\n g_free(ctx);\n\n return 0;\n\n }\n\n\n\n if (ctx->zflag && ctx->Pflag) {\n\n printf(\"-z and -P cannot be specified at the same time\\n\");\n\n g_free(ctx);\n\n return 0;\n\n }\n\n\n\n ctx->offset = cvtnum(argv[optind]);\n\n if (ctx->offset < 0) {\n\n print_cvtnum_err(ctx->offset, argv[optind]);\n\n g_free(ctx);\n\n return 0;\n\n }\n\n optind++;\n\n\n\n if (ctx->zflag) {\n\n int64_t count = cvtnum(argv[optind]);\n\n if (count < 0) {\n\n print_cvtnum_err(count, argv[optind]);\n\n g_free(ctx);\n\n return 0;\n\n }\n\n\n\n ctx->qiov.size = count;\n\n blk_aio_write_zeroes(blk, ctx->offset, count, flags, aio_write_done,\n\n ctx);\n\n } else {\n\n nr_iov = argc - optind;\n\n ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov,\n\n pattern);\n\n if (ctx->buf == NULL) {\n\n block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);\n\n g_free(ctx);\n\n return 0;\n\n }\n\n\n\n gettimeofday(&ctx->t1, NULL);\n\n block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,\n\n BLOCK_ACCT_WRITE);\n\n\n\n blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_done,\n\n ctx);\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "37546ff28fb89744ebf2223db22cbc253592abe1", + "length": 696 + }, + { + "index": 18522, + "code": "static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)\n\n{\n\n MpegTSContext *ts = filter->u.section_filter.opaque;\n\n MpegTSSectionFilter *tssf = &filter->u.section_filter;\n\n SectionHeader h1, *h = &h1;\n\n const uint8_t *p, *p_end;\n\n int sid, pmt_pid;\n\n AVProgram *program;\n\n\n\n av_log(ts->stream, AV_LOG_TRACE, \"PAT:\\n\");\n\n hex_dump_debug(ts->stream, section, section_len);\n\n\n\n p_end = section + section_len - 4;\n\n p = section;\n\n if (parse_section_header(h, &p, p_end) < 0)\n\n return;\n\n if (h->tid != PAT_TID)\n\n return;\n\n if (ts->skip_changes)\n\n return;\n\n\n\n if (h->version == tssf->last_ver)\n\n return;\n\n tssf->last_ver = h->version;\n\n ts->stream->ts_id = h->id;\n\n\n\n clear_programs(ts);\n\n for (;;) {\n\n sid = get16(&p, p_end);\n\n if (sid < 0)\n\n break;\n\n pmt_pid = get16(&p, p_end);\n\n if (pmt_pid < 0)\n\n break;\n\n pmt_pid &= 0x1fff;\n\n\n\n if (pmt_pid == ts->current_pid)\n\n break;\n\n\n\n av_log(ts->stream, AV_LOG_TRACE, \"sid=0x%x pid=0x%x\\n\", sid, pmt_pid);\n\n\n\n if (sid == 0x0000) {\n\n /* NIT info */\n\n } else {\n\n MpegTSFilter *fil = ts->pids[pmt_pid];\n\n program = av_new_program(ts->stream, sid);\n\n if (program) {\n\n program->program_num = sid;\n\n program->pmt_pid = pmt_pid;\n\n }\n\n if (fil)\n\n if ( fil->type != MPEGTS_SECTION\n\n || fil->pid != pmt_pid\n\n || fil->u.section_filter.section_cb != pmt_cb)\n\n mpegts_close_filter(ts, ts->pids[pmt_pid]);\n\n\n\n if (!ts->pids[pmt_pid])\n\n mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1);\n\n add_pat_entry(ts, sid);\n\n add_pid_to_pmt(ts, sid, 0); // add pat pid to program\n\n add_pid_to_pmt(ts, sid, pmt_pid);\n\n }\n\n }\n\n\n\n if (sid < 0) {\n\n int i,j;\n\n for (j=0; jstream->nb_programs; j++) {\n\n for (i = 0; i < ts->nb_prg; i++)\n\n if (ts->prg[i].id == ts->stream->programs[j]->id)\n\n break;\n\n if (i==ts->nb_prg && !ts->skip_clear)\n\n clear_avprogram(ts, ts->stream->programs[j]->id);\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "4e8d01f20ce82b49f47c704a461c5d30866affaf", + "length": 670 + }, + { + "index": 8525, + "code": "static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,\n\n int index, const int type)\n\n{\n\n static const uint8_t *const scan_patterns[4] =\n\n { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };\n\n\n\n int run, level, sign, vlc, limit;\n\n const int intra = 3 * type >> 2;\n\n const uint8_t *const scan = scan_patterns[type];\n\n\n\n for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {\n\n for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {\n\n if (vlc == INVALID_VLC)\n\n return -1;\n\n\n\n sign = (vlc & 0x1) - 1;\n\n vlc = vlc + 1 >> 1;\n\n\n\n if (type == 3) {\n\n if (vlc < 3) {\n\n run = 0;\n\n level = vlc;\n\n } else if (vlc < 4) {\n\n run = 1;\n\n level = 1;\n\n } else {\n\n run = vlc & 0x3;\n\n level = (vlc + 9 >> 2) - run;\n\n }\n\n } else {\n\n if (vlc < 16) {\n\n run = svq3_dct_tables[intra][vlc].run;\n\n level = svq3_dct_tables[intra][vlc].level;\n\n } else if (intra) {\n\n run = vlc & 0x7;\n\n level = (vlc >> 3) +\n\n ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));\n\n } else {\n\n run = vlc & 0xF;\n\n level = (vlc >> 4) +\n\n ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));\n\n }\n\n }\n\n\n\n if ((index += run) >= limit)\n\n return -1;\n\n\n\n block[scan[index]] = (level ^ sign) - sign;\n\n }\n\n\n\n if (type != 2) {\n\n break;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "9a2e79116d6235c53d8e9663a8d30d1950d7431a", + "length": 519 + }, + { + "index": 16446, + "code": "void cpu_register_physical_memory(target_phys_addr_t start_addr, \n\n unsigned long size,\n\n unsigned long phys_offset)\n\n{\n\n target_phys_addr_t addr, end_addr;\n\n PhysPageDesc *p;\n\n CPUState *env;\n\n unsigned long orig_size = size;\n\n void *subpage;\n\n\n\n end_addr = start_addr + (target_phys_addr_t)size;\n\n size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;\n\n for(addr = start_addr; addr < end_addr; addr += TARGET_PAGE_SIZE) {\n\n p = phys_page_find(addr >> TARGET_PAGE_BITS);\n\n if (p && p->phys_offset != IO_MEM_UNASSIGNED) {\n\n unsigned long orig_memory = p->phys_offset;\n\n target_phys_addr_t start_addr2, end_addr2;\n\n int need_subpage = 0;\n\n\n\n CHECK_SUBPAGE(addr, start_addr, start_addr2, end_addr, end_addr2,\n\n need_subpage);\n\n if (need_subpage) {\n\n if (!(orig_memory & IO_MEM_SUBPAGE)) {\n\n subpage = subpage_init((addr & TARGET_PAGE_MASK),\n\n &p->phys_offset, orig_memory);\n\n } else {\n\n subpage = io_mem_opaque[(orig_memory & ~TARGET_PAGE_MASK)\n\n >> IO_MEM_SHIFT];\n\n }\n\n subpage_register(subpage, start_addr2, end_addr2, phys_offset);\n\n } else {\n\n p->phys_offset = phys_offset;\n\n if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||\n\n (phys_offset & IO_MEM_ROMD))\n\n phys_offset += TARGET_PAGE_SIZE;\n\n }\n\n } else {\n\n p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 1);\n\n p->phys_offset = phys_offset;\n\n if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||\n\n (phys_offset & IO_MEM_ROMD))\n\n phys_offset += TARGET_PAGE_SIZE;\n\n else {\n\n target_phys_addr_t start_addr2, end_addr2;\n\n int need_subpage = 0;\n\n\n\n CHECK_SUBPAGE(addr, start_addr, start_addr2, end_addr,\n\n end_addr2, need_subpage);\n\n\n\n if (need_subpage) {\n\n subpage = subpage_init((addr & TARGET_PAGE_MASK),\n\n &p->phys_offset, IO_MEM_UNASSIGNED);\n\n subpage_register(subpage, start_addr2, end_addr2,\n\n phys_offset);\n\n }\n\n }\n\n }\n\n }\n\n \n\n /* since each CPU stores ram addresses in its TLB cache, we must\n\n reset the modified entries */\n\n /* XXX: slow ! */\n\n for(env = first_cpu; env != NULL; env = env->next_cpu) {\n\n tlb_flush(env, 1);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "49e9fba27138adb4ca52385f6ecc63b0ff0d3546", + "length": 580 + }, + { + "index": 12948, + "code": "int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,\n\n AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,\n\n void *log_ctx)\n\n{\n\n int index = 0, ret = 0;\n\n char chr = 0;\n\n\n\n AVFilterInOut *curr_inputs = NULL;\n\n AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL;\n\n AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;\n\n\n\n do {\n\n AVFilterContext *filter;\n\n const char *filterchain = filters;\n\n filters += strspn(filters, WHITESPACES);\n\n\n\n if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)\n\n goto end;\n\n\n\n if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)\n\n goto end;\n\n\n\n if (filter->input_count == 1 && !curr_inputs && !index) {\n\n /* First input pad, assume it is \"[in]\" if not specified */\n\n const char *tmp = \"[in]\";\n\n if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)\n\n goto end;\n\n }\n\n\n\n if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)\n\n goto end;\n\n\n\n if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,\n\n log_ctx)) < 0)\n\n goto end;\n\n\n\n filters += strspn(filters, WHITESPACES);\n\n chr = *filters++;\n\n\n\n if (chr == ';' && curr_inputs) {\n\n av_log(log_ctx, AV_LOG_ERROR,\n\n \"Invalid filterchain containing an unlabelled output pad: \\\"%s\\\"\\n\",\n\n filterchain);\n\n ret = AVERROR(EINVAL);\n\n goto end;\n\n }\n\n index++;\n\n } while (chr == ',' || chr == ';');\n\n\n\n if (chr) {\n\n av_log(log_ctx, AV_LOG_ERROR,\n\n \"Unable to parse graph description substring: \\\"%s\\\"\\n\",\n\n filters - 1);\n\n ret = AVERROR(EINVAL);\n\n goto end;\n\n }\n\n\n\n if (open_inputs && !strcmp(open_inputs->name, \"out\") && curr_inputs) {\n\n /* Last output pad, assume it is \"[out]\" if not specified */\n\n const char *tmp = \"[out]\";\n\n if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,\n\n log_ctx)) < 0)\n\n goto end;\n\n }\n\n\n\nend:\n\n /* clear open_in/outputs only if not passed as parameters */\n\n if (open_inputs_ptr) *open_inputs_ptr = open_inputs;\n\n else avfilter_inout_free(&open_inputs);\n\n if (open_outputs_ptr) *open_outputs_ptr = open_outputs;\n\n else avfilter_inout_free(&open_outputs);\n\n avfilter_inout_free(&curr_inputs);\n\n\n\n if (ret < 0) {\n\n for (; graph->filter_count > 0; graph->filter_count--)\n\n avfilter_free(graph->filters[graph->filter_count - 1]);\n\n av_freep(&graph->filters);\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2420763638bef385c8116a44ff5c0d2c15589494", + "length": 702 + }, + { + "index": 6295, + "code": "static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags)\n\n{\n\n BDRVRBDState *s = bs->opaque;\n\n char pool[RBD_MAX_POOL_NAME_SIZE];\n\n char snap_buf[RBD_MAX_SNAP_NAME_SIZE];\n\n char conf[RBD_MAX_CONF_SIZE];\n\n int r;\n\n\n\n if (qemu_rbd_parsename(filename, pool, sizeof(pool),\n\n snap_buf, sizeof(snap_buf),\n\n s->name, sizeof(s->name),\n\n conf, sizeof(conf)) < 0) {\n\n return -EINVAL;\n\n }\n\n s->snap = NULL;\n\n if (snap_buf[0] != '\\0') {\n\n s->snap = g_strdup(snap_buf);\n\n }\n\n\n\n r = rados_create(&s->cluster, NULL);\n\n if (r < 0) {\n\n error_report(\"error initializing\");\n\n return r;\n\n }\n\n\n\n if (strstr(conf, \"conf=\") == NULL) {\n\n r = rados_conf_read_file(s->cluster, NULL);\n\n if (r < 0) {\n\n error_report(\"error reading config file\");\n\n rados_shutdown(s->cluster);\n\n return r;\n\n }\n\n }\n\n\n\n if (conf[0] != '\\0') {\n\n r = qemu_rbd_set_conf(s->cluster, conf);\n\n if (r < 0) {\n\n error_report(\"error setting config options\");\n\n rados_shutdown(s->cluster);\n\n return r;\n\n }\n\n }\n\n\n\n r = rados_connect(s->cluster);\n\n if (r < 0) {\n\n error_report(\"error connecting\");\n\n rados_shutdown(s->cluster);\n\n return r;\n\n }\n\n\n\n r = rados_ioctx_create(s->cluster, pool, &s->io_ctx);\n\n if (r < 0) {\n\n error_report(\"error opening pool %s\", pool);\n\n rados_shutdown(s->cluster);\n\n return r;\n\n }\n\n\n\n r = rbd_open(s->io_ctx, s->name, &s->image, s->snap);\n\n if (r < 0) {\n\n error_report(\"error reading header from %s\", s->name);\n\n rados_ioctx_destroy(s->io_ctx);\n\n rados_shutdown(s->cluster);\n\n return r;\n\n }\n\n\n\n bs->read_only = (s->snap != NULL);\n\n\n\n s->event_reader_pos = 0;\n\n r = qemu_pipe(s->fds);\n\n if (r < 0) {\n\n error_report(\"error opening eventfd\");\n\n goto failed;\n\n }\n\n fcntl(s->fds[0], F_SETFL, O_NONBLOCK);\n\n fcntl(s->fds[1], F_SETFL, O_NONBLOCK);\n\n qemu_aio_set_fd_handler(s->fds[RBD_FD_READ], qemu_rbd_aio_event_reader,\n\n NULL, qemu_rbd_aio_flush_cb, NULL, s);\n\n\n\n\n\n return 0;\n\n\n\nfailed:\n\n rbd_close(s->image);\n\n rados_ioctx_destroy(s->io_ctx);\n\n rados_shutdown(s->cluster);\n\n return r;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "7c7e9df0232a1ce5c411f0f348038d2e72097ae1", + "length": 649 + }, + { + "index": 8034, + "code": "yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],\n\n const int32_t *ubuf[2], const int32_t *vbuf[2],\n\n const int32_t *abuf[2], uint16_t *dest, int dstW,\n\n int yalpha, int uvalpha, int y,\n\n enum PixelFormat target)\n\n{\n\n const int32_t *buf0 = buf[0], *buf1 = buf[1],\n\n *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],\n\n *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];\n\n int yalpha1 = 4095 - yalpha;\n\n int uvalpha1 = 4095 - uvalpha;\n\n int i;\n\n\n\n for (i = 0; i < ((dstW + 1) >> 1); i++) {\n\n int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;\n\n int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;\n\n int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;\n\n int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;\n\n int R, G, B;\n\n\n\n Y1 -= c->yuv2rgb_y_offset;\n\n Y2 -= c->yuv2rgb_y_offset;\n\n Y1 *= c->yuv2rgb_y_coeff;\n\n Y2 *= c->yuv2rgb_y_coeff;\n\n Y1 += 1 << 13;\n\n Y2 += 1 << 13;\n\n\n\n R = V * c->yuv2rgb_v2r_coeff;\n\n G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;\n\n B = U * c->yuv2rgb_u2b_coeff;\n\n\n\n output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);\n\n output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);\n\n output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);\n\n output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);\n\n output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);\n\n output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);\n\n dest += 6;\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "4860625236475da20d0da954017e8c7fe412dea2", + "length": 673 + }, + { + "index": 5068, + "code": "static int fourxm_read_packet(AVFormatContext *s,\n\n AVPacket *pkt)\n\n{\n\n FourxmDemuxContext *fourxm = s->priv_data;\n\n ByteIOContext *pb = s->pb;\n\n unsigned int fourcc_tag;\n\n unsigned int size, out_size;\n\n int ret = 0;\n\n unsigned int track_number;\n\n int packet_read = 0;\n\n unsigned char header[8];\n\n int audio_frame_count;\n\n\n\n while (!packet_read) {\n\n\n\n if ((ret = get_buffer(s->pb, header, 8)) < 0)\n\n return ret;\n\n fourcc_tag = AV_RL32(&header[0]);\n\n size = AV_RL32(&header[4]);\n\n if (url_feof(pb))\n\n return AVERROR(EIO);\n\n switch (fourcc_tag) {\n\n\n\n case LIST_TAG:\n\n /* this is a good time to bump the video pts */\n\n fourxm->video_pts ++;\n\n\n\n /* skip the LIST-* tag and move on to the next fourcc */\n\n get_le32(pb);\n\n break;\n\n\n\n case ifrm_TAG:\n\n case pfrm_TAG:\n\n case cfrm_TAG:\n\n case ifr2_TAG:\n\n case pfr2_TAG:\n\n case cfr2_TAG:\n\n /* allocate 8 more bytes than 'size' to account for fourcc\n\n * and size */\n\n if (size + 8 < size || av_new_packet(pkt, size + 8))\n\n return AVERROR(EIO);\n\n pkt->stream_index = fourxm->video_stream_index;\n\n pkt->pts = fourxm->video_pts;\n\n pkt->pos = url_ftell(s->pb);\n\n memcpy(pkt->data, header, 8);\n\n ret = get_buffer(s->pb, &pkt->data[8], size);\n\n\n\n if (ret < 0){\n\n av_free_packet(pkt);\n\n }else\n\n packet_read = 1;\n\n break;\n\n\n\n case snd__TAG:\n\n track_number = get_le32(pb);\n\n out_size= get_le32(pb);\n\n size-=8;\n\n\n\n if (track_number < fourxm->track_count) {\n\n ret= av_get_packet(s->pb, pkt, size);\n\n if(ret<0)\n\n return AVERROR(EIO);\n\n pkt->stream_index =\n\n fourxm->tracks[track_number].stream_index;\n\n pkt->pts = fourxm->tracks[track_number].audio_pts;\n\n packet_read = 1;\n\n\n\n /* pts accounting */\n\n audio_frame_count = size;\n\n if (fourxm->tracks[track_number].adpcm)\n\n audio_frame_count -=\n\n 2 * (fourxm->tracks[track_number].channels);\n\n audio_frame_count /=\n\n fourxm->tracks[track_number].channels;\n\n if (fourxm->tracks[track_number].adpcm){\n\n audio_frame_count *= 2;\n\n }else\n\n audio_frame_count /=\n\n (fourxm->tracks[track_number].bits / 8);\n\n fourxm->tracks[track_number].audio_pts += audio_frame_count;\n\n\n\n } else {\n\n url_fseek(pb, size, SEEK_CUR);\n\n }\n\n break;\n\n\n\n default:\n\n url_fseek(pb, size, SEEK_CUR);\n\n break;\n\n }\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "8bb7d97be0cda3c944956c79c50d0cf6f1efb7b9", + "length": 691 + }, + { + "index": 17891, + "code": "static int decode_codestream(Jpeg2000DecoderContext *s)\n\n{\n\n Jpeg2000CodingStyle *codsty = s->codsty;\n\n Jpeg2000QuantStyle *qntsty = s->qntsty;\n\n uint8_t *properties = s->properties;\n\n\n\n for (;;){\n\n int oldpos, marker, len, ret = 0;\n\n\n\n if (bytestream2_get_bytes_left(&s->g) < 2) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Missing EOC\\n\");\n\n break;\n\n }\n\n\n\n marker = bytestream2_get_be16u(&s->g);\n\n av_dlog(s->avctx, \"marker 0x%.4X at pos 0x%x\\n\", marker, bytestream2_tell(&s->g) - 4);\n\n oldpos = bytestream2_tell(&s->g);\n\n\n\n if (marker == JPEG2000_SOD){\n\n Jpeg2000Tile *tile = s->tile + s->curtileno;\n\n if (ret = init_tile(s, s->curtileno)) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"tile initialization failed\\n\");\n\n return ret;\n\n }\n\n if (ret = jpeg2000_decode_packets(s, tile)) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"packets decoding failed\\n\");\n\n return ret;\n\n }\n\n continue;\n\n }\n\n if (marker == JPEG2000_EOC)\n\n break;\n\n\n\n if (bytestream2_get_bytes_left(&s->g) < 2)\n\n return AVERROR(EINVAL);\n\n len = bytestream2_get_be16u(&s->g);\n\n switch (marker){\n\n case JPEG2000_SIZ:\n\n ret = get_siz(s);\n\n\n\n break;\n\n case JPEG2000_COC:\n\n ret = get_coc(s, codsty, properties);\n\n break;\n\n case JPEG2000_COD:\n\n ret = get_cod(s, codsty, properties);\n\n break;\n\n case JPEG2000_QCC:\n\n ret = get_qcc(s, len, qntsty, properties);\n\n break;\n\n case JPEG2000_QCD:\n\n ret = get_qcd(s, len, qntsty, properties);\n\n break;\n\n case JPEG2000_SOT:\n\n if (!(ret = get_sot(s))){\n\n codsty = s->tile[s->curtileno].codsty;\n\n qntsty = s->tile[s->curtileno].qntsty;\n\n properties = s->tile[s->curtileno].properties;\n\n }\n\n break;\n\n case JPEG2000_COM:\n\n // the comment is ignored\n\n bytestream2_skip(&s->g, len - 2);\n\n break;\n\n default:\n\n av_log(s->avctx, AV_LOG_ERROR, \"unsupported marker 0x%.4X at pos 0x%x\\n\", marker, bytestream2_tell(&s->g) - 4);\n\n bytestream2_skip(&s->g, len - 2);\n\n break;\n\n }\n\n if (bytestream2_tell(&s->g) - oldpos != len || ret){\n\n av_log(s->avctx, AV_LOG_ERROR, \"error during processing marker segment %.4x\\n\", marker);\n\n return ret ? ret : -1;\n\n }\n\n }\n\n return 0;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "17e66c9ff4774e254932d34dade77b1c04139a4f", + "length": 733 + }, + { + "index": 13175, + "code": "BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)\n\n{\n\n ImageInfo **p_image_info;\n\n BlockDriverState *bs0;\n\n BlockDeviceInfo *info = g_malloc0(sizeof(*info));\n\n\n\n info->file = g_strdup(bs->filename);\n\n info->ro = bs->read_only;\n\n info->drv = g_strdup(bs->drv->format_name);\n\n info->encrypted = bs->encrypted;\n\n info->encryption_key_missing = bdrv_key_required(bs);\n\n\n\n info->cache = g_new(BlockdevCacheInfo, 1);\n\n *info->cache = (BlockdevCacheInfo) {\n\n .writeback = bdrv_enable_write_cache(bs),\n\n .direct = !!(bs->open_flags & BDRV_O_NOCACHE),\n\n .no_flush = !!(bs->open_flags & BDRV_O_NO_FLUSH),\n\n };\n\n\n\n if (bs->node_name[0]) {\n\n info->has_node_name = true;\n\n info->node_name = g_strdup(bs->node_name);\n\n }\n\n\n\n if (bs->backing_file[0]) {\n\n info->has_backing_file = true;\n\n info->backing_file = g_strdup(bs->backing_file);\n\n }\n\n\n\n info->backing_file_depth = bdrv_get_backing_file_depth(bs);\n\n info->detect_zeroes = bs->detect_zeroes;\n\n\n\n if (bs->io_limits_enabled) {\n\n ThrottleConfig cfg;\n\n\n\n throttle_group_get_config(bs, &cfg);\n\n\n\n info->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg;\n\n info->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg;\n\n info->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg;\n\n\n\n info->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg;\n\n info->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg;\n\n info->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg;\n\n\n\n info->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max;\n\n info->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max;\n\n info->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max;\n\n info->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max;\n\n info->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max;\n\n info->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max;\n\n\n\n info->has_iops_max = cfg.buckets[THROTTLE_OPS_TOTAL].max;\n\n info->iops_max = cfg.buckets[THROTTLE_OPS_TOTAL].max;\n\n info->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max;\n\n info->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max;\n\n info->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;\n\n info->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;\n\n\n\n info->has_iops_size = cfg.op_size;\n\n info->iops_size = cfg.op_size;\n\n\n\n info->has_group = true;\n\n info->group = g_strdup(throttle_group_get_name(bs));\n\n }\n\n\n\n info->write_threshold = bdrv_write_threshold_get(bs);\n\n\n\n bs0 = bs;\n\n p_image_info = &info->image;\n\n while (1) {\n\n Error *local_err = NULL;\n\n bdrv_query_image_info(bs0, p_image_info, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n qapi_free_BlockDeviceInfo(info);\n\n return NULL;\n\n }\n\n if (bs0->drv && bs0->backing) {\n\n bs0 = bs0->backing->bs;\n\n (*p_image_info)->has_backing_image = true;\n\n p_image_info = &((*p_image_info)->backing_image);\n\n } else {\n\n break;\n\n }\n\n }\n\n\n\n return info;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a0d64a61db602696f4f1895a890c65eda5b3b618", + "length": 931 + }, + { + "index": 17621, + "code": "int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)\n\n{\n\n int (*start_frame)(AVFilterLink *, AVFilterBufferRef *);\n\n AVFilterPad *src = link->srcpad;\n\n AVFilterPad *dst = link->dstpad;\n\n int ret, perms;\n\n AVFilterCommand *cmd= link->dst->command_queue;\n\n int64_t pts;\n\n\n\n FF_TPRINTF_START(NULL, start_frame); ff_tlog_link(NULL, link, 0); ff_tlog(NULL, \" \"); ff_tlog_ref(NULL, picref, 1);\n\n\n\n av_assert1(picref->format == link->format);\n\n av_assert1(picref->video->w == link->w);\n\n av_assert1(picref->video->h == link->h);\n\n\n\n if (link->closed) {\n\n avfilter_unref_buffer(picref);\n\n return AVERROR_EOF;\n\n }\n\n\n\n if (!(start_frame = dst->start_frame))\n\n start_frame = default_start_frame;\n\n\n\n av_assert1((picref->perms & src->min_perms) == src->min_perms);\n\n picref->perms &= ~ src->rej_perms;\n\n perms = picref->perms;\n\n\n\n if (picref->linesize[0] < 0)\n\n perms |= AV_PERM_NEG_LINESIZES;\n\n /* prepare to copy the picture if it has insufficient permissions */\n\n if ((dst->min_perms & perms) != dst->min_perms || dst->rej_perms & perms) {\n\n av_log(link->dst, AV_LOG_DEBUG,\n\n \"frame copy needed (have perms %x, need %x, reject %x)\\n\",\n\n picref->perms,\n\n link->dstpad->min_perms, link->dstpad->rej_perms);\n\n\n\n link->cur_buf = ff_get_video_buffer(link, dst->min_perms, link->w, link->h);\n\n if (!link->cur_buf) {\n\n avfilter_unref_bufferp(&picref);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n link->src_buf = picref;\n\n avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);\n\n\n\n /* copy palette if required */\n\n if (av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PAL)\n\n memcpy(link->cur_buf->data[1], link->src_buf-> data[1], AVPALETTE_SIZE);\n\n }\n\n else\n\n link->cur_buf = picref;\n\n\n\n link->cur_buf_copy = link->cur_buf;\n\n\n\n while(cmd && cmd->time <= picref->pts * av_q2d(link->time_base)){\n\n av_log(link->dst, AV_LOG_DEBUG,\n\n \"Processing command time:%f command:%s arg:%s\\n\",\n\n cmd->time, cmd->command, cmd->arg);\n\n avfilter_process_command(link->dst, cmd->command, cmd->arg, 0, 0, cmd->flags);\n\n ff_command_queue_pop(link->dst);\n\n cmd= link->dst->command_queue;\n\n }\n\n pts = link->cur_buf->pts;\n\n ret = start_frame(link, link->cur_buf);\n\n ff_update_link_current_pts(link, pts);\n\n if (ret < 0)\n\n clear_link(link);\n\n else\n\n /* incoming buffers must not be freed in start frame,\n\n because they can still be in use by the automatic copy mechanism */\n\n av_assert1(link->cur_buf_copy->buf->refcount > 0);\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5d2b8850746b4513a43938f60930b060cad36ee5", + "length": 736 + }, + { + "index": 21219, + "code": "static int s390_ipl_init(SysBusDevice *dev)\n\n{\n\n S390IPLState *ipl = S390_IPL(dev);\n\n uint64_t pentry = KERN_IMAGE_START;\n\n int kernel_size;\n\n\n\n int bios_size;\n\n char *bios_filename;\n\n\n\n /*\n\n * Always load the bios if it was enforced,\n\n * even if an external kernel has been defined.\n\n */\n\n if (!ipl->kernel || ipl->enforce_bios) {\n\n uint64_t fwbase = (MIN(ram_size, 0x80000000U) - 0x200000) & ~0xffffUL;\n\n\n\n if (bios_name == NULL) {\n\n bios_name = ipl->firmware;\n\n }\n\n\n\n bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);\n\n if (bios_filename == NULL) {\n\n hw_error(\"could not find stage1 bootloader\\n\");\n\n }\n\n\n\n bios_size = load_elf(bios_filename, bios_translate_addr, &fwbase,\n\n &ipl->bios_start_addr, NULL, NULL, 1,\n\n ELF_MACHINE, 0);\n\n if (bios_size > 0) {\n\n /* Adjust ELF start address to final location */\n\n ipl->bios_start_addr += fwbase;\n\n } else {\n\n /* Try to load non-ELF file (e.g. s390-zipl.rom) */\n\n bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START,\n\n 4096);\n\n ipl->bios_start_addr = ZIPL_IMAGE_START;\n\n if (bios_size > 4096) {\n\n hw_error(\"stage1 bootloader is > 4k\\n\");\n\n }\n\n }\n\n g_free(bios_filename);\n\n\n\n if (bios_size == -1) {\n\n hw_error(\"could not load bootloader '%s'\\n\", bios_name);\n\n }\n\n\n\n /* default boot target is the bios */\n\n ipl->start_addr = ipl->bios_start_addr;\n\n }\n\n\n\n if (ipl->kernel) {\n\n kernel_size = load_elf(ipl->kernel, NULL, NULL, &pentry, NULL,\n\n NULL, 1, ELF_MACHINE, 0);\n\n if (kernel_size < 0) {\n\n kernel_size = load_image_targphys(ipl->kernel, 0, ram_size);\n\n }\n\n if (kernel_size < 0) {\n\n fprintf(stderr, \"could not load kernel '%s'\\n\", ipl->kernel);\n\n return -1;\n\n }\n\n /*\n\n * Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the\n\n * kernel parameters here as well. Note: For old kernels (up to 3.2)\n\n * we can not rely on the ELF entry point - it was 0x800 (the SALIPL\n\n * loader) and it won't work. For this case we force it to 0x10000, too.\n\n */\n\n if (pentry == KERN_IMAGE_START || pentry == 0x800) {\n\n ipl->start_addr = KERN_IMAGE_START;\n\n /* Overwrite parameters in the kernel image, which are \"rom\" */\n\n strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline);\n\n } else {\n\n ipl->start_addr = pentry;\n\n }\n\n\n\n if (ipl->initrd) {\n\n ram_addr_t initrd_offset;\n\n int initrd_size;\n\n\n\n initrd_offset = INITRD_START;\n\n while (kernel_size + 0x100000 > initrd_offset) {\n\n initrd_offset += 0x100000;\n\n }\n\n initrd_size = load_image_targphys(ipl->initrd, initrd_offset,\n\n ram_size - initrd_offset);\n\n if (initrd_size == -1) {\n\n fprintf(stderr, \"qemu: could not load initrd '%s'\\n\",\n\n ipl->initrd);\n\n exit(1);\n\n }\n\n\n\n /*\n\n * we have to overwrite values in the kernel image,\n\n * which are \"rom\"\n\n */\n\n stq_p(rom_ptr(INITRD_PARM_START), initrd_offset);\n\n stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "7b527b86eb3560d68f41218cec0cdf3d60a38323", + "length": 915 + }, + { + "index": 13300, + "code": "static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)\n\n{\n\n AVStream *st;\n\n MOVStreamContext *sc;\n\n unsigned int i, j, entries, ctts_count = 0;\n\n\n\n if (c->fc->nb_streams < 1)\n\n return 0;\n\n st = c->fc->streams[c->fc->nb_streams-1];\n\n sc = st->priv_data;\n\n\n\n avio_r8(pb); /* version */\n\n avio_rb24(pb); /* flags */\n\n entries = avio_rb32(pb);\n\n\n\n av_log(c->fc, AV_LOG_TRACE, \"track[%u].ctts.entries = %u\\n\", c->fc->nb_streams - 1, entries);\n\n\n\n if (!entries)\n\n return 0;\n\n if (entries >= UINT_MAX / sizeof(*sc->ctts_data))\n\n return AVERROR_INVALIDDATA;\n\n av_freep(&sc->ctts_data);\n\n sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data));\n\n if (!sc->ctts_data)\n\n return AVERROR(ENOMEM);\n\n\n\n for (i = 0; i < entries && !pb->eof_reached; i++) {\n\n int count =avio_rb32(pb);\n\n int duration =avio_rb32(pb);\n\n\n\n if (count <= 0) {\n\n av_log(c->fc, AV_LOG_TRACE,\n\n \"ignoring CTTS entry with count=%d duration=%d\\n\",\n\n count, duration);\n\n continue;\n\n }\n\n\n\n /* Expand entries such that we have a 1-1 mapping with samples. */\n\n for (j = 0; j < count; j++)\n\n add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, 1, duration);\n\n\n\n av_log(c->fc, AV_LOG_TRACE, \"count=%d, duration=%d\\n\",\n\n count, duration);\n\n\n\n if (FFNABS(duration) < -(1<<28) && i+2fc, AV_LOG_WARNING, \"CTTS invalid\\n\");\n\n av_freep(&sc->ctts_data);\n\n sc->ctts_count = 0;\n\n return 0;\n\n }\n\n\n\n if (i+2ctts_count = ctts_count;\n\n\n\n if (pb->eof_reached)\n\n return AVERROR_EOF;\n\n\n\n av_log(c->fc, AV_LOG_TRACE, \"dts shift %d\\n\", sc->dts_shift);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2d015d3bf9fed59c65a3819a35fedbb8b7dde623", + "length": 575 + }, + { + "index": 14521, + "code": "float16 float32_to_float16(float32 a, flag ieee STATUS_PARAM)\n\n{\n\n flag aSign;\n\n int_fast16_t aExp;\n\n uint32_t aSig;\n\n uint32_t mask;\n\n uint32_t increment;\n\n int8 roundingMode;\n\n a = float32_squash_input_denormal(a STATUS_VAR);\n\n\n\n aSig = extractFloat32Frac( a );\n\n aExp = extractFloat32Exp( a );\n\n aSign = extractFloat32Sign( a );\n\n if ( aExp == 0xFF ) {\n\n if (aSig) {\n\n /* Input is a NaN */\n\n float16 r = commonNaNToFloat16( float32ToCommonNaN( a STATUS_VAR ) STATUS_VAR );\n\n if (!ieee) {\n\n return packFloat16(aSign, 0, 0);\n\n }\n\n return r;\n\n }\n\n /* Infinity */\n\n if (!ieee) {\n\n float_raise(float_flag_invalid STATUS_VAR);\n\n return packFloat16(aSign, 0x1f, 0x3ff);\n\n }\n\n return packFloat16(aSign, 0x1f, 0);\n\n }\n\n if (aExp == 0 && aSig == 0) {\n\n return packFloat16(aSign, 0, 0);\n\n }\n\n /* Decimal point between bits 22 and 23. */\n\n aSig |= 0x00800000;\n\n aExp -= 0x7f;\n\n if (aExp < -14) {\n\n mask = 0x00ffffff;\n\n if (aExp >= -24) {\n\n mask >>= 25 + aExp;\n\n }\n\n } else {\n\n mask = 0x00001fff;\n\n }\n\n if (aSig & mask) {\n\n float_raise( float_flag_underflow STATUS_VAR );\n\n roundingMode = STATUS(float_rounding_mode);\n\n switch (roundingMode) {\n\n case float_round_nearest_even:\n\n increment = (mask + 1) >> 1;\n\n if ((aSig & mask) == increment) {\n\n increment = aSig & (increment << 1);\n\n }\n\n break;\n\n case float_round_up:\n\n increment = aSign ? 0 : mask;\n\n break;\n\n case float_round_down:\n\n increment = aSign ? mask : 0;\n\n break;\n\n default: /* round_to_zero */\n\n increment = 0;\n\n break;\n\n }\n\n aSig += increment;\n\n if (aSig >= 0x01000000) {\n\n aSig >>= 1;\n\n aExp++;\n\n }\n\n } else if (aExp < -14\n\n && STATUS(float_detect_tininess) == float_tininess_before_rounding) {\n\n float_raise( float_flag_underflow STATUS_VAR);\n\n }\n\n\n\n if (ieee) {\n\n if (aExp > 15) {\n\n float_raise( float_flag_overflow | float_flag_inexact STATUS_VAR);\n\n return packFloat16(aSign, 0x1f, 0);\n\n }\n\n } else {\n\n if (aExp > 16) {\n\n float_raise(float_flag_invalid | float_flag_inexact STATUS_VAR);\n\n return packFloat16(aSign, 0x1f, 0x3ff);\n\n }\n\n }\n\n if (aExp < -24) {\n\n return packFloat16(aSign, 0, 0);\n\n }\n\n if (aExp < -14) {\n\n aSig >>= -14 - aExp;\n\n aExp = -14;\n\n }\n\n return packFloat16(aSign, aExp + 14, aSig >> 13);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "1bf6beec8a012cae4bb6fbc89c465127e9650c92", + "length": 766 + }, + { + "index": 22416, + "code": "int ff_aac_ac3_parse(AVCodecParserContext *s1,\n\n AVCodecContext *avctx,\n\n const uint8_t **poutbuf, int *poutbuf_size,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n AACAC3ParseContext *s = s1->priv_data;\n\n const uint8_t *buf_ptr;\n\n int len, sample_rate, bit_rate, channels, samples;\n\n\n\n *poutbuf = NULL;\n\n *poutbuf_size = 0;\n\n\n\n buf_ptr = buf;\n\n while (buf_size > 0) {\n\n int size_needed= s->frame_size ? s->frame_size : s->header_size;\n\n len = s->inbuf_ptr - s->inbuf;\n\n\n\n if(leninbuf_ptr, buf_ptr, len);\n\n buf_ptr += len;\n\n s->inbuf_ptr += len;\n\n buf_size -= len;\n\n }\n\n\n\n if (s->frame_size == 0) {\n\n if ((s->inbuf_ptr - s->inbuf) == s->header_size) {\n\n len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,\n\n &samples);\n\n if (len == 0) {\n\n /* no sync found : move by one byte (inefficient, but simple!) */\n\n memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);\n\n s->inbuf_ptr--;\n\n } else {\n\n s->frame_size = len;\n\n /* update codec info */\n\n avctx->sample_rate = sample_rate;\n\n avctx->channels = channels;\n\n /* allow downmixing to mono or stereo for AC3 */\n\n if(avctx->request_channels > 0 &&\n\n avctx->request_channels < channels &&\n\n avctx->request_channels <= 2 &&\n\n avctx->codec_id == CODEC_ID_AC3) {\n\n avctx->channels = avctx->request_channels;\n\n }\n\n avctx->bit_rate = bit_rate;\n\n avctx->frame_size = samples;\n\n }\n\n }\n\n } else {\n\n if(s->inbuf_ptr - s->inbuf == s->frame_size){\n\n *poutbuf = s->inbuf;\n\n *poutbuf_size = s->frame_size;\n\n s->inbuf_ptr = s->inbuf;\n\n s->frame_size = 0;\n\n break;\n\n }\n\n }\n\n }\n\n return buf_ptr - buf;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "6cd325c1064c80f47b596f3b2bea24f227b198f2", + "length": 553 + }, + { + "index": 5304, + "code": "static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addr, int mem_index,\n\n TCGMemOp s_bits, int which)\n\n{\n\n const TCGReg r0 = TCG_REG_O0;\n\n const TCGReg r1 = TCG_REG_O1;\n\n const TCGReg r2 = TCG_REG_O2;\n\n int tlb_ofs;\n\n\n\n /* Shift the page number down. */\n\n tcg_out_arithi(s, r1, addr, TARGET_PAGE_BITS, SHIFT_SRL);\n\n\n\n /* Mask out the page offset, except for the required alignment. */\n\n tcg_out_movi(s, TCG_TYPE_TL, TCG_REG_T1,\n\n TARGET_PAGE_MASK | ((1 << s_bits) - 1));\n\n\n\n /* Mask the tlb index. */\n\n tcg_out_arithi(s, r1, r1, CPU_TLB_SIZE - 1, ARITH_AND);\n\n \n\n /* Mask page, part 2. */\n\n tcg_out_arith(s, r0, addr, TCG_REG_T1, ARITH_AND);\n\n\n\n /* Shift the tlb index into place. */\n\n tcg_out_arithi(s, r1, r1, CPU_TLB_ENTRY_BITS, SHIFT_SLL);\n\n\n\n /* Relative to the current ENV. */\n\n tcg_out_arith(s, r1, TCG_AREG0, r1, ARITH_ADD);\n\n\n\n /* Find a base address that can load both tlb comparator and addend. */\n\n tlb_ofs = offsetof(CPUArchState, tlb_table[mem_index][0]);\n\n if (!check_fit_tl(tlb_ofs + sizeof(CPUTLBEntry), 13)) {\n\n tcg_out_addi(s, r1, tlb_ofs & ~0x3ff);\n\n tlb_ofs &= 0x3ff;\n\n }\n\n\n\n /* Load the tlb comparator and the addend. */\n\n tcg_out_ld(s, TCG_TYPE_TL, r2, r1, tlb_ofs + which);\n\n tcg_out_ld(s, TCG_TYPE_PTR, r1, r1, tlb_ofs+offsetof(CPUTLBEntry, addend));\n\n\n\n /* subcc arg0, arg2, %g0 */\n\n tcg_out_cmp(s, r0, r2, 0);\n\n\n\n /* If the guest address must be zero-extended, do so now. */\n\n if (SPARC64 && TARGET_LONG_BITS == 32) {\n\n tcg_out_arithi(s, r0, addr, 0, SHIFT_SRL);\n\n return r0;\n\n }\n\n return addr;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "425532d71d5d295cc9c649500e4969ac621ce51d", + "length": 580 + }, + { + "index": 10603, + "code": "void commit_start(BlockDriverState *bs, BlockDriverState *base,\n\n BlockDriverState *top, int64_t speed,\n\n BlockdevOnError on_error, BlockDriverCompletionFunc *cb,\n\n void *opaque, Error **errp)\n\n{\n\n CommitBlockJob *s;\n\n BlockReopenQueue *reopen_queue = NULL;\n\n int orig_overlay_flags;\n\n int orig_base_flags;\n\n BlockDriverState *overlay_bs;\n\n Error *local_err = NULL;\n\n\n\n if ((on_error == BLOCKDEV_ON_ERROR_STOP ||\n\n on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&\n\n !bdrv_iostatus_is_enabled(bs)) {\n\n error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);\n\n return;\n\n }\n\n\n\n /* Once we support top == active layer, remove this check */\n\n if (top == bs) {\n\n error_setg(errp,\n\n \"Top image as the active layer is currently unsupported\");\n\n return;\n\n }\n\n\n\n if (top == base) {\n\n error_setg(errp, \"Invalid files for merge: top and base are the same\");\n\n return;\n\n }\n\n\n\n /* top and base may be valid, but let's make sure that base is reachable\n\n * from top */\n\n if (bdrv_find_backing_image(top, base->filename) != base) {\n\n error_setg(errp,\n\n \"Base (%s) is not reachable from top (%s)\",\n\n base->filename, top->filename);\n\n return;\n\n }\n\n\n\n overlay_bs = bdrv_find_overlay(bs, top);\n\n\n\n if (overlay_bs == NULL) {\n\n error_setg(errp, \"Could not find overlay image for %s:\", top->filename);\n\n return;\n\n }\n\n\n\n orig_base_flags = bdrv_get_flags(base);\n\n orig_overlay_flags = bdrv_get_flags(overlay_bs);\n\n\n\n /* convert base & overlay_bs to r/w, if necessary */\n\n if (!(orig_base_flags & BDRV_O_RDWR)) {\n\n reopen_queue = bdrv_reopen_queue(reopen_queue, base,\n\n orig_base_flags | BDRV_O_RDWR);\n\n }\n\n if (!(orig_overlay_flags & BDRV_O_RDWR)) {\n\n reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs,\n\n orig_overlay_flags | BDRV_O_RDWR);\n\n }\n\n if (reopen_queue) {\n\n bdrv_reopen_multiple(reopen_queue, &local_err);\n\n if (local_err != NULL) {\n\n error_propagate(errp, local_err);\n\n return;\n\n }\n\n }\n\n\n\n\n\n s = block_job_create(&commit_job_type, bs, speed, cb, opaque, errp);\n\n if (!s) {\n\n return;\n\n }\n\n\n\n s->base = base;\n\n s->top = top;\n\n s->active = bs;\n\n\n\n s->base_flags = orig_base_flags;\n\n s->orig_overlay_flags = orig_overlay_flags;\n\n\n\n s->on_error = on_error;\n\n s->common.co = qemu_coroutine_create(commit_run);\n\n\n\n trace_commit_start(bs, base, top, s, s->common.co, opaque);\n\n qemu_coroutine_enter(s->common.co, s);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "d5208c45be38ab858db6ec5a5097aa1c1a8ebbc9", + "length": 662 + }, + { + "index": 196, + "code": "static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){\n\n AVFrame *pic=NULL;\n\n int i;\n\n const int encoding_delay= s->max_b_frames;\n\n int direct=1;\n\n \n\n if(pic_arg){\n\n if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;\n\n if(pic_arg->linesize[0] != s->linesize) direct=0;\n\n if(pic_arg->linesize[1] != s->uvlinesize) direct=0;\n\n if(pic_arg->linesize[2] != s->uvlinesize) direct=0;\n\n \n\n// printf(\"%d %d %d %d\\n\",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);\n\n \n\n if(direct){\n\n i= find_unused_picture(s, 1);\n\n\n\n pic= (AVFrame*)&s->picture[i];\n\n pic->reference= 3;\n\n \n\n for(i=0; i<4; i++){\n\n pic->data[i]= pic_arg->data[i];\n\n pic->linesize[i]= pic_arg->linesize[i];\n\n }\n\n alloc_picture(s, (Picture*)pic, 1);\n\n }else{\n\n i= find_unused_picture(s, 0);\n\n\n\n pic= (AVFrame*)&s->picture[i];\n\n pic->reference= 3;\n\n\n\n alloc_picture(s, (Picture*)pic, 0);\n\n for(i=0; i<4; i++){\n\n /* the input will be 16 pixels to the right relative to the actual buffer start\n\n * and the current_pic, so the buffer can be reused, yes its not beatifull \n\n */\n\n pic->data[i]+= 16; \n\n }\n\n\n\n if( pic->data[0] == pic_arg->data[0] \n\n && pic->data[1] == pic_arg->data[1]\n\n && pic->data[2] == pic_arg->data[2]){\n\n // empty\n\n }else{\n\n int h_chroma_shift, v_chroma_shift;\n\n avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);\n\n \n\n for(i=0; i<3; i++){\n\n int src_stride= pic_arg->linesize[i];\n\n int dst_stride= i ? s->uvlinesize : s->linesize;\n\n int h_shift= i ? h_chroma_shift : 0;\n\n int v_shift= i ? v_chroma_shift : 0;\n\n int w= s->width >>h_shift;\n\n int h= s->height>>v_shift;\n\n uint8_t *src= pic_arg->data[i];\n\n uint8_t *dst= pic->data[i];\n\n \n\n if(src_stride==dst_stride)\n\n memcpy(dst, src, src_stride*h);\n\n else{\n\n while(h--){\n\n memcpy(dst, src, w);\n\n dst += dst_stride;\n\n src += src_stride;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n pic->quality= pic_arg->quality;\n\n pic->pict_type= pic_arg->pict_type;\n\n pic->pts = pic_arg->pts;\n\n \n\n if(s->input_picture[encoding_delay])\n\n pic->display_picture_number= s->input_picture[encoding_delay]->display_picture_number + 1;\n\n \n\n }\n\n\n\n /* shift buffer entries */\n\n for(i=1; iencoding_delay+1*/; i++)\n\n s->input_picture[i-1]= s->input_picture[i];\n\n \n\n s->input_picture[encoding_delay]= (Picture*)pic;\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6571e41dcdee4655237bca0a3277df8976167aee", + "length": 796 + }, + { + "index": 4390, + "code": "static void x86_cpu_load_features(X86CPU *cpu, Error **errp)\n\n{\n\n CPUX86State *env = &cpu->env;\n\n FeatureWord w;\n\n GList *l;\n\n Error *local_err = NULL;\n\n\n\n /*TODO: cpu->max_features incorrectly overwrites features\n\n * set using \"feat=on|off\". Once we fix this, we can convert\n\n * plus_features & minus_features to global properties\n\n * inside x86_cpu_parse_featurestr() too.\n\n */\n\n if (cpu->max_features) {\n\n for (w = 0; w < FEATURE_WORDS; w++) {\n\n env->features[w] =\n\n x86_cpu_get_supported_feature_word(w, cpu->migratable);\n\n }\n\n }\n\n\n\n for (l = plus_features; l; l = l->next) {\n\n const char *prop = l->data;\n\n object_property_set_bool(OBJECT(cpu), true, prop, &local_err);\n\n if (local_err) {\n\n goto out;\n\n }\n\n }\n\n\n\n for (l = minus_features; l; l = l->next) {\n\n const char *prop = l->data;\n\n object_property_set_bool(OBJECT(cpu), false, prop, &local_err);\n\n if (local_err) {\n\n goto out;\n\n }\n\n }\n\n\n\n if (!kvm_enabled() || !cpu->expose_kvm) {\n\n env->features[FEAT_KVM] = 0;\n\n }\n\n\n\n x86_cpu_enable_xsave_components(cpu);\n\n\n\n /* CPUID[EAX=7,ECX=0].EBX always increased level automatically: */\n\n x86_cpu_adjust_feat_level(cpu, FEAT_7_0_EBX);\n\n if (cpu->full_cpuid_auto_level) {\n\n x86_cpu_adjust_feat_level(cpu, FEAT_1_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_1_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_6_EAX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_7_0_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0007_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_SVM);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);\n\n /* SVM requires CPUID[0x8000000A] */\n\n if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {\n\n x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);\n\n }\n\n }\n\n\n\n /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */\n\n if (env->cpuid_level == UINT32_MAX) {\n\n env->cpuid_level = env->cpuid_min_level;\n\n }\n\n if (env->cpuid_xlevel == UINT32_MAX) {\n\n env->cpuid_xlevel = env->cpuid_min_xlevel;\n\n }\n\n if (env->cpuid_xlevel2 == UINT32_MAX) {\n\n env->cpuid_xlevel2 = env->cpuid_min_xlevel2;\n\n }\n\n\n\nout:\n\n if (local_err != NULL) {\n\n error_propagate(errp, local_err);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b8d834a00fa3ed4dad7d371e1a00938a126a54a0", + "length": 763 + }, + { + "index": 15905, + "code": "static void vc1_decode_p_blocks(VC1Context *v)\n\n{\n\n MpegEncContext *s = &v->s;\n\n int apply_loop_filter;\n\n\n\n /* select codingmode used for VLC tables selection */\n\n switch (v->c_ac_table_index) {\n\n case 0:\n\n v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;\n\n break;\n\n case 1:\n\n v->codingset = CS_HIGH_MOT_INTRA;\n\n break;\n\n case 2:\n\n v->codingset = CS_MID_RATE_INTRA;\n\n break;\n\n }\n\n\n\n switch (v->c_ac_table_index) {\n\n case 0:\n\n v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;\n\n break;\n\n case 1:\n\n v->codingset2 = CS_HIGH_MOT_INTER;\n\n break;\n\n case 2:\n\n v->codingset2 = CS_MID_RATE_INTER;\n\n break;\n\n }\n\n\n\n apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);\n\n s->first_slice_line = 1;\n\n memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);\n\n for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {\n\n s->mb_x = 0;\n\n ff_init_block_index(s);\n\n for (; s->mb_x < s->mb_width; s->mb_x++) {\n\n ff_update_block_index(s);\n\n\n\n if (v->fcm == ILACE_FIELD)\n\n vc1_decode_p_mb_intfi(v);\n\n else if (v->fcm == ILACE_FRAME)\n\n vc1_decode_p_mb_intfr(v);\n\n else vc1_decode_p_mb(v);\n\n if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == PROGRESSIVE)\n\n vc1_apply_p_loop_filter(v);\n\n if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {\n\n // TODO: may need modification to handle slice coding\n\n ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);\n\n av_log(s->avctx, AV_LOG_ERROR, \"Bits overconsumption: %i > %i at %ix%i\\n\",\n\n get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);\n\n return;\n\n }\n\n }\n\n memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0]) * s->mb_stride);\n\n memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0]) * s->mb_stride);\n\n memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);\n\n memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0]) * s->mb_stride);\n\n if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);\n\n s->first_slice_line = 0;\n\n }\n\n if (apply_loop_filter && v->fcm == PROGRESSIVE) {\n\n s->mb_x = 0;\n\n ff_init_block_index(s);\n\n for (; s->mb_x < s->mb_width; s->mb_x++) {\n\n ff_update_block_index(s);\n\n vc1_apply_p_loop_filter(v);\n\n }\n\n }\n\n if (s->end_mb_y >= s->start_mb_y)\n\n ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);\n\n ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,\n\n (s->end_mb_y << v->field_mode) - 1, ER_MB_END);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "0d194ee51ed477f843900e657a7edbcbecdffa42", + "length": 928 + }, + { + "index": 13775, + "code": "static inline int silk_is_lpc_stable(const int16_t lpc[16], int order)\n\n{\n\n int k, j, DC_resp = 0;\n\n int32_t lpc32[2][16]; // Q24\n\n int totalinvgain = 1 << 30; // 1.0 in Q30\n\n int32_t *row = lpc32[0], *prevrow;\n\n\n\n /* initialize the first row for the Levinson recursion */\n\n for (k = 0; k < order; k++) {\n\n DC_resp += lpc[k];\n\n row[k] = lpc[k] * 4096;\n\n }\n\n\n\n if (DC_resp >= 4096)\n\n return 0;\n\n\n\n /* check if prediction gain pushes any coefficients too far */\n\n for (k = order - 1; 1; k--) {\n\n int rc; // Q31; reflection coefficient\n\n int gaindiv; // Q30; inverse of the gain (the divisor)\n\n int gain; // gain for this reflection coefficient\n\n int fbits; // fractional bits used for the gain\n\n int error; // Q29; estimate of the error of our partial estimate of 1/gaindiv\n\n\n\n if (FFABS(row[k]) > 16773022)\n\n return 0;\n\n\n\n rc = -(row[k] * 128);\n\n gaindiv = (1 << 30) - MULH(rc, rc);\n\n\n\n totalinvgain = MULH(totalinvgain, gaindiv) << 2;\n\n if (k == 0)\n\n return (totalinvgain >= 107374);\n\n\n\n /* approximate 1.0/gaindiv */\n\n fbits = opus_ilog(gaindiv);\n\n gain = ((1 << 29) - 1) / (gaindiv >> (fbits + 1 - 16)); // Q\n\n error = (1 << 29) - MULL(gaindiv << (15 + 16 - fbits), gain, 16);\n\n gain = ((gain << 16) + (error * gain >> 13));\n\n\n\n /* switch to the next row of the LPC coefficients */\n\n prevrow = row;\n\n row = lpc32[k & 1];\n\n\n\n for (j = 0; j < k; j++) {\n\n int x = prevrow[j] - ROUND_MULL(prevrow[k - j - 1], rc, 31);\n\n row[j] = ROUND_MULL(x, gain, fbits);\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "511e6f17f493719058229630c7db4d8d7c05aeac", + "length": 555 + }, + { + "index": 23086, + "code": "static int vpc_open(BlockDriverState *bs, int flags)\n\n{\n\n BDRVVPCState *s = bs->opaque;\n\n int i;\n\n struct vhd_footer* footer;\n\n struct vhd_dyndisk_header* dyndisk_header;\n\n uint8_t buf[HEADER_SIZE];\n\n uint32_t checksum;\n\n int err = -1;\n\n int disk_type = VHD_DYNAMIC;\n\n\n\n if (bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE) != HEADER_SIZE)\n\n goto fail;\n\n\n\n footer = (struct vhd_footer*) s->footer_buf;\n\n if (strncmp(footer->creator, \"conectix\", 8)) {\n\n int64_t offset = bdrv_getlength(bs->file);\n\n if (offset < HEADER_SIZE) {\n\n goto fail;\n\n }\n\n /* If a fixed disk, the footer is found only at the end of the file */\n\n if (bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf, HEADER_SIZE)\n\n != HEADER_SIZE) {\n\n goto fail;\n\n }\n\n if (strncmp(footer->creator, \"conectix\", 8)) {\n\n goto fail;\n\n }\n\n disk_type = VHD_FIXED;\n\n }\n\n\n\n checksum = be32_to_cpu(footer->checksum);\n\n footer->checksum = 0;\n\n if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum)\n\n fprintf(stderr, \"block-vpc: The header checksum of '%s' is \"\n\n \"incorrect.\\n\", bs->filename);\n\n\n\n /* Write 'checksum' back to footer, or else will leave it with zero. */\n\n footer->checksum = be32_to_cpu(checksum);\n\n\n\n // The visible size of a image in Virtual PC depends on the geometry\n\n // rather than on the size stored in the footer (the size in the footer\n\n // is too large usually)\n\n bs->total_sectors = (int64_t)\n\n be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl;\n\n\n\n if (bs->total_sectors >= 65535 * 16 * 255) {\n\n err = -EFBIG;\n\n goto fail;\n\n }\n\n\n\n if (disk_type == VHD_DYNAMIC) {\n\n if (bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf,\n\n HEADER_SIZE) != HEADER_SIZE) {\n\n goto fail;\n\n }\n\n\n\n dyndisk_header = (struct vhd_dyndisk_header *) buf;\n\n\n\n if (strncmp(dyndisk_header->magic, \"cxsparse\", 8)) {\n\n goto fail;\n\n }\n\n\n\n s->block_size = be32_to_cpu(dyndisk_header->block_size);\n\n s->bitmap_size = ((s->block_size / (8 * 512)) + 511) & ~511;\n\n\n\n s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries);\n\n s->pagetable = g_malloc(s->max_table_entries * 4);\n\n\n\n s->bat_offset = be64_to_cpu(dyndisk_header->table_offset);\n\n if (bdrv_pread(bs->file, s->bat_offset, s->pagetable,\n\n s->max_table_entries * 4) != s->max_table_entries * 4) {\n\n goto fail;\n\n }\n\n\n\n s->free_data_block_offset =\n\n (s->bat_offset + (s->max_table_entries * 4) + 511) & ~511;\n\n\n\n for (i = 0; i < s->max_table_entries; i++) {\n\n be32_to_cpus(&s->pagetable[i]);\n\n if (s->pagetable[i] != 0xFFFFFFFF) {\n\n int64_t next = (512 * (int64_t) s->pagetable[i]) +\n\n s->bitmap_size + s->block_size;\n\n\n\n if (next > s->free_data_block_offset) {\n\n s->free_data_block_offset = next;\n\n }\n\n }\n\n }\n\n\n\n s->last_bitmap_offset = (int64_t) -1;\n\n\n\n#ifdef CACHE\n\n s->pageentry_u8 = g_malloc(512);\n\n s->pageentry_u32 = s->pageentry_u8;\n\n s->pageentry_u16 = s->pageentry_u8;\n\n s->last_pagetable = -1;\n\n#endif\n\n }\n\n\n\n qemu_co_mutex_init(&s->lock);\n\n\n\n /* Disable migration when VHD images are used */\n\n error_set(&s->migration_blocker,\n\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n\n \"vpc\", bs->device_name, \"live migration\");\n\n migrate_add_blocker(s->migration_blocker);\n\n\n\n return 0;\n\n fail:\n\n return err;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "258d2edbcd4bb5d267c96163333820332e1c14fa", + "length": 1003 + }, + { + "index": 16129, + "code": "static void xhci_events_update(XHCIState *xhci, int v)\n\n{\n\n XHCIInterrupter *intr = &xhci->intr[v];\n\n dma_addr_t erdp;\n\n unsigned int dp_idx;\n\n bool do_irq = 0;\n\n\n\n if (xhci->usbsts & USBSTS_HCH) {\n\n return;\n\n }\n\n\n\n erdp = xhci_addr64(intr->erdp_low, intr->erdp_high);\n\n if (erdp < intr->er_start ||\n\n erdp >= (intr->er_start + TRB_SIZE*intr->er_size)) {\n\n DPRINTF(\"xhci: ERDP out of bounds: \"DMA_ADDR_FMT\"\\n\", erdp);\n\n DPRINTF(\"xhci: ER[%d] at \"DMA_ADDR_FMT\" len %d\\n\",\n\n v, intr->er_start, intr->er_size);\n\n xhci_die(xhci);\n\n return;\n\n }\n\n dp_idx = (erdp - intr->er_start) / TRB_SIZE;\n\n assert(dp_idx < intr->er_size);\n\n\n\n /* NEC didn't read section 4.9.4 of the spec (v1.0 p139 top Note) and thus\n\n * deadlocks when the ER is full. Hack it by holding off events until\n\n * the driver decides to free at least half of the ring */\n\n if (intr->er_full) {\n\n int er_free = dp_idx - intr->er_ep_idx;\n\n if (er_free <= 0) {\n\n er_free += intr->er_size;\n\n }\n\n if (er_free < (intr->er_size/2)) {\n\n DPRINTF(\"xhci_events_update(): event ring still \"\n\n \"more than half full (hack)\\n\");\n\n return;\n\n }\n\n }\n\n\n\n while (intr->ev_buffer_put != intr->ev_buffer_get) {\n\n assert(intr->er_full);\n\n if (((intr->er_ep_idx+1) % intr->er_size) == dp_idx) {\n\n DPRINTF(\"xhci_events_update(): event ring full again\\n\");\n\n#ifndef ER_FULL_HACK\n\n XHCIEvent full = {ER_HOST_CONTROLLER, CC_EVENT_RING_FULL_ERROR};\n\n xhci_write_event(xhci, &full, v);\n\n#endif\n\n do_irq = 1;\n\n break;\n\n }\n\n XHCIEvent *event = &intr->ev_buffer[intr->ev_buffer_get];\n\n xhci_write_event(xhci, event, v);\n\n intr->ev_buffer_get++;\n\n do_irq = 1;\n\n if (intr->ev_buffer_get == EV_QUEUE) {\n\n intr->ev_buffer_get = 0;\n\n }\n\n }\n\n\n\n if (do_irq) {\n\n xhci_intr_raise(xhci, v);\n\n }\n\n\n\n if (intr->er_full && intr->ev_buffer_put == intr->ev_buffer_get) {\n\n DPRINTF(\"xhci_events_update(): event ring no longer full\\n\");\n\n intr->er_full = 0;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "898248a32915024a4f01ce4f0c3519509fb703cb", + "length": 627 + }, + { + "index": 19844, + "code": "static int s390_ipl_init(SysBusDevice *dev)\n\n{\n\n S390IPLState *ipl = S390_IPL(dev);\n\n int kernel_size;\n\n\n\n if (!ipl->kernel) {\n\n int bios_size;\n\n char *bios_filename;\n\n\n\n /* Load zipl bootloader */\n\n if (bios_name == NULL) {\n\n bios_name = ipl->firmware;\n\n }\n\n\n\n bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);\n\n if (bios_filename == NULL) {\n\n hw_error(\"could not find stage1 bootloader\\n\");\n\n }\n\n\n\n bios_size = load_elf(bios_filename, NULL, NULL, &ipl->start_addr, NULL,\n\n NULL, 1, ELF_MACHINE, 0);\n\n if (bios_size == -1) {\n\n bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START,\n\n 4096);\n\n ipl->start_addr = ZIPL_IMAGE_START;\n\n if (bios_size > 4096) {\n\n hw_error(\"stage1 bootloader is > 4k\\n\");\n\n }\n\n }\n\n g_free(bios_filename);\n\n\n\n if (bios_size == -1) {\n\n hw_error(\"could not load bootloader '%s'\\n\", bios_name);\n\n }\n\n return 0;\n\n } else {\n\n uint64_t pentry = KERN_IMAGE_START;\n\n kernel_size = load_elf(ipl->kernel, NULL, NULL, &pentry, NULL,\n\n NULL, 1, ELF_MACHINE, 0);\n\n if (kernel_size == -1) {\n\n kernel_size = load_image_targphys(ipl->kernel, 0, ram_size);\n\n }\n\n if (kernel_size == -1) {\n\n fprintf(stderr, \"could not load kernel '%s'\\n\", ipl->kernel);\n\n return -1;\n\n }\n\n /*\n\n * Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the\n\n * kernel parameters here as well. Note: For old kernels (up to 3.2)\n\n * we can not rely on the ELF entry point - it was 0x800 (the SALIPL\n\n * loader) and it won't work. For this case we force it to 0x10000, too.\n\n */\n\n if (pentry == KERN_IMAGE_START || pentry == 0x800) {\n\n ipl->start_addr = KERN_IMAGE_START;\n\n /* Overwrite parameters in the kernel image, which are \"rom\" */\n\n strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline);\n\n } else {\n\n ipl->start_addr = pentry;\n\n }\n\n }\n\n if (ipl->initrd) {\n\n ram_addr_t initrd_offset;\n\n int initrd_size;\n\n\n\n initrd_offset = INITRD_START;\n\n while (kernel_size + 0x100000 > initrd_offset) {\n\n initrd_offset += 0x100000;\n\n }\n\n initrd_size = load_image_targphys(ipl->initrd, initrd_offset,\n\n ram_size - initrd_offset);\n\n if (initrd_size == -1) {\n\n fprintf(stderr, \"qemu: could not load initrd '%s'\\n\", ipl->initrd);\n\n exit(1);\n\n }\n\n\n\n /* we have to overwrite values in the kernel image, which are \"rom\" */\n\n stq_p(rom_ptr(INITRD_PARM_START), initrd_offset);\n\n stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "18674b26788a9e47f1157170234e32ece2044367", + "length": 767 + }, + { + "index": 25828, + "code": "static int pixlet_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n PixletContext *ctx = avctx->priv_data;\n int i, w, h, width, height, ret, version;\n AVFrame *p = data;\n ThreadFrame frame = { .f = data };\n uint32_t pktsize;\n bytestream2_init(&ctx->gb, avpkt->data, avpkt->size);\n pktsize = bytestream2_get_be32(&ctx->gb);\n if (pktsize <= 44 || pktsize - 4 > bytestream2_get_bytes_left(&ctx->gb)) {\n av_log(avctx, AV_LOG_ERROR, \"Invalid packet size %\"PRIu32\"\\n\", pktsize);\n }\n version = bytestream2_get_le32(&ctx->gb);\n if (version != 1)\n avpriv_request_sample(avctx, \"Version %d\", version);\n bytestream2_skip(&ctx->gb, 4);\n if (bytestream2_get_be32(&ctx->gb) != 1)\n bytestream2_skip(&ctx->gb, 4);\n width = bytestream2_get_be32(&ctx->gb);\n height = bytestream2_get_be32(&ctx->gb);\n w = FFALIGN(width, 1 << (NB_LEVELS + 1));\n h = FFALIGN(height, 1 << (NB_LEVELS + 1));\n ctx->levels = bytestream2_get_be32(&ctx->gb);\n if (ctx->levels != NB_LEVELS)\n ctx->depth = bytestream2_get_be32(&ctx->gb);\n if (ctx->depth < 8 || ctx->depth > 15) {\n avpriv_request_sample(avctx, \"Depth %d\", ctx->depth);\n }\n ret = ff_set_dimensions(avctx, w, h);\n if (ret < 0)\n return ret;\n avctx->width = width;\n avctx->height = height;\n if (ctx->w != w || ctx->h != h) {\n free_buffers(avctx);\n ctx->w = w;\n ctx->h = h;\n ret = init_decoder(avctx);\n if (ret < 0) {\n free_buffers(avctx);\n ctx->w = 0;\n ctx->h = 0;\n return ret;\n }\n }\n bytestream2_skip(&ctx->gb, 8);\n p->pict_type = AV_PICTURE_TYPE_I;\n p->key_frame = 1;\n p->color_range = AVCOL_RANGE_JPEG;\n ret = ff_thread_get_buffer(avctx, &frame, 0);\n if (ret < 0)\n return ret;\n for (i = 0; i < 3; i++) {\n ret = decode_plane(avctx, i, avpkt, frame.f);\n if (ret < 0)\n return ret;\n if (avctx->flags & AV_CODEC_FLAG_GRAY)\n break;\n }\n postprocess_luma(frame.f, ctx->w, ctx->h, ctx->depth);\n postprocess_chroma(frame.f, ctx->w >> 1, ctx->h >> 1, ctx->depth);\n *got_frame = 1;\n return pktsize;\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "77d98898211eeb0241e8411428b0b364a6231744", + "length": 735 + }, + { + "index": 1126, + "code": "static int read_tfra(MOVContext *mov, AVIOContext *f)\n\n{\n\n MOVFragmentIndex* index = NULL;\n\n int version, fieldlength, i, j, err;\n\n int64_t pos = avio_tell(f);\n\n uint32_t size = avio_rb32(f);\n\n if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a')) {\n\n return -1;\n\n }\n\n av_log(mov->fc, AV_LOG_VERBOSE, \"found tfra\\n\");\n\n index = av_mallocz(sizeof(MOVFragmentIndex));\n\n if (!index) {\n\n return AVERROR(ENOMEM);\n\n }\n\n mov->fragment_index_count++;\n\n if ((err = av_reallocp(&mov->fragment_index_data,\n\n mov->fragment_index_count *\n\n sizeof(MOVFragmentIndex*))) < 0) {\n\n av_freep(&index);\n\n return err;\n\n }\n\n mov->fragment_index_data[mov->fragment_index_count - 1] =\n\n index;\n\n\n\n version = avio_r8(f);\n\n avio_rb24(f);\n\n index->track_id = avio_rb32(f);\n\n fieldlength = avio_rb32(f);\n\n index->item_count = avio_rb32(f);\n\n index->items = av_mallocz(\n\n index->item_count * sizeof(MOVFragmentIndexItem));\n\n if (!index->items) {\n\n return AVERROR(ENOMEM);\n\n }\n\n for (i = 0; i < index->item_count; i++) {\n\n int64_t time, offset;\n\n if (version == 1) {\n\n time = avio_rb64(f);\n\n offset = avio_rb64(f);\n\n } else {\n\n time = avio_rb32(f);\n\n offset = avio_rb32(f);\n\n }\n\n index->items[i].time = time;\n\n index->items[i].moof_offset = offset;\n\n for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)\n\n avio_r8(f);\n\n for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)\n\n avio_r8(f);\n\n for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)\n\n avio_r8(f);\n\n }\n\n\n\n avio_seek(f, pos + size, SEEK_SET);\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "db42d93a61be26873be6115c57f5921b4dfdec14", + "length": 536 + }, + { + "index": 24557, + "code": "static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable *g)\n\n{\n\n ASFContext *asf = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n uint64_t size;\n\n uint32_t err_data_len, ts_data_len; // type specific data length\n\n uint16_t flags;\n\n ff_asf_guid stream_type;\n\n enum AVMediaType type;\n\n int i, ret;\n\n uint8_t stream_index;\n\n AVStream *st;\n\n ASFStream *asf_st;\n\n\n\n // ASF file must not contain more than 128 streams according to the specification\n\n if (asf->nb_streams >= ASF_MAX_STREAMS)\n\n return AVERROR_INVALIDDATA;\n\n\n\n size = avio_rl64(pb);\n\n ff_get_guid(pb, &stream_type);\n\n if (!ff_guidcmp(&stream_type, &ff_asf_audio_stream))\n\n type = AVMEDIA_TYPE_AUDIO;\n\n else if (!ff_guidcmp(&stream_type, &ff_asf_video_stream))\n\n type = AVMEDIA_TYPE_VIDEO;\n\n else if (!ff_guidcmp(&stream_type, &ff_asf_jfif_media))\n\n type = AVMEDIA_TYPE_VIDEO;\n\n else if (!ff_guidcmp(&stream_type, &ff_asf_command_stream))\n\n type = AVMEDIA_TYPE_DATA;\n\n else if (!ff_guidcmp(&stream_type,\n\n &ff_asf_ext_stream_embed_stream_header))\n\n type = AVMEDIA_TYPE_UNKNOWN;\n\n else\n\n return AVERROR_INVALIDDATA;\n\n\n\n ff_get_guid(pb, &stream_type); // error correction type\n\n avio_skip(pb, 8); // skip the time offset\n\n ts_data_len = avio_rl32(pb);\n\n err_data_len = avio_rl32(pb);\n\n flags = avio_rl16(pb); // bit 15 - Encrypted Content\n\n\n\n stream_index = flags & ASF_STREAM_NUM;\n\n for (i = 0; i < asf->nb_streams; i++)\n\n if (stream_index == asf->asf_st[i]->stream_index) {\n\n av_log(s, AV_LOG_WARNING,\n\n \"Duplicate stream found, this stream will be ignored.\\n\");\n\n align_position(pb, asf->offset, size);\n\n return 0;\n\n }\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n avpriv_set_pts_info(st, 32, 1, 1000); // pts should be dword, in milliseconds\n\n st->codec->codec_type = type;\n\n asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));\n\n if (!asf->asf_st[asf->nb_streams])\n\n return AVERROR(ENOMEM);\n\n asf_st = asf->asf_st[asf->nb_streams];\n\n asf_st->stream_index = stream_index;\n\n asf_st->index = st->index;\n\n asf_st->indexed = 0;\n\n st->id = flags & ASF_STREAM_NUM;\n\n av_init_packet(&asf_st->pkt.avpkt);\n\n asf_st->pkt.data_size = 0;\n\n avio_skip(pb, 4); // skip reserved field\n\n\n\n switch (type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n asf_st->type = AVMEDIA_TYPE_AUDIO;\n\n if ((ret = ff_get_wav_header(s, pb, st->codec, ts_data_len)) < 0)\n\n return ret;\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n asf_st->type = AVMEDIA_TYPE_VIDEO;\n\n if ((ret = parse_video_info(pb, st)) < 0)\n\n return ret;\n\n break;\n\n default:\n\n avio_skip(pb, ts_data_len);\n\n break;\n\n }\n\n\n\n if (err_data_len) {\n\n if (type == AVMEDIA_TYPE_AUDIO) {\n\n uint8_t span = avio_r8(pb);\n\n if (span > 1) {\n\n asf_st->span = span;\n\n asf_st->virtual_pkt_len = avio_rl16(pb);\n\n asf_st->virtual_chunk_len = avio_rl16(pb);\n\n if (!asf_st->virtual_chunk_len || !asf_st->virtual_pkt_len)\n\n return AVERROR_INVALIDDATA;\n\n avio_skip(pb, err_data_len - 5);\n\n } else\n\n avio_skip(pb, err_data_len - 1);\n\n } else\n\n avio_skip(pb, err_data_len);\n\n }\n\n\n\n asf->nb_streams++;\n\n align_position(pb, asf->offset, size);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "aed7715b8fa295980c221f1cd095d42cd3bd74a6", + "length": 1003 + }, + { + "index": 26728, + "code": "static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)\n\n{\n\n OMAContext *oc = s->priv_data;\n\n ID3v2ExtraMetaGEOB *geob = NULL;\n\n uint8_t *gdata;\n\n\n\n oc->encrypted = 1;\n\n av_log(s, AV_LOG_INFO, \"File is encrypted\\n\");\n\n\n\n /* find GEOB metadata */\n\n while (em) {\n\n if (!strcmp(em->tag, \"GEOB\") &&\n\n (geob = em->data) &&\n\n (!strcmp(geob->description, \"OMG_LSI\") ||\n\n !strcmp(geob->description, \"OMG_BKLSI\"))) {\n\n break;\n\n }\n\n em = em->next;\n\n }\n\n if (!em) {\n\n av_log(s, AV_LOG_ERROR, \"No encryption header found\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (geob->datasize < 64) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Invalid GEOB data size: %u\\n\", geob->datasize);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n gdata = geob->data;\n\n\n\n if (AV_RB16(gdata) != 1)\n\n av_log(s, AV_LOG_WARNING, \"Unknown version in encryption header\\n\");\n\n\n\n oc->k_size = AV_RB16(&gdata[2]);\n\n oc->e_size = AV_RB16(&gdata[4]);\n\n oc->i_size = AV_RB16(&gdata[6]);\n\n oc->s_size = AV_RB16(&gdata[8]);\n\n\n\n if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], \"KEYRING \", 12)) {\n\n av_log(s, AV_LOG_ERROR, \"Invalid encryption header\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);\n\n av_log(s, AV_LOG_DEBUG, \"RID: %.8x\\n\", oc->rid);\n\n\n\n memcpy(oc->iv, &header[0x58], 8);\n\n hex_log(s, AV_LOG_DEBUG, \"IV\", oc->iv, 8);\n\n\n\n hex_log(s, AV_LOG_DEBUG, \"CBC-MAC\",\n\n &gdata[OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size + oc->i_size],\n\n 8);\n\n\n\n if (s->keylen > 0) {\n\n kset(s, s->key, s->key, s->keylen);\n\n }\n\n if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||\n\n rprobe(s, gdata, oc->r_val) < 0 &&\n\n nprobe(s, gdata, geob->datasize, oc->n_val) < 0) {\n\n int i;\n\n for (i = 0; i < FF_ARRAY_ELEMS(leaf_table); i += 2) {\n\n uint8_t buf[16];\n\n AV_WL64(buf, leaf_table[i]);\n\n AV_WL64(&buf[8], leaf_table[i + 1]);\n\n kset(s, buf, buf, 16);\n\n if (!rprobe(s, gdata, oc->r_val) ||\n\n !nprobe(s, gdata, geob->datasize, oc->n_val))\n\n break;\n\n }\n\n if (i >= sizeof(leaf_table)) {\n\n av_log(s, AV_LOG_ERROR, \"Invalid key\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n /* e_val */\n\n av_des_init(&oc->av_des, oc->m_val, 64, 0);\n\n av_des_crypt(&oc->av_des, oc->e_val,\n\n &gdata[OMA_ENC_HEADER_SIZE + 40], 1, NULL, 0);\n\n hex_log(s, AV_LOG_DEBUG, \"EK\", oc->e_val, 8);\n\n\n\n /* init e_val */\n\n av_des_init(&oc->av_des, oc->e_val, 64, 1);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "9d0b45ade864f3d2ccd8610149fe1fff53c4e937", + "length": 898 + }, + { + "index": 4517, + "code": "int bdrv_open(BlockDriverState *bs, const char *filename, int flags,\n\n BlockDriver *drv)\n\n{\n\n int ret;\n\n char tmp_filename[PATH_MAX];\n\n\n\n if (flags & BDRV_O_SNAPSHOT) {\n\n BlockDriverState *bs1;\n\n int64_t total_size;\n\n int is_protocol = 0;\n\n BlockDriver *bdrv_qcow2;\n\n QEMUOptionParameter *options;\n\n char backing_filename[PATH_MAX];\n\n\n\n /* if snapshot, we create a temporary backing file and open it\n\n instead of opening 'filename' directly */\n\n\n\n /* if there is a backing file, use it */\n\n bs1 = bdrv_new(\"\");\n\n ret = bdrv_open(bs1, filename, 0, drv);\n\n if (ret < 0) {\n\n bdrv_delete(bs1);\n\n return ret;\n\n }\n\n total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;\n\n\n\n if (bs1->drv && bs1->drv->protocol_name)\n\n is_protocol = 1;\n\n\n\n bdrv_delete(bs1);\n\n\n\n get_tmp_filename(tmp_filename, sizeof(tmp_filename));\n\n\n\n /* Real path is meaningless for protocols */\n\n if (is_protocol)\n\n snprintf(backing_filename, sizeof(backing_filename),\n\n \"%s\", filename);\n\n else if (!realpath(filename, backing_filename))\n\n return -errno;\n\n\n\n bdrv_qcow2 = bdrv_find_format(\"qcow2\");\n\n options = parse_option_parameters(\"\", bdrv_qcow2->create_options, NULL);\n\n\n\n set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size);\n\n set_option_parameter(options, BLOCK_OPT_BACKING_FILE, backing_filename);\n\n if (drv) {\n\n set_option_parameter(options, BLOCK_OPT_BACKING_FMT,\n\n drv->format_name);\n\n }\n\n\n\n ret = bdrv_create(bdrv_qcow2, tmp_filename, options);\n\n free_option_parameters(options);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n filename = tmp_filename;\n\n drv = bdrv_qcow2;\n\n bs->is_temporary = 1;\n\n }\n\n\n\n /* Find the right image format driver */\n\n if (!drv) {\n\n ret = find_image_format(filename, &drv);\n\n }\n\n\n\n if (!drv) {\n\n goto unlink_and_fail;\n\n }\n\n\n\n /* Open the image */\n\n ret = bdrv_open_common(bs, filename, flags, drv);\n\n if (ret < 0) {\n\n goto unlink_and_fail;\n\n }\n\n\n\n /* If there is a backing file, use it */\n\n if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\\0') {\n\n char backing_filename[PATH_MAX];\n\n int back_flags;\n\n BlockDriver *back_drv = NULL;\n\n\n\n bs->backing_hd = bdrv_new(\"\");\n\n bdrv_get_full_backing_filename(bs, backing_filename,\n\n sizeof(backing_filename));\n\n\n\n if (bs->backing_format[0] != '\\0') {\n\n back_drv = bdrv_find_format(bs->backing_format);\n\n }\n\n\n\n /* backing files always opened read-only */\n\n back_flags =\n\n flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);\n\n\n\n ret = bdrv_open(bs->backing_hd, backing_filename, back_flags, back_drv);\n\n if (ret < 0) {\n\n bdrv_close(bs);\n\n return ret;\n\n }\n\n if (bs->is_temporary) {\n\n bs->backing_hd->keep_read_only = !(flags & BDRV_O_RDWR);\n\n } else {\n\n /* base image inherits from \"parent\" */\n\n bs->backing_hd->keep_read_only = bs->keep_read_only;\n\n }\n\n }\n\n\n\n if (!bdrv_key_required(bs)) {\n\n bdrv_dev_change_media_cb(bs, true);\n\n }\n\n\n\n /* throttling disk I/O limits */\n\n if (bs->io_limits_enabled) {\n\n bdrv_io_limits_enable(bs);\n\n }\n\n\n\n return 0;\n\n\n\nunlink_and_fail:\n\n if (bs->is_temporary) {\n\n unlink(filename);\n\n }\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "c2d76497b6eafcaedc806e07804e7bed55a98a0b", + "length": 874 + }, + { + "index": 21562, + "code": "static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,\n\n int ctb_addr_ts)\n\n{\n\n HEVCLocalContext *lc = &s->HEVClc;\n\n int ctb_size = 1 << s->ps.sps->log2_ctb_size;\n\n int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];\n\n int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;\n\n\n\n s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;\n\n\n\n if (s->ps.pps->entropy_coding_sync_enabled_flag) {\n\n if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)\n\n lc->first_qp_group = 1;\n\n lc->end_of_tiles_x = s->ps.sps->width;\n\n } else if (s->ps.pps->tiles_enabled_flag) {\n\n if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {\n\n int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size];\n\n lc->start_of_tiles_x = x_ctb;\n\n lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size);\n\n lc->first_qp_group = 1;\n\n }\n\n } else {\n\n lc->end_of_tiles_x = s->ps.sps->width;\n\n }\n\n\n\n lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height);\n\n\n\n lc->boundary_flags = 0;\n\n if (s->ps.pps->tiles_enabled_flag) {\n\n if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])\n\n lc->boundary_flags |= BOUNDARY_LEFT_TILE;\n\n if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1])\n\n lc->boundary_flags |= BOUNDARY_LEFT_SLICE;\n\n if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]])\n\n lc->boundary_flags |= BOUNDARY_UPPER_TILE;\n\n if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width])\n\n lc->boundary_flags |= BOUNDARY_UPPER_SLICE;\n\n } else {\n\n if (!ctb_addr_in_slice > 0)\n\n lc->boundary_flags |= BOUNDARY_LEFT_SLICE;\n\n if (ctb_addr_in_slice < s->ps.sps->ctb_width)\n\n lc->boundary_flags |= BOUNDARY_UPPER_SLICE;\n\n }\n\n\n\n lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));\n\n lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));\n\n lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]]));\n\n lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]]));\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "b8b13acd70a1c1b6c044f967d78cb82f1a53887b", + "length": 1021 + }, + { + "index": 7379, + "code": "static int dmg_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n BDRVDMGState *s = bs->opaque;\n\n DmgHeaderState ds;\n\n uint64_t rsrc_fork_offset, rsrc_fork_length;\n\n uint64_t plist_xml_offset, plist_xml_length;\n\n int64_t offset;\n\n int ret;\n\n\n\n bs->file = bdrv_open_child(NULL, options, \"file\", bs, &child_file,\n\n false, errp);\n\n if (!bs->file) {\n\n return -EINVAL;\n\n }\n\n\n\n block_module_load_one(\"dmg-bz2\");\n\n bs->read_only = true;\n\n\n\n s->n_chunks = 0;\n\n s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;\n\n /* used by dmg_read_mish_block to keep track of the current I/O position */\n\n ds.data_fork_offset = 0;\n\n ds.max_compressed_size = 1;\n\n ds.max_sectors_per_chunk = 1;\n\n\n\n /* locate the UDIF trailer */\n\n offset = dmg_find_koly_offset(bs->file, errp);\n\n if (offset < 0) {\n\n ret = offset;\n\n goto fail;\n\n }\n\n\n\n /* offset of data fork (DataForkOffset) */\n\n ret = read_uint64(bs, offset + 0x18, &ds.data_fork_offset);\n\n if (ret < 0) {\n\n goto fail;\n\n } else if (ds.data_fork_offset > offset) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n /* offset of resource fork (RsrcForkOffset) */\n\n ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n ret = read_uint64(bs, offset + 0x30, &rsrc_fork_length);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n if (rsrc_fork_offset >= offset ||\n\n rsrc_fork_length > offset - rsrc_fork_offset) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n /* offset of property list (XMLOffset) */\n\n ret = read_uint64(bs, offset + 0xd8, &plist_xml_offset);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n ret = read_uint64(bs, offset + 0xe0, &plist_xml_length);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n if (plist_xml_offset >= offset ||\n\n plist_xml_length > offset - plist_xml_offset) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n if (bs->total_sectors < 0) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n if (rsrc_fork_length != 0) {\n\n ret = dmg_read_resource_fork(bs, &ds,\n\n rsrc_fork_offset, rsrc_fork_length);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n } else if (plist_xml_length != 0) {\n\n ret = dmg_read_plist_xml(bs, &ds, plist_xml_offset, plist_xml_length);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n } else {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n /* initialize zlib engine */\n\n s->compressed_chunk = qemu_try_blockalign(bs->file->bs,\n\n ds.max_compressed_size + 1);\n\n s->uncompressed_chunk = qemu_try_blockalign(bs->file->bs,\n\n 512 * ds.max_sectors_per_chunk);\n\n if (s->compressed_chunk == NULL || s->uncompressed_chunk == NULL) {\n\n ret = -ENOMEM;\n\n goto fail;\n\n }\n\n\n\n if (inflateInit(&s->zstream) != Z_OK) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n s->current_chunk = s->n_chunks;\n\n\n\n qemu_co_mutex_init(&s->lock);\n\n return 0;\n\n\n\nfail:\n\n g_free(s->types);\n\n g_free(s->offsets);\n\n g_free(s->lengths);\n\n g_free(s->sectors);\n\n g_free(s->sectorcounts);\n\n qemu_vfree(s->compressed_chunk);\n\n qemu_vfree(s->uncompressed_chunk);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "fe5241bfe3fb61ec3f589ceacd91c1469bfd400f", + "length": 986 + }, + { + "index": 13613, + "code": "static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv)\n\n{\n\n static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};\n\n MXFContext *mxf = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n int64_t end = avio_tell(pb) + klv->length;\n\n uint64_t size;\n\n uint64_t orig_size;\n\n uint64_t plaintext_size;\n\n uint8_t ivec[16];\n\n uint8_t tmpbuf[16];\n\n int index;\n\n\n\n if (!mxf->aesc && s->key && s->keylen == 16) {\n\n mxf->aesc = av_malloc(av_aes_size);\n\n if (!mxf->aesc)\n\n return -1;\n\n av_aes_init(mxf->aesc, s->key, 128, 1);\n\n }\n\n // crypto context\n\n avio_skip(pb, klv_decode_ber_length(pb));\n\n // plaintext offset\n\n klv_decode_ber_length(pb);\n\n plaintext_size = avio_rb64(pb);\n\n // source klv key\n\n klv_decode_ber_length(pb);\n\n avio_read(pb, klv->key, 16);\n\n if (!IS_KLV_KEY(klv, mxf_essence_element_key))\n\n return -1;\n\n index = mxf_get_stream_index(s, klv);\n\n if (index < 0)\n\n return -1;\n\n // source size\n\n klv_decode_ber_length(pb);\n\n orig_size = avio_rb64(pb);\n\n if (orig_size < plaintext_size)\n\n return -1;\n\n // enc. code\n\n size = klv_decode_ber_length(pb);\n\n if (size < 32 || size - 32 < orig_size)\n\n return -1;\n\n avio_read(pb, ivec, 16);\n\n avio_read(pb, tmpbuf, 16);\n\n if (mxf->aesc)\n\n av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1);\n\n if (memcmp(tmpbuf, checkv, 16))\n\n av_log(s, AV_LOG_ERROR, \"probably incorrect decryption key\\n\");\n\n size -= 32;\n\n size = av_get_packet(pb, pkt, size);\n\n if (size < 0)\n\n return size;\n\n else if (size < plaintext_size)\n\n return AVERROR_INVALIDDATA;\n\n size -= plaintext_size;\n\n if (mxf->aesc)\n\n av_aes_crypt(mxf->aesc, &pkt->data[plaintext_size],\n\n &pkt->data[plaintext_size], size >> 4, ivec, 1);\n\n av_shrink_packet(pkt, orig_size);\n\n pkt->stream_index = index;\n\n avio_skip(pb, end - avio_tell(pb));\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "735e601be1b7731d256a41e942b31a96255a6bec", + "length": 698 + }, + { + "index": 20518, + "code": "static void console_handle_escape(QemuConsole *s)\n\n{\n\n int i;\n\n\n\n for (i=0; inb_esc_params; i++) {\n\n switch (s->esc_params[i]) {\n\n case 0: /* reset all console attributes to default */\n\n s->t_attrib = s->t_attrib_default;\n\n break;\n\n case 1:\n\n s->t_attrib.bold = 1;\n\n break;\n\n case 4:\n\n s->t_attrib.uline = 1;\n\n break;\n\n case 5:\n\n s->t_attrib.blink = 1;\n\n break;\n\n case 7:\n\n s->t_attrib.invers = 1;\n\n break;\n\n case 8:\n\n s->t_attrib.unvisible = 1;\n\n break;\n\n case 22:\n\n s->t_attrib.bold = 0;\n\n break;\n\n case 24:\n\n s->t_attrib.uline = 0;\n\n break;\n\n case 25:\n\n s->t_attrib.blink = 0;\n\n break;\n\n case 27:\n\n s->t_attrib.invers = 0;\n\n break;\n\n case 28:\n\n s->t_attrib.unvisible = 0;\n\n break;\n\n /* set foreground color */\n\n case 30:\n\n s->t_attrib.fgcol=COLOR_BLACK;\n\n break;\n\n case 31:\n\n s->t_attrib.fgcol=COLOR_RED;\n\n break;\n\n case 32:\n\n s->t_attrib.fgcol=COLOR_GREEN;\n\n break;\n\n case 33:\n\n s->t_attrib.fgcol=COLOR_YELLOW;\n\n break;\n\n case 34:\n\n s->t_attrib.fgcol=COLOR_BLUE;\n\n break;\n\n case 35:\n\n s->t_attrib.fgcol=COLOR_MAGENTA;\n\n break;\n\n case 36:\n\n s->t_attrib.fgcol=COLOR_CYAN;\n\n break;\n\n case 37:\n\n s->t_attrib.fgcol=COLOR_WHITE;\n\n break;\n\n /* set background color */\n\n case 40:\n\n s->t_attrib.bgcol=COLOR_BLACK;\n\n break;\n\n case 41:\n\n s->t_attrib.bgcol=COLOR_RED;\n\n break;\n\n case 42:\n\n s->t_attrib.bgcol=COLOR_GREEN;\n\n break;\n\n case 43:\n\n s->t_attrib.bgcol=COLOR_YELLOW;\n\n break;\n\n case 44:\n\n s->t_attrib.bgcol=COLOR_BLUE;\n\n break;\n\n case 45:\n\n s->t_attrib.bgcol=COLOR_MAGENTA;\n\n break;\n\n case 46:\n\n s->t_attrib.bgcol=COLOR_CYAN;\n\n break;\n\n case 47:\n\n s->t_attrib.bgcol=COLOR_WHITE;\n\n break;\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4083733db5e4120939acee57019ff52db1f45b9d", + "length": 593 + }, + { + "index": 13287, + "code": "static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset)\n\n{\n\n uint8_t *prev, *cur;\n\n int blk, blocks, t, blk2;\n\n int blocktypes = 0;\n\n int x, y, a, b;\n\n int pattype, pattern;\n\n const int width = c->avctx->width;\n\n uint8_t *pstart = c->prev_frame;\n\n uint8_t *pend = c->prev_frame + width*c->avctx->height;\n\n\n\n prev = c->prev_frame + offset;\n\n cur = c->frame;\n\n\n\n blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);\n\n blk2 = 0;\n\n for(blk = 0; blk < blocks; blk++){\n\n if(!(blk & 3))\n\n blocktypes = bytestream_get_byte(&buf);\n\n switch(blocktypes & 0xC0){\n\n case 0x00: //skip\n\n for(y = 0; y < 4; y++)\n\n if(check_line(prev + y*width, pstart, pend))\n\n memcpy(cur + y*width, prev + y*width, 4);\n\n else\n\n memset(cur + y*width, 0, 4);\n\n break;\n\n case 0x40:\n\n t = bytestream_get_byte(&buf);\n\n if(!t){ //raw block\n\n for(y = 0; y < 4; y++)\n\n memcpy(cur + y*width, buf + y*4, 4);\n\n buf += 16;\n\n }else{ // motion compensation\n\n x = ((t & 0xF)^8) - 8;\n\n y = ((t >> 4) ^8) - 8;\n\n t = x + y*width;\n\n for(y = 0; y < 4; y++)\n\n if(check_line(prev + t + y*width, pstart, pend))\n\n memcpy(cur + y*width, prev + t + y*width, 4);\n\n else\n\n memset(cur + y*width, 0, 4);\n\n }\n\n break;\n\n case 0x80: // fill\n\n t = bytestream_get_byte(&buf);\n\n for(y = 0; y < 4; y++)\n\n memset(cur + y*width, t, 4);\n\n break;\n\n case 0xC0: // pattern fill\n\n t = bytestream_get_byte(&buf);\n\n pattype = t >> 6;\n\n pattern = vb_patterns[t & 0x3F];\n\n switch(pattype){\n\n case 0:\n\n a = bytestream_get_byte(&buf);\n\n b = bytestream_get_byte(&buf);\n\n for(y = 0; y < 4; y++)\n\n for(x = 0; x < 4; x++, pattern >>= 1)\n\n cur[x + y*width] = (pattern & 1) ? b : a;\n\n break;\n\n case 1:\n\n pattern = ~pattern;\n\n case 2:\n\n a = bytestream_get_byte(&buf);\n\n for(y = 0; y < 4; y++)\n\n for(x = 0; x < 4; x++, pattern >>= 1)\n\n if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))\n\n cur[x + y*width] = prev[x + y*width];\n\n else\n\n cur[x + y*width] = a;\n\n break;\n\n case 3:\n\n av_log(c->avctx, AV_LOG_ERROR, \"Invalid opcode seen @%d\\n\",blk);\n\n return -1;\n\n }\n\n break;\n\n }\n\n blocktypes <<= 2;\n\n cur += 4;\n\n prev += 4;\n\n blk2++;\n\n if(blk2 == (width >> 2)){\n\n blk2 = 0;\n\n cur += width * 3;\n\n prev += width * 3;\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "57835fc1aeaf0b3bbc0816b123a931ea39de758b", + "length": 870 + }, + { + "index": 6691, + "code": "static void stream_component_close(VideoState *is, int stream_index)\n\n{\n\n AVFormatContext *ic = is->ic;\n\n AVCodecContext *avctx;\n\n\n\n if (stream_index < 0 || stream_index >= ic->nb_streams)\n\n return;\n\n avctx = ic->streams[stream_index]->codec;\n\n\n\n switch(avctx->codec_type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n packet_queue_abort(&is->audioq);\n\n\n\n SDL_CloseAudio();\n\n\n\n packet_queue_end(&is->audioq);\n\n av_free_packet(&is->audio_pkt);\n\n if (is->reformat_ctx)\n\n av_audio_convert_free(is->reformat_ctx);\n\n is->reformat_ctx = NULL;\n\n\n\n if (is->rdft) {\n\n av_rdft_end(is->rdft);\n\n av_freep(&is->rdft_data);\n\n\n\n }\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n packet_queue_abort(&is->videoq);\n\n\n\n /* note: we also signal this mutex to make sure we deblock the\n\n video thread in all cases */\n\n SDL_LockMutex(is->pictq_mutex);\n\n SDL_CondSignal(is->pictq_cond);\n\n SDL_UnlockMutex(is->pictq_mutex);\n\n\n\n SDL_WaitThread(is->video_tid, NULL);\n\n\n\n packet_queue_end(&is->videoq);\n\n break;\n\n case AVMEDIA_TYPE_SUBTITLE:\n\n packet_queue_abort(&is->subtitleq);\n\n\n\n /* note: we also signal this mutex to make sure we deblock the\n\n video thread in all cases */\n\n SDL_LockMutex(is->subpq_mutex);\n\n is->subtitle_stream_changed = 1;\n\n\n\n SDL_CondSignal(is->subpq_cond);\n\n SDL_UnlockMutex(is->subpq_mutex);\n\n\n\n SDL_WaitThread(is->subtitle_tid, NULL);\n\n\n\n packet_queue_end(&is->subtitleq);\n\n break;\n\n default:\n\n break;\n\n }\n\n\n\n ic->streams[stream_index]->discard = AVDISCARD_ALL;\n\n avcodec_close(avctx);\n\n switch(avctx->codec_type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n is->audio_st = NULL;\n\n is->audio_stream = -1;\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n is->video_st = NULL;\n\n is->video_stream = -1;\n\n break;\n\n case AVMEDIA_TYPE_SUBTITLE:\n\n is->subtitle_st = NULL;\n\n is->subtitle_stream = -1;\n\n break;\n\n default:\n\n break;\n\n }\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "f9324d5adda6147b3faad5970b6d88263397c76b", + "length": 532 + }, + { + "index": 7664, + "code": "static int check_refcounts_l1(BlockDriverState *bs,\n\n BdrvCheckResult *res,\n\n uint16_t *refcount_table,\n\n int refcount_table_size,\n\n int64_t l1_table_offset, int l1_size,\n\n int flags)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t *l1_table, l2_offset, l1_size2;\n\n int i, ret;\n\n\n\n l1_size2 = l1_size * sizeof(uint64_t);\n\n\n\n /* Mark L1 table as used */\n\n inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l1_table_offset, l1_size2);\n\n\n\n /* Read L1 table entries from disk */\n\n if (l1_size2 == 0) {\n\n l1_table = NULL;\n\n } else {\n\n l1_table = g_malloc(l1_size2);\n\n if (bdrv_pread(bs->file, l1_table_offset,\n\n l1_table, l1_size2) != l1_size2)\n\n goto fail;\n\n for(i = 0;i < l1_size; i++)\n\n be64_to_cpus(&l1_table[i]);\n\n }\n\n\n\n /* Do the actual checks */\n\n for(i = 0; i < l1_size; i++) {\n\n l2_offset = l1_table[i];\n\n if (l2_offset) {\n\n /* Mark L2 table as used */\n\n l2_offset &= L1E_OFFSET_MASK;\n\n inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l2_offset, s->cluster_size);\n\n\n\n /* L2 tables are cluster aligned */\n\n if (offset_into_cluster(s, l2_offset)) {\n\n fprintf(stderr, \"ERROR l2_offset=%\" PRIx64 \": Table is not \"\n\n \"cluster aligned; L1 entry corrupted\\n\", l2_offset);\n\n res->corruptions++;\n\n }\n\n\n\n /* Process and check L2 entries */\n\n ret = check_refcounts_l2(bs, res, refcount_table,\n\n refcount_table_size, l2_offset, flags);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n }\n\n }\n\n g_free(l1_table);\n\n return 0;\n\n\n\nfail:\n\n fprintf(stderr, \"ERROR: I/O error in check_refcounts_l1\\n\");\n\n res->check_errors++;\n\n g_free(l1_table);\n\n return -EIO;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "de82815db1c89da058b7fb941dab137d6d9ab738", + "length": 515 + }, + { + "index": 18299, + "code": "int av_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n int ret, i;\n\n AVStream *st;\n\n\n\n for(;;){\n\n AVPacketList *pktl = s->raw_packet_buffer;\n\n\n\n if (pktl) {\n\n *pkt = pktl->pkt;\n\n if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE ||\n\n !s->streams[pkt->stream_index]->probe_packets){\n\n s->raw_packet_buffer = pktl->next;\n\n av_free(pktl);\n\n return 0;\n\n }\n\n }\n\n\n\n av_init_packet(pkt);\n\n ret= s->iformat->read_packet(s, pkt);\n\n if (ret < 0) {\n\n if (!pktl || ret == AVERROR(EAGAIN))\n\n return ret;\n\n for (i = 0; i < s->nb_streams; i++)\n\n s->streams[i]->probe_packets = 0;\n\n continue;\n\n }\n\n st= s->streams[pkt->stream_index];\n\n\n\n switch(st->codec->codec_type){\n\n case CODEC_TYPE_VIDEO:\n\n if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;\n\n break;\n\n case CODEC_TYPE_AUDIO:\n\n if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id;\n\n break;\n\n case CODEC_TYPE_SUBTITLE:\n\n if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;\n\n break;\n\n }\n\n\n\n if(!pktl && (st->codec->codec_id != CODEC_ID_PROBE ||\n\n !st->probe_packets))\n\n return ret;\n\n\n\n add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end);\n\n\n\n if(st->codec->codec_id == CODEC_ID_PROBE){\n\n AVProbeData *pd = &st->probe_data;\n\n\n\n --st->probe_packets;\n\n\n\n pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);\n\n memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);\n\n pd->buf_size += pkt->size;\n\n memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);\n\n\n\n if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){\n\n set_codec_from_probe_data(st, pd, 1);\n\n if(st->codec->codec_id != CODEC_ID_PROBE){\n\n pd->buf_size=0;\n\n av_freep(&pd->buf);\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "af122d6a80686d9c786b4b46213ef1f5a9699b3e", + "length": 572 + }, + { + "index": 25873, + "code": "static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])\n\n{\n\n int i, a1, b1, c1, d1;\n\n int16_t tmp[16];\n\n\n\n for (i = 0; i < 4; i++) {\n\n a1 = (dc[i * 4 + 0] + dc[i * 4 + 2]) * 23170;\n\n b1 = (dc[i * 4 + 0] - dc[i * 4 + 2]) * 23170;\n\n c1 = dc[i * 4 + 1] * 12540 - dc[i * 4 + 3] * 30274;\n\n d1 = dc[i * 4 + 1] * 30274 + dc[i * 4 + 3] * 12540;\n\n tmp[i * 4 + 0] = (a1 + d1) >> 14;\n\n tmp[i * 4 + 3] = (a1 - d1) >> 14;\n\n tmp[i * 4 + 1] = (b1 + c1) >> 14;\n\n tmp[i * 4 + 2] = (b1 - c1) >> 14;\n\n }\n\n\n\n for (i = 0; i < 4; i++) {\n\n a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;\n\n b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;\n\n c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;\n\n d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;\n\n AV_ZERO64(dc + i * 4);\n\n block[0][i][0] = (a1 + d1 + 0x20000) >> 18;\n\n block[3][i][0] = (a1 - d1 + 0x20000) >> 18;\n\n block[1][i][0] = (b1 + c1 + 0x20000) >> 18;\n\n block[2][i][0] = (b1 - c1 + 0x20000) >> 18;\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ccce2248bf56692fc7bd436ca2c9acca772d486a", + "length": 519 + }, + { + "index": 25694, + "code": "static int resample(SwrContext *s, AudioData *out_param, int out_count,\n\n const AudioData * in_param, int in_count){\n\n AudioData in, out, tmp;\n\n int ret_sum=0;\n\n int border=0;\n\n\n\n av_assert1(s->in_buffer.ch_count == in_param->ch_count);\n\n av_assert1(s->in_buffer.planar == in_param->planar);\n\n av_assert1(s->in_buffer.fmt == in_param->fmt);\n\n\n\n tmp=out=*out_param;\n\n in = *in_param;\n\n\n\n do{\n\n int ret, size, consumed;\n\n if(!s->resample_in_constraint && s->in_buffer_count){\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index);\n\n ret= s->resampler->multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &consumed);\n\n out_count -= ret;\n\n ret_sum += ret;\n\n buf_set(&out, &out, ret);\n\n s->in_buffer_count -= consumed;\n\n s->in_buffer_index += consumed;\n\n\n\n if(!in_count)\n\n break;\n\n if(s->in_buffer_count <= border){\n\n buf_set(&in, &in, -s->in_buffer_count);\n\n in_count += s->in_buffer_count;\n\n s->in_buffer_count=0;\n\n s->in_buffer_index=0;\n\n border = 0;\n\n }\n\n }\n\n\n\n if((s->flushed || in_count) && !s->in_buffer_count){\n\n s->in_buffer_index=0;\n\n ret= s->resampler->multiple_resample(s->resample, &out, out_count, &in, in_count, &consumed);\n\n out_count -= ret;\n\n ret_sum += ret;\n\n buf_set(&out, &out, ret);\n\n in_count -= consumed;\n\n buf_set(&in, &in, consumed);\n\n }\n\n\n\n //TODO is this check sane considering the advanced copy avoidance below\n\n size= s->in_buffer_index + s->in_buffer_count + in_count;\n\n if( size > s->in_buffer.count\n\n && s->in_buffer_count + in_count <= s->in_buffer_index){\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index);\n\n copy(&s->in_buffer, &tmp, s->in_buffer_count);\n\n s->in_buffer_index=0;\n\n }else\n\n if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0)\n\n return ret;\n\n\n\n if(in_count){\n\n int count= in_count;\n\n if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2;\n\n\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);\n\n copy(&tmp, &in, /*in_*/count);\n\n s->in_buffer_count += count;\n\n in_count -= count;\n\n border += count;\n\n buf_set(&in, &in, count);\n\n s->resample_in_constraint= 0;\n\n if(s->in_buffer_count != count || in_count)\n\n continue;\n\n }\n\n break;\n\n }while(1);\n\n\n\n s->resample_in_constraint= !!out_count;\n\n\n\n return ret_sum;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "a6af5da7a2f817d52ea00e2aa93ccf5804afa3e0", + "length": 721 + }, + { + "index": 24200, + "code": "static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion)\n\n{\n\n struct ohci_ed ed;\n\n uint32_t next_ed;\n\n uint32_t cur;\n\n int active;\n\n\n\n active = 0;\n\n\n\n if (head == 0)\n\n return 0;\n\n\n\n for (cur = head; cur; cur = next_ed) {\n\n if (ohci_read_ed(ohci, cur, &ed)) {\n\n trace_usb_ohci_ed_read_error(cur);\n\n ohci_die(ohci);\n\n return 0;\n\n }\n\n\n\n next_ed = ed.next & OHCI_DPTR_MASK;\n\n\n\n if ((ed.head & OHCI_ED_H) || (ed.flags & OHCI_ED_K)) {\n\n uint32_t addr;\n\n /* Cancel pending packets for ED that have been paused. */\n\n addr = ed.head & OHCI_DPTR_MASK;\n\n if (ohci->async_td && addr == ohci->async_td) {\n\n usb_cancel_packet(&ohci->usb_packet);\n\n ohci->async_td = 0;\n\n usb_device_ep_stopped(ohci->usb_packet.ep->dev,\n\n ohci->usb_packet.ep);\n\n }\n\n continue;\n\n }\n\n\n\n while ((ed.head & OHCI_DPTR_MASK) != ed.tail) {\n\n trace_usb_ohci_ed_pkt(cur, (ed.head & OHCI_ED_H) != 0,\n\n (ed.head & OHCI_ED_C) != 0, ed.head & OHCI_DPTR_MASK,\n\n ed.tail & OHCI_DPTR_MASK, ed.next & OHCI_DPTR_MASK);\n\n trace_usb_ohci_ed_pkt_flags(\n\n OHCI_BM(ed.flags, ED_FA), OHCI_BM(ed.flags, ED_EN),\n\n OHCI_BM(ed.flags, ED_D), (ed.flags & OHCI_ED_S)!= 0,\n\n (ed.flags & OHCI_ED_K) != 0, (ed.flags & OHCI_ED_F) != 0,\n\n OHCI_BM(ed.flags, ED_MPS));\n\n\n\n active = 1;\n\n\n\n if ((ed.flags & OHCI_ED_F) == 0) {\n\n if (ohci_service_td(ohci, &ed))\n\n break;\n\n } else {\n\n /* Handle isochronous endpoints */\n\n if (ohci_service_iso_td(ohci, &ed, completion))\n\n break;\n\n }\n\n }\n\n\n\n if (ohci_put_ed(ohci, cur, &ed)) {\n\n ohci_die(ohci);\n\n return 0;\n\n }\n\n }\n\n\n\n return active;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "95ed56939eb2eaa4e2f349fe6dcd13ca4edfd8fb", + "length": 553 + }, + { + "index": 8930, + "code": "static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){\n\n int i, mb_x, mb_y;\n\n uint16_t (*buffer)[4];\n\n int left[3], top[3], topleft[3];\n\n const int linesize= s->linesize[0];\n\n const int mask= (1<bits)-1;\n\n\n\n av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));\n\n buffer= s->ljpeg_buffer;\n\n\n\n for(i=0; i<3; i++){\n\n buffer[0][i]= 1 << (s->bits + point_transform - 1);\n\n }\n\n for(mb_y = 0; mb_y < s->mb_height; mb_y++) {\n\n const int modified_predictor= mb_y ? predictor : 1;\n\n uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);\n\n\n\n if (s->interlaced && s->bottom_field)\n\n ptr += linesize >> 1;\n\n\n\n for(i=0; i<3; i++){\n\n top[i]= left[i]= topleft[i]= buffer[0][i];\n\n }\n\n for(mb_x = 0; mb_x < s->mb_width; mb_x++) {\n\n if (s->restart_interval && !s->restart_count)\n\n s->restart_count = s->restart_interval;\n\n\n\n for(i=0;i<3;i++) {\n\n int pred;\n\n\n\n topleft[i]= top[i];\n\n top[i]= buffer[mb_x][i];\n\n\n\n PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);\n\n\n\n left[i]=\n\n buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));\n\n }\n\n\n\n if (s->restart_interval && !--s->restart_count) {\n\n align_get_bits(&s->gb);\n\n skip_bits(&s->gb, 16); /* skip RSTn */\n\n }\n\n }\n\n\n\n if(s->rct){\n\n for(mb_x = 0; mb_x < s->mb_width; mb_x++) {\n\n ptr[3*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);\n\n ptr[3*mb_x+0] = buffer[mb_x][1] + ptr[3*mb_x+1];\n\n ptr[3*mb_x+2] = buffer[mb_x][2] + ptr[3*mb_x+1];\n\n }\n\n }else if(s->pegasus_rct){\n\n for(mb_x = 0; mb_x < s->mb_width; mb_x++) {\n\n ptr[3*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);\n\n ptr[3*mb_x+0] = buffer[mb_x][1] + ptr[3*mb_x+1];\n\n ptr[3*mb_x+2] = buffer[mb_x][2] + ptr[3*mb_x+1];\n\n }\n\n }else{\n\n for(mb_x = 0; mb_x < s->mb_width; mb_x++) {\n\n ptr[3*mb_x+0] = buffer[mb_x][2];\n\n ptr[3*mb_x+1] = buffer[mb_x][1];\n\n ptr[3*mb_x+2] = buffer[mb_x][0];\n\n }\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "484b1cdd5303771447e15d0067a2034b0c17fdc8", + "length": 812 + }, + { + "index": 4465, + "code": "static int64_t run_opencl_bench(AVOpenCLExternalEnv *ext_opencl_env)\n\n{\n\n int i, arg = 0, width = 1920, height = 1088;\n\n int64_t start, ret = 0;\n\n cl_int status;\n\n size_t kernel_len;\n\n char *inbuf;\n\n int *mask;\n\n int buf_size = width * height * sizeof(char);\n\n int mask_size = sizeof(uint32_t) * 128;\n\n\n\n cl_mem cl_mask, cl_inbuf, cl_outbuf;\n\n cl_kernel kernel = NULL;\n\n cl_program program = NULL;\n\n size_t local_work_size_2d[2] = {16, 16};\n\n size_t global_work_size_2d[2] = {(size_t)width, (size_t)height};\n\n\n\n if (!(inbuf = av_malloc(buf_size)) || !(mask = av_malloc(mask_size))) {\n\n av_log(NULL, AV_LOG_ERROR, \"Out of memory\\n\");\n\n ret = AVERROR(ENOMEM);\n\n goto end;\n\n }\n\n fill_rand_int((int*)inbuf, buf_size/4);\n\n fill_rand_int(mask, mask_size/4);\n\n\n\n CREATEBUF(cl_mask, CL_MEM_READ_ONLY, mask_size);\n\n CREATEBUF(cl_inbuf, CL_MEM_READ_ONLY, buf_size);\n\n CREATEBUF(cl_outbuf, CL_MEM_READ_WRITE, buf_size);\n\n\n\n kernel_len = strlen(ocl_bench_source);\n\n program = clCreateProgramWithSource(ext_opencl_env->context, 1, &ocl_bench_source,\n\n &kernel_len, &status);\n\n if (status != CL_SUCCESS || !program) {\n\n av_log(NULL, AV_LOG_ERROR, \"OpenCL unable to create benchmark program\\n\");\n\n ret = AVERROR_EXTERNAL;\n\n goto end;\n\n }\n\n status = clBuildProgram(program, 1, &(ext_opencl_env->device_id), NULL, NULL, NULL);\n\n if (status != CL_SUCCESS) {\n\n av_log(NULL, AV_LOG_ERROR, \"OpenCL unable to build benchmark program\\n\");\n\n ret = AVERROR_EXTERNAL;\n\n goto end;\n\n }\n\n kernel = clCreateKernel(program, \"unsharp_bench\", &status);\n\n if (status != CL_SUCCESS) {\n\n av_log(NULL, AV_LOG_ERROR, \"OpenCL unable to create benchmark kernel\\n\");\n\n ret = AVERROR_EXTERNAL;\n\n goto end;\n\n }\n\n\n\n OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_inbuf, CL_TRUE, 0,\n\n buf_size, inbuf, 0, NULL, NULL);\n\n OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_mask, CL_TRUE, 0,\n\n mask_size, mask, 0, NULL, NULL);\n\n OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_inbuf);\n\n OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_outbuf);\n\n OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_mask);\n\n OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &width);\n\n OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &height);\n\n\n\n start = av_gettime_relative();\n\n for (i = 0; i < OPENCL_NB_ITER; i++)\n\n OCLCHECK(clEnqueueNDRangeKernel, ext_opencl_env->command_queue, kernel, 2, NULL,\n\n global_work_size_2d, local_work_size_2d, 0, NULL, NULL);\n\n clFinish(ext_opencl_env->command_queue);\n\n ret = (av_gettime_relative() - start)/OPENCL_NB_ITER;\n\nend:\n\n if (kernel)\n\n clReleaseKernel(kernel);\n\n if (program)\n\n clReleaseProgram(program);\n\n if (cl_inbuf)\n\n clReleaseMemObject(cl_inbuf);\n\n if (cl_outbuf)\n\n clReleaseMemObject(cl_outbuf);\n\n if (cl_mask)\n\n clReleaseMemObject(cl_mask);\n\n av_free(inbuf);\n\n av_free(mask);\n\n return ret;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "d712a5cddbfc12e21384f97a291aa64ea7e8005f", + "length": 880 + }, + { + "index": 3890, + "code": "AudioState *AUD_init (void)\n\n{\n\n size_t i;\n\n int done = 0;\n\n const char *drvname;\n\n AudioState *s = &glob_audio_state;\n\n\n\n LIST_INIT (&s->hw_head_out);\n\n LIST_INIT (&s->hw_head_in);\n\n LIST_INIT (&s->cap_head);\n\n atexit (audio_atexit);\n\n\n\n s->ts = qemu_new_timer (vm_clock, audio_timer, s);\n\n if (!s->ts) {\n\n dolog (\"Could not create audio timer\\n\");\n\n return NULL;\n\n }\n\n\n\n audio_process_options (\"AUDIO\", audio_options);\n\n\n\n s->nb_hw_voices_out = conf.fixed_out.nb_voices;\n\n s->nb_hw_voices_in = conf.fixed_in.nb_voices;\n\n\n\n if (s->nb_hw_voices_out <= 0) {\n\n dolog (\"Bogus number of playback voices %d, setting to 1\\n\",\n\n s->nb_hw_voices_out);\n\n s->nb_hw_voices_out = 1;\n\n }\n\n\n\n if (s->nb_hw_voices_in <= 0) {\n\n dolog (\"Bogus number of capture voices %d, setting to 0\\n\",\n\n s->nb_hw_voices_in);\n\n s->nb_hw_voices_in = 0;\n\n }\n\n\n\n {\n\n int def;\n\n drvname = audio_get_conf_str (\"QEMU_AUDIO_DRV\", NULL, &def);\n\n }\n\n\n\n if (drvname) {\n\n int found = 0;\n\n\n\n for (i = 0; i < ARRAY_SIZE (drvtab); i++) {\n\n if (!strcmp (drvname, drvtab[i]->name)) {\n\n done = !audio_driver_init (s, drvtab[i]);\n\n found = 1;\n\n break;\n\n }\n\n }\n\n\n\n if (!found) {\n\n dolog (\"Unknown audio driver `%s'\\n\", drvname);\n\n dolog (\"Run with -audio-help to list available drivers\\n\");\n\n }\n\n }\n\n\n\n if (!done) {\n\n for (i = 0; !done && i < ARRAY_SIZE (drvtab); i++) {\n\n if (drvtab[i]->can_be_default) {\n\n done = !audio_driver_init (s, drvtab[i]);\n\n }\n\n }\n\n }\n\n\n\n if (!done) {\n\n done = !audio_driver_init (s, &no_audio_driver);\n\n if (!done) {\n\n dolog (\"Could not initialize audio subsystem\\n\");\n\n }\n\n else {\n\n dolog (\"warning: Using timer based audio emulation\\n\");\n\n }\n\n }\n\n\n\n if (done) {\n\n VMChangeStateEntry *e;\n\n\n\n if (conf.period.hertz <= 0) {\n\n if (conf.period.hertz < 0) {\n\n dolog (\"warning: Timer period is negative - %d \"\n\n \"treating as zero\\n\",\n\n conf.period.hertz);\n\n }\n\n conf.period.ticks = 1;\n\n }\n\n else {\n\n conf.period.ticks = ticks_per_sec / conf.period.hertz;\n\n }\n\n\n\n e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);\n\n if (!e) {\n\n dolog (\"warning: Could not register change state handler\\n\"\n\n \"(Audio can continue looping even after stopping the VM)\\n\");\n\n }\n\n }\n\n else {\n\n qemu_del_timer (s->ts);\n\n return NULL;\n\n }\n\n\n\n LIST_INIT (&s->card_head);\n\n register_savevm (\"audio\", 0, 1, audio_save, audio_load, s);\n\n qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);\n\n return s;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "0d9acba8fddbf970c7353083e6a60b47017ce3e4", + "length": 779 + }, + { + "index": 5144, + "code": "static int gif_read_image(GifState *s)\n\n{\n\n int left, top, width, height, bits_per_pixel, code_size, flags;\n\n int is_interleaved, has_local_palette, y, pass, y1, linesize, n, i;\n\n uint8_t *ptr, *spal, *palette, *ptr1;\n\n\n\n left = bytestream_get_le16(&s->bytestream);\n\n top = bytestream_get_le16(&s->bytestream);\n\n width = bytestream_get_le16(&s->bytestream);\n\n height = bytestream_get_le16(&s->bytestream);\n\n flags = bytestream_get_byte(&s->bytestream);\n\n is_interleaved = flags & 0x40;\n\n has_local_palette = flags & 0x80;\n\n bits_per_pixel = (flags & 0x07) + 1;\n\n\n\n av_dlog(s->avctx, \"gif: image x=%d y=%d w=%d h=%d\\n\", left, top, width, height);\n\n\n\n if (has_local_palette) {\n\n bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel));\n\n palette = s->local_palette;\n\n } else {\n\n palette = s->global_palette;\n\n bits_per_pixel = s->bits_per_pixel;\n\n }\n\n\n\n /* verify that all the image is inside the screen dimensions */\n\n if (left + width > s->screen_width ||\n\n top + height > s->screen_height)\n\n return AVERROR(EINVAL);\n\n\n\n /* build the palette */\n\n n = (1 << bits_per_pixel);\n\n spal = palette;\n\n for(i = 0; i < n; i++) {\n\n s->image_palette[i] = (0xff << 24) | AV_RB24(spal);\n\n spal += 3;\n\n }\n\n for(; i < 256; i++)\n\n s->image_palette[i] = (0xff << 24);\n\n /* handle transparency */\n\n if (s->transparent_color_index >= 0)\n\n s->image_palette[s->transparent_color_index] = 0;\n\n\n\n /* now get the image data */\n\n code_size = bytestream_get_byte(&s->bytestream);\n\n ff_lzw_decode_init(s->lzw, code_size, s->bytestream,\n\n s->bytestream_end - s->bytestream, FF_LZW_GIF);\n\n\n\n /* read all the image */\n\n linesize = s->picture.linesize[0];\n\n ptr1 = s->picture.data[0] + top * linesize + left;\n\n ptr = ptr1;\n\n pass = 0;\n\n y1 = 0;\n\n for (y = 0; y < height; y++) {\n\n ff_lzw_decode(s->lzw, ptr, width);\n\n if (is_interleaved) {\n\n switch(pass) {\n\n default:\n\n case 0:\n\n case 1:\n\n y1 += 8;\n\n ptr += linesize * 8;\n\n if (y1 >= height) {\n\n y1 = pass ? 2 : 4;\n\n ptr = ptr1 + linesize * y1;\n\n pass++;\n\n }\n\n break;\n\n case 2:\n\n y1 += 4;\n\n ptr += linesize * 4;\n\n if (y1 >= height) {\n\n y1 = 1;\n\n ptr = ptr1 + linesize;\n\n pass++;\n\n }\n\n break;\n\n case 3:\n\n y1 += 2;\n\n ptr += linesize * 2;\n\n break;\n\n }\n\n } else {\n\n ptr += linesize;\n\n }\n\n }\n\n /* read the garbage data until end marker is found */\n\n ff_lzw_decode_tail(s->lzw);\n\n s->bytestream = ff_lzw_cur_ptr(s->lzw);\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "3bd1162a52cafc1bb758b25636e857c94fd3999c", + "length": 842 + }, + { + "index": 25056, + "code": "static int mpeg_decode_frame(AVCodecContext *avctx, \n\n void *data, int *data_size,\n\n uint8_t *buf, int buf_size)\n\n{\n\n Mpeg1Context *s = avctx->priv_data;\n\n uint8_t *buf_end, *buf_ptr;\n\n int ret, start_code, input_size;\n\n AVFrame *picture = data;\n\n MpegEncContext *s2 = &s->mpeg_enc_ctx;\n\n dprintf(\"fill_buffer\\n\");\n\n\n\n *data_size = 0;\n\n\n\n /* special case for last picture */\n\n if (buf_size == 0) {\n\n if (s2->picture_number > 0) {\n\n *picture= *(AVFrame*)&s2->next_picture;\n\n\n\n *data_size = sizeof(AVFrame);\n\n }\n\n return 0;\n\n }\n\n\n\n if(s2->flags&CODEC_FLAG_TRUNCATED){\n\n int next;\n\n \n\n next= mpeg1_find_frame_end(s2, buf, buf_size);\n\n \n\n if( ff_combine_frame(s2, next, &buf, &buf_size) < 0 )\n\n return buf_size;\n\n } \n\n \n\n buf_ptr = buf;\n\n buf_end = buf + buf_size;\n\n\n\n#if 0 \n\n if (s->repeat_field % 2 == 1) { \n\n s->repeat_field++;\n\n //fprintf(stderr,\"\\nRepeating last frame: %d -> %d! pict: %d %d\", avctx->frame_number-1, avctx->frame_number,\n\n // s2->picture_number, s->repeat_field);\n\n if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {\n\n *data_size = sizeof(AVPicture);\n\n goto the_end;\n\n }\n\n }\n\n#endif\n\n for(;;) {\n\n /* find start next code */\n\n start_code = find_start_code(&buf_ptr, buf_end);\n\n if (start_code < 0){ \n\n printf(\"missing end of picture\\n\");\n\n return FFMAX(1, buf_ptr - buf - s2->parse_context.last_index);\n\n }\n\n\n\n /* prepare data for next start code */\n\n input_size = buf_end - buf_ptr;\n\n switch(start_code) {\n\n case SEQ_START_CODE:\n\n mpeg1_decode_sequence(avctx, buf_ptr, \n\n input_size);\n\n break;\n\n \n\n case PICTURE_START_CODE:\n\n /* we have a complete image : we try to decompress it */\n\n mpeg1_decode_picture(avctx, \n\n buf_ptr, input_size);\n\n break;\n\n case EXT_START_CODE:\n\n mpeg_decode_extension(avctx,\n\n buf_ptr, input_size);\n\n break;\n\n case USER_START_CODE:\n\n mpeg_decode_user_data(avctx, \n\n buf_ptr, input_size);\n\n break;\n\n default:\n\n if (start_code >= SLICE_MIN_START_CODE &&\n\n start_code <= SLICE_MAX_START_CODE) {\n\n \n\n /* skip b frames if we dont have reference frames */\n\n if(s2->last_picture_ptr==NULL && s2->pict_type==B_TYPE) break;\n\n /* skip b frames if we are in a hurry */\n\n if(avctx->hurry_up && s2->pict_type==B_TYPE) break;\n\n /* skip everything if we are in a hurry>=5 */\n\n if(avctx->hurry_up>=5) break;\n\n \n\n if (!s->mpeg_enc_ctx_allocated) break;\n\n\n\n ret = mpeg_decode_slice(avctx, picture,\n\n start_code, &buf_ptr, input_size);\n\n\n\n if (ret == DECODE_SLICE_EOP) {\n\n if(s2->last_picture_ptr) //FIXME merge with the stuff in mpeg_decode_slice\n\n *data_size = sizeof(AVPicture);\n\n return FFMAX(1, buf_ptr - buf - s2->parse_context.last_index);\n\n }else if(ret < 0){\n\n if(ret == DECODE_SLICE_ERROR)\n\n ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);\n\n \n\n fprintf(stderr,\"Error while decoding slice\\n\");\n\n\t\t\t if(ret==DECODE_SLICE_FATAL_ERROR) return -1;\n\n }\n\n }\n\n break;\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "bb463d81020a2f3c5cf3403e18f980171773f48a", + "length": 915 + }, + { + "index": 8992, + "code": "static void asf_build_simple_index(AVFormatContext *s, int stream_index)\n\n{\n\n ff_asf_guid g;\n\n ASFContext *asf = s->priv_data;\n\n int64_t current_pos= avio_tell(s->pb);\n\n int i;\n\n\n\n avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);\n\n ff_get_guid(s->pb, &g);\n\n\n\n /* the data object can be followed by other top-level objects,\n\n skip them until the simple index object is reached */\n\n while (ff_guidcmp(&g, &index_guid)) {\n\n int64_t gsize= avio_rl64(s->pb);\n\n if (gsize < 24 || url_feof(s->pb)) {\n\n avio_seek(s->pb, current_pos, SEEK_SET);\n\n return;\n\n }\n\n avio_skip(s->pb, gsize-24);\n\n ff_get_guid(s->pb, &g);\n\n }\n\n\n\n {\n\n int64_t itime, last_pos=-1;\n\n int pct, ict;\n\n int64_t av_unused gsize= avio_rl64(s->pb);\n\n ff_get_guid(s->pb, &g);\n\n itime=avio_rl64(s->pb);\n\n pct=avio_rl32(s->pb);\n\n ict=avio_rl32(s->pb);\n\n av_log(s, AV_LOG_DEBUG, \"itime:0x%\"PRIx64\", pct:%d, ict:%d\\n\",itime,pct,ict);\n\n\n\n for (i=0;ipb);\n\n int pktct =avio_rl16(s->pb);\n\n int64_t pos = s->data_offset + s->packet_size*(int64_t)pktnum;\n\n int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);\n\n\n\n if(pos != last_pos){\n\n av_log(s, AV_LOG_DEBUG, \"pktnum:%d, pktct:%d pts: %\"PRId64\"\\n\", pktnum, pktct, index_pts);\n\n av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);\n\n last_pos=pos;\n\n }\n\n }\n\n asf->index_read= 1;\n\n }\n\n avio_seek(s->pb, current_pos, SEEK_SET);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "ac1d489320f476c18d6a8125f73389aecb73f3d3", + "length": 538 + }, + { + "index": 5826, + "code": "static void sha1_transform(uint32_t state[5], const uint8_t buffer[64])\n\n{\n\n uint32_t block[80];\n\n unsigned int i, a, b, c, d, e;\n\n\n\n a = state[0];\n\n b = state[1];\n\n c = state[2];\n\n d = state[3];\n\n e = state[4];\n\n#if CONFIG_SMALL\n\n for (i = 0; i < 80; i++) {\n\n int t;\n\n if (i < 16)\n\n t = AV_RB32(buffer + 4 * i);\n\n else\n\n t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1);\n\n block[i] = t;\n\n t += e + rol(a, 5);\n\n if (i < 40) {\n\n if (i < 20)\n\n t += ((b&(c^d))^d) + 0x5A827999;\n\n else\n\n t += ( b^c ^d) + 0x6ED9EBA1;\n\n } else {\n\n if (i < 60)\n\n t += (((b|c)&d)|(b&c)) + 0x8F1BBCDC;\n\n else\n\n t += ( b^c ^d) + 0xCA62C1D6;\n\n }\n\n e = d;\n\n d = c;\n\n c = rol(b, 30);\n\n b = a;\n\n a = t;\n\n }\n\n#else\n\n for (i = 0; i < 15; i += 5) {\n\n R0(a, b, c, d, e, 0 + i);\n\n R0(e, a, b, c, d, 1 + i);\n\n R0(d, e, a, b, c, 2 + i);\n\n R0(c, d, e, a, b, 3 + i);\n\n R0(b, c, d, e, a, 4 + i);\n\n }\n\n R0(a, b, c, d, e, 15);\n\n R1(e, a, b, c, d, 16);\n\n R1(d, e, a, b, c, 17);\n\n R1(c, d, e, a, b, 18);\n\n R1(b, c, d, e, a, 19);\n\n for (i = 20; i < 40; i += 5) {\n\n R2(a, b, c, d, e, 0 + i);\n\n R2(e, a, b, c, d, 1 + i);\n\n R2(d, e, a, b, c, 2 + i);\n\n R2(c, d, e, a, b, 3 + i);\n\n R2(b, c, d, e, a, 4 + i);\n\n }\n\n for (; i < 60; i += 5) {\n\n R3(a, b, c, d, e, 0 + i);\n\n R3(e, a, b, c, d, 1 + i);\n\n R3(d, e, a, b, c, 2 + i);\n\n R3(c, d, e, a, b, 3 + i);\n\n R3(b, c, d, e, a, 4 + i);\n\n }\n\n for (; i < 80; i += 5) {\n\n R4(a, b, c, d, e, 0 + i);\n\n R4(e, a, b, c, d, 1 + i);\n\n R4(d, e, a, b, c, 2 + i);\n\n R4(c, d, e, a, b, 3 + i);\n\n R4(b, c, d, e, a, 4 + i);\n\n }\n\n#endif\n\n state[0] += a;\n\n state[1] += b;\n\n state[2] += c;\n\n state[3] += d;\n\n state[4] += e;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "7e4fe5162ab94a413e04caae19193c5e7a4c6478", + "length": 894 + }, + { + "index": 1148, + "code": "int ff_get_qtpalette(int codec_id, AVIOContext *pb, uint32_t *palette)\n\n{\n\n int tmp, bit_depth, color_table_id, greyscale, i;\n\n\n\n avio_seek(pb, 82, SEEK_CUR);\n\n\n\n /* Get the bit depth and greyscale state */\n\n tmp = avio_rb16(pb);\n\n bit_depth = tmp & 0x1F;\n\n greyscale = tmp & 0x20;\n\n\n\n /* Get the color table ID */\n\n color_table_id = avio_rb16(pb);\n\n\n\n /* Do not create a greyscale palette for Cinepak */\n\n if (greyscale && codec_id == AV_CODEC_ID_CINEPAK)\n\n return 0;\n\n\n\n /* If the depth is 1, 2, 4, or 8 bpp, file is palettized. */\n\n if ((bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8)) {\n\n int color_count, color_start, color_end;\n\n uint32_t a, r, g, b;\n\n\n\n /* Ignore the greyscale bit for 1-bit video and sample\n\n * descriptions containing a color table. */\n\n if (greyscale && bit_depth > 1 && color_table_id) {\n\n int color_index, color_dec;\n\n /* compute the greyscale palette */\n\n color_count = 1 << bit_depth;\n\n color_index = 255;\n\n color_dec = 256 / (color_count - 1);\n\n for (i = 0; i < color_count; i++) {\n\n r = g = b = color_index;\n\n palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b);\n\n color_index -= color_dec;\n\n if (color_index < 0)\n\n color_index = 0;\n\n }\n\n } else if (color_table_id) {\n\n /* The color table ID is non-zero. Interpret this as\n\n * being -1, which means use the default Macintosh\n\n * color table */\n\n const uint8_t *color_table;\n\n color_count = 1 << bit_depth;\n\n if (bit_depth == 1)\n\n color_table = ff_qt_default_palette_2;\n\n else if (bit_depth == 2)\n\n color_table = ff_qt_default_palette_4;\n\n else if (bit_depth == 4)\n\n color_table = ff_qt_default_palette_16;\n\n else\n\n color_table = ff_qt_default_palette_256;\n\n for (i = 0; i < color_count; i++) {\n\n r = color_table[i * 3 + 0];\n\n g = color_table[i * 3 + 1];\n\n b = color_table[i * 3 + 2];\n\n palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b);\n\n }\n\n } else {\n\n /* The color table ID is 0; the color table is in the sample\n\n * description */\n\n color_start = avio_rb32(pb);\n\n avio_rb16(pb); /* color table flags */\n\n color_end = avio_rb16(pb);\n\n if ((color_start <= 255) && (color_end <= 255)) {\n\n for (i = color_start; i <= color_end; i++) {\n\n /* each A, R, G, or B component is 16 bits;\n\n * only use the top 8 bits */\n\n a = avio_r8(pb);\n\n avio_r8(pb);\n\n r = avio_r8(pb);\n\n avio_r8(pb);\n\n g = avio_r8(pb);\n\n avio_r8(pb);\n\n b = avio_r8(pb);\n\n avio_r8(pb);\n\n palette[i] = (a << 24 ) | (r << 16) | (g << 8) | (b);\n\n }\n\n }\n\n }\n\n\n\n return 1;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "63c9b30f98ce7d160b3a6dec1b36dc05fbb71941", + "length": 860 + }, + { + "index": 22574, + "code": "static int cpu_mips_register (CPUMIPSState *env, const mips_def_t *def)\n\n{\n\n env->CP0_PRid = def->CP0_PRid;\n\n env->CP0_Config0 = def->CP0_Config0;\n\n#ifdef TARGET_WORDS_BIGENDIAN\n\n env->CP0_Config0 |= (1 << CP0C0_BE);\n\n#endif\n\n env->CP0_Config1 = def->CP0_Config1;\n\n env->CP0_Config2 = def->CP0_Config2;\n\n env->CP0_Config3 = def->CP0_Config3;\n\n env->CP0_Config6 = def->CP0_Config6;\n\n env->CP0_Config7 = def->CP0_Config7;\n\n env->SYNCI_Step = def->SYNCI_Step;\n\n env->CCRes = def->CCRes;\n\n env->CP0_Status_rw_bitmask = def->CP0_Status_rw_bitmask;\n\n env->CP0_TCStatus_rw_bitmask = def->CP0_TCStatus_rw_bitmask;\n\n env->CP0_SRSCtl = def->CP0_SRSCtl;\n\n env->current_tc = 0;\n\n env->SEGBITS = def->SEGBITS;\n\n env->SEGMask = (target_ulong)((1ULL << def->SEGBITS) - 1);\n\n#if defined(TARGET_MIPS64)\n\n if (def->insn_flags & ISA_MIPS3) {\n\n env->hflags |= MIPS_HFLAG_64;\n\n env->SEGMask |= 3ULL << 62;\n\n }\n\n#endif\n\n env->PABITS = def->PABITS;\n\n env->PAMask = (target_ulong)((1ULL << def->PABITS) - 1);\n\n env->CP0_SRSConf0_rw_bitmask = def->CP0_SRSConf0_rw_bitmask;\n\n env->CP0_SRSConf0 = def->CP0_SRSConf0;\n\n env->CP0_SRSConf1_rw_bitmask = def->CP0_SRSConf1_rw_bitmask;\n\n env->CP0_SRSConf1 = def->CP0_SRSConf1;\n\n env->CP0_SRSConf2_rw_bitmask = def->CP0_SRSConf2_rw_bitmask;\n\n env->CP0_SRSConf2 = def->CP0_SRSConf2;\n\n env->CP0_SRSConf3_rw_bitmask = def->CP0_SRSConf3_rw_bitmask;\n\n env->CP0_SRSConf3 = def->CP0_SRSConf3;\n\n env->CP0_SRSConf4_rw_bitmask = def->CP0_SRSConf4_rw_bitmask;\n\n env->CP0_SRSConf4 = def->CP0_SRSConf4;\n\n env->insn_flags = def->insn_flags;\n\n\n\n#ifndef CONFIG_USER_ONLY\n\n mmu_init(env, def);\n\n#endif\n\n fpu_init(env, def);\n\n mvp_init(env, def);\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "51cc2e783af5586b2e742ce9e5b2762dc50ad325", + "length": 639 + }, + { + "index": 27058, + "code": "cpu_x86_dump_seg_cache(CPUState *env, FILE *f, fprintf_function cpu_fprintf,\n\n const char *name, struct SegmentCache *sc)\n\n{\n\n#ifdef TARGET_X86_64\n\n if (env->hflags & HF_CS64_MASK) {\n\n cpu_fprintf(f, \"%-3s=%04x %016\" PRIx64 \" %08x %08x\", name,\n\n sc->selector, sc->base, sc->limit, sc->flags);\n\n } else\n\n#endif\n\n {\n\n cpu_fprintf(f, \"%-3s=%04x %08x %08x %08x\", name, sc->selector,\n\n (uint32_t)sc->base, sc->limit, sc->flags);\n\n }\n\n\n\n if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK))\n\n goto done;\n\n\n\n cpu_fprintf(f, \" DPL=%d \", (sc->flags & DESC_DPL_MASK) >> DESC_DPL_SHIFT);\n\n if (sc->flags & DESC_S_MASK) {\n\n if (sc->flags & DESC_CS_MASK) {\n\n cpu_fprintf(f, (sc->flags & DESC_L_MASK) ? \"CS64\" :\n\n ((sc->flags & DESC_B_MASK) ? \"CS32\" : \"CS16\"));\n\n cpu_fprintf(f, \" [%c%c\", (sc->flags & DESC_C_MASK) ? 'C' : '-',\n\n (sc->flags & DESC_R_MASK) ? 'R' : '-');\n\n } else {\n\n cpu_fprintf(f, (sc->flags & DESC_B_MASK) ? \"DS \" : \"DS16\");\n\n cpu_fprintf(f, \" [%c%c\", (sc->flags & DESC_E_MASK) ? 'E' : '-',\n\n (sc->flags & DESC_W_MASK) ? 'W' : '-');\n\n }\n\n cpu_fprintf(f, \"%c]\", (sc->flags & DESC_A_MASK) ? 'A' : '-');\n\n } else {\n\n static const char *sys_type_name[2][16] = {\n\n { /* 32 bit mode */\n\n \"Reserved\", \"TSS16-avl\", \"LDT\", \"TSS16-busy\",\n\n \"CallGate16\", \"TaskGate\", \"IntGate16\", \"TrapGate16\",\n\n \"Reserved\", \"TSS32-avl\", \"Reserved\", \"TSS32-busy\",\n\n \"CallGate32\", \"Reserved\", \"IntGate32\", \"TrapGate32\"\n\n },\n\n { /* 64 bit mode */\n\n \"\", \"Reserved\", \"LDT\", \"Reserved\", \"Reserved\",\n\n \"Reserved\", \"Reserved\", \"Reserved\", \"Reserved\",\n\n \"TSS64-avl\", \"Reserved\", \"TSS64-busy\", \"CallGate64\",\n\n \"Reserved\", \"IntGate64\", \"TrapGate64\"\n\n }\n\n };\n\n cpu_fprintf(f, \"%s\",\n\n sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0]\n\n [(sc->flags & DESC_TYPE_MASK)\n\n >> DESC_TYPE_SHIFT]);\n\n }\n\ndone:\n\n cpu_fprintf(f, \"\\n\");\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4058fd98fd7e9c476774717adbd49698dd273166", + "length": 678 + }, + { + "index": 24132, + "code": "static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,\n\n AVFormatContext *s)\n\n{\n\n int i;\n\n int64_t pos = avio_tell(pb);\n\n avio_wb32(pb, 0); /* size placeholder*/\n\n ffio_wfourcc(pb, \"moov\");\n\n\n\n for (i = 0; i < mov->nb_streams; i++) {\n\n if (mov->tracks[i].entry <= 0 && !(mov->flags & FF_MOV_FLAG_FRAGMENT))\n\n continue;\n\n\n\n mov->tracks[i].time = mov->time;\n\n mov->tracks[i].track_id = i + 1;\n\n\n\n if (mov->tracks[i].entry)\n\n build_chunks(&mov->tracks[i]);\n\n }\n\n\n\n if (mov->chapter_track)\n\n for (i = 0; i < s->nb_streams; i++) {\n\n mov->tracks[i].tref_tag = MKTAG('c','h','a','p');\n\n mov->tracks[i].tref_id = mov->tracks[mov->chapter_track].track_id;\n\n }\n\n for (i = 0; i < mov->nb_streams; i++) {\n\n if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) {\n\n mov->tracks[i].tref_tag = MKTAG('h','i','n','t');\n\n mov->tracks[i].tref_id =\n\n mov->tracks[mov->tracks[i].src_track].track_id;\n\n }\n\n }\n\n for (i = 0; i < mov->nb_streams; i++) {\n\n if (mov->tracks[i].tag == MKTAG('t','m','c','d')) {\n\n int src_trk = mov->tracks[i].src_track;\n\n mov->tracks[src_trk].tref_tag = mov->tracks[i].tag;\n\n mov->tracks[src_trk].tref_id = mov->tracks[i].track_id;\n\n //src_trk may have a different timescale than the tmcd track\n\n mov->tracks[i].track_duration = av_rescale(mov->tracks[src_trk].track_duration,\n\n mov->tracks[i].timescale,\n\n mov->tracks[src_trk].timescale);\n\n }\n\n }\n\n\n\n mov_write_mvhd_tag(pb, mov);\n\n if (mov->mode != MODE_MOV && !mov->iods_skip)\n\n mov_write_iods_tag(pb, mov);\n\n for (i = 0; i < mov->nb_streams; i++) {\n\n if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) {\n\n mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);\n\n }\n\n }\n\n if (mov->flags & FF_MOV_FLAG_FRAGMENT)\n\n mov_write_mvex_tag(pb, mov); /* QuickTime requires trak to precede this */\n\n\n\n if (mov->mode == MODE_PSP)\n\n mov_write_uuidusmt_tag(pb, s);\n\n else\n\n mov_write_udta_tag(pb, mov, s);\n\n\n\n return update_size(pb, pos);\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "da048c6d24729d3bab6ccb0ac340ea129e3e88d5", + "length": 680 + }, + { + "index": 12545, + "code": "static int get_phys_addr_v5(CPUState *env, uint32_t address, int access_type,\n\n\t\t\t int is_user, uint32_t *phys_ptr, int *prot)\n\n{\n\n int code;\n\n uint32_t table;\n\n uint32_t desc;\n\n int type;\n\n int ap;\n\n int domain;\n\n uint32_t phys_addr;\n\n\n\n /* Pagetable walk. */\n\n /* Lookup l1 descriptor. */\n\n table = get_level1_table_address(env, address);\n\n desc = ldl_phys(table);\n\n type = (desc & 3);\n\n domain = (env->cp15.c3 >> ((desc >> 4) & 0x1e)) & 3;\n\n if (type == 0) {\n\n /* Section translation fault. */\n\n code = 5;\n\n goto do_fault;\n\n }\n\n if (domain == 0 || domain == 2) {\n\n if (type == 2)\n\n code = 9; /* Section domain fault. */\n\n else\n\n code = 11; /* Page domain fault. */\n\n goto do_fault;\n\n }\n\n if (type == 2) {\n\n /* 1Mb section. */\n\n phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);\n\n ap = (desc >> 10) & 3;\n\n code = 13;\n\n } else {\n\n /* Lookup l2 entry. */\n\n\tif (type == 1) {\n\n\t /* Coarse pagetable. */\n\n\t table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);\n\n\t} else {\n\n\t /* Fine pagetable. */\n\n\t table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);\n\n\t}\n\n desc = ldl_phys(table);\n\n switch (desc & 3) {\n\n case 0: /* Page translation fault. */\n\n code = 7;\n\n goto do_fault;\n\n case 1: /* 64k page. */\n\n phys_addr = (desc & 0xffff0000) | (address & 0xffff);\n\n ap = (desc >> (4 + ((address >> 13) & 6))) & 3;\n\n break;\n\n case 2: /* 4k page. */\n\n phys_addr = (desc & 0xfffff000) | (address & 0xfff);\n\n ap = (desc >> (4 + ((address >> 13) & 6))) & 3;\n\n break;\n\n case 3: /* 1k page. */\n\n\t if (type == 1) {\n\n\t\tif (arm_feature(env, ARM_FEATURE_XSCALE)) {\n\n\t\t phys_addr = (desc & 0xfffff000) | (address & 0xfff);\n\n\t\t} else {\n\n\t\t /* Page translation fault. */\n\n\t\t code = 7;\n\n\t\t goto do_fault;\n\n\t\t}\n\n\t } else {\n\n\t\tphys_addr = (desc & 0xfffffc00) | (address & 0x3ff);\n\n\t }\n\n ap = (desc >> 4) & 3;\n\n break;\n\n default:\n\n /* Never happens, but compiler isn't smart enough to tell. */\n\n abort();\n\n }\n\n code = 15;\n\n }\n\n *prot = check_ap(env, ap, domain, access_type, is_user);\n\n if (!*prot) {\n\n /* Access permission fault. */\n\n goto do_fault;\n\n }\n\n *phys_ptr = phys_addr;\n\n return 0;\n\ndo_fault:\n\n return code | (domain << 4);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d4c430a80f000d722bb70287af4d4c184a8d7006", + "length": 781 + }, + { + "index": 9659, + "code": "void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)\n\n{\n\n int i;\n\n int16_t *ac_val, *ac_val1;\n\n int8_t *const qscale_table = s->current_picture.qscale_table;\n\n\n\n /* find prediction */\n\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n\n ac_val1 = ac_val;\n\n if (s->ac_pred) {\n\n if (dir == 0) {\n\n const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride;\n\n /* left prediction */\n\n ac_val -= 16;\n\n\n\n if (s->mb_x == 0 || s->qscale == qscale_table[xy] ||\n\n n == 1 || n == 3) {\n\n /* same qscale */\n\n for (i = 1; i < 8; i++)\n\n block[s->idsp.idct_permutation[i << 3]] += ac_val[i];\n\n } else {\n\n /* different qscale, we must rescale */\n\n for (i = 1; i < 8; i++)\n\n block[s->idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], s->qscale);\n\n }\n\n } else {\n\n const int xy = s->mb_x + s->mb_y * s->mb_stride - s->mb_stride;\n\n /* top prediction */\n\n ac_val -= 16 * s->block_wrap[n];\n\n\n\n if (s->mb_y == 0 || s->qscale == qscale_table[xy] ||\n\n n == 2 || n == 3) {\n\n /* same qscale */\n\n for (i = 1; i < 8; i++)\n\n block[s->idsp.idct_permutation[i]] += ac_val[i + 8];\n\n } else {\n\n /* different qscale, we must rescale */\n\n for (i = 1; i < 8; i++)\n\n block[s->idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], s->qscale);\n\n }\n\n }\n\n }\n\n /* left copy */\n\n for (i = 1; i < 8; i++)\n\n ac_val1[i] = block[s->idsp.idct_permutation[i << 3]];\n\n\n\n /* top copy */\n\n for (i = 1; i < 8; i++)\n\n ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "564dd3f0f40008be8943af59686c0e8c4d67dd08", + "length": 586 + }, + { + "index": 572, + "code": "static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)\n\n{\n\n IscsiLun *iscsilun = bs->opaque;\n\n struct iscsi_context *iscsi = NULL;\n\n struct iscsi_url *iscsi_url = NULL;\n\n struct IscsiTask task;\n\n char *initiator_name = NULL;\n\n int ret;\n\n\n\n if ((BDRV_SECTOR_SIZE % 512) != 0) {\n\n error_report(\"iSCSI: Invalid BDRV_SECTOR_SIZE. \"\n\n \"BDRV_SECTOR_SIZE(%lld) is not a multiple \"\n\n \"of 512\", BDRV_SECTOR_SIZE);\n\n return -EINVAL;\n\n }\n\n\n\n iscsi_url = iscsi_parse_full_url(iscsi, filename);\n\n if (iscsi_url == NULL) {\n\n error_report(\"Failed to parse URL : %s %s\", filename,\n\n iscsi_get_error(iscsi));\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n memset(iscsilun, 0, sizeof(IscsiLun));\n\n\n\n initiator_name = parse_initiator_name(iscsi_url->target);\n\n\n\n iscsi = iscsi_create_context(initiator_name);\n\n if (iscsi == NULL) {\n\n error_report(\"iSCSI: Failed to create iSCSI context.\");\n\n ret = -ENOMEM;\n\n goto failed;\n\n }\n\n\n\n if (iscsi_set_targetname(iscsi, iscsi_url->target)) {\n\n error_report(\"iSCSI: Failed to set target name.\");\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n if (iscsi_url->user != NULL) {\n\n ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,\n\n iscsi_url->passwd);\n\n if (ret != 0) {\n\n error_report(\"Failed to set initiator username and password\");\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n }\n\n\n\n /* check if we got CHAP username/password via the options */\n\n if (parse_chap(iscsi, iscsi_url->target) != 0) {\n\n error_report(\"iSCSI: Failed to set CHAP user/password\");\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) != 0) {\n\n error_report(\"iSCSI: Failed to set session type to normal.\");\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);\n\n\n\n /* check if we got HEADER_DIGEST via the options */\n\n parse_header_digest(iscsi, iscsi_url->target);\n\n\n\n task.iscsilun = iscsilun;\n\n task.status = 0;\n\n task.complete = 0;\n\n task.bs = bs;\n\n\n\n iscsilun->iscsi = iscsi;\n\n iscsilun->lun = iscsi_url->lun;\n\n\n\n if (iscsi_full_connect_async(iscsi, iscsi_url->portal, iscsi_url->lun,\n\n iscsi_connect_cb, &task)\n\n != 0) {\n\n error_report(\"iSCSI: Failed to start async connect.\");\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n while (!task.complete) {\n\n iscsi_set_events(iscsilun);\n\n qemu_aio_wait();\n\n }\n\n if (task.status != 0) {\n\n error_report(\"iSCSI: Failed to connect to LUN : %s\",\n\n iscsi_get_error(iscsi));\n\n ret = -EINVAL;\n\n goto failed;\n\n }\n\n\n\n if (iscsi_url != NULL) {\n\n iscsi_destroy_url(iscsi_url);\n\n }\n\n\n\n /* Medium changer or tape. We dont have any emulation for this so this must\n\n * be sg ioctl compatible. We force it to be sg, otherwise qemu will try\n\n * to read from the device to guess the image format.\n\n */\n\n if (iscsilun->type == TYPE_MEDIUM_CHANGER ||\n\n iscsilun->type == TYPE_TAPE) {\n\n bs->sg = 1;\n\n }\n\n\n\n return 0;\n\n\n\nfailed:\n\n if (initiator_name != NULL) {\n\n g_free(initiator_name);\n\n }\n\n if (iscsi_url != NULL) {\n\n iscsi_destroy_url(iscsi_url);\n\n }\n\n if (iscsi != NULL) {\n\n iscsi_destroy_context(iscsi);\n\n }\n\n memset(iscsilun, 0, sizeof(IscsiLun));\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "b93c94f7ec74a577a0f74c724e8d251f01eaf65a", + "length": 967 + }, + { + "index": 16171, + "code": "static void test_ivshmem_server(void)\n\n{\n\n IVState state1, state2, *s1, *s2;\n\n ServerThread thread;\n\n IvshmemServer server;\n\n int ret, vm1, vm2;\n\n int nvectors = 2;\n\n guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;\n\n\n\n memset(tmpshmem, 0x42, TMPSHMSIZE);\n\n ret = ivshmem_server_init(&server, tmpserver, tmpshm,\n\n TMPSHMSIZE, nvectors,\n\n g_test_verbose());\n\n g_assert_cmpint(ret, ==, 0);\n\n\n\n ret = ivshmem_server_start(&server);\n\n g_assert_cmpint(ret, ==, 0);\n\n\n\n setup_vm_with_server(&state1, nvectors);\n\n s1 = &state1;\n\n setup_vm_with_server(&state2, nvectors);\n\n s2 = &state2;\n\n\n\n g_assert_cmpuint(in_reg(s1, IVPOSITION), ==, 0xffffffff);\n\n g_assert_cmpuint(in_reg(s2, IVPOSITION), ==, 0xffffffff);\n\n\n\n g_assert_cmpuint(qtest_readb(s1->qtest, (uintptr_t)s1->mem_base), ==, 0x00);\n\n\n\n thread.server = &server;\n\n ret = pipe(thread.pipe);\n\n g_assert_cmpint(ret, ==, 0);\n\n thread.thread = g_thread_new(\"ivshmem-server\", server_thread, &thread);\n\n g_assert(thread.thread != NULL);\n\n\n\n /* waiting until mapping is done */\n\n while (g_get_monotonic_time() < end_time) {\n\n g_usleep(1000);\n\n\n\n if (qtest_readb(s1->qtest, (uintptr_t)s1->mem_base) == 0x42 &&\n\n qtest_readb(s2->qtest, (uintptr_t)s2->mem_base) == 0x42) {\n\n break;\n\n }\n\n }\n\n\n\n /* check got different VM ids */\n\n vm1 = in_reg(s1, IVPOSITION);\n\n vm2 = in_reg(s2, IVPOSITION);\n\n g_assert_cmpuint(vm1, !=, vm2);\n\n\n\n global_qtest = s1->qtest;\n\n ret = qpci_msix_table_size(s1->dev);\n\n g_assert_cmpuint(ret, ==, nvectors);\n\n\n\n /* ping vm2 -> vm1 */\n\n ret = qpci_msix_pending(s1->dev, 0);\n\n g_assert_cmpuint(ret, ==, 0);\n\n out_reg(s2, DOORBELL, vm1 << 16);\n\n do {\n\n g_usleep(10000);\n\n ret = qpci_msix_pending(s1->dev, 0);\n\n } while (ret == 0 && g_get_monotonic_time() < end_time);\n\n g_assert_cmpuint(ret, !=, 0);\n\n\n\n /* ping vm1 -> vm2 */\n\n global_qtest = s2->qtest;\n\n ret = qpci_msix_pending(s2->dev, 0);\n\n g_assert_cmpuint(ret, ==, 0);\n\n out_reg(s1, DOORBELL, vm2 << 16);\n\n do {\n\n g_usleep(10000);\n\n ret = qpci_msix_pending(s2->dev, 0);\n\n } while (ret == 0 && g_get_monotonic_time() < end_time);\n\n g_assert_cmpuint(ret, !=, 0);\n\n\n\n qtest_quit(s2->qtest);\n\n qtest_quit(s1->qtest);\n\n\n\n if (qemu_write_full(thread.pipe[1], \"q\", 1) != 1) {\n\n g_error(\"qemu_write_full: %s\", g_strerror(errno));\n\n }\n\n\n\n g_thread_join(thread.thread);\n\n\n\n ivshmem_server_close(&server);\n\n close(thread.pipe[1]);\n\n close(thread.pipe[0]);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "1760048a5d21bacf0e4838da2f61b2d8db7d2866", + "length": 830 + }, + { + "index": 5217, + "code": "static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,\n\n uint16_t *refcount_table, int64_t refcount_table_size, int64_t l2_offset,\n\n int flags)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t *l2_table, l2_entry;\n\n uint64_t next_contiguous_offset = 0;\n\n int i, l2_size, nb_csectors, ret;\n\n\n\n /* Read L2 table from disk */\n\n l2_size = s->l2_size * sizeof(uint64_t);\n\n l2_table = g_malloc(l2_size);\n\n\n\n ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size);\n\n if (ret < 0) {\n\n fprintf(stderr, \"ERROR: I/O error in check_refcounts_l2\\n\");\n\n res->check_errors++;\n\n goto fail;\n\n }\n\n\n\n /* Do the actual checks */\n\n for(i = 0; i < s->l2_size; i++) {\n\n l2_entry = be64_to_cpu(l2_table[i]);\n\n\n\n switch (qcow2_get_cluster_type(l2_entry)) {\n\n case QCOW2_CLUSTER_COMPRESSED:\n\n /* Compressed clusters don't have QCOW_OFLAG_COPIED */\n\n if (l2_entry & QCOW_OFLAG_COPIED) {\n\n fprintf(stderr, \"ERROR: cluster %\" PRId64 \": \"\n\n \"copied flag must never be set for compressed \"\n\n \"clusters\\n\", l2_entry >> s->cluster_bits);\n\n l2_entry &= ~QCOW_OFLAG_COPIED;\n\n res->corruptions++;\n\n }\n\n\n\n /* Mark cluster as used */\n\n nb_csectors = ((l2_entry >> s->csize_shift) &\n\n s->csize_mask) + 1;\n\n l2_entry &= s->cluster_offset_mask;\n\n ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l2_entry & ~511, nb_csectors * 512);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n if (flags & CHECK_FRAG_INFO) {\n\n res->bfi.allocated_clusters++;\n\n res->bfi.compressed_clusters++;\n\n\n\n /* Compressed clusters are fragmented by nature. Since they\n\n * take up sub-sector space but we only have sector granularity\n\n * I/O we need to re-read the same sectors even for adjacent\n\n * compressed clusters.\n\n */\n\n res->bfi.fragmented_clusters++;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_ZERO:\n\n if ((l2_entry & L2E_OFFSET_MASK) == 0) {\n\n break;\n\n }\n\n /* fall through */\n\n\n\n case QCOW2_CLUSTER_NORMAL:\n\n {\n\n uint64_t offset = l2_entry & L2E_OFFSET_MASK;\n\n\n\n if (flags & CHECK_FRAG_INFO) {\n\n res->bfi.allocated_clusters++;\n\n if (next_contiguous_offset &&\n\n offset != next_contiguous_offset) {\n\n res->bfi.fragmented_clusters++;\n\n }\n\n next_contiguous_offset = offset + s->cluster_size;\n\n }\n\n\n\n /* Mark cluster as used */\n\n ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n offset, s->cluster_size);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Correct offsets are cluster aligned */\n\n if (offset_into_cluster(s, offset)) {\n\n fprintf(stderr, \"ERROR offset=%\" PRIx64 \": Cluster is not \"\n\n \"properly aligned; L2 entry corrupted.\\n\", offset);\n\n res->corruptions++;\n\n }\n\n break;\n\n }\n\n\n\n case QCOW2_CLUSTER_UNALLOCATED:\n\n break;\n\n\n\n default:\n\n abort();\n\n }\n\n }\n\n\n\n g_free(l2_table);\n\n return 0;\n\n\n\nfail:\n\n g_free(l2_table);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "641bb63cd6b003ab0ca2e312a014449037d71647", + "length": 839 + }, + { + "index": 6814, + "code": "static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y)\n\n{\n\n YuvPixel p;\n\n const int y0 = y * mp->avctx->width;\n\n int w, i, x = 0;\n\n\n\n p = mp->vpt[y];\n\n if (mp->changes_map[y0 + x] == 0) {\n\n memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));\n\n ++x;\n\n }\n\n while (x < mp->avctx->width) {\n\n w = mp->changes_map[y0 + x];\n\n if (w != 0) {\n\n if ((y & 3) == 0) {\n\n if (mp->changes_map[y0 + x + mp->avctx->width] < w ||\n\n mp->changes_map[y0 + x + mp->avctx->width * 2] < w ||\n\n mp->changes_map[y0 + x + mp->avctx->width * 3] < w) {\n\n for (i = (x + 3) & ~3; i < x + w; i += 4) {\n\n mp->hpt[((y / 4) * mp->avctx->width + i) / 4] = mp_get_yuv_from_rgb(mp, i, y);\n\n }\n\n }\n\n }\n\n x += w;\n\n memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));\n\n p = mp_get_yuv_from_rgb(mp, x - 1, y);\n\n } else {\n\n p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));\n\n\n if ((x & 3) == 0) {\n\n if ((y & 3) == 0) {\n\n p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb));\n\n\n p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb));\n\n\n mp->hpt[((y / 4) * mp->avctx->width + x) / 4] = p;\n\n } else {\n\n p.v = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].v;\n\n p.u = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].u;\n\n }\n\n }\n\n mp_set_rgb_from_yuv(mp, x, y, &p);\n\n ++x;\n\n }\n\n }\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "b5da848facd41169283d7bfe568b83bdfa7fc42e", + "length": 539 + }, + { + "index": 16891, + "code": "static int vnc_display_get_addresses(QemuOpts *opts,\n\n bool reverse,\n\n SocketAddressLegacy ***retsaddr,\n\n size_t *retnsaddr,\n\n SocketAddressLegacy ***retwsaddr,\n\n size_t *retnwsaddr,\n\n Error **errp)\n\n{\n\n SocketAddressLegacy *saddr = NULL;\n\n SocketAddressLegacy *wsaddr = NULL;\n\n QemuOptsIter addriter;\n\n const char *addr;\n\n int to = qemu_opt_get_number(opts, \"to\", 0);\n\n bool has_ipv4 = qemu_opt_get(opts, \"ipv4\");\n\n bool has_ipv6 = qemu_opt_get(opts, \"ipv6\");\n\n bool ipv4 = qemu_opt_get_bool(opts, \"ipv4\", false);\n\n bool ipv6 = qemu_opt_get_bool(opts, \"ipv6\", false);\n\n size_t i;\n\n int displaynum = -1;\n\n int ret = -1;\n\n\n\n *retsaddr = NULL;\n\n *retnsaddr = 0;\n\n *retwsaddr = NULL;\n\n *retnwsaddr = 0;\n\n\n\n addr = qemu_opt_get(opts, \"vnc\");\n\n if (addr == NULL || g_str_equal(addr, \"none\")) {\n\n ret = 0;\n\n goto cleanup;\n\n }\n\n if (qemu_opt_get(opts, \"websocket\") &&\n\n !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {\n\n error_setg(errp,\n\n \"SHA1 hash support is required for websockets\");\n\n goto cleanup;\n\n }\n\n\n\n qemu_opt_iter_init(&addriter, opts, \"vnc\");\n\n while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {\n\n int rv;\n\n rv = vnc_display_get_address(addr, false, reverse, 0, to,\n\n has_ipv4, has_ipv6,\n\n ipv4, ipv6,\n\n &saddr, errp);\n\n if (rv < 0) {\n\n goto cleanup;\n\n }\n\n /* Historical compat - first listen address can be used\n\n * to set the default websocket port\n\n */\n\n if (displaynum == -1) {\n\n displaynum = rv;\n\n }\n\n *retsaddr = g_renew(SocketAddressLegacy *, *retsaddr, *retnsaddr + 1);\n\n (*retsaddr)[(*retnsaddr)++] = saddr;\n\n }\n\n\n\n /* If we had multiple primary displays, we don't do defaults\n\n * for websocket, and require explicit config instead. */\n\n if (*retnsaddr > 1) {\n\n displaynum = -1;\n\n }\n\n\n\n qemu_opt_iter_init(&addriter, opts, \"websocket\");\n\n while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {\n\n if (vnc_display_get_address(addr, true, reverse, displaynum, to,\n\n has_ipv4, has_ipv6,\n\n ipv4, ipv6,\n\n &wsaddr, errp) < 0) {\n\n goto cleanup;\n\n }\n\n\n\n /* Historical compat - if only a single listen address was\n\n * provided, then this is used to set the default listen\n\n * address for websocket too\n\n */\n\n if (*retnsaddr == 1 &&\n\n (*retsaddr)[0]->type == SOCKET_ADDRESS_LEGACY_KIND_INET &&\n\n wsaddr->type == SOCKET_ADDRESS_LEGACY_KIND_INET &&\n\n g_str_equal(wsaddr->u.inet.data->host, \"\") &&\n\n !g_str_equal((*retsaddr)[0]->u.inet.data->host, \"\")) {\n\n g_free(wsaddr->u.inet.data->host);\n\n wsaddr->u.inet.data->host =\n\n g_strdup((*retsaddr)[0]->u.inet.data->host);\n\n }\n\n\n\n *retwsaddr = g_renew(SocketAddressLegacy *, *retwsaddr, *retnwsaddr + 1);\n\n (*retwsaddr)[(*retnwsaddr)++] = wsaddr;\n\n }\n\n\n\n ret = 0;\n\n cleanup:\n\n if (ret < 0) {\n\n for (i = 0; i < *retnsaddr; i++) {\n\n qapi_free_SocketAddressLegacy((*retsaddr)[i]);\n\n }\n\n g_free(*retsaddr);\n\n for (i = 0; i < *retnwsaddr; i++) {\n\n qapi_free_SocketAddressLegacy((*retwsaddr)[i]);\n\n }\n\n g_free(*retwsaddr);\n\n *retsaddr = *retwsaddr = NULL;\n\n *retnsaddr = *retnwsaddr = 0;\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884", + "length": 979 + }, + { + "index": 25866, + "code": "static void cortex_a15_initfn(Object *obj)\n\n{\n\n ARMCPU *cpu = ARM_CPU(obj);\n\n set_feature(&cpu->env, ARM_FEATURE_V7);\n\n set_feature(&cpu->env, ARM_FEATURE_VFP4);\n\n set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);\n\n set_feature(&cpu->env, ARM_FEATURE_NEON);\n\n set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);\n\n set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);\n\n set_feature(&cpu->env, ARM_FEATURE_V7MP);\n\n set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);\n\n set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);\n\n\n cpu->midr = 0x412fc0f1;\n\n cpu->reset_fpsid = 0x410430f0;\n\n cpu->mvfr0 = 0x10110222;\n\n cpu->mvfr1 = 0x11111111;\n\n cpu->ctr = 0x8444c004;\n\n cpu->reset_sctlr = 0x00c50078;\n\n cpu->id_pfr0 = 0x00001131;\n\n cpu->id_pfr1 = 0x00011011;\n\n cpu->id_dfr0 = 0x02010555;\n\n cpu->id_afr0 = 0x00000000;\n\n cpu->id_mmfr0 = 0x10201105;\n\n cpu->id_mmfr1 = 0x20000000;\n\n cpu->id_mmfr2 = 0x01240000;\n\n cpu->id_mmfr3 = 0x02102211;\n\n cpu->id_isar0 = 0x02101110;\n\n cpu->id_isar1 = 0x13112111;\n\n cpu->id_isar2 = 0x21232041;\n\n cpu->id_isar3 = 0x11112131;\n\n cpu->id_isar4 = 0x10011142;\n\n cpu->clidr = 0x0a200023;\n\n cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */\n\n cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */\n\n cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */\n\n define_arm_cp_regs(cpu, cortexa15_cp_reginfo);\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "de9b05b807918d40db9e26ddd6a54ad2978ac5b7", + "length": 543 + }, + { + "index": 3628, + "code": "static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],\n\n const DVprofile *sys)\n\n{\n\n int size, chan, i, j, d, of, smpls, freq, quant, half_ch;\n\n uint16_t lc, rc;\n\n const uint8_t* as_pack;\n\n uint8_t *pcm, ipcm;\n\n\n\n as_pack = dv_extract_pack(frame, dv_audio_source);\n\n if (!as_pack) /* No audio ? */\n\n return 0;\n\n\n\n smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */\n\n freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */\n\n quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */\n\n\n\n if (quant > 1)\n\n return -1; /* unsupported quantization */\n\n\n\n size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */\n\n half_ch = sys->difseg_size / 2;\n\n\n\n /* We work with 720p frames split in half, thus even frames have\n\n * channels 0,1 and odd 2,3. */\n\n ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;\n\n pcm = ppcm[ipcm++];\n\n\n\n /* for each DIF channel */\n\n for (chan = 0; chan < sys->n_difchan; chan++) {\n\n /* for each DIF segment */\n\n for (i = 0; i < sys->difseg_size; i++) {\n\n frame += 6 * 80; /* skip DIF segment header */\n\n if (quant == 1 && i == half_ch) {\n\n /* next stereo channel (12bit mode only) */\n\n pcm = ppcm[ipcm++];\n\n if (!pcm)\n\n break;\n\n }\n\n\n\n /* for each AV sequence */\n\n for (j = 0; j < 9; j++) {\n\n for (d = 8; d < 80; d += 2) {\n\n if (quant == 0) { /* 16bit quantization */\n\n of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride;\n\n if (of*2 >= size)\n\n continue;\n\n\n\n pcm[of*2] = frame[d+1]; // FIXME: maybe we have to admit\n\n pcm[of*2+1] = frame[d]; // that DV is a big-endian PCM\n\n if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)\n\n pcm[of*2+1] = 0;\n\n } else { /* 12bit quantization */\n\n lc = ((uint16_t)frame[d] << 4) |\n\n ((uint16_t)frame[d+2] >> 4);\n\n rc = ((uint16_t)frame[d+1] << 4) |\n\n ((uint16_t)frame[d+2] & 0x0f);\n\n lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));\n\n rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));\n\n\n\n of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride;\n\n if (of*2 >= size)\n\n continue;\n\n\n\n pcm[of*2] = lc & 0xff; // FIXME: maybe we have to admit\n\n pcm[of*2+1] = lc >> 8; // that DV is a big-endian PCM\n\n of = sys->audio_shuffle[i%half_ch+half_ch][j] +\n\n (d - 8) / 3 * sys->audio_stride;\n\n pcm[of*2] = rc & 0xff; // FIXME: maybe we have to admit\n\n pcm[of*2+1] = rc >> 8; // that DV is a big-endian PCM\n\n ++d;\n\n }\n\n }\n\n\n\n frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */\n\n }\n\n }\n\n\n\n /* next stereo channel (50Mbps and 100Mbps only) */\n\n pcm = ppcm[ipcm++];\n\n if (!pcm)\n\n break;\n\n }\n\n\n\n return size;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "88d84dd8eacd4edfe29f12209f10733d631ca5ae", + "length": 1019 + }, + { + "index": 11900, + "code": "int rom_add_file(const char *file, const char *fw_dir,\n\n target_phys_addr_t addr, int32_t bootindex)\n\n{\n\n Rom *rom;\n\n int rc, fd = -1;\n\n char devpath[100];\n\n\n\n rom = g_malloc0(sizeof(*rom));\n\n rom->name = g_strdup(file);\n\n rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);\n\n if (rom->path == NULL) {\n\n rom->path = g_strdup(file);\n\n }\n\n\n\n fd = open(rom->path, O_RDONLY | O_BINARY);\n\n if (fd == -1) {\n\n fprintf(stderr, \"Could not open option rom '%s': %s\\n\",\n\n rom->path, strerror(errno));\n\n goto err;\n\n }\n\n\n\n if (fw_dir) {\n\n rom->fw_dir = g_strdup(fw_dir);\n\n rom->fw_file = g_strdup(file);\n\n }\n\n rom->addr = addr;\n\n rom->romsize = lseek(fd, 0, SEEK_END);\n\n rom->data = g_malloc0(rom->romsize);\n\n lseek(fd, 0, SEEK_SET);\n\n rc = read(fd, rom->data, rom->romsize);\n\n if (rc != rom->romsize) {\n\n fprintf(stderr, \"rom: file %-20s: read error: rc=%d (expected %zd)\\n\",\n\n rom->name, rc, rom->romsize);\n\n goto err;\n\n }\n\n close(fd);\n\n rom_insert(rom);\n\n if (rom->fw_file && fw_cfg) {\n\n const char *basename;\n\n char fw_file_name[56];\n\n\n\n basename = strrchr(rom->fw_file, '/');\n\n if (basename) {\n\n basename++;\n\n } else {\n\n basename = rom->fw_file;\n\n }\n\n snprintf(fw_file_name, sizeof(fw_file_name), \"%s/%s\", rom->fw_dir,\n\n basename);\n\n fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);\n\n snprintf(devpath, sizeof(devpath), \"/rom@%s\", fw_file_name);\n\n } else {\n\n snprintf(devpath, sizeof(devpath), \"/rom@\" TARGET_FMT_plx, addr);\n\n }\n\n\n\n add_boot_device_path(bootindex, NULL, devpath);\n\n return 0;\n\n\n\nerr:\n\n if (fd != -1)\n\n close(fd);\n\n g_free(rom->data);\n\n g_free(rom->path);\n\n g_free(rom->name);\n\n g_free(rom);\n\n return -1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a8170e5e97ad17ca169c64ba87ae2f53850dab4c", + "length": 551 + }, + { + "index": 16960, + "code": "static int pic_arrays_init(HEVCContext *s)\n\n{\n\n int log2_min_cb_size = s->sps->log2_min_cb_size;\n\n int width = s->sps->width;\n\n int height = s->sps->height;\n\n int pic_size = width * height;\n\n int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *\n\n ((height >> log2_min_cb_size) + 1);\n\n int ctb_count = s->sps->ctb_width * s->sps->ctb_height;\n\n int min_pu_width = width >> s->sps->log2_min_pu_size;\n\n int pic_height_in_min_pu = height >> s->sps->log2_min_pu_size;\n\n int pic_size_in_min_pu = min_pu_width * pic_height_in_min_pu;\n\n int pic_width_in_min_tu = width >> s->sps->log2_min_tb_size;\n\n int pic_height_in_min_tu = height >> s->sps->log2_min_tb_size;\n\n\n\n s->bs_width = width >> 3;\n\n s->bs_height = height >> 3;\n\n\n\n s->sao = av_mallocz_array(ctb_count, sizeof(*s->sao));\n\n s->deblock = av_mallocz_array(ctb_count, sizeof(*s->deblock));\n\n s->split_cu_flag = av_malloc(pic_size);\n\n if (!s->sao || !s->deblock || !s->split_cu_flag)\n\n goto fail;\n\n\n\n s->skip_flag = av_malloc(pic_size_in_ctb);\n\n s->tab_ct_depth = av_malloc(s->sps->min_cb_height * s->sps->min_cb_width);\n\n if (!s->skip_flag || !s->tab_ct_depth)\n\n goto fail;\n\n\n\n s->tab_ipm = av_malloc(pic_size_in_min_pu);\n\n s->cbf_luma = av_malloc(pic_width_in_min_tu * pic_height_in_min_tu);\n\n s->is_pcm = av_malloc(pic_size_in_min_pu);\n\n if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)\n\n goto fail;\n\n\n\n s->filter_slice_edges = av_malloc(ctb_count);\n\n s->tab_slice_address = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address));\n\n s->qp_y_tab = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab));\n\n if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)\n\n goto fail;\n\n\n\n s->horizontal_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));\n\n s->vertical_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));\n\n if (!s->horizontal_bs || !s->vertical_bs)\n\n goto fail;\n\n\n\n s->tab_mvf_pool = av_buffer_pool_init(pic_size_in_min_pu * sizeof(MvField),\n\n av_buffer_alloc);\n\n s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),\n\n av_buffer_allocz);\n\n if (!s->tab_mvf_pool || !s->rpl_tab_pool)\n\n goto fail;\n\n\n\n return 0;\n\nfail:\n\n pic_arrays_free(s);\n\n return AVERROR(ENOMEM);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "4db81f081743aeed366e8af7a748667818a27e0f", + "length": 755 + }, + { + "index": 8881, + "code": "int av_write_header(AVFormatContext *s)\n\n{\n\n int ret, i;\n\n AVStream *st;\n\n\n\n // some sanity checks\n\n if (s->nb_streams == 0) {\n\n av_log(s, AV_LOG_ERROR, \"no streams\\n\");\n\n return -1;\n\n }\n\n\n\n for(i=0;inb_streams;i++) {\n\n st = s->streams[i];\n\n\n\n switch (st->codec->codec_type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n if(st->codec->sample_rate<=0){\n\n av_log(s, AV_LOG_ERROR, \"sample rate not set\\n\");\n\n return -1;\n\n }\n\n if(!st->codec->block_align)\n\n st->codec->block_align = st->codec->channels *\n\n av_get_bits_per_sample(st->codec->codec_id) >> 3;\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too?\n\n av_log(s, AV_LOG_ERROR, \"time base not set\\n\");\n\n return -1;\n\n }\n\n if((st->codec->width<=0 || st->codec->height<=0) && !(s->oformat->flags & AVFMT_NODIMENSIONS)){\n\n av_log(s, AV_LOG_ERROR, \"dimensions not set\\n\");\n\n return -1;\n\n }\n\n if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)){\n\n av_log(s, AV_LOG_ERROR, \"Aspect ratio mismatch between encoder and muxer layer\\n\");\n\n return -1;\n\n }\n\n break;\n\n }\n\n\n\n if(s->oformat->codec_tag){\n\n if(st->codec->codec_tag){\n\n //FIXME\n\n //check that tag + id is in the table\n\n //if neither is in the table -> OK\n\n //if tag is in the table with another id -> FAIL\n\n //if id is in the table with another tag -> FAIL unless strict < ?\n\n }else\n\n st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id);\n\n }\n\n\n\n if(s->oformat->flags & AVFMT_GLOBALHEADER &&\n\n !(st->codec->flags & CODEC_FLAG_GLOBAL_HEADER))\n\n av_log(s, AV_LOG_WARNING, \"Codec for stream %d does not use global headers but container format requires global headers\\n\", i);\n\n }\n\n\n\n if (!s->priv_data && s->oformat->priv_data_size > 0) {\n\n s->priv_data = av_mallocz(s->oformat->priv_data_size);\n\n if (!s->priv_data)\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n#if LIBAVFORMAT_VERSION_MAJOR < 53\n\n ff_metadata_mux_compat(s);\n\n#endif\n\n\n\n /* set muxer identification string */\n\n if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {\n\n AVMetadata *m;\n\n AVMetadataTag *t;\n\n\n\n if (!(m = av_mallocz(sizeof(AVMetadata))))\n\n return AVERROR(ENOMEM);\n\n av_metadata_set2(&m, \"encoder\", LIBAVFORMAT_IDENT, 0);\n\n metadata_conv(&m, s->oformat->metadata_conv, NULL);\n\n if ((t = av_metadata_get(m, \"\", NULL, AV_METADATA_IGNORE_SUFFIX)))\n\n av_metadata_set2(&s->metadata, t->key, t->value, 0);\n\n av_metadata_free(&m);\n\n }\n\n\n\n if(s->oformat->write_header){\n\n ret = s->oformat->write_header(s);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n\n\n /* init PTS generation */\n\n for(i=0;inb_streams;i++) {\n\n int64_t den = AV_NOPTS_VALUE;\n\n st = s->streams[i];\n\n\n\n switch (st->codec->codec_type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n den = (int64_t)st->time_base.num * st->codec->sample_rate;\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n den = (int64_t)st->time_base.num * st->codec->time_base.den;\n\n break;\n\n default:\n\n break;\n\n }\n\n if (den != AV_NOPTS_VALUE) {\n\n if (den <= 0)\n\n return AVERROR_INVALIDDATA;\n\n av_frac_init(&st->pts, 0, 0, den);\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "698f4cc7f0af0ba9ef54b01cfffd1f02d7aa5d05", + "length": 957 + }, + { + "index": 3099, + "code": "yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,\n\n int lumFilterSize, const int16_t *chrFilter,\n\n const int32_t **chrUSrc, const int32_t **chrVSrc,\n\n int chrFilterSize, const int32_t **alpSrc,\n\n uint16_t *dest[4], int dstW, int chrDstW,\n\n int big_endian, int output_bits)\n\n{\n\n //FIXME Optimize (just quickly written not optimized..)\n\n int i;\n\n int dword= output_bits == 16;\n\n uint16_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],\n\n *aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;\n\n int shift = 11 + 4*dword + 16 - output_bits;\n\n\n\n#define output_pixel(pos, val) \\\n\n if (big_endian) { \\\n\n if (output_bits == 16) { \\\n\n AV_WB16(pos, av_clip_uint16(val >> shift)); \\\n\n } else { \\\n\n AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \\\n\n } \\\n\n } else { \\\n\n if (output_bits == 16) { \\\n\n AV_WL16(pos, av_clip_uint16(val >> shift)); \\\n\n } else { \\\n\n AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \\\n\n } \\\n\n }\n\n for (i = 0; i < dstW; i++) {\n\n int val = 1 << (26-output_bits + 4*dword);\n\n int j;\n\n\n\n for (j = 0; j < lumFilterSize; j++)\n\n val += (dword ? lumSrc[j][i] : ((int16_t**)lumSrc)[j][i]) * lumFilter[j];\n\n\n\n output_pixel(&yDest[i], val);\n\n }\n\n\n\n if (uDest) {\n\n for (i = 0; i < chrDstW; i++) {\n\n int u = 1 << (26-output_bits + 4*dword);\n\n int v = 1 << (26-output_bits + 4*dword);\n\n int j;\n\n\n\n for (j = 0; j < chrFilterSize; j++) {\n\n u += (dword ? chrUSrc[j][i] : ((int16_t**)chrUSrc)[j][i]) * chrFilter[j];\n\n v += (dword ? chrVSrc[j][i] : ((int16_t**)chrVSrc)[j][i]) * chrFilter[j];\n\n }\n\n\n\n output_pixel(&uDest[i], u);\n\n output_pixel(&vDest[i], v);\n\n }\n\n }\n\n\n\n if (CONFIG_SWSCALE_ALPHA && aDest) {\n\n for (i = 0; i < dstW; i++) {\n\n int val = 1 << (26-output_bits + 4*dword);\n\n int j;\n\n\n\n for (j = 0; j < lumFilterSize; j++)\n\n val += (dword ? alpSrc[j][i] : ((int16_t**)alpSrc)[j][i]) * lumFilter[j];\n\n\n\n output_pixel(&aDest[i], val);\n\n }\n\n }\n\n#undef output_pixel\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "93a10dd56121862fab13aa6676227673c534cc12", + "length": 713 + }, + { + "index": 17103, + "code": "int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){\n\n int i, j, k, pass;\n\n const int n= pca->n;\n\n double z[n];\n\n\n\n memset(eigenvector, 0, sizeof(double)*n*n);\n\n\n\n for(j=0; jmean[j] /= pca->count;\n\n eigenvector[j + j*n] = 1.0;\n\n for(i=0; i<=j; i++){\n\n pca->covariance[j + i*n] /= pca->count;\n\n pca->covariance[j + i*n] -= pca->mean[i] * pca->mean[j];\n\n pca->covariance[i + j*n] = pca->covariance[j + i*n];\n\n }\n\n eigenvalue[j]= pca->covariance[j + j*n];\n\n z[j]= 0;\n\n }\n\n\n\n for(pass=0; pass < 50; pass++){\n\n double sum=0;\n\n\n\n for(i=0; icovariance[j + i*n]);\n\n\n\n if(sum == 0){\n\n for(i=0; i maxvalue){\n\n maxvalue= eigenvalue[j];\n\n k= j;\n\n }\n\n }\n\n eigenvalue[k]= eigenvalue[i];\n\n eigenvalue[i]= maxvalue;\n\n for(j=0; jcovariance[j + i*n];\n\n double t,c,s,tau,theta, h;\n\n\n\n if(pass < 3 && fabs(covar) < sum / (5*n*n)) //FIXME why pass < 3\n\n continue;\n\n if(fabs(covar) == 0.0) //FIXME shouldnt be needed\n\n continue;\n\n if(pass >=3 && fabs((eigenvalue[j]+z[j])/covar) > (1LL<<32) && fabs((eigenvalue[i]+z[i])/covar) > (1LL<<32)){\n\n pca->covariance[j + i*n]=0.0;\n\n continue;\n\n }\n\n\n\n h= (eigenvalue[j]+z[j]) - (eigenvalue[i]+z[i]);\n\n theta=0.5*h/covar;\n\n t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));\n\n if(theta < 0.0) t = -t;\n\n\n\n c=1.0/sqrt(1+t*t);\n\n s=t*c;\n\n tau=s/(1.0+c);\n\n z[i] -= t*covar;\n\n z[j] += t*covar;\n\n\n\n#define ROTATE(a,i,j,k,l) {\\\n\n double g=a[j + i*n];\\\n\n double h=a[l + k*n];\\\n\n a[j + i*n]=g-s*(h+g*tau);\\\n\n a[l + k*n]=h+s*(g-h*tau); }\n\n for(k=0; kcovariance,FFMIN(k,i),FFMAX(k,i),FFMIN(k,j),FFMAX(k,j))\n\n }\n\n ROTATE(eigenvector,k,i,k,j)\n\n }\n\n pca->covariance[j + i*n]=0.0;\n\n }\n\n }\n\n for (i=0; ipix_fmt);\n\n FrameBuffer *buf;\n\n int i, ret;\n\n int pixel_size;\n\n int h_chroma_shift, v_chroma_shift;\n\n int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1\n\n int w = s->width, h = s->height;\n\n\n\n if (!desc)\n\n return AVERROR(EINVAL);\n\n pixel_size = desc->comp[0].step_minus1 + 1;\n\n\n\n buf = av_mallocz(sizeof(*buf));\n\n if (!buf)\n\n return AVERROR(ENOMEM);\n\n\n\n if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {\n\n w += 2*edge;\n\n h += 2*edge;\n\n }\n\n\n\n avcodec_align_dimensions(s, &w, &h);\n\n if ((ret = av_image_alloc(buf->base, buf->linesize, w, h,\n\n s->pix_fmt, 32)) < 0) {\n\n av_freep(&buf);\n\n return ret;\n\n }\n\n /* XXX this shouldn't be needed, but some tests break without this line\n\n * those decoders are buggy and need to be fixed.\n\n * the following tests fail:\n\n */\n\n memset(buf->base[0], 128, ret);\n\n\n\n av_pix_fmt_get_chroma_sub_sample(s->pix_fmt,\n\n &h_chroma_shift, &v_chroma_shift);\n\n\n\n for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {\n\n const int h_shift = i==0 ? 0 : h_chroma_shift;\n\n const int v_shift = i==0 ? 0 : v_chroma_shift;\n\n if (s->flags & CODEC_FLAG_EMU_EDGE)\n\n buf->data[i] = buf->base[i];\n\n else if (buf->base[i])\n\n buf->data[i] = buf->base[i] +\n\n FFALIGN((buf->linesize[i]*edge >> v_shift) +\n\n (pixel_size*edge >> h_shift), 32);\n\n }\n\n buf->w = s->width;\n\n buf->h = s->height;\n\n buf->pix_fmt = s->pix_fmt;\n\n buf->pool = pool;\n\n\n\n *pbuf = buf;\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d2a25c4032ce6ceabb0f51b5c1e6ca865395a793", + "length": 523 + }, + { + "index": 17928, + "code": "static void *bochs_bios_init(void)\n\n{\n\n void *fw_cfg;\n\n uint8_t *smbios_table;\n\n size_t smbios_len;\n\n uint64_t *numa_fw_cfg;\n\n int i, j;\n\n\n\n fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);\n\n\n\n fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);\n\n fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);\n\n fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,\n\n acpi_tables_len);\n\n fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());\n\n\n\n smbios_table = smbios_get_table(&smbios_len);\n\n if (smbios_table)\n\n fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,\n\n smbios_table, smbios_len);\n\n fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,\n\n sizeof(e820_table));\n\n\n\n fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, (uint8_t *)&hpet_cfg,\n\n sizeof(struct hpet_fw_config));\n\n /* allocate memory for the NUMA channel: one (64bit) word for the number\n\n * of nodes, one word for each VCPU->node and one word for each node to\n\n * hold the amount of memory.\n\n */\n\n numa_fw_cfg = g_new0(uint64_t, 1 + max_cpus + nb_numa_nodes);\n\n numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes);\n\n for (i = 0; i < max_cpus; i++) {\n\n for (j = 0; j < nb_numa_nodes; j++) {\n\n if (test_bit(i, node_cpumask[j])) {\n\n numa_fw_cfg[i + 1] = cpu_to_le64(j);\n\n break;\n\n }\n\n }\n\n }\n\n for (i = 0; i < nb_numa_nodes; i++) {\n\n numa_fw_cfg[max_cpus + 1 + i] = cpu_to_le64(node_mem[i]);\n\n }\n\n fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,\n\n (1 + max_cpus + nb_numa_nodes) * sizeof(*numa_fw_cfg));\n\n\n\n return fw_cfg;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "089da572b956ef0f8f5b8d5917358e07892a77c2", + "length": 541 + }, + { + "index": 18800, + "code": "static void ide_dma_cb(void *opaque, int ret)\n\n{\n\n IDEState *s = opaque;\n\n int n;\n\n int64_t sector_num;\n\n uint64_t offset;\n\n bool stay_active = false;\n\n\n\n if (ret == -ECANCELED) {\n\n return;\n\n }\n\n if (ret < 0) {\n\n if (ide_handle_rw_error(s, -ret, ide_dma_cmd_to_retry(s->dma_cmd))) {\n\n s->bus->dma->aiocb = NULL;\n\n dma_buf_commit(s, 0);\n\n return;\n\n }\n\n }\n\n\n\n n = s->io_buffer_size >> 9;\n\n if (n > s->nsector) {\n\n /* The PRDs were longer than needed for this request. Shorten them so\n\n * we don't get a negative remainder. The Active bit must remain set\n\n * after the request completes. */\n\n n = s->nsector;\n\n stay_active = true;\n\n }\n\n\n\n sector_num = ide_get_sector(s);\n\n if (n > 0) {\n\n assert(n * 512 == s->sg.size);\n\n dma_buf_commit(s, s->sg.size);\n\n sector_num += n;\n\n ide_set_sector(s, sector_num);\n\n s->nsector -= n;\n\n }\n\n\n\n /* end of transfer ? */\n\n if (s->nsector == 0) {\n\n s->status = READY_STAT | SEEK_STAT;\n\n ide_set_irq(s->bus);\n\n goto eot;\n\n }\n\n\n\n /* launch next transfer */\n\n n = s->nsector;\n\n s->io_buffer_index = 0;\n\n s->io_buffer_size = n * 512;\n\n if (s->bus->dma->ops->prepare_buf(s->bus->dma, s->io_buffer_size) < 512) {\n\n /* The PRDs were too short. Reset the Active bit, but don't raise an\n\n * interrupt. */\n\n s->status = READY_STAT | SEEK_STAT;\n\n dma_buf_commit(s, 0);\n\n goto eot;\n\n }\n\n\n\n trace_ide_dma_cb(s, sector_num, n, IDE_DMA_CMD_str(s->dma_cmd));\n\n\n\n if ((s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) &&\n\n !ide_sect_range_ok(s, sector_num, n)) {\n\n ide_dma_error(s);\n\n block_acct_invalid(blk_get_stats(s->blk), s->acct.type);\n\n return;\n\n }\n\n\n\n offset = sector_num << BDRV_SECTOR_BITS;\n\n switch (s->dma_cmd) {\n\n case IDE_DMA_READ:\n\n s->bus->dma->aiocb = dma_blk_read(s->blk, &s->sg, offset,\n\n BDRV_SECTOR_SIZE, ide_dma_cb, s);\n\n break;\n\n case IDE_DMA_WRITE:\n\n s->bus->dma->aiocb = dma_blk_write(s->blk, &s->sg, offset,\n\n BDRV_SECTOR_SIZE, ide_dma_cb, s);\n\n break;\n\n case IDE_DMA_TRIM:\n\n s->bus->dma->aiocb = dma_blk_io(blk_get_aio_context(s->blk),\n\n &s->sg, offset, BDRV_SECTOR_SIZE,\n\n ide_issue_trim, s->blk, ide_dma_cb, s,\n\n DMA_DIRECTION_TO_DEVICE);\n\n break;\n\n default:\n\n abort();\n\n }\n\n return;\n\n\n\neot:\n\n if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {\n\n block_acct_done(blk_get_stats(s->blk), &s->acct);\n\n }\n\n ide_set_inactive(s, stay_active);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ef0e64a9838c0a20b5cb8a0bd2dcbcc59b0b812d", + "length": 773 + }, + { + "index": 20111, + "code": "static int ape_decode_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n APEContext *s = avctx->priv_data;\n\n int16_t *samples = data;\n\n int nblocks;\n\n int i, n;\n\n int blockstodecode;\n\n int bytes_used;\n\n\n\n /* should not happen but who knows */\n\n if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {\n\n av_log (avctx, AV_LOG_ERROR, \"Output buffer is too small.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if(!s->samples){\n\n void *tmp_data = av_realloc(s->data, (buf_size + 3) & ~3);\n\n if (!tmp_data)\n\n return AVERROR(ENOMEM);\n\n s->data = tmp_data;\n\n s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2);\n\n s->ptr = s->last_ptr = s->data;\n\n s->data_end = s->data + buf_size;\n\n\n\n nblocks = s->samples = bytestream_get_be32(&s->ptr);\n\n n = bytestream_get_be32(&s->ptr);\n\n if(n < 0 || n > 3){\n\n av_log(avctx, AV_LOG_ERROR, \"Incorrect offset passed\\n\");\n\n s->data = NULL;\n\n return AVERROR_INVALIDDATA;\n\n }\n\n s->ptr += n;\n\n\n\n s->currentframeblocks = nblocks;\n\n buf += 4;\n\n if (s->samples <= 0) {\n\n *data_size = 0;\n\n return buf_size;\n\n }\n\n\n\n memset(s->decoded0, 0, sizeof(s->decoded0));\n\n memset(s->decoded1, 0, sizeof(s->decoded1));\n\n\n\n /* Initialize the frame decoder */\n\n init_frame_decoder(s);\n\n }\n\n\n\n if (!s->data) {\n\n *data_size = 0;\n\n return buf_size;\n\n }\n\n\n\n nblocks = s->samples;\n\n blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks);\n\n\n\n s->error=0;\n\n\n\n if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO))\n\n ape_unpack_mono(s, blockstodecode);\n\n else\n\n ape_unpack_stereo(s, blockstodecode);\n\n emms_c();\n\n\n\n if(s->error || s->ptr > s->data_end){\n\n s->samples=0;\n\n av_log(avctx, AV_LOG_ERROR, \"Error decoding frame\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n for (i = 0; i < blockstodecode; i++) {\n\n *samples++ = s->decoded0[i];\n\n if(s->channels == 2)\n\n *samples++ = s->decoded1[i];\n\n }\n\n\n\n s->samples -= blockstodecode;\n\n\n\n *data_size = blockstodecode * 2 * s->channels;\n\n bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size;\n\n s->last_ptr = s->ptr;\n\n return bytes_used;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "b7e514575982fd2f5db5ea4f3b466d6dd6a08aa7", + "length": 719 + }, + { + "index": 17755, + "code": "static void coroutine_fn v9fs_write(void *opaque)\n\n{\n\n ssize_t err;\n\n int32_t fid;\n\n uint64_t off;\n\n uint32_t count;\n\n int32_t len = 0;\n\n int32_t total = 0;\n\n size_t offset = 7;\n\n V9fsFidState *fidp;\n\n V9fsPDU *pdu = opaque;\n\n V9fsState *s = pdu->s;\n\n QEMUIOVector qiov_full;\n\n QEMUIOVector qiov;\n\n\n\n err = pdu_unmarshal(pdu, offset, \"dqd\", &fid, &off, &count);\n\n if (err < 0) {\n\n pdu_complete(pdu, err);\n\n return;\n\n }\n\n offset += err;\n\n v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, count, true);\n\n trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, qiov_full.niov);\n\n\n\n fidp = get_fid(pdu, fid);\n\n if (fidp == NULL) {\n\n err = -EINVAL;\n\n goto out_nofid;\n\n }\n\n if (fidp->fid_type == P9_FID_FILE) {\n\n if (fidp->fs.fd == -1) {\n\n err = -EINVAL;\n\n goto out;\n\n }\n\n } else if (fidp->fid_type == P9_FID_XATTR) {\n\n /*\n\n * setxattr operation\n\n */\n\n err = v9fs_xattr_write(s, pdu, fidp, off, count,\n\n qiov_full.iov, qiov_full.niov);\n\n goto out;\n\n } else {\n\n err = -EINVAL;\n\n goto out;\n\n }\n\n qemu_iovec_init(&qiov, qiov_full.niov);\n\n do {\n\n qemu_iovec_reset(&qiov);\n\n qemu_iovec_concat(&qiov, &qiov_full, total, qiov_full.size - total);\n\n if (0) {\n\n print_sg(qiov.iov, qiov.niov);\n\n }\n\n /* Loop in case of EINTR */\n\n do {\n\n len = v9fs_co_pwritev(pdu, fidp, qiov.iov, qiov.niov, off);\n\n if (len >= 0) {\n\n off += len;\n\n total += len;\n\n }\n\n } while (len == -EINTR && !pdu->cancelled);\n\n if (len < 0) {\n\n /* IO error return the error */\n\n err = len;\n\n goto out_qiov;\n\n }\n\n } while (total < count && len > 0);\n\n\n\n offset = 7;\n\n err = pdu_marshal(pdu, offset, \"d\", total);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n err += offset;\n\n trace_v9fs_write_return(pdu->tag, pdu->id, total, err);\n\nout_qiov:\n\n qemu_iovec_destroy(&qiov);\n\nout:\n\n put_fid(pdu, fidp);\n\nout_nofid:\n\n qemu_iovec_destroy(&qiov_full);\n\n pdu_complete(pdu, err);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "fdfcc9aeea1492f4b819a24c94dfb678145b1bf9", + "length": 679 + }, + { + "index": 6729, + "code": "int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,\n\n int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))\n\n{\n\n AVPacketList **next_point, *this_pktl;\n\n AVStream *st = s->streams[pkt->stream_index];\n\n int chunked = s->max_chunk_size || s->max_chunk_duration;\n\n\n\n this_pktl = av_mallocz(sizeof(AVPacketList));\n\n if (!this_pktl)\n\n return AVERROR(ENOMEM);\n\n this_pktl->pkt = *pkt;\n\n pkt->destruct = NULL; // do not free original but only the copy\n\n av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-allocated memory\n\n\n\n if (s->streams[pkt->stream_index]->last_in_packet_buffer) {\n\n next_point = &(st->last_in_packet_buffer->next);\n\n } else {\n\n next_point = &s->packet_buffer;\n\n }\n\n\n\n if (chunked) {\n\n uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);\n\n st->interleaver_chunk_size += pkt->size;\n\n st->interleaver_chunk_duration += pkt->duration;\n\n if ( st->interleaver_chunk_size > s->max_chunk_size-1U\n\n || st->interleaver_chunk_duration > max-1U) {\n\n st->interleaver_chunk_size =\n\n st->interleaver_chunk_duration = 0;\n\n this_pktl->pkt.flags |= CHUNK_START;\n\n }\n\n }\n\n if (*next_point) {\n\n if (chunked && !(this_pktl->pkt.flags & CHUNK_START))\n\n goto next_non_null;\n\n\n\n if (compare(s, &s->packet_buffer_end->pkt, pkt)) {\n\n while ( *next_point\n\n && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))\n\n || !compare(s, &(*next_point)->pkt, pkt)))\n\n next_point = &(*next_point)->next;\n\n if (*next_point)\n\n goto next_non_null;\n\n } else {\n\n next_point = &(s->packet_buffer_end->next);\n\n }\n\n }\n\n av_assert1(!*next_point);\n\n\n\n s->packet_buffer_end = this_pktl;\n\nnext_non_null:\n\n\n\n this_pktl->next = *next_point;\n\n\n\n s->streams[pkt->stream_index]->last_in_packet_buffer =\n\n *next_point = this_pktl;\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "69a96f9d4cf6d5a7f5b568c713b48d78452838fd", + "length": 553 + }, + { + "index": 18306, + "code": "static void qdm2_decode_fft_packets(QDM2Context *q)\n\n{\n\n int i, j, min, max, value, type, unknown_flag;\n\n GetBitContext gb;\n\n\n\n if (q->sub_packet_list_B[0].packet == NULL)\n\n return;\n\n\n\n /* reset minimum indexes for FFT coefficients */\n\n q->fft_coefs_index = 0;\n\n for (i = 0; i < 5; i++)\n\n q->fft_coefs_min_index[i] = -1;\n\n\n\n /* process subpackets ordered by type, largest type first */\n\n for (i = 0, max = 256; i < q->sub_packets_B; i++) {\n\n QDM2SubPacket *packet = NULL;\n\n\n\n /* find subpacket with largest type less than max */\n\n for (j = 0, min = 0; j < q->sub_packets_B; j++) {\n\n value = q->sub_packet_list_B[j].packet->type;\n\n if (value > min && value < max) {\n\n min = value;\n\n packet = q->sub_packet_list_B[j].packet;\n\n }\n\n }\n\n\n\n max = min;\n\n\n\n /* check for errors (?) */\n\n if (!packet)\n\n return;\n\n\n\n if (i == 0 &&\n\n (packet->type < 16 || packet->type >= 48 ||\n\n fft_subpackets[packet->type - 16]))\n\n return;\n\n\n\n /* decode FFT tones */\n\n init_get_bits(&gb, packet->data, packet->size * 8);\n\n\n\n if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])\n\n unknown_flag = 1;\n\n else\n\n unknown_flag = 0;\n\n\n\n type = packet->type;\n\n\n\n if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {\n\n int duration = q->sub_sampling + 5 - (type & 15);\n\n\n\n if (duration >= 0 && duration < 4)\n\n qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);\n\n } else if (type == 31) {\n\n for (j = 0; j < 4; j++)\n\n qdm2_fft_decode_tones(q, j, &gb, unknown_flag);\n\n } else if (type == 46) {\n\n for (j = 0; j < 6; j++)\n\n q->fft_level_exp[j] = get_bits(&gb, 6);\n\n for (j = 0; j < 4; j++)\n\n qdm2_fft_decode_tones(q, j, &gb, unknown_flag);\n\n }\n\n } // Loop on B packets\n\n\n\n /* calculate maximum indexes for FFT coefficients */\n\n for (i = 0, j = -1; i < 5; i++)\n\n if (q->fft_coefs_min_index[i] >= 0) {\n\n if (j >= 0)\n\n q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];\n\n j = i;\n\n }\n\n if (j >= 0)\n\n q->fft_coefs_max_index[j] = q->fft_coefs_index;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f929ab0569ff31ed5a59b0b0adb7ce09df3fca39", + "length": 701 + }, + { + "index": 4649, + "code": "static int mjpeg_decode_sof0(MJpegDecodeContext *s,\n\n UINT8 *buf, int buf_size)\n\n{\n\n int len, nb_components, i, width, height;\n\n\n\n init_get_bits(&s->gb, buf, buf_size);\n\n\n\n /* XXX: verify len field validity */\n\n len = get_bits(&s->gb, 16);\n\n /* only 8 bits/component accepted */\n\n if (get_bits(&s->gb, 8) != 8)\n\n return -1;\n\n height = get_bits(&s->gb, 16);\n\n width = get_bits(&s->gb, 16);\n\n\n\n nb_components = get_bits(&s->gb, 8);\n\n if (nb_components <= 0 ||\n\n nb_components > MAX_COMPONENTS)\n\n return -1;\n\n s->nb_components = nb_components;\n\n s->h_max = 1;\n\n s->v_max = 1;\n\n for(i=0;icomponent_id[i] = get_bits(&s->gb, 8) - 1;\n\n s->h_count[i] = get_bits(&s->gb, 4);\n\n s->v_count[i] = get_bits(&s->gb, 4);\n\n /* compute hmax and vmax (only used in interleaved case) */\n\n if (s->h_count[i] > s->h_max)\n\n s->h_max = s->h_count[i];\n\n if (s->v_count[i] > s->v_max)\n\n s->v_max = s->v_count[i];\n\n s->quant_index[i] = get_bits(&s->gb, 8);\n\n if (s->quant_index[i] >= 4)\n\n return -1;\n\n dprintf(\"component %d %d:%d\\n\", i, s->h_count[i], s->v_count[i]);\n\n }\n\n\n\n /* if different size, realloc/alloc picture */\n\n /* XXX: also check h_count and v_count */\n\n if (width != s->width || height != s->height) {\n\n for(i=0;icurrent_picture[i]);\n\n s->current_picture[i] = NULL;\n\n }\n\n s->width = width;\n\n s->height = height;\n\n /* test interlaced mode */\n\n if (s->first_picture &&\n\n s->org_height != 0 &&\n\n s->height < ((s->org_height * 3) / 4)) {\n\n s->interlaced = 1;\n\n s->bottom_field = 0;\n\n }\n\n\n\n for(i=0;iwidth + 8 * s->h_max - 1) / (8 * s->h_max);\n\n h = (s->height + 8 * s->v_max - 1) / (8 * s->v_max);\n\n w = w * 8 * s->h_count[i];\n\n h = h * 8 * s->v_count[i];\n\n if (s->interlaced)\n\n w *= 2;\n\n s->linesize[i] = w;\n\n /* memory test is done in mjpeg_decode_sos() */\n\n s->current_picture[i] = av_mallocz(w * h);\n\n }\n\n s->first_picture = 0;\n\n }\n\n\n\n if (len != 8+(3*nb_components))\n\n\tdprintf(\"decode_sof0: error, len(%d) mismatch\\n\", len);\n\n \n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "af289048d8f720743ed82a4e674cff01ab02a836", + "length": 770 + }, + { + "index": 12877, + "code": "static int xenfb_map_fb(struct XenFB *xenfb)\n\n{\n\n struct xenfb_page *page = xenfb->c.page;\n\n char *protocol = xenfb->c.xendev.protocol;\n\n int n_fbdirs;\n\n unsigned long *pgmfns = NULL;\n\n unsigned long *fbmfns = NULL;\n\n void *map, *pd;\n\n int mode, ret = -1;\n\n\n\n /* default to native */\n\n pd = page->pd;\n\n mode = sizeof(unsigned long) * 8;\n\n\n\n if (!protocol) {\n\n\t/*\n\n\t * Undefined protocol, some guesswork needed.\n\n\t *\n\n\t * Old frontends which don't set the protocol use\n\n\t * one page directory only, thus pd[1] must be zero.\n\n\t * pd[1] of the 32bit struct layout and the lower\n\n\t * 32 bits of pd[0] of the 64bit struct layout have\n\n\t * the same location, so we can check that ...\n\n\t */\n\n\tuint32_t *ptr32 = NULL;\n\n\tuint32_t *ptr64 = NULL;\n\n#if defined(__i386__)\n\n\tptr32 = (void*)page->pd;\n\n\tptr64 = ((void*)page->pd) + 4;\n\n#elif defined(__x86_64__)\n\n\tptr32 = ((void*)page->pd) - 4;\n\n\tptr64 = (void*)page->pd;\n\n#endif\n\n\tif (ptr32) {\n\n\t if (ptr32[1] == 0) {\n\n\t\tmode = 32;\n\n\t\tpd = ptr32;\n\n\t } else {\n\n\t\tmode = 64;\n\n\t\tpd = ptr64;\n\n\t }\n\n\t}\n\n#if defined(__x86_64__)\n\n } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {\n\n\t/* 64bit dom0, 32bit domU */\n\n\tmode = 32;\n\n\tpd = ((void*)page->pd) - 4;\n\n#elif defined(__i386__)\n\n } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {\n\n\t/* 32bit dom0, 64bit domU */\n\n\tmode = 64;\n\n\tpd = ((void*)page->pd) + 4;\n\n#endif\n\n }\n\n\n\n if (xenfb->pixels) {\n\n munmap(xenfb->pixels, xenfb->fbpages * XC_PAGE_SIZE);\n\n xenfb->pixels = NULL;\n\n }\n\n\n\n xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;\n\n n_fbdirs = xenfb->fbpages * mode / 8;\n\n n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;\n\n\n\n pgmfns = g_malloc0(sizeof(unsigned long) * n_fbdirs);\n\n fbmfns = g_malloc0(sizeof(unsigned long) * xenfb->fbpages);\n\n\n\n xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);\n\n map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,\n\n\t\t\t PROT_READ, pgmfns, n_fbdirs);\n\n if (map == NULL)\n\n\tgoto out;\n\n xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);\n\n munmap(map, n_fbdirs * XC_PAGE_SIZE);\n\n\n\n xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,\n\n\t\t\t\t\t PROT_READ | PROT_WRITE, fbmfns, xenfb->fbpages);\n\n if (xenfb->pixels == NULL)\n\n\tgoto out;\n\n\n\n ret = 0; /* all is fine */\n\n\n\nout:\n\n g_free(pgmfns);\n\n g_free(fbmfns);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "0193c62c94643a837832f2b5ccc133434ee740cb", + "length": 805 + }, + { + "index": 8434, + "code": "int MPA_encode_init(AVCodecContext *avctx)\n\n{\n\n MpegAudioContext *s = avctx->priv_data;\n\n int freq = avctx->sample_rate;\n\n int bitrate = avctx->bit_rate;\n\n int channels = avctx->channels;\n\n int i, v, table;\n\n float a;\n\n\n\n if (channels > 2)\n\n return -1;\n\n bitrate = bitrate / 1000;\n\n s->nb_channels = channels;\n\n s->freq = freq;\n\n s->bit_rate = bitrate * 1000;\n\n avctx->frame_size = MPA_FRAME_SIZE;\n\n avctx->key_frame = 1; /* always key frame */\n\n\n\n /* encoding freq */\n\n s->lsf = 0;\n\n for(i=0;i<3;i++) {\n\n if (mpa_freq_tab[i] == freq) \n\n break;\n\n if ((mpa_freq_tab[i] / 2) == freq) {\n\n s->lsf = 1;\n\n break;\n\n }\n\n }\n\n if (i == 3)\n\n return -1;\n\n s->freq_index = i;\n\n\n\n /* encoding bitrate & frequency */\n\n for(i=0;i<15;i++) {\n\n if (mpa_bitrate_tab[s->lsf][1][i] == bitrate) \n\n break;\n\n }\n\n if (i == 15)\n\n return -1;\n\n s->bitrate_index = i;\n\n\n\n /* compute total header size & pad bit */\n\n \n\n a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);\n\n s->frame_size = ((int)a) * 8;\n\n\n\n /* frame fractional size to compute padding */\n\n s->frame_frac = 0;\n\n s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);\n\n \n\n /* select the right allocation table */\n\n table = l2_select_table(bitrate, s->nb_channels, freq, s->lsf);\n\n\n\n /* number of used subbands */\n\n s->sblimit = sblimit_table[table];\n\n s->alloc_table = alloc_tables[table];\n\n\n\n#ifdef DEBUG\n\n printf(\"%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\\n\", \n\n bitrate, freq, s->frame_size, table, s->frame_frac_incr);\n\n#endif\n\n\n\n for(i=0;inb_channels;i++)\n\n s->samples_offset[i] = 0;\n\n\n\n for(i=0;i<257;i++) {\n\n int v;\n\n v = (mpa_enwindow[i] + 2) >> 2;\n\n filter_bank[i] = v;\n\n if ((i & 63) != 0)\n\n v = -v;\n\n if (i != 0)\n\n filter_bank[512 - i] = v;\n\n }\n\n\n\n for(i=0;i<64;i++) {\n\n v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20));\n\n if (v <= 0)\n\n v = 1;\n\n scale_factor_table[i] = v;\n\n#ifdef USE_FLOATS\n\n scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20);\n\n#else\n\n#define P 15\n\n scale_factor_shift[i] = 21 - P - (i / 3);\n\n scale_factor_mult[i] = (1 << P) * pow(2.0, (i % 3) / 3.0);\n\n#endif\n\n }\n\n for(i=0;i<128;i++) {\n\n v = i - 64;\n\n if (v <= -3)\n\n v = 0;\n\n else if (v < 0)\n\n v = 1;\n\n else if (v == 0)\n\n v = 2;\n\n else if (v < 3)\n\n v = 3;\n\n else \n\n v = 4;\n\n scale_diff_table[i] = v;\n\n }\n\n\n\n for(i=0;i<17;i++) {\n\n v = quant_bits[i];\n\n if (v < 0) \n\n v = -v;\n\n else\n\n v = v * 3;\n\n total_quant_bits[i] = 12 * v;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "afa982fdae1b49a8aee00a27da876bba10ba1073", + "length": 944 + }, + { + "index": 25383, + "code": "static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n HLSContext *c = s->priv_data;\n\n int ret, i, minvariant = -1;\n\n\n\n if (c->first_packet) {\n\n recheck_discard_flags(s, 1);\n\n c->first_packet = 0;\n\n }\n\n\n\nstart:\n\n c->end_of_segment = 0;\n\n for (i = 0; i < c->n_variants; i++) {\n\n struct variant *var = c->variants[i];\n\n /* Make sure we've got one buffered packet from each open variant\n\n * stream */\n\n if (var->needed && !var->pkt.data) {\n\n while (1) {\n\n int64_t ts_diff;\n\n AVStream *st;\n\n ret = av_read_frame(var->ctx, &var->pkt);\n\n if (ret < 0) {\n\n if (!var->pb.eof_reached)\n\n return ret;\n\n\n break;\n\n } else {\n\n if (c->first_timestamp == AV_NOPTS_VALUE &&\n\n var->pkt.dts != AV_NOPTS_VALUE)\n\n c->first_timestamp = av_rescale_q(var->pkt.dts,\n\n var->ctx->streams[var->pkt.stream_index]->time_base,\n\n AV_TIME_BASE_Q);\n\n }\n\n\n\n if (c->seek_timestamp == AV_NOPTS_VALUE)\n\n break;\n\n\n\n if (var->pkt.dts == AV_NOPTS_VALUE) {\n\n c->seek_timestamp = AV_NOPTS_VALUE;\n\n break;\n\n }\n\n\n\n st = var->ctx->streams[var->pkt.stream_index];\n\n ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE,\n\n st->time_base.den, AV_ROUND_DOWN) -\n\n c->seek_timestamp;\n\n if (ts_diff >= 0 && (c->seek_flags & AVSEEK_FLAG_ANY ||\n\n var->pkt.flags & AV_PKT_FLAG_KEY)) {\n\n c->seek_timestamp = AV_NOPTS_VALUE;\n\n break;\n\n }\n\n\n\n }\n\n }\n\n /* Check if this stream still is on an earlier segment number, or\n\n * has the packet with the lowest dts */\n\n if (var->pkt.data) {\n\n struct variant *minvar = c->variants[minvariant];\n\n if (minvariant < 0 || var->cur_seq_no < minvar->cur_seq_no) {\n\n minvariant = i;\n\n } else if (var->cur_seq_no == minvar->cur_seq_no) {\n\n int64_t dts = var->pkt.dts;\n\n int64_t mindts = minvar->pkt.dts;\n\n AVStream *st = var->ctx->streams[var->pkt.stream_index];\n\n AVStream *minst = minvar->ctx->streams[minvar->pkt.stream_index];\n\n\n\n if (dts == AV_NOPTS_VALUE) {\n\n minvariant = i;\n\n } else if (mindts != AV_NOPTS_VALUE) {\n\n if (st->start_time != AV_NOPTS_VALUE)\n\n dts -= st->start_time;\n\n if (minst->start_time != AV_NOPTS_VALUE)\n\n mindts -= minst->start_time;\n\n\n\n if (av_compare_ts(dts, st->time_base,\n\n mindts, minst->time_base) < 0)\n\n minvariant = i;\n\n }\n\n }\n\n }\n\n }\n\n if (c->end_of_segment) {\n\n if (recheck_discard_flags(s, 0))\n\n goto start;\n\n }\n\n /* If we got a packet, return it */\n\n if (minvariant >= 0) {\n\n *pkt = c->variants[minvariant]->pkt;\n\n pkt->stream_index += c->variants[minvariant]->stream_offset;\n\n reset_packet(&c->variants[minvariant]->pkt);\n\n return 0;\n\n }\n\n return AVERROR_EOF;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "06205b5efdcf0bc4c5463bfdd02f09b5f79fc4cd", + "length": 824 + }, + { + "index": 6658, + "code": "struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe,\n\n int start, int w, int g, float ener0,\n\n float ener1, float ener01,\n\n int use_pcoeffs, int phase)\n\n{\n\n int i, w2;\n\n SingleChannelElement *sce0 = &cpe->ch[0];\n\n SingleChannelElement *sce1 = &cpe->ch[1];\n\n float *L = use_pcoeffs ? sce0->pcoeffs : sce0->coeffs;\n\n float *R = use_pcoeffs ? sce1->pcoeffs : sce1->coeffs;\n\n float *L34 = &s->scoefs[256*0], *R34 = &s->scoefs[256*1];\n\n float *IS = &s->scoefs[256*2], *I34 = &s->scoefs[256*3];\n\n float dist1 = 0.0f, dist2 = 0.0f;\n\n struct AACISError is_error = {0};\n\n\n\n if (ener01 <= 0 || ener0 <= 0) {\n\n is_error.pass = 0;\n\n return is_error;\n\n }\n\n\n\n for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {\n\n FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];\n\n FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];\n\n int is_band_type, is_sf_idx = FFMAX(1, sce0->sf_idx[(w+w2)*16+g]-4);\n\n float e01_34 = phase*pow(ener1/ener0, 3.0/4.0);\n\n float maxval, dist_spec_err = 0.0f;\n\n float minthr = FFMIN(band0->threshold, band1->threshold);\n\n for (i = 0; i < sce0->ics.swb_sizes[g]; i++)\n\n IS[i] = (L[start+(w+w2)*128+i] + phase*R[start+(w+w2)*128+i])*sqrt(ener0/ener01);\n\n abs_pow34_v(L34, &L[start+(w+w2)*128], sce0->ics.swb_sizes[g]);\n\n abs_pow34_v(R34, &R[start+(w+w2)*128], sce0->ics.swb_sizes[g]);\n\n abs_pow34_v(I34, IS, sce0->ics.swb_sizes[g]);\n\n maxval = find_max_val(1, sce0->ics.swb_sizes[g], I34);\n\n is_band_type = find_min_book(maxval, is_sf_idx);\n\n dist1 += quantize_band_cost(s, &L[start + (w+w2)*128], L34,\n\n sce0->ics.swb_sizes[g],\n\n sce0->sf_idx[(w+w2)*16+g],\n\n sce0->band_type[(w+w2)*16+g],\n\n s->lambda / band0->threshold, INFINITY, NULL, NULL, 0);\n\n dist1 += quantize_band_cost(s, &R[start + (w+w2)*128], R34,\n\n sce1->ics.swb_sizes[g],\n\n sce1->sf_idx[(w+w2)*16+g],\n\n sce1->band_type[(w+w2)*16+g],\n\n s->lambda / band1->threshold, INFINITY, NULL, NULL, 0);\n\n dist2 += quantize_band_cost(s, IS, I34, sce0->ics.swb_sizes[g],\n\n is_sf_idx, is_band_type,\n\n s->lambda / minthr, INFINITY, NULL, NULL, 0);\n\n for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {\n\n dist_spec_err += (L34[i] - I34[i])*(L34[i] - I34[i]);\n\n dist_spec_err += (R34[i] - I34[i]*e01_34)*(R34[i] - I34[i]*e01_34);\n\n }\n\n dist_spec_err *= s->lambda / minthr;\n\n dist2 += dist_spec_err;\n\n }\n\n\n\n is_error.pass = dist2 <= dist1;\n\n is_error.phase = phase;\n\n is_error.error = fabsf(dist1 - dist2);\n\n is_error.dist1 = dist1;\n\n is_error.dist2 = dist2;\n\n is_error.ener01 = ener01;\n\n\n\n return is_error;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "4dcb69cc12d00d46f93a07178e2087a8d27c8f64", + "length": 1008 + }, + { + "index": 3723, + "code": "static void vbe_update_vgaregs(VGACommonState *s)\n\n{\n\n int h, shift_control;\n\n\n\n if (!vbe_enabled(s)) {\n\n /* vbe is turned off -- nothing to do */\n\n return;\n\n }\n\n\n\n /* graphic mode + memory map 1 */\n\n s->gr[VGA_GFX_MISC] = (s->gr[VGA_GFX_MISC] & ~0x0c) | 0x04 |\n\n VGA_GR06_GRAPHICS_MODE;\n\n s->cr[VGA_CRTC_MODE] |= 3; /* no CGA modes */\n\n s->cr[VGA_CRTC_OFFSET] = s->vbe_line_offset >> 3;\n\n /* width */\n\n s->cr[VGA_CRTC_H_DISP] =\n\n (s->vbe_regs[VBE_DISPI_INDEX_XRES] >> 3) - 1;\n\n /* height (only meaningful if < 1024) */\n\n h = s->vbe_regs[VBE_DISPI_INDEX_YRES] - 1;\n\n s->cr[VGA_CRTC_V_DISP_END] = h;\n\n s->cr[VGA_CRTC_OVERFLOW] = (s->cr[VGA_CRTC_OVERFLOW] & ~0x42) |\n\n ((h >> 7) & 0x02) | ((h >> 3) & 0x40);\n\n /* line compare to 1023 */\n\n s->cr[VGA_CRTC_LINE_COMPARE] = 0xff;\n\n s->cr[VGA_CRTC_OVERFLOW] |= 0x10;\n\n s->cr[VGA_CRTC_MAX_SCAN] |= 0x40;\n\n\n\n if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {\n\n shift_control = 0;\n\n s->sr[VGA_SEQ_CLOCK_MODE] &= ~8; /* no double line */\n\n } else {\n\n shift_control = 2;\n\n /* set chain 4 mode */\n\n s->sr[VGA_SEQ_MEMORY_MODE] |= VGA_SR04_CHN_4M;\n\n /* activate all planes */\n\n s->sr[VGA_SEQ_PLANE_WRITE] |= VGA_SR02_ALL_PLANES;\n\n }\n\n s->gr[VGA_GFX_MODE] = (s->gr[VGA_GFX_MODE] & ~0x60) |\n\n (shift_control << 5);\n\n s->cr[VGA_CRTC_MAX_SCAN] &= ~0x9f; /* no double scan */\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "94ef4f337fb614f18b765a8e0e878a4c23cdedcd", + "length": 516 + }, + { + "index": 26971, + "code": "static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) {\n\n GetBitContext *gb=&vc->gb;\n\n uint_fast8_t i, j;\n\n\n\n vc->mapping_count=get_bits(gb, 6)+1;\n\n vc->mappings=(vorbis_mapping *)av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));\n\n\n\n AV_DEBUG(\" There are %d mappings. \\n\", vc->mapping_count);\n\n\n\n for(i=0;imapping_count;++i) {\n\n vorbis_mapping *mapping_setup=&vc->mappings[i];\n\n\n\n if (get_bits(gb, 16)) {\n\n av_log(vc->avccontext, AV_LOG_ERROR, \"Other mappings than type 0 are not compliant with the Vorbis I specification. \\n\");\n\n return 1;\n\n }\n\n if (get_bits1(gb)) {\n\n mapping_setup->submaps=get_bits(gb, 4)+1;\n\n } else {\n\n mapping_setup->submaps=1;\n\n }\n\n\n\n if (get_bits1(gb)) {\n\n mapping_setup->coupling_steps=get_bits(gb, 8)+1;\n\n mapping_setup->magnitude=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));\n\n mapping_setup->angle=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));\n\n for(j=0;jcoupling_steps;++j) {\n\n mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1));\n\n mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1));\n\n // FIXME: sanity checks\n\n }\n\n } else {\n\n mapping_setup->coupling_steps=0;\n\n }\n\n\n\n AV_DEBUG(\" %d mapping coupling steps: %d \\n\", i, mapping_setup->coupling_steps);\n\n\n\n if(get_bits(gb, 2)) {\n\n av_log(vc->avccontext, AV_LOG_ERROR, \"%d. mapping setup data invalid. \\n\", i);\n\n return 1; // following spec.\n\n }\n\n\n\n if (mapping_setup->submaps>1) {\n\n mapping_setup->mux=(uint_fast8_t *)av_mallocz(vc->audio_channels * sizeof(uint_fast8_t));\n\n for(j=0;jaudio_channels;++j) {\n\n mapping_setup->mux[j]=get_bits(gb, 4);\n\n }\n\n }\n\n\n\n for(j=0;jsubmaps;++j) {\n\n skip_bits(gb, 8); // FIXME check?\n\n mapping_setup->submap_floor[j]=get_bits(gb, 8);\n\n mapping_setup->submap_residue[j]=get_bits(gb, 8);\n\n\n\n AV_DEBUG(\" %d mapping %d submap : floor %d, residue %d \\n\", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "90901860c21468d6e9ae437c2bacb099c7bd3acf", + "length": 647 + }, + { + "index": 12167, + "code": "static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,\n\n CodedBitstreamUnit *unit)\n\n{\n\n BitstreamContext bc;\n\n int err;\n\n\n\n err = bitstream_init(&bc, unit->data, 8 * unit->data_size);\n\n if (err < 0)\n\n return err;\n\n\n\n if (MPEG2_START_IS_SLICE(unit->type)) {\n\n MPEG2RawSlice *slice;\n\n int pos, len;\n\n\n\n slice = av_mallocz(sizeof(*slice));\n\n if (!slice)\n\n return AVERROR(ENOMEM);\n\n err = cbs_mpeg2_read_slice_header(ctx, &bc, &slice->header);\n\n if (err < 0) {\n\n av_free(slice);\n\n return err;\n\n }\n\n\n\n pos = bitstream_tell(&bc);\n\n len = unit->data_size;\n\n\n\n slice->data_size = len - pos / 8;\n\n slice->data = av_malloc(slice->data_size);\n\n if (!slice->data) {\n\n av_free(slice);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n memcpy(slice->data,\n\n unit->data + pos / 8, slice->data_size);\n\n slice->data_bit_start = pos % 8;\n\n\n\n unit->content = slice;\n\n\n\n } else {\n\n switch (unit->type) {\n\n#define START(start_code, type, func) \\\n\n case start_code: \\\n\n { \\\n\n type *header; \\\n\n header = av_mallocz(sizeof(*header)); \\\n\n if (!header) \\\n\n return AVERROR(ENOMEM); \\\n\n err = cbs_mpeg2_read_ ## func(ctx, &bc, header); \\\n\n if (err < 0) { \\\n\n av_free(header); \\\n\n return err; \\\n\n } \\\n\n unit->content = header; \\\n\n } \\\n\n break;\n\n START(0x00, MPEG2RawPictureHeader, picture_header);\n\n START(0xb2, MPEG2RawUserData, user_data);\n\n START(0xb3, MPEG2RawSequenceHeader, sequence_header);\n\n START(0xb5, MPEG2RawExtensionData, extension_data);\n\n START(0xb8, MPEG2RawGroupOfPicturesHeader, group_of_pictures_header);\n\n#undef START\n\n default:\n\n av_log(ctx->log_ctx, AV_LOG_ERROR, \"Unknown start code %02x.\\n\",\n\n unit->type);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "7bf3f380466eeff24916fd6218aca13e414c6240", + "length": 525 + }, + { + "index": 7751, + "code": "static int cpu_mips_register (CPUMIPSState *env, const mips_def_t *def)\n\n{\n\n env->CP0_PRid = def->CP0_PRid;\n\n env->CP0_Config0 = def->CP0_Config0;\n\n#ifdef TARGET_WORDS_BIGENDIAN\n\n env->CP0_Config0 |= (1 << CP0C0_BE);\n\n#endif\n\n env->CP0_Config1 = def->CP0_Config1;\n\n env->CP0_Config2 = def->CP0_Config2;\n\n env->CP0_Config3 = def->CP0_Config3;\n\n env->CP0_Config6 = def->CP0_Config6;\n\n env->CP0_Config7 = def->CP0_Config7;\n\n env->SYNCI_Step = def->SYNCI_Step;\n\n env->CCRes = def->CCRes;\n\n env->CP0_Status_rw_bitmask = def->CP0_Status_rw_bitmask;\n\n env->CP0_TCStatus_rw_bitmask = def->CP0_TCStatus_rw_bitmask;\n\n env->CP0_SRSCtl = def->CP0_SRSCtl;\n\n env->current_tc = 0;\n\n env->SEGBITS = def->SEGBITS;\n\n env->SEGMask = (target_ulong)((1ULL << def->SEGBITS) - 1);\n\n#if defined(TARGET_MIPS64)\n\n if (def->insn_flags & ISA_MIPS3) {\n\n env->hflags |= MIPS_HFLAG_64;\n\n env->SEGMask |= 3ULL << 62;\n\n }\n\n#endif\n\n env->PABITS = def->PABITS;\n\n env->PAMask = (target_ulong)((1ULL << def->PABITS) - 1);\n\n env->CP0_SRSConf0_rw_bitmask = def->CP0_SRSConf0_rw_bitmask;\n\n env->CP0_SRSConf0 = def->CP0_SRSConf0;\n\n env->CP0_SRSConf1_rw_bitmask = def->CP0_SRSConf1_rw_bitmask;\n\n env->CP0_SRSConf1 = def->CP0_SRSConf1;\n\n env->CP0_SRSConf2_rw_bitmask = def->CP0_SRSConf2_rw_bitmask;\n\n env->CP0_SRSConf2 = def->CP0_SRSConf2;\n\n env->CP0_SRSConf3_rw_bitmask = def->CP0_SRSConf3_rw_bitmask;\n\n env->CP0_SRSConf3 = def->CP0_SRSConf3;\n\n env->CP0_SRSConf4_rw_bitmask = def->CP0_SRSConf4_rw_bitmask;\n\n env->CP0_SRSConf4 = def->CP0_SRSConf4;\n\n env->insn_flags = def->insn_flags;\n\n\n\n#ifndef CONFIG_USER_ONLY\n\n if (!env->user_mode_only)\n\n mmu_init(env, def);\n\n#endif\n\n fpu_init(env, def);\n\n mvp_init(env, def);\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "932e71cd57bab4e6206e1355c6425290721bbe34", + "length": 648 + }, + { + "index": 18265, + "code": "uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,\n\n int *num)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n unsigned int l1_index, l2_index;\n\n uint64_t l2_offset, *l2_table, cluster_offset;\n\n int l1_bits, c;\n\n unsigned int index_in_cluster, nb_clusters;\n\n uint64_t nb_available, nb_needed;\n\n\n\n index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1);\n\n nb_needed = *num + index_in_cluster;\n\n\n\n l1_bits = s->l2_bits + s->cluster_bits;\n\n\n\n /* compute how many bytes there are between the offset and\n\n * the end of the l1 entry\n\n */\n\n\n\n nb_available = (1ULL << l1_bits) - (offset & ((1ULL << l1_bits) - 1));\n\n\n\n /* compute the number of available sectors */\n\n\n\n nb_available = (nb_available >> 9) + index_in_cluster;\n\n\n\n if (nb_needed > nb_available) {\n\n nb_needed = nb_available;\n\n }\n\n\n\n cluster_offset = 0;\n\n\n\n /* seek the the l2 offset in the l1 table */\n\n\n\n l1_index = offset >> l1_bits;\n\n if (l1_index >= s->l1_size)\n\n goto out;\n\n\n\n l2_offset = s->l1_table[l1_index];\n\n\n\n /* seek the l2 table of the given l2 offset */\n\n\n\n if (!l2_offset)\n\n goto out;\n\n\n\n /* load the l2 table in memory */\n\n\n\n l2_offset &= ~QCOW_OFLAG_COPIED;\n\n l2_table = l2_load(bs, l2_offset);\n\n if (l2_table == NULL)\n\n return 0;\n\n\n\n /* find the cluster offset for the given disk offset */\n\n\n\n l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);\n\n cluster_offset = be64_to_cpu(l2_table[l2_index]);\n\n nb_clusters = size_to_clusters(s, nb_needed << 9);\n\n\n\n if (!cluster_offset) {\n\n /* how many empty clusters ? */\n\n c = count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]);\n\n } else {\n\n /* how many allocated clusters ? */\n\n c = count_contiguous_clusters(nb_clusters, s->cluster_size,\n\n &l2_table[l2_index], 0, QCOW_OFLAG_COPIED);\n\n }\n\n\n\n nb_available = (c * s->cluster_sectors);\n\nout:\n\n if (nb_available > nb_needed)\n\n nb_available = nb_needed;\n\n\n\n *num = nb_available - index_in_cluster;\n\n\n\n return cluster_offset & ~QCOW_OFLAG_COPIED;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "1c46efaa0a175e468772405385ca26a1e35dd94c", + "length": 589 + }, + { + "index": 15779, + "code": "static int get_physical_address(CPUPPCState *env, mmu_ctx_t *ctx,\n\n target_ulong eaddr, int rw, int access_type)\n\n{\n\n int ret;\n\n\n\n#if 0\n\n qemu_log(\"%s\\n\", __func__);\n\n#endif\n\n if ((access_type == ACCESS_CODE && msr_ir == 0) ||\n\n (access_type != ACCESS_CODE && msr_dr == 0)) {\n\n if (env->mmu_model == POWERPC_MMU_BOOKE) {\n\n /* The BookE MMU always performs address translation. The\n\n IS and DS bits only affect the address space. */\n\n ret = mmubooke_get_physical_address(env, ctx, eaddr,\n\n rw, access_type);\n\n } else if (env->mmu_model == POWERPC_MMU_BOOKE206) {\n\n ret = mmubooke206_get_physical_address(env, ctx, eaddr, rw,\n\n access_type);\n\n } else {\n\n /* No address translation. */\n\n ret = check_physical(env, ctx, eaddr, rw);\n\n }\n\n } else {\n\n ret = -1;\n\n switch (env->mmu_model) {\n\n case POWERPC_MMU_32B:\n\n case POWERPC_MMU_601:\n\n /* Try to find a BAT */\n\n if (env->nb_BATs != 0) {\n\n ret = get_bat(env, ctx, eaddr, rw, access_type);\n\n }\n\n if (ret < 0) {\n\n /* We didn't match any BAT entry or don't have BATs */\n\n ret = get_segment32(env, ctx, eaddr, rw, access_type);\n\n }\n\n break;\n\n\n\n case POWERPC_MMU_SOFT_6xx:\n\n case POWERPC_MMU_SOFT_74xx:\n\n /* Try to find a BAT */\n\n if (env->nb_BATs != 0) {\n\n ret = get_bat(env, ctx, eaddr, rw, access_type);\n\n }\n\n if (ret < 0) {\n\n /* We didn't match any BAT entry or don't have BATs */\n\n ret = get_segment_6xx_tlb(env, ctx, eaddr, rw, access_type);\n\n }\n\n break;\n\n\n\n#if defined(TARGET_PPC64)\n\n case POWERPC_MMU_64B:\n\n case POWERPC_MMU_2_06:\n\n case POWERPC_MMU_2_06d:\n\n ret = get_segment64(env, ctx, eaddr, rw, access_type);\n\n break;\n\n#endif\n\n\n\n case POWERPC_MMU_SOFT_4xx:\n\n case POWERPC_MMU_SOFT_4xx_Z:\n\n ret = mmu40x_get_physical_address(env, ctx, eaddr,\n\n rw, access_type);\n\n break;\n\n case POWERPC_MMU_BOOKE:\n\n ret = mmubooke_get_physical_address(env, ctx, eaddr,\n\n rw, access_type);\n\n break;\n\n case POWERPC_MMU_BOOKE206:\n\n ret = mmubooke206_get_physical_address(env, ctx, eaddr, rw,\n\n access_type);\n\n break;\n\n case POWERPC_MMU_MPC8xx:\n\n /* XXX: TODO */\n\n cpu_abort(env, \"MPC8xx MMU model is not implemented\\n\");\n\n break;\n\n case POWERPC_MMU_REAL:\n\n cpu_abort(env, \"PowerPC in real mode do not do any translation\\n\");\n\n return -1;\n\n default:\n\n cpu_abort(env, \"Unknown or invalid MMU model\\n\");\n\n return -1;\n\n }\n\n }\n\n#if 0\n\n qemu_log(\"%s address \" TARGET_FMT_lx \" => %d \" TARGET_FMT_plx \"\\n\",\n\n __func__, eaddr, ret, ctx->raddr);\n\n#endif\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "44bc910794eff956ceba0030f0751a26bed748b5", + "length": 801 + }, + { + "index": 25161, + "code": "static void test_mirror(void)\n\n{\n\n int send_sock[2], recv_sock;\n\n char *cmdline;\n\n uint32_t ret = 0, len = 0;\n\n char send_buf[] = \"Hello! filter-mirror~\";\n\n char sock_path[] = \"filter-mirror.XXXXXX\";\n\n char *recv_buf;\n\n uint32_t size = sizeof(send_buf);\n\n size = htonl(size);\n\n\n\n ret = socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock);\n\n g_assert_cmpint(ret, !=, -1);\n\n\n\n ret = mkstemp(sock_path);\n\n g_assert_cmpint(ret, !=, -1);\n\n\n\n cmdline = g_strdup_printf(\"-netdev socket,id=qtest-bn0,fd=%d \"\n\n \"-device e1000,netdev=qtest-bn0,id=qtest-e0 \"\n\n \"-chardev socket,id=mirror0,path=%s,server,nowait \"\n\n \"-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 \"\n\n , send_sock[1], sock_path);\n\n qtest_start(cmdline);\n\n g_free(cmdline);\n\n\n\n recv_sock = unix_connect(sock_path, NULL);\n\n g_assert_cmpint(recv_sock, !=, -1);\n\n\n\n struct iovec iov[] = {\n\n {\n\n .iov_base = &size,\n\n .iov_len = sizeof(size),\n\n }, {\n\n .iov_base = send_buf,\n\n .iov_len = sizeof(send_buf),\n\n },\n\n };\n\n\n\n /* send a qmp command to guarantee that 'connected' is setting to true. */\n\n qmp_discard_response(\"{ 'execute' : 'query-status'}\");\n\n ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf));\n\n g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));\n\n close(send_sock[0]);\n\n\n\n ret = qemu_recv(recv_sock, &len, sizeof(len), 0);\n\n g_assert_cmpint(ret, ==, sizeof(len));\n\n len = ntohl(len);\n\n\n\n g_assert_cmpint(len, ==, sizeof(send_buf));\n\n recv_buf = g_malloc(len);\n\n ret = qemu_recv(recv_sock, recv_buf, len, 0);\n\n g_assert_cmpstr(recv_buf, ==, send_buf);\n\n\n\n g_free(recv_buf);\n\n close(recv_sock);\n\n unlink(sock_path);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ea5bef49eadd240c7924f287f2da1bb457a3f92c", + "length": 515 + }, + { + "index": 5153, + "code": "static int ws_snd_decode_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n// WSSNDContext *c = avctx->priv_data;\n\n\n\n int in_size, out_size;\n\n int sample = 128;\n\n int i;\n\n uint8_t *samples = data;\n\n\n\n if (!buf_size)\n\n return 0;\n\n\n\n out_size = AV_RL16(&buf[0]);\n\n in_size = AV_RL16(&buf[2]);\n\n buf += 4;\n\n\n\n if (out_size > *data_size) {\n\n av_log(avctx, AV_LOG_ERROR, \"Frame is too large to fit in buffer\\n\");\n\n return -1;\n\n }\n\n if (in_size > buf_size) {\n\n av_log(avctx, AV_LOG_ERROR, \"Frame data is larger than input buffer\\n\");\n\n return -1;\n\n }\n\n\n\n *data_size = out_size;\n\n\n\n if (in_size == out_size) {\n\n for (i = 0; i < out_size; i++)\n\n *samples++ = *buf++;\n\n return buf_size;\n\n }\n\n\n\n while (out_size > 0) {\n\n int code;\n\n uint8_t count;\n\n code = (*buf) >> 6;\n\n count = (*buf) & 0x3F;\n\n buf++;\n\n switch(code) {\n\n case 0: /* ADPCM 2-bit */\n\n for (count++; count > 0; count--) {\n\n code = *buf++;\n\n sample += ws_adpcm_2bit[code & 0x3];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n sample += ws_adpcm_2bit[(code >> 2) & 0x3];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n sample += ws_adpcm_2bit[(code >> 4) & 0x3];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n sample += ws_adpcm_2bit[(code >> 6) & 0x3];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n out_size -= 4;\n\n }\n\n break;\n\n case 1: /* ADPCM 4-bit */\n\n for (count++; count > 0; count--) {\n\n code = *buf++;\n\n sample += ws_adpcm_4bit[code & 0xF];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n sample += ws_adpcm_4bit[code >> 4];\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n out_size -= 2;\n\n }\n\n break;\n\n case 2: /* no compression */\n\n if (count & 0x20) { /* big delta */\n\n int8_t t;\n\n t = count;\n\n t <<= 3;\n\n sample += t >> 3;\n\n sample = av_clip_uint8(sample);\n\n *samples++ = sample;\n\n out_size--;\n\n } else { /* copy */\n\n for (count++; count > 0; count--) {\n\n *samples++ = *buf++;\n\n out_size--;\n\n }\n\n sample = buf[-1];\n\n }\n\n break;\n\n default: /* run */\n\n for(count++; count > 0; count--) {\n\n *samples++ = sample;\n\n out_size--;\n\n }\n\n }\n\n }\n\n\n\n return buf_size;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "417364ce1f979031ef6fee661fc15e1869bdb1b4", + "length": 764 + }, + { + "index": 5753, + "code": "static sd_rsp_type_t sd_app_command(SDState *sd,\n\n SDRequest req)\n\n{\n\n DPRINTF(\"ACMD%d 0x%08x\\n\", req.cmd, req.arg);\n\n switch (req.cmd) {\n\n case 6:\t/* ACMD6: SET_BUS_WIDTH */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n sd->sd_status[0] &= 0x3f;\n\n sd->sd_status[0] |= (req.arg & 0x03) << 6;\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 13:\t/* ACMD13: SD_STATUS */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n sd->state = sd_sendingdata_state;\n\n sd->data_start = 0;\n\n sd->data_offset = 0;\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 22:\t/* ACMD22: SEND_NUM_WR_BLOCKS */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n *(uint32_t *) sd->data = sd->blk_written;\n\n\n\n sd->state = sd_sendingdata_state;\n\n sd->data_start = 0;\n\n sd->data_offset = 0;\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 23:\t/* ACMD23: SET_WR_BLK_ERASE_COUNT */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 41:\t/* ACMD41: SD_APP_OP_COND */\n\n if (sd->spi) {\n\n /* SEND_OP_CMD */\n\n sd->state = sd_transfer_state;\n\n return sd_r1;\n\n }\n\n switch (sd->state) {\n\n case sd_idle_state:\n\n /* We accept any voltage. 10000 V is nothing. */\n\n if (req.arg)\n\n sd->state = sd_ready_state;\n\n\n\n return sd_r3;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 42:\t/* ACMD42: SET_CLR_CARD_DETECT */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n /* Bringing in the 50KOhm pull-up resistor... Done. */\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n case 51:\t/* ACMD51: SEND_SCR */\n\n switch (sd->state) {\n\n case sd_transfer_state:\n\n sd->state = sd_sendingdata_state;\n\n sd->data_start = 0;\n\n sd->data_offset = 0;\n\n return sd_r1;\n\n\n\n default:\n\n break;\n\n }\n\n break;\n\n\n\n default:\n\n /* Fall back to standard commands. */\n\n sd->card_status &= ~APP_CMD;\n\n return sd_normal_command(sd, req);\n\n }\n\n\n\n fprintf(stderr, \"SD: ACMD%i in a wrong state\\n\", req.cmd);\n\n return sd_illegal;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "1d06cb7ab93f879ac25c9f5ef1d1ac8d97a42dfc", + "length": 656 + }, + { + "index": 24230, + "code": "static int read_kuki_chunk(AVFormatContext *s, int64_t size)\n\n{\n\n AVIOContext *pb = s->pb;\n\n AVStream *st = s->streams[0];\n\n\n\n if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)\n\n return -1;\n\n\n\n if (st->codec->codec_id == AV_CODEC_ID_AAC) {\n\n /* The magic cookie format for AAC is an mp4 esds atom.\n\n The lavc AAC decoder requires the data from the codec specific\n\n description as extradata input. */\n\n int strt, skip;\n\n MOVAtom atom;\n\n\n\n strt = avio_tell(pb);\n\n ff_mov_read_esds(s, pb, atom);\n\n skip = size - (avio_tell(pb) - strt);\n\n if (skip < 0 || !st->codec->extradata ||\n\n st->codec->codec_id != AV_CODEC_ID_AAC) {\n\n av_log(s, AV_LOG_ERROR, \"invalid AAC magic cookie\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avio_skip(pb, skip);\n\n } else if (st->codec->codec_id == AV_CODEC_ID_ALAC) {\n\n#define ALAC_PREAMBLE 12\n\n#define ALAC_HEADER 36\n\n#define ALAC_NEW_KUKI 24\n\n uint8_t preamble[12];\n\n if (size < ALAC_NEW_KUKI) {\n\n av_log(s, AV_LOG_ERROR, \"invalid ALAC magic cookie\\n\");\n\n avio_skip(pb, size);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avio_read(pb, preamble, ALAC_PREAMBLE);\n\n\n\n st->codec->extradata = av_mallocz(ALAC_HEADER + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata)\n\n return AVERROR(ENOMEM);\n\n\n\n /* For the old style cookie, we skip 12 bytes, then read 36 bytes.\n\n * The new style cookie only contains the last 24 bytes of what was\n\n * 36 bytes in the old style cookie, so we fabricate the first 12 bytes\n\n * in that case to maintain compatibility. */\n\n if (!memcmp(&preamble[4], \"frmaalac\", 8)) {\n\n if (size < ALAC_PREAMBLE + ALAC_HEADER) {\n\n av_log(s, AV_LOG_ERROR, \"invalid ALAC magic cookie\\n\");\n\n av_freep(&st->codec->extradata);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avio_read(pb, st->codec->extradata, ALAC_HEADER);\n\n avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER);\n\n } else {\n\n AV_WB32(st->codec->extradata, 36);\n\n memcpy(&st->codec->extradata[4], \"alac\", 4);\n\n AV_WB32(&st->codec->extradata[8], 0);\n\n memcpy(&st->codec->extradata[12], preamble, 12);\n\n avio_read(pb, &st->codec->extradata[24], ALAC_NEW_KUKI - 12);\n\n avio_skip(pb, size - ALAC_NEW_KUKI);\n\n }\n\n st->codec->extradata_size = ALAC_HEADER;\n\n } else {\n\n st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata)\n\n return AVERROR(ENOMEM);\n\n avio_read(pb, st->codec->extradata, size);\n\n st->codec->extradata_size = size;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "86dfcfd0e30d6645eea2c63c1c60a0550e7c97ea", + "length": 768 + }, + { + "index": 16441, + "code": "static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)\n\n{\n\n int64_t maxTrackLenTemp;\n\n put_be32(pb, 0x5c); /* size (always 0x5c) */\n\n put_tag(pb, \"tkhd\");\n\n put_be32(pb, 0xf); /* version & flags (track enabled) */\n\n put_be32(pb, track->time); /* creation time */\n\n put_be32(pb, track->time); /* modification time */\n\n put_be32(pb, track->trackID); /* track-id */\n\n put_be32(pb, 0); /* reserved */\n\n maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale;\n\n put_be32(pb, (long)maxTrackLenTemp); /* duration */\n\n\n\n put_be32(pb, 0); /* reserved */\n\n put_be32(pb, 0); /* reserved */\n\n put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */\n\n /* Volume, only for audio */\n\n if(track->enc->codec_type == CODEC_TYPE_AUDIO)\n\n put_be16(pb, 0x0100);\n\n else\n\n put_be16(pb, 0);\n\n put_be16(pb, 0); /* reserved */\n\n\n\n /* Matrix structure */\n\n put_be32(pb, 0x00010000); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x00010000); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x0); /* reserved */\n\n put_be32(pb, 0x40000000); /* reserved */\n\n\n\n /* Track width and height, for visual only */\n\n if(track->enc->codec_type == CODEC_TYPE_VIDEO) {\n\n put_be32(pb, track->enc->width*0x10000);\n\n put_be32(pb, track->enc->height*0x10000);\n\n }\n\n else {\n\n put_be32(pb, 0);\n\n put_be32(pb, 0);\n\n }\n\n return 0x5c;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "69dde1ad36b7d95b8b9268f414aa6c076212ed41", + "length": 519 + }, + { + "index": 1005, + "code": "bool throttle_is_valid(ThrottleConfig *cfg, Error **errp)\n{\n int i;\n bool bps_flag, ops_flag;\n bool bps_max_flag, ops_max_flag;\n bps_flag = cfg->buckets[THROTTLE_BPS_TOTAL].avg &&\n (cfg->buckets[THROTTLE_BPS_READ].avg ||\n cfg->buckets[THROTTLE_BPS_WRITE].avg);\n ops_flag = cfg->buckets[THROTTLE_OPS_TOTAL].avg &&\n (cfg->buckets[THROTTLE_OPS_READ].avg ||\n cfg->buckets[THROTTLE_OPS_WRITE].avg);\n bps_max_flag = cfg->buckets[THROTTLE_BPS_TOTAL].max &&\n (cfg->buckets[THROTTLE_BPS_READ].max ||\n cfg->buckets[THROTTLE_BPS_WRITE].max);\n ops_max_flag = cfg->buckets[THROTTLE_OPS_TOTAL].max &&\n (cfg->buckets[THROTTLE_OPS_READ].max ||\n cfg->buckets[THROTTLE_OPS_WRITE].max);\n if (bps_flag || ops_flag || bps_max_flag || ops_max_flag) {\n error_setg(errp, \"bps/iops/max total values and read/write values\"\n \" cannot be used at the same time\");\n if (cfg->op_size &&\n !cfg->buckets[THROTTLE_OPS_TOTAL].avg &&\n !cfg->buckets[THROTTLE_OPS_READ].avg &&\n !cfg->buckets[THROTTLE_OPS_WRITE].avg) {\n error_setg(errp, \"iops size requires an iops value to be set\");\n for (i = 0; i < BUCKETS_COUNT; i++) {\n LeakyBucket *bkt = &cfg->buckets[i];\n if (bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) {\n error_setg(errp, \"bps/iops/max values must be within [0, %lld]\",\n THROTTLE_VALUE_MAX);\n if (!bkt->burst_length) {\n error_setg(errp, \"the burst length cannot be 0\");\n if (bkt->burst_length > 1 && !bkt->max) {\n error_setg(errp, \"burst length set without burst rate\");\n if (bkt->max && !bkt->avg) {\n error_setg(errp, \"bps_max/iops_max require corresponding\"\n \" bps/iops values\");\n if (bkt->max && bkt->max < bkt->avg) {\n error_setg(errp, \"bps_max/iops_max cannot be lower than bps/iops\");\n return true;", + "label": 1, + "project": "qemu", + "commit_id": "67335a4558d3cad2173aac0ce13b6c096b077c41", + "length": 602 + }, + { + "index": 1185, + "code": "static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,\n\n int is_async)\n\n{\n\n BlkMigBlock *blk;\n\n BlockDriverState *bs = blk_bs(bmds->blk);\n\n int64_t total_sectors = bmds->total_sectors;\n\n int64_t sector;\n\n int nr_sectors;\n\n int ret = -EIO;\n\n\n\n for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {\n\n blk_mig_lock();\n\n if (bmds_aio_inflight(bmds, sector)) {\n\n blk_mig_unlock();\n\n blk_drain(bmds->blk);\n\n } else {\n\n blk_mig_unlock();\n\n }\n\n if (bdrv_get_dirty(bs, bmds->dirty_bitmap, sector)) {\n\n\n\n if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {\n\n nr_sectors = total_sectors - sector;\n\n } else {\n\n nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;\n\n }\n\n bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, sector, nr_sectors);\n\n\n\n blk = g_new(BlkMigBlock, 1);\n\n blk->buf = g_malloc(BLOCK_SIZE);\n\n blk->bmds = bmds;\n\n blk->sector = sector;\n\n blk->nr_sectors = nr_sectors;\n\n\n\n if (is_async) {\n\n blk->iov.iov_base = blk->buf;\n\n blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;\n\n qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);\n\n\n\n blk->aiocb = blk_aio_preadv(bmds->blk,\n\n sector * BDRV_SECTOR_SIZE,\n\n &blk->qiov, 0, blk_mig_read_cb,\n\n blk);\n\n\n\n blk_mig_lock();\n\n block_mig_state.submitted++;\n\n bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);\n\n blk_mig_unlock();\n\n } else {\n\n ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, blk->buf,\n\n nr_sectors * BDRV_SECTOR_SIZE);\n\n if (ret < 0) {\n\n goto error;\n\n }\n\n blk_send(f, blk);\n\n\n\n g_free(blk->buf);\n\n g_free(blk);\n\n }\n\n\n\n sector += nr_sectors;\n\n bmds->cur_dirty = sector;\n\n\n\n break;\n\n }\n\n sector += BDRV_SECTORS_PER_DIRTY_CHUNK;\n\n bmds->cur_dirty = sector;\n\n }\n\n\n\n return (bmds->cur_dirty >= bmds->total_sectors);\n\n\n\nerror:\n\n DPRINTF(\"Error reading sector %\" PRId64 \"\\n\", sector);\n\n g_free(blk->buf);\n\n g_free(blk);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b64bd51efa9bbf30df1b2f91477d2805678d0b93", + "length": 634 + }, + { + "index": 18464, + "code": "static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap,\n\n struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps)\n\n{\n\n dc1394_data* dc1394 = c->priv_data;\n\n AVStream* vst;\n\n struct dc1394_frame_format *fmt;\n\n struct dc1394_frame_rate *fps;\n\n enum PixelFormat pix_fmt;\n\n int width, height;\n\n AVRational framerate;\n\n int ret = 0;\n\n\n\n if ((pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) {\n\n av_log(c, AV_LOG_ERROR, \"No such pixel format: %s.\\n\", dc1394->pixel_format);\n\n ret = AVERROR(EINVAL);\n\n goto out;\n\n }\n\n\n\n if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) {\n\n av_log(c, AV_LOG_ERROR, \"Couldn't parse video size.\\n\");\n\n goto out;\n\n }\n\n if ((ret = av_parse_video_rate(&framerate, dc1394->framerate)) < 0) {\n\n av_log(c, AV_LOG_ERROR, \"Couldn't parse framerate.\\n\");\n\n goto out;\n\n }\n\n#if FF_API_FORMAT_PARAMETERS\n\n if (ap->width > 0)\n\n width = ap->width;\n\n if (ap->height > 0)\n\n height = ap->height;\n\n if (ap->pix_fmt)\n\n pix_fmt = ap->pix_fmt;\n\n if (ap->time_base.num)\n\n framerate = (AVRational){ap->time_base.den, ap->time_base.num};\n\n#endif\n\n dc1394->frame_rate = av_rescale(1000, framerate.num, framerate.den);\n\n\n\n for (fmt = dc1394_frame_formats; fmt->width; fmt++)\n\n if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height)\n\n break;\n\n\n\n for (fps = dc1394_frame_rates; fps->frame_rate; fps++)\n\n if (fps->frame_rate == dc1394->frame_rate)\n\n break;\n\n\n\n if (!fps->frame_rate || !fmt->width) {\n\n av_log(c, AV_LOG_ERROR, \"Can't find matching camera format for %s, %dx%d@%d:1000fps\\n\", av_get_pix_fmt_name(pix_fmt),\n\n width, height, dc1394->frame_rate);\n\n ret = AVERROR(EINVAL);\n\n goto out;\n\n }\n\n\n\n /* create a video stream */\n\n vst = av_new_stream(c, 0);\n\n if (!vst) {\n\n ret = AVERROR(ENOMEM);\n\n goto out;\n\n }\n\n av_set_pts_info(vst, 64, 1, 1000);\n\n vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n vst->codec->codec_id = CODEC_ID_RAWVIDEO;\n\n vst->codec->time_base.den = framerate.num;\n\n vst->codec->time_base.num = framerate.den;\n\n vst->codec->width = fmt->width;\n\n vst->codec->height = fmt->height;\n\n vst->codec->pix_fmt = fmt->pix_fmt;\n\n\n\n /* packet init */\n\n av_init_packet(&dc1394->packet);\n\n dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height);\n\n dc1394->packet.stream_index = vst->index;\n\n dc1394->packet.flags |= AV_PKT_FLAG_KEY;\n\n\n\n dc1394->current_frame = 0;\n\n\n\n vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);\n\n *select_fps = fps;\n\n *select_fmt = fmt;\n\nout:\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "41b68dce4d148b6a227d001b32deb275c01aa550", + "length": 828 + }, + { + "index": 15710, + "code": "bool hvf_inject_interrupts(CPUState *cpu_state)\n\n{\n\n int allow_nmi = !(rvmcs(cpu_state->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY) &\n\n VMCS_INTERRUPTIBILITY_NMI_BLOCKING);\n\n X86CPU *x86cpu = X86_CPU(cpu_state);\n\n CPUX86State *env = &x86cpu->env;\n\n\n\n uint64_t idt_info = rvmcs(cpu_state->hvf_fd, VMCS_IDT_VECTORING_INFO);\n\n uint64_t info = 0;\n\n \n\n if (idt_info & VMCS_IDT_VEC_VALID) {\n\n uint8_t vector = idt_info & 0xff;\n\n uint64_t intr_type = idt_info & VMCS_INTR_T_MASK;\n\n info = idt_info;\n\n \n\n uint64_t reason = rvmcs(cpu_state->hvf_fd, VMCS_EXIT_REASON);\n\n if (intr_type == VMCS_INTR_T_NMI && reason != EXIT_REASON_TASK_SWITCH) {\n\n allow_nmi = 1;\n\n vmx_clear_nmi_blocking(cpu_state);\n\n }\n\n \n\n if ((allow_nmi || intr_type != VMCS_INTR_T_NMI)) {\n\n info &= ~(1 << 12); /* clear undefined bit */\n\n if (intr_type == VMCS_INTR_T_SWINTR ||\n\n intr_type == VMCS_INTR_T_PRIV_SWEXCEPTION ||\n\n intr_type == VMCS_INTR_T_SWEXCEPTION) {\n\n uint64_t ins_len = rvmcs(cpu_state->hvf_fd,\n\n VMCS_EXIT_INSTRUCTION_LENGTH);\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INST_LENGTH, ins_len);\n\n }\n\n if (vector == EXCEPTION_BP || vector == EXCEPTION_OF) {\n\n /*\n\n * VT-x requires #BP and #OF to be injected as software\n\n * exceptions.\n\n */\n\n info &= ~VMCS_INTR_T_MASK;\n\n info |= VMCS_INTR_T_SWEXCEPTION;\n\n uint64_t ins_len = rvmcs(cpu_state->hvf_fd,\n\n VMCS_EXIT_INSTRUCTION_LENGTH);\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INST_LENGTH, ins_len);\n\n }\n\n \n\n uint64_t err = 0;\n\n if (idt_info & VMCS_INTR_DEL_ERRCODE) {\n\n err = rvmcs(cpu_state->hvf_fd, VMCS_IDT_VECTORING_ERROR);\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_EXCEPTION_ERROR, err);\n\n }\n\n /*printf(\"reinject %lx err %d\\n\", info, err);*/\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);\n\n };\n\n }\n\n\n\n if (cpu_state->interrupt_request & CPU_INTERRUPT_NMI) {\n\n if (allow_nmi && !(info & VMCS_INTR_VALID)) {\n\n cpu_state->interrupt_request &= ~CPU_INTERRUPT_NMI;\n\n info = VMCS_INTR_VALID | VMCS_INTR_T_NMI | NMI_VEC;\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);\n\n } else {\n\n vmx_set_nmi_window_exiting(cpu_state);\n\n }\n\n }\n\n\n\n if (env->hvf_emul->interruptable &&\n\n (cpu_state->interrupt_request & CPU_INTERRUPT_HARD) &&\n\n (EFLAGS(env) & IF_MASK) && !(info & VMCS_INTR_VALID)) {\n\n int line = cpu_get_pic_interrupt(&x86cpu->env);\n\n cpu_state->interrupt_request &= ~CPU_INTERRUPT_HARD;\n\n if (line >= 0) {\n\n wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, line |\n\n VMCS_INTR_VALID | VMCS_INTR_T_HWINTR);\n\n }\n\n }\n\n if (cpu_state->interrupt_request & CPU_INTERRUPT_HARD) {\n\n vmx_set_int_window_exiting(cpu_state);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b7394c8394d38cb38b6db14eb431cac7a91e7140", + "length": 822 + }, + { + "index": 18625, + "code": "static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)\n\n{\n\n int sx = 0, sy = 0;\n\n int dx = 0, dy = 0;\n\n int depth = 0;\n\n int notify = 0;\n\n\n\n /* make sure to only copy if it's a plain copy ROP */\n\n if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src ||\n\n *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) {\n\n\n\n int width, height;\n\n\n\n depth = s->vga.get_bpp(&s->vga) / 8;\n\n if (!depth) {\n\n return 0;\n\n }\n\n s->vga.get_resolution(&s->vga, &width, &height);\n\n\n\n /* extra x, y */\n\n sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;\n\n sy = (src / ABS(s->cirrus_blt_srcpitch));\n\n dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;\n\n dy = (dst / ABS(s->cirrus_blt_dstpitch));\n\n\n\n /* normalize width */\n\n w /= depth;\n\n\n\n /* if we're doing a backward copy, we have to adjust\n\n our x/y to be the upper left corner (instead of the lower\n\n right corner) */\n\n if (s->cirrus_blt_dstpitch < 0) {\n\n sx -= (s->cirrus_blt_width / depth) - 1;\n\n dx -= (s->cirrus_blt_width / depth) - 1;\n\n sy -= s->cirrus_blt_height - 1;\n\n dy -= s->cirrus_blt_height - 1;\n\n }\n\n\n\n /* are we in the visible portion of memory? */\n\n if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&\n\n (sx + w) <= width && (sy + h) <= height &&\n\n (dx + w) <= width && (dy + h) <= height) {\n\n notify = 1;\n\n }\n\n }\n\n\n\n /* we have to flush all pending changes so that the copy\n\n is generated at the appropriate moment in time */\n\n if (notify)\n\n graphic_hw_update(s->vga.con);\n\n\n\n (*s->cirrus_rop) (s, s->vga.vram_ptr + s->cirrus_blt_dstaddr,\n\n s->vga.vram_ptr + s->cirrus_blt_srcaddr,\n\n\t\t s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,\n\n\t\t s->cirrus_blt_width, s->cirrus_blt_height);\n\n\n\n if (notify) {\n\n qemu_console_copy(s->vga.con,\n\n\t\t\t sx, sy, dx, dy,\n\n\t\t\t s->cirrus_blt_width / depth,\n\n\t\t\t s->cirrus_blt_height);\n\n }\n\n\n\n /* we don't have to notify the display that this portion has\n\n changed since qemu_console_copy implies this */\n\n\n\n cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,\n\n\t\t\t\ts->cirrus_blt_dstpitch, s->cirrus_blt_width,\n\n\t\t\t\ts->cirrus_blt_height);\n\n\n\n return 1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "50628d3479e4f9aa97e323506856e394fe7ad7a6", + "length": 715 + }, + { + "index": 17894, + "code": "static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n\tconst uint16_t *end;\n\n#ifdef HAVE_MMX\n\n\tconst uint16_t *mm_end;\n\n#endif\n\n\tuint8_t *d = (uint8_t *)dst;\n\n\tconst uint16_t *s = (uint16_t *)src;\n\n\tend = s + src_size/2;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(PREFETCH\"\t%0\"::\"m\"(*s):\"memory\");\n\n\t__asm __volatile(\"pxor\t%%mm7,%%mm7\\n\\t\":::\"memory\");\n\n\tmm_end = end - 3;\n\n\twhile(s < mm_end)\n\n\t{\n\n\t __asm __volatile(\n\n\t\tPREFETCH\" 32%1\\n\\t\"\n\n\t\t\"movq\t%1, %%mm0\\n\\t\"\n\n\t\t\"movq\t%1, %%mm1\\n\\t\"\n\n\t\t\"movq\t%1, %%mm2\\n\\t\"\n\n\t\t\"pand\t%2, %%mm0\\n\\t\"\n\n\t\t\"pand\t%3, %%mm1\\n\\t\"\n\n\t\t\"pand\t%4, %%mm2\\n\\t\"\n\n\t\t\"psllq\t$3, %%mm0\\n\\t\"\n\n\t\t\"psrlq\t$3, %%mm1\\n\\t\"\n\n\t\t\"psrlq\t$8, %%mm2\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm3\\n\\t\"\n\n\t\t\"movq\t%%mm1, %%mm4\\n\\t\"\n\n\t\t\"movq\t%%mm2, %%mm5\\n\\t\"\n\n\t\t\"punpcklwd %%mm7, %%mm0\\n\\t\"\n\n\t\t\"punpcklwd %%mm7, %%mm1\\n\\t\"\n\n\t\t\"punpcklwd %%mm7, %%mm2\\n\\t\"\n\n\t\t\"punpckhwd %%mm7, %%mm3\\n\\t\"\n\n\t\t\"punpckhwd %%mm7, %%mm4\\n\\t\"\n\n\t\t\"punpckhwd %%mm7, %%mm5\\n\\t\"\n\n\t\t\"psllq\t$8, %%mm1\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm2\\n\\t\"\n\n\t\t\"por\t%%mm1, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm2, %%mm0\\n\\t\"\n\n\t\t\"psllq\t$8, %%mm4\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm5\\n\\t\"\n\n\t\t\"por\t%%mm4, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm5, %%mm3\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm3, 8%0\\n\\t\"\n\n\t\t:\"=m\"(*d)\n\n\t\t:\"m\"(*s),\"m\"(mask16b),\"m\"(mask16g),\"m\"(mask16r)\n\n\t\t:\"memory\");\n\n\t\td += 16;\n\n\t\ts += 4;\n\n\t}\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n\twhile(s < end)\n\n\t{\n\n\t\tregister uint16_t bgr;\n\n\t\tbgr = *s++;\n\n#ifdef WORDS_BIGENDIAN\n\n\t\t*d++ = 0;\n\n\t\t*d++ = (bgr&0xF800)>>8;\n\n\t\t*d++ = (bgr&0x7E0)>>3;\n\n\t\t*d++ = (bgr&0x1F)<<3;\n\n#else\n\n\t\t*d++ = (bgr&0x1F)<<3;\n\n\t\t*d++ = (bgr&0x7E0)>>3;\n\n\t\t*d++ = (bgr&0xF800)>>8;\n\n\t\t*d++ = 0;\n\n#endif\n\n\t}\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6e42e6c4b410dbef8b593c2d796a5dad95f89ee4", + "length": 853 + }, + { + "index": 25942, + "code": "static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,\n uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)\n{\n BDRVQcowState *s = bs->opaque;\n int l2_index;\n uint64_t *l2_table;\n uint64_t entry;\n unsigned int nb_clusters;\n int ret;\n uint64_t alloc_cluster_offset;\n trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,\n *bytes);\n assert(*bytes > 0);\n /*\n * Calculate the number of clusters to look for. We stop at L2 table\n * boundaries to keep things simple.\n */\n nb_clusters =\n size_to_clusters(s, offset_into_cluster(s, guest_offset) + *bytes);\n l2_index = offset_to_l2_index(s, guest_offset);\n nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);\n /* Find L2 entry for the first involved cluster */\n ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);\n if (ret < 0) {\n return ret;\n entry = be64_to_cpu(l2_table[l2_index]);\n /* For the moment, overwrite compressed clusters one by one */\n if (entry & QCOW_OFLAG_COMPRESSED) {\n nb_clusters = 1;\n } else {\n nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index);\n /* This function is only called when there were no non-COW clusters, so if\n * we can't find any unallocated or COW clusters either, something is\n * wrong with our code. */\n assert(nb_clusters > 0);\n ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);\n if (ret < 0) {\n return ret;\n /* Allocate, if necessary at a given offset in the image file */\n alloc_cluster_offset = start_of_cluster(s, *host_offset);\n ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,\n &nb_clusters);\n if (ret < 0) {\n /* Can't extend contiguous allocation */\n if (nb_clusters == 0) {\n *bytes = 0;\n return 0;\n /*\n * Save info needed for meta data update.\n *\n * requested_sectors: Number of sectors from the start of the first\n * newly allocated cluster to the end of the (possibly shortened\n * before) write request.\n *\n * avail_sectors: Number of sectors from the start of the first\n * newly allocated to the end of the last newly allocated cluster.\n *\n * nb_sectors: The number of sectors from the start of the first\n * newly allocated cluster to the end of the area that the write\n * request actually writes to (excluding COW at the end)\n */\n int requested_sectors =\n (*bytes + offset_into_cluster(s, guest_offset))\n >> BDRV_SECTOR_BITS;\n int avail_sectors = nb_clusters\n << (s->cluster_bits - BDRV_SECTOR_BITS);\n int alloc_n_start = offset_into_cluster(s, guest_offset)\n >> BDRV_SECTOR_BITS;\n int nb_sectors = MIN(requested_sectors, avail_sectors);\n QCowL2Meta *old_m = *m;\n *m = g_malloc0(sizeof(**m));\n **m = (QCowL2Meta) {\n .next = old_m,\n .alloc_offset = alloc_cluster_offset,\n .offset = start_of_cluster(s, guest_offset),\n .nb_clusters = nb_clusters,\n .nb_available = nb_sectors,\n .cow_start = {\n .offset = 0,\n .nb_sectors = alloc_n_start,\n },\n .cow_end = {\n .offset = nb_sectors * BDRV_SECTOR_SIZE,\n .nb_sectors = avail_sectors - nb_sectors,\n },\n };\n qemu_co_queue_init(&(*m)->dependent_requests);\n QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight);\n *host_offset = alloc_cluster_offset + offset_into_cluster(s, guest_offset);\n *bytes = MIN(*bytes, (nb_sectors * BDRV_SECTOR_SIZE)\n - offset_into_cluster(s, guest_offset));\n assert(*bytes != 0);\n return 1;\nfail:\n if (*m && (*m)->nb_clusters > 0) {\n QLIST_REMOVE(*m, next_in_flight);\n return ret;", + "label": 1, + "project": "qemu", + "commit_id": "ff52aab2df5c5e10f231481961b88d25a3021724", + "length": 1001 + }, + { + "index": 16061, + "code": "static int read_sbr_channel_pair_element(AACContext *ac,\n\n SpectralBandReplication *sbr,\n\n GetBitContext *gb)\n\n{\n\n if (get_bits1(gb)) // bs_data_extra\n\n skip_bits(gb, 8); // bs_reserved\n\n\n\n if ((sbr->bs_coupling = get_bits1(gb))) {\n\n if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]))\n\n return -1;\n\n copy_sbr_grid(&sbr->data[1], &sbr->data[0]);\n\n read_sbr_dtdf(sbr, gb, &sbr->data[0]);\n\n read_sbr_dtdf(sbr, gb, &sbr->data[1]);\n\n read_sbr_invf(sbr, gb, &sbr->data[0]);\n\n memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));\n\n memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));\n\n read_sbr_envelope(sbr, gb, &sbr->data[0], 0);\n\n read_sbr_noise(sbr, gb, &sbr->data[0], 0);\n\n read_sbr_envelope(sbr, gb, &sbr->data[1], 1);\n\n read_sbr_noise(sbr, gb, &sbr->data[1], 1);\n\n } else {\n\n if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) ||\n\n read_sbr_grid(ac, sbr, gb, &sbr->data[1]))\n\n return -1;\n\n read_sbr_dtdf(sbr, gb, &sbr->data[0]);\n\n read_sbr_dtdf(sbr, gb, &sbr->data[1]);\n\n read_sbr_invf(sbr, gb, &sbr->data[0]);\n\n read_sbr_invf(sbr, gb, &sbr->data[1]);\n\n read_sbr_envelope(sbr, gb, &sbr->data[0], 0);\n\n read_sbr_envelope(sbr, gb, &sbr->data[1], 1);\n\n read_sbr_noise(sbr, gb, &sbr->data[0], 0);\n\n read_sbr_noise(sbr, gb, &sbr->data[1], 1);\n\n }\n\n\n\n if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))\n\n get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);\n\n if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb)))\n\n get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d877b88f5188fa3d71525c8d4d404daa4798e9fb", + "length": 689 + }, + { + "index": 11842, + "code": "SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd)\n\n{\n\n SimpleSpiceUpdate *update;\n\n QXLDrawable *drawable;\n\n QXLImage *image;\n\n QXLCommand *cmd;\n\n uint8_t *src, *dst;\n\n int by, bw, bh;\n\n\n\n if (qemu_spice_rect_is_empty(&ssd->dirty)) {\n\n return NULL;\n\n };\n\n\n\n pthread_mutex_lock(&ssd->lock);\n\n dprint(2, \"%s: lr %d -> %d, tb -> %d -> %d\\n\", __FUNCTION__,\n\n ssd->dirty.left, ssd->dirty.right,\n\n ssd->dirty.top, ssd->dirty.bottom);\n\n\n\n update = qemu_mallocz(sizeof(*update));\n\n drawable = &update->drawable;\n\n image = &update->image;\n\n cmd = &update->ext.cmd;\n\n\n\n bw = ssd->dirty.right - ssd->dirty.left;\n\n bh = ssd->dirty.bottom - ssd->dirty.top;\n\n update->bitmap = qemu_malloc(bw * bh * 4);\n\n\n\n drawable->bbox = ssd->dirty;\n\n drawable->clip.type = SPICE_CLIP_TYPE_NONE;\n\n drawable->effect = QXL_EFFECT_OPAQUE;\n\n drawable->release_info.id = (intptr_t)update;\n\n drawable->type = QXL_DRAW_COPY;\n\n drawable->surfaces_dest[0] = -1;\n\n drawable->surfaces_dest[1] = -1;\n\n drawable->surfaces_dest[2] = -1;\n\n\n\n drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;\n\n drawable->u.copy.src_bitmap = (intptr_t)image;\n\n drawable->u.copy.src_area.right = bw;\n\n drawable->u.copy.src_area.bottom = bh;\n\n\n\n QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ssd->unique++);\n\n image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;\n\n image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;\n\n image->bitmap.stride = bw * 4;\n\n image->descriptor.width = image->bitmap.x = bw;\n\n image->descriptor.height = image->bitmap.y = bh;\n\n image->bitmap.data = (intptr_t)(update->bitmap);\n\n image->bitmap.palette = 0;\n\n image->bitmap.format = SPICE_BITMAP_FMT_32BIT;\n\n\n\n if (ssd->conv == NULL) {\n\n PixelFormat dst = qemu_default_pixelformat(32);\n\n ssd->conv = qemu_pf_conv_get(&dst, &ssd->ds->surface->pf);\n\n assert(ssd->conv);\n\n }\n\n\n\n src = ds_get_data(ssd->ds) +\n\n ssd->dirty.top * ds_get_linesize(ssd->ds) +\n\n ssd->dirty.left * ds_get_bytes_per_pixel(ssd->ds);\n\n dst = update->bitmap;\n\n for (by = 0; by < bh; by++) {\n\n qemu_pf_conv_run(ssd->conv, dst, src, bw);\n\n src += ds_get_linesize(ssd->ds);\n\n dst += image->bitmap.stride;\n\n }\n\n\n\n cmd->type = QXL_CMD_DRAW;\n\n cmd->data = (intptr_t)drawable;\n\n\n\n memset(&ssd->dirty, 0, sizeof(ssd->dirty));\n\n pthread_mutex_unlock(&ssd->lock);\n\n return update;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "7466bc49107fbd84336ba680f860d5eadd6def13", + "length": 742 + }, + { + "index": 6548, + "code": "static inline int mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, int n)\n\n{\n\n int level, dc, diff, i, j, run;\n\n int component;\n\n RLTable *rl = &ff_rl_mpeg1;\n\n uint8_t * const scantable = s->intra_scantable.permutated;\n\n const uint16_t *quant_matrix = s->intra_matrix;\n\n const int qscale = s->qscale;\n\n\n\n /* DC coefficient */\n\n component = (n <= 3 ? 0 : n - 4 + 1);\n\n diff = decode_dc(&s->gb, component);\n\n if (diff >= 0xffff)\n\n return -1;\n\n dc = s->last_dc[component];\n\n dc += diff;\n\n s->last_dc[component] = dc;\n\n block[0] = dc * quant_matrix[0];\n\n av_dlog(s->avctx, \"dc=%d diff=%d\\n\", dc, diff);\n\n i = 0;\n\n {\n\n OPEN_READER(re, &s->gb);\n\n /* now quantify & encode AC coefficients */\n\n for (;;) {\n\n UPDATE_CACHE(re, &s->gb);\n\n GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);\n\n\n\n if (level == 127) {\n\n break;\n\n } else if (level != 0) {\n\n i += run;\n\n j = scantable[i];\n\n level = (level * qscale * quant_matrix[j]) >> 4;\n\n level = (level - 1) | 1;\n\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n\n LAST_SKIP_BITS(re, &s->gb, 1);\n\n } else {\n\n /* escape */\n\n run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);\n\n UPDATE_CACHE(re, &s->gb);\n\n level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);\n\n if (level == -128) {\n\n level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);\n\n } else if (level == 0) {\n\n level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);\n\n }\n\n i += run;\n\n j = scantable[i];\n\n if (level < 0) {\n\n level = -level;\n\n level = (level * qscale * quant_matrix[j]) >> 4;\n\n level = (level - 1) | 1;\n\n level = -level;\n\n } else {\n\n level = (level * qscale * quant_matrix[j]) >> 4;\n\n level = (level - 1) | 1;\n\n }\n\n }\n\n if (i > 63) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"ac-tex damaged at %d %d\\n\", s->mb_x, s->mb_y);\n\n return -1;\n\n }\n\n\n\n block[j] = level;\n\n }\n\n CLOSE_READER(re, &s->gb);\n\n }\n\n s->block_last_index[n] = i;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6d93307f8df81808f0dcdbc064b848054a6e83b3", + "length": 768 + }, + { + "index": 23831, + "code": "static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)\n\n{\n\n char *backing_file = NULL;\n\n char *backing_fmt = NULL;\n\n char *buf = NULL;\n\n uint64_t size = 0;\n\n int flags = 0;\n\n size_t cluster_size = DEFAULT_CLUSTER_SIZE;\n\n PreallocMode prealloc;\n\n int version = 3;\n\n uint64_t refcount_bits = 16;\n\n int refcount_order;\n\n Error *local_err = NULL;\n\n int ret;\n\n\n\n /* Read out options */\n\n size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),\n\n BDRV_SECTOR_SIZE);\n\n backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);\n\n backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);\n\n if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {\n\n flags |= BLOCK_FLAG_ENCRYPT;\n\n }\n\n cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,\n\n DEFAULT_CLUSTER_SIZE);\n\n buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);\n\n prealloc = qapi_enum_parse(PreallocMode_lookup, buf,\n\n PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,\n\n &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n g_free(buf);\n\n buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);\n\n if (!buf) {\n\n /* keep the default */\n\n } else if (!strcmp(buf, \"0.10\")) {\n\n version = 2;\n\n } else if (!strcmp(buf, \"1.1\")) {\n\n version = 3;\n\n } else {\n\n error_setg(errp, \"Invalid compatibility level: '%s'\", buf);\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n\n\n if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {\n\n flags |= BLOCK_FLAG_LAZY_REFCOUNTS;\n\n }\n\n\n\n if (backing_file && prealloc != PREALLOC_MODE_OFF) {\n\n error_setg(errp, \"Backing file and preallocation cannot be used at \"\n\n \"the same time\");\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n\n\n if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) {\n\n error_setg(errp, \"Lazy refcounts only supported with compatibility \"\n\n \"level 1.1 and above (use compat=1.1 or greater)\");\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n\n\n refcount_bits = qemu_opt_get_number_del(opts, BLOCK_OPT_REFCOUNT_BITS,\n\n refcount_bits);\n\n if (refcount_bits > 64 || !is_power_of_2(refcount_bits)) {\n\n error_setg(errp, \"Refcount width must be a power of two and may not \"\n\n \"exceed 64 bits\");\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n\n\n if (version < 3 && refcount_bits != 16) {\n\n error_setg(errp, \"Different refcount widths than 16 bits require \"\n\n \"compatibility level 1.1 or above (use compat=1.1 or \"\n\n \"greater)\");\n\n ret = -EINVAL;\n\n goto finish;\n\n }\n\n\n\n refcount_order = ctz32(refcount_bits);\n\n\n\n ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags,\n\n cluster_size, prealloc, opts, version, refcount_order,\n\n &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n }\n\n\n\nfinish:\n\n g_free(backing_file);\n\n g_free(backing_fmt);\n\n g_free(buf);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "621ff94d5074d88253a5818c6b9c4db718fbfc65", + "length": 823 + }, + { + "index": 16726, + "code": "static void spitz_common_init(ram_addr_t ram_size, int vga_ram_size,\n\n const char *kernel_filename,\n\n const char *kernel_cmdline, const char *initrd_filename,\n\n const char *cpu_model, enum spitz_model_e model, int arm_id)\n\n{\n\n struct pxa2xx_state_s *cpu;\n\n struct scoop_info_s *scp0, *scp1 = NULL;\n\n\n\n if (!cpu_model)\n\n cpu_model = (model == terrier) ? \"pxa270-c5\" : \"pxa270-c0\";\n\n\n\n /* Setup CPU & memory */\n\n if (ram_size < SPITZ_RAM + SPITZ_ROM + PXA2XX_INTERNAL_SIZE) {\n\n fprintf(stderr, \"This platform requires %i bytes of memory\\n\",\n\n SPITZ_RAM + SPITZ_ROM + PXA2XX_INTERNAL_SIZE);\n\n exit(1);\n\n }\n\n cpu = pxa270_init(spitz_binfo.ram_size, cpu_model);\n\n\n\n sl_flash_register(cpu, (model == spitz) ? FLASH_128M : FLASH_1024M);\n\n\n\n cpu_register_physical_memory(0, SPITZ_ROM,\n\n qemu_ram_alloc(SPITZ_ROM) | IO_MEM_ROM);\n\n\n\n /* Setup peripherals */\n\n spitz_keyboard_register(cpu);\n\n\n\n spitz_ssp_attach(cpu);\n\n\n\n scp0 = scoop_init(cpu, 0, 0x10800000);\n\n if (model != akita) {\n\n\t scp1 = scoop_init(cpu, 1, 0x08800040);\n\n }\n\n\n\n spitz_scoop_gpio_setup(cpu, scp0, scp1);\n\n\n\n spitz_gpio_setup(cpu, (model == akita) ? 1 : 2);\n\n\n\n spitz_i2c_setup(cpu);\n\n\n\n if (model == akita)\n\n spitz_akita_i2c_setup(cpu);\n\n\n\n if (model == terrier)\n\n /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */\n\n spitz_microdrive_attach(cpu, 1);\n\n else if (model != akita)\n\n /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */\n\n spitz_microdrive_attach(cpu, 0);\n\n\n\n /* Setup initial (reset) machine state */\n\n cpu->env->regs[15] = spitz_binfo.loader_start;\n\n\n\n spitz_binfo.kernel_filename = kernel_filename;\n\n spitz_binfo.kernel_cmdline = kernel_cmdline;\n\n spitz_binfo.initrd_filename = initrd_filename;\n\n spitz_binfo.board_id = arm_id;\n\n arm_load_kernel(cpu->env, &spitz_binfo);\n\n sl_bootparam_write(SL_PXA_PARAM_BASE);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a0b753dfd3920df146a5f4d05e442e3c522900c7", + "length": 573 + }, + { + "index": 21390, + "code": "static inline CopyRet receive_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n uint8_t second_field)\n\n{\n\n BC_STATUS ret;\n\n BC_DTS_PROC_OUT output = {\n\n .PicInfo.width = avctx->width,\n\n .PicInfo.height = avctx->height,\n\n };\n\n CHDContext *priv = avctx->priv_data;\n\n HANDLE dev = priv->dev;\n\n\n\n *data_size = 0;\n\n\n\n // Request decoded data from the driver\n\n ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);\n\n if (ret == BC_STS_FMT_CHANGE) {\n\n av_log(avctx, AV_LOG_VERBOSE, \"CrystalHD: Initial format change\\n\");\n\n avctx->width = output.PicInfo.width;\n\n avctx->height = output.PicInfo.height;\n\n return RET_COPY_AGAIN;\n\n } else if (ret == BC_STS_SUCCESS) {\n\n int copy_ret = -1;\n\n if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {\n\n if (priv->last_picture == -1) {\n\n /*\n\n * Init to one less, so that the incrementing code doesn't\n\n * need to be special-cased.\n\n */\n\n priv->last_picture = output.PicInfo.picture_number - 1;\n\n }\n\n\n\n if (avctx->codec->id == CODEC_ID_MPEG4 &&\n\n output.PicInfo.timeStamp == 0) {\n\n av_log(avctx, AV_LOG_VERBOSE,\n\n \"CrystalHD: Not returning packed frame twice.\\n\");\n\n priv->last_picture++;\n\n DtsReleaseOutputBuffs(dev, NULL, FALSE);\n\n return RET_COPY_AGAIN;\n\n }\n\n\n\n print_frame_info(priv, &output);\n\n\n\n if (priv->last_picture + 1 < output.PicInfo.picture_number) {\n\n av_log(avctx, AV_LOG_WARNING,\n\n \"CrystalHD: Picture Number discontinuity\\n\");\n\n /*\n\n * Have we lost frames? If so, we need to shrink the\n\n * pipeline length appropriately.\n\n *\n\n * XXX: I have no idea what the semantics of this situation\n\n * are so I don't even know if we've lost frames or which\n\n * ones.\n\n *\n\n * In any case, only warn the first time.\n\n */\n\n priv->last_picture = output.PicInfo.picture_number - 1;\n\n }\n\n\n\n copy_ret = copy_frame(avctx, &output, data, data_size, second_field);\n\n if (*data_size > 0) {\n\n avctx->has_b_frames--;\n\n priv->last_picture++;\n\n av_log(avctx, AV_LOG_VERBOSE, \"CrystalHD: Pipeline length: %u\\n\",\n\n avctx->has_b_frames);\n\n }\n\n } else {\n\n /*\n\n * An invalid frame has been consumed.\n\n */\n\n av_log(avctx, AV_LOG_ERROR, \"CrystalHD: ProcOutput succeeded with \"\n\n \"invalid PIB\\n\");\n\n avctx->has_b_frames--;\n\n copy_ret = RET_OK;\n\n }\n\n DtsReleaseOutputBuffs(dev, NULL, FALSE);\n\n\n\n return copy_ret;\n\n } else if (ret == BC_STS_BUSY) {\n\n return RET_COPY_AGAIN;\n\n } else {\n\n av_log(avctx, AV_LOG_ERROR, \"CrystalHD: ProcOutput failed %d\\n\", ret);\n\n return RET_ERROR;\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ae7a4a1594e3624f7c844dec44266d2dc74a6be2", + "length": 723 + }, + { + "index": 19698, + "code": "static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,\n\n BdrvCheckMode fix, bool *rebuild,\n\n int64_t *highest_cluster,\n\n uint16_t *refcount_table, int64_t nb_clusters)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int64_t i;\n\n uint64_t refcount1, refcount2;\n\n int ret;\n\n\n\n for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {\n\n ret = qcow2_get_refcount(bs, i, &refcount1);\n\n if (ret < 0) {\n\n fprintf(stderr, \"Can't get refcount for cluster %\" PRId64 \": %s\\n\",\n\n i, strerror(-ret));\n\n res->check_errors++;\n\n continue;\n\n }\n\n\n\n refcount2 = refcount_table[i];\n\n\n\n if (refcount1 > 0 || refcount2 > 0) {\n\n *highest_cluster = i;\n\n }\n\n\n\n if (refcount1 != refcount2) {\n\n /* Check if we're allowed to fix the mismatch */\n\n int *num_fixed = NULL;\n\n if (refcount1 == 0) {\n\n *rebuild = true;\n\n } else if (refcount1 > refcount2 && (fix & BDRV_FIX_LEAKS)) {\n\n num_fixed = &res->leaks_fixed;\n\n } else if (refcount1 < refcount2 && (fix & BDRV_FIX_ERRORS)) {\n\n num_fixed = &res->corruptions_fixed;\n\n }\n\n\n\n fprintf(stderr, \"%s cluster %\" PRId64 \" refcount=%\" PRIu64\n\n \" reference=%\" PRIu64 \"\\n\",\n\n num_fixed != NULL ? \"Repairing\" :\n\n refcount1 < refcount2 ? \"ERROR\" :\n\n \"Leaked\",\n\n i, refcount1, refcount2);\n\n\n\n if (num_fixed) {\n\n ret = update_refcount(bs, i << s->cluster_bits, 1,\n\n refcount_diff(refcount1, refcount2),\n\n refcount1 > refcount2,\n\n QCOW2_DISCARD_ALWAYS);\n\n if (ret >= 0) {\n\n (*num_fixed)++;\n\n continue;\n\n }\n\n }\n\n\n\n /* And if we couldn't, print an error */\n\n if (refcount1 < refcount2) {\n\n res->corruptions++;\n\n } else {\n\n res->leaks++;\n\n }\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "7453c96b78c2b09aa72924f933bb9616e5474194", + "length": 532 + }, + { + "index": 1651, + "code": "void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)\n\n{\n\n RTPMuxContext *s = s1->priv_data;\n\n int len, max_packet_size;\n\n uint8_t *p;\n\n const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;\n\n const int max_au_headers_size = 2 + 2 * max_frames_per_packet;\n\n\n\n /* skip ADTS header, if present */\n\n if ((s1->streams[0]->codec->extradata_size) == 0) {\n\n size -= 7;\n\n buff += 7;\n\n }\n\n max_packet_size = s->max_payload_size - max_au_headers_size;\n\n\n\n /* test if the packet must be sent */\n\n len = (s->buf_ptr - s->buf);\n\n if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {\n\n int au_size = s->num_frames * 2;\n\n\n\n p = s->buf + max_au_headers_size - au_size - 2;\n\n if (p != s->buf) {\n\n memmove(p + 2, s->buf + 2, au_size);\n\n }\n\n /* Write the AU header size */\n\n p[0] = ((au_size * 8) & 0xFF) >> 8;\n\n p[1] = (au_size * 8) & 0xFF;\n\n\n\n ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);\n\n\n\n s->num_frames = 0;\n\n }\n\n if (s->num_frames == 0) {\n\n s->buf_ptr = s->buf + max_au_headers_size;\n\n s->timestamp = s->cur_timestamp;\n\n }\n\n\n\n if (size <= max_packet_size) {\n\n p = s->buf + s->num_frames++ * 2 + 2;\n\n *p++ = size >> 5;\n\n *p = (size & 0x1F) << 3;\n\n memcpy(s->buf_ptr, buff, size);\n\n s->buf_ptr += size;\n\n } else {\n\n int au_size = size;\n\n\n\n max_packet_size = s->max_payload_size - 4;\n\n p = s->buf;\n\n p[0] = 0;\n\n p[1] = 16;\n\n while (size > 0) {\n\n len = FFMIN(size, max_packet_size);\n\n p[2] = au_size >> 5;\n\n p[3] = (au_size & 0x1F) << 3;\n\n memcpy(p + 4, buff, len);\n\n ff_rtp_send_data(s1, p, len + 4, len == size);\n\n size -= len;\n\n buff += len;\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "e004d175fe2463af8242e390b15350f4745be7b4", + "length": 621 + }, + { + "index": 16803, + "code": "void process_pending_signals(CPUArchState *cpu_env)\n\n{\n\n CPUState *cpu = ENV_GET_CPU(cpu_env);\n\n int sig;\n\n abi_ulong handler;\n\n sigset_t set, old_set;\n\n target_sigset_t target_old_set;\n\n struct emulated_sigtable *k;\n\n struct target_sigaction *sa;\n\n struct sigqueue *q;\n\n TaskState *ts = cpu->opaque;\n\n\n\n if (!ts->signal_pending)\n\n return;\n\n\n\n /* FIXME: This is not threadsafe. */\n\n k = ts->sigtab;\n\n for(sig = 1; sig <= TARGET_NSIG; sig++) {\n\n if (k->pending)\n\n goto handle_signal;\n\n k++;\n\n }\n\n /* if no signal is pending, just return */\n\n ts->signal_pending = 0;\n\n return;\n\n\n\n handle_signal:\n\n#ifdef DEBUG_SIGNAL\n\n fprintf(stderr, \"qemu: process signal %d\\n\", sig);\n\n#endif\n\n /* dequeue signal */\n\n q = k->first;\n\n k->first = q->next;\n\n if (!k->first)\n\n k->pending = 0;\n\n\n\n sig = gdb_handlesig(cpu, sig);\n\n if (!sig) {\n\n sa = NULL;\n\n handler = TARGET_SIG_IGN;\n\n } else {\n\n sa = &sigact_table[sig - 1];\n\n handler = sa->_sa_handler;\n\n }\n\n\n\n if (handler == TARGET_SIG_DFL) {\n\n /* default handler : ignore some signal. The other are job control or fatal */\n\n if (sig == TARGET_SIGTSTP || sig == TARGET_SIGTTIN || sig == TARGET_SIGTTOU) {\n\n kill(getpid(),SIGSTOP);\n\n } else if (sig != TARGET_SIGCHLD &&\n\n sig != TARGET_SIGURG &&\n\n sig != TARGET_SIGWINCH &&\n\n sig != TARGET_SIGCONT) {\n\n force_sig(sig);\n\n }\n\n } else if (handler == TARGET_SIG_IGN) {\n\n /* ignore sig */\n\n } else if (handler == TARGET_SIG_ERR) {\n\n force_sig(sig);\n\n } else {\n\n /* compute the blocked signals during the handler execution */\n\n target_to_host_sigset(&set, &sa->sa_mask);\n\n /* SA_NODEFER indicates that the current signal should not be\n\n blocked during the handler */\n\n if (!(sa->sa_flags & TARGET_SA_NODEFER))\n\n sigaddset(&set, target_to_host_signal(sig));\n\n\n\n /* block signals in the handler using Linux */\n\n sigprocmask(SIG_BLOCK, &set, &old_set);\n\n /* save the previous blocked signal state to restore it at the\n\n end of the signal execution (see do_sigreturn) */\n\n host_to_target_sigset_internal(&target_old_set, &old_set);\n\n\n\n /* if the CPU is in VM86 mode, we restore the 32 bit values */\n\n#if defined(TARGET_I386) && !defined(TARGET_X86_64)\n\n {\n\n CPUX86State *env = cpu_env;\n\n if (env->eflags & VM_MASK)\n\n save_v86_state(env);\n\n }\n\n#endif\n\n /* prepare the stack frame of the virtual CPU */\n\n#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)\n\n /* These targets do not have traditional signals. */\n\n setup_rt_frame(sig, sa, &q->info, &target_old_set, cpu_env);\n\n#else\n\n if (sa->sa_flags & TARGET_SA_SIGINFO)\n\n setup_rt_frame(sig, sa, &q->info, &target_old_set, cpu_env);\n\n else\n\n setup_frame(sig, sa, &target_old_set, cpu_env);\n\n#endif\n\n\tif (sa->sa_flags & TARGET_SA_RESETHAND)\n\n sa->_sa_handler = TARGET_SIG_DFL;\n\n }\n\n if (q != &k->info)\n\n free_sigqueue(cpu_env, q);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "1c275925bfbbc2de84a8f0e09d1dd70bbefb6da3", + "length": 818 + }, + { + "index": 25282, + "code": "static av_cold int MPA_encode_init(AVCodecContext *avctx)\n\n{\n\n MpegAudioContext *s = avctx->priv_data;\n\n int freq = avctx->sample_rate;\n\n int bitrate = avctx->bit_rate;\n\n int channels = avctx->channels;\n\n int i, v, table;\n\n float a;\n\n\n\n if (channels <= 0 || channels > 2){\n\n av_log(avctx, AV_LOG_ERROR, \"encoding %d channel(s) is not allowed in mp2\\n\", channels);\n\n return AVERROR(EINVAL);\n\n }\n\n bitrate = bitrate / 1000;\n\n s->nb_channels = channels;\n\n avctx->frame_size = MPA_FRAME_SIZE;\n\n avctx->delay = 512 - 32 + 1;\n\n\n\n /* encoding freq */\n\n s->lsf = 0;\n\n for(i=0;i<3;i++) {\n\n if (avpriv_mpa_freq_tab[i] == freq)\n\n break;\n\n if ((avpriv_mpa_freq_tab[i] / 2) == freq) {\n\n s->lsf = 1;\n\n break;\n\n }\n\n }\n\n if (i == 3){\n\n av_log(avctx, AV_LOG_ERROR, \"Sampling rate %d is not allowed in mp2\\n\", freq);\n\n return AVERROR(EINVAL);\n\n }\n\n s->freq_index = i;\n\n\n\n /* encoding bitrate & frequency */\n\n for(i=0;i<15;i++) {\n\n if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate)\n\n break;\n\n }\n\n if (i == 15){\n\n av_log(avctx, AV_LOG_ERROR, \"bitrate %d is not allowed in mp2\\n\", bitrate);\n\n return AVERROR(EINVAL);\n\n }\n\n s->bitrate_index = i;\n\n\n\n /* compute total header size & pad bit */\n\n\n\n a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);\n\n s->frame_size = ((int)a) * 8;\n\n\n\n /* frame fractional size to compute padding */\n\n s->frame_frac = 0;\n\n s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);\n\n\n\n /* select the right allocation table */\n\n table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf);\n\n\n\n /* number of used subbands */\n\n s->sblimit = ff_mpa_sblimit_table[table];\n\n s->alloc_table = ff_mpa_alloc_tables[table];\n\n\n\n av_dlog(avctx, \"%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\\n\",\n\n bitrate, freq, s->frame_size, table, s->frame_frac_incr);\n\n\n\n for(i=0;inb_channels;i++)\n\n s->samples_offset[i] = 0;\n\n\n\n for(i=0;i<257;i++) {\n\n int v;\n\n v = ff_mpa_enwindow[i];\n\n#if WFRAC_BITS != 16\n\n v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);\n\n#endif\n\n s->filter_bank[i] = v;\n\n if ((i & 63) != 0)\n\n v = -v;\n\n if (i != 0)\n\n s->filter_bank[512 - i] = v;\n\n }\n\n\n\n for(i=0;i<64;i++) {\n\n v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20));\n\n if (v <= 0)\n\n v = 1;\n\n s->scale_factor_table[i] = v;\n\n s->scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20);\n\n }\n\n for(i=0;i<128;i++) {\n\n v = i - 64;\n\n if (v <= -3)\n\n v = 0;\n\n else if (v < 0)\n\n v = 1;\n\n else if (v == 0)\n\n v = 2;\n\n else if (v < 3)\n\n v = 3;\n\n else\n\n v = 4;\n\n s->scale_diff_table[i] = v;\n\n }\n\n\n\n for(i=0;i<17;i++) {\n\n v = ff_mpa_quant_bits[i];\n\n if (v < 0)\n\n v = -v;\n\n else\n\n v = v * 3;\n\n s->total_quant_bits[i] = 12 * v;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2df0c32ea12ddfa72ba88309812bfb13b674130f", + "length": 1017 + }, + { + "index": 4593, + "code": "static int mov_write_sidx_tag(AVIOContext *pb,\n\n MOVTrack *track, int ref_size, int total_sidx_size)\n\n{\n\n int64_t pos = avio_tell(pb), offset_pos, end_pos;\n\n int64_t presentation_time, duration, offset;\n\n int starts_with_SAP, i, entries;\n\n\n\n if (track->entry) {\n\n entries = 1;\n\n presentation_time = track->start_dts + track->frag_start +\n\n track->cluster[0].cts;\n\n duration = track->end_pts -\n\n (track->cluster[0].dts + track->cluster[0].cts);\n\n starts_with_SAP = track->cluster[0].flags & MOV_SYNC_SAMPLE;\n\n\n\n // pts<0 should be cut away using edts\n\n if (presentation_time < 0) {\n\n duration += presentation_time;\n\n presentation_time = 0;\n\n }\n\n } else {\n\n entries = track->nb_frag_info;\n\n\n\n presentation_time = track->frag_info[0].time;\n\n }\n\n\n\n avio_wb32(pb, 0); /* size */\n\n ffio_wfourcc(pb, \"sidx\");\n\n avio_w8(pb, 1); /* version */\n\n avio_wb24(pb, 0);\n\n avio_wb32(pb, track->track_id); /* reference_ID */\n\n avio_wb32(pb, track->timescale); /* timescale */\n\n avio_wb64(pb, presentation_time); /* earliest_presentation_time */\n\n offset_pos = avio_tell(pb);\n\n avio_wb64(pb, 0); /* first_offset (offset to referenced moof) */\n\n avio_wb16(pb, 0); /* reserved */\n\n\n\n avio_wb16(pb, entries); /* reference_count */\n\n for (i = 0; i < entries; i++) {\n\n if (!track->entry) {\n\n if (i > 1 && track->frag_info[i].offset != track->frag_info[i - 1].offset + track->frag_info[i - 1].size) {\n\n av_log(NULL, AV_LOG_ERROR, \"Non-consecutive fragments, writing incorrect sidx\\n\");\n\n }\n\n duration = track->frag_info[i].duration;\n\n ref_size = track->frag_info[i].size;\n\n starts_with_SAP = 1;\n\n }\n\n avio_wb32(pb, (0 << 31) | (ref_size & 0x7fffffff)); /* reference_type (0 = media) | referenced_size */\n\n avio_wb32(pb, duration); /* subsegment_duration */\n\n avio_wb32(pb, (starts_with_SAP << 31) | (0 << 28) | 0); /* starts_with_SAP | SAP_type | SAP_delta_time */\n\n }\n\n\n\n end_pos = avio_tell(pb);\n\n offset = pos + total_sidx_size - end_pos;\n\n avio_seek(pb, offset_pos, SEEK_SET);\n\n avio_wb64(pb, offset);\n\n avio_seek(pb, end_pos, SEEK_SET);\n\n return update_size(pb, pos);\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "8e34089e265a6b01e1e3301e8864439d26793753", + "length": 662 + }, + { + "index": 10241, + "code": "_syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)\n\n#endif\n\n#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)\n\n_syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)\n\n_syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,\n\n uid_t,owner,gid_t,group,int,flags)\n\n#endif\n\n#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \\\n\n defined(__NR_fstatat64)\n\n_syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname,\n\n struct stat *,buf,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)\n\n_syscall3(int,sys_futimesat,int,dirfd,const char *,pathname,\n\n const struct timeval *,times)\n\n#endif\n\n#if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \\\n\n defined(__NR_newfstatat)\n\n_syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname,\n\n struct stat *,buf,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_linkat) && defined(__NR_linkat)\n\n_syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath,\n\n int,newdirfd,const char *,newpath,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)\n\n_syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)\n\n_syscall4(int,sys_mknodat,int,dirfd,const char *,pathname,\n\n mode_t,mode,dev_t,dev)\n\n#endif\n\n#if defined(TARGET_NR_openat) && defined(__NR_openat)\n\n_syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)\n\n_syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname,\n\n char *,buf,size_t,bufsize)\n\n#endif\n\n#if defined(TARGET_NR_renameat) && defined(__NR_renameat)\n\n_syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath,\n\n int,newdirfd,const char *,newpath)\n\n#endif\n\n#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)\n\n_syscall3(int,sys_symlinkat,const char *,oldpath,\n\n int,newdirfd,const char *,newpath)\n\n#endif\n\n#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)\n\n_syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)\n\n_syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,\n\n const struct timespec *,tsp,int,flags)\n\n#endif\n\n\n\n#endif /* CONFIG_ATFILE */\n\n\n\n#ifdef CONFIG_INOTIFY\n\n#include \n\n\n\n#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)\n\nstatic int sys_inotify_init(void)\n\n{\n\n return (inotify_init());\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ebc996f3b13004e7272c462254522ba0102f09fe", + "length": 765 + }, + { + "index": 7412, + "code": "static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t old_l2_offset;\n\n uint64_t *l2_table;\n\n int64_t l2_offset;\n\n int ret;\n\n\n\n old_l2_offset = s->l1_table[l1_index];\n\n\n\n trace_qcow2_l2_allocate(bs, l1_index);\n\n\n\n /* allocate a new l2 entry */\n\n\n\n l2_offset = qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t));\n\n if (l2_offset < 0) {\n\n return l2_offset;\n\n }\n\n\n\n ret = qcow2_cache_flush(bs, s->refcount_block_cache);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* allocate a new entry in the l2 cache */\n\n\n\n trace_qcow2_l2_allocate_get_empty(bs, l1_index);\n\n ret = qcow2_cache_get_empty(bs, s->l2_table_cache, l2_offset, (void**) table);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n l2_table = *table;\n\n\n\n if ((old_l2_offset & L1E_OFFSET_MASK) == 0) {\n\n /* if there was no old l2 table, clear the new table */\n\n memset(l2_table, 0, s->l2_size * sizeof(uint64_t));\n\n } else {\n\n uint64_t* old_table;\n\n\n\n /* if there was an old l2 table, read it from the disk */\n\n BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_COW_READ);\n\n ret = qcow2_cache_get(bs, s->l2_table_cache,\n\n old_l2_offset & L1E_OFFSET_MASK,\n\n (void**) &old_table);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n memcpy(l2_table, old_table, s->cluster_size);\n\n\n\n ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &old_table);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n }\n\n\n\n /* write the l2 table to the file */\n\n BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_WRITE);\n\n\n\n trace_qcow2_l2_allocate_write_l2(bs, l1_index);\n\n qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);\n\n ret = qcow2_cache_flush(bs, s->l2_table_cache);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* update the L1 entry */\n\n trace_qcow2_l2_allocate_write_l1(bs, l1_index);\n\n s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED;\n\n ret = write_l1_entry(bs, l1_index);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n *table = l2_table;\n\n trace_qcow2_l2_allocate_done(bs, l1_index, 0);\n\n return 0;\n\n\n\nfail:\n\n trace_qcow2_l2_allocate_done(bs, l1_index, ret);\n\n qcow2_cache_put(bs, s->l2_table_cache, (void**) table);\n\n s->l1_table[l1_index] = old_l2_offset;\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "e23e400ec62a03dea58ddb38479b4f1ef86f556d", + "length": 731 + }, + { + "index": 3616, + "code": "int ff_mpv_common_frame_size_change(MpegEncContext *s)\n\n{\n\n int i, err = 0;\n\n\n\n if (!s->context_initialized)\n\n return AVERROR(EINVAL);\n\n\n\n if (s->slice_context_count > 1) {\n\n for (i = 0; i < s->slice_context_count; i++) {\n\n free_duplicate_context(s->thread_context[i]);\n\n }\n\n for (i = 1; i < s->slice_context_count; i++) {\n\n av_freep(&s->thread_context[i]);\n\n }\n\n } else\n\n free_duplicate_context(s);\n\n\n\n free_context_frame(s);\n\n\n\n if (s->picture)\n\n for (i = 0; i < MAX_PICTURE_COUNT; i++) {\n\n s->picture[i].needs_realloc = 1;\n\n }\n\n\n\n s->last_picture_ptr =\n\n s->next_picture_ptr =\n\n s->current_picture_ptr = NULL;\n\n\n\n // init\n\n if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)\n\n s->mb_height = (s->height + 31) / 32 * 2;\n\n else\n\n s->mb_height = (s->height + 15) / 16;\n\n\n\n if ((s->width || s->height) &&\n\n (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)\n\n goto fail;\n\n\n\n if ((err = init_context_frame(s)))\n\n goto fail;\n\n\n\n s->thread_context[0] = s;\n\n\n\n if (s->width && s->height) {\n\n int nb_slices = s->slice_context_count;\n\n if (nb_slices > 1) {\n\n for (i = 1; i < nb_slices; i++) {\n\n s->thread_context[i] = av_malloc(sizeof(MpegEncContext));\n\n memcpy(s->thread_context[i], s, sizeof(MpegEncContext));\n\n }\n\n\n\n for (i = 0; i < nb_slices; i++) {\n\n if ((err = init_duplicate_context(s->thread_context[i])) < 0)\n\n goto fail;\n\n s->thread_context[i]->start_mb_y =\n\n (s->mb_height * (i) + nb_slices / 2) / nb_slices;\n\n s->thread_context[i]->end_mb_y =\n\n (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;\n\n }\n\n } else {\n\n err = init_duplicate_context(s);\n\n if (err < 0)\n\n goto fail;\n\n s->start_mb_y = 0;\n\n s->end_mb_y = s->mb_height;\n\n }\n\n s->slice_context_count = nb_slices;\n\n }\n\n\n\n return 0;\n\n fail:\n\n ff_mpv_common_end(s);\n\n return err;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f30a7d9861af884f352ec2484820a75d79a4e0e2", + "length": 610 + }, + { + "index": 19182, + "code": "static int decode_header(MPADecodeContext *s, UINT32 header)\n\n{\n\n int sample_rate, frame_size, mpeg25, padding;\n\n int sample_rate_index, bitrate_index;\n\n if (header & (1<<20)) {\n\n s->lsf = (header & (1<<19)) ? 0 : 1;\n\n mpeg25 = 0;\n\n } else {\n\n s->lsf = 1;\n\n mpeg25 = 1;\n\n }\n\n \n\n s->layer = 4 - ((header >> 17) & 3);\n\n /* extract frequency */\n\n sample_rate_index = (header >> 10) & 3;\n\n sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);\n\n if (sample_rate == 0)\n\n return 1;\n\n sample_rate_index += 3 * (s->lsf + mpeg25);\n\n s->sample_rate_index = sample_rate_index;\n\n s->error_protection = ((header >> 16) & 1) ^ 1;\n\n\n\n bitrate_index = (header >> 12) & 0xf;\n\n padding = (header >> 9) & 1;\n\n //extension = (header >> 8) & 1;\n\n s->mode = (header >> 6) & 3;\n\n s->mode_ext = (header >> 4) & 3;\n\n //copyright = (header >> 3) & 1;\n\n //original = (header >> 2) & 1;\n\n //emphasis = header & 3;\n\n\n\n if (s->mode == MPA_MONO)\n\n s->nb_channels = 1;\n\n else\n\n s->nb_channels = 2;\n\n \n\n if (bitrate_index != 0) {\n\n frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];\n\n s->bit_rate = frame_size * 1000;\n\n switch(s->layer) {\n\n case 1:\n\n frame_size = (frame_size * 12000) / sample_rate;\n\n frame_size = (frame_size + padding) * 4;\n\n break;\n\n case 2:\n\n frame_size = (frame_size * 144000) / sample_rate;\n\n frame_size += padding;\n\n break;\n\n default:\n\n case 3:\n\n frame_size = (frame_size * 144000) / (sample_rate << s->lsf);\n\n frame_size += padding;\n\n break;\n\n }\n\n s->frame_size = frame_size;\n\n } else {\n\n /* if no frame size computed, signal it */\n\n if (!s->free_format_frame_size)\n\n return 1;\n\n /* free format: compute bitrate and real frame size from the\n\n frame size we extracted by reading the bitstream */\n\n s->frame_size = s->free_format_frame_size;\n\n switch(s->layer) {\n\n case 1:\n\n s->frame_size += padding * 4;\n\n s->bit_rate = (s->frame_size * sample_rate) / 48000;\n\n break;\n\n case 2:\n\n s->frame_size += padding;\n\n s->bit_rate = (s->frame_size * sample_rate) / 144000;\n\n break;\n\n default:\n\n case 3:\n\n s->frame_size += padding;\n\n s->bit_rate = (s->frame_size * (sample_rate << s->lsf)) / 144000;\n\n break;\n\n }\n\n }\n\n s->sample_rate = sample_rate;\n\n \n\n#ifdef DEBUG\n\n printf(\"layer%d, %d Hz, %d kbits/s, \",\n\n s->layer, s->sample_rate, s->bit_rate);\n\n if (s->nb_channels == 2) {\n\n if (s->layer == 3) {\n\n if (s->mode_ext & MODE_EXT_MS_STEREO)\n\n printf(\"ms-\");\n\n if (s->mode_ext & MODE_EXT_I_STEREO)\n\n printf(\"i-\");\n\n }\n\n printf(\"stereo\");\n\n } else {\n\n printf(\"mono\");\n\n }\n\n printf(\"\\n\");\n\n#endif\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "fad9f495c07be2d990620f5000de075ba2cf1cbd", + "length": 892 + }, + { + "index": 16578, + "code": "static int megasas_dcmd_cfg_read(MegasasState *s, MegasasCmd *cmd)\n\n{\n\n uint8_t data[4096];\n\n struct mfi_config_data *info;\n\n int num_pd_disks = 0, array_offset, ld_offset;\n\n BusChild *kid;\n\n\n\n if (cmd->iov_size > 4096) {\n\n return MFI_STAT_INVALID_PARAMETER;\n\n }\n\n\n\n QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {\n\n num_pd_disks++;\n\n }\n\n info = (struct mfi_config_data *)&data;\n\n /*\n\n * Array mapping:\n\n * - One array per SCSI device\n\n * - One logical drive per SCSI device\n\n * spanning the entire device\n\n */\n\n info->array_count = num_pd_disks;\n\n info->array_size = sizeof(struct mfi_array) * num_pd_disks;\n\n info->log_drv_count = num_pd_disks;\n\n info->log_drv_size = sizeof(struct mfi_ld_config) * num_pd_disks;\n\n info->spares_count = 0;\n\n info->spares_size = sizeof(struct mfi_spare);\n\n info->size = sizeof(struct mfi_config_data) + info->array_size +\n\n info->log_drv_size;\n\n if (info->size > 4096) {\n\n return MFI_STAT_INVALID_PARAMETER;\n\n }\n\n\n\n array_offset = sizeof(struct mfi_config_data);\n\n ld_offset = array_offset + sizeof(struct mfi_array) * num_pd_disks;\n\n\n\n QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {\n\n SCSIDevice *sdev = DO_UPCAST(SCSIDevice, qdev, kid->child);\n\n BlockConf *conf = &sdev->conf;\n\n uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (sdev->lun & 0xFF);\n\n struct mfi_array *array;\n\n struct mfi_ld_config *ld;\n\n uint64_t pd_size;\n\n int i;\n\n\n\n array = (struct mfi_array *)(data + array_offset);\n\n bdrv_get_geometry(conf->bs, &pd_size);\n\n array->size = cpu_to_le64(pd_size);\n\n array->num_drives = 1;\n\n array->array_ref = cpu_to_le16(sdev_id);\n\n array->pd[0].ref.v.device_id = cpu_to_le16(sdev_id);\n\n array->pd[0].ref.v.seq_num = 0;\n\n array->pd[0].fw_state = MFI_PD_STATE_ONLINE;\n\n array->pd[0].encl.pd = 0xFF;\n\n array->pd[0].encl.slot = (sdev->id & 0xFF);\n\n for (i = 1; i < MFI_MAX_ROW_SIZE; i++) {\n\n array->pd[i].ref.v.device_id = 0xFFFF;\n\n array->pd[i].ref.v.seq_num = 0;\n\n array->pd[i].fw_state = MFI_PD_STATE_UNCONFIGURED_GOOD;\n\n array->pd[i].encl.pd = 0xFF;\n\n array->pd[i].encl.slot = 0xFF;\n\n }\n\n array_offset += sizeof(struct mfi_array);\n\n ld = (struct mfi_ld_config *)(data + ld_offset);\n\n memset(ld, 0, sizeof(struct mfi_ld_config));\n\n ld->properties.ld.v.target_id = (sdev->id & 0xFF);\n\n ld->properties.default_cache_policy = MR_LD_CACHE_READ_AHEAD |\n\n MR_LD_CACHE_READ_ADAPTIVE;\n\n ld->properties.current_cache_policy = MR_LD_CACHE_READ_AHEAD |\n\n MR_LD_CACHE_READ_ADAPTIVE;\n\n ld->params.state = MFI_LD_STATE_OPTIMAL;\n\n ld->params.stripe_size = 3;\n\n ld->params.num_drives = 1;\n\n ld->params.span_depth = 1;\n\n ld->params.is_consistent = 1;\n\n ld->span[0].start_block = 0;\n\n ld->span[0].num_blocks = cpu_to_le64(pd_size);\n\n ld->span[0].array_ref = cpu_to_le16(sdev_id);\n\n ld_offset += sizeof(struct mfi_ld_config);\n\n }\n\n\n\n cmd->iov_size -= dma_buf_read((uint8_t *)data, info->size, &cmd->qsg);\n\n return MFI_STAT_OK;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4be746345f13e99e468c60acbd3a355e8183e3ce", + "length": 947 + }, + { + "index": 15380, + "code": "D(float, sse)\n\nD(float, avx)\n\nD(int16, mmx)\n\nD(int16, sse2)\n\n\n\nav_cold void swri_rematrix_init_x86(struct SwrContext *s){\n\n int mm_flags = av_get_cpu_flags();\n\n int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);\n\n int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);\n\n int num = nb_in * nb_out;\n\n int i,j;\n\n\n\n s->mix_1_1_simd = NULL;\n\n s->mix_2_1_simd = NULL;\n\n\n\n if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){\n\n if(mm_flags & AV_CPU_FLAG_MMX) {\n\n s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;\n\n s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;\n\n }\n\n if(mm_flags & AV_CPU_FLAG_SSE2) {\n\n s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;\n\n s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;\n\n }\n\n s->native_simd_matrix = av_mallocz(2 * num * sizeof(int16_t));\n\n s->native_simd_one = av_mallocz(2 * sizeof(int16_t));\n\n for(i=0; inative_matrix)[i * nb_in + j]));\n\n sh = FFMAX(av_log2(sh) - 14, 0);\n\n for(j=0; jnative_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;\n\n ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =\n\n ((((int*)s->native_matrix)[i * nb_in + j]) + (1<>1)) >> sh;\n\n }\n\n }\n\n ((int16_t*)s->native_simd_one)[1] = 14;\n\n ((int16_t*)s->native_simd_one)[0] = 16384;\n\n } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){\n\n if(mm_flags & AV_CPU_FLAG_SSE) {\n\n s->mix_1_1_simd = ff_mix_1_1_a_float_sse;\n\n s->mix_2_1_simd = ff_mix_2_1_a_float_sse;\n\n }\n\n if(HAVE_AVX_EXTERNAL && mm_flags & AV_CPU_FLAG_AVX) {\n\n s->mix_1_1_simd = ff_mix_1_1_a_float_avx;\n\n s->mix_2_1_simd = ff_mix_2_1_a_float_avx;\n\n }\n\n s->native_simd_matrix = av_mallocz(num * sizeof(float));\n\n memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));\n\n s->native_simd_one = av_mallocz(sizeof(float));\n\n memcpy(s->native_simd_one, s->native_one, sizeof(float));\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "9937362c54be085e75c90c55dad443329be59e69", + "length": 734 + }, + { + "index": 16289, + "code": "static void init_proc_970FX (CPUPPCState *env)\n\n{\n\n gen_spr_ne_601(env);\n\n gen_spr_7xx(env);\n\n /* Time base */\n\n gen_tbl(env);\n\n /* Hardware implementation registers */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID0, \"HID0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_clear,\n\n 0x60000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID1, \"HID1\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_750FX_HID2, \"HID2\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_970_HID5, \"HID5\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n POWERPC970_HID5_INIT);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_L2CR, \"L2CR\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, NULL,\n\n 0x00000000);\n\n /* Memory management */\n\n /* XXX: not correct */\n\n gen_low_BATs(env);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCFG, \"MMUCFG\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, SPR_NOACCESS,\n\n 0x00000000); /* TOFIX */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCSR0, \"MMUCSR0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000); /* TOFIX */\n\n spr_register(env, SPR_HIOR, \"SPR_HIOR\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_hior, &spr_write_hior,\n\n 0x00000000);\n\n spr_register(env, SPR_CTRL, \"SPR_CTRL\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n spr_register(env, SPR_UCTRL, \"SPR_UCTRL\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n spr_register(env, SPR_VRSAVE, \"SPR_VRSAVE\",\n\n &spr_read_generic, &spr_write_generic,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n#if !defined(CONFIG_USER_ONLY)\n\n env->slb_nr = 64;\n\n#endif\n\n init_excp_970(env);\n\n env->dcache_line_size = 128;\n\n env->icache_line_size = 128;\n\n /* Allocate hardware IRQ controller */\n\n ppc970_irq_init(env);\n\n /* Can't find information on what this should be on reset. This\n\n * value is the one used by 74xx processors. */\n\n vscr_init(env, 0x00010000);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "9633fcc6a02f23e3ef00aa5fe3fe9c41f57c3456", + "length": 718 + }, + { + "index": 20041, + "code": "void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,\n\n VirtIOBlockDataPlane **dataplane,\n\n Error **errp)\n\n{\n\n VirtIOBlockDataPlane *s;\n\n Error *local_err = NULL;\n\n BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));\n\n VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);\n\n\n\n *dataplane = NULL;\n\n\n\n if (!conf->data_plane && !conf->iothread) {\n\n return;\n\n }\n\n\n\n /* Don't try if transport does not support notifiers. */\n\n if (!k->set_guest_notifiers || !k->set_host_notifier) {\n\n error_setg(errp,\n\n \"device is incompatible with x-data-plane \"\n\n \"(transport does not support notifiers)\");\n\n return;\n\n }\n\n\n\n /* If dataplane is (re-)enabled while the guest is running there could be\n\n * block jobs that can conflict.\n\n */\n\n if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE,\n\n &local_err)) {\n\n error_setg(errp, \"cannot start dataplane thread: %s\",\n\n error_get_pretty(local_err));\n\n error_free(local_err);\n\n return;\n\n }\n\n\n\n s = g_new0(VirtIOBlockDataPlane, 1);\n\n s->vdev = vdev;\n\n s->conf = conf;\n\n\n\n if (conf->iothread) {\n\n s->iothread = conf->iothread;\n\n object_ref(OBJECT(s->iothread));\n\n } else {\n\n /* Create per-device IOThread if none specified. This is for\n\n * x-data-plane option compatibility. If x-data-plane is removed we\n\n * can drop this.\n\n */\n\n object_initialize(&s->internal_iothread_obj,\n\n sizeof(s->internal_iothread_obj),\n\n TYPE_IOTHREAD);\n\n user_creatable_complete(OBJECT(&s->internal_iothread_obj), &error_abort);\n\n s->iothread = &s->internal_iothread_obj;\n\n }\n\n s->ctx = iothread_get_aio_context(s->iothread);\n\n s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);\n\n\n\n error_setg(&s->blocker, \"block device is in use by data plane\");\n\n blk_op_block_all(conf->conf.blk, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_RESIZE, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_BACKUP_SOURCE, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_COMMIT, s->blocker);\n\n\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_MIRROR, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_STREAM, s->blocker);\n\n blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_REPLACE, s->blocker);\n\n\n\n *dataplane = s;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "4ef3982a99f9d2634588b4785c8d841605517946", + "length": 673 + }, + { + "index": 20851, + "code": "int ff_h264_context_init(H264Context *h)\n\n{\n\n ERContext *er = &h->er;\n\n int mb_array_size = h->mb_height * h->mb_stride;\n\n int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1);\n\n int c_size = h->mb_stride * (h->mb_height + 1);\n\n int yc_size = y_size + 2 * c_size;\n\n int x, y, i;\n\n\n\n FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[0],\n\n h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail)\n\n FF_ALLOCZ_OR_GOTO(h->avctx, h->top_borders[1],\n\n h->mb_width * 16 * 3 * sizeof(uint8_t) * 2, fail)\n\n\n\n h->ref_cache[0][scan8[5] + 1] =\n\n h->ref_cache[0][scan8[7] + 1] =\n\n h->ref_cache[0][scan8[13] + 1] =\n\n h->ref_cache[1][scan8[5] + 1] =\n\n h->ref_cache[1][scan8[7] + 1] =\n\n h->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;\n\n\n\n if (CONFIG_ERROR_RESILIENCE) {\n\n /* init ER */\n\n er->avctx = h->avctx;\n\n er->mecc = &h->mecc;\n\n er->decode_mb = h264_er_decode_mb;\n\n er->opaque = h;\n\n er->quarter_sample = 1;\n\n\n\n er->mb_num = h->mb_num;\n\n er->mb_width = h->mb_width;\n\n er->mb_height = h->mb_height;\n\n er->mb_stride = h->mb_stride;\n\n er->b8_stride = h->mb_width * 2 + 1;\n\n\n\n // error resilience code looks cleaner with this\n\n FF_ALLOCZ_OR_GOTO(h->avctx, er->mb_index2xy,\n\n (h->mb_num + 1) * sizeof(int), fail);\n\n\n\n for (y = 0; y < h->mb_height; y++)\n\n for (x = 0; x < h->mb_width; x++)\n\n er->mb_index2xy[x + y * h->mb_width] = x + y * h->mb_stride;\n\n\n\n er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) *\n\n h->mb_stride + h->mb_width;\n\n\n\n FF_ALLOCZ_OR_GOTO(h->avctx, er->error_status_table,\n\n mb_array_size * sizeof(uint8_t), fail);\n\n\n\n FF_ALLOC_OR_GOTO(h->avctx, er->mbintra_table, mb_array_size, fail);\n\n memset(er->mbintra_table, 1, mb_array_size);\n\n\n\n FF_ALLOCZ_OR_GOTO(h->avctx, er->mbskip_table, mb_array_size + 2, fail);\n\n\n\n FF_ALLOC_OR_GOTO(h->avctx, er->er_temp_buffer,\n\n h->mb_height * h->mb_stride, fail);\n\n\n\n FF_ALLOCZ_OR_GOTO(h->avctx, h->dc_val_base,\n\n yc_size * sizeof(int16_t), fail);\n\n er->dc_val[0] = h->dc_val_base + h->mb_width * 2 + 2;\n\n er->dc_val[1] = h->dc_val_base + y_size + h->mb_stride + 1;\n\n er->dc_val[2] = er->dc_val[1] + c_size;\n\n for (i = 0; i < yc_size; i++)\n\n h->dc_val_base[i] = 1024;\n\n }\n\n\n\n return 0;\n\n\n\nfail:\n\n return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "cf1e0786ed64e69614760bfb4ecd7adbde8e6094", + "length": 885 + }, + { + "index": 5126, + "code": "static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)\n\n{\n\n CPUArchState *env = cpu->env_ptr;\n\n uintptr_t ret;\n\n TranslationBlock *last_tb;\n\n int tb_exit;\n\n uint8_t *tb_ptr = itb->tc_ptr;\n\n\n\n qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,\n\n \"Trace %p [\" TARGET_FMT_lx \"] %s\\n\",\n\n itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));\n\n\n\n#if defined(DEBUG_DISAS)\n\n if (qemu_loglevel_mask(CPU_LOG_TB_CPU)\n\n && qemu_log_in_addr_range(itb->pc)) {\n\n#if defined(TARGET_I386)\n\n log_cpu_state(cpu, CPU_DUMP_CCOP);\n\n#elif defined(TARGET_M68K)\n\n /* ??? Should not modify env state for dumping. */\n\n cpu_m68k_flush_flags(env, env->cc_op);\n\n env->cc_op = CC_OP_FLAGS;\n\n env->sr = (env->sr & 0xffe0) | env->cc_dest | (env->cc_x << 4);\n\n log_cpu_state(cpu, 0);\n\n#else\n\n log_cpu_state(cpu, 0);\n\n#endif\n\n }\n\n#endif /* DEBUG_DISAS */\n\n\n\n cpu->can_do_io = !use_icount;\n\n ret = tcg_qemu_tb_exec(env, tb_ptr);\n\n cpu->can_do_io = 1;\n\n last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);\n\n tb_exit = ret & TB_EXIT_MASK;\n\n trace_exec_tb_exit(last_tb, tb_exit);\n\n\n\n if (tb_exit > TB_EXIT_IDX1) {\n\n /* We didn't start executing this TB (eg because the instruction\n\n * counter hit zero); we must restore the guest PC to the address\n\n * of the start of the TB.\n\n */\n\n CPUClass *cc = CPU_GET_CLASS(cpu);\n\n qemu_log_mask_and_addr(CPU_LOG_EXEC, last_tb->pc,\n\n \"Stopped execution of TB chain before %p [\"\n\n TARGET_FMT_lx \"] %s\\n\",\n\n last_tb->tc_ptr, last_tb->pc,\n\n lookup_symbol(last_tb->pc));\n\n if (cc->synchronize_from_tb) {\n\n cc->synchronize_from_tb(cpu, last_tb);\n\n } else {\n\n assert(cc->set_pc);\n\n cc->set_pc(cpu, last_tb->pc);\n\n }\n\n }\n\n if (tb_exit == TB_EXIT_REQUESTED) {\n\n /* We were asked to stop executing TBs (probably a pending\n\n * interrupt. We've now stopped, so clear the flag.\n\n */\n\n cpu->tcg_exit_req = 0;\n\n }\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "027d9a7d2911e993cdcbd21c7c35d1dd058f05bb", + "length": 580 + }, + { + "index": 18860, + "code": "dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,\n\n IBaseFilter *device_filter, IPin **ppin)\n\n{\n\n IEnumPins *pins = 0;\n\n IPin *device_pin = NULL;\n\n IPin *pin;\n\n int r;\n\n\n\n const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };\n\n const char *devtypename = (devtype == VideoDevice) ? \"video\" : \"audio\";\n\n\n\n r = IBaseFilter_EnumPins(device_filter, &pins);\n\n if (r != S_OK) {\n\n av_log(avctx, AV_LOG_ERROR, \"Could not enumerate pins.\\n\");\n\n return AVERROR(EIO);\n\n }\n\n\n\n while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {\n\n IKsPropertySet *p = NULL;\n\n IEnumMediaTypes *types;\n\n PIN_INFO info = {0};\n\n AM_MEDIA_TYPE *type;\n\n GUID category;\n\n DWORD r2;\n\n\n\n IPin_QueryPinInfo(pin, &info);\n\n IBaseFilter_Release(info.pFilter);\n\n\n\n if (info.dir != PINDIR_OUTPUT)\n\n goto next;\n\n if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)\n\n goto next;\n\n if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,\n\n NULL, 0, &category, sizeof(GUID), &r2) != S_OK)\n\n goto next;\n\n if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))\n\n goto next;\n\n\n\n if (IPin_EnumMediaTypes(pin, &types) != S_OK)\n\n goto next;\n\n\n\n IEnumMediaTypes_Reset(types);\n\n while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {\n\n if (IsEqualGUID(&type->majortype, mediatype[devtype])) {\n\n device_pin = pin;\n\n goto next;\n\n }\n\n CoTaskMemFree(type);\n\n }\n\n\n\nnext:\n\n if (types)\n\n IEnumMediaTypes_Release(types);\n\n if (p)\n\n IKsPropertySet_Release(p);\n\n if (device_pin != pin)\n\n IPin_Release(pin);\n\n }\n\n\n\n IEnumPins_Release(pins);\n\n\n\n if (!device_pin) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Could not find output pin from %s capture device.\\n\", devtypename);\n\n return AVERROR(EIO);\n\n }\n\n *ppin = device_pin;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d0da310317cae25c0c533f6862fb25dc81ec3d4b", + "length": 579 + }, + { + "index": 20838, + "code": "static void numa_add(const char *optarg)\n\n{\n\n char option[128];\n\n char *endptr;\n\n unsigned long long value, endvalue;\n\n unsigned long long nodenr;\n\n\n\n value = endvalue = 0ULL;\n\n\n\n optarg = get_opt_name(option, 128, optarg, ',');\n\n if (*optarg == ',') {\n\n optarg++;\n\n }\n\n if (!strcmp(option, \"node\")) {\n\n\n\n if (nb_numa_nodes >= MAX_NODES) {\n\n fprintf(stderr, \"qemu: too many NUMA nodes\\n\");\n\n exit(1);\n\n }\n\n\n\n if (get_param_value(option, 128, \"nodeid\", optarg) == 0) {\n\n nodenr = nb_numa_nodes;\n\n } else {\n\n nodenr = strtoull(option, NULL, 10);\n\n }\n\n\n\n if (nodenr >= MAX_NODES) {\n\n fprintf(stderr, \"qemu: invalid NUMA nodeid: %llu\\n\", nodenr);\n\n exit(1);\n\n }\n\n\n\n if (get_param_value(option, 128, \"mem\", optarg) == 0) {\n\n node_mem[nodenr] = 0;\n\n } else {\n\n int64_t sval;\n\n sval = strtosz(option, &endptr);\n\n if (sval < 0 || *endptr) {\n\n fprintf(stderr, \"qemu: invalid numa mem size: %s\\n\", optarg);\n\n exit(1);\n\n }\n\n node_mem[nodenr] = sval;\n\n }\n\n if (get_param_value(option, 128, \"cpus\", optarg) != 0) {\n\n value = strtoull(option, &endptr, 10);\n\n if (*endptr == '-') {\n\n endvalue = strtoull(endptr+1, &endptr, 10);\n\n } else {\n\n endvalue = value;\n\n }\n\n\n\n if (!(endvalue < MAX_CPUMASK_BITS)) {\n\n endvalue = MAX_CPUMASK_BITS - 1;\n\n fprintf(stderr,\n\n \"A max of %d CPUs are supported in a guest\\n\",\n\n MAX_CPUMASK_BITS);\n\n }\n\n\n\n bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);\n\n }\n\n nb_numa_nodes++;\n\n } else {\n\n fprintf(stderr, \"Invalid -numa option: %s\\n\", option);\n\n exit(1);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "5f1399651eaab1b04e49107250d182968a227aa6", + "length": 512 + }, + { + "index": 13074, + "code": "static int vnc_refresh_server_surface(VncDisplay *vd)\n\n{\n\n int width = MIN(pixman_image_get_width(vd->guest.fb),\n\n pixman_image_get_width(vd->server));\n\n int height = MIN(pixman_image_get_height(vd->guest.fb),\n\n pixman_image_get_height(vd->server));\n\n int cmp_bytes, server_stride, min_stride, guest_stride, y = 0;\n\n uint8_t *guest_row0 = NULL, *server_row0;\n\n VncState *vs;\n\n int has_dirty = 0;\n\n pixman_image_t *tmpbuf = NULL;\n\n\n\n struct timeval tv = { 0, 0 };\n\n\n\n if (!vd->non_adaptive) {\n\n gettimeofday(&tv, NULL);\n\n has_dirty = vnc_update_stats(vd, &tv);\n\n }\n\n\n\n /*\n\n * Walk through the guest dirty map.\n\n * Check and copy modified bits from guest to server surface.\n\n * Update server dirty map.\n\n */\n\n server_row0 = (uint8_t *)pixman_image_get_data(vd->server);\n\n server_stride = guest_stride = pixman_image_get_stride(vd->server);\n\n cmp_bytes = MIN(VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES,\n\n server_stride);\n\n if (vd->guest.format != VNC_SERVER_FB_FORMAT) {\n\n int width = pixman_image_get_width(vd->server);\n\n tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, width);\n\n } else {\n\n guest_row0 = (uint8_t *)pixman_image_get_data(vd->guest.fb);\n\n guest_stride = pixman_image_get_stride(vd->guest.fb);\n\n }\n\n min_stride = MIN(server_stride, guest_stride);\n\n\n\n for (;;) {\n\n int x;\n\n uint8_t *guest_ptr, *server_ptr;\n\n unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty,\n\n height * VNC_DIRTY_BPL(&vd->guest),\n\n y * VNC_DIRTY_BPL(&vd->guest));\n\n if (offset == height * VNC_DIRTY_BPL(&vd->guest)) {\n\n /* no more dirty bits */\n\n break;\n\n }\n\n y = offset / VNC_DIRTY_BPL(&vd->guest);\n\n x = offset % VNC_DIRTY_BPL(&vd->guest);\n\n\n\n server_ptr = server_row0 + y * server_stride + x * cmp_bytes;\n\n\n\n if (vd->guest.format != VNC_SERVER_FB_FORMAT) {\n\n qemu_pixman_linebuf_fill(tmpbuf, vd->guest.fb, width, 0, y);\n\n guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);\n\n } else {\n\n guest_ptr = guest_row0 + y * guest_stride;\n\n }\n\n guest_ptr += x * cmp_bytes;\n\n\n\n for (; x < DIV_ROUND_UP(width, VNC_DIRTY_PIXELS_PER_BIT);\n\n x++, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {\n\n int _cmp_bytes = cmp_bytes;\n\n if (!test_and_clear_bit(x, vd->guest.dirty[y])) {\n\n continue;\n\n }\n\n if ((x + 1) * cmp_bytes > min_stride) {\n\n _cmp_bytes = min_stride - x * cmp_bytes;\n\n }\n\n if (memcmp(server_ptr, guest_ptr, _cmp_bytes) == 0) {\n\n continue;\n\n }\n\n memcpy(server_ptr, guest_ptr, _cmp_bytes);\n\n if (!vd->non_adaptive) {\n\n vnc_rect_updated(vd, x * VNC_DIRTY_PIXELS_PER_BIT,\n\n y, &tv);\n\n }\n\n QTAILQ_FOREACH(vs, &vd->clients, next) {\n\n set_bit(x, vs->dirty[y]);\n\n }\n\n has_dirty++;\n\n }\n\n\n\n y++;\n\n }\n\n qemu_pixman_image_unref(tmpbuf);\n\n return has_dirty;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "eb8934b0418b3b1d125edddc4fc334a54334a49b", + "length": 824 + }, + { + "index": 1727, + "code": "int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n IVI45DecContext *ctx = avctx->priv_data;\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n int result, p, b;\n\n\n\n init_get_bits(&ctx->gb, buf, buf_size * 8);\n\n ctx->frame_data = buf;\n\n ctx->frame_size = buf_size;\n\n\n\n result = ctx->decode_pic_hdr(ctx, avctx);\n\n if (result) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Error while decoding picture header: %d\\n\", result);\n\n return -1;\n\n }\n\n if (ctx->gop_invalid)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (ctx->gop_flags & IVI5_IS_PROTECTED) {\n\n av_log(avctx, AV_LOG_ERROR, \"Password-protected clip!\\n\");\n\n return -1;\n\n }\n\n\n\n ctx->switch_buffers(ctx);\n\n\n\n //{ START_TIMER;\n\n\n\n if (ctx->is_nonnull_frame(ctx)) {\n\n for (p = 0; p < 3; p++) {\n\n for (b = 0; b < ctx->planes[p].num_bands; b++) {\n\n result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx);\n\n if (result) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Error while decoding band: %d, plane: %d\\n\", b, p);\n\n return -1;\n\n }\n\n }\n\n }\n\n }\n\n\n\n //STOP_TIMER(\"decode_planes\"); }\n\n\n\n /* If the bidirectional mode is enabled, next I and the following P frame will */\n\n /* be sent together. Unfortunately the approach below seems to be the only way */\n\n /* to handle the B-frames mode. That's exactly the same Intel decoders do. */\n\n if (avctx->codec_id == AV_CODEC_ID_INDEO4 && ctx->frame_type == 0/*FRAMETYPE_INTRA*/) {\n\n while (get_bits(&ctx->gb, 8)); // skip version string\n\n skip_bits_long(&ctx->gb, 64); // skip padding, TODO: implement correct 8-bytes alignment\n\n if (get_bits_left(&ctx->gb) > 18 && show_bits(&ctx->gb, 18) == 0x3FFF8)\n\n av_log(avctx, AV_LOG_ERROR, \"Buffer contains IP frames!\\n\");\n\n }\n\n\n\n if (ctx->frame.data[0])\n\n avctx->release_buffer(avctx, &ctx->frame);\n\n\n\n ctx->frame.reference = 0;\n\n\n if ((result = avctx->get_buffer(avctx, &ctx->frame)) < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"get_buffer() failed\\n\");\n\n return result;\n\n }\n\n\n\n if (ctx->is_scalable) {\n\n if (avctx->codec_id == AV_CODEC_ID_INDEO4)\n\n ff_ivi_recompose_haar(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);\n\n else\n\n ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);\n\n } else {\n\n ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);\n\n }\n\n\n\n ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]);\n\n ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]);\n\n\n\n *data_size = sizeof(AVFrame);\n\n *(AVFrame*)data = ctx->frame;\n\n\n\n return buf_size;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "b146d74730ab9ec5abede9066f770ad851e45fbc", + "length": 845 + }, + { + "index": 10399, + "code": "static void update_stream_timings(AVFormatContext *ic)\n\n{\n\n int64_t start_time, start_time1, start_time_text, end_time, end_time1;\n\n int64_t duration, duration1, filesize;\n\n int i;\n\n AVStream *st;\n\n AVProgram *p;\n\n\n\n start_time = INT64_MAX;\n\n start_time_text = INT64_MAX;\n\n end_time = INT64_MIN;\n\n duration = INT64_MIN;\n\n for (i = 0; i < ic->nb_streams; i++) {\n\n st = ic->streams[i];\n\n if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {\n\n start_time1 = av_rescale_q(st->start_time, st->time_base,\n\n AV_TIME_BASE_Q);\n\n if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codec->codec_type == AVMEDIA_TYPE_DATA) {\n\n if (start_time1 < start_time_text)\n\n start_time_text = start_time1;\n\n } else\n\n start_time = FFMIN(start_time, start_time1);\n\n end_time1 = AV_NOPTS_VALUE;\n\n if (st->duration != AV_NOPTS_VALUE) {\n\n end_time1 = start_time1 +\n\n av_rescale_q(st->duration, st->time_base,\n\n AV_TIME_BASE_Q);\n\n end_time = FFMAX(end_time, end_time1);\n\n }\n\n for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) {\n\n if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1)\n\n p->start_time = start_time1;\n\n if (p->end_time < end_time1)\n\n p->end_time = end_time1;\n\n }\n\n }\n\n if (st->duration != AV_NOPTS_VALUE) {\n\n duration1 = av_rescale_q(st->duration, st->time_base,\n\n AV_TIME_BASE_Q);\n\n duration = FFMAX(duration, duration1);\n\n }\n\n }\n\n if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE))\n\n start_time = start_time_text;\n\n else if (start_time > start_time_text)\n\n av_log(ic, AV_LOG_VERBOSE, \"Ignoring outlier non primary stream starttime %f\\n\", start_time_text / (float)AV_TIME_BASE);\n\n\n\n if (start_time != INT64_MAX) {\n\n ic->start_time = start_time;\n\n if (end_time != INT64_MIN) {\n\n if (ic->nb_programs) {\n\n for (i = 0; i < ic->nb_programs; i++) {\n\n p = ic->programs[i];\n\n if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time)\n\n duration = FFMAX(duration, p->end_time - p->start_time);\n\n }\n\n } else\n\n duration = FFMAX(duration, end_time - start_time);\n\n }\n\n }\n\n if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) {\n\n ic->duration = duration;\n\n }\n\n if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) {\n\n /* compute the bitrate */\n\n double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /\n\n (double) ic->duration;\n\n if (bitrate >= 0 && (!AV_HAVE_INCOMPATIBLE_LIBAV_ABI || bitrate <= INT_MAX))\n\n ic->bit_rate = bitrate;\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "655b6dcb34b25d591e15ede17673ea6cb8074711", + "length": 779 + }, + { + "index": 24236, + "code": "static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)\n\n{\n\n CURLState *state = NULL;\n\n int i, j;\n\n\n\n do {\n\n for (i=0; istates[i].acb[j])\n\n continue;\n\n if (s->states[i].in_use)\n\n continue;\n\n\n\n state = &s->states[i];\n\n state->in_use = 1;\n\n break;\n\n }\n\n if (!state) {\n\n qemu_mutex_unlock(&s->mutex);\n\n aio_poll(bdrv_get_aio_context(bs), true);\n\n qemu_mutex_lock(&s->mutex);\n\n }\n\n } while(!state);\n\n\n\n if (!state->curl) {\n\n state->curl = curl_easy_init();\n\n if (!state->curl) {\n\n return NULL;\n\n }\n\n curl_easy_setopt(state->curl, CURLOPT_URL, s->url);\n\n curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,\n\n (long) s->sslverify);\n\n if (s->cookie) {\n\n curl_easy_setopt(state->curl, CURLOPT_COOKIE, s->cookie);\n\n }\n\n curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, (long)s->timeout);\n\n curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,\n\n (void *)curl_read_cb);\n\n curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);\n\n curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);\n\n curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);\n\n curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);\n\n curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);\n\n curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);\n\n curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);\n\n\n\n if (s->username) {\n\n curl_easy_setopt(state->curl, CURLOPT_USERNAME, s->username);\n\n }\n\n if (s->password) {\n\n curl_easy_setopt(state->curl, CURLOPT_PASSWORD, s->password);\n\n }\n\n if (s->proxyusername) {\n\n curl_easy_setopt(state->curl,\n\n CURLOPT_PROXYUSERNAME, s->proxyusername);\n\n }\n\n if (s->proxypassword) {\n\n curl_easy_setopt(state->curl,\n\n CURLOPT_PROXYPASSWORD, s->proxypassword);\n\n }\n\n\n\n /* Restrict supported protocols to avoid security issues in the more\n\n * obscure protocols. For example, do not allow POP3/SMTP/IMAP see\n\n * CVE-2013-0249.\n\n *\n\n * Restricting protocols is only supported from 7.19.4 upwards.\n\n */\n\n#if LIBCURL_VERSION_NUM >= 0x071304\n\n curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);\n\n curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);\n\n#endif\n\n\n\n#ifdef DEBUG_VERBOSE\n\n curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);\n\n#endif\n\n }\n\n\n\n QLIST_INIT(&state->sockets);\n\n state->s = s;\n\n\n\n return state;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "3ce6a729b5d78b13283ddc6c529811f67519a62d", + "length": 686 + }, + { + "index": 4509, + "code": "static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,\n\n uint64_t image_size, VHDXImageType type,\n\n bool use_zero_blocks, uint64_t file_offset,\n\n uint32_t length)\n\n{\n\n int ret = 0;\n\n uint64_t data_file_offset;\n\n uint64_t total_sectors = 0;\n\n uint64_t sector_num = 0;\n\n uint64_t unused;\n\n int block_state;\n\n VHDXSectorInfo sinfo;\n\n\n\n assert(s->bat == NULL);\n\n\n\n /* this gives a data start after BAT/bitmap entries, and well\n\n * past any metadata entries (with a 4 MB buffer for future\n\n * expansion */\n\n data_file_offset = file_offset + length + 5 * MiB;\n\n total_sectors = image_size >> s->logical_sector_size_bits;\n\n\n\n if (type == VHDX_TYPE_DYNAMIC) {\n\n /* All zeroes, so we can just extend the file - the end of the BAT\n\n * is the furthest thing we have written yet */\n\n ret = bdrv_truncate(bs, data_file_offset);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n } else if (type == VHDX_TYPE_FIXED) {\n\n ret = bdrv_truncate(bs, data_file_offset + image_size);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n } else {\n\n ret = -ENOTSUP;\n\n goto exit;\n\n }\n\n\n\n if (type == VHDX_TYPE_FIXED ||\n\n use_zero_blocks ||\n\n bdrv_has_zero_init(bs) == 0) {\n\n /* for a fixed file, the default BAT entry is not zero */\n\n s->bat = g_try_malloc0(length);\n\n if (length && s->bat != NULL) {\n\n ret = -ENOMEM;\n\n goto exit;\n\n }\n\n block_state = type == VHDX_TYPE_FIXED ? PAYLOAD_BLOCK_FULLY_PRESENT :\n\n PAYLOAD_BLOCK_NOT_PRESENT;\n\n block_state = use_zero_blocks ? PAYLOAD_BLOCK_ZERO : block_state;\n\n /* fill the BAT by emulating sector writes of sectors_per_block size */\n\n while (sector_num < total_sectors) {\n\n vhdx_block_translate(s, sector_num, s->sectors_per_block, &sinfo);\n\n sinfo.file_offset = data_file_offset +\n\n (sector_num << s->logical_sector_size_bits);\n\n sinfo.file_offset = ROUND_UP(sinfo.file_offset, MiB);\n\n vhdx_update_bat_table_entry(bs, s, &sinfo, &unused, &unused,\n\n block_state);\n\n cpu_to_le64s(&s->bat[sinfo.bat_idx]);\n\n sector_num += s->sectors_per_block;\n\n }\n\n ret = bdrv_pwrite(bs, file_offset, s->bat, length);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n }\n\n\n\n\n\n\n\nexit:\n\n g_free(s->bat);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a011898d25b8a26a311d56dfe37e8d3a4374ec65", + "length": 628 + }, + { + "index": 6218, + "code": "int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps,\n\n int *is_nalff, int *nal_length_size,\n\n int err_recognition, void *logctx)\n\n{\n\n int ret = 0;\n\n GetByteContext gb;\n\n\n\n bytestream2_init(&gb, data, size);\n\n\n\n if (size > 3 && (data[0] || data[1] || data[2] > 1)) {\n\n /* It seems the extradata is encoded as hvcC format.\n\n * Temporarily, we support configurationVersion==0 until 14496-15 3rd\n\n * is finalized. When finalized, configurationVersion will be 1 and we\n\n * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */\n\n int i, j, num_arrays, nal_len_size;\n\n\n\n *is_nalff = 1;\n\n\n\n bytestream2_skip(&gb, 21);\n\n nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;\n\n num_arrays = bytestream2_get_byte(&gb);\n\n\n\n /* nal units in the hvcC always have length coded with 2 bytes,\n\n * so put a fake nal_length_size = 2 while parsing them */\n\n *nal_length_size = 2;\n\n\n\n /* Decode nal units from hvcC. */\n\n for (i = 0; i < num_arrays; i++) {\n\n int type = bytestream2_get_byte(&gb) & 0x3f;\n\n int cnt = bytestream2_get_be16(&gb);\n\n\n\n for (j = 0; j < cnt; j++) {\n\n // +2 for the nal size field\n\n int nalsize = bytestream2_peek_be16(&gb) + 2;\n\n if (bytestream2_get_bytes_left(&gb) < nalsize) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"Invalid NAL unit size in extradata.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n ret = hevc_decode_nal_units(gb.buffer, nalsize, ps, *is_nalff, *nal_length_size, logctx);\n\n if (ret < 0) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"Decoding nal unit %d %d from hvcC failed\\n\",\n\n type, i);\n\n return ret;\n\n }\n\n bytestream2_skip(&gb, nalsize);\n\n }\n\n }\n\n\n\n /* Now store right nal length size, that will be used to parse\n\n * all other nals */\n\n *nal_length_size = nal_len_size;\n\n } else {\n\n *is_nalff = 0;\n\n ret = hevc_decode_nal_units(data, size, ps, *is_nalff, *nal_length_size, logctx);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n\n\n return ret;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "159ab4625bd3641e79b564335be8069dca881978", + "length": 648 + }, + { + "index": 10823, + "code": "static int decode_hextile(VmncContext *c, uint8_t *dst, const uint8_t *src,\n\n int ssize, int w, int h, int stride)\n\n{\n\n int i, j, k;\n\n int bg = 0, fg = 0, rects, color, flags, xy, wh;\n\n const int bpp = c->bpp2;\n\n uint8_t *dst2;\n\n int bw = 16, bh = 16;\n\n const uint8_t *ssrc = src;\n\n\n\n for (j = 0; j < h; j += 16) {\n\n dst2 = dst;\n\n bw = 16;\n\n if (j + 16 > h)\n\n bh = h - j;\n\n for (i = 0; i < w; i += 16, dst2 += 16 * bpp) {\n\n if (src - ssrc >= ssize) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return -1;\n\n }\n\n if (i + 16 > w)\n\n bw = w - i;\n\n flags = *src++;\n\n if (flags & HT_RAW) {\n\n if (src - ssrc > ssize - bw * bh * bpp) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return -1;\n\n }\n\n paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);\n\n src += bw * bh * bpp;\n\n } else {\n\n if (flags & HT_BKG) {\n\n bg = vmnc_get_pixel(src, bpp, c->bigendian);\n\n src += bpp;\n\n }\n\n if (flags & HT_FG) {\n\n fg = vmnc_get_pixel(src, bpp, c->bigendian);\n\n src += bpp;\n\n }\n\n rects = 0;\n\n if (flags & HT_SUB)\n\n rects = *src++;\n\n color = !!(flags & HT_CLR);\n\n\n\n paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);\n\n\n\n if (src - ssrc > ssize - rects * (color * bpp + 2)) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return -1;\n\n }\n\n for (k = 0; k < rects; k++) {\n\n if (color) {\n\n fg = vmnc_get_pixel(src, bpp, c->bigendian);\n\n src += bpp;\n\n }\n\n xy = *src++;\n\n wh = *src++;\n\n paint_rect(dst2, xy >> 4, xy & 0xF, (wh >> 4) + 1,\n\n (wh & 0xF) + 1, fg, bpp, stride);\n\n }\n\n }\n\n }\n\n dst += stride * 16;\n\n }\n\n return src - ssrc;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "61cd19b8bc32185c8caf64d89d1b0909877a0707", + "length": 632 + }, + { + "index": 18493, + "code": "static float64 roundAndPackFloat64( flag zSign, int16 zExp, uint64_t zSig STATUS_PARAM)\n\n{\n\n int8 roundingMode;\n\n flag roundNearestEven;\n\n int16 roundIncrement, roundBits;\n\n flag isTiny;\n\n\n\n roundingMode = STATUS(float_rounding_mode);\n\n roundNearestEven = ( roundingMode == float_round_nearest_even );\n\n roundIncrement = 0x200;\n\n if ( ! roundNearestEven ) {\n\n if ( roundingMode == float_round_to_zero ) {\n\n roundIncrement = 0;\n\n }\n\n else {\n\n roundIncrement = 0x3FF;\n\n if ( zSign ) {\n\n if ( roundingMode == float_round_up ) roundIncrement = 0;\n\n }\n\n else {\n\n if ( roundingMode == float_round_down ) roundIncrement = 0;\n\n }\n\n }\n\n }\n\n roundBits = zSig & 0x3FF;\n\n if ( 0x7FD <= (uint16_t) zExp ) {\n\n if ( ( 0x7FD < zExp )\n\n || ( ( zExp == 0x7FD )\n\n && ( (int64_t) ( zSig + roundIncrement ) < 0 ) )\n\n ) {\n\n float_raise( float_flag_overflow | float_flag_inexact STATUS_VAR);\n\n return packFloat64( zSign, 0x7FF, - ( roundIncrement == 0 ));\n\n }\n\n if ( zExp < 0 ) {\n\n if ( STATUS(flush_to_zero) ) return packFloat64( zSign, 0, 0 );\n\n isTiny =\n\n ( STATUS(float_detect_tininess) == float_tininess_before_rounding )\n\n || ( zExp < -1 )\n\n || ( zSig + roundIncrement < LIT64( 0x8000000000000000 ) );\n\n shift64RightJamming( zSig, - zExp, &zSig );\n\n zExp = 0;\n\n roundBits = zSig & 0x3FF;\n\n if ( isTiny && roundBits ) float_raise( float_flag_underflow STATUS_VAR);\n\n }\n\n }\n\n if ( roundBits ) STATUS(float_exception_flags) |= float_flag_inexact;\n\n zSig = ( zSig + roundIncrement )>>10;\n\n zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );\n\n if ( zSig == 0 ) zExp = 0;\n\n return packFloat64( zSign, zExp, zSig );\n\n\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "e6afc87f804abee7d0479be5e8e31c56d885fafb", + "length": 545 + }, + { + "index": 17563, + "code": "static int compat_decode(AVCodecContext *avctx, AVFrame *frame,\n\n int *got_frame, const AVPacket *pkt)\n\n{\n\n AVCodecInternal *avci = avctx->internal;\n\n int ret;\n\n\n\n av_assert0(avci->compat_decode_consumed == 0);\n\n\n\n *got_frame = 0;\n\n avci->compat_decode = 1;\n\n\n\n if (avci->compat_decode_partial_size > 0 &&\n\n avci->compat_decode_partial_size != pkt->size) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Got unexpected packet size after a partial decode\\n\");\n\n ret = AVERROR(EINVAL);\n\n goto finish;\n\n }\n\n\n\n if (!avci->compat_decode_partial_size) {\n\n ret = avcodec_send_packet(avctx, pkt);\n\n if (ret == AVERROR_EOF)\n\n ret = 0;\n\n else if (ret == AVERROR(EAGAIN)) {\n\n /* we fully drain all the output in each decode call, so this should not\n\n * ever happen */\n\n ret = AVERROR_BUG;\n\n goto finish;\n\n } else if (ret < 0)\n\n goto finish;\n\n }\n\n\n\n while (ret >= 0) {\n\n ret = avcodec_receive_frame(avctx, frame);\n\n if (ret < 0) {\n\n if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)\n\n ret = 0;\n\n goto finish;\n\n }\n\n\n\n if (frame != avci->compat_decode_frame) {\n\n if (!avctx->refcounted_frames) {\n\n ret = unrefcount_frame(avci, frame);\n\n if (ret < 0)\n\n goto finish;\n\n }\n\n\n\n *got_frame = 1;\n\n frame = avci->compat_decode_frame;\n\n } else {\n\n if (!avci->compat_decode_warned) {\n\n av_log(avctx, AV_LOG_WARNING, \"The deprecated avcodec_decode_* \"\n\n \"API cannot return all the frames for this decoder. \"\n\n \"Some frames will be dropped. Update your code to the \"\n\n \"new decoding API to fix this.\\n\");\n\n avci->compat_decode_warned = 1;\n\n }\n\n }\n\n\n\n if (avci->draining || (!avctx->codec->bsfs && avci->compat_decode_consumed < pkt->size))\n\n break;\n\n }\n\n\n\nfinish:\n\n if (ret == 0) {\n\n /* if there are any bsfs then assume full packet is always consumed */\n\n if (avctx->codec->bsfs)\n\n ret = pkt->size;\n\n else\n\n ret = FFMIN(avci->compat_decode_consumed, pkt->size);\n\n }\n\n avci->compat_decode_consumed = 0;\n\n avci->compat_decode_partial_size = (ret >= 0) ? pkt->size - ret : 0;\n\n\n\n return ret;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "960b4d47612ec89cfdf0ff8b83bc7424ad4c754a", + "length": 608 + }, + { + "index": 4036, + "code": "static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, unsigned int src_size)\n\n{\n\n\tconst uint8_t *s = src;\n\n\tconst uint8_t *end;\n\n#ifdef HAVE_MMX\n\n\tconst uint8_t *mm_end;\n\n#endif\n\n\tuint16_t *d = (uint16_t *)dst;\n\n\tend = s + src_size;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(PREFETCH\"\t%0\"::\"m\"(*src):\"memory\");\n\n\t__asm __volatile(\n\n\t \"movq\t%0, %%mm7\\n\\t\"\n\n\t \"movq\t%1, %%mm6\\n\\t\"\n\n\t ::\"m\"(red_16mask),\"m\"(green_16mask));\n\n\tmm_end = end - 15;\n\n\twhile(s < mm_end)\n\n\t{\n\n\t __asm __volatile(\n\n\t\tPREFETCH\" 32%1\\n\\t\"\n\n\t\t\"movd\t%1, %%mm0\\n\\t\"\n\n\t\t\"movd\t4%1, %%mm3\\n\\t\"\n\n\t\t\"punpckldq 8%1, %%mm0\\n\\t\"\n\n\t\t\"punpckldq 12%1, %%mm3\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm1\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm2\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm4\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm5\\n\\t\"\n\n\t\t\"psllq\t$8, %%mm0\\n\\t\"\n\n\t\t\"psllq\t$8, %%mm3\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm0\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm3\\n\\t\"\n\n\t\t\"psrlq\t$5, %%mm1\\n\\t\"\n\n\t\t\"psrlq\t$5, %%mm4\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm1\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm4\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm2\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm5\\n\\t\"\n\n\t\t\"pand\t%2, %%mm2\\n\\t\"\n\n\t\t\"pand\t%2, %%mm5\\n\\t\"\n\n\t\t\"por\t%%mm1, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm4, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm2, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm5, %%mm3\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm3, %%mm0\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\t\t:\"=m\"(*d):\"m\"(*s),\"m\"(blue_16mask):\"memory\");\n\n\t\td += 4;\n\n\t\ts += 16;\n\n\t}\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n\twhile(s < end)\n\n\t{\n\n\t\t// FIXME on bigendian\n\n\t\tconst int src= *s; s += 4;\n\n\t\t*d++ = ((src&0xF8)<<8) + ((src&0xFC00)>>5) + ((src&0xF80000)>>19);\n\n\t}\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "7f526efd17973ec6d2204f7a47b6923e2be31363", + "length": 759 + }, + { + "index": 16652, + "code": "static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)\n\n{\n\n AVFilterContext *ctx = inlink->dst;\n\n ASyncContext *s = ctx->priv;\n\n AVFilterLink *outlink = ctx->outputs[0];\n\n int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);\n\n int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :\n\n av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);\n\n int out_size, ret;\n\n int64_t delta;\n\n\n\n /* buffer data until we get the first timestamp */\n\n if (s->pts == AV_NOPTS_VALUE) {\n\n if (pts != AV_NOPTS_VALUE) {\n\n s->pts = pts - get_delay(s);\n\n }\n\n return write_to_fifo(s, buf);\n\n }\n\n\n\n /* now wait for the next timestamp */\n\n if (pts == AV_NOPTS_VALUE) {\n\n return write_to_fifo(s, buf);\n\n }\n\n\n\n /* when we have two timestamps, compute how many samples would we have\n\n * to add/remove to get proper sync between data and timestamps */\n\n delta = pts - s->pts - get_delay(s);\n\n out_size = avresample_available(s->avr);\n\n\n\n if (labs(delta) > s->min_delta) {\n\n av_log(ctx, AV_LOG_VERBOSE, \"Discontinuity - %\"PRId64\" samples.\\n\", delta);\n\n out_size = av_clipl_int32((int64_t)out_size + delta);\n\n } else {\n\n if (s->resample) {\n\n int comp = av_clip(delta, -s->max_comp, s->max_comp);\n\n av_log(ctx, AV_LOG_VERBOSE, \"Compensating %d samples per second.\\n\", comp);\n\n avresample_set_compensation(s->avr, delta, inlink->sample_rate);\n\n }\n\n delta = 0;\n\n }\n\n\n\n if (out_size > 0) {\n\n AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,\n\n out_size);\n\n if (!buf_out) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n avresample_read(s->avr, buf_out->extended_data, out_size);\n\n buf_out->pts = s->pts;\n\n\n\n if (delta > 0) {\n\n av_samples_set_silence(buf_out->extended_data, out_size - delta,\n\n delta, nb_channels, buf->format);\n\n }\n\n ret = ff_filter_frame(outlink, buf_out);\n\n if (ret < 0)\n\n goto fail;\n\n s->got_output = 1;\n\n } else {\n\n av_log(ctx, AV_LOG_WARNING, \"Non-monotonous timestamps, dropping \"\n\n \"whole buffer.\\n\");\n\n }\n\n\n\n /* drain any remaining buffered data */\n\n avresample_read(s->avr, NULL, avresample_available(s->avr));\n\n\n\n s->pts = pts - avresample_get_delay(s->avr);\n\n ret = avresample_convert(s->avr, NULL, 0, 0, buf->extended_data,\n\n buf->linesize[0], buf->audio->nb_samples);\n\n\n\nfail:\n\n avfilter_unref_buffer(buf);\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "8083332c2de9ee189f96844ff4c2d9be1844116f", + "length": 704 + }, + { + "index": 7105, + "code": "int sd_do_command(SDState *sd, SDRequest *req,\n\n uint8_t *response) {\n\n uint32_t last_status = sd->card_status;\n\n sd_rsp_type_t rtype;\n\n int rsplen;\n\n\n\n if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) {\n\n return 0;\n\n }\n\n\n\n if (sd_req_crc_validate(req)) {\n\n sd->card_status |= COM_CRC_ERROR;\n\n rtype = sd_illegal;\n\n goto send_response;\n\n }\n\n\n\n sd->card_status &= ~CARD_STATUS_B;\n\n sd_set_status(sd);\n\n\n\n if (last_status & CARD_IS_LOCKED) {\n\n if (!cmd_valid_while_locked(sd, req)) {\n\n sd->card_status |= ILLEGAL_COMMAND;\n\n fprintf(stderr, \"SD: Card is locked\\n\");\n\n rtype = sd_illegal;\n\n goto send_response;\n\n }\n\n }\n\n\n\n if (last_status & APP_CMD) {\n\n rtype = sd_app_command(sd, *req);\n\n sd->card_status &= ~APP_CMD;\n\n } else\n\n rtype = sd_normal_command(sd, *req);\n\n\n\n if (rtype == sd_illegal) {\n\n sd->card_status |= ILLEGAL_COMMAND;\n\n }\n\n\n\n sd->current_cmd = req->cmd;\n\n\n\nsend_response:\n\n switch (rtype) {\n\n case sd_r1:\n\n case sd_r1b:\n\n sd_response_r1_make(sd, response, last_status);\n\n rsplen = 4;\n\n break;\n\n\n\n case sd_r2_i:\n\n memcpy(response, sd->cid, sizeof(sd->cid));\n\n rsplen = 16;\n\n break;\n\n\n\n case sd_r2_s:\n\n memcpy(response, sd->csd, sizeof(sd->csd));\n\n rsplen = 16;\n\n break;\n\n\n\n case sd_r3:\n\n sd_response_r3_make(sd, response);\n\n rsplen = 4;\n\n break;\n\n\n\n case sd_r6:\n\n sd_response_r6_make(sd, response);\n\n rsplen = 4;\n\n break;\n\n\n\n case sd_r7:\n\n sd_response_r7_make(sd, response);\n\n rsplen = 4;\n\n break;\n\n\n\n case sd_r0:\n\n case sd_illegal:\n\n default:\n\n rsplen = 0;\n\n break;\n\n }\n\n\n\n#ifdef DEBUG_SD\n\n if (rsplen) {\n\n int i;\n\n DPRINTF(\"Response:\");\n\n for (i = 0; i < rsplen; i++)\n\n printf(\" %02x\", response[i]);\n\n printf(\" state %d\\n\", sd->state);\n\n } else {\n\n DPRINTF(\"No response %d\\n\", sd->state);\n\n }\n\n#endif\n\n\n\n return rsplen;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "10a412dab3f54439ea3d60274eb41668f7d83bd2", + "length": 576 + }, + { + "index": 8268, + "code": "static void gem_write(void *opaque, hwaddr offset, uint64_t val,\n\n unsigned size)\n\n{\n\n GemState *s = (GemState *)opaque;\n\n uint32_t readonly;\n\n\n\n DB_PRINT(\"offset: 0x%04x write: 0x%08x \", (unsigned)offset, (unsigned)val);\n\n offset >>= 2;\n\n\n\n /* Squash bits which are read only in write value */\n\n val &= ~(s->regs_ro[offset]);\n\n /* Preserve (only) bits which are read only and wtc in register */\n\n readonly = s->regs[offset] & (s->regs_ro[offset] | s->regs_w1c[offset]);\n\n\n\n /* Copy register write to backing store */\n\n s->regs[offset] = (val & ~s->regs_w1c[offset]) | readonly;\n\n\n\n /* do w1c */\n\n s->regs[offset] &= ~(s->regs_w1c[offset] & val);\n\n\n\n /* Handle register write side effects */\n\n switch (offset) {\n\n case GEM_NWCTRL:\n\n if (val & GEM_NWCTRL_RXENA) {\n\n gem_get_rx_desc(s);\n\n }\n\n if (val & GEM_NWCTRL_TXSTART) {\n\n gem_transmit(s);\n\n }\n\n if (!(val & GEM_NWCTRL_TXENA)) {\n\n /* Reset to start of Q when transmit disabled. */\n\n s->tx_desc_addr = s->regs[GEM_TXQBASE];\n\n }\n\n if (val & GEM_NWCTRL_RXENA) {\n\n qemu_flush_queued_packets(qemu_get_queue(s->nic));\n\n }\n\n break;\n\n\n\n case GEM_TXSTATUS:\n\n gem_update_int_status(s);\n\n break;\n\n case GEM_RXQBASE:\n\n s->rx_desc_addr = val;\n\n break;\n\n case GEM_TXQBASE:\n\n s->tx_desc_addr = val;\n\n break;\n\n case GEM_RXSTATUS:\n\n gem_update_int_status(s);\n\n break;\n\n case GEM_IER:\n\n s->regs[GEM_IMR] &= ~val;\n\n gem_update_int_status(s);\n\n break;\n\n case GEM_IDR:\n\n s->regs[GEM_IMR] |= val;\n\n gem_update_int_status(s);\n\n break;\n\n case GEM_SPADDR1LO:\n\n case GEM_SPADDR2LO:\n\n case GEM_SPADDR3LO:\n\n case GEM_SPADDR4LO:\n\n s->sar_active[(offset - GEM_SPADDR1LO) / 2] = false;\n\n break;\n\n case GEM_SPADDR1HI:\n\n case GEM_SPADDR2HI:\n\n case GEM_SPADDR3HI:\n\n case GEM_SPADDR4HI:\n\n s->sar_active[(offset - GEM_SPADDR1HI) / 2] = true;\n\n break;\n\n case GEM_PHYMNTNC:\n\n if (val & GEM_PHYMNTNC_OP_W) {\n\n uint32_t phy_addr, reg_num;\n\n\n\n phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;\n\n if (phy_addr == BOARD_PHY_ADDRESS) {\n\n reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;\n\n gem_phy_write(s, reg_num, val);\n\n }\n\n }\n\n break;\n\n }\n\n\n\n DB_PRINT(\"newval: 0x%08x\\n\", s->regs[offset]);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "8202aa539135a44906c38f82a469234ec65e0ef7", + "length": 737 + }, + { + "index": 17692, + "code": "static ssize_t nbd_co_receive_request(NBDRequestData *req,\n\n NBDRequest *request)\n\n{\n\n NBDClient *client = req->client;\n\n ssize_t rc;\n\n\n\n g_assert(qemu_in_coroutine());\n\n assert(client->recv_coroutine == qemu_coroutine_self());\n\n rc = nbd_receive_request(client->ioc, request);\n\n if (rc < 0) {\n\n if (rc != -EAGAIN) {\n\n rc = -EIO;\n\n }\n\n goto out;\n\n }\n\n\n\n TRACE(\"Decoding type\");\n\n\n\n if (request->type != NBD_CMD_WRITE) {\n\n /* No payload, we are ready to read the next request. */\n\n req->complete = true;\n\n }\n\n\n\n if (request->type == NBD_CMD_DISC) {\n\n /* Special case: we're going to disconnect without a reply,\n\n * whether or not flags, from, or len are bogus */\n\n TRACE(\"Request type is DISCONNECT\");\n\n rc = -EIO;\n\n goto out;\n\n }\n\n\n\n /* Check for sanity in the parameters, part 1. Defer as many\n\n * checks as possible until after reading any NBD_CMD_WRITE\n\n * payload, so we can try and keep the connection alive. */\n\n if ((request->from + request->len) < request->from) {\n\n LOG(\"integer overflow detected, you're probably being attacked\");\n\n rc = -EINVAL;\n\n goto out;\n\n }\n\n\n\n if (request->type == NBD_CMD_READ || request->type == NBD_CMD_WRITE) {\n\n if (request->len > NBD_MAX_BUFFER_SIZE) {\n\n LOG(\"len (%\" PRIu32\" ) is larger than max len (%u)\",\n\n request->len, NBD_MAX_BUFFER_SIZE);\n\n rc = -EINVAL;\n\n goto out;\n\n }\n\n\n\n req->data = blk_try_blockalign(client->exp->blk, request->len);\n\n if (req->data == NULL) {\n\n rc = -ENOMEM;\n\n goto out;\n\n }\n\n }\n\n if (request->type == NBD_CMD_WRITE) {\n\n TRACE(\"Reading %\" PRIu32 \" byte(s)\", request->len);\n\n\n\n if (read_sync(client->ioc, req->data, request->len, NULL) < 0) {\n\n LOG(\"reading from socket failed\");\n\n rc = -EIO;\n\n goto out;\n\n }\n\n req->complete = true;\n\n }\n\n\n\n /* Sanity checks, part 2. */\n\n if (request->from + request->len > client->exp->size) {\n\n LOG(\"operation past EOF; From: %\" PRIu64 \", Len: %\" PRIu32\n\n \", Size: %\" PRIu64, request->from, request->len,\n\n (uint64_t)client->exp->size);\n\n rc = request->type == NBD_CMD_WRITE ? -ENOSPC : -EINVAL;\n\n goto out;\n\n }\n\n if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) {\n\n LOG(\"unsupported flags (got 0x%x)\", request->flags);\n\n rc = -EINVAL;\n\n goto out;\n\n }\n\n if (request->type != NBD_CMD_WRITE_ZEROES &&\n\n (request->flags & NBD_CMD_FLAG_NO_HOLE)) {\n\n LOG(\"unexpected flags (got 0x%x)\", request->flags);\n\n rc = -EINVAL;\n\n goto out;\n\n }\n\n\n\n rc = 0;\n\n\n\nout:\n\n client->recv_coroutine = NULL;\n\n nbd_client_receive_next_request(client);\n\n\n\n return rc;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d1fdf257d52822695f5ace6c586e059aa17d4b79", + "length": 760 + }, + { + "index": 22110, + "code": "static int oss_open (int in, struct oss_params *req,\n\n struct oss_params *obt, int *pfd)\n\n{\n\n int fd;\n\n int oflags;\n\n int mmmmssss;\n\n audio_buf_info abinfo;\n\n int fmt, freq, nchannels;\n\n const char *dspname = in ? conf.devpath_in : conf.devpath_out;\n\n const char *typ = in ? \"ADC\" : \"DAC\";\n\n\n\n /* Kludge needed to have working mmap on Linux */\n\n oflags = conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);\n\n fd = open (dspname, oflags | O_NONBLOCK);\n\n if (-1 == fd) {\n\n oss_logerr2 (errno, typ, \"Failed to open `%s'\\n\", dspname);\n\n return -1;\n\n }\n\n\n\n freq = req->freq;\n\n nchannels = req->nchannels;\n\n fmt = req->fmt;\n\n\n\n if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {\n\n oss_logerr2 (errno, typ, \"Failed to set sample size %d\\n\", req->fmt);\n\n goto err;\n\n }\n\n\n\n if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {\n\n oss_logerr2 (errno, typ, \"Failed to set number of channels %d\\n\",\n\n req->nchannels);\n\n goto err;\n\n }\n\n\n\n if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {\n\n oss_logerr2 (errno, typ, \"Failed to set frequency %d\\n\", req->freq);\n\n goto err;\n\n }\n\n\n\n if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {\n\n oss_logerr2 (errno, typ, \"Failed to set non-blocking mode\\n\");\n\n goto err;\n\n }\n\n\n\n mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);\n\n if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {\n\n oss_logerr2 (errno, typ, \"Failed to set buffer length (%d, %d)\\n\",\n\n req->nfrags, req->fragsize);\n\n goto err;\n\n }\n\n\n\n if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {\n\n oss_logerr2 (errno, typ, \"Failed to get buffer length\\n\");\n\n goto err;\n\n }\n\n\n\n if (!abinfo.fragstotal || !abinfo.fragsize) {\n\n AUD_log (AUDIO_CAP, \"Returned bogus buffer information(%d, %d) for %s\\n\",\n\n abinfo.fragstotal, abinfo.fragsize, typ);\n\n goto err;\n\n }\n\n\n\n obt->fmt = fmt;\n\n obt->nchannels = nchannels;\n\n obt->freq = freq;\n\n obt->nfrags = abinfo.fragstotal;\n\n obt->fragsize = abinfo.fragsize;\n\n *pfd = fd;\n\n\n\n#ifdef DEBUG_MISMATCHES\n\n if ((req->fmt != obt->fmt) ||\n\n (req->nchannels != obt->nchannels) ||\n\n (req->freq != obt->freq) ||\n\n (req->fragsize != obt->fragsize) ||\n\n (req->nfrags != obt->nfrags)) {\n\n dolog (\"Audio parameters mismatch\\n\");\n\n oss_dump_info (req, obt);\n\n }\n\n#endif\n\n\n\n#ifdef DEBUG\n\n oss_dump_info (req, obt);\n\n#endif\n\n return 0;\n\n\n\n err:\n\n oss_anal_close (&fd);\n\n return -1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "0b3652bc70891940f2c7142d39576d17c4d07196", + "length": 783 + }, + { + "index": 20491, + "code": "static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,\n\n BdrvCheckMode fix, uint16_t **refcount_table,\n\n int64_t *nb_clusters)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int64_t i;\n\n\n\n for(i = 0; i < s->refcount_table_size; i++) {\n\n uint64_t offset, cluster;\n\n offset = s->refcount_table[i];\n\n cluster = offset >> s->cluster_bits;\n\n\n\n /* Refcount blocks are cluster aligned */\n\n if (offset_into_cluster(s, offset)) {\n\n fprintf(stderr, \"ERROR refcount block %\" PRId64 \" is not \"\n\n \"cluster aligned; refcount table entry corrupted\\n\", i);\n\n res->corruptions++;\n\n continue;\n\n }\n\n\n\n if (cluster >= *nb_clusters) {\n\n fprintf(stderr, \"ERROR refcount block %\" PRId64\n\n \" is outside image\\n\", i);\n\n res->corruptions++;\n\n continue;\n\n }\n\n\n\n if (offset != 0) {\n\n inc_refcounts(bs, res, *refcount_table, *nb_clusters,\n\n offset, s->cluster_size);\n\n if ((*refcount_table)[cluster] != 1) {\n\n fprintf(stderr, \"%s refcount block %\" PRId64\n\n \" refcount=%d\\n\",\n\n fix & BDRV_FIX_ERRORS ? \"Repairing\" :\n\n \"ERROR\",\n\n i, (*refcount_table)[cluster]);\n\n\n\n if (fix & BDRV_FIX_ERRORS) {\n\n int64_t new_offset;\n\n\n\n new_offset = realloc_refcount_block(bs, i, offset);\n\n if (new_offset < 0) {\n\n res->corruptions++;\n\n continue;\n\n }\n\n\n\n /* update refcounts */\n\n if ((new_offset >> s->cluster_bits) >= *nb_clusters) {\n\n /* increase refcount_table size if necessary */\n\n int old_nb_clusters = *nb_clusters;\n\n *nb_clusters = (new_offset >> s->cluster_bits) + 1;\n\n *refcount_table = g_renew(uint16_t, *refcount_table,\n\n *nb_clusters);\n\n memset(&(*refcount_table)[old_nb_clusters], 0,\n\n (*nb_clusters - old_nb_clusters) *\n\n sizeof(uint16_t));\n\n }\n\n (*refcount_table)[cluster]--;\n\n inc_refcounts(bs, res, *refcount_table, *nb_clusters,\n\n new_offset, s->cluster_size);\n\n\n\n res->corruptions_fixed++;\n\n } else {\n\n res->corruptions++;\n\n }\n\n }\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "78fb328e854542d79bebe54f3a426cba6d46dbf1", + "length": 549 + }, + { + "index": 15855, + "code": "static void ehci_advance_state(EHCIState *ehci,\n\n int async)\n\n{\n\n EHCIQueue *q = NULL;\n\n int again;\n\n int iter = 0;\n\n\n\n do {\n\n if (ehci_get_state(ehci, async) == EST_FETCHQH) {\n\n iter++;\n\n /* if we are roaming a lot of QH without executing a qTD\n\n * something is wrong with the linked list. TO-DO: why is\n\n * this hack needed?\n\n */\n\n assert(iter < MAX_ITERATIONS);\n\n#if 0\n\n if (iter > MAX_ITERATIONS) {\n\n DPRINTF(\"\\n*** advance_state: bailing on MAX ITERATIONS***\\n\");\n\n ehci_set_state(ehci, async, EST_ACTIVE);\n\n break;\n\n }\n\n#endif\n\n }\n\n switch(ehci_get_state(ehci, async)) {\n\n case EST_WAITLISTHEAD:\n\n again = ehci_state_waitlisthead(ehci, async);\n\n break;\n\n\n\n case EST_FETCHENTRY:\n\n again = ehci_state_fetchentry(ehci, async);\n\n break;\n\n\n\n case EST_FETCHQH:\n\n q = ehci_state_fetchqh(ehci, async);\n\n again = q ? 1 : 0;\n\n break;\n\n\n\n case EST_FETCHITD:\n\n again = ehci_state_fetchitd(ehci, async);\n\n break;\n\n\n\n case EST_FETCHSITD:\n\n again = ehci_state_fetchsitd(ehci, async);\n\n break;\n\n\n\n case EST_ADVANCEQUEUE:\n\n again = ehci_state_advqueue(q, async);\n\n break;\n\n\n\n case EST_FETCHQTD:\n\n again = ehci_state_fetchqtd(q, async);\n\n break;\n\n\n\n case EST_HORIZONTALQH:\n\n again = ehci_state_horizqh(q, async);\n\n break;\n\n\n\n case EST_EXECUTE:\n\n iter = 0;\n\n again = ehci_state_execute(q, async);\n\n break;\n\n\n\n case EST_EXECUTING:\n\n assert(q != NULL);\n\n again = ehci_state_executing(q, async);\n\n break;\n\n\n\n case EST_WRITEBACK:\n\n assert(q != NULL);\n\n again = ehci_state_writeback(q, async);\n\n break;\n\n\n\n default:\n\n fprintf(stderr, \"Bad state!\\n\");\n\n again = -1;\n\n assert(0);\n\n break;\n\n }\n\n\n\n if (again < 0) {\n\n fprintf(stderr, \"processing error - resetting ehci HC\\n\");\n\n ehci_reset(ehci);\n\n again = 0;\n\n assert(0);\n\n }\n\n }\n\n while (again);\n\n\n\n ehci_commit_interrupt(ehci);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "c7020c974073ba9c0110d45361720a29ff6b2f59", + "length": 546 + }, + { + "index": 2107, + "code": "static void filter_mb_edgeh( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp ) {\n\n int i, d;\n\n const int index_a = clip( qp + h->slice_alpha_c0_offset, 0, 51 );\n\n const int alpha = alpha_table[index_a];\n\n const int beta = beta_table[clip( qp + h->slice_beta_offset, 0, 51 )];\n\n const int pix_next = stride;\n\n\n\n for( i = 0; i < 4; i++ ) {\n\n if( bS[i] == 0 ) {\n\n pix += 4;\n\n continue;\n\n }\n\n\n\n /* 4px edge length */\n\n for( d = 0; d < 4; d++ ) {\n\n const uint8_t p0 = pix[-1*pix_next];\n\n const uint8_t p1 = pix[-2*pix_next];\n\n const uint8_t p2 = pix[-3*pix_next];\n\n const uint8_t q0 = pix[0];\n\n const uint8_t q1 = pix[1*pix_next];\n\n const uint8_t q2 = pix[2*pix_next];\n\n\n\n if( abs( p0 - q0 ) >= alpha ||\n\n abs( p1 - p0 ) >= beta ||\n\n abs( q1 - q0 ) >= beta ) {\n\n pix++;\n\n continue;\n\n }\n\n\n\n if( bS[i] < 4 ) {\n\n const int tc0 = tc0_table[index_a][bS[i] - 1];\n\n int tc = tc0;\n\n int i_delta;\n\n\n\n if( abs( p2 - p0 ) < beta ) {\n\n pix[-2*pix_next] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );\n\n tc++;\n\n }\n\n if( abs( q2 - q0 ) < beta ) {\n\n pix[pix_next] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );\n\n tc++;\n\n }\n\n\n\n i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );\n\n pix[-pix_next] = clip( p0 + i_delta, 0, 255 ); /* p0' */\n\n pix[0] = clip( q0 - i_delta, 0, 255 ); /* q0' */\n\n }\n\n else\n\n {\n\n const uint8_t p3 = pix[-4*pix_next];\n\n const uint8_t q3 = pix[ 3*pix_next];\n\n const int c = abs( p0 - q0 ) < (( alpha >> 2 ) + 2 );\n\n\n\n if( abs( p2 - p0 ) < beta && c ) {\n\n /* p0', p1', p2' */\n\n pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;\n\n pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;\n\n pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;\n\n } else {\n\n /* p0' */\n\n pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;\n\n }\n\n if( abs( q2 - q0 ) < beta && c ) {\n\n /* q0', q1', q2' */\n\n pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;\n\n pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;\n\n pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;\n\n } else {\n\n /* q0' */\n\n pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;\n\n }\n\n }\n\n pix++;\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3ebc7e04dea6072400d91c1c90eb3911754cee06", + "length": 1008 + }, + { + "index": 10591, + "code": "void vga_reset(void *opaque)\n\n{\n\n VGAState *s = (VGAState *) opaque;\n\n\n\n s->lfb_addr = 0;\n\n s->lfb_end = 0;\n\n s->map_addr = 0;\n\n s->map_end = 0;\n\n s->lfb_vram_mapped = 0;\n\n s->bios_offset = 0;\n\n s->bios_size = 0;\n\n s->sr_index = 0;\n\n memset(s->sr, '\\0', sizeof(s->sr));\n\n s->gr_index = 0;\n\n memset(s->gr, '\\0', sizeof(s->gr));\n\n s->ar_index = 0;\n\n memset(s->ar, '\\0', sizeof(s->ar));\n\n s->ar_flip_flop = 0;\n\n s->cr_index = 0;\n\n memset(s->cr, '\\0', sizeof(s->cr));\n\n s->msr = 0;\n\n s->fcr = 0;\n\n s->st00 = 0;\n\n s->st01 = 0;\n\n s->dac_state = 0;\n\n s->dac_sub_index = 0;\n\n s->dac_read_index = 0;\n\n s->dac_write_index = 0;\n\n memset(s->dac_cache, '\\0', sizeof(s->dac_cache));\n\n s->dac_8bit = 0;\n\n memset(s->palette, '\\0', sizeof(s->palette));\n\n s->bank_offset = 0;\n\n#ifdef CONFIG_BOCHS_VBE\n\n s->vbe_index = 0;\n\n memset(s->vbe_regs, '\\0', sizeof(s->vbe_regs));\n\n s->vbe_regs[VBE_DISPI_INDEX_ID] = VBE_DISPI_ID0;\n\n s->vbe_start_addr = 0;\n\n s->vbe_line_offset = 0;\n\n s->vbe_bank_mask = (s->vram_size >> 16) - 1;\n\n#endif\n\n memset(s->font_offsets, '\\0', sizeof(s->font_offsets));\n\n s->graphic_mode = -1; /* force full update */\n\n s->shift_control = 0;\n\n s->double_scan = 0;\n\n s->line_offset = 0;\n\n s->line_compare = 0;\n\n s->start_addr = 0;\n\n s->plane_updated = 0;\n\n s->last_cw = 0;\n\n s->last_ch = 0;\n\n s->last_width = 0;\n\n s->last_height = 0;\n\n s->last_scr_width = 0;\n\n s->last_scr_height = 0;\n\n s->cursor_start = 0;\n\n s->cursor_end = 0;\n\n s->cursor_offset = 0;\n\n memset(s->invalidated_y_table, '\\0', sizeof(s->invalidated_y_table));\n\n memset(s->last_palette, '\\0', sizeof(s->last_palette));\n\n memset(s->last_ch_attr, '\\0', sizeof(s->last_ch_attr));\n\n switch (vga_retrace_method) {\n\n case VGA_RETRACE_DUMB:\n\n break;\n\n case VGA_RETRACE_PRECISE:\n\n memset(&s->retrace_info, 0, sizeof (s->retrace_info));\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "9586fefefe383a9aa25ad99bde9a6b240309ca33", + "length": 700 + }, + { + "index": 13856, + "code": "static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame,\n\n NvencSurface *nvenc_frame)\n\n{\n\n NvencContext *ctx = avctx->priv_data;\n\n NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;\n\n NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;\n\n\n\n int res;\n\n NVENCSTATUS nv_status;\n\n\n\n if (avctx->pix_fmt == AV_PIX_FMT_CUDA || avctx->pix_fmt == AV_PIX_FMT_D3D11) {\n\n int reg_idx = nvenc_register_frame(avctx, frame);\n\n if (reg_idx < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Could not register an input HW frame\\n\");\n\n return reg_idx;\n\n }\n\n\n\n res = av_frame_ref(nvenc_frame->in_ref, frame);\n\n if (res < 0)\n\n return res;\n\n\n\n nvenc_frame->in_map.version = NV_ENC_MAP_INPUT_RESOURCE_VER;\n\n nvenc_frame->in_map.registeredResource = ctx->registered_frames[reg_idx].regptr;\n\n nv_status = p_nvenc->nvEncMapInputResource(ctx->nvencoder, &nvenc_frame->in_map);\n\n if (nv_status != NV_ENC_SUCCESS) {\n\n av_frame_unref(nvenc_frame->in_ref);\n\n return nvenc_print_error(avctx, nv_status, \"Error mapping an input resource\");\n\n }\n\n\n\n ctx->registered_frames[reg_idx].mapped = 1;\n\n nvenc_frame->reg_idx = reg_idx;\n\n nvenc_frame->input_surface = nvenc_frame->in_map.mappedResource;\n\n nvenc_frame->format = nvenc_frame->in_map.mappedBufferFmt;\n\n nvenc_frame->pitch = frame->linesize[0];\n\n return 0;\n\n } else {\n\n NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };\n\n\n\n lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;\n\n lockBufferParams.inputBuffer = nvenc_frame->input_surface;\n\n\n\n nv_status = p_nvenc->nvEncLockInputBuffer(ctx->nvencoder, &lockBufferParams);\n\n if (nv_status != NV_ENC_SUCCESS) {\n\n return nvenc_print_error(avctx, nv_status, \"Failed locking nvenc input buffer\");\n\n }\n\n\n\n nvenc_frame->pitch = lockBufferParams.pitch;\n\n res = nvenc_copy_frame(avctx, nvenc_frame, &lockBufferParams, frame);\n\n\n\n nv_status = p_nvenc->nvEncUnlockInputBuffer(ctx->nvencoder, nvenc_frame->input_surface);\n\n if (nv_status != NV_ENC_SUCCESS) {\n\n return nvenc_print_error(avctx, nv_status, \"Failed unlocking input buffer!\");\n\n }\n\n\n\n return res;\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "bbe1b21022e4872bc64066d46a4567dc1b655f7a", + "length": 594 + }, + { + "index": 2977, + "code": "static void test_visitor_out_struct_nested(TestOutputVisitorData *data,\n\n const void *unused)\n\n{\n\n int64_t value = 42;\n\n Error *err = NULL;\n\n UserDefNested *ud2;\n\n QObject *obj;\n\n QDict *qdict, *dict1, *dict2, *dict3, *userdef;\n\n const char *string = \"user def string\";\n\n const char *strings[] = { \"forty two\", \"forty three\", \"forty four\",\n\n \"forty five\" };\n\n\n\n ud2 = g_malloc0(sizeof(*ud2));\n\n ud2->string0 = g_strdup(strings[0]);\n\n\n\n ud2->dict1.string1 = g_strdup(strings[1]);\n\n ud2->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne));\n\n ud2->dict1.dict2.userdef1->string = g_strdup(string);\n\n ud2->dict1.dict2.userdef1->base = g_new0(UserDefZero, 1);\n\n ud2->dict1.dict2.userdef1->base->integer = value;\n\n ud2->dict1.dict2.string2 = g_strdup(strings[2]);\n\n\n\n ud2->dict1.has_dict3 = true;\n\n ud2->dict1.dict3.userdef2 = g_malloc0(sizeof(UserDefOne));\n\n ud2->dict1.dict3.userdef2->string = g_strdup(string);\n\n ud2->dict1.dict3.userdef2->base = g_new0(UserDefZero, 1);\n\n ud2->dict1.dict3.userdef2->base->integer = value;\n\n ud2->dict1.dict3.string3 = g_strdup(strings[3]);\n\n\n\n visit_type_UserDefNested(data->ov, &ud2, \"unused\", &err);\n\n g_assert(!err);\n\n\n\n obj = qmp_output_get_qobject(data->qov);\n\n g_assert(obj != NULL);\n\n g_assert(qobject_type(obj) == QTYPE_QDICT);\n\n\n\n qdict = qobject_to_qdict(obj);\n\n g_assert_cmpint(qdict_size(qdict), ==, 2);\n\n g_assert_cmpstr(qdict_get_str(qdict, \"string0\"), ==, strings[0]);\n\n\n\n dict1 = qdict_get_qdict(qdict, \"dict1\");\n\n g_assert_cmpint(qdict_size(dict1), ==, 3);\n\n g_assert_cmpstr(qdict_get_str(dict1, \"string1\"), ==, strings[1]);\n\n\n\n dict2 = qdict_get_qdict(dict1, \"dict2\");\n\n g_assert_cmpint(qdict_size(dict2), ==, 2);\n\n g_assert_cmpstr(qdict_get_str(dict2, \"string2\"), ==, strings[2]);\n\n userdef = qdict_get_qdict(dict2, \"userdef1\");\n\n g_assert_cmpint(qdict_size(userdef), ==, 2);\n\n g_assert_cmpint(qdict_get_int(userdef, \"integer\"), ==, value);\n\n g_assert_cmpstr(qdict_get_str(userdef, \"string\"), ==, string);\n\n\n\n dict3 = qdict_get_qdict(dict1, \"dict3\");\n\n g_assert_cmpint(qdict_size(dict3), ==, 2);\n\n g_assert_cmpstr(qdict_get_str(dict3, \"string3\"), ==, strings[3]);\n\n userdef = qdict_get_qdict(dict3, \"userdef2\");\n\n g_assert_cmpint(qdict_size(userdef), ==, 2);\n\n g_assert_cmpint(qdict_get_int(userdef, \"integer\"), ==, value);\n\n g_assert_cmpstr(qdict_get_str(userdef, \"string\"), ==, string);\n\n\n\n QDECREF(qdict);\n\n qapi_free_UserDefNested(ud2);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b6fcf32d9b851a83dedcb609091236b97cc4a985", + "length": 800 + }, + { + "index": 23164, + "code": "static int vnc_display_get_addresses(QemuOpts *opts,\n\n bool reverse,\n\n SocketAddress ***retsaddr,\n\n size_t *retnsaddr,\n\n SocketAddress ***retwsaddr,\n\n size_t *retnwsaddr,\n\n Error **errp)\n\n{\n\n SocketAddress *saddr = NULL;\n\n SocketAddress *wsaddr = NULL;\n\n QemuOptsIter addriter;\n\n const char *addr;\n\n int to = qemu_opt_get_number(opts, \"to\", 0);\n\n bool has_ipv4 = qemu_opt_get(opts, \"ipv4\");\n\n bool has_ipv6 = qemu_opt_get(opts, \"ipv6\");\n\n bool ipv4 = qemu_opt_get_bool(opts, \"ipv4\", false);\n\n bool ipv6 = qemu_opt_get_bool(opts, \"ipv6\", false);\n\n size_t i;\n\n int displaynum = -1;\n\n int ret = -1;\n\n\n\n *retsaddr = NULL;\n\n *retnsaddr = 0;\n\n *retwsaddr = NULL;\n\n *retnwsaddr = 0;\n\n\n\n addr = qemu_opt_get(opts, \"vnc\");\n\n if (addr == NULL || g_str_equal(addr, \"none\")) {\n\n ret = 0;\n\n goto cleanup;\n\n }\n\n if (qemu_opt_get(opts, \"websocket\") &&\n\n !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {\n\n error_setg(errp,\n\n \"SHA1 hash support is required for websockets\");\n\n goto cleanup;\n\n }\n\n\n\n qemu_opt_iter_init(&addriter, opts, \"vnc\");\n\n while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {\n\n int rv;\n\n rv = vnc_display_get_address(addr, false, reverse, 0, to,\n\n has_ipv4, has_ipv6,\n\n ipv4, ipv6,\n\n &saddr, errp);\n\n if (rv < 0) {\n\n goto cleanup;\n\n }\n\n /* Historical compat - first listen address can be used\n\n * to set the default websocket port\n\n */\n\n if (displaynum == -1) {\n\n displaynum = rv;\n\n }\n\n *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1);\n\n (*retsaddr)[(*retnsaddr)++] = saddr;\n\n }\n\n\n\n /* If we had multiple primary displays, we don't do defaults\n\n * for websocket, and require explicit config instead. */\n\n if (*retnsaddr > 1) {\n\n displaynum = -1;\n\n }\n\n\n\n qemu_opt_iter_init(&addriter, opts, \"websocket\");\n\n while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {\n\n if (vnc_display_get_address(addr, true, reverse, displaynum, to,\n\n has_ipv4, has_ipv6,\n\n ipv4, ipv6,\n\n &wsaddr, errp) < 0) {\n\n goto cleanup;\n\n }\n\n\n\n /* Historical compat - if only a single listen address was\n\n * provided, then this is used to set the default listen\n\n * address for websocket too\n\n */\n\n if (*retnsaddr == 1 &&\n\n (*retsaddr)[0]->type == SOCKET_ADDRESS_KIND_INET &&\n\n wsaddr->type == SOCKET_ADDRESS_KIND_INET &&\n\n g_str_equal(wsaddr->u.inet.data->host, \"\") &&\n\n !g_str_equal((*retsaddr)[0]->u.inet.data->host, \"\")) {\n\n g_free(wsaddr->u.inet.data->host);\n\n wsaddr->u.inet.data->host =\n\n g_strdup((*retsaddr)[0]->u.inet.data->host);\n\n }\n\n\n\n *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1);\n\n (*retwsaddr)[(*retnwsaddr)++] = wsaddr;\n\n }\n\n\n\n ret = 0;\n\n cleanup:\n\n if (ret < 0) {\n\n for (i = 0; i < *retnsaddr; i++) {\n\n qapi_free_SocketAddress((*retsaddr)[i]);\n\n }\n\n g_free(*retsaddr);\n\n for (i = 0; i < *retnwsaddr; i++) {\n\n qapi_free_SocketAddress((*retwsaddr)[i]);\n\n }\n\n g_free(*retwsaddr);\n\n *retsaddr = *retwsaddr = NULL;\n\n *retnsaddr = *retnwsaddr = 0;\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "dfd100f242370886bb6732f70f1f7cbd8eb9fedc", + "length": 967 + }, + { + "index": 11369, + "code": "static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,\n\n const char *name, int devfn,\n\n Error **errp)\n\n{\n\n PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);\n\n PCIConfigReadFunc *config_read = pc->config_read;\n\n PCIConfigWriteFunc *config_write = pc->config_write;\n\n Error *local_err = NULL;\n\n AddressSpace *dma_as;\n\n DeviceState *dev = DEVICE(pci_dev);\n\n\n\n pci_dev->bus = bus;\n\n /* Only pci bridges can be attached to extra PCI root buses */\n\n if (pci_bus_is_root(bus) && bus->parent_dev && !pc->is_bridge) {\n\n error_setg(errp,\n\n \"PCI: Only PCI/PCIe bridges can be plugged into %s\",\n\n bus->parent_dev->name);\n\n return NULL;\n\n }\n\n\n\n if (devfn < 0) {\n\n for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);\n\n devfn += PCI_FUNC_MAX) {\n\n if (!bus->devices[devfn])\n\n goto found;\n\n }\n\n error_setg(errp, \"PCI: no slot/function available for %s, all in use\",\n\n name);\n\n return NULL;\n\n found: ;\n\n } else if (bus->devices[devfn]) {\n\n error_setg(errp, \"PCI: slot %d function %d not available for %s,\"\n\n \" in use by %s\",\n\n PCI_SLOT(devfn), PCI_FUNC(devfn), name,\n\n bus->devices[devfn]->name);\n\n return NULL;\n\n } else if (dev->hotplugged &&\n\n pci_get_function_0(pci_dev)) {\n\n error_setg(errp, \"PCI: slot %d function 0 already ocuppied by %s,\"\n\n \" new func %s cannot be exposed to guest.\",\n\n PCI_SLOT(devfn),\n\n bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,\n\n name);\n\n\n\n return NULL;\n\n }\n\n\n\n pci_dev->devfn = devfn;\n\n\n dma_as = pci_device_iommu_address_space(pci_dev);\n\n\n\n memory_region_init_alias(&pci_dev->bus_master_enable_region,\n\n OBJECT(pci_dev), \"bus master\",\n\n dma_as->root, 0, memory_region_size(dma_as->root));\n\n memory_region_set_enabled(&pci_dev->bus_master_enable_region, false);\n\n address_space_init(&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region,\n\n name);\n\n\n\n pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);\n\n pci_dev->irq_state = 0;\n\n pci_config_alloc(pci_dev);\n\n\n\n pci_config_set_vendor_id(pci_dev->config, pc->vendor_id);\n\n pci_config_set_device_id(pci_dev->config, pc->device_id);\n\n pci_config_set_revision(pci_dev->config, pc->revision);\n\n pci_config_set_class(pci_dev->config, pc->class_id);\n\n\n\n if (!pc->is_bridge) {\n\n if (pc->subsystem_vendor_id || pc->subsystem_id) {\n\n pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID,\n\n pc->subsystem_vendor_id);\n\n pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID,\n\n pc->subsystem_id);\n\n } else {\n\n pci_set_default_subsystem_id(pci_dev);\n\n }\n\n } else {\n\n /* subsystem_vendor_id/subsystem_id are only for header type 0 */\n\n assert(!pc->subsystem_vendor_id);\n\n assert(!pc->subsystem_id);\n\n }\n\n pci_init_cmask(pci_dev);\n\n pci_init_wmask(pci_dev);\n\n pci_init_w1cmask(pci_dev);\n\n if (pc->is_bridge) {\n\n pci_init_mask_bridge(pci_dev);\n\n }\n\n pci_init_multifunction(bus, pci_dev, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n do_pci_unregister_device(pci_dev);\n\n return NULL;\n\n }\n\n\n\n if (!config_read)\n\n config_read = pci_default_read_config;\n\n if (!config_write)\n\n config_write = pci_default_write_config;\n\n pci_dev->config_read = config_read;\n\n pci_dev->config_write = config_write;\n\n bus->devices[devfn] = pci_dev;\n\n pci_dev->version_id = 2; /* Current pci device vmstate version */\n\n return pci_dev;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "4a94b3aa6d97dfa67a20c7a0315c9773352f0e8e", + "length": 967 + }, + { + "index": 15015, + "code": "static int qemu_rdma_broken_ipv6_kernel(Error **errp, struct ibv_context *verbs)\n\n{\n\n struct ibv_port_attr port_attr;\n\n\n\n /* This bug only exists in linux, to our knowledge. */\n\n#ifdef CONFIG_LINUX\n\n\n\n /* \n\n * Verbs are only NULL if management has bound to '[::]'.\n\n * \n\n * Let's iterate through all the devices and see if there any pure IB\n\n * devices (non-ethernet).\n\n * \n\n * If not, then we can safely proceed with the migration.\n\n * Otherwise, there are no guarantees until the bug is fixed in linux.\n\n */\n\n if (!verbs) {\n\n\t int num_devices, x;\n\n struct ibv_device ** dev_list = ibv_get_device_list(&num_devices);\n\n bool roce_found = false;\n\n bool ib_found = false;\n\n\n\n for (x = 0; x < num_devices; x++) {\n\n verbs = ibv_open_device(dev_list[x]);\n\n\n\n if (ibv_query_port(verbs, 1, &port_attr)) {\n\n ibv_close_device(verbs);\n\n ERROR(errp, \"Could not query initial IB port\");\n\n return -EINVAL;\n\n }\n\n\n\n if (port_attr.link_layer == IBV_LINK_LAYER_INFINIBAND) {\n\n ib_found = true;\n\n } else if (port_attr.link_layer == IBV_LINK_LAYER_ETHERNET) {\n\n roce_found = true;\n\n }\n\n\n\n ibv_close_device(verbs);\n\n\n\n }\n\n\n\n if (roce_found) {\n\n if (ib_found) {\n\n fprintf(stderr, \"WARN: migrations may fail:\"\n\n \" IPv6 over RoCE / iWARP in linux\"\n\n \" is broken. But since you appear to have a\"\n\n \" mixed RoCE / IB environment, be sure to only\"\n\n \" migrate over the IB fabric until the kernel \"\n\n \" fixes the bug.\\n\");\n\n } else {\n\n ERROR(errp, \"You only have RoCE / iWARP devices in your systems\"\n\n \" and your management software has specified '[::]'\"\n\n \", but IPv6 over RoCE / iWARP is not supported in Linux.\");\n\n return -ENONET;\n\n }\n\n }\n\n\n\n return 0;\n\n }\n\n\n\n /*\n\n * If we have a verbs context, that means that some other than '[::]' was\n\n * used by the management software for binding. In which case we can actually \n\n * warn the user about a potential broken kernel;\n\n */\n\n\n\n /* IB ports start with 1, not 0 */\n\n if (ibv_query_port(verbs, 1, &port_attr)) {\n\n ERROR(errp, \"Could not query initial IB port\");\n\n return -EINVAL;\n\n }\n\n\n\n if (port_attr.link_layer == IBV_LINK_LAYER_ETHERNET) {\n\n ERROR(errp, \"Linux kernel's RoCE / iWARP does not support IPv6 \"\n\n \"(but patches on linux-rdma in progress)\");\n\n return -ENONET;\n\n }\n\n\n\n#endif\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "02942db7982541716131ca486ca0d59eae107553", + "length": 643 + }, + { + "index": 4576, + "code": "static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,\n\n AVFilterInOut *in)\n\n{\n\n AVFilterContext *last_filter;\n\n const AVFilter *buffer_filt = avfilter_get_by_name(\"buffer\");\n\n InputStream *ist = ifilter->ist;\n\n InputFile *f = input_files[ist->file_index];\n\n AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :\n\n ist->st->time_base;\n\n AVRational sar;\n\n char args[255], name[255];\n\n int ret, pad_idx = 0;\n\n\n\n sar = ist->st->sample_aspect_ratio.num ?\n\n ist->st->sample_aspect_ratio :\n\n ist->st->codec->sample_aspect_ratio;\n\n snprintf(args, sizeof(args), \"%d:%d:%d:%d:%d:%d:%d\", ist->st->codec->width,\n\n ist->st->codec->height, ist->st->codec->pix_fmt,\n\n tb.num, tb.den, sar.num, sar.den);\n\n snprintf(name, sizeof(name), \"graph %d input from stream %d:%d\", fg->index,\n\n ist->file_index, ist->st->index);\n\n\n\n if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,\n\n args, NULL, fg->graph)) < 0)\n\n return ret;\n\n last_filter = ifilter->filter;\n\n\n\n if (ist->framerate.num) {\n\n AVFilterContext *setpts;\n\n\n\n snprintf(name, sizeof(name), \"force CFR for input from stream %d:%d\",\n\n ist->file_index, ist->st->index);\n\n if ((ret = avfilter_graph_create_filter(&setpts,\n\n avfilter_get_by_name(\"setpts\"),\n\n name, \"N\", NULL,\n\n fg->graph)) < 0)\n\n return ret;\n\n\n\n if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)\n\n return ret;\n\n\n\n last_filter = setpts;\n\n }\n\n\n\n snprintf(name, sizeof(name), \"trim for input stream %d:%d\",\n\n ist->file_index, ist->st->index);\n\n ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?\n\n AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)\n\n return ret;\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "488a0fa68973d48e264d54f1722f7afb18afbea7", + "length": 562 + }, + { + "index": 9608, + "code": "static void qtrle_decode_32bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change)\n\n{\n\n int rle_code;\n\n int pixel_ptr;\n\n int row_inc = s->frame.linesize[0];\n\n unsigned char a, r, g, b;\n\n unsigned int argb;\n\n unsigned char *rgb = s->frame.data[0];\n\n int pixel_limit = s->frame.linesize[0] * s->avctx->height;\n\n\n\n while (lines_to_change--) {\n\n CHECK_STREAM_PTR(2);\n\n pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4;\n\n\n\n\n while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {\n\n if (rle_code == 0) {\n\n /* there's another skip code in the stream */\n\n CHECK_STREAM_PTR(1);\n\n pixel_ptr += (s->buf[stream_ptr++] - 1) * 4;\n\n\n } else if (rle_code < 0) {\n\n /* decode the run length code */\n\n rle_code = -rle_code;\n\n CHECK_STREAM_PTR(4);\n\n a = s->buf[stream_ptr++];\n\n r = s->buf[stream_ptr++];\n\n g = s->buf[stream_ptr++];\n\n b = s->buf[stream_ptr++];\n\n argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);\n\n\n\n CHECK_PIXEL_PTR(rle_code * 4);\n\n\n\n while (rle_code--) {\n\n *(unsigned int *)(&rgb[pixel_ptr]) = argb;\n\n pixel_ptr += 4;\n\n }\n\n } else {\n\n CHECK_STREAM_PTR(rle_code * 4);\n\n CHECK_PIXEL_PTR(rle_code * 4);\n\n\n\n /* copy pixels directly to output */\n\n while (rle_code--) {\n\n a = s->buf[stream_ptr++];\n\n r = s->buf[stream_ptr++];\n\n g = s->buf[stream_ptr++];\n\n b = s->buf[stream_ptr++];\n\n argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);\n\n *(unsigned int *)(&rgb[pixel_ptr]) = argb;\n\n pixel_ptr += 4;\n\n }\n\n }\n\n }\n\n row_ptr += row_inc;\n\n }\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "7fb92be7e50ea4ba5712804326c6814ae02dd190", + "length": 527 + }, + { + "index": 26854, + "code": "static void mtree_print_mr(fprintf_function mon_printf, void *f,\n\n const MemoryRegion *mr, unsigned int level,\n\n target_phys_addr_t base,\n\n MemoryRegionListHead *alias_print_queue)\n\n{\n\n MemoryRegionList *new_ml, *ml, *next_ml;\n\n MemoryRegionListHead submr_print_queue;\n\n const MemoryRegion *submr;\n\n unsigned int i;\n\n\n\n if (!mr) {\n\n return;\n\n }\n\n\n\n for (i = 0; i < level; i++) {\n\n mon_printf(f, \" \");\n\n }\n\n\n\n if (mr->alias) {\n\n MemoryRegionList *ml;\n\n bool found = false;\n\n\n\n /* check if the alias is already in the queue */\n\n QTAILQ_FOREACH(ml, alias_print_queue, queue) {\n\n if (ml->mr == mr->alias && !ml->printed) {\n\n found = true;\n\n }\n\n }\n\n\n\n if (!found) {\n\n ml = g_new(MemoryRegionList, 1);\n\n ml->mr = mr->alias;\n\n ml->printed = false;\n\n QTAILQ_INSERT_TAIL(alias_print_queue, ml, queue);\n\n }\n\n mon_printf(f, TARGET_FMT_plx \"-\" TARGET_FMT_plx \" (prio %d): alias %s @%s \"\n\n TARGET_FMT_plx \"-\" TARGET_FMT_plx \"\\n\",\n\n base + mr->addr,\n\n base + mr->addr\n\n + (target_phys_addr_t)int128_get64(mr->size) - 1,\n\n mr->priority,\n\n mr->name,\n\n mr->alias->name,\n\n mr->alias_offset,\n\n mr->alias_offset\n\n + (target_phys_addr_t)int128_get64(mr->size) - 1);\n\n } else {\n\n mon_printf(f, TARGET_FMT_plx \"-\" TARGET_FMT_plx \" (prio %d): %s\\n\",\n\n base + mr->addr,\n\n base + mr->addr\n\n + (target_phys_addr_t)int128_get64(mr->size) - 1,\n\n mr->priority,\n\n mr->name);\n\n }\n\n\n\n QTAILQ_INIT(&submr_print_queue);\n\n\n\n QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) {\n\n new_ml = g_new(MemoryRegionList, 1);\n\n new_ml->mr = submr;\n\n QTAILQ_FOREACH(ml, &submr_print_queue, queue) {\n\n if (new_ml->mr->addr < ml->mr->addr ||\n\n (new_ml->mr->addr == ml->mr->addr &&\n\n new_ml->mr->priority > ml->mr->priority)) {\n\n QTAILQ_INSERT_BEFORE(ml, new_ml, queue);\n\n new_ml = NULL;\n\n break;\n\n }\n\n }\n\n if (new_ml) {\n\n QTAILQ_INSERT_TAIL(&submr_print_queue, new_ml, queue);\n\n }\n\n }\n\n\n\n QTAILQ_FOREACH(ml, &submr_print_queue, queue) {\n\n mtree_print_mr(mon_printf, f, ml->mr, level + 1, base + mr->addr,\n\n alias_print_queue);\n\n }\n\n\n\n QTAILQ_FOREACH_SAFE(next_ml, &submr_print_queue, queue, ml) {\n\n g_free(ml);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "88365e47dd19da8776252a94ed5fa0b7242ea9e9", + "length": 695 + }, + { + "index": 13884, + "code": "static int vvfat_open(BlockDriverState *bs, QDict *options, int flags)\n\n{\n\n BDRVVVFATState *s = bs->opaque;\n\n int cyls, heads, secs;\n\n bool floppy;\n\n const char *dirname;\n\n QemuOpts *opts;\n\n Error *local_err = NULL;\n\n int ret;\n\n\n\n#ifdef DEBUG\n\n vvv = s;\n\n#endif\n\n\n\nDLOG(if (stderr == NULL) {\n\n stderr = fopen(\"vvfat.log\", \"a\");\n\n setbuf(stderr, NULL);\n\n})\n\n\n\n opts = qemu_opts_create_nofail(&runtime_opts);\n\n qemu_opts_absorb_qdict(opts, options, &local_err);\n\n if (error_is_set(&local_err)) {\n\n qerror_report_err(local_err);\n\n error_free(local_err);\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n dirname = qemu_opt_get(opts, \"dir\");\n\n if (!dirname) {\n\n qerror_report(ERROR_CLASS_GENERIC_ERROR, \"vvfat block driver requires \"\n\n \"a 'dir' option\");\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n s->fat_type = qemu_opt_get_number(opts, \"fat-type\", 0);\n\n floppy = qemu_opt_get_bool(opts, \"floppy\", false);\n\n\n\n if (floppy) {\n\n /* 1.44MB or 2.88MB floppy. 2.88MB can be FAT12 (default) or FAT16. */\n\n if (!s->fat_type) {\n\n s->fat_type = 12;\n\n secs = 36;\n\n s->sectors_per_cluster = 2;\n\n } else {\n\n secs = s->fat_type == 12 ? 18 : 36;\n\n s->sectors_per_cluster = 1;\n\n }\n\n s->first_sectors_number = 1;\n\n cyls = 80;\n\n heads = 2;\n\n } else {\n\n /* 32MB or 504MB disk*/\n\n if (!s->fat_type) {\n\n s->fat_type = 16;\n\n }\n\n cyls = s->fat_type == 12 ? 64 : 1024;\n\n heads = 16;\n\n secs = 63;\n\n }\n\n\n\n switch (s->fat_type) {\n\n case 32:\n\n\t fprintf(stderr, \"Big fat greek warning: FAT32 has not been tested. \"\n\n \"You are welcome to do so!\\n\");\n\n break;\n\n case 16:\n\n case 12:\n\n break;\n\n default:\n\n qerror_report(ERROR_CLASS_GENERIC_ERROR, \"Valid FAT types are only \"\n\n \"12, 16 and 32\");\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n\n\n s->bs = bs;\n\n\n\n /* LATER TODO: if FAT32, adjust */\n\n s->sectors_per_cluster=0x10;\n\n\n\n s->current_cluster=0xffffffff;\n\n\n\n s->first_sectors_number=0x40;\n\n /* read only is the default for safety */\n\n bs->read_only = 1;\n\n s->qcow = s->write_target = NULL;\n\n s->qcow_filename = NULL;\n\n s->fat2 = NULL;\n\n s->downcase_short_names = 1;\n\n\n\n fprintf(stderr, \"vvfat %s chs %d,%d,%d\\n\",\n\n dirname, cyls, heads, secs);\n\n\n\n s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1);\n\n\n\n if (qemu_opt_get_bool(opts, \"rw\", false)) {\n\n if (enable_write_target(s)) {\n\n ret = -EIO;\n\n goto fail;\n\n }\n\n bs->read_only = 0;\n\n }\n\n\n\n bs->total_sectors = cyls * heads * secs;\n\n\n\n if (init_directories(s, dirname, heads, secs)) {\n\n ret = -EIO;\n\n goto fail;\n\n }\n\n\n\n s->sector_count = s->faked_sectors + s->sectors_per_cluster*s->cluster_count;\n\n\n\n if (s->first_sectors_number == 0x40) {\n\n init_mbr(s, cyls, heads, secs);\n\n }\n\n\n\n // assert(is_consistent(s));\n\n qemu_co_mutex_init(&s->lock);\n\n\n\n /* Disable migration when vvfat is used rw */\n\n if (s->qcow) {\n\n error_set(&s->migration_blocker,\n\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n\n \"vvfat (rw)\", bs->device_name, \"live migration\");\n\n migrate_add_blocker(s->migration_blocker);\n\n }\n\n\n\n ret = 0;\n\nfail:\n\n qemu_opts_del(opts);\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "78f27bd02ceba4a2f6ac5c725f4d4410eec205ef", + "length": 985 + }, + { + "index": 18346, + "code": "static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,\n\n int width, int height)\n\n{\n\n int wrap, wrap3, width2;\n\n int r, g, b, r1, g1, b1, w;\n\n uint8_t *lum, *cb, *cr;\n\n const uint8_t *p;\n\n\n\n lum = dst->data[0];\n\n cb = dst->data[1];\n\n cr = dst->data[2];\n\n\n\n width2 = (width + 1) >> 1;\n\n wrap = dst->linesize[0];\n\n wrap3 = src->linesize[0];\n\n p = src->data[0];\n\n for(;height>=2;height -= 2) {\n\n for(w = width; w >= 2; w -= 2) {\n\n RGB_IN(r, g, b, p);\n\n r1 = r;\n\n g1 = g;\n\n b1 = b;\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n\n\n RGB_IN(r, g, b, p + BPP);\n\n r1 += r;\n\n g1 += g;\n\n b1 += b;\n\n lum[1] = RGB_TO_Y(r, g, b);\n\n p += wrap3;\n\n lum += wrap;\n\n\n\n RGB_IN(r, g, b, p);\n\n r1 += r;\n\n g1 += g;\n\n b1 += b;\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n\n\n RGB_IN(r, g, b, p + BPP);\n\n r1 += r;\n\n g1 += g;\n\n b1 += b;\n\n lum[1] = RGB_TO_Y(r, g, b);\n\n\n\n cb[0] = RGB_TO_U(r1, g1, b1, 2);\n\n cr[0] = RGB_TO_V(r1, g1, b1, 2);\n\n\n\n cb++;\n\n cr++;\n\n p += -wrap3 + 2 * BPP;\n\n lum += -wrap + 2;\n\n }\n\n if (w) {\n\n RGB_IN(r, g, b, p);\n\n r1 = r;\n\n g1 = g;\n\n b1 = b;\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n p += wrap3;\n\n lum += wrap;\n\n RGB_IN(r, g, b, p);\n\n r1 += r;\n\n g1 += g;\n\n b1 += b;\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n cb[0] = RGB_TO_U(r1, g1, b1, 1);\n\n cr[0] = RGB_TO_V(r1, g1, b1, 1);\n\n cb++;\n\n cr++;\n\n p += -wrap3 + BPP;\n\n lum += -wrap + 1;\n\n }\n\n p += wrap3 + (wrap3 - width * BPP);\n\n lum += wrap + (wrap - width);\n\n cb += dst->linesize[1] - width2;\n\n cr += dst->linesize[2] - width2;\n\n }\n\n /* handle odd height */\n\n if (height) {\n\n for(w = width; w >= 2; w -= 2) {\n\n RGB_IN(r, g, b, p);\n\n r1 = r;\n\n g1 = g;\n\n b1 = b;\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n\n\n RGB_IN(r, g, b, p + BPP);\n\n r1 += r;\n\n g1 += g;\n\n b1 += b;\n\n lum[1] = RGB_TO_Y(r, g, b);\n\n cb[0] = RGB_TO_U(r1, g1, b1, 1);\n\n cr[0] = RGB_TO_V(r1, g1, b1, 1);\n\n cb++;\n\n cr++;\n\n p += 2 * BPP;\n\n lum += 2;\n\n }\n\n if (w) {\n\n RGB_IN(r, g, b, p);\n\n lum[0] = RGB_TO_Y(r, g, b);\n\n cb[0] = RGB_TO_U(r, g, b, 0);\n\n cr[0] = RGB_TO_V(r, g, b, 0);\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "7e7e59409294af9caa63808e56c5cc824c98b4fc", + "length": 933 + }, + { + "index": 9462, + "code": "int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,\n\n uint8_t *buf, int buf_size,\n\n const short *samples)\n\n{\n\n AVPacket pkt;\n\n AVFrame frame0 = { 0 };\n\n AVFrame *frame;\n\n int ret, samples_size, got_packet;\n\n\n\n av_init_packet(&pkt);\n\n pkt.data = buf;\n\n pkt.size = buf_size;\n\n\n\n if (samples) {\n\n frame = &frame0;\n\n avcodec_get_frame_defaults(frame);\n\n\n\n if (avctx->frame_size) {\n\n frame->nb_samples = avctx->frame_size;\n\n } else {\n\n /* if frame_size is not set, the number of samples must be\n\n * calculated from the buffer size */\n\n int64_t nb_samples;\n\n if (!av_get_bits_per_sample(avctx->codec_id)) {\n\n av_log(avctx, AV_LOG_ERROR, \"avcodec_encode_audio() does not \"\n\n \"support this codec\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n nb_samples = (int64_t)buf_size * 8 /\n\n (av_get_bits_per_sample(avctx->codec_id) *\n\n avctx->channels);\n\n if (nb_samples >= INT_MAX)\n\n return AVERROR(EINVAL);\n\n frame->nb_samples = nb_samples;\n\n }\n\n\n\n /* it is assumed that the samples buffer is large enough based on the\n\n * relevant parameters */\n\n samples_size = av_samples_get_buffer_size(NULL, avctx->channels,\n\n frame->nb_samples,\n\n avctx->sample_fmt, 1);\n\n if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,\n\n avctx->sample_fmt,\n\n (const uint8_t *)samples,\n\n samples_size, 1)))\n\n return ret;\n\n\n\n /* fabricate frame pts from sample count.\n\n * this is needed because the avcodec_encode_audio() API does not have\n\n * a way for the user to provide pts */\n\n if (avctx->sample_rate && avctx->time_base.num)\n\n frame->pts = ff_samples_to_time_base(avctx,\n\n avctx->internal->sample_count);\n\n else\n\n frame->pts = AV_NOPTS_VALUE;\n\n avctx->internal->sample_count += frame->nb_samples;\n\n } else {\n\n frame = NULL;\n\n }\n\n\n\n got_packet = 0;\n\n ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);\n\n if (!ret && got_packet && avctx->coded_frame) {\n\n avctx->coded_frame->pts = pkt.pts;\n\n avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);\n\n }\n\n /* free any side data since we cannot return it */\n\n ff_packet_free_side_data(&pkt);\n\n\n\n if (frame && frame->extended_data != frame->data)\n\n av_freep(&frame->extended_data);\n\n\n\n return ret ? ret : pkt.size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e55c3857d20ba015e4914c2e80fcab037af0799d", + "length": 620 + }, + { + "index": 14846, + "code": "static void cmd_get_event_status_notification(IDEState *s,\n\n uint8_t *buf)\n\n{\n\n const uint8_t *packet = buf;\n\n\n\n struct {\n\n uint8_t opcode;\n\n uint8_t polled; /* lsb bit is polled; others are reserved */\n\n uint8_t reserved2[2];\n\n uint8_t class;\n\n uint8_t reserved3[2];\n\n uint16_t len;\n\n uint8_t control;\n\n } __attribute__((packed)) *gesn_cdb;\n\n\n\n struct {\n\n uint16_t len;\n\n uint8_t notification_class;\n\n uint8_t supported_events;\n\n } __attribute((packed)) *gesn_event_header;\n\n\n\n enum notification_class_request_type {\n\n NCR_RESERVED1 = 1 << 0,\n\n NCR_OPERATIONAL_CHANGE = 1 << 1,\n\n NCR_POWER_MANAGEMENT = 1 << 2,\n\n NCR_EXTERNAL_REQUEST = 1 << 3,\n\n NCR_MEDIA = 1 << 4,\n\n NCR_MULTI_HOST = 1 << 5,\n\n NCR_DEVICE_BUSY = 1 << 6,\n\n NCR_RESERVED2 = 1 << 7,\n\n };\n\n enum event_notification_class_field {\n\n ENC_NO_EVENTS = 0,\n\n ENC_OPERATIONAL_CHANGE,\n\n ENC_POWER_MANAGEMENT,\n\n ENC_EXTERNAL_REQUEST,\n\n ENC_MEDIA,\n\n ENC_MULTIPLE_HOSTS,\n\n ENC_DEVICE_BUSY,\n\n ENC_RESERVED,\n\n };\n\n unsigned int max_len, used_len;\n\n\n\n gesn_cdb = (void *)packet;\n\n gesn_event_header = (void *)buf;\n\n\n\n max_len = be16_to_cpu(gesn_cdb->len);\n\n\n\n /* It is fine by the MMC spec to not support async mode operations */\n\n if (!(gesn_cdb->polled & 0x01)) { /* asynchronous mode */\n\n /* Only polling is supported, asynchronous mode is not. */\n\n ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,\n\n ASC_INV_FIELD_IN_CMD_PACKET);\n\n return;\n\n }\n\n\n\n /* polling mode operation */\n\n\n\n /*\n\n * These are the supported events.\n\n *\n\n * We currently only support requests of the 'media' type.\n\n */\n\n gesn_event_header->supported_events = NCR_MEDIA;\n\n\n\n /*\n\n * We use |= below to set the class field; other bits in this byte\n\n * are reserved now but this is useful to do if we have to use the\n\n * reserved fields later.\n\n */\n\n gesn_event_header->notification_class = 0;\n\n\n\n /*\n\n * Responses to requests are to be based on request priority. The\n\n * notification_class_request_type enum above specifies the\n\n * priority: upper elements are higher prio than lower ones.\n\n */\n\n if (gesn_cdb->class & NCR_MEDIA) {\n\n gesn_event_header->notification_class |= ENC_MEDIA;\n\n used_len = event_status_media(s, buf);\n\n } else {\n\n gesn_event_header->notification_class = 0x80; /* No event available */\n\n used_len = sizeof(*gesn_event_header);\n\n }\n\n gesn_event_header->len = cpu_to_be16(used_len\n\n - sizeof(*gesn_event_header));\n\n ide_atapi_cmd_reply(s, used_len, max_len);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "541dc0d47f10973c241e9955afc2aefc96adec51", + "length": 694 + }, + { + "index": 21137, + "code": "static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,\n\n TCGv addr, int size)\n\n{\n\n TCGv tmp;\n\n int done_label;\n\n int fail_label;\n\n\n\n /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]) {\n\n [addr] = {Rt};\n\n {Rd} = 0;\n\n } else {\n\n {Rd} = 1;\n\n } */\n\n fail_label = gen_new_label();\n\n done_label = gen_new_label();\n\n tcg_gen_brcond_i32(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);\n\n switch (size) {\n\n case 0:\n\n tmp = gen_ld8u(addr, IS_USER(s));\n\n break;\n\n case 1:\n\n tmp = gen_ld16u(addr, IS_USER(s));\n\n break;\n\n case 2:\n\n case 3:\n\n tmp = gen_ld32(addr, IS_USER(s));\n\n break;\n\n default:\n\n abort();\n\n }\n\n tcg_gen_brcond_i32(TCG_COND_NE, tmp, cpu_exclusive_val, fail_label);\n\n dead_tmp(tmp);\n\n if (size == 3) {\n\n TCGv tmp2 = new_tmp();\n\n tcg_gen_addi_i32(tmp2, addr, 4);\n\n tmp = gen_ld32(tmp2, IS_USER(s));\n\n dead_tmp(tmp2);\n\n tcg_gen_brcond_i32(TCG_COND_NE, tmp, cpu_exclusive_high, fail_label);\n\n dead_tmp(tmp);\n\n }\n\n tmp = load_reg(s, rt);\n\n switch (size) {\n\n case 0:\n\n gen_st8(tmp, addr, IS_USER(s));\n\n break;\n\n case 1:\n\n gen_st16(tmp, addr, IS_USER(s));\n\n break;\n\n case 2:\n\n case 3:\n\n gen_st32(tmp, addr, IS_USER(s));\n\n break;\n\n default:\n\n abort();\n\n }\n\n if (size == 3) {\n\n tcg_gen_addi_i32(addr, addr, 4);\n\n tmp = load_reg(s, rt2);\n\n gen_st32(tmp, addr, IS_USER(s));\n\n }\n\n tcg_gen_movi_i32(cpu_R[rd], 0);\n\n tcg_gen_br(done_label);\n\n gen_set_label(fail_label);\n\n tcg_gen_movi_i32(cpu_R[rd], 1);\n\n gen_set_label(done_label);\n\n tcg_gen_movi_i32(cpu_exclusive_addr, -1);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "7d1b0095bff7157e856d1d0e6c4295641ced2752", + "length": 544 + }, + { + "index": 26793, + "code": "void virtio_scsi_dataplane_start(VirtIOSCSI *s)\n\n{\n\n int i;\n\n int rc;\n\n BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s)));\n\n VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);\n\n VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);\n\n\n\n if (s->dataplane_started ||\n\n s->dataplane_starting ||\n\n s->dataplane_fenced ||\n\n s->ctx != iothread_get_aio_context(vs->conf.iothread)) {\n\n return;\n\n }\n\n\n\n s->dataplane_starting = true;\n\n\n\n /* Set up guest notifier (irq) */\n\n rc = k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, true);\n\n if (rc != 0) {\n\n fprintf(stderr, \"virtio-scsi: Failed to set guest notifiers (%d), \"\n\n \"ensure -enable-kvm is set\\n\", rc);\n\n goto fail_guest_notifiers;\n\n }\n\n\n\n aio_context_acquire(s->ctx);\n\n rc = virtio_scsi_vring_init(s, vs->ctrl_vq, 0,\n\n virtio_scsi_data_plane_handle_ctrl);\n\n if (rc) {\n\n goto fail_vrings;\n\n }\n\n rc = virtio_scsi_vring_init(s, vs->event_vq, 1,\n\n virtio_scsi_data_plane_handle_event);\n\n if (rc) {\n\n goto fail_vrings;\n\n }\n\n for (i = 0; i < vs->conf.num_queues; i++) {\n\n rc = virtio_scsi_vring_init(s, vs->cmd_vqs[i], i + 2,\n\n virtio_scsi_data_plane_handle_cmd);\n\n if (rc) {\n\n goto fail_vrings;\n\n }\n\n }\n\n\n\n s->dataplane_starting = false;\n\n s->dataplane_started = true;\n\n aio_context_release(s->ctx);\n\n return;\n\n\n\nfail_vrings:\n\n virtio_scsi_clear_aio(s);\n\n aio_context_release(s->ctx);\n\n for (i = 0; i < vs->conf.num_queues + 2; i++) {\n\n virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);\n\n }\n\n k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);\n\nfail_guest_notifiers:\n\n s->dataplane_fenced = true;\n\n s->dataplane_starting = false;\n\n s->dataplane_started = true;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ad07cd69ecaffbaa015459a46975ab32e50df805", + "length": 546 + }, + { + "index": 6750, + "code": "static void eeprom24c0x_write(int scl, int sda)\n\n{\n\n if (eeprom.scl && scl && (eeprom.sda != sda)) {\n\n logout(\"%u: scl = %u->%u, sda = %u->%u i2c %s\\n\",\n\n eeprom.tick, eeprom.scl, scl, eeprom.sda, sda, sda ? \"stop\" : \"start\");\n\n if (!sda) {\n\n eeprom.tick = 1;\n\n eeprom.command = 0;\n\n }\n\n } else if (eeprom.tick == 0 && !eeprom.ack) {\n\n /* Waiting for start. */\n\n logout(\"%u: scl = %u->%u, sda = %u->%u wait for i2c start\\n\",\n\n eeprom.tick, eeprom.scl, scl, eeprom.sda, sda);\n\n } else if (!eeprom.scl && scl) {\n\n logout(\"%u: scl = %u->%u, sda = %u->%u trigger bit\\n\",\n\n eeprom.tick, eeprom.scl, scl, eeprom.sda, sda);\n\n if (eeprom.ack) {\n\n logout(\"\\ti2c ack bit = 0\\n\");\n\n sda = 0;\n\n eeprom.ack = 0;\n\n } else if (eeprom.sda == sda) {\n\n uint8_t bit = (sda != 0);\n\n logout(\"\\ti2c bit = %d\\n\", bit);\n\n if (eeprom.tick < 9) {\n\n eeprom.command <<= 1;\n\n eeprom.command += bit;\n\n eeprom.tick++;\n\n if (eeprom.tick == 9) {\n\n logout(\"\\tcommand 0x%04x, %s\\n\", eeprom.command, bit ? \"read\" : \"write\");\n\n eeprom.ack = 1;\n\n }\n\n } else if (eeprom.tick < 17) {\n\n if (eeprom.command & 1) {\n\n sda = ((eeprom.data & 0x80) != 0);\n\n }\n\n eeprom.address <<= 1;\n\n eeprom.address += bit;\n\n eeprom.tick++;\n\n eeprom.data <<= 1;\n\n if (eeprom.tick == 17) {\n\n eeprom.data = eeprom.contents[eeprom.address];\n\n logout(\"\\taddress 0x%04x, data 0x%02x\\n\", eeprom.address, eeprom.data);\n\n eeprom.ack = 1;\n\n eeprom.tick = 0;\n\n }\n\n } else if (eeprom.tick >= 17) {\n\n sda = 0;\n\n }\n\n } else {\n\n logout(\"\\tsda changed with raising scl\\n\");\n\n }\n\n } else {\n\n logout(\"%u: scl = %u->%u, sda = %u->%u\\n\", eeprom.tick, eeprom.scl, scl, eeprom.sda, sda);\n\n }\n\n eeprom.scl = scl;\n\n eeprom.sda = sda;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "35c648078aa493c3b976840eb7cf2e53ab5b7a2d", + "length": 663 + }, + { + "index": 15851, + "code": "static int clv_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n CLVContext *c = avctx->priv_data;\n GetByteContext gb;\n uint32_t frame_type;\n int i, j;\n int ret;\n int mb_ret = 0;\n bytestream2_init(&gb, buf, buf_size);\n if (avctx->codec_tag == MKTAG('C','L','V','1')) {\n int skip = bytestream2_get_byte(&gb);\n bytestream2_skip(&gb, (skip + 1) * 8);\n frame_type = bytestream2_get_byte(&gb);\n if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)\n return ret;\n c->pic->key_frame = frame_type & 0x20 ? 1 : 0;\n c->pic->pict_type = frame_type & 0x20 ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;\n if (frame_type & 0x2) {\n bytestream2_get_be32(&gb); // frame size;\n c->ac_quant = bytestream2_get_byte(&gb);\n c->luma_dc_quant = 32;\n c->chroma_dc_quant = 32;\n if ((ret = init_get_bits8(&c->gb, buf + bytestream2_tell(&gb),\n (buf_size - bytestream2_tell(&gb)))) < 0)\n return ret;\n for (i = 0; i < 3; i++)\n c->top_dc[i] = 32;\n for (i = 0; i < 4; i++)\n c->left_dc[i] = 32;\n for (j = 0; j < c->mb_height; j++) {\n for (i = 0; i < c->mb_width; i++) {\n ret = decode_mb(c, i, j);\n if (ret < 0)\n mb_ret = ret;\n } else {\n if ((ret = av_frame_ref(data, c->pic)) < 0)\n return ret;\n *got_frame = 1;\n return mb_ret < 0 ? mb_ret : buf_size;", + "label": 1, + "project": "FFmpeg", + "commit_id": "43c394dcaebe9eec5802b420f273385473380909", + "length": 526 + }, + { + "index": 13410, + "code": "static void cdrom_pio_impl(int nblocks)\n\n{\n\n QPCIDevice *dev;\n\n QPCIBar bmdma_bar, ide_bar;\n\n FILE *fh;\n\n int patt_blocks = MAX(16, nblocks);\n\n size_t patt_len = ATAPI_BLOCK_SIZE * patt_blocks;\n\n char *pattern = g_malloc(patt_len);\n\n size_t rxsize = ATAPI_BLOCK_SIZE * nblocks;\n\n uint16_t *rx = g_malloc0(rxsize);\n\n int i, j;\n\n uint8_t data;\n\n uint16_t limit;\n\n\n\n /* Prepopulate the CDROM with an interesting pattern */\n\n generate_pattern(pattern, patt_len, ATAPI_BLOCK_SIZE);\n\n fh = fopen(tmp_path, \"w+\");\n\n fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh);\n\n fclose(fh);\n\n\n\n ide_test_start(\"-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 \"\n\n \"-device ide-cd,drive=sr0,bus=ide.0\", tmp_path);\n\n dev = get_pci_device(&bmdma_bar, &ide_bar);\n\n qtest_irq_intercept_in(global_qtest, \"ioapic\");\n\n\n\n /* PACKET command on device 0 */\n\n qpci_io_writeb(dev, ide_bar, reg_device, 0);\n\n qpci_io_writeb(dev, ide_bar, reg_lba_middle, BYTE_COUNT_LIMIT & 0xFF);\n\n qpci_io_writeb(dev, ide_bar, reg_lba_high, (BYTE_COUNT_LIMIT >> 8 & 0xFF));\n\n qpci_io_writeb(dev, ide_bar, reg_command, CMD_PACKET);\n\n /* HP0: Check_Status_A State */\n\n nsleep(400);\n\n data = ide_wait_clear(BSY);\n\n /* HP1: Send_Packet State */\n\n assert_bit_set(data, DRQ | DRDY);\n\n assert_bit_clear(data, ERR | DF | BSY);\n\n\n\n /* SCSI CDB (READ10) -- read n*2048 bytes from block 0 */\n\n send_scsi_cdb_read10(dev, ide_bar, 0, nblocks);\n\n\n\n /* Read data back: occurs in bursts of 'BYTE_COUNT_LIMIT' bytes.\n\n * If BYTE_COUNT_LIMIT is odd, we transfer BYTE_COUNT_LIMIT - 1 bytes.\n\n * We allow an odd limit only when the remaining transfer size is\n\n * less than BYTE_COUNT_LIMIT. However, SCSI's read10 command can only\n\n * request n blocks, so our request size is always even.\n\n * For this reason, we assume there is never a hanging byte to fetch. */\n\n g_assert(!(rxsize & 1));\n\n limit = BYTE_COUNT_LIMIT & ~1;\n\n for (i = 0; i < DIV_ROUND_UP(rxsize, limit); i++) {\n\n size_t offset = i * (limit / 2);\n\n size_t rem = (rxsize / 2) - offset;\n\n\n\n /* HP3: INTRQ_Wait */\n\n ide_wait_intr(IDE_PRIMARY_IRQ);\n\n\n\n /* HP2: Check_Status_B (and clear IRQ) */\n\n data = ide_wait_clear(BSY);\n\n assert_bit_set(data, DRQ | DRDY);\n\n assert_bit_clear(data, ERR | DF | BSY);\n\n\n\n /* HP4: Transfer_Data */\n\n for (j = 0; j < MIN((limit / 2), rem); j++) {\n\n rx[offset + j] = cpu_to_le16(qpci_io_readw(dev, ide_bar,\n\n reg_data));\n\n }\n\n }\n\n\n\n /* Check for final completion IRQ */\n\n ide_wait_intr(IDE_PRIMARY_IRQ);\n\n\n\n /* Sanity check final state */\n\n data = ide_wait_clear(DRQ);\n\n assert_bit_set(data, DRDY);\n\n assert_bit_clear(data, DRQ | ERR | DF | BSY);\n\n\n\n g_assert_cmpint(memcmp(pattern, rx, rxsize), ==, 0);\n\n g_free(pattern);\n\n g_free(rx);\n\n test_bmdma_teardown();\n\n free_pci_device(dev);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "543f8f13e256a081dd820375e9575439b659ccd8", + "length": 853 + }, + { + "index": 13764, + "code": "static void s390_init(MachineState *machine)\n\n{\n\n ram_addr_t my_ram_size = machine->ram_size;\n\n MemoryRegion *sysmem = get_system_memory();\n\n MemoryRegion *ram = g_new(MemoryRegion, 1);\n\n int increment_size = 20;\n\n void *virtio_region;\n\n hwaddr virtio_region_len;\n\n hwaddr virtio_region_start;\n\n\n\n if (machine->ram_slots) {\n\n error_report(\"Memory hotplug not supported by the selected machine.\");\n\n exit(EXIT_FAILURE);\n\n }\n\n /*\n\n * The storage increment size is a multiple of 1M and is a power of 2.\n\n * The number of storage increments must be MAX_STORAGE_INCREMENTS or\n\n * fewer.\n\n */\n\n while ((my_ram_size >> increment_size) > MAX_STORAGE_INCREMENTS) {\n\n increment_size++;\n\n }\n\n my_ram_size = my_ram_size >> increment_size << increment_size;\n\n\n\n /* let's propagate the changed ram size into the global variable. */\n\n ram_size = my_ram_size;\n\n\n\n /* get a BUS */\n\n s390_bus = s390_virtio_bus_init(&my_ram_size);\n\n s390_sclp_init();\n\n s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,\n\n machine->initrd_filename, ZIPL_FILENAME, false);\n\n s390_flic_init();\n\n\n\n /* register hypercalls */\n\n s390_virtio_register_hcalls();\n\n\n\n /* allocate RAM */\n\n memory_region_init_ram(ram, NULL, \"s390.ram\", my_ram_size, &error_abort);\n\n vmstate_register_ram_global(ram);\n\n memory_region_add_subregion(sysmem, 0, ram);\n\n\n\n /* clear virtio region */\n\n virtio_region_len = my_ram_size - ram_size;\n\n virtio_region_start = ram_size;\n\n virtio_region = cpu_physical_memory_map(virtio_region_start,\n\n &virtio_region_len, true);\n\n memset(virtio_region, 0, virtio_region_len);\n\n cpu_physical_memory_unmap(virtio_region, virtio_region_len, 1,\n\n virtio_region_len);\n\n\n\n /* Initialize storage key device */\n\n s390_skeys_init();\n\n\n\n /* init CPUs */\n\n s390_init_cpus(machine->cpu_model);\n\n\n\n /* Create VirtIO network adapters */\n\n s390_create_virtio_net((BusState *)s390_bus, \"virtio-net-s390\");\n\n\n\n /* Register savevm handler for guest TOD clock */\n\n register_savevm(NULL, \"todclock\", 0, 1, gtod_save, gtod_load, NULL);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "1cf065fb87e8787e3e9cebcdb4713b81e4e61422", + "length": 551 + }, + { + "index": 4967, + "code": "static void ipvideo_decode_opcodes(IpvideoContext *s, AVFrame *frame)\n\n{\n\n int x, y;\n\n unsigned char opcode;\n\n int ret;\n\n GetBitContext gb;\n\n\n\n bytestream2_skip(&s->stream_ptr, 14); /* data starts 14 bytes in */\n\n if (!s->is_16bpp) {\n\n /* this is PAL8, so make the palette available */\n\n memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);\n\n\n\n s->stride = frame->linesize[0];\n\n } else {\n\n s->stride = frame->linesize[0] >> 1;\n\n s->mv_ptr = s->stream_ptr;\n\n bytestream2_skip(&s->mv_ptr, bytestream2_get_le16(&s->stream_ptr));\n\n }\n\n s->line_inc = s->stride - 8;\n\n s->upper_motion_limit_offset = (s->avctx->height - 8) * frame->linesize[0]\n\n + (s->avctx->width - 8) * (1 + s->is_16bpp);\n\n\n\n init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8);\n\n for (y = 0; y < s->avctx->height; y += 8) {\n\n for (x = 0; x < s->avctx->width; x += 8) {\n\n if (get_bits_left(&gb) < 4)\n\n return;\n\n opcode = get_bits(&gb, 4);\n\n\n\n ff_tlog(s->avctx,\n\n \" block @ (%3d, %3d): encoding 0x%X, data ptr offset %d\\n\",\n\n x, y, opcode, bytestream2_tell(&s->stream_ptr));\n\n\n\n if (!s->is_16bpp) {\n\n s->pixel_ptr = frame->data[0] + x\n\n + y*frame->linesize[0];\n\n ret = ipvideo_decode_block[opcode](s, frame);\n\n } else {\n\n s->pixel_ptr = frame->data[0] + x*2\n\n + y*frame->linesize[0];\n\n ret = ipvideo_decode_block16[opcode](s, frame);\n\n }\n\n if (ret != 0) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"decode problem on frame %d, @ block (%d, %d)\\n\",\n\n s->avctx->frame_number, x, y);\n\n return;\n\n }\n\n }\n\n }\n\n if (bytestream2_get_bytes_left(&s->stream_ptr) > 1) {\n\n av_log(s->avctx, AV_LOG_DEBUG,\n\n \"decode finished with %d bytes left over\\n\",\n\n bytestream2_get_bytes_left(&s->stream_ptr));\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "19f6fd199e46c5a56f09a768ece4246b48bd86dd", + "length": 614 + }, + { + "index": 5428, + "code": "static inline void decode_block_intra(MadContext *s, int16_t * block)\n\n{\n\n int level, i, j, run;\n\n RLTable *rl = &ff_rl_mpeg1;\n\n const uint8_t *scantable = s->scantable.permutated;\n\n int16_t *quant_matrix = s->quant_matrix;\n\n\n\n block[0] = (128 + get_sbits(&s->gb, 8)) * quant_matrix[0];\n\n\n\n /* The RL decoder is derived from mpeg1_decode_block_intra;\n\n Escaped level and run values a decoded differently */\n\n i = 0;\n\n {\n\n OPEN_READER(re, &s->gb);\n\n /* now quantify & encode AC coefficients */\n\n for (;;) {\n\n UPDATE_CACHE(re, &s->gb);\n\n GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);\n\n\n\n if (level == 127) {\n\n break;\n\n } else if (level != 0) {\n\n i += run;\n\n j = scantable[i];\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n\n LAST_SKIP_BITS(re, &s->gb, 1);\n\n } else {\n\n /* escape */\n\n UPDATE_CACHE(re, &s->gb);\n\n level = SHOW_SBITS(re, &s->gb, 10); SKIP_BITS(re, &s->gb, 10);\n\n\n\n UPDATE_CACHE(re, &s->gb);\n\n run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);\n\n\n\n i += run;\n\n j = scantable[i];\n\n if (level < 0) {\n\n level = -level;\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n level = -level;\n\n } else {\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n }\n\n }\n\n if (i > 63) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"ac-tex damaged at %d %d\\n\", s->mb_x, s->mb_y);\n\n return;\n\n }\n\n\n\n block[j] = level;\n\n }\n\n CLOSE_READER(re, &s->gb);\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "061c489895d29049a88dc6118e4b639a273b31d6", + "length": 562 + }, + { + "index": 22177, + "code": "static void niagara_init(MachineState *machine)\n\n{\n\n NiagaraBoardState *s = g_new(NiagaraBoardState, 1);\n\n DriveInfo *dinfo = drive_get_next(IF_PFLASH);\n\n MemoryRegion *sysmem = get_system_memory();\n\n\n\n /* init CPUs */\n\n sparc64_cpu_devinit(machine->cpu_model, \"Sun UltraSparc T1\",\n\n NIAGARA_PROM_BASE);\n\n /* set up devices */\n\n memory_region_allocate_system_memory(&s->hv_ram, NULL, \"sun4v-hv.ram\",\n\n NIAGARA_HV_RAM_SIZE);\n\n memory_region_add_subregion(sysmem, NIAGARA_HV_RAM_BASE, &s->hv_ram);\n\n\n\n memory_region_allocate_system_memory(&s->partition_ram, NULL,\n\n \"sun4v-partition.ram\",\n\n machine->ram_size);\n\n memory_region_add_subregion(sysmem, NIAGARA_PARTITION_RAM_BASE,\n\n &s->partition_ram);\n\n\n\n memory_region_allocate_system_memory(&s->nvram, NULL,\n\n \"sun4v.nvram\", NIAGARA_NVRAM_SIZE);\n\n memory_region_add_subregion(sysmem, NIAGARA_NVRAM_BASE, &s->nvram);\n\n memory_region_allocate_system_memory(&s->md_rom, NULL,\n\n \"sun4v-md.rom\", NIAGARA_MD_ROM_SIZE);\n\n memory_region_add_subregion(sysmem, NIAGARA_MD_ROM_BASE, &s->md_rom);\n\n memory_region_allocate_system_memory(&s->hv_rom, NULL,\n\n \"sun4v-hv.rom\", NIAGARA_HV_ROM_SIZE);\n\n memory_region_add_subregion(sysmem, NIAGARA_HV_ROM_BASE, &s->hv_rom);\n\n memory_region_allocate_system_memory(&s->prom, NULL,\n\n \"sun4v.prom\", PROM_SIZE_MAX);\n\n memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom);\n\n\n\n add_rom_or_fail(\"nvram1\", NIAGARA_NVRAM_BASE);\n\n add_rom_or_fail(\"1up-md.bin\", NIAGARA_MD_ROM_BASE);\n\n add_rom_or_fail(\"1up-hv.bin\", NIAGARA_HV_ROM_BASE);\n\n\n\n add_rom_or_fail(\"reset.bin\", NIAGARA_PROM_BASE);\n\n add_rom_or_fail(\"q.bin\", NIAGARA_PROM_BASE + NIAGARA_Q_OFFSET);\n\n add_rom_or_fail(\"openboot.bin\", NIAGARA_PROM_BASE + NIAGARA_OBP_OFFSET);\n\n\n\n /* the virtual ramdisk is kind of initrd, but it resides\n\n outside of the partition RAM */\n\n if (dinfo) {\n\n BlockBackend *blk = blk_by_legacy_dinfo(dinfo);\n\n int size = blk_getlength(blk);\n\n if (size > 0) {\n\n memory_region_allocate_system_memory(&s->vdisk_ram, NULL,\n\n \"sun4v_vdisk.ram\", size);\n\n memory_region_add_subregion(get_system_memory(),\n\n NIAGARA_VDISK_BASE, &s->vdisk_ram);\n\n dinfo->is_default = 1;\n\n rom_add_file_fixed(blk_bs(blk)->filename, NIAGARA_VDISK_BASE, -1);\n\n } else {\n\n fprintf(stderr, \"qemu: could not load ram disk '%s'\\n\",\n\n blk_bs(blk)->filename);\n\n exit(1);\n\n }\n\n }\n\n serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL, 115200,\n\n serial_hds[0], DEVICE_BIG_ENDIAN);\n\n\n\n empty_slot_init(NIAGARA_IOBBASE, NIAGARA_IOBSIZE);\n\n sun4v_rtc_init(NIAGARA_RTC_BASE);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a5a08302d44a8b1a8c5819b1411002f85bb5f847", + "length": 779 + }, + { + "index": 19072, + "code": "static av_cold int imc_decode_init(AVCodecContext * avctx)\n\n{\n\n int i, j;\n\n IMCContext *q = avctx->priv_data;\n\n double r1, r2;\n\n\n\n q->decoder_reset = 1;\n\n\n\n for(i = 0; i < BANDS; i++)\n\n q->old_floor[i] = 1.0;\n\n\n\n /* Build mdct window, a simple sine window normalized with sqrt(2) */\n\n ff_sine_window_init(q->mdct_sine_window, COEFFS);\n\n for(i = 0; i < COEFFS; i++)\n\n q->mdct_sine_window[i] *= sqrt(2.0);\n\n for(i = 0; i < COEFFS/2; i++){\n\n q->post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);\n\n q->post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);\n\n\n\n r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);\n\n r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);\n\n\n\n if (i & 0x1)\n\n {\n\n q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);\n\n q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);\n\n }\n\n else\n\n {\n\n q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);\n\n q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);\n\n }\n\n\n\n q->last_fft_im[i] = 0;\n\n }\n\n\n\n /* Generate a square root table */\n\n\n\n for(i = 0; i < 30; i++) {\n\n q->sqrt_tab[i] = sqrt(i);\n\n }\n\n\n\n /* initialize the VLC tables */\n\n for(i = 0; i < 4 ; i++) {\n\n for(j = 0; j < 4; j++) {\n\n huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]];\n\n huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];\n\n init_vlc(&huffman_vlc[i][j], 9, imc_huffman_sizes[i],\n\n imc_huffman_lens[i][j], 1, 1,\n\n imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);\n\n }\n\n }\n\n q->one_div_log2 = 1/log(2);\n\n\n\n ff_fft_init(&q->fft, 7, 1);\n\n dsputil_init(&q->dsp, avctx);\n\n avctx->sample_fmt = AV_SAMPLE_FMT_FLT;\n\n avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "95fee70d6773fde1c34ff6422f48e5e66f37f263", + "length": 704 + }, + { + "index": 3115, + "code": "static void megasas_mmio_write(void *opaque, hwaddr addr,\n\n uint64_t val, unsigned size)\n\n{\n\n MegasasState *s = opaque;\n\n PCIDevice *pci_dev = PCI_DEVICE(s);\n\n uint64_t frame_addr;\n\n uint32_t frame_count;\n\n int i;\n\n\n\n switch (addr) {\n\n case MFI_IDB:\n\n trace_megasas_mmio_writel(\"MFI_IDB\", val);\n\n if (val & MFI_FWINIT_ABORT) {\n\n /* Abort all pending cmds */\n\n for (i = 0; i < s->fw_cmds; i++) {\n\n megasas_abort_command(&s->frames[i]);\n\n }\n\n }\n\n if (val & MFI_FWINIT_READY) {\n\n /* move to FW READY */\n\n megasas_soft_reset(s);\n\n }\n\n if (val & MFI_FWINIT_MFIMODE) {\n\n /* discard MFIs */\n\n }\n\n if (val & MFI_FWINIT_STOP_ADP) {\n\n /* Terminal error, stop processing */\n\n s->fw_state = MFI_FWSTATE_FAULT;\n\n }\n\n break;\n\n case MFI_OMSK:\n\n trace_megasas_mmio_writel(\"MFI_OMSK\", val);\n\n s->intr_mask = val;\n\n if (!megasas_intr_enabled(s) &&\n\n !msi_enabled(pci_dev) &&\n\n !msix_enabled(pci_dev)) {\n\n trace_megasas_irq_lower();\n\n pci_irq_deassert(pci_dev);\n\n }\n\n if (megasas_intr_enabled(s)) {\n\n if (msix_enabled(pci_dev)) {\n\n trace_megasas_msix_enabled(0);\n\n } else if (msi_enabled(pci_dev)) {\n\n trace_megasas_msi_enabled(0);\n\n } else {\n\n trace_megasas_intr_enabled();\n\n }\n\n } else {\n\n trace_megasas_intr_disabled();\n\n megasas_soft_reset(s);\n\n }\n\n break;\n\n case MFI_ODCR0:\n\n trace_megasas_mmio_writel(\"MFI_ODCR0\", val);\n\n s->doorbell = 0;\n\n if (megasas_intr_enabled(s)) {\n\n if (!msix_enabled(pci_dev) && !msi_enabled(pci_dev)) {\n\n trace_megasas_irq_lower();\n\n pci_irq_deassert(pci_dev);\n\n }\n\n }\n\n break;\n\n case MFI_IQPH:\n\n trace_megasas_mmio_writel(\"MFI_IQPH\", val);\n\n /* Received high 32 bits of a 64 bit MFI frame address */\n\n s->frame_hi = val;\n\n break;\n\n case MFI_IQPL:\n\n trace_megasas_mmio_writel(\"MFI_IQPL\", val);\n\n /* Received low 32 bits of a 64 bit MFI frame address */\n\n /* Fallthrough */\n\n case MFI_IQP:\n\n if (addr == MFI_IQP) {\n\n trace_megasas_mmio_writel(\"MFI_IQP\", val);\n\n /* Received 64 bit MFI frame address */\n\n s->frame_hi = 0;\n\n }\n\n frame_addr = (val & ~0x1F);\n\n /* Add possible 64 bit offset */\n\n frame_addr |= ((uint64_t)s->frame_hi << 32);\n\n s->frame_hi = 0;\n\n frame_count = (val >> 1) & 0xF;\n\n megasas_handle_frame(s, frame_addr, frame_count);\n\n break;\n\n case MFI_SEQ:\n\n trace_megasas_mmio_writel(\"MFI_SEQ\", val);\n\n /* Magic sequence to start ADP reset */\n\n if (adp_reset_seq[s->adp_reset] == val) {\n\n s->adp_reset++;\n\n } else {\n\n s->adp_reset = 0;\n\n s->diag = 0;\n\n }\n\n if (s->adp_reset == 6) {\n\n s->diag = MFI_DIAG_WRITE_ENABLE;\n\n }\n\n break;\n\n case MFI_DIAG:\n\n trace_megasas_mmio_writel(\"MFI_DIAG\", val);\n\n /* ADP reset */\n\n if ((s->diag & MFI_DIAG_WRITE_ENABLE) &&\n\n (val & MFI_DIAG_RESET_ADP)) {\n\n s->diag |= MFI_DIAG_RESET_ADP;\n\n megasas_soft_reset(s);\n\n s->adp_reset = 0;\n\n s->diag = 0;\n\n }\n\n break;\n\n default:\n\n trace_megasas_mmio_invalid_writel(addr, val);\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "24dfa9fa2f90a95ac33c7372de4f4f2c8a2c141f", + "length": 983 + }, + { + "index": 2750, + "code": "void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)\n\n{\n\n mpeg1_encode_sequence_header(s);\n\n\n\n /* mpeg1 picture header */\n\n put_header(s, PICTURE_START_CODE);\n\n /* temporal reference */\n\n\n\n // RAL: s->picture_number instead of s->fake_picture_number\n\n put_bits(&s->pb, 10, (s->picture_number - \n\n s->gop_picture_number) & 0x3ff); \n\n s->fake_picture_number++;\n\n \n\n put_bits(&s->pb, 3, s->pict_type);\n\n\n\n s->vbv_delay_ptr= s->pb.buf + get_bit_count(&s->pb)/8;\n\n put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */\n\n \n\n // RAL: Forward f_code also needed for B frames\n\n if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {\n\n put_bits(&s->pb, 1, 0); /* half pel coordinates */\n\n if(s->codec_id == CODEC_ID_MPEG1VIDEO)\n\n put_bits(&s->pb, 3, s->f_code); /* forward_f_code */\n\n else\n\n put_bits(&s->pb, 3, 7); /* forward_f_code */\n\n }\n\n \n\n // RAL: Backward f_code necessary for B frames\n\n if (s->pict_type == B_TYPE) {\n\n put_bits(&s->pb, 1, 0); /* half pel coordinates */\n\n if(s->codec_id == CODEC_ID_MPEG1VIDEO)\n\n put_bits(&s->pb, 3, s->b_code); /* backward_f_code */\n\n else\n\n put_bits(&s->pb, 3, 7); /* backward_f_code */\n\n }\n\n\n\n put_bits(&s->pb, 1, 0); /* extra bit picture */\n\n\n\n s->frame_pred_frame_dct = 1;\n\n if(s->codec_id == CODEC_ID_MPEG2VIDEO){\n\n put_header(s, EXT_START_CODE);\n\n put_bits(&s->pb, 4, 8); //pic ext\n\n if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {\n\n put_bits(&s->pb, 4, s->f_code);\n\n put_bits(&s->pb, 4, s->f_code);\n\n }else{\n\n put_bits(&s->pb, 8, 255);\n\n }\n\n if (s->pict_type == B_TYPE) {\n\n put_bits(&s->pb, 4, s->b_code);\n\n put_bits(&s->pb, 4, s->b_code);\n\n }else{\n\n put_bits(&s->pb, 8, 255);\n\n }\n\n put_bits(&s->pb, 2, s->intra_dc_precision);\n\n put_bits(&s->pb, 2, s->picture_structure= PICT_FRAME);\n\n if (s->progressive_sequence) {\n\n put_bits(&s->pb, 1, 0); /* no repeat */\n\n } else {\n\n put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);\n\n }\n\n /* XXX: optimize the generation of this flag with entropy\n\n measures */\n\n s->frame_pred_frame_dct = s->progressive_sequence;\n\n \n\n put_bits(&s->pb, 1, s->frame_pred_frame_dct);\n\n put_bits(&s->pb, 1, s->concealment_motion_vectors);\n\n put_bits(&s->pb, 1, s->q_scale_type);\n\n put_bits(&s->pb, 1, s->intra_vlc_format);\n\n put_bits(&s->pb, 1, s->alternate_scan);\n\n put_bits(&s->pb, 1, s->repeat_first_field);\n\n put_bits(&s->pb, 1, s->chroma_420_type=1);\n\n s->progressive_frame = s->progressive_sequence;\n\n put_bits(&s->pb, 1, s->progressive_frame);\n\n put_bits(&s->pb, 1, 0); //composite_display_flag\n\n }\n\n if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){\n\n int i;\n\n\n\n put_header(s, USER_START_CODE);\n\n for(i=0; ipb, 8, svcd_scan_offset_placeholder[i]);\n\n }\n\n }\n\n \n\n s->mb_y=0;\n\n ff_mpeg1_encode_slice_header(s);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2c492e94fc9d8a5e998b25f4d0390c95f2d4674f", + "length": 998 + }, + { + "index": 6000, + "code": "static void ehci_frame_timer(void *opaque)\n\n{\n\n EHCIState *ehci = opaque;\n\n int need_timer = 0;\n\n int64_t expire_time, t_now;\n\n uint64_t ns_elapsed;\n\n uint64_t uframes, skipped_uframes;\n\n int i;\n\n\n\n t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);\n\n ns_elapsed = t_now - ehci->last_run_ns;\n\n uframes = ns_elapsed / UFRAME_TIMER_NS;\n\n\n\n if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) {\n\n need_timer++;\n\n\n\n if (uframes > (ehci->maxframes * 8)) {\n\n skipped_uframes = uframes - (ehci->maxframes * 8);\n\n ehci_update_frindex(ehci, skipped_uframes);\n\n ehci->last_run_ns += UFRAME_TIMER_NS * skipped_uframes;\n\n uframes -= skipped_uframes;\n\n DPRINTF(\"WARNING - EHCI skipped %d uframes\\n\", skipped_uframes);\n\n }\n\n\n\n for (i = 0; i < uframes; i++) {\n\n /*\n\n * If we're running behind schedule, we should not catch up\n\n * too fast, as that will make some guests unhappy:\n\n * 1) We must process a minimum of MIN_UFR_PER_TICK frames,\n\n * otherwise we will never catch up\n\n * 2) Process frames until the guest has requested an irq (IOC)\n\n */\n\n if (i >= MIN_UFR_PER_TICK) {\n\n ehci_commit_irq(ehci);\n\n if ((ehci->usbsts & USBINTR_MASK) & ehci->usbintr) {\n\n break;\n\n }\n\n }\n\n if (ehci->periodic_sched_active) {\n\n ehci->periodic_sched_active--;\n\n }\n\n ehci_update_frindex(ehci, 1);\n\n if ((ehci->frindex & 7) == 0) {\n\n ehci_advance_periodic_state(ehci);\n\n }\n\n ehci->last_run_ns += UFRAME_TIMER_NS;\n\n }\n\n } else {\n\n ehci->periodic_sched_active = 0;\n\n ehci_update_frindex(ehci, uframes);\n\n ehci->last_run_ns += UFRAME_TIMER_NS * uframes;\n\n }\n\n\n\n if (ehci->periodic_sched_active) {\n\n ehci->async_stepdown = 0;\n\n } else if (ehci->async_stepdown < ehci->maxframes / 2) {\n\n ehci->async_stepdown++;\n\n }\n\n\n\n /* Async is not inside loop since it executes everything it can once\n\n * called\n\n */\n\n if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) {\n\n need_timer++;\n\n ehci_advance_async_state(ehci);\n\n }\n\n\n\n ehci_commit_irq(ehci);\n\n if (ehci->usbsts_pending) {\n\n need_timer++;\n\n ehci->async_stepdown = 0;\n\n }\n\n\n\n if (ehci_enabled(ehci) && (ehci->usbintr & USBSTS_FLR)) {\n\n need_timer++;\n\n }\n\n\n\n if (need_timer) {\n\n /* If we've raised int, we speed up the timer, so that we quickly\n\n * notice any new packets queued up in response */\n\n if (ehci->int_req_by_async && (ehci->usbsts & USBSTS_INT)) {\n\n expire_time = t_now +\n\n NANOSECONDS_PER_SECOND / (FRAME_TIMER_FREQ * 4);\n\n ehci->int_req_by_async = false;\n\n } else {\n\n expire_time = t_now + (NANOSECONDS_PER_SECOND\n\n * (ehci->async_stepdown+1) / FRAME_TIMER_FREQ);\n\n }\n\n timer_mod(ehci->frame_timer, expire_time);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "3bfecee2cb71f21cd39d6183f18b446c01917573", + "length": 819 + }, + { + "index": 6728, + "code": "static void gem_transmit(CadenceGEMState *s)\n{\n unsigned desc[2];\n hwaddr packet_desc_addr;\n uint8_t tx_packet[2048];\n uint8_t *p;\n unsigned total_bytes;\n /* Do nothing if transmit is not enabled. */\n if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {\n return;\n DB_PRINT(\"\\n\");\n /* The packet we will hand off to QEMU.\n * Packets scattered across multiple descriptors are gathered to this\n * one contiguous buffer first.\n */\n p = tx_packet;\n total_bytes = 0;\n /* read current descriptor */\n packet_desc_addr = s->tx_desc_addr;\n DB_PRINT(\"read descriptor 0x%\" HWADDR_PRIx \"\\n\", packet_desc_addr);\n cpu_physical_memory_read(packet_desc_addr,\n (uint8_t *)desc, sizeof(desc));\n /* Handle all descriptors owned by hardware */\n while (tx_desc_get_used(desc) == 0) {\n /* Do nothing if transmit is not enabled. */\n if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {\n return;\n print_gem_tx_desc(desc);\n /* The real hardware would eat this (and possibly crash).\n * For QEMU let's lend a helping hand.\n */\n if ((tx_desc_get_buffer(desc) == 0) ||\n (tx_desc_get_length(desc) == 0)) {\n DB_PRINT(\"Invalid TX descriptor @ 0x%x\\n\",\n (unsigned)packet_desc_addr);\n /* Gather this fragment of the packet from \"dma memory\" to our contig.\n * buffer.\n */\n cpu_physical_memory_read(tx_desc_get_buffer(desc), p,\n tx_desc_get_length(desc));\n p += tx_desc_get_length(desc);\n total_bytes += tx_desc_get_length(desc);\n /* Last descriptor for this packet; hand the whole thing off */\n if (tx_desc_get_last(desc)) {\n unsigned desc_first[2];\n /* Modify the 1st descriptor of this packet to be owned by\n * the processor.\n */\n cpu_physical_memory_read(s->tx_desc_addr, (uint8_t *)desc_first,\n sizeof(desc_first));\n tx_desc_set_used(desc_first);\n cpu_physical_memory_write(s->tx_desc_addr, (uint8_t *)desc_first,\n sizeof(desc_first));\n /* Advance the hardware current descriptor past this packet */\n if (tx_desc_get_wrap(desc)) {\n s->tx_desc_addr = s->regs[GEM_TXQBASE];\n } else {\n s->tx_desc_addr = packet_desc_addr + 8;\n DB_PRINT(\"TX descriptor next: 0x%08x\\n\", s->tx_desc_addr);\n s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;\n s->regs[GEM_ISR] |= GEM_INT_TXCMPL & ~(s->regs[GEM_IMR]);\n /* Handle interrupt consequences */\n gem_update_int_status(s);\n /* Is checksum offload enabled? */\n if (s->regs[GEM_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {\n net_checksum_calculate(tx_packet, total_bytes);\n /* Update MAC statistics */\n gem_transmit_updatestats(s, tx_packet, total_bytes);\n /* Send the packet somewhere */\n if (s->phy_loop || (s->regs[GEM_NWCTRL] & GEM_NWCTRL_LOCALLOOP)) {\n gem_receive(qemu_get_queue(s->nic), tx_packet, total_bytes);\n } else {\n qemu_send_packet(qemu_get_queue(s->nic), tx_packet,\n total_bytes);\n /* Prepare for next packet */\n p = tx_packet;\n total_bytes = 0;\n /* read next descriptor */\n if (tx_desc_get_wrap(desc)) {\n packet_desc_addr = s->regs[GEM_TXQBASE];\n } else {\n packet_desc_addr += 8;\n DB_PRINT(\"read descriptor 0x%\" HWADDR_PRIx \"\\n\", packet_desc_addr);\n cpu_physical_memory_read(packet_desc_addr,\n (uint8_t *)desc, sizeof(desc));\n if (tx_desc_get_used(desc)) {\n s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_USED;\n s->regs[GEM_ISR] |= GEM_INT_TXUSED & ~(s->regs[GEM_IMR]);\n gem_update_int_status(s);", + "label": 1, + "project": "qemu", + "commit_id": "d7f053652fef48bee7c461c162c8d4d2c96ab157", + "length": 951 + }, + { + "index": 13720, + "code": "static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model)\n\n{\n\n unsigned int i;\n\n const sparc_def_t *def = NULL;\n\n char *s = strdup(cpu_model);\n\n char *featurestr, *name = strtok(s, \",\");\n\n uint32_t plus_features = 0;\n\n uint32_t minus_features = 0;\n\n uint64_t iu_version;\n\n uint32_t fpu_version, mmu_version, nwindows;\n\n\n\n for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {\n\n if (strcasecmp(name, sparc_defs[i].name) == 0) {\n\n def = &sparc_defs[i];\n\n }\n\n }\n\n if (!def) {\n\n goto error;\n\n }\n\n memcpy(cpu_def, def, sizeof(*def));\n\n\n\n featurestr = strtok(NULL, \",\");\n\n while (featurestr) {\n\n char *val;\n\n\n\n if (featurestr[0] == '+') {\n\n add_flagname_to_bitmaps(featurestr + 1, &plus_features);\n\n } else if (featurestr[0] == '-') {\n\n add_flagname_to_bitmaps(featurestr + 1, &minus_features);\n\n } else if ((val = strchr(featurestr, '='))) {\n\n *val = 0; val++;\n\n if (!strcmp(featurestr, \"iu_version\")) {\n\n char *err;\n\n\n\n iu_version = strtoll(val, &err, 0);\n\n if (!*val || *err) {\n\n fprintf(stderr, \"bad numerical value %s\\n\", val);\n\n goto error;\n\n }\n\n cpu_def->iu_version = iu_version;\n\n#ifdef DEBUG_FEATURES\n\n fprintf(stderr, \"iu_version %\" PRIx64 \"\\n\", iu_version);\n\n#endif\n\n } else if (!strcmp(featurestr, \"fpu_version\")) {\n\n char *err;\n\n\n\n fpu_version = strtol(val, &err, 0);\n\n if (!*val || *err) {\n\n fprintf(stderr, \"bad numerical value %s\\n\", val);\n\n goto error;\n\n }\n\n cpu_def->fpu_version = fpu_version;\n\n#ifdef DEBUG_FEATURES\n\n fprintf(stderr, \"fpu_version %x\\n\", fpu_version);\n\n#endif\n\n } else if (!strcmp(featurestr, \"mmu_version\")) {\n\n char *err;\n\n\n\n mmu_version = strtol(val, &err, 0);\n\n if (!*val || *err) {\n\n fprintf(stderr, \"bad numerical value %s\\n\", val);\n\n goto error;\n\n }\n\n cpu_def->mmu_version = mmu_version;\n\n#ifdef DEBUG_FEATURES\n\n fprintf(stderr, \"mmu_version %x\\n\", mmu_version);\n\n#endif\n\n } else if (!strcmp(featurestr, \"nwindows\")) {\n\n char *err;\n\n\n\n nwindows = strtol(val, &err, 0);\n\n if (!*val || *err || nwindows > MAX_NWINDOWS ||\n\n nwindows < MIN_NWINDOWS) {\n\n fprintf(stderr, \"bad numerical value %s\\n\", val);\n\n goto error;\n\n }\n\n cpu_def->nwindows = nwindows;\n\n#ifdef DEBUG_FEATURES\n\n fprintf(stderr, \"nwindows %d\\n\", nwindows);\n\n#endif\n\n } else {\n\n fprintf(stderr, \"unrecognized feature %s\\n\", featurestr);\n\n goto error;\n\n }\n\n } else {\n\n fprintf(stderr, \"feature string `%s' not in format \"\n\n \"(+feature|-feature|feature=xyz)\\n\", featurestr);\n\n goto error;\n\n }\n\n featurestr = strtok(NULL, \",\");\n\n }\n\n cpu_def->features |= plus_features;\n\n cpu_def->features &= ~minus_features;\n\n#ifdef DEBUG_FEATURES\n\n print_features(stderr, fprintf, cpu_def->features, NULL);\n\n#endif\n\n free(s);\n\n return 0;\n\n\n\n error:\n\n free(s);\n\n return -1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "bfad67399bcca8c1afbbc93593d365044d92f7c6", + "length": 828 + }, + { + "index": 5239, + "code": "void tcp_connect(struct socket *inso)\n\n{\n\n Slirp *slirp = inso->slirp;\n\n struct socket *so;\n\n struct sockaddr_in addr;\n\n socklen_t addrlen = sizeof(struct sockaddr_in);\n\n struct tcpcb *tp;\n\n int s, opt;\n\n\n\n DEBUG_CALL(\"tcp_connect\");\n\n DEBUG_ARG(\"inso = %p\", inso);\n\n\n\n /*\n\n * If it's an SS_ACCEPTONCE socket, no need to socreate()\n\n * another socket, just use the accept() socket.\n\n */\n\n if (inso->so_state & SS_FACCEPTONCE) {\n\n /* FACCEPTONCE already have a tcpcb */\n\n so = inso;\n\n } else {\n\n so = socreate(slirp);\n\n if (so == NULL) {\n\n /* If it failed, get rid of the pending connection */\n\n closesocket(accept(inso->s, (struct sockaddr *)&addr, &addrlen));\n\n return;\n\n }\n\n if (tcp_attach(so) < 0) {\n\n free(so); /* NOT sofree */\n\n return;\n\n }\n\n so->so_lfamily = AF_INET;\n\n so->so_laddr = inso->so_laddr;\n\n so->so_lport = inso->so_lport;\n\n }\n\n\n\n tcp_mss(sototcpcb(so), 0);\n\n\n\n s = accept(inso->s, (struct sockaddr *)&addr, &addrlen);\n\n if (s < 0) {\n\n tcp_close(sototcpcb(so)); /* This will sofree() as well */\n\n return;\n\n }\n\n qemu_set_nonblock(s);\n\n socket_set_fast_reuse(s);\n\n opt = 1;\n\n qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));\n\n socket_set_nodelay(s);\n\n\n\n so->so_ffamily = AF_INET;\n\n so->so_fport = addr.sin_port;\n\n so->so_faddr = addr.sin_addr;\n\n /* Translate connections from localhost to the real hostname */\n\n if (so->so_faddr.s_addr == 0 ||\n\n (so->so_faddr.s_addr & loopback_mask) ==\n\n (loopback_addr.s_addr & loopback_mask)) {\n\n so->so_faddr = slirp->vhost_addr;\n\n }\n\n\n\n /* Close the accept() socket, set right state */\n\n if (inso->so_state & SS_FACCEPTONCE) {\n\n /* If we only accept once, close the accept() socket */\n\n closesocket(so->s);\n\n\n\n /* Don't select it yet, even though we have an FD */\n\n /* if it's not FACCEPTONCE, it's already NOFDREF */\n\n so->so_state = SS_NOFDREF;\n\n }\n\n so->s = s;\n\n so->so_state |= SS_INCOMING;\n\n\n\n so->so_iptos = tcp_tos(so);\n\n tp = sototcpcb(so);\n\n\n\n tcp_template(tp);\n\n\n\n tp->t_state = TCPS_SYN_SENT;\n\n tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;\n\n tp->iss = slirp->tcp_iss;\n\n slirp->tcp_iss += TCP_ISSINCR/2;\n\n tcp_sendseqinit(tp);\n\n tcp_output(tp);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "5379229a2708df3a1506113315214c3ce5325859", + "length": 708 + }, + { + "index": 23887, + "code": "static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,\n\n unsigned len)\n\n{\n\n OpenPICState *opp = opaque;\n\n IRQ_dst_t *dst;\n\n int idx;\n\n\n\n DPRINTF(\"%s: addr \" TARGET_FMT_plx \" <= %08x\\n\", __func__, addr, val);\n\n if (addr & 0xF)\n\n return;\n\n switch (addr) {\n\n case 0x00: /* Block Revision Register1 (BRR1) is Readonly */\n\n break;\n\n case 0x40:\n\n case 0x50:\n\n case 0x60:\n\n case 0x70:\n\n case 0x80:\n\n case 0x90:\n\n case 0xA0:\n\n case 0xB0:\n\n openpic_cpu_write_internal(opp, addr, val, get_current_cpu());\n\n break;\n\n case 0x1000: /* FREP */\n\n break;\n\n case 0x1020: /* GLBC */\n\n if (val & GLBC_RESET) {\n\n openpic_reset(&opp->busdev.qdev);\n\n }\n\n break;\n\n case 0x1080: /* VENI */\n\n break;\n\n case 0x1090: /* PINT */\n\n for (idx = 0; idx < opp->nb_cpus; idx++) {\n\n if ((val & (1 << idx)) && !(opp->pint & (1 << idx))) {\n\n DPRINTF(\"Raise OpenPIC RESET output for CPU %d\\n\", idx);\n\n dst = &opp->dst[idx];\n\n qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_RESET]);\n\n } else if (!(val & (1 << idx)) && (opp->pint & (1 << idx))) {\n\n DPRINTF(\"Lower OpenPIC RESET output for CPU %d\\n\", idx);\n\n dst = &opp->dst[idx];\n\n qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_RESET]);\n\n }\n\n }\n\n opp->pint = val;\n\n break;\n\n case 0x10A0: /* IPI_IPVP */\n\n case 0x10B0:\n\n case 0x10C0:\n\n case 0x10D0:\n\n {\n\n int idx;\n\n idx = (addr - 0x10A0) >> 4;\n\n write_IRQreg_ipvp(opp, opp->irq_ipi0 + idx, val);\n\n }\n\n break;\n\n case 0x10E0: /* SPVE */\n\n opp->spve = val & opp->vector_mask;\n\n break;\n\n default:\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "af7e9e74c6a62a5bcd911726a9e88d28b61490e0", + "length": 560 + }, + { + "index": 20671, + "code": "static void fdctrl_write_data (fdctrl_t *fdctrl, uint32_t value)\n\n{\n\n fdrive_t *cur_drv;\n\n int pos;\n\n\n\n /* Reset mode */\n\n if (!(fdctrl->dor & FD_DOR_nRESET)) {\n\n FLOPPY_DPRINTF(\"Floppy controller in RESET state !\\n\");\n\n return;\n\n }\n\n if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {\n\n FLOPPY_ERROR(\"controller not ready for writing\\n\");\n\n return;\n\n }\n\n fdctrl->dsr &= ~FD_DSR_PWRDOWN;\n\n /* Is it write command time ? */\n\n if (fdctrl->msr & FD_MSR_NONDMA) {\n\n /* FIFO data write */\n\n fdctrl->fifo[fdctrl->data_pos++] = value;\n\n if (fdctrl->data_pos % FD_SECTOR_LEN == (FD_SECTOR_LEN - 1) ||\n\n fdctrl->data_pos == fdctrl->data_len) {\n\n cur_drv = get_cur_drv(fdctrl);\n\n if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {\n\n FLOPPY_ERROR(\"writing sector %d\\n\", fd_sector(cur_drv));\n\n return;\n\n }\n\n if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {\n\n FLOPPY_DPRINTF(\"error seeking to next sector %d\\n\",\n\n fd_sector(cur_drv));\n\n return;\n\n }\n\n }\n\n /* Switch from transfer mode to status mode\n\n * then from status mode to command mode\n\n */\n\n if (fdctrl->data_pos == fdctrl->data_len)\n\n fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);\n\n return;\n\n }\n\n if (fdctrl->data_pos == 0) {\n\n /* Command */\n\n pos = command_to_handler[value & 0xff];\n\n FLOPPY_DPRINTF(\"%s command\\n\", handlers[pos].name);\n\n fdctrl->data_len = handlers[pos].parameters + 1;\n\n }\n\n\n\n FLOPPY_DPRINTF(\"%s: %02x\\n\", __func__, value);\n\n fdctrl->fifo[fdctrl->data_pos++] = value;\n\n if (fdctrl->data_pos == fdctrl->data_len) {\n\n /* We now have all parameters\n\n * and will be able to treat the command\n\n */\n\n if (fdctrl->data_state & FD_STATE_FORMAT) {\n\n fdctrl_format_sector(fdctrl);\n\n return;\n\n }\n\n\n\n pos = command_to_handler[fdctrl->fifo[0] & 0xff];\n\n FLOPPY_DPRINTF(\"treat %s command\\n\", handlers[pos].name);\n\n (*handlers[pos].handler)(fdctrl, handlers[pos].direction);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "b3bc154098f211db7014de151c79b4234ae5029b", + "length": 619 + }, + { + "index": 1748, + "code": "static int megasas_dcmd_cfg_read(MegasasState *s, MegasasCmd *cmd)\n\n{\n\n uint8_t data[4096];\n\n struct mfi_config_data *info;\n\n int num_pd_disks = 0, array_offset, ld_offset;\n\n BusChild *kid;\n\n\n\n if (cmd->iov_size > 4096) {\n\n return MFI_STAT_INVALID_PARAMETER;\n\n }\n\n\n\n QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {\n\n num_pd_disks++;\n\n }\n\n info = (struct mfi_config_data *)&data;\n\n /*\n\n * Array mapping:\n\n * - One array per SCSI device\n\n * - One logical drive per SCSI device\n\n * spanning the entire device\n\n */\n\n info->array_count = num_pd_disks;\n\n info->array_size = sizeof(struct mfi_array) * num_pd_disks;\n\n info->log_drv_count = num_pd_disks;\n\n info->log_drv_size = sizeof(struct mfi_ld_config) * num_pd_disks;\n\n info->spares_count = 0;\n\n info->spares_size = sizeof(struct mfi_spare);\n\n info->size = sizeof(struct mfi_config_data) + info->array_size +\n\n info->log_drv_size;\n\n if (info->size > 4096) {\n\n return MFI_STAT_INVALID_PARAMETER;\n\n }\n\n\n\n array_offset = sizeof(struct mfi_config_data);\n\n ld_offset = array_offset + sizeof(struct mfi_array) * num_pd_disks;\n\n\n\n QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {\n\n SCSIDevice *sdev = SCSI_DEVICE(kid->child);\n\n uint16_t sdev_id = ((sdev->id & 0xFF) << 8) | (sdev->lun & 0xFF);\n\n struct mfi_array *array;\n\n struct mfi_ld_config *ld;\n\n uint64_t pd_size;\n\n int i;\n\n\n\n array = (struct mfi_array *)(data + array_offset);\n\n blk_get_geometry(sdev->conf.blk, &pd_size);\n\n array->size = cpu_to_le64(pd_size);\n\n array->num_drives = 1;\n\n array->array_ref = cpu_to_le16(sdev_id);\n\n array->pd[0].ref.v.device_id = cpu_to_le16(sdev_id);\n\n array->pd[0].ref.v.seq_num = 0;\n\n array->pd[0].fw_state = MFI_PD_STATE_ONLINE;\n\n array->pd[0].encl.pd = 0xFF;\n\n array->pd[0].encl.slot = (sdev->id & 0xFF);\n\n for (i = 1; i < MFI_MAX_ROW_SIZE; i++) {\n\n array->pd[i].ref.v.device_id = 0xFFFF;\n\n array->pd[i].ref.v.seq_num = 0;\n\n array->pd[i].fw_state = MFI_PD_STATE_UNCONFIGURED_GOOD;\n\n array->pd[i].encl.pd = 0xFF;\n\n array->pd[i].encl.slot = 0xFF;\n\n }\n\n array_offset += sizeof(struct mfi_array);\n\n ld = (struct mfi_ld_config *)(data + ld_offset);\n\n memset(ld, 0, sizeof(struct mfi_ld_config));\n\n ld->properties.ld.v.target_id = sdev->id;\n\n ld->properties.default_cache_policy = MR_LD_CACHE_READ_AHEAD |\n\n MR_LD_CACHE_READ_ADAPTIVE;\n\n ld->properties.current_cache_policy = MR_LD_CACHE_READ_AHEAD |\n\n MR_LD_CACHE_READ_ADAPTIVE;\n\n ld->params.state = MFI_LD_STATE_OPTIMAL;\n\n ld->params.stripe_size = 3;\n\n ld->params.num_drives = 1;\n\n ld->params.span_depth = 1;\n\n ld->params.is_consistent = 1;\n\n ld->span[0].start_block = 0;\n\n ld->span[0].num_blocks = cpu_to_le64(pd_size);\n\n ld->span[0].array_ref = cpu_to_le16(sdev_id);\n\n ld_offset += sizeof(struct mfi_ld_config);\n\n }\n\n\n\n cmd->iov_size -= dma_buf_read((uint8_t *)data, info->size, &cmd->qsg);\n\n return MFI_STAT_OK;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "d37af740730dbbb93960cd318e040372d04d6dcf", + "length": 925 + }, + { + "index": 20540, + "code": "static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)\n\n{\n\n int ret = 0;\n\n\n\n /* apply the output bitstream filters, if any */\n\n if (ost->nb_bitstream_filters) {\n\n int idx;\n\n\n\n ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);\n\n if (ret < 0)\n\n goto finish;\n\n\n\n idx = 1;\n\n while (idx) {\n\n /* get a packet from the previous filter up the chain */\n\n ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);\n\n if (ret == AVERROR(EAGAIN)) {\n\n ret = 0;\n\n idx--;\n\n continue;\n\n } else if (ret < 0)\n\n goto finish;\n\n /* HACK! - aac_adtstoasc updates extradata after filtering the first frame when\n\n * the api states this shouldn't happen after init(). Propagate it here to the\n\n * muxer and to the next filters in the chain to workaround this.\n\n * TODO/FIXME - Make aac_adtstoasc use new packet side data instead of changing\n\n * par_out->extradata and adapt muxers accordingly to get rid of this. */\n\n if (!(ost->bsf_extradata_updated[idx - 1] & 1)) {\n\n ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out);\n\n if (ret < 0)\n\n goto finish;\n\n ost->bsf_extradata_updated[idx - 1] |= 1;\n\n }\n\n\n\n /* send it to the next filter down the chain or to the muxer */\n\n if (idx < ost->nb_bitstream_filters) {\n\n /* HACK/FIXME! - See above */\n\n if (!(ost->bsf_extradata_updated[idx] & 2)) {\n\n ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out);\n\n if (ret < 0)\n\n goto finish;\n\n ost->bsf_extradata_updated[idx] |= 2;\n\n }\n\n ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);\n\n if (ret < 0)\n\n goto finish;\n\n idx++;\n\n } else\n\n write_packet(of, pkt, ost);\n\n }\n\n } else\n\n write_packet(of, pkt, ost);\n\n\n\nfinish:\n\n if (ret < 0 && ret != AVERROR_EOF) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error applying bitstream filters to an output \"\n\n \"packet for stream #%d:%d.\\n\", ost->file_index, ost->index);\n\n if(exit_on_error)\n\n exit_program(1);\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "c4be288fdbe1993110f1abd28ea57587cb2bc221", + "length": 599 + }, + { + "index": 1445, + "code": "int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,\n\n AVCodecContext *codec, int size)\n\n{\n\n int id;\n\n\n\n if (size < 14)\n\n return AVERROR_INVALIDDATA;\n\n\n\n id = avio_rl16(pb);\n\n codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n codec->channels = avio_rl16(pb);\n\n codec->sample_rate = avio_rl32(pb);\n\n codec->bit_rate = avio_rl32(pb) * 8;\n\n codec->block_align = avio_rl16(pb);\n\n if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */\n\n codec->bits_per_coded_sample = 8;\n\n } else\n\n codec->bits_per_coded_sample = avio_rl16(pb);\n\n if (id == 0xFFFE) {\n\n codec->codec_tag = 0;\n\n } else {\n\n codec->codec_tag = id;\n\n codec->codec_id = ff_wav_codec_get_id(id,\n\n codec->bits_per_coded_sample);\n\n }\n\n if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */\n\n int cbSize = avio_rl16(pb); /* cbSize */\n\n size -= 18;\n\n cbSize = FFMIN(size, cbSize);\n\n if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */\n\n parse_waveformatex(pb, codec);\n\n cbSize -= 22;\n\n size -= 22;\n\n }\n\n codec->extradata_size = cbSize;\n\n if (cbSize > 0) {\n\n av_free(codec->extradata);\n\n codec->extradata = av_mallocz(codec->extradata_size +\n\n FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!codec->extradata)\n\n return AVERROR(ENOMEM);\n\n avio_read(pb, codec->extradata, codec->extradata_size);\n\n size -= cbSize;\n\n }\n\n\n\n /* It is possible for the chunk to contain garbage at the end */\n\n if (size > 0)\n\n avio_skip(pb, size);\n\n }\n\n if (codec->sample_rate <= 0) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Invalid sample rate: %d\\n\", codec->sample_rate);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {\n\n /* Channels and sample_rate values are those prior to applying SBR\n\n * and/or PS. */\n\n codec->channels = 0;\n\n codec->sample_rate = 0;\n\n }\n\n /* override bits_per_coded_sample for G.726 */\n\n if (codec->codec_id == AV_CODEC_ID_ADPCM_G726)\n\n codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f1bdc234370401c032cd85184e93c7c155eb6d62", + "length": 623 + }, + { + "index": 16445, + "code": "static int assign_intx(AssignedDevice *dev)\n\n{\n\n AssignedIRQType new_type;\n\n PCIINTxRoute intx_route;\n\n bool intx_host_msi;\n\n int r;\n\n\n\n /* Interrupt PIN 0 means don't use INTx */\n\n if (assigned_dev_pci_read_byte(&dev->dev, PCI_INTERRUPT_PIN) == 0) {\n\n pci_device_set_intx_routing_notifier(&dev->dev, NULL);\n\n return 0;\n\n }\n\n\n\n if (!check_irqchip_in_kernel()) {\n\n return -ENOTSUP;\n\n }\n\n\n\n pci_device_set_intx_routing_notifier(&dev->dev,\n\n assigned_dev_update_irq_routing);\n\n\n\n intx_route = pci_device_route_intx_to_irq(&dev->dev, dev->intpin);\n\n assert(intx_route.mode != PCI_INTX_INVERTED);\n\n\n\n if (!pci_intx_route_changed(&dev->intx_route, &intx_route)) {\n\n return 0;\n\n }\n\n\n\n switch (dev->assigned_irq_type) {\n\n case ASSIGNED_IRQ_INTX_HOST_INTX:\n\n case ASSIGNED_IRQ_INTX_HOST_MSI:\n\n intx_host_msi = dev->assigned_irq_type == ASSIGNED_IRQ_INTX_HOST_MSI;\n\n r = kvm_device_intx_deassign(kvm_state, dev->dev_id, intx_host_msi);\n\n break;\n\n case ASSIGNED_IRQ_MSI:\n\n r = kvm_device_msi_deassign(kvm_state, dev->dev_id);\n\n break;\n\n case ASSIGNED_IRQ_MSIX:\n\n r = kvm_device_msix_deassign(kvm_state, dev->dev_id);\n\n break;\n\n default:\n\n r = 0;\n\n break;\n\n }\n\n if (r) {\n\n perror(\"assign_intx: deassignment of previous interrupt failed\");\n\n }\n\n dev->assigned_irq_type = ASSIGNED_IRQ_NONE;\n\n\n\n if (intx_route.mode == PCI_INTX_DISABLED) {\n\n dev->intx_route = intx_route;\n\n return 0;\n\n }\n\n\n\nretry:\n\n if (dev->features & ASSIGNED_DEVICE_PREFER_MSI_MASK &&\n\n dev->cap.available & ASSIGNED_DEVICE_CAP_MSI) {\n\n intx_host_msi = true;\n\n new_type = ASSIGNED_IRQ_INTX_HOST_MSI;\n\n } else {\n\n intx_host_msi = false;\n\n new_type = ASSIGNED_IRQ_INTX_HOST_INTX;\n\n }\n\n\n\n r = kvm_device_intx_assign(kvm_state, dev->dev_id, intx_host_msi,\n\n intx_route.irq);\n\n if (r < 0) {\n\n if (r == -EIO && !(dev->features & ASSIGNED_DEVICE_PREFER_MSI_MASK) &&\n\n dev->cap.available & ASSIGNED_DEVICE_CAP_MSI) {\n\n /* Retry with host-side MSI. There might be an IRQ conflict and\n\n * either the kernel or the device doesn't support sharing. */\n\n error_report(\"Host-side INTx sharing not supported, \"\n\n \"using MSI instead\");\n\n error_printf(\"Some devices do not work properly in this mode.\\n\");\n\n dev->features |= ASSIGNED_DEVICE_PREFER_MSI_MASK;\n\n goto retry;\n\n }\n\n error_report(\"Failed to assign irq for \\\"%s\\\": %s\",\n\n dev->dev.qdev.id, strerror(-r));\n\n error_report(\"Perhaps you are assigning a device \"\n\n \"that shares an IRQ with another device?\");\n\n return r;\n\n }\n\n\n\n dev->intx_route = intx_route;\n\n dev->assigned_irq_type = new_type;\n\n return r;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "665f119fbad97c05c2603673ac6b2dcbf0d0e9e1", + "length": 748 + }, + { + "index": 8033, + "code": "static int vc9_decode_init(AVCodecContext *avctx)\n\n{\n\n VC9Context *v = avctx->priv_data;\n\n MpegEncContext *s = &v->s;\n\n GetBitContext gb;\n\n\n\n if (!avctx->extradata_size || !avctx->extradata) return -1;\n\n avctx->pix_fmt = PIX_FMT_YUV420P;\n\n v->s.avctx = avctx;\n\n\n\n if(ff_h263_decode_init(avctx) < 0)\n\n return -1;\n\n if (vc9_init_common(v) < 0) return -1;\n\n\n\n avctx->coded_width = avctx->width;\n\n avctx->coded_height = avctx->height;\n\n if (avctx->codec_id == CODEC_ID_WMV3)\n\n {\n\n int count = 0;\n\n\n\n // looks like WMV3 has a sequence header stored in the extradata\n\n // advanced sequence header may be before the first frame\n\n // the last byte of the extradata is a version number, 1 for the\n\n // samples we can decode\n\n\n\n init_get_bits(&gb, avctx->extradata, avctx->extradata_size);\n\n \n\n decode_sequence_header(avctx, &gb);\n\n\n\n count = avctx->extradata_size*8 - get_bits_count(&gb);\n\n if (count>0)\n\n {\n\n av_log(avctx, AV_LOG_INFO, \"Extra data: %i bits left, value: %X\\n\",\n\n count, get_bits(&gb, count));\n\n }\n\n else\n\n {\n\n av_log(avctx, AV_LOG_INFO, \"Read %i bits in overflow\\n\", -count);\n\n }\n\n }\n\n avctx->has_b_frames= !!(avctx->max_b_frames);\n\n\n\n s->mb_width = (avctx->coded_width+15)>>4;\n\n s->mb_height = (avctx->coded_height+15)>>4;\n\n\n\n /* Allocate mb bitplanes */\n\n if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n\n\n /* For predictors */\n\n v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4);\n\n if (!v->previous_line_cbpcy) return -1;\n\n\n\n#if HAS_ADVANCED_PROFILE\n\n if (v->profile > PROFILE_MAIN)\n\n {\n\n if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)\n\n return -1;\n\n }\n\n#endif\n\n\n\n return 0;\n\n }\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "7cc84d241ba6ef8e27e4d057176a4ad385ad3d59", + "length": 682 + }, + { + "index": 3878, + "code": "static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offset)\n\n{\n\n AVPacket pkt1, *pkt = &pkt1;\n\n AVStream *st;\n\n int read_size, i, ret;\n\n int64_t end_time;\n\n int64_t filesize, offset, duration;\n\n\n\n /* free previous packet */\n\n if (ic->cur_st && ic->cur_st->parser)\n\n av_free_packet(&ic->cur_pkt);\n\n ic->cur_st = NULL;\n\n\n\n /* flush packet queue */\n\n flush_packet_queue(ic);\n\n\n\n for(i=0;inb_streams;i++) {\n\n st = ic->streams[i];\n\n if (st->parser) {\n\n av_parser_close(st->parser);\n\n st->parser= NULL;\n\n }\n\n }\n\n\n\n /* we read the first packets to get the first PTS (not fully\n\n accurate, but it is enough now) */\n\n url_fseek(&ic->pb, 0, SEEK_SET);\n\n read_size = 0;\n\n for(;;) {\n\n if (read_size >= DURATION_MAX_READ_SIZE)\n\n break;\n\n /* if all info is available, we can stop */\n\n for(i = 0;i < ic->nb_streams; i++) {\n\n st = ic->streams[i];\n\n if (st->start_time == AV_NOPTS_VALUE)\n\n break;\n\n }\n\n if (i == ic->nb_streams)\n\n break;\n\n\n\n ret = av_read_packet(ic, pkt);\n\n if (ret != 0)\n\n break;\n\n read_size += pkt->size;\n\n st = ic->streams[pkt->stream_index];\n\n if (pkt->pts != AV_NOPTS_VALUE) {\n\n if (st->start_time == AV_NOPTS_VALUE)\n\n st->start_time = pkt->pts;\n\n }\n\n av_free_packet(pkt);\n\n }\n\n\n\n /* estimate the end time (duration) */\n\n /* XXX: may need to support wrapping */\n\n filesize = ic->file_size;\n\n offset = filesize - DURATION_MAX_READ_SIZE;\n\n if (offset < 0)\n\n offset = 0;\n\n\n\n url_fseek(&ic->pb, offset, SEEK_SET);\n\n read_size = 0;\n\n for(;;) {\n\n if (read_size >= DURATION_MAX_READ_SIZE)\n\n break;\n\n\n\n ret = av_read_packet(ic, pkt);\n\n if (ret != 0)\n\n break;\n\n read_size += pkt->size;\n\n st = ic->streams[pkt->stream_index];\n\n if (pkt->pts != AV_NOPTS_VALUE &&\n\n st->start_time != AV_NOPTS_VALUE) {\n\n end_time = pkt->pts;\n\n duration = end_time - st->start_time;\n\n if (duration > 0) {\n\n if (st->duration == AV_NOPTS_VALUE ||\n\n st->duration < duration)\n\n st->duration = duration;\n\n }\n\n }\n\n av_free_packet(pkt);\n\n }\n\n\n\n fill_all_stream_timings(ic);\n\n\n\n url_fseek(&ic->pb, old_offset, SEEK_SET);\n\n for(i=0; inb_streams; i++){\n\n st= ic->streams[i];\n\n st->cur_dts= st->first_dts;\n\n\n }\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "cc5297e871f2a30b62b972c6479ab1d4fdc14132", + "length": 680 + }, + { + "index": 19867, + "code": "static void test_visitor_in_intList(TestInputVisitorData *data,\n const void *unused)\n{\n /* Note: the visitor *sorts* ranges *unsigned* */\n int64_t expect1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 };\n int64_t expect2[] = { 32767, -32768, -32767 };\n int64_t expect3[] = { INT64_MAX, INT64_MIN };\n uint64_t expect4[] = { UINT64_MAX };\n Error *err = NULL;\n int64List *res = NULL;\n int64List *tail;\n Visitor *v;\n int64_t val;\n /* Valid lists */\n v = visitor_input_test_init(data, \"1,2,0,2-4,20,5-9,1-8\");\n check_ilist(v, expect1, ARRAY_SIZE(expect1));\n v = visitor_input_test_init(data, \"32767,-32768--32767\");\n check_ilist(v, expect2, ARRAY_SIZE(expect2));\n v = visitor_input_test_init(data,\n \"-9223372036854775808,9223372036854775807\");\n check_ilist(v, expect3, ARRAY_SIZE(expect3));\n v = visitor_input_test_init(data, \"18446744073709551615\");\n check_ulist(v, expect4, ARRAY_SIZE(expect4));\n /* Empty list is invalid (weird) */\n v = visitor_input_test_init(data, \"\");\n visit_type_int64List(v, NULL, &res, &err);\n error_free_or_abort(&err);\n /* Not a list */\n v = visitor_input_test_init(data, \"not an int list\");\n visit_type_int64List(v, NULL, &res, &err);\n error_free_or_abort(&err);\n g_assert(!res);\n /* Unvisited list tail */\n v = visitor_input_test_init(data, \"0,2-3\");\n /* Would be simpler if the visitor genuinely supported virtual walks */\n visit_type_int64(v, NULL, &tail->value, &error_abort);\n tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));\n g_assert(tail);\n visit_type_int64(v, NULL, &tail->value, &error_abort);\n g_assert_cmpint(tail->value, ==, 2);\n tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));\n g_assert(tail);\n visit_check_list(v, &err);\n error_free_or_abort(&err);\n}", + "label": 1, + "project": "qemu", + "commit_id": "a9416dc62c36079b93b4951c894a0b15e53bb38c", + "length": 578 + }, + { + "index": 20291, + "code": "static int sd_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n int ret, fd;\n\n uint32_t vid = 0;\n\n BDRVSheepdogState *s = bs->opaque;\n\n char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];\n\n uint32_t snapid;\n\n char *buf = NULL;\n\n QemuOpts *opts;\n\n Error *local_err = NULL;\n\n const char *filename;\n\n\n\n s->bs = bs;\n\n s->aio_context = bdrv_get_aio_context(bs);\n\n\n\n opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);\n\n qemu_opts_absorb_qdict(opts, options, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n filename = qemu_opt_get(opts, \"filename\");\n\n\n\n QLIST_INIT(&s->inflight_aio_head);\n\n QLIST_INIT(&s->failed_aio_head);\n\n QLIST_INIT(&s->inflight_aiocb_head);\n\n s->fd = -1;\n\n\n\n memset(vdi, 0, sizeof(vdi));\n\n memset(tag, 0, sizeof(tag));\n\n\n\n if (strstr(filename, \"://\")) {\n\n ret = sd_parse_uri(s, filename, vdi, &snapid, tag);\n\n } else {\n\n ret = parse_vdiname(s, filename, vdi, &snapid, tag);\n\n }\n\n if (ret < 0) {\n\n error_setg(errp, \"Can't parse filename\");\n\n goto out;\n\n }\n\n s->fd = get_sheep_fd(s, errp);\n\n if (s->fd < 0) {\n\n ret = s->fd;\n\n goto out;\n\n }\n\n\n\n ret = find_vdi_name(s, vdi, snapid, tag, &vid, true, errp);\n\n if (ret) {\n\n goto out;\n\n }\n\n\n\n /*\n\n * QEMU block layer emulates writethrough cache as 'writeback + flush', so\n\n * we always set SD_FLAG_CMD_CACHE (writeback cache) as default.\n\n */\n\n s->cache_flags = SD_FLAG_CMD_CACHE;\n\n if (flags & BDRV_O_NOCACHE) {\n\n s->cache_flags = SD_FLAG_CMD_DIRECT;\n\n }\n\n s->discard_supported = true;\n\n\n\n if (snapid || tag[0] != '\\0') {\n\n DPRINTF(\"%\" PRIx32 \" snapshot inode was open.\\n\", vid);\n\n s->is_snapshot = true;\n\n }\n\n\n\n fd = connect_to_sdog(s, errp);\n\n if (fd < 0) {\n\n ret = fd;\n\n goto out;\n\n }\n\n\n\n buf = g_malloc(SD_INODE_SIZE);\n\n ret = read_object(fd, s->aio_context, buf, vid_to_vdi_oid(vid),\n\n 0, SD_INODE_SIZE, 0, s->cache_flags);\n\n\n\n closesocket(fd);\n\n\n\n if (ret) {\n\n error_setg(errp, \"Can't read snapshot inode\");\n\n goto out;\n\n }\n\n\n\n memcpy(&s->inode, buf, sizeof(s->inode));\n\n s->min_dirty_data_idx = UINT32_MAX;\n\n s->max_dirty_data_idx = 0;\n\n\n\n bs->total_sectors = s->inode.vdi_size / BDRV_SECTOR_SIZE;\n\n pstrcpy(s->name, sizeof(s->name), vdi);\n\n qemu_co_mutex_init(&s->lock);\n\n qemu_co_queue_init(&s->overwrapping_queue);\n\n qemu_opts_del(opts);\n\n g_free(buf);\n\n return 0;\n\nout:\n\n aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, NULL, NULL, NULL);\n\n if (s->fd >= 0) {\n\n closesocket(s->fd);\n\n }\n\n qemu_opts_del(opts);\n\n g_free(buf);\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "498f21405a286f718a0767c791b7d2db19f4e5bd", + "length": 853 + }, + { + "index": 24222, + "code": "static int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num,\n\n int remaining_sectors, QEMUIOVector *qiov)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int index_in_cluster, n1;\n\n int ret;\n\n int cur_nr_sectors; /* number of sectors in current iteration */\n\n uint64_t cluster_offset = 0;\n\n uint64_t bytes_done = 0;\n\n QEMUIOVector hd_qiov;\n\n uint8_t *cluster_data = NULL;\n\n\n\n qemu_iovec_init(&hd_qiov, qiov->niov);\n\n\n\n qemu_co_mutex_lock(&s->lock);\n\n\n\n while (remaining_sectors != 0) {\n\n\n\n /* prepare next request */\n\n cur_nr_sectors = remaining_sectors;\n\n if (s->crypt_method) {\n\n cur_nr_sectors = MIN(cur_nr_sectors,\n\n QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors);\n\n }\n\n\n\n ret = qcow2_get_cluster_offset(bs, sector_num << 9,\n\n &cur_nr_sectors, &cluster_offset);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n index_in_cluster = sector_num & (s->cluster_sectors - 1);\n\n\n\n qemu_iovec_reset(&hd_qiov);\n\n qemu_iovec_copy(&hd_qiov, qiov, bytes_done,\n\n cur_nr_sectors * 512);\n\n\n\n if (!cluster_offset) {\n\n\n\n if (bs->backing_hd) {\n\n /* read from the base image */\n\n n1 = qcow2_backing_read1(bs->backing_hd, &hd_qiov,\n\n sector_num, cur_nr_sectors);\n\n if (n1 > 0) {\n\n BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);\n\n qemu_co_mutex_unlock(&s->lock);\n\n ret = bdrv_co_readv(bs->backing_hd, sector_num,\n\n n1, &hd_qiov);\n\n qemu_co_mutex_lock(&s->lock);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n }\n\n } else {\n\n /* Note: in this case, no need to wait */\n\n qemu_iovec_memset(&hd_qiov, 0, 512 * cur_nr_sectors);\n\n }\n\n } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {\n\n /* add AIO support for compressed blocks ? */\n\n ret = qcow2_decompress_cluster(bs, cluster_offset);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n qemu_iovec_from_buffer(&hd_qiov,\n\n s->cluster_cache + index_in_cluster * 512,\n\n 512 * cur_nr_sectors);\n\n } else {\n\n if ((cluster_offset & 511) != 0) {\n\n ret = -EIO;\n\n goto fail;\n\n }\n\n\n\n if (s->crypt_method) {\n\n /*\n\n * For encrypted images, read everything into a temporary\n\n * contiguous buffer on which the AES functions can work.\n\n */\n\n if (!cluster_data) {\n\n cluster_data =\n\n g_malloc0(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size);\n\n }\n\n\n\n assert(cur_nr_sectors <=\n\n QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors);\n\n qemu_iovec_reset(&hd_qiov);\n\n qemu_iovec_add(&hd_qiov, cluster_data,\n\n 512 * cur_nr_sectors);\n\n }\n\n\n\n BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);\n\n qemu_co_mutex_unlock(&s->lock);\n\n ret = bdrv_co_readv(bs->file,\n\n (cluster_offset >> 9) + index_in_cluster,\n\n cur_nr_sectors, &hd_qiov);\n\n qemu_co_mutex_lock(&s->lock);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n if (s->crypt_method) {\n\n qcow2_encrypt_sectors(s, sector_num, cluster_data,\n\n cluster_data, cur_nr_sectors, 0, &s->aes_decrypt_key);\n\n qemu_iovec_reset(&hd_qiov);\n\n qemu_iovec_copy(&hd_qiov, qiov, bytes_done,\n\n cur_nr_sectors * 512);\n\n qemu_iovec_from_buffer(&hd_qiov, cluster_data,\n\n 512 * cur_nr_sectors);\n\n }\n\n }\n\n\n\n remaining_sectors -= cur_nr_sectors;\n\n sector_num += cur_nr_sectors;\n\n bytes_done += cur_nr_sectors * 512;\n\n }\n\n ret = 0;\n\n\n\nfail:\n\n qemu_co_mutex_unlock(&s->lock);\n\n\n\n qemu_iovec_destroy(&hd_qiov);\n\n\n\n\n return ret;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "ab0997e0afdcb272fd04784a280b2df46b0c759f", + "length": 1001 + }, + { + "index": 9131, + "code": "static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n SIFFContext *c = s->priv_data;\n\n\n\n if (c->has_video) {\n\n unsigned int size;\n\n if (c->cur_frame >= c->frames)\n\n return AVERROR_EOF;\n\n if (c->curstrm == -1) {\n\n c->pktsize = avio_rl32(s->pb) - 4;\n\n c->flags = avio_rl16(s->pb);\n\n c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0;\n\n if (c->gmcsize)\n\n avio_read(s->pb, c->gmc, c->gmcsize);\n\n c->sndsize = (c->flags & VB_HAS_AUDIO) ? avio_rl32(s->pb) : 0;\n\n c->curstrm = !!(c->flags & VB_HAS_AUDIO);\n\n }\n\n\n\n if (!c->curstrm) {\n\n size = c->pktsize - c->sndsize - c->gmcsize - 2;\n\n size = ffio_limit(s->pb, size);\n\n if (size < 0 || c->pktsize < c->sndsize)\n\n return AVERROR_INVALIDDATA;\n\n if (av_new_packet(pkt, size + c->gmcsize + 2) < 0)\n\n return AVERROR(ENOMEM);\n\n AV_WL16(pkt->data, c->flags);\n\n if (c->gmcsize)\n\n memcpy(pkt->data + 2, c->gmc, c->gmcsize);\n\n if (avio_read(s->pb, pkt->data + 2 + c->gmcsize, size) != size) {\n\n av_free_packet(pkt);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n pkt->stream_index = 0;\n\n c->curstrm = -1;\n\n } else {\n\n int pktsize = av_get_packet(s->pb, pkt, c->sndsize - 4);\n\n if (pktsize < 0)\n\n return AVERROR(EIO);\n\n pkt->stream_index = 1;\n\n pkt->duration = pktsize;\n\n c->curstrm = 0;\n\n }\n\n if (!c->cur_frame || c->curstrm)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n if (c->curstrm == -1)\n\n c->cur_frame++;\n\n } else {\n\n int pktsize = av_get_packet(s->pb, pkt, c->block_align);\n\n if (!pktsize)\n\n return AVERROR_EOF;\n\n if (pktsize <= 0)\n\n return AVERROR(EIO);\n\n pkt->duration = pktsize;\n\n }\n\n return pkt->size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e71dce5769b2282824da7cfd6f7e4ce0d1985876", + "length": 596 + }, + { + "index": 26189, + "code": "static int mov_open_dref(MOVContext *c, AVIOContext **pb, const char *src, MOVDref *ref,\n\n AVIOInterruptCB *int_cb)\n\n{\n\n AVOpenCallback open_func = c->fc->open_cb;\n\n\n\n if (!open_func)\n\n open_func = ffio_open2_wrapper;\n\n\n\n /* try relative path, we do not try the absolute because it can leak information about our\n\n system to an attacker */\n\n if (ref->nlvl_to > 0 && ref->nlvl_from > 0 && ref->path[0] != '/') {\n\n char filename[1025];\n\n const char *src_path;\n\n int i, l;\n\n\n\n /* find a source dir */\n\n src_path = strrchr(src, '/');\n\n if (src_path)\n\n src_path++;\n\n else\n\n src_path = src;\n\n\n\n /* find a next level down to target */\n\n for (i = 0, l = strlen(ref->path) - 1; l >= 0; l--)\n\n if (ref->path[l] == '/') {\n\n if (i == ref->nlvl_to - 1)\n\n break;\n\n else\n\n i++;\n\n }\n\n\n\n /* compose filename if next level down to target was found */\n\n if (i == ref->nlvl_to - 1 && src_path - src < sizeof(filename)) {\n\n memcpy(filename, src, src_path - src);\n\n filename[src_path - src] = 0;\n\n\n\n for (i = 1; i < ref->nlvl_from; i++)\n\n av_strlcat(filename, \"../\", sizeof(filename));\n\n\n\n av_strlcat(filename, ref->path + l + 1, sizeof(filename));\n\n if (!c->use_absolute_path && !c->fc->open_cb)\n\n if(strstr(ref->path + l + 1, \"..\") || ref->nlvl_from > 1)\n\n return AVERROR(ENOENT);\n\n\n\n if (strlen(filename) + 1 == sizeof(filename))\n\n return AVERROR(ENOENT);\n\n if (!open_func(c->fc, pb, filename, AVIO_FLAG_READ, int_cb, NULL))\n\n return 0;\n\n }\n\n } else if (c->use_absolute_path) {\n\n av_log(c->fc, AV_LOG_WARNING, \"Using absolute path on user request, \"\n\n \"this is a possible security issue\\n\");\n\n if (!open_func(c->fc, pb, ref->path, AVIO_FLAG_READ, int_cb, NULL))\n\n return 0;\n\n } else if (c->fc->open_cb) {\n\n if (!open_func(c->fc, pb, ref->path, AVIO_FLAG_READ, int_cb, NULL))\n\n return 0;\n\n } else {\n\n av_log(c->fc, AV_LOG_ERROR,\n\n \"Absolute path %s not tried for security reasons, \"\n\n \"set demuxer option use_absolute_path to allow absolute paths\\n\",\n\n ref->path);\n\n }\n\n\n\n return AVERROR(ENOENT);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "c9c7263e5820c957598643216c42be9b1c4f2d2b", + "length": 641 + }, + { + "index": 22803, + "code": "static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)\n\n{\n\n AVIContext *avi = s->priv_data;\n\n AVStream *st;\n\n int i, index;\n\n int64_t pos, pos_min;\n\n AVIStream *ast;\n\n\n\n if (!avi->index_loaded) {\n\n /* we only load the index on demand */\n\n avi_load_index(s);\n\n avi->index_loaded = 1;\n\n }\n\n assert(stream_index>= 0);\n\n\n\n st = s->streams[stream_index];\n\n ast= st->priv_data;\n\n index= av_index_search_timestamp(st, timestamp * FFMAX(ast->sample_size, 1), flags);\n\n if(index<0)\n\n return -1;\n\n\n\n /* find the position */\n\n pos = st->index_entries[index].pos;\n\n timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);\n\n\n\n// av_log(s, AV_LOG_DEBUG, \"XX %\"PRId64\" %d %\"PRId64\"\\n\", timestamp, index, st->index_entries[index].timestamp);\n\n\n\n if (CONFIG_DV_DEMUXER && avi->dv_demux) {\n\n /* One and only one real stream for DV in AVI, and it has video */\n\n /* offsets. Calling with other stream indexes should have failed */\n\n /* the av_index_search_timestamp call above. */\n\n assert(stream_index == 0);\n\n\n\n /* Feed the DV video stream version of the timestamp to the */\n\n /* DV demux so it can synthesize correct timestamps. */\n\n dv_offset_reset(avi->dv_demux, timestamp);\n\n\n\n avio_seek(s->pb, pos, SEEK_SET);\n\n avi->stream_index= -1;\n\n return 0;\n\n }\n\n\n\n pos_min= pos;\n\n for(i = 0; i < s->nb_streams; i++) {\n\n AVStream *st2 = s->streams[i];\n\n AVIStream *ast2 = st2->priv_data;\n\n\n\n ast2->packet_size=\n\n ast2->remaining= 0;\n\n\n\n if (ast2->sub_ctx) {\n\n seek_subtitle(st, st2, timestamp);\n\n continue;\n\n }\n\n\n\n if (st2->nb_index_entries <= 0)\n\n continue;\n\n\n\n// assert(st2->codec->block_align);\n\n assert((int64_t)st2->time_base.num*ast2->rate == (int64_t)st2->time_base.den*ast2->scale);\n\n index = av_index_search_timestamp(\n\n st2,\n\n av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),\n\n flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));\n\n if(index<0)\n\n index=0;\n\n ast2->seek_pos= st2->index_entries[index].pos;\n\n pos_min= FFMIN(pos_min,ast2->seek_pos);\n\n }\n\n for(i = 0; i < s->nb_streams; i++) {\n\n AVStream *st2 = s->streams[i];\n\n AVIStream *ast2 = st2->priv_data;\n\n\n\n if (ast2->sub_ctx || st2->nb_index_entries <= 0)\n\n continue;\n\n\n\n index = av_index_search_timestamp(\n\n st2,\n\n av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),\n\n flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));\n\n if(index<0)\n\n index=0;\n\n while(!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)\n\n index--;\n\n ast2->frame_offset = st2->index_entries[index].timestamp;\n\n }\n\n\n\n /* do the seek */\n\n avio_seek(s->pb, pos_min, SEEK_SET);\n\n avi->stream_index= -1;\n\n avi->dts_max= INT_MIN;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f9e083a156f19094cb6fcd134c1ca4ca899a1a6d", + "length": 898 + }, + { + "index": 18357, + "code": "static void decode_scaling_matrices(H264Context *h, SPS *sps,\n\n PPS *pps, int is_sps,\n\n uint8_t(*scaling_matrix4)[16],\n\n uint8_t(*scaling_matrix8)[64])\n\n{\n\n int fallback_sps = !is_sps && sps->scaling_matrix_present;\n\n const uint8_t *fallback[4] = {\n\n fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0],\n\n fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1],\n\n fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0],\n\n fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1]\n\n };\n\n if (get_bits1(&h->gb)) {\n\n sps->scaling_matrix_present |= is_sps;\n\n decode_scaling_list(h, scaling_matrix4[0], 16, default_scaling4[0], fallback[0]); // Intra, Y\n\n decode_scaling_list(h, scaling_matrix4[1], 16, default_scaling4[0], scaling_matrix4[0]); // Intra, Cr\n\n decode_scaling_list(h, scaling_matrix4[2], 16, default_scaling4[0], scaling_matrix4[1]); // Intra, Cb\n\n decode_scaling_list(h, scaling_matrix4[3], 16, default_scaling4[1], fallback[1]); // Inter, Y\n\n decode_scaling_list(h, scaling_matrix4[4], 16, default_scaling4[1], scaling_matrix4[3]); // Inter, Cr\n\n decode_scaling_list(h, scaling_matrix4[5], 16, default_scaling4[1], scaling_matrix4[4]); // Inter, Cb\n\n if (is_sps || pps->transform_8x8_mode) {\n\n decode_scaling_list(h, scaling_matrix8[0], 64, default_scaling8[0], fallback[2]); // Intra, Y\n\n if (sps->chroma_format_idc == 3) {\n\n decode_scaling_list(h, scaling_matrix8[1], 64, default_scaling8[0], scaling_matrix8[0]); // Intra, Cr\n\n decode_scaling_list(h, scaling_matrix8[2], 64, default_scaling8[0], scaling_matrix8[1]); // Intra, Cb\n\n }\n\n decode_scaling_list(h, scaling_matrix8[3], 64, default_scaling8[1], fallback[3]); // Inter, Y\n\n if (sps->chroma_format_idc == 3) {\n\n decode_scaling_list(h, scaling_matrix8[4], 64, default_scaling8[1], scaling_matrix8[3]); // Inter, Cr\n\n decode_scaling_list(h, scaling_matrix8[5], 64, default_scaling8[1], scaling_matrix8[4]); // Inter, Cb\n\n }\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3176217c60ca7828712985092d9102d331ea4f3d", + "length": 639 + }, + { + "index": 9459, + "code": "void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)\n\n{\n\n CPUSH4State *env = cs->env_ptr;\n\n DisasContext ctx;\n\n target_ulong pc_start;\n\n int num_insns;\n\n int max_insns;\n\n\n\n pc_start = tb->pc;\n\n ctx.pc = pc_start;\n\n ctx.tbflags = (uint32_t)tb->flags;\n\n ctx.envflags = tb->flags & TB_FLAG_ENVFLAGS_MASK;\n\n ctx.bstate = BS_NONE;\n\n ctx.memidx = (ctx.tbflags & (1u << SR_MD)) == 0 ? 1 : 0;\n\n /* We don't know if the delayed pc came from a dynamic or static branch,\n\n so assume it is a dynamic branch. */\n\n ctx.delayed_pc = -1; /* use delayed pc from env pointer */\n\n ctx.tb = tb;\n\n ctx.singlestep_enabled = cs->singlestep_enabled;\n\n ctx.features = env->features;\n\n ctx.has_movcal = (ctx.tbflags & TB_FLAG_PENDING_MOVCA);\n\n ctx.gbank = ((ctx.tbflags & (1 << SR_MD)) &&\n\n (ctx.tbflags & (1 << SR_RB))) * 0x10;\n\n ctx.fbank = ctx.tbflags & FPSCR_FR ? 0x10 : 0;\n\n\n\n max_insns = tb->cflags & CF_COUNT_MASK;\n\n if (max_insns == 0) {\n\n max_insns = CF_COUNT_MASK;\n\n }\n\n max_insns = MIN(max_insns, TCG_MAX_INSNS);\n\n\n\n /* Since the ISA is fixed-width, we can bound by the number\n\n of instructions remaining on the page. */\n\n num_insns = -(ctx.pc | TARGET_PAGE_MASK) / 2;\n\n max_insns = MIN(max_insns, num_insns);\n\n\n\n /* Single stepping means just that. */\n\n if (ctx.singlestep_enabled || singlestep) {\n\n max_insns = 1;\n\n }\n\n\n\n gen_tb_start(tb);\n\n num_insns = 0;\n\n\n\n#ifdef CONFIG_USER_ONLY\n\n if (ctx.tbflags & GUSA_MASK) {\n\n num_insns = decode_gusa(&ctx, env, &max_insns);\n\n }\n\n#endif\n\n\n\n while (ctx.bstate == BS_NONE\n\n && num_insns < max_insns\n\n && !tcg_op_buf_full()) {\n\n tcg_gen_insn_start(ctx.pc, ctx.envflags);\n\n num_insns++;\n\n\n\n if (unlikely(cpu_breakpoint_test(cs, ctx.pc, BP_ANY))) {\n\n /* We have hit a breakpoint - make sure PC is up-to-date */\n\n gen_save_cpu_state(&ctx, true);\n\n gen_helper_debug(cpu_env);\n\n ctx.bstate = BS_EXCP;\n\n /* The address covered by the breakpoint must be included in\n\n [tb->pc, tb->pc + tb->size) in order to for it to be\n\n properly cleared -- thus we increment the PC here so that\n\n the logic setting tb->size below does the right thing. */\n\n ctx.pc += 2;\n\n break;\n\n }\n\n\n\n if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {\n\n gen_io_start();\n\n }\n\n\n\n ctx.opcode = cpu_lduw_code(env, ctx.pc);\n\n\tdecode_opc(&ctx);\n\n\tctx.pc += 2;\n\n }\n\n if (tb->cflags & CF_LAST_IO) {\n\n gen_io_end();\n\n }\n\n\n\n if (ctx.tbflags & GUSA_EXCLUSIVE) {\n\n /* Ending the region of exclusivity. Clear the bits. */\n\n ctx.envflags &= ~GUSA_MASK;\n\n }\n\n\n\n if (cs->singlestep_enabled) {\n\n gen_save_cpu_state(&ctx, true);\n\n gen_helper_debug(cpu_env);\n\n } else {\n\n\tswitch (ctx.bstate) {\n\n case BS_STOP:\n\n gen_save_cpu_state(&ctx, true);\n\n tcg_gen_exit_tb(0);\n\n break;\n\n case BS_NONE:\n\n gen_save_cpu_state(&ctx, false);\n\n gen_goto_tb(&ctx, 0, ctx.pc);\n\n break;\n\n case BS_EXCP:\n\n /* fall through */\n\n case BS_BRANCH:\n\n default:\n\n break;\n\n\t}\n\n }\n\n\n\n gen_tb_end(tb, num_insns);\n\n\n\n tb->size = ctx.pc - pc_start;\n\n tb->icount = num_insns;\n\n\n\n#ifdef DEBUG_DISAS\n\n if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)\n\n && qemu_log_in_addr_range(pc_start)) {\n\n qemu_log_lock();\n\n\tqemu_log(\"IN:\\n\");\t/* , lookup_symbol(pc_start)); */\n\n log_target_disas(cs, pc_start, ctx.pc - pc_start, 0);\n\n\tqemu_log(\"\\n\");\n\n qemu_log_unlock();\n\n }\n\n#endif\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "c5a49c63fa26e8825ad101dfe86339ae4c216539", + "length": 1018 + }, + { + "index": 3061, + "code": "static void tcg_target_qemu_prologue(TCGContext *s)\n\n{\n\n int frame_size, i;\n\n\n\n /* Allocate space for the fixed frame marker. */\n\n frame_size = -TCG_TARGET_CALL_STACK_OFFSET;\n\n frame_size += TCG_TARGET_STATIC_CALL_ARGS_SIZE;\n\n\n\n /* Allocate space for the saved registers. */\n\n frame_size += ARRAY_SIZE(tcg_target_callee_save_regs) * 4;\n\n\n\n /* Align the allocated space. */\n\n frame_size = ((frame_size + TCG_TARGET_STACK_ALIGN - 1)\n\n & -TCG_TARGET_STACK_ALIGN);\n\n\n\n /* The return address is stored in the caller's frame. */\n\n tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_RP, TCG_REG_SP, -20);\n\n\n\n /* Allocate stack frame, saving the first register at the same time. */\n\n tcg_out_ldst(s, tcg_target_callee_save_regs[0],\n\n TCG_REG_SP, frame_size, INSN_STWM);\n\n\n\n /* Save all callee saved registers. */\n\n for (i = 1; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {\n\n tcg_out_st(s, TCG_TYPE_PTR, tcg_target_callee_save_regs[i],\n\n TCG_REG_SP, -frame_size + i * 4);\n\n }\n\n\n\n#ifdef CONFIG_USE_GUEST_BASE\n\n if (GUEST_BASE != 0) {\n\n tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, GUEST_BASE);\n\n tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);\n\n }\n\n#endif\n\n\n\n /* Jump to TB, and adjust R18 to be the return address. */\n\n tcg_out32(s, INSN_BLE_SR4 | INSN_R2(TCG_REG_R26));\n\n tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R18, TCG_REG_R31);\n\n\n\n /* Restore callee saved registers. */\n\n tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_RP, TCG_REG_SP, -frame_size - 20);\n\n for (i = 1; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {\n\n tcg_out_ld(s, TCG_TYPE_PTR, tcg_target_callee_save_regs[i],\n\n TCG_REG_SP, -frame_size + i * 4);\n\n }\n\n\n\n /* Deallocate stack frame and return. */\n\n tcg_out32(s, INSN_BV | INSN_R2(TCG_REG_RP));\n\n tcg_out_ldst(s, tcg_target_callee_save_regs[0],\n\n TCG_REG_SP, -frame_size, INSN_LDWM);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "cea5f9a28faa528b6b1b117c9ab2d8828f473fef", + "length": 583 + }, + { + "index": 387, + "code": "int ff_h2645_extract_rbsp(const uint8_t *src, int length,\n\n H2645NAL *nal)\n\n{\n\n int i, si, di;\n\n uint8_t *dst;\n\n\n\n nal->skipped_bytes = 0;\n\n#define STARTCODE_TEST \\\n\n if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \\\n\n if (src[i + 2] != 3 && src[i + 2] != 0) { \\\n\n /* startcode, so we must be past the end */ \\\n\n length = i; \\\n\n } \\\n\n break; \\\n\n }\n\n#if HAVE_FAST_UNALIGNED\n\n#define FIND_FIRST_ZERO \\\n\n if (i > 0 && !src[i]) \\\n\n i--; \\\n\n while (src[i]) \\\n\n i++\n\n#if HAVE_FAST_64BIT\n\n for (i = 0; i + 1 < length; i += 9) {\n\n if (!((~AV_RN64A(src + i) &\n\n (AV_RN64A(src + i) - 0x0100010001000101ULL)) &\n\n 0x8000800080008080ULL))\n\n continue;\n\n FIND_FIRST_ZERO;\n\n STARTCODE_TEST;\n\n i -= 7;\n\n }\n\n#else\n\n for (i = 0; i + 1 < length; i += 5) {\n\n if (!((~AV_RN32A(src + i) &\n\n (AV_RN32A(src + i) - 0x01000101U)) &\n\n 0x80008080U))\n\n continue;\n\n FIND_FIRST_ZERO;\n\n STARTCODE_TEST;\n\n i -= 3;\n\n }\n\n#endif /* HAVE_FAST_64BIT */\n\n#else\n\n for (i = 0; i + 1 < length; i += 2) {\n\n if (src[i])\n\n continue;\n\n if (i > 0 && src[i - 1] == 0)\n\n i--;\n\n STARTCODE_TEST;\n\n }\n\n#endif /* HAVE_FAST_UNALIGNED */\n\n\n\n if (i >= length - 1) { // no escaped 0\n\n nal->data =\n\n nal->raw_data = src;\n\n nal->size =\n\n nal->raw_size = length;\n\n return length;\n\n }\n\n\n\n av_fast_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size,\n\n length + AV_INPUT_BUFFER_PADDING_SIZE);\n\n if (!nal->rbsp_buffer)\n\n return AVERROR(ENOMEM);\n\n\n\n dst = nal->rbsp_buffer;\n\n\n\n memcpy(dst, src, i);\n\n si = di = i;\n\n while (si + 2 < length) {\n\n // remove escapes (very rare 1:2^22)\n\n if (src[si + 2] > 3) {\n\n dst[di++] = src[si++];\n\n dst[di++] = src[si++];\n\n } else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {\n\n if (src[si + 2] == 3) { // escape\n\n dst[di++] = 0;\n\n dst[di++] = 0;\n\n si += 3;\n\n\n\n if (nal->skipped_bytes_pos) {\n\n nal->skipped_bytes++;\n\n if (nal->skipped_bytes_pos_size < nal->skipped_bytes) {\n\n nal->skipped_bytes_pos_size *= 2;\n\n av_assert0(nal->skipped_bytes_pos_size >= nal->skipped_bytes);\n\n av_reallocp_array(&nal->skipped_bytes_pos,\n\n nal->skipped_bytes_pos_size,\n\n sizeof(*nal->skipped_bytes_pos));\n\n if (!nal->skipped_bytes_pos) {\n\n nal->skipped_bytes_pos_size = 0;\n\n return AVERROR(ENOMEM);\n\n }\n\n }\n\n if (nal->skipped_bytes_pos)\n\n nal->skipped_bytes_pos[nal->skipped_bytes-1] = di - 1;\n\n }\n\n continue;\n\n } else // next start code\n\n goto nsc;\n\n }\n\n\n\n dst[di++] = src[si++];\n\n }\n\n while (si < length)\n\n dst[di++] = src[si++];\n\n\n\nnsc:\n\n memset(dst + di, 0, AV_INPUT_BUFFER_PADDING_SIZE);\n\n\n\n nal->data = dst;\n\n nal->size = di;\n\n nal->raw_data = src;\n\n nal->raw_size = si;\n\n return si;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "cc13bc8c4f0f4afa30d0b94c3f3a369ccd2aaf0b", + "length": 992 + }, + { + "index": 18593, + "code": "static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,\n\n const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc,\n\n uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW)\n\n{\n\n#if COMPILE_TEMPLATE_MMX\n\n if(!(c->flags & SWS_BITEXACT)) {\n\n if (c->flags & SWS_ACCURATE_RND) {\n\n if (uDest) {\n\n YSCALEYUV2YV12X_ACCURATE( \"0\", CHR_MMX_FILTER_OFFSET, uDest, chrDstW)\n\n YSCALEYUV2YV12X_ACCURATE(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW)\n\n }\n\n if (CONFIG_SWSCALE_ALPHA && aDest) {\n\n YSCALEYUV2YV12X_ACCURATE( \"0\", ALP_MMX_FILTER_OFFSET, aDest, dstW)\n\n }\n\n\n\n YSCALEYUV2YV12X_ACCURATE(\"0\", LUM_MMX_FILTER_OFFSET, dest, dstW)\n\n } else {\n\n if (uDest) {\n\n YSCALEYUV2YV12X( \"0\", CHR_MMX_FILTER_OFFSET, uDest, chrDstW)\n\n YSCALEYUV2YV12X(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW)\n\n }\n\n if (CONFIG_SWSCALE_ALPHA && aDest) {\n\n YSCALEYUV2YV12X( \"0\", ALP_MMX_FILTER_OFFSET, aDest, dstW)\n\n }\n\n\n\n YSCALEYUV2YV12X(\"0\", LUM_MMX_FILTER_OFFSET, dest, dstW)\n\n }\n\n return;\n\n }\n\n#endif\n\n#if COMPILE_TEMPLATE_ALTIVEC\n\n yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,\n\n chrFilter, chrSrc, chrFilterSize,\n\n dest, uDest, vDest, dstW, chrDstW);\n\n#else //COMPILE_TEMPLATE_ALTIVEC\n\n yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,\n\n chrFilter, chrSrc, chrFilterSize,\n\n alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW);\n\n#endif //!COMPILE_TEMPLATE_ALTIVEC\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d1adad3cca407f493c3637e20ecd4f7124e69212", + "length": 570 + }, + { + "index": 18498, + "code": "static int skeleton_header(AVFormatContext *s, int idx)\n\n{\n\n struct ogg *ogg = s->priv_data;\n\n struct ogg_stream *os = ogg->streams + idx;\n\n AVStream *st = s->streams[idx];\n\n uint8_t *buf = os->buf + os->pstart;\n\n int version_major, version_minor;\n\n int64_t start_num, start_den, start_granule;\n\n int target_idx, start_time;\n\n\n\n strcpy(st->codec->codec_name, \"skeleton\");\n\n st->codec->codec_type = AVMEDIA_TYPE_DATA;\n\n\n\n if (os->psize < 8)\n\n return -1;\n\n\n\n if (!strncmp(buf, \"fishead\", 8)) {\n\n if (os->psize < 64)\n\n return -1;\n\n\n\n version_major = AV_RL16(buf+8);\n\n version_minor = AV_RL16(buf+10);\n\n\n\n if (version_major != 3 && version_major != 4) {\n\n av_log(s, AV_LOG_WARNING, \"Unknown skeleton version %d.%d\\n\",\n\n version_major, version_minor);\n\n return -1;\n\n }\n\n\n\n // This is the overall start time. We use it for the start time of\n\n // of the skeleton stream since if left unset lavf assumes 0,\n\n // which we don't want since skeleton is timeless\n\n // FIXME: the real meaning of this field is \"start playback at\n\n // this time which can be in the middle of a packet\n\n start_num = AV_RL64(buf+12);\n\n start_den = AV_RL64(buf+20);\n\n\n\n if (start_den) {\n\n int base_den;\n\n av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);\n\n avpriv_set_pts_info(st, 64, 1, base_den);\n\n os->lastpts =\n\n st->start_time = start_time;\n\n }\n\n } else if (!strncmp(buf, \"fisbone\", 8)) {\n\n if (os->psize < 52)\n\n return -1;\n\n\n\n target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));\n\n start_granule = AV_RL64(buf+36);\n\n if (target_idx >= 0 && start_granule != -1) {\n\n ogg->streams[target_idx].lastpts =\n\n s->streams[target_idx]->start_time = ogg_gptopts(s, target_idx, start_granule, NULL);\n\n }\n\n }\n\n\n\n return 1;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f927c5b753f2ec1f037ad38cb55b4407dd7a9d79", + "length": 546 + }, + { + "index": 1428, + "code": "void ff_fix_long_p_mvs(MpegEncContext * s)\n\n{\n\n const int f_code= s->f_code;\n\n int y;\n\n UINT8 * fcode_tab= s->fcode_tab;\n\n\n\n /* clip / convert to intra 16x16 type MVs */\n\n for(y=0; ymb_height; y++){\n\n int x;\n\n int xy= (y+1)* (s->mb_width+2)+1;\n\n int i= y*s->mb_width;\n\n for(x=0; xmb_width; x++){\n\n if(s->mb_type[i]&MB_TYPE_INTER){\n\n if( fcode_tab[s->p_mv_table[xy][0] + MAX_MV] > f_code\n\n || fcode_tab[s->p_mv_table[xy][0] + MAX_MV] == 0\n\n || fcode_tab[s->p_mv_table[xy][1] + MAX_MV] > f_code\n\n || fcode_tab[s->p_mv_table[xy][1] + MAX_MV] == 0 ){\n\n s->mb_type[i] &= ~MB_TYPE_INTER;\n\n s->mb_type[i] |= MB_TYPE_INTRA;\n\n s->p_mv_table[xy][0] = 0;\n\n s->p_mv_table[xy][1] = 0;\n\n }\n\n }\n\n xy++;\n\n i++;\n\n }\n\n }\n\n\n\n if(s->flags&CODEC_FLAG_4MV){\n\n const int wrap= 2+ s->mb_width*2;\n\n\n\n /* clip / convert to intra 8x8 type MVs */\n\n for(y=0; ymb_height; y++){\n\n int xy= (y*2 + 1)*wrap + 1;\n\n int i= y*s->mb_width;\n\n int x;\n\n\n\n for(x=0; xmb_width; x++){\n\n if(s->mb_type[i]&MB_TYPE_INTER4V){\n\n int block;\n\n for(block=0; block<4; block++){\n\n int off= (block& 1) + (block>>1)*wrap;\n\n int mx= s->motion_val[ xy + off ][0];\n\n int my= s->motion_val[ xy + off ][1];\n\n\n\n if( fcode_tab[mx + MAX_MV] > f_code\n\n || fcode_tab[mx + MAX_MV] == 0\n\n || fcode_tab[my + MAX_MV] > f_code\n\n || fcode_tab[my + MAX_MV] == 0 ){\n\n s->mb_type[i] &= ~MB_TYPE_INTER4V;\n\n s->mb_type[i] |= MB_TYPE_INTRA;\n\n }\n\n }\n\n xy+=2;\n\n i++;\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "0d21a84605bad4e75dacb8196e5859902ed36f01", + "length": 597 + }, + { + "index": 22841, + "code": "void qmp_drive_mirror(const char *device, const char *target,\n\n bool has_format, const char *format,\n\n enum MirrorSyncMode sync,\n\n bool has_mode, enum NewImageMode mode,\n\n bool has_speed, int64_t speed, Error **errp)\n\n{\n\n BlockDriverInfo bdi;\n\n BlockDriverState *bs;\n\n BlockDriverState *source, *target_bs;\n\n BlockDriver *proto_drv;\n\n BlockDriver *drv = NULL;\n\n Error *local_err = NULL;\n\n int flags;\n\n uint64_t size;\n\n int ret;\n\n\n\n if (!has_speed) {\n\n speed = 0;\n\n }\n\n if (!has_mode) {\n\n mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;\n\n }\n\n\n\n bs = bdrv_find(device);\n\n if (!bs) {\n\n error_set(errp, QERR_DEVICE_NOT_FOUND, device);\n\n return;\n\n }\n\n\n\n if (!bdrv_is_inserted(bs)) {\n\n error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);\n\n return;\n\n }\n\n\n\n if (!has_format) {\n\n format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;\n\n }\n\n if (format) {\n\n drv = bdrv_find_format(format);\n\n if (!drv) {\n\n error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);\n\n return;\n\n }\n\n }\n\n\n\n if (bdrv_in_use(bs)) {\n\n error_set(errp, QERR_DEVICE_IN_USE, device);\n\n return;\n\n }\n\n\n\n flags = bs->open_flags | BDRV_O_RDWR;\n\n source = bs->backing_hd;\n\n if (!source && sync == MIRROR_SYNC_MODE_TOP) {\n\n sync = MIRROR_SYNC_MODE_FULL;\n\n }\n\n\n\n proto_drv = bdrv_find_protocol(target);\n\n if (!proto_drv) {\n\n error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);\n\n return;\n\n }\n\n\n\n if (sync == MIRROR_SYNC_MODE_FULL && mode != NEW_IMAGE_MODE_EXISTING) {\n\n /* create new image w/o backing file */\n\n assert(format && drv);\n\n bdrv_get_geometry(bs, &size);\n\n size *= 512;\n\n ret = bdrv_img_create(target, format,\n\n NULL, NULL, NULL, size, flags);\n\n } else {\n\n switch (mode) {\n\n case NEW_IMAGE_MODE_EXISTING:\n\n ret = 0;\n\n break;\n\n case NEW_IMAGE_MODE_ABSOLUTE_PATHS:\n\n /* create new image with backing file */\n\n ret = bdrv_img_create(target, format,\n\n source->filename,\n\n source->drv->format_name,\n\n NULL, -1, flags);\n\n break;\n\n default:\n\n abort();\n\n }\n\n }\n\n\n\n if (ret) {\n\n error_set(errp, QERR_OPEN_FILE_FAILED, target);\n\n return;\n\n }\n\n\n\n target_bs = bdrv_new(\"\");\n\n ret = bdrv_open(target_bs, target, flags | BDRV_O_NO_BACKING, drv);\n\n\n\n if (ret < 0) {\n\n bdrv_delete(target_bs);\n\n error_set(errp, QERR_OPEN_FILE_FAILED, target);\n\n return;\n\n }\n\n\n\n /* We need a backing file if we will copy parts of a cluster. */\n\n if (bdrv_get_info(target_bs, &bdi) >= 0 && bdi.cluster_size != 0 &&\n\n bdi.cluster_size >= BDRV_SECTORS_PER_DIRTY_CHUNK * 512) {\n\n ret = bdrv_open_backing_file(target_bs);\n\n if (ret < 0) {\n\n bdrv_delete(target_bs);\n\n error_set(errp, QERR_OPEN_FILE_FAILED, target);\n\n return;\n\n }\n\n }\n\n\n\n mirror_start(bs, target_bs, speed, sync, block_job_cb, bs, &local_err);\n\n if (local_err != NULL) {\n\n bdrv_delete(target_bs);\n\n error_propagate(errp, local_err);\n\n return;\n\n }\n\n\n\n /* Grab a reference so hotplug does not delete the BlockDriverState from\n\n * underneath us.\n\n */\n\n drive_get_ref(drive_get_by_blockdev(bs));\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "b952b5589a36114e06201c0d2e82c293dbad2b1f", + "length": 863 + }, + { + "index": 20858, + "code": "static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf)\n\n{\n\n FrameBuffer *buf = av_mallocz(sizeof(*buf));\n\n int i, ret;\n\n const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;\n\n int h_chroma_shift, v_chroma_shift;\n\n int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1\n\n int w = s->width, h = s->height;\n\n\n\n if (!buf)\n\n return AVERROR(ENOMEM);\n\n\n\n if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {\n\n w += 2*edge;\n\n h += 2*edge;\n\n }\n\n\n\n avcodec_align_dimensions(s, &w, &h);\n\n if ((ret = av_image_alloc(buf->base, buf->linesize, w, h,\n\n s->pix_fmt, 32)) < 0) {\n\n av_freep(&buf);\n\n return ret;\n\n }\n\n /* XXX this shouldn't be needed, but some tests break without this line\n\n * those decoders are buggy and need to be fixed.\n\n * the following tests fail:\n\n * bethsoft-vid, cdgraphics, ansi, aasc, fraps-v1, qtrle-1bit\n\n */\n\n memset(buf->base[0], 128, ret);\n\n\n\n avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);\n\n for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {\n\n const int h_shift = i==0 ? 0 : h_chroma_shift;\n\n const int v_shift = i==0 ? 0 : v_chroma_shift;\n\n if (s->flags & CODEC_FLAG_EMU_EDGE)\n\n buf->data[i] = buf->base[i];\n\n else\n\n buf->data[i] = buf->base[i] +\n\n FFALIGN((buf->linesize[i]*edge >> v_shift) +\n\n (pixel_size*edge >> h_shift), 32);\n\n }\n\n buf->w = s->width;\n\n buf->h = s->height;\n\n buf->pix_fmt = s->pix_fmt;\n\n buf->ist = ist;\n\n\n\n *pbuf = buf;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "60991ad6ae61e131085891c37e8e517b5014ce21", + "length": 515 + }, + { + "index": 37, + "code": "int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,\n\n AVCodecContext *codec, int size, int big_endian)\n\n{\n\n int id;\n\n uint64_t bitrate;\n\n\n\n if (size < 14) {\n\n avpriv_request_sample(codec, \"wav header size < 14\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n if (!big_endian) {\n\n id = avio_rl16(pb);\n\n codec->channels = avio_rl16(pb);\n\n codec->sample_rate = avio_rl32(pb);\n\n bitrate = avio_rl32(pb) * 8;\n\n codec->block_align = avio_rl16(pb);\n\n } else {\n\n id = avio_rb16(pb);\n\n codec->channels = avio_rb16(pb);\n\n codec->sample_rate = avio_rb32(pb);\n\n bitrate = avio_rb32(pb) * 8;\n\n codec->block_align = avio_rb16(pb);\n\n }\n\n if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */\n\n codec->bits_per_coded_sample = 8;\n\n } else {\n\n if (!big_endian) {\n\n codec->bits_per_coded_sample = avio_rl16(pb);\n\n } else {\n\n codec->bits_per_coded_sample = avio_rb16(pb);\n\n }\n\n }\n\n if (id == 0xFFFE) {\n\n codec->codec_tag = 0;\n\n } else {\n\n codec->codec_tag = id;\n\n codec->codec_id = ff_wav_codec_get_id(id,\n\n codec->bits_per_coded_sample);\n\n }\n\n if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */\n\n int cbSize = avio_rl16(pb); /* cbSize */\n\n if (big_endian) {\n\n avpriv_report_missing_feature(codec, \"WAVEFORMATEX support for RIFX files\\n\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n size -= 18;\n\n cbSize = FFMIN(size, cbSize);\n\n if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */\n\n parse_waveformatex(pb, codec);\n\n cbSize -= 22;\n\n size -= 22;\n\n }\n\n if (cbSize > 0) {\n\n av_freep(&codec->extradata);\n\n if (ff_get_extradata(codec, pb, cbSize) < 0)\n\n return AVERROR(ENOMEM);\n\n size -= cbSize;\n\n }\n\n\n\n /* It is possible for the chunk to contain garbage at the end */\n\n if (size > 0)\n\n avio_skip(pb, size);\n\n }\n\n\n\n if (bitrate > INT_MAX) {\n\n if (s->error_recognition & AV_EF_EXPLODE) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"The bitrate %\"PRIu64\" is too large.\\n\",\n\n bitrate);\n\n return AVERROR_INVALIDDATA;\n\n } else {\n\n av_log(s, AV_LOG_WARNING,\n\n \"The bitrate %\"PRIu64\" is too large, resetting to 0.\",\n\n bitrate);\n\n codec->bit_rate = 0;\n\n }\n\n } else {\n\n codec->bit_rate = bitrate;\n\n }\n\n\n\n if (codec->sample_rate <= 0) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Invalid sample rate: %d\\n\", codec->sample_rate);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {\n\n /* Channels and sample_rate values are those prior to applying SBR\n\n * and/or PS. */\n\n codec->channels = 0;\n\n codec->sample_rate = 0;\n\n }\n\n /* override bits_per_coded_sample for G.726 */\n\n if (codec->codec_id == AV_CODEC_ID_ADPCM_G726 && codec->sample_rate)\n\n codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "839d6bc192f7ef94343872ff039799501af38855", + "length": 880 + }, + { + "index": 12095, + "code": "static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)\n\n{\n\n int i = 0;\n\n unsigned int ave_mean;\n\n s->transient[ch] = get_bits1(&s->gb);\n\n if (s->transient[ch]) {\n\n s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));\n\n if (s->transient_pos[ch])\n\n s->transient[ch] = 0;\n\n s->channel[ch].transient_counter =\n\n FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);\n\n } else if (s->channel[ch].transient_counter)\n\n s->transient[ch] = 1;\n\n\n\n if (s->seekable_tile) {\n\n ave_mean = get_bits(&s->gb, s->bits_per_sample);\n\n s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);\n\n }\n\n\n\n if (s->seekable_tile) {\n\n if (s->do_inter_ch_decorr)\n\n s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample + 1);\n\n else\n\n s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample);\n\n i++;\n\n }\n\n for (; i < tile_size; i++) {\n\n int quo = 0, rem, rem_bits, residue;\n\n while(get_bits1(&s->gb)) {\n\n quo++;\n\n if (get_bits_left(&s->gb) <= 0)\n\n return -1;\n\n }\n\n if (quo >= 32)\n\n quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);\n\n\n\n ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);\n\n if (ave_mean <= 1)\n\n residue = quo;\n\n else {\n\n rem_bits = av_ceil_log2(ave_mean);\n\n rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0;\n\n residue = (quo << rem_bits) + rem;\n\n }\n\n\n\n s->ave_sum[ch] = residue + s->ave_sum[ch] -\n\n (s->ave_sum[ch] >> s->movave_scaling);\n\n\n\n if (residue & 1)\n\n residue = -(residue >> 1) - 1;\n\n else\n\n residue = residue >> 1;\n\n s->channel_residues[ch][i] = residue;\n\n }\n\n\n\n return 0;\n\n\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6a99310fce49f51773ab7d8ffa4f4748bbf58db9", + "length": 575 + }, + { + "index": 1980, + "code": "static int alsa_run_in (HWVoiceIn *hw)\n\n{\n\n ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;\n\n int hwshift = hw->info.shift;\n\n int i;\n\n int live = audio_pcm_hw_get_live_in (hw);\n\n int dead = hw->samples - live;\n\n int decr;\n\n struct {\n\n int add;\n\n int len;\n\n } bufs[2] = {\n\n { hw->wpos, 0 },\n\n { 0, 0 }\n\n };\n\n snd_pcm_sframes_t avail;\n\n snd_pcm_uframes_t read_samples = 0;\n\n\n\n if (!dead) {\n\n return 0;\n\n }\n\n\n\n avail = alsa_get_avail (alsa->handle);\n\n if (avail < 0) {\n\n dolog (\"Could not get number of captured frames\\n\");\n\n return 0;\n\n }\n\n\n\n if (!avail && (snd_pcm_state (alsa->handle) == SND_PCM_STATE_PREPARED)) {\n\n avail = hw->samples;\n\n }\n\n\n\n decr = audio_MIN (dead, avail);\n\n if (!decr) {\n\n return 0;\n\n }\n\n\n\n if (hw->wpos + decr > hw->samples) {\n\n bufs[0].len = (hw->samples - hw->wpos);\n\n bufs[1].len = (decr - (hw->samples - hw->wpos));\n\n }\n\n else {\n\n bufs[0].len = decr;\n\n }\n\n\n\n for (i = 0; i < 2; ++i) {\n\n void *src;\n\n st_sample_t *dst;\n\n snd_pcm_sframes_t nread;\n\n snd_pcm_uframes_t len;\n\n\n\n len = bufs[i].len;\n\n\n\n src = advance (alsa->pcm_buf, bufs[i].add << hwshift);\n\n dst = hw->conv_buf + bufs[i].add;\n\n\n\n while (len) {\n\n nread = snd_pcm_readi (alsa->handle, src, len);\n\n\n\n if (nread <= 0) {\n\n switch (nread) {\n\n case 0:\n\n if (conf.verbose) {\n\n dolog (\"Failed to read %ld frames (read zero)\\n\", len);\n\n }\n\n goto exit;\n\n\n\n case -EPIPE:\n\n if (alsa_recover (alsa->handle)) {\n\n alsa_logerr (nread, \"Failed to read %ld frames\\n\", len);\n\n goto exit;\n\n }\n\n if (conf.verbose) {\n\n dolog (\"Recovering from capture xrun\\n\");\n\n }\n\n continue;\n\n\n\n case -EAGAIN:\n\n goto exit;\n\n\n\n default:\n\n alsa_logerr (\n\n nread,\n\n \"Failed to read %ld frames from %p\\n\",\n\n len,\n\n src\n\n );\n\n goto exit;\n\n }\n\n }\n\n\n\n hw->conv (dst, src, nread, &nominal_volume);\n\n\n\n src = advance (src, nread << hwshift);\n\n dst += nread;\n\n\n\n read_samples += nread;\n\n len -= nread;\n\n }\n\n }\n\n\n\n exit:\n\n hw->wpos = (hw->wpos + read_samples) % hw->samples;\n\n return read_samples;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "1ea879e5580f63414693655fcf0328559cdce138", + "length": 683 + }, + { + "index": 23191, + "code": "int hmp_pcie_aer_inject_error(Monitor *mon,\n\n const QDict *qdict, QObject **ret_data)\n\n{\n\n const char *id = qdict_get_str(qdict, \"id\");\n\n const char *error_name;\n\n uint32_t error_status;\n\n bool correctable;\n\n PCIDevice *dev;\n\n PCIEAERErr err;\n\n int ret;\n\n\n\n ret = pci_qdev_find_device(id, &dev);\n\n if (ret < 0) {\n\n monitor_printf(mon,\n\n \"id or pci device path is invalid or device not \"\n\n \"found. %s\\n\", id);\n\n return ret;\n\n }\n\n if (!pci_is_express(dev)) {\n\n monitor_printf(mon, \"the device doesn't support pci express. %s\\n\",\n\n id);\n\n return -ENOSYS;\n\n }\n\n\n\n error_name = qdict_get_str(qdict, \"error_status\");\n\n if (pcie_aer_parse_error_string(error_name, &error_status, &correctable)) {\n\n char *e = NULL;\n\n error_status = strtoul(error_name, &e, 0);\n\n correctable = qdict_get_try_bool(qdict, \"correctable\", 0);\n\n if (!e || *e != '\\0') {\n\n monitor_printf(mon, \"invalid error status value. \\\"%s\\\"\",\n\n error_name);\n\n return -EINVAL;\n\n }\n\n }\n\n err.status = error_status;\n\n err.source_id = (pci_bus_num(dev->bus) << 8) | dev->devfn;\n\n\n\n err.flags = 0;\n\n if (correctable) {\n\n err.flags |= PCIE_AER_ERR_IS_CORRECTABLE;\n\n }\n\n if (qdict_get_try_bool(qdict, \"advisory_non_fatal\", 0)) {\n\n err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY;\n\n }\n\n if (qdict_haskey(qdict, \"header0\")) {\n\n err.flags |= PCIE_AER_ERR_HEADER_VALID;\n\n }\n\n if (qdict_haskey(qdict, \"prefix0\")) {\n\n err.flags |= PCIE_AER_ERR_TLP_PREFIX_PRESENT;\n\n }\n\n\n\n err.header[0] = qdict_get_try_int(qdict, \"header0\", 0);\n\n err.header[1] = qdict_get_try_int(qdict, \"header1\", 0);\n\n err.header[2] = qdict_get_try_int(qdict, \"header2\", 0);\n\n err.header[3] = qdict_get_try_int(qdict, \"header3\", 0);\n\n\n\n err.prefix[0] = qdict_get_try_int(qdict, \"prefix0\", 0);\n\n err.prefix[1] = qdict_get_try_int(qdict, \"prefix1\", 0);\n\n err.prefix[2] = qdict_get_try_int(qdict, \"prefix2\", 0);\n\n err.prefix[3] = qdict_get_try_int(qdict, \"prefix3\", 0);\n\n\n\n ret = pcie_aer_inject_error(dev, &err);\n\n *ret_data = qobject_from_jsonf(\"{'id': %s, \"\n\n \"'root_bus': %s, 'bus': %d, 'devfn': %d, \"\n\n \"'ret': %d}\",\n\n id, pci_root_bus_path(dev),\n\n pci_bus_num(dev->bus), dev->devfn,\n\n ret);\n\n assert(*ret_data);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "04e00c92ef75629a241ebc50537f75de0867928d", + "length": 733 + }, + { + "index": 4094, + "code": "static void svq3_add_idct_c(uint8_t *dst, int16_t *block,\n\n int stride, int qp, int dc)\n\n{\n\n const int qmul = svq3_dequant_coeff[qp];\n\n int i;\n\n\n\n if (dc) {\n\n dc = 13 * 13 * (dc == 1 ? 1538U* block[0]\n\n : qmul * (block[0] >> 3) / 2);\n\n block[0] = 0;\n\n }\n\n\n\n for (i = 0; i < 4; i++) {\n\n const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);\n\n const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);\n\n const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];\n\n const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];\n\n\n\n block[0 + 4 * i] = z0 + z3;\n\n block[1 + 4 * i] = z1 + z2;\n\n block[2 + 4 * i] = z1 - z2;\n\n block[3 + 4 * i] = z0 - z3;\n\n }\n\n\n\n for (i = 0; i < 4; i++) {\n\n const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);\n\n const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);\n\n const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];\n\n const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];\n\n const int rr = (dc + 0x80000);\n\n\n\n dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));\n\n dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));\n\n dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));\n\n dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));\n\n }\n\n\n\n memset(block, 0, 16 * sizeof(int16_t));\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "2c933c51687db958d8045d25ed87848342e869f6", + "length": 667 + }, + { + "index": 26381, + "code": "void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment, uint8_t *ref)\n\n{\n\n VP56RangeCoder *c = &s->c;\n\n\n\n if (s->segmentation.update_map)\n\n *segment = vp8_rac_get_tree(c, vp8_segmentid_tree, s->prob->segmentid);\n\n else\n\n *segment = ref ? *ref : *segment;\n\n s->segment = *segment;\n\n\n\n mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;\n\n\n\n if (s->keyframe) {\n\n mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);\n\n\n\n if (mb->mode == MODE_I4x4) {\n\n decode_intra4x4_modes(s, c, mb_x, 1);\n\n } else {\n\n const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;\n\n AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);\n\n AV_WN32A(s->intra4x4_pred_mode_left, modes);\n\n }\n\n\n\n s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra);\n\n mb->ref_frame = VP56_FRAME_CURRENT;\n\n } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {\n\n // inter MB, 16.2\n\n if (vp56_rac_get_prob_branchy(c, s->prob->last))\n\n mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ?\n\n VP56_FRAME_GOLDEN2 /* altref */ : VP56_FRAME_GOLDEN;\n\n else\n\n mb->ref_frame = VP56_FRAME_PREVIOUS;\n\n s->ref_count[mb->ref_frame-1]++;\n\n\n\n // motion vectors, 16.3\n\n decode_mvs(s, mb, mb_x, mb_y);\n\n } else {\n\n // intra MB, 16.1\n\n mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);\n\n\n\n if (mb->mode == MODE_I4x4)\n\n decode_intra4x4_modes(s, c, mb_x, 0);\n\n\n\n s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, s->prob->pred8x8c);\n\n mb->ref_frame = VP56_FRAME_CURRENT;\n\n mb->partitioning = VP8_SPLITMVMODE_NONE;\n\n AV_ZERO32(&mb->bmv[0]);\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "30011bf20109eef1a0f9ee949b19f9998ad88663", + "length": 640 + }, + { + "index": 22474, + "code": "e1000e_process_tx_desc(E1000ECore *core,\n\n struct e1000e_tx *tx,\n\n struct e1000_tx_desc *dp,\n\n int queue_index)\n\n{\n\n uint32_t txd_lower = le32_to_cpu(dp->lower.data);\n\n uint32_t dtype = txd_lower & (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D);\n\n unsigned int split_size = txd_lower & 0xffff;\n\n uint64_t addr;\n\n struct e1000_context_desc *xp = (struct e1000_context_desc *)dp;\n\n bool eop = txd_lower & E1000_TXD_CMD_EOP;\n\n\n\n if (dtype == E1000_TXD_CMD_DEXT) { /* context descriptor */\n\n e1000x_read_tx_ctx_descr(xp, &tx->props);\n\n e1000e_process_snap_option(core, le32_to_cpu(xp->cmd_and_length));\n\n return;\n\n } else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) {\n\n /* data descriptor */\n\n tx->props.sum_needed = le32_to_cpu(dp->upper.data) >> 8;\n\n tx->props.cptse = (txd_lower & E1000_TXD_CMD_TSE) ? 1 : 0;\n\n e1000e_process_ts_option(core, dp);\n\n } else {\n\n /* legacy descriptor */\n\n e1000e_process_ts_option(core, dp);\n\n tx->props.cptse = 0;\n\n }\n\n\n\n addr = le64_to_cpu(dp->buffer_addr);\n\n\n\n if (!tx->skip_cp) {\n\n if (!net_tx_pkt_add_raw_fragment(tx->tx_pkt, addr, split_size)) {\n\n tx->skip_cp = true;\n\n }\n\n }\n\n\n\n if (eop) {\n\n if (!tx->skip_cp && net_tx_pkt_parse(tx->tx_pkt)) {\n\n if (e1000x_vlan_enabled(core->mac) &&\n\n e1000x_is_vlan_txd(txd_lower)) {\n\n net_tx_pkt_setup_vlan_header_ex(tx->tx_pkt,\n\n le16_to_cpu(dp->upper.fields.special), core->vet);\n\n }\n\n if (e1000e_tx_pkt_send(core, tx, queue_index)) {\n\n e1000e_on_tx_done_update_stats(core, tx->tx_pkt);\n\n }\n\n }\n\n\n\n tx->skip_cp = false;\n\n net_tx_pkt_reset(tx->tx_pkt);\n\n\n\n tx->props.sum_needed = 0;\n\n tx->props.cptse = 0;\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "7d08c73e7bdc39b10e5f2f5acdce700f17ffe962", + "length": 551 + }, + { + "index": 2519, + "code": "int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)\n\n{\n\n ram_addr_t addr;\n\n uint64_t bytes_transferred_last;\n\n double bwidth = 0;\n\n uint64_t expected_time = 0;\n\n\n\n if (stage < 0) {\n\n cpu_physical_memory_set_dirty_tracking(0);\n\n return 0;\n\n }\n\n\n\n if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {\n\n qemu_file_set_error(f, -EINVAL);\n\n return 0;\n\n }\n\n\n\n if (stage == 1) {\n\n RAMBlock *block;\n\n bytes_transferred = 0;\n\n last_block = NULL;\n\n last_offset = 0;\n\n sort_ram_list();\n\n\n\n /* Make sure all dirty bits are set */\n\n QLIST_FOREACH(block, &ram_list.blocks, next) {\n\n for (addr = block->offset; addr < block->offset + block->length;\n\n addr += TARGET_PAGE_SIZE) {\n\n if (!cpu_physical_memory_get_dirty(addr,\n\n MIGRATION_DIRTY_FLAG)) {\n\n cpu_physical_memory_set_dirty(addr);\n\n }\n\n }\n\n }\n\n\n\n /* Enable dirty memory tracking */\n\n cpu_physical_memory_set_dirty_tracking(1);\n\n\n\n qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);\n\n\n\n QLIST_FOREACH(block, &ram_list.blocks, next) {\n\n qemu_put_byte(f, strlen(block->idstr));\n\n qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));\n\n qemu_put_be64(f, block->length);\n\n }\n\n }\n\n\n\n bytes_transferred_last = bytes_transferred;\n\n bwidth = qemu_get_clock_ns(rt_clock);\n\n\n\n while (!qemu_file_rate_limit(f)) {\n\n int bytes_sent;\n\n\n\n bytes_sent = ram_save_block(f);\n\n bytes_transferred += bytes_sent;\n\n if (bytes_sent == 0) { /* no more blocks */\n\n break;\n\n }\n\n }\n\n\n\n bwidth = qemu_get_clock_ns(rt_clock) - bwidth;\n\n bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;\n\n\n\n /* if we haven't transferred anything this round, force expected_time to a\n\n * a very high value, but without crashing */\n\n if (bwidth == 0) {\n\n bwidth = 0.000001;\n\n }\n\n\n\n /* try transferring iterative blocks of memory */\n\n if (stage == 3) {\n\n int bytes_sent;\n\n\n\n /* flush all remaining blocks regardless of rate limiting */\n\n while ((bytes_sent = ram_save_block(f)) != 0) {\n\n bytes_transferred += bytes_sent;\n\n }\n\n cpu_physical_memory_set_dirty_tracking(0);\n\n }\n\n\n\n qemu_put_be64(f, RAM_SAVE_FLAG_EOS);\n\n\n\n expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;\n\n\n\n return (stage == 2) && (expected_time <= migrate_max_downtime());\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "2975725f6b3d634dbe924ea9d9f4d86b8a5b217d", + "length": 624 + }, + { + "index": 2321, + "code": "static void exynos4210_gic_init(Object *obj)\n\n{\n\n DeviceState *dev = DEVICE(obj);\n\n Exynos4210GicState *s = EXYNOS4210_GIC(obj);\n\n SysBusDevice *sbd = SYS_BUS_DEVICE(obj);\n\n uint32_t i;\n\n const char cpu_prefix[] = \"exynos4210-gic-alias_cpu\";\n\n const char dist_prefix[] = \"exynos4210-gic-alias_dist\";\n\n char cpu_alias_name[sizeof(cpu_prefix) + 3];\n\n char dist_alias_name[sizeof(cpu_prefix) + 3];\n\n SysBusDevice *busdev;\n\n\n\n s->gic = qdev_create(NULL, \"arm_gic\");\n\n qdev_prop_set_uint32(s->gic, \"num-cpu\", s->num_cpu);\n\n qdev_prop_set_uint32(s->gic, \"num-irq\", EXYNOS4210_GIC_NIRQ);\n\n qdev_init_nofail(s->gic);\n\n busdev = SYS_BUS_DEVICE(s->gic);\n\n\n\n /* Pass through outbound IRQ lines from the GIC */\n\n sysbus_pass_irq(sbd, busdev);\n\n\n\n /* Pass through inbound GPIO lines to the GIC */\n\n qdev_init_gpio_in(dev, exynos4210_gic_set_irq,\n\n EXYNOS4210_GIC_NIRQ - 32);\n\n\n\n memory_region_init(&s->cpu_container, obj, \"exynos4210-cpu-container\",\n\n EXYNOS4210_EXT_GIC_CPU_REGION_SIZE);\n\n memory_region_init(&s->dist_container, obj, \"exynos4210-dist-container\",\n\n EXYNOS4210_EXT_GIC_DIST_REGION_SIZE);\n\n\n\n for (i = 0; i < s->num_cpu; i++) {\n\n /* Map CPU interface per SMP Core */\n\n sprintf(cpu_alias_name, \"%s%x\", cpu_prefix, i);\n\n memory_region_init_alias(&s->cpu_alias[i], obj,\n\n cpu_alias_name,\n\n sysbus_mmio_get_region(busdev, 1),\n\n 0,\n\n EXYNOS4210_GIC_CPU_REGION_SIZE);\n\n memory_region_add_subregion(&s->cpu_container,\n\n EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(i), &s->cpu_alias[i]);\n\n\n\n /* Map Distributor per SMP Core */\n\n sprintf(dist_alias_name, \"%s%x\", dist_prefix, i);\n\n memory_region_init_alias(&s->dist_alias[i], obj,\n\n dist_alias_name,\n\n sysbus_mmio_get_region(busdev, 0),\n\n 0,\n\n EXYNOS4210_GIC_DIST_REGION_SIZE);\n\n memory_region_add_subregion(&s->dist_container,\n\n EXYNOS4210_EXT_GIC_DIST_GET_OFFSET(i), &s->dist_alias[i]);\n\n }\n\n\n\n sysbus_init_mmio(sbd, &s->cpu_container);\n\n sysbus_init_mmio(sbd, &s->dist_container);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "ee78356eba8df05043bac392c263450db5e7eed6", + "length": 617 + }, + { + "index": 2399, + "code": "static int scan_mmco_reset(AVCodecParserContext *s)\n\n{\n\n H264ParseContext *p = s->priv_data;\n\n H264Context *h = &p->h;\n\n H264SliceContext *sl = &h->slice_ctx[0];\n\n\n\n sl->slice_type_nos = s->pict_type & 3;\n\n\n\n if (h->pps.redundant_pic_cnt_present)\n\n get_ue_golomb(&sl->gb); // redundant_pic_count\n\n\n\n if (ff_set_ref_count(h, sl) < 0)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n\n int list;\n\n for (list = 0; list < sl->list_count; list++) {\n\n if (get_bits1(&sl->gb)) {\n\n int index;\n\n for (index = 0; ; index++) {\n\n unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(&sl->gb);\n\n\n\n if (reordering_of_pic_nums_idc < 3)\n\n get_ue_golomb(&sl->gb);\n\n else if (reordering_of_pic_nums_idc > 3) {\n\n av_log(h->avctx, AV_LOG_ERROR,\n\n \"illegal reordering_of_pic_nums_idc %d\\n\",\n\n reordering_of_pic_nums_idc);\n\n return AVERROR_INVALIDDATA;\n\n } else\n\n break;\n\n\n\n if (index >= sl->ref_count[list]) {\n\n av_log(h->avctx, AV_LOG_ERROR,\n\n \"reference count %d overflow\\n\", index);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n\n\n if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||\n\n (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B))\n\n ff_pred_weight_table(h, sl);\n\n\n\n if (get_bits1(&sl->gb)) { // adaptive_ref_pic_marking_mode_flag\n\n int i;\n\n for (i = 0; i < MAX_MMCO_COUNT; i++) {\n\n MMCOOpcode opcode = get_ue_golomb_31(&sl->gb);\n\n if (opcode > (unsigned) MMCO_LONG) {\n\n av_log(h->avctx, AV_LOG_ERROR,\n\n \"illegal memory management control operation %d\\n\",\n\n opcode);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (opcode == MMCO_END)\n\n return 0;\n\n else if (opcode == MMCO_RESET)\n\n return 1;\n\n\n\n if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG)\n\n get_ue_golomb(&sl->gb);\n\n if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||\n\n opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG)\n\n get_ue_golomb_31(&sl->gb);\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "c51c08e0e70c186971385bdbb225f69edd4e3375", + "length": 646 + }, + { + "index": 9053, + "code": "static void create_gic(VirtBoardInfo *vbi, qemu_irq *pic, int type, bool secure)\n\n{\n\n /* We create a standalone GIC */\n\n DeviceState *gicdev;\n\n SysBusDevice *gicbusdev;\n\n const char *gictype;\n\n int i;\n\n\n\n gictype = (type == 3) ? gicv3_class_name() : gic_class_name();\n\n\n\n gicdev = qdev_create(NULL, gictype);\n\n qdev_prop_set_uint32(gicdev, \"revision\", type);\n\n qdev_prop_set_uint32(gicdev, \"num-cpu\", smp_cpus);\n\n /* Note that the num-irq property counts both internal and external\n\n * interrupts; there are always 32 of the former (mandated by GIC spec).\n\n */\n\n qdev_prop_set_uint32(gicdev, \"num-irq\", NUM_IRQS + 32);\n\n if (!kvm_irqchip_in_kernel()) {\n\n qdev_prop_set_bit(gicdev, \"has-security-extensions\", secure);\n\n }\n\n qdev_init_nofail(gicdev);\n\n gicbusdev = SYS_BUS_DEVICE(gicdev);\n\n sysbus_mmio_map(gicbusdev, 0, vbi->memmap[VIRT_GIC_DIST].base);\n\n if (type == 3) {\n\n sysbus_mmio_map(gicbusdev, 1, vbi->memmap[VIRT_GIC_REDIST].base);\n\n } else {\n\n sysbus_mmio_map(gicbusdev, 1, vbi->memmap[VIRT_GIC_CPU].base);\n\n }\n\n\n\n /* Wire the outputs from each CPU's generic timer to the\n\n * appropriate GIC PPI inputs, and the GIC's IRQ output to\n\n * the CPU's IRQ input.\n\n */\n\n for (i = 0; i < smp_cpus; i++) {\n\n DeviceState *cpudev = DEVICE(qemu_get_cpu(i));\n\n int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS;\n\n int irq;\n\n /* Mapping from the output timer irq lines from the CPU to the\n\n * GIC PPI inputs we use for the virt board.\n\n */\n\n const int timer_irq[] = {\n\n [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,\n\n [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,\n\n [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ,\n\n [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ,\n\n };\n\n\n\n for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {\n\n qdev_connect_gpio_out(cpudev, irq,\n\n qdev_get_gpio_in(gicdev,\n\n ppibase + timer_irq[irq]));\n\n }\n\n\n\n sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));\n\n sysbus_connect_irq(gicbusdev, i + smp_cpus,\n\n qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));\n\n }\n\n\n\n for (i = 0; i < NUM_IRQS; i++) {\n\n pic[i] = qdev_get_gpio_in(gicdev, i);\n\n }\n\n\n\n fdt_add_gic_node(vbi, type);\n\n\n\n if (type == 3) {\n\n create_its(vbi, gicdev);\n\n } else {\n\n create_v2m(vbi, pic);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "2231f69b4e4523c43aa459cab18ab77c0e29b4d1", + "length": 741 + }, + { + "index": 26988, + "code": "static void vp6_parse_coeff_models(VP56Context *s)\n\n{\n\n VP56RangeCoder *c = &s->c;\n\n VP56Model *model = s->modelp;\n\n int def_prob[11];\n\n int node, cg, ctx, pos;\n\n int ct; /* code type */\n\n int pt; /* plane type (0 for Y, 1 for U or V) */\n\n\n\n memset(def_prob, 0x80, sizeof(def_prob));\n\n\n\n for (pt=0; pt<2; pt++)\n\n for (node=0; node<11; node++)\n\n if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {\n\n def_prob[node] = vp56_rac_gets_nn(c, 7);\n\n model->coeff_dccv[pt][node] = def_prob[node];\n\n } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {\n\n model->coeff_dccv[pt][node] = def_prob[node];\n\n }\n\n\n\n if (vp56_rac_get(c)) {\n\n for (pos=1; pos<64; pos++)\n\n if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))\n\n model->coeff_reorder[pos] = vp56_rac_gets(c, 4);\n\n vp6_coeff_order_table_init(s);\n\n }\n\n\n\n for (cg=0; cg<2; cg++)\n\n for (node=0; node<14; node++)\n\n if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))\n\n model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);\n\n\n\n for (ct=0; ct<3; ct++)\n\n for (pt=0; pt<2; pt++)\n\n for (cg=0; cg<6; cg++)\n\n for (node=0; node<11; node++)\n\n if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {\n\n def_prob[node] = vp56_rac_gets_nn(c, 7);\n\n model->coeff_ract[pt][ct][cg][node] = def_prob[node];\n\n } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {\n\n model->coeff_ract[pt][ct][cg][node] = def_prob[node];\n\n }\n\n\n\n if (s->use_huffman) {\n\n for (pt=0; pt<2; pt++) {\n\n vp6_build_huff_tree(s, model->coeff_dccv[pt],\n\n vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);\n\n vp6_build_huff_tree(s, model->coeff_runv[pt],\n\n vp6_huff_run_map, 9, &s->runv_vlc[pt]);\n\n for (ct=0; ct<3; ct++)\n\n for (cg = 0; cg < 6; cg++)\n\n vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],\n\n vp6_huff_coeff_map, 12,\n\n &s->ract_vlc[pt][ct][cg]);\n\n }\n\n memset(s->nb_null, 0, sizeof(s->nb_null));\n\n } else {\n\n /* coeff_dcct is a linear combination of coeff_dccv */\n\n for (pt=0; pt<2; pt++)\n\n for (ctx=0; ctx<3; ctx++)\n\n for (node=0; node<5; node++)\n\n model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "066fff755a5d8edc660c010ddb08474d208eeade", + "length": 865 + }, + { + "index": 21996, + "code": "int virtio_load(VirtIODevice *vdev, QEMUFile *f)\n\n{\n\n int num, i, ret;\n\n uint32_t features;\n\n uint32_t supported_features =\n\n vdev->binding->get_features(vdev->binding_opaque);\n\n\n\n\n if (vdev->binding->load_config) {\n\n ret = vdev->binding->load_config(vdev->binding_opaque, f);\n\n if (ret)\n\n return ret;\n\n }\n\n\n\n qemu_get_8s(f, &vdev->status);\n\n qemu_get_8s(f, &vdev->isr);\n\n qemu_get_be16s(f, &vdev->queue_sel);\n\n qemu_get_be32s(f, &features);\n\n if (features & ~supported_features) {\n\n fprintf(stderr, \"Features 0x%x unsupported. Allowed features: 0x%x\\n\",\n\n features, supported_features);\n\n return -1;\n\n }\n\n if (vdev->set_features)\n\n vdev->set_features(vdev, features);\n\n vdev->guest_features = features;\n\n vdev->config_len = qemu_get_be32(f);\n\n qemu_get_buffer(f, vdev->config, vdev->config_len);\n\n\n\n num = qemu_get_be32(f);\n\n\n\n for (i = 0; i < num; i++) {\n\n vdev->vq[i].vring.num = qemu_get_be32(f);\n\n vdev->vq[i].pa = qemu_get_be64(f);\n\n qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);\n\n\n\n if (vdev->vq[i].pa) {\n\n virtqueue_init(&vdev->vq[i]);\n\n }\n\n\tnum_heads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;\n\n\t/* Check it isn't doing very strange things with descriptor numbers. */\n\n\tif (num_heads > vdev->vq[i].vring.num) {\n\n\t\tfprintf(stderr, \"VQ %d size 0x%x Guest index 0x%x \"\n\n \"inconsistent with Host index 0x%x: delta 0x%x\\n\",\n\n\t\t\ti, vdev->vq[i].vring.num,\n\n vring_avail_idx(&vdev->vq[i]),\n\n vdev->vq[i].last_avail_idx, num_heads);\n\n\t\treturn -1;\n\n\t}\n\n if (vdev->binding->load_queue) {\n\n ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);\n\n if (ret)\n\n return ret;\n\n }\n\n }\n\n\n\n virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);\n\n return 0;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "258dc7c96bb4b7ca71d5bee811e73933310e168c", + "length": 575 + }, + { + "index": 26290, + "code": "static int megasas_scsi_init(PCIDevice *dev)\n\n{\n\n DeviceState *d = DEVICE(dev);\n\n MegasasState *s = MEGASAS(dev);\n\n MegasasBaseClass *b = MEGASAS_DEVICE_GET_CLASS(s);\n\n uint8_t *pci_conf;\n\n int i, bar_type;\n\n Error *err = NULL;\n\n\n\n pci_conf = dev->config;\n\n\n\n /* PCI latency timer = 0 */\n\n pci_conf[PCI_LATENCY_TIMER] = 0;\n\n /* Interrupt pin 1 */\n\n pci_conf[PCI_INTERRUPT_PIN] = 0x01;\n\n\n\n memory_region_init_io(&s->mmio_io, OBJECT(s), &megasas_mmio_ops, s,\n\n \"megasas-mmio\", 0x4000);\n\n memory_region_init_io(&s->port_io, OBJECT(s), &megasas_port_ops, s,\n\n \"megasas-io\", 256);\n\n memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s,\n\n \"megasas-queue\", 0x40000);\n\n\n\n if (megasas_use_msi(s) &&\n\n msi_init(dev, 0x50, 1, true, false)) {\n\n s->flags &= ~MEGASAS_MASK_USE_MSI;\n\n }\n\n if (megasas_use_msix(s) &&\n\n msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,\n\n &s->mmio_io, b->mmio_bar, 0x3800, 0x68)) {\n\n s->flags &= ~MEGASAS_MASK_USE_MSIX;\n\n }\n\n if (pci_is_express(dev)) {\n\n pcie_endpoint_cap_init(dev, 0xa0);\n\n }\n\n\n\n bar_type = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64;\n\n pci_register_bar(dev, b->ioport_bar,\n\n PCI_BASE_ADDRESS_SPACE_IO, &s->port_io);\n\n pci_register_bar(dev, b->mmio_bar, bar_type, &s->mmio_io);\n\n pci_register_bar(dev, 3, bar_type, &s->queue_io);\n\n\n\n if (megasas_use_msix(s)) {\n\n msix_vector_use(dev, 0);\n\n }\n\n\n\n s->fw_state = MFI_FWSTATE_READY;\n\n if (!s->sas_addr) {\n\n s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |\n\n IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;\n\n s->sas_addr |= (pci_bus_num(dev->bus) << 16);\n\n s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);\n\n s->sas_addr |= PCI_FUNC(dev->devfn);\n\n }\n\n if (!s->hba_serial) {\n\n s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);\n\n }\n\n if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {\n\n s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;\n\n } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {\n\n s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;\n\n } else {\n\n s->fw_sge = 64 - MFI_PASS_FRAME_SIZE;\n\n }\n\n if (s->fw_cmds > MEGASAS_MAX_FRAMES) {\n\n s->fw_cmds = MEGASAS_MAX_FRAMES;\n\n }\n\n trace_megasas_init(s->fw_sge, s->fw_cmds,\n\n megasas_is_jbod(s) ? \"jbod\" : \"raid\");\n\n\n\n if (megasas_is_jbod(s)) {\n\n s->fw_luns = MFI_MAX_SYS_PDS;\n\n } else {\n\n s->fw_luns = MFI_MAX_LD;\n\n }\n\n s->producer_pa = 0;\n\n s->consumer_pa = 0;\n\n for (i = 0; i < s->fw_cmds; i++) {\n\n s->frames[i].index = i;\n\n s->frames[i].context = -1;\n\n s->frames[i].pa = 0;\n\n s->frames[i].state = s;\n\n }\n\n\n\n scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),\n\n &megasas_scsi_info, NULL);\n\n if (!d->hotplugged) {\n\n scsi_bus_legacy_handle_cmdline(&s->bus, &err);\n\n if (err != NULL) {\n\n\n error_free(err);\n\n return -1;\n\n }\n\n }\n\n return 0;\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "fa617181839741727d0067ea68807133f498f29b", + "length": 1023 + }, + { + "index": 10801, + "code": "static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int offset)\n\n{\n\n AHCICmdHdr *cmd = ad->cur_cmd;\n\n uint32_t opts = le32_to_cpu(cmd->opts);\n\n uint64_t prdt_addr = le64_to_cpu(cmd->tbl_addr) + 0x80;\n\n int sglist_alloc_hint = opts >> AHCI_CMD_HDR_PRDT_LEN;\n\n dma_addr_t prdt_len = (sglist_alloc_hint * sizeof(AHCI_SG));\n\n dma_addr_t real_prdt_len = prdt_len;\n\n uint8_t *prdt;\n\n int i;\n\n int r = 0;\n\n int sum = 0;\n\n int off_idx = -1;\n\n int off_pos = -1;\n\n int tbl_entry_size;\n\n IDEBus *bus = &ad->port;\n\n BusState *qbus = BUS(bus);\n\n\n\n if (!sglist_alloc_hint) {\n\n DPRINTF(ad->port_no, \"no sg list given by guest: 0x%08x\\n\", opts);\n\n return -1;\n\n }\n\n\n\n /* map PRDT */\n\n if (!(prdt = dma_memory_map(ad->hba->as, prdt_addr, &prdt_len,\n\n DMA_DIRECTION_TO_DEVICE))){\n\n DPRINTF(ad->port_no, \"map failed\\n\");\n\n return -1;\n\n }\n\n\n\n if (prdt_len < real_prdt_len) {\n\n DPRINTF(ad->port_no, \"mapped less than expected\\n\");\n\n r = -1;\n\n goto out;\n\n }\n\n\n\n /* Get entries in the PRDT, init a qemu sglist accordingly */\n\n if (sglist_alloc_hint > 0) {\n\n AHCI_SG *tbl = (AHCI_SG *)prdt;\n\n sum = 0;\n\n for (i = 0; i < sglist_alloc_hint; i++) {\n\n /* flags_size is zero-based */\n\n tbl_entry_size = (le32_to_cpu(tbl[i].flags_size) + 1);\n\n if (offset <= (sum + tbl_entry_size)) {\n\n off_idx = i;\n\n off_pos = offset - sum;\n\n break;\n\n }\n\n sum += tbl_entry_size;\n\n }\n\n if ((off_idx == -1) || (off_pos < 0) || (off_pos > tbl_entry_size)) {\n\n DPRINTF(ad->port_no, \"%s: Incorrect offset! \"\n\n \"off_idx: %d, off_pos: %d\\n\",\n\n __func__, off_idx, off_pos);\n\n r = -1;\n\n goto out;\n\n }\n\n\n\n qemu_sglist_init(sglist, qbus->parent, (sglist_alloc_hint - off_idx),\n\n ad->hba->as);\n\n qemu_sglist_add(sglist, le64_to_cpu(tbl[off_idx].addr + off_pos),\n\n le32_to_cpu(tbl[off_idx].flags_size) + 1 - off_pos);\n\n\n\n for (i = off_idx + 1; i < sglist_alloc_hint; i++) {\n\n /* flags_size is zero-based */\n\n qemu_sglist_add(sglist, le64_to_cpu(tbl[i].addr),\n\n le32_to_cpu(tbl[i].flags_size) + 1);\n\n }\n\n }\n\n\n\nout:\n\n dma_memory_unmap(ad->hba->as, prdt, prdt_len,\n\n DMA_DIRECTION_TO_DEVICE, prdt_len);\n\n return r;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "d02f8adc6d2a178bcbf77d0413f9a96fdbed53f0", + "length": 732 + }, + { + "index": 21770, + "code": "static void video_decode_example(const char *outfilename, const char *filename)\n\n{\n\n AVCodec *codec;\n\n AVCodecContext *c= NULL;\n\n int frame, got_picture, len;\n\n FILE *f;\n\n AVFrame *picture;\n\n uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];\n\n char buf[1024];\n\n AVPacket avpkt;\n\n\n\n av_init_packet(&avpkt);\n\n\n\n /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */\n\n memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n\n\n\n printf(\"Decode video file %s\\n\", filename);\n\n\n\n /* find the mpeg1 video decoder */\n\n codec = avcodec_find_decoder(AV_CODEC_ID_MPEG1VIDEO);\n\n if (!codec) {\n\n fprintf(stderr, \"codec not found\\n\");\n\n exit(1);\n\n }\n\n\n\n c = avcodec_alloc_context3(codec);\n\n picture= avcodec_alloc_frame();\n\n\n\n if(codec->capabilities&CODEC_CAP_TRUNCATED)\n\n c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */\n\n\n\n /* For some codecs, such as msmpeg4 and mpeg4, width and height\n\n MUST be initialized there because this information is not\n\n available in the bitstream. */\n\n\n\n /* open it */\n\n if (avcodec_open2(c, codec, NULL) < 0) {\n\n fprintf(stderr, \"could not open codec\\n\");\n\n exit(1);\n\n }\n\n\n\n /* the codec gives us the frame size, in samples */\n\n\n\n f = fopen(filename, \"rb\");\n\n if (!f) {\n\n fprintf(stderr, \"could not open %s\\n\", filename);\n\n exit(1);\n\n }\n\n\n\n frame = 0;\n\n for(;;) {\n\n avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);\n\n if (avpkt.size == 0)\n\n break;\n\n\n\n /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)\n\n and this is the only method to use them because you cannot\n\n know the compressed data size before analysing it.\n\n\n\n BUT some other codecs (msmpeg4, mpeg4) are inherently frame\n\n based, so you must call them with all the data for one\n\n frame exactly. You must also initialize 'width' and\n\n 'height' before initializing them. */\n\n\n\n /* NOTE2: some codecs allow the raw parameters (frame size,\n\n sample rate) to be changed at any frame. We handle this, so\n\n you should also take care of it */\n\n\n\n /* here, we use a stream based decoder (mpeg1video), so we\n\n feed decoder and see if it could decode a frame */\n\n avpkt.data = inbuf;\n\n while (avpkt.size > 0) {\n\n len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);\n\n if (len < 0) {\n\n fprintf(stderr, \"Error while decoding frame %d\\n\", frame);\n\n exit(1);\n\n }\n\n if (got_picture) {\n\n printf(\"saving frame %3d\\n\", frame);\n\n fflush(stdout);\n\n\n\n /* the picture is allocated by the decoder. no need to\n\n free it */\n\n snprintf(buf, sizeof(buf), outfilename, frame);\n\n pgm_save(picture->data[0], picture->linesize[0],\n\n c->width, c->height, buf);\n\n frame++;\n\n }\n\n avpkt.size -= len;\n\n avpkt.data += len;\n\n }\n\n }\n\n\n\n /* some codecs, such as MPEG, transmit the I and P frame with a\n\n latency of one frame. You must do the following to have a\n\n chance to get the last frame of the video */\n\n avpkt.data = NULL;\n\n avpkt.size = 0;\n\n len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);\n\n if (got_picture) {\n\n printf(\"saving last frame %3d\\n\", frame);\n\n fflush(stdout);\n\n\n\n /* the picture is allocated by the decoder. no need to\n\n free it */\n\n snprintf(buf, sizeof(buf), outfilename, frame);\n\n pgm_save(picture->data[0], picture->linesize[0],\n\n c->width, c->height, buf);\n\n frame++;\n\n }\n\n\n\n fclose(f);\n\n\n\n avcodec_close(c);\n\n av_free(c);\n\n av_free(picture);\n\n printf(\"\\n\");\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "535df748c5043bac6b03e598cfa93160ecce8383", + "length": 954 + }, + { + "index": 8758, + "code": "read_f(int argc, char **argv)\n\n{\n\n\tstruct timeval t1, t2;\n\n\tint Cflag = 0, pflag = 0, qflag = 0, vflag = 0;\n\n\tint Pflag = 0, sflag = 0, lflag = 0, bflag = 0;\n\n\tint c, cnt;\n\n\tchar *buf;\n\n\tint64_t offset;\n\n\tint count;\n\n /* Some compilers get confused and warn if this is not initialized. */\n\n int total = 0;\n\n\tint pattern = 0, pattern_offset = 0, pattern_count = 0;\n\n\n\n\twhile ((c = getopt(argc, argv, \"bCl:pP:qs:v\")) != EOF) {\n\n\t\tswitch (c) {\n\n\t\tcase 'b':\n\n\t\t\tbflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 'C':\n\n\t\t\tCflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 'l':\n\n\t\t\tlflag = 1;\n\n\t\t\tpattern_count = cvtnum(optarg);\n\n\t\t\tif (pattern_count < 0) {\n\n\t\t\t\tprintf(\"non-numeric length argument -- %s\\n\", optarg);\n\n\t\t\t\treturn 0;\n\n\t\t\t}\n\n\t\t\tbreak;\n\n\t\tcase 'p':\n\n\t\t\tpflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 'P':\n\n\t\t\tPflag = 1;\n\n\t\t\tpattern = atoi(optarg);\n\n\t\t\tbreak;\n\n\t\tcase 'q':\n\n\t\t\tqflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 's':\n\n\t\t\tsflag = 1;\n\n\t\t\tpattern_offset = cvtnum(optarg);\n\n\t\t\tif (pattern_offset < 0) {\n\n\t\t\t\tprintf(\"non-numeric length argument -- %s\\n\", optarg);\n\n\t\t\t\treturn 0;\n\n\t\t\t}\n\n\t\t\tbreak;\n\n\t\tcase 'v':\n\n\t\t\tvflag = 1;\n\n\t\t\tbreak;\n\n\t\tdefault:\n\n\t\t\treturn command_usage(&read_cmd);\n\n\t\t}\n\n\t}\n\n\n\n\tif (optind != argc - 2)\n\n\t\treturn command_usage(&read_cmd);\n\n\n\n\tif (bflag && pflag) {\n\n\t\tprintf(\"-b and -p cannot be specified at the same time\\n\");\n\n\t\treturn 0;\n\n\t}\n\n\n\n\toffset = cvtnum(argv[optind]);\n\n\tif (offset < 0) {\n\n\t\tprintf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n\t\treturn 0;\n\n\t}\n\n\n\n\toptind++;\n\n\tcount = cvtnum(argv[optind]);\n\n\tif (count < 0) {\n\n\t\tprintf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n\t\treturn 0;\n\n\t}\n\n\n\n if (!Pflag && (lflag || sflag)) {\n\n return command_usage(&read_cmd);\n\n }\n\n\n\n if (!lflag) {\n\n pattern_count = count - pattern_offset;\n\n }\n\n\n\n if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {\n\n printf(\"pattern verfication range exceeds end of read data\\n\");\n\n return 0;\n\n }\n\n\n\n\tif (!pflag)\n\n\t\tif (offset & 0x1ff) {\n\n\t\t\tprintf(\"offset %lld is not sector aligned\\n\",\n\n\t\t\t\t(long long)offset);\n\n\t\t\treturn 0;\n\n\n\n\t\tif (count & 0x1ff) {\n\n\t\t\tprintf(\"count %d is not sector aligned\\n\",\n\n\t\t\t\tcount);\n\n\t\t\treturn 0;\n\n\t\t}\n\n\t}\n\n\n\n\tbuf = qemu_io_alloc(count, 0xab);\n\n\n\n\tgettimeofday(&t1, NULL);\n\n\tif (pflag)\n\n\t\tcnt = do_pread(buf, offset, count, &total);\n\n\telse if (bflag)\n\n\t\tcnt = do_load_vmstate(buf, offset, count, &total);\n\n\telse\n\n\t\tcnt = do_read(buf, offset, count, &total);\n\n\tgettimeofday(&t2, NULL);\n\n\n\n\tif (cnt < 0) {\n\n\t\tprintf(\"read failed: %s\\n\", strerror(-cnt));\n\n\t\tgoto out;\n\n\t}\n\n\n\n\tif (Pflag) {\n\n\t\tvoid* cmp_buf = malloc(pattern_count);\n\n\t\tmemset(cmp_buf, pattern, pattern_count);\n\n\t\tif (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {\n\n\t\t\tprintf(\"Pattern verification failed at offset %lld, \"\n\n\t\t\t\t\"%d bytes\\n\",\n\n\t\t\t\t(long long) offset + pattern_offset, pattern_count);\n\n\t\t}\n\n\t\tfree(cmp_buf);\n\n\t}\n\n\n\n\tif (qflag)\n\n\t\tgoto out;\n\n\n\n if (vflag)\n\n\t\tdump_buffer(buf, offset, count);\n\n\n\n\t/* Finally, report back -- -C gives a parsable format */\n\n\tt2 = tsub(t2, t1);\n\n\tprint_report(\"read\", &t2, offset, count, total, cnt, Cflag);\n\n\n\nout:\n\n\tqemu_io_free(buf);\n\n\n\n\treturn 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "cf070d7ec0b8fb21faa9a630ed5cc66f90844a08", + "length": 963 + }, + { + "index": 5982, + "code": "static void mpeg_decode_sequence_extension(Mpeg1Context *s1)\n\n{\n\n MpegEncContext *s = &s1->mpeg_enc_ctx;\n\n int horiz_size_ext, vert_size_ext;\n\n int bit_rate_ext;\n\n\n\n skip_bits(&s->gb, 1); /* profile and level esc*/\n\n s->avctx->profile = get_bits(&s->gb, 3);\n\n s->avctx->level = get_bits(&s->gb, 4);\n\n s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */\n\n s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */\n\n\n\n if (!s->chroma_format) {\n\n s->chroma_format = 1;\n\n av_log(s->avctx, AV_LOG_WARNING, \"Chroma format invalid\\n\");\n\n }\n\n\n\n horiz_size_ext = get_bits(&s->gb, 2);\n\n vert_size_ext = get_bits(&s->gb, 2);\n\n s->width |= (horiz_size_ext << 12);\n\n s->height |= (vert_size_ext << 12);\n\n bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */\n\n s->bit_rate += (bit_rate_ext << 18) * 400;\n\n check_marker(&s->gb, \"after bit rate extension\");\n\n s->avctx->rc_buffer_size += get_bits(&s->gb, 8) * 1024 * 16 << 10;\n\n\n\n s->low_delay = get_bits1(&s->gb);\n\n if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)\n\n s->low_delay = 1;\n\n\n\n s1->frame_rate_ext.num = get_bits(&s->gb, 2) + 1;\n\n s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1;\n\n\n\n ff_dlog(s->avctx, \"sequence extension\\n\");\n\n s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;\n\n\n\n if (s->avctx->debug & FF_DEBUG_PICT_INFO)\n\n av_log(s->avctx, AV_LOG_DEBUG,\n\n \"profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%\"PRId64\"\\n\",\n\n s->avctx->profile, s->avctx->level, s->progressive_sequence, s->chroma_format,\n\n s->avctx->rc_buffer_size, s->bit_rate);\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "863522431fb2fc7d35fce582fcaacdcf37fc3c44", + "length": 576 + }, + { + "index": 16053, + "code": "static int protocol_client_auth_sasl_start(VncState *vs, uint8_t *data, size_t len)\n\n{\n\n uint32_t datalen = len;\n\n const char *serverout;\n\n unsigned int serveroutlen;\n\n int err;\n\n char *clientdata = NULL;\n\n\n\n /* NB, distinction of NULL vs \"\" is *critical* in SASL */\n\n if (datalen) {\n\n clientdata = (char*)data;\n\n clientdata[datalen-1] = '\\0'; /* Should be on wire, but make sure */\n\n datalen--; /* Don't count NULL byte when passing to _start() */\n\n }\n\n\n\n VNC_DEBUG(\"Start SASL auth with mechanism %s. Data %p (%d bytes)\\n\",\n\n vs->sasl.mechlist, clientdata, datalen);\n\n err = sasl_server_start(vs->sasl.conn,\n\n vs->sasl.mechlist,\n\n clientdata,\n\n datalen,\n\n &serverout,\n\n &serveroutlen);\n\n if (err != SASL_OK &&\n\n err != SASL_CONTINUE) {\n\n VNC_DEBUG(\"sasl start failed %d (%s)\\n\",\n\n err, sasl_errdetail(vs->sasl.conn));\n\n sasl_dispose(&vs->sasl.conn);\n\n vs->sasl.conn = NULL;\n\n goto authabort;\n\n }\n\n if (serveroutlen > SASL_DATA_MAX_LEN) {\n\n VNC_DEBUG(\"sasl start reply data too long %d\\n\",\n\n serveroutlen);\n\n sasl_dispose(&vs->sasl.conn);\n\n vs->sasl.conn = NULL;\n\n goto authabort;\n\n }\n\n\n\n VNC_DEBUG(\"SASL return data %d bytes, nil; %d\\n\",\n\n serveroutlen, serverout ? 0 : 1);\n\n\n\n if (serveroutlen) {\n\n vnc_write_u32(vs, serveroutlen + 1);\n\n vnc_write(vs, serverout, serveroutlen + 1);\n\n } else {\n\n vnc_write_u32(vs, 0);\n\n }\n\n\n\n /* Whether auth is complete */\n\n vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1);\n\n\n\n if (err == SASL_CONTINUE) {\n\n VNC_DEBUG(\"%s\", \"Authentication must continue\\n\");\n\n /* Wait for step length */\n\n vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4);\n\n } else {\n\n if (!vnc_auth_sasl_check_ssf(vs)) {\n\n VNC_DEBUG(\"Authentication rejected for weak SSF %p\\n\", vs->ioc);\n\n goto authreject;\n\n }\n\n\n\n /* Check username whitelist ACL */\n\n if (vnc_auth_sasl_check_access(vs) < 0) {\n\n VNC_DEBUG(\"Authentication rejected for ACL %p\\n\", vs->ioc);\n\n goto authreject;\n\n }\n\n\n\n VNC_DEBUG(\"Authentication successful %p\\n\", vs->ioc);\n\n vnc_write_u32(vs, 0); /* Accept auth */\n\n start_client_init(vs);\n\n }\n\n\n\n return 0;\n\n\n\n authreject:\n\n vnc_write_u32(vs, 1); /* Reject auth */\n\n vnc_write_u32(vs, sizeof(\"Authentication failed\"));\n\n vnc_write(vs, \"Authentication failed\", sizeof(\"Authentication failed\"));\n\n vnc_flush(vs);\n\n vnc_client_error(vs);\n\n return -1;\n\n\n\n authabort:\n\n vnc_client_error(vs);\n\n return -1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "7364dbdabb7824d5bde1e341bb6d928282f01c83", + "length": 733 + }, + { + "index": 27055, + "code": "static int vdi_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n BDRVVdiState *s = bs->opaque;\n\n VdiHeader header;\n\n size_t bmap_size;\n\n int ret;\n\n\n\n logout(\"\\n\");\n\n\n\n ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n vdi_header_to_cpu(&header);\n\n#if defined(CONFIG_VDI_DEBUG)\n\n vdi_header_print(&header);\n\n#endif\n\n\n\n if (header.disk_size % SECTOR_SIZE != 0) {\n\n /* 'VBoxManage convertfromraw' can create images with odd disk sizes.\n\n We accept them but round the disk size to the next multiple of\n\n SECTOR_SIZE. */\n\n logout(\"odd disk size %\" PRIu64 \" B, round up\\n\", header.disk_size);\n\n header.disk_size += SECTOR_SIZE - 1;\n\n header.disk_size &= ~(SECTOR_SIZE - 1);\n\n }\n\n\n\n if (header.signature != VDI_SIGNATURE) {\n\n logout(\"bad vdi signature %08x\\n\", header.signature);\n\n ret = -EMEDIUMTYPE;\n\n goto fail;\n\n } else if (header.version != VDI_VERSION_1_1) {\n\n logout(\"unsupported version %u.%u\\n\",\n\n header.version >> 16, header.version & 0xffff);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.offset_bmap % SECTOR_SIZE != 0) {\n\n /* We only support block maps which start on a sector boundary. */\n\n logout(\"unsupported block map offset 0x%x B\\n\", header.offset_bmap);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.offset_data % SECTOR_SIZE != 0) {\n\n /* We only support data blocks which start on a sector boundary. */\n\n logout(\"unsupported data offset 0x%x B\\n\", header.offset_data);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.sector_size != SECTOR_SIZE) {\n\n logout(\"unsupported sector size %u B\\n\", header.sector_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.block_size != 1 * MiB) {\n\n logout(\"unsupported block size %u B\\n\", header.block_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.disk_size >\n\n (uint64_t)header.blocks_in_image * header.block_size) {\n\n logout(\"unsupported disk size %\" PRIu64 \" B\\n\", header.disk_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (!uuid_is_null(header.uuid_link)) {\n\n logout(\"link uuid != 0, unsupported\\n\");\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (!uuid_is_null(header.uuid_parent)) {\n\n logout(\"parent uuid != 0, unsupported\\n\");\n\n ret = -ENOTSUP;\n\n goto fail;\n\n }\n\n\n\n bs->total_sectors = header.disk_size / SECTOR_SIZE;\n\n\n\n s->block_size = header.block_size;\n\n s->block_sectors = header.block_size / SECTOR_SIZE;\n\n s->bmap_sector = header.offset_bmap / SECTOR_SIZE;\n\n s->header = header;\n\n\n\n bmap_size = header.blocks_in_image * sizeof(uint32_t);\n\n bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;\n\n s->bmap = g_malloc(bmap_size * SECTOR_SIZE);\n\n ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size);\n\n if (ret < 0) {\n\n goto fail_free_bmap;\n\n }\n\n\n\n /* Disable migration when vdi images are used */\n\n error_set(&s->migration_blocker,\n\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n\n \"vdi\", bs->device_name, \"live migration\");\n\n migrate_add_blocker(s->migration_blocker);\n\n\n\n return 0;\n\n\n\n fail_free_bmap:\n\n g_free(s->bmap);\n\n\n\n fail:\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "76abe4071d111a9ca6dcc9b9689a831c39ffa718", + "length": 907 + }, + { + "index": 21228, + "code": "static void decode_format80(const unsigned char *src, int src_size,\n\n unsigned char *dest, int dest_size, int check_size) {\n\n\n\n int src_index = 0;\n\n int dest_index = 0;\n\n int count;\n\n int src_pos;\n\n unsigned char color;\n\n int i;\n\n\n\n while (src_index < src_size) {\n\n\n\n av_dlog(NULL, \" opcode %02X: \", src[src_index]);\n\n\n\n /* 0x80 means that frame is finished */\n\n if (src[src_index] == 0x80)\n\n\n\n\n if (dest_index >= dest_size) {\n\n av_log(NULL, AV_LOG_ERROR, \" VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\\n\",\n\n dest_index, dest_size);\n\n\n }\n\n\n\n if (src[src_index] == 0xFF) {\n\n\n\n src_index++;\n\n count = AV_RL16(&src[src_index]);\n\n src_index += 2;\n\n src_pos = AV_RL16(&src[src_index]);\n\n src_index += 2;\n\n av_dlog(NULL, \"(1) copy %X bytes from absolute pos %X\\n\", count, src_pos);\n\n CHECK_COUNT();\n\n if (src_pos + count > dest_size)\n\n\n for (i = 0; i < count; i++)\n\n dest[dest_index + i] = dest[src_pos + i];\n\n dest_index += count;\n\n\n\n } else if (src[src_index] == 0xFE) {\n\n\n\n src_index++;\n\n count = AV_RL16(&src[src_index]);\n\n src_index += 2;\n\n color = src[src_index++];\n\n av_dlog(NULL, \"(2) set %X bytes to %02X\\n\", count, color);\n\n CHECK_COUNT();\n\n memset(&dest[dest_index], color, count);\n\n dest_index += count;\n\n\n\n } else if ((src[src_index] & 0xC0) == 0xC0) {\n\n\n\n count = (src[src_index++] & 0x3F) + 3;\n\n src_pos = AV_RL16(&src[src_index]);\n\n src_index += 2;\n\n av_dlog(NULL, \"(3) copy %X bytes from absolute pos %X\\n\", count, src_pos);\n\n CHECK_COUNT();\n\n if (src_pos + count > dest_size)\n\n\n for (i = 0; i < count; i++)\n\n dest[dest_index + i] = dest[src_pos + i];\n\n dest_index += count;\n\n\n\n } else if (src[src_index] > 0x80) {\n\n\n\n count = src[src_index++] & 0x3F;\n\n av_dlog(NULL, \"(4) copy %X bytes from source to dest\\n\", count);\n\n CHECK_COUNT();\n\n memcpy(&dest[dest_index], &src[src_index], count);\n\n src_index += count;\n\n dest_index += count;\n\n\n\n } else {\n\n\n\n count = ((src[src_index] & 0x70) >> 4) + 3;\n\n src_pos = AV_RB16(&src[src_index]) & 0x0FFF;\n\n src_index += 2;\n\n av_dlog(NULL, \"(5) copy %X bytes from relpos %X\\n\", count, src_pos);\n\n CHECK_COUNT();\n\n\n\n for (i = 0; i < count; i++)\n\n dest[dest_index + i] = dest[dest_index - src_pos + i];\n\n dest_index += count;\n\n }\n\n }\n\n\n\n /* validate that the entire destination buffer was filled; this is\n\n * important for decoding frame maps since each vector needs to have a\n\n * codebook entry; it is not important for compressed codebooks because\n\n * not every entry needs to be filled */\n\n if (check_size)\n\n if (dest_index < dest_size)\n\n av_log(NULL, AV_LOG_ERROR, \" VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\\n\",\n\n dest_index, dest_size);\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "6d45702f7f257c1cfcd3ce3287bf258854528a4a", + "length": 852 + }, + { + "index": 17653, + "code": "static void gen_branch(DisasContext *ctx, int insn_bytes)\n\n{\n\n if (ctx->hflags & MIPS_HFLAG_BMASK) {\n\n int proc_hflags = ctx->hflags & MIPS_HFLAG_BMASK;\n\n /* Branches completion */\n\n ctx->hflags &= ~MIPS_HFLAG_BMASK;\n\n ctx->bstate = BS_BRANCH;\n\n save_cpu_state(ctx, 0);\n\n /* FIXME: Need to clear can_do_io. */\n\n switch (proc_hflags & MIPS_HFLAG_BMASK_BASE) {\n\n case MIPS_HFLAG_FBNSLOT:\n\n MIPS_DEBUG(\"forbidden slot\");\n\n gen_goto_tb(ctx, 0, ctx->pc + insn_bytes);\n\n break;\n\n case MIPS_HFLAG_B:\n\n /* unconditional branch */\n\n MIPS_DEBUG(\"unconditional branch\");\n\n if (proc_hflags & MIPS_HFLAG_BX) {\n\n tcg_gen_xori_i32(hflags, hflags, MIPS_HFLAG_M16);\n\n }\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n break;\n\n case MIPS_HFLAG_BL:\n\n /* blikely taken case */\n\n MIPS_DEBUG(\"blikely branch taken\");\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n break;\n\n case MIPS_HFLAG_BC:\n\n /* Conditional branch */\n\n MIPS_DEBUG(\"conditional branch\");\n\n {\n\n int l1 = gen_new_label();\n\n\n\n tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);\n\n gen_goto_tb(ctx, 1, ctx->pc + insn_bytes);\n\n gen_set_label(l1);\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n }\n\n break;\n\n case MIPS_HFLAG_BR:\n\n /* unconditional branch to register */\n\n MIPS_DEBUG(\"branch to register\");\n\n if (ctx->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {\n\n TCGv t0 = tcg_temp_new();\n\n TCGv_i32 t1 = tcg_temp_new_i32();\n\n\n\n tcg_gen_andi_tl(t0, btarget, 0x1);\n\n tcg_gen_trunc_tl_i32(t1, t0);\n\n tcg_temp_free(t0);\n\n tcg_gen_andi_i32(hflags, hflags, ~(uint32_t)MIPS_HFLAG_M16);\n\n tcg_gen_shli_i32(t1, t1, MIPS_HFLAG_M16_SHIFT);\n\n tcg_gen_or_i32(hflags, hflags, t1);\n\n tcg_temp_free_i32(t1);\n\n\n\n tcg_gen_andi_tl(cpu_PC, btarget, ~(target_ulong)0x1);\n\n } else {\n\n tcg_gen_mov_tl(cpu_PC, btarget);\n\n }\n\n if (ctx->singlestep_enabled) {\n\n save_cpu_state(ctx, 0);\n\n gen_helper_0e0i(raise_exception, EXCP_DEBUG);\n\n }\n\n tcg_gen_exit_tb(0);\n\n break;\n\n default:\n\n MIPS_DEBUG(\"unknown branch\");\n\n break;\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "42a268c241183877192c376d03bd9b6d527407c7", + "length": 648 + }, + { + "index": 26502, + "code": "static void output_client_manifest(struct VideoFiles *files,\n\n const char *basename, int split)\n\n{\n\n char filename[1000];\n\n FILE *out;\n\n int i, j;\n\n\n\n if (split)\n\n snprintf(filename, sizeof(filename), \"Manifest\");\n\n else\n\n snprintf(filename, sizeof(filename), \"%s.ismc\", basename);\n\n out = fopen(filename, \"w\");\n\n if (!out) {\n\n perror(filename);\n\n return;\n\n }\n\n fprintf(out, \"\\n\");\n\n fprintf(out, \"\\n\", files->duration * 10);\n\n if (files->video_file >= 0) {\n\n struct VideoFile *vf = files->files[files->video_file];\n\n int index = 0;\n\n fprintf(out,\n\n \"\\t\\n\",\n\n files->nb_video_files, vf->chunks);\n\n for (i = 0; i < files->nb_files; i++) {\n\n vf = files->files[i];\n\n if (!vf->is_video)\n\n continue;\n\n fprintf(out,\n\n \"\\t\\tbitrate, vf->fourcc, vf->width, vf->height);\n\n for (j = 0; j < vf->codec_private_size; j++)\n\n fprintf(out, \"%02X\", vf->codec_private[j]);\n\n fprintf(out, \"\\\" />\\n\");\n\n index++;\n\n }\n\n vf = files->files[files->video_file];\n\n for (i = 0; i < vf->chunks; i++)\n\n fprintf(out, \"\\t\\t\\n\", i,\n\n vf->offsets[i].duration);\n\n fprintf(out, \"\\t\\n\");\n\n }\n\n if (files->audio_file >= 0) {\n\n struct VideoFile *vf = files->files[files->audio_file];\n\n int index = 0;\n\n fprintf(out,\n\n \"\\t\\n\",\n\n files->nb_audio_files, vf->chunks);\n\n for (i = 0; i < files->nb_files; i++) {\n\n vf = files->files[i];\n\n if (!vf->is_audio)\n\n continue;\n\n fprintf(out,\n\n \"\\t\\tbitrate, vf->fourcc, vf->sample_rate,\n\n vf->channels, vf->blocksize, vf->tag);\n\n for (j = 0; j < vf->codec_private_size; j++)\n\n fprintf(out, \"%02X\", vf->codec_private[j]);\n\n fprintf(out, \"\\\" />\\n\");\n\n index++;\n\n }\n\n vf = files->files[files->audio_file];\n\n for (i = 0; i < vf->chunks; i++)\n\n fprintf(out, \"\\t\\t\\n\",\n\n i, vf->offsets[i].duration);\n\n fprintf(out, \"\\t\\n\");\n\n }\n\n fprintf(out, \"\\n\");\n\n fclose(out);\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "30327865f388260e49d40affd1b9c9fc2e20ebfe", + "length": 835 + }, + { + "index": 17888, + "code": "static int opus_packet(AVFormatContext *avf, int idx)\n\n{\n\n struct ogg *ogg = avf->priv_data;\n\n struct ogg_stream *os = &ogg->streams[idx];\n\n AVStream *st = avf->streams[idx];\n\n struct oggopus_private *priv = os->private;\n\n uint8_t *packet = os->buf + os->pstart;\n\n int ret;\n\n\n\n if (!os->psize)\n\n return AVERROR_INVALIDDATA;\n\n if (os->granule > INT64_MAX - UINT32_MAX) {\n\n av_log(avf, AV_LOG_ERROR, \"Unsupported huge granule pos %\"PRId64 \"\\n\", os->granule);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {\n\n int seg, d;\n\n int duration;\n\n uint8_t *last_pkt = os->buf + os->pstart;\n\n uint8_t *next_pkt = last_pkt;\n\n\n\n duration = 0;\n\n seg = os->segp;\n\n d = opus_duration(last_pkt, os->psize);\n\n if (d < 0) {\n\n os->pflags |= AV_PKT_FLAG_CORRUPT;\n\n return 0;\n\n }\n\n duration += d;\n\n last_pkt = next_pkt = next_pkt + os->psize;\n\n for (; seg < os->nsegs; seg++) {\n\n next_pkt += os->segments[seg];\n\n if (os->segments[seg] < 255 && next_pkt != last_pkt) {\n\n int d = opus_duration(last_pkt, next_pkt - last_pkt);\n\n if (d > 0)\n\n duration += d;\n\n last_pkt = next_pkt;\n\n }\n\n }\n\n os->lastpts =\n\n os->lastdts = os->granule - duration;\n\n }\n\n\n\n if ((ret = opus_duration(packet, os->psize)) < 0)\n\n return ret;\n\n\n\n os->pduration = ret;\n\n if (os->lastpts != AV_NOPTS_VALUE) {\n\n if (st->start_time == AV_NOPTS_VALUE)\n\n st->start_time = os->lastpts;\n\n priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;\n\n }\n\n\n\n priv->cur_dts += os->pduration;\n\n if ((os->flags & OGG_FLAG_EOS)) {\n\n int64_t skip = priv->cur_dts - os->granule + priv->pre_skip;\n\n skip = FFMIN(skip, os->pduration);\n\n if (skip > 0) {\n\n os->pduration = skip < os->pduration ? os->pduration - skip : 1;\n\n os->end_trimming = skip;\n\n av_log(avf, AV_LOG_DEBUG,\n\n \"Last packet was truncated to %d due to end trimming.\\n\",\n\n os->pduration);\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "1a82d2cf8fb6a7e854e7548dfcf73c3d046b34ac", + "length": 657 + }, + { + "index": 17064, + "code": "static int img_create(int argc, char **argv)\n\n{\n\n int c, ret, flags;\n\n const char *fmt = \"raw\";\n\n const char *base_fmt = NULL;\n\n const char *filename;\n\n const char *base_filename = NULL;\n\n BlockDriver *drv;\n\n QEMUOptionParameter *param = NULL;\n\n char *options = NULL;\n\n\n\n flags = 0;\n\n for(;;) {\n\n c = getopt(argc, argv, \"F:b:f:he6o:\");\n\n if (c == -1)\n\n break;\n\n switch(c) {\n\n case 'h':\n\n help();\n\n break;\n\n case 'F':\n\n base_fmt = optarg;\n\n break;\n\n case 'b':\n\n base_filename = optarg;\n\n break;\n\n case 'f':\n\n fmt = optarg;\n\n break;\n\n case 'e':\n\n flags |= BLOCK_FLAG_ENCRYPT;\n\n break;\n\n case '6':\n\n flags |= BLOCK_FLAG_COMPAT6;\n\n break;\n\n case 'o':\n\n options = optarg;\n\n break;\n\n }\n\n }\n\n\n\n /* Find driver and parse its options */\n\n drv = bdrv_find_format(fmt);\n\n if (!drv)\n\n error(\"Unknown file format '%s'\", fmt);\n\n\n\n if (options && !strcmp(options, \"?\")) {\n\n print_option_help(drv->create_options);\n\n return 0;\n\n }\n\n\n\n if (options) {\n\n param = parse_option_parameters(options, drv->create_options, param);\n\n if (param == NULL) {\n\n error(\"Invalid options for file format '%s'.\", fmt);\n\n }\n\n } else {\n\n param = parse_option_parameters(\"\", drv->create_options, param);\n\n }\n\n\n\n /* Get the filename */\n\n if (optind >= argc)\n\n help();\n\n filename = argv[optind++];\n\n\n\n /* Add size to parameters */\n\n if (optind < argc) {\n\n set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]);\n\n }\n\n\n\n /* Add old-style options to parameters */\n\n add_old_style_options(fmt, param, flags, base_filename, base_fmt);\n\n\n\n // The size for the image must always be specified, with one exception:\n\n // If we are using a backing file, we can obtain the size from there\n\n if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == 0) {\n\n\n\n QEMUOptionParameter *backing_file =\n\n get_option_parameter(param, BLOCK_OPT_BACKING_FILE);\n\n QEMUOptionParameter *backing_fmt =\n\n get_option_parameter(param, BLOCK_OPT_BACKING_FMT);\n\n\n\n if (backing_file && backing_file->value.s) {\n\n BlockDriverState *bs;\n\n uint64_t size;\n\n const char *fmt = NULL;\n\n char buf[32];\n\n\n\n if (backing_fmt && backing_fmt->value.s) {\n\n if (bdrv_find_format(backing_fmt->value.s)) {\n\n fmt = backing_fmt->value.s;\n\n } else {\n\n error(\"Unknown backing file format '%s'\",\n\n backing_fmt->value.s);\n\n }\n\n }\n\n\n\n bs = bdrv_new_open(backing_file->value.s, fmt);\n\n bdrv_get_geometry(bs, &size);\n\n size *= 512;\n\n bdrv_delete(bs);\n\n\n\n snprintf(buf, sizeof(buf), \"%\" PRId64, size);\n\n set_option_parameter(param, BLOCK_OPT_SIZE, buf);\n\n } else {\n\n error(\"Image creation needs a size parameter\");\n\n }\n\n }\n\n\n\n printf(\"Formatting '%s', fmt=%s \", filename, fmt);\n\n print_option_parameters(param);\n\n puts(\"\");\n\n\n\n ret = bdrv_create(drv, filename, param);\n\n free_option_parameters(param);\n\n\n\n if (ret < 0) {\n\n if (ret == -ENOTSUP) {\n\n error(\"Formatting or formatting option not supported for file format '%s'\", fmt);\n\n } else if (ret == -EFBIG) {\n\n error(\"The image size is too large for file format '%s'\", fmt);\n\n } else {\n\n error(\"Error while formatting\");\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "9f56640c8536a8dfb78fc05a39c1bf9921483b12", + "length": 852 + }, + { + "index": 17497, + "code": "static int decode_i_frame(FourXContext *f, AVFrame *frame, const uint8_t *buf, int length)\n\n{\n\n int x, y, ret;\n\n const int width = f->avctx->width;\n\n const int height = f->avctx->height;\n\n const unsigned int bitstream_size = AV_RL32(buf);\n\n int token_count av_unused;\n\n unsigned int prestream_size;\n\n const uint8_t *prestream;\n\n\n\n if (length < bitstream_size + 12) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"packet size too small\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n token_count = AV_RL32(buf + bitstream_size + 8);\n\n prestream_size = 4 * AV_RL32(buf + bitstream_size + 4);\n\n prestream = buf + bitstream_size + 12;\n\n\n\n if (prestream_size + bitstream_size + 12 != length\n\n || bitstream_size > (1 << 26)\n\n || prestream_size > (1 << 26)) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"size mismatch %d %d %d\\n\",\n\n prestream_size, bitstream_size, length);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n prestream = read_huffman_tables(f, prestream, prestream_size);\n\n if (!prestream) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"Error reading Huffman tables.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n init_get_bits(&f->gb, buf + 4, 8 * bitstream_size);\n\n\n\n prestream_size = length + buf - prestream;\n\n\n\n av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,\n\n prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!f->bitstream_buffer)\n\n return AVERROR(ENOMEM);\n\n f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream,\n\n prestream_size / 4);\n\n memset((uint8_t*)f->bitstream_buffer + prestream_size,\n\n 0, FF_INPUT_BUFFER_PADDING_SIZE);\n\n init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);\n\n\n\n f->last_dc = 0 * 128 * 8 * 8;\n\n\n\n for (y = 0; y < height; y += 16) {\n\n for (x = 0; x < width; x += 16) {\n\n if ((ret = decode_i_mb(f)) < 0)\n\n return ret;\n\n\n\n idct_put(f, frame, x, y);\n\n }\n\n }\n\n\n\n if (get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256)\n\n av_log(f->avctx, AV_LOG_ERROR, \"end mismatch\\n\");\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "59d7bb99b6a963b7e11c637228b2203adf535eee", + "length": 636 + }, + { + "index": 17920, + "code": "static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan,\n\n const int32_t quant_matrices[16][64], int q)\n\n{\n\n int coef_list[128];\n\n int mode_list[128];\n\n int i, t, mask, bits, ccoef, mode, sign;\n\n int list_start = 64, list_end = 64, list_pos;\n\n int coef_count = 0;\n\n int coef_idx[64];\n\n int quant_idx;\n\n const int32_t *quant;\n\n\n\n coef_list[list_end] = 4; mode_list[list_end++] = 0;\n\n coef_list[list_end] = 24; mode_list[list_end++] = 0;\n\n coef_list[list_end] = 44; mode_list[list_end++] = 0;\n\n coef_list[list_end] = 1; mode_list[list_end++] = 3;\n\n coef_list[list_end] = 2; mode_list[list_end++] = 3;\n\n coef_list[list_end] = 3; mode_list[list_end++] = 3;\n\n\n\n bits = get_bits(gb, 4) - 1;\n\n for (mask = 1 << bits; bits >= 0; mask >>= 1, bits--) {\n\n list_pos = list_start;\n\n while (list_pos < list_end) {\n\n if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) {\n\n list_pos++;\n\n continue;\n\n }\n\n ccoef = coef_list[list_pos];\n\n mode = mode_list[list_pos];\n\n switch (mode) {\n\n case 0:\n\n coef_list[list_pos] = ccoef + 4;\n\n mode_list[list_pos] = 1;\n\n case 2:\n\n if (mode == 2) {\n\n coef_list[list_pos] = 0;\n\n mode_list[list_pos++] = 0;\n\n }\n\n for (i = 0; i < 4; i++, ccoef++) {\n\n if (get_bits1(gb)) {\n\n coef_list[--list_start] = ccoef;\n\n mode_list[ list_start] = 3;\n\n } else {\n\n if (!bits) {\n\n t = 1 - (get_bits1(gb) << 1);\n\n } else {\n\n t = get_bits(gb, bits) | mask;\n\n sign = -get_bits1(gb);\n\n t = (t ^ sign) - sign;\n\n }\n\n block[scan[ccoef]] = t;\n\n coef_idx[coef_count++] = ccoef;\n\n }\n\n }\n\n break;\n\n case 1:\n\n mode_list[list_pos] = 2;\n\n for (i = 0; i < 3; i++) {\n\n ccoef += 4;\n\n coef_list[list_end] = ccoef;\n\n mode_list[list_end++] = 2;\n\n }\n\n break;\n\n case 3:\n\n if (!bits) {\n\n t = 1 - (get_bits1(gb) << 1);\n\n } else {\n\n t = get_bits(gb, bits) | mask;\n\n sign = -get_bits1(gb);\n\n t = (t ^ sign) - sign;\n\n }\n\n block[scan[ccoef]] = t;\n\n coef_idx[coef_count++] = ccoef;\n\n coef_list[list_pos] = 0;\n\n mode_list[list_pos++] = 0;\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (q == -1) {\n\n quant_idx = get_bits(gb, 4);\n\n } else {\n\n quant_idx = q;\n\n }\n\n\n\n quant = quant_matrices[quant_idx];\n\n\n\n block[0] = (block[0] * quant[0]) >> 11;\n\n for (i = 0; i < coef_count; i++) {\n\n int idx = coef_idx[i];\n\n block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3f5d6a665aba439a9309ed735e71403d236a313d", + "length": 861 + }, + { + "index": 5664, + "code": "static int opt_list(void *obj, void *av_log_obj, char *unit)\n\n{\n\n AVOption *opt=NULL;\n\n\n\n while((opt= av_next_option(obj, opt))){\n\n if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM)))\n\n continue;\n\n\n\n /* Don't print CONST's on level one.\n\n * Don't print anything but CONST's on level two.\n\n * Only print items from the requested unit.\n\n */\n\n if (!unit && opt->type==FF_OPT_TYPE_CONST)\n\n continue;\n\n else if (unit && opt->type!=FF_OPT_TYPE_CONST)\n\n continue;\n\n else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))\n\n continue;\n\n else if (unit && opt->type == FF_OPT_TYPE_CONST)\n\n av_log(av_log_obj, AV_LOG_INFO, \" %-15s \", opt->name);\n\n else\n\n av_log(av_log_obj, AV_LOG_INFO, \"-%-17s \", opt->name);\n\n\n\n switch( opt->type )\n\n {\n\n case FF_OPT_TYPE_FLAGS:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_INT:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_INT64:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_DOUBLE:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_FLOAT:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_STRING:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_RATIONAL:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n case FF_OPT_TYPE_CONST:\n\n default:\n\n av_log( av_log_obj, AV_LOG_INFO, \"%-7s \", \"\" );\n\n break;\n\n }\n\n av_log(av_log_obj, AV_LOG_INFO, \"%c\", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');\n\n av_log(av_log_obj, AV_LOG_INFO, \"%c\", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');\n\n av_log(av_log_obj, AV_LOG_INFO, \"%c\", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');\n\n av_log(av_log_obj, AV_LOG_INFO, \"%c\", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');\n\n av_log(av_log_obj, AV_LOG_INFO, \"%c\", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');\n\n\n\n if(opt->help)\n\n av_log(av_log_obj, AV_LOG_INFO, \" %s\", opt->help);\n\n av_log(av_log_obj, AV_LOG_INFO, \"\\n\");\n\n if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {\n\n opt_list(obj, av_log_obj, opt->unit);\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "a10c779f76fb5aa6d437c3cd69ac88ad17a30308", + "length": 723 + }, + { + "index": 4796, + "code": "static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)\n\n{\n\n int level, diff, i, j, run;\n\n int component;\n\n RLTable *rl = &ff_rl_mpeg1;\n\n uint8_t * const scantable = a->scantable.permutated;\n\n const uint16_t *quant_matrix = ff_mpeg1_default_intra_matrix;\n\n const int qscale = a->qscale;\n\n\n\n /* DC coefficient */\n\n if (a->version == 2) {\n\n block[0] = 2 * get_sbits(&a->gb, 10) + 1024;\n\n } else {\n\n component = (n <= 3 ? 0 : n - 4 + 1);\n\n diff = decode_dc(&a->gb, component);\n\n if (diff >= 0xffff)\n\n return AVERROR_INVALIDDATA;\n\n a->last_dc[component] += diff;\n\n block[0] = a->last_dc[component] << 3;\n\n }\n\n\n\n i = 0;\n\n {\n\n OPEN_READER(re, &a->gb);\n\n /* now quantify & encode AC coefficients */\n\n for (;;) {\n\n UPDATE_CACHE(re, &a->gb);\n\n GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);\n\n\n\n if (level == 127) {\n\n break;\n\n } else if (level != 0) {\n\n i += run;\n\n if (i > 63) {\n\n av_log(a->avctx, AV_LOG_ERROR,\n\n \"ac-tex damaged at %d %d\\n\", a->mb_x, a->mb_y);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n j = scantable[i];\n\n level = (level * qscale * quant_matrix[j]) >> 3;\n\n level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1);\n\n LAST_SKIP_BITS(re, &a->gb, 1);\n\n } else {\n\n /* escape */\n\n run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6);\n\n UPDATE_CACHE(re, &a->gb);\n\n level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10);\n\n i += run;\n\n if (i > 63) {\n\n av_log(a->avctx, AV_LOG_ERROR,\n\n \"ac-tex damaged at %d %d\\n\", a->mb_x, a->mb_y);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n j = scantable[i];\n\n if (level < 0) {\n\n level = -level;\n\n level = (level * qscale * quant_matrix[j]) >> 3;\n\n level = (level - 1) | 1;\n\n level = -level;\n\n } else {\n\n level = (level * qscale * quant_matrix[j]) >> 3;\n\n level = (level - 1) | 1;\n\n }\n\n }\n\n\n\n block[j] = level;\n\n }\n\n CLOSE_READER(re, &a->gb);\n\n }\n\n a->block_last_index[n] = i;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6ca82975b7a8eaf676a52738ec8e7e36732327cc", + "length": 727 + }, + { + "index": 21927, + "code": "static int decode_hextile(VmncContext *c, uint8_t* dst, GetByteContext *gb,\n\n int w, int h, int stride)\n\n{\n\n int i, j, k;\n\n int bg = 0, fg = 0, rects, color, flags, xy, wh;\n\n const int bpp = c->bpp2;\n\n uint8_t *dst2;\n\n int bw = 16, bh = 16;\n\n\n\n for (j = 0; j < h; j += 16) {\n\n dst2 = dst;\n\n bw = 16;\n\n if (j + 16 > h)\n\n bh = h - j;\n\n for (i = 0; i < w; i += 16, dst2 += 16 * bpp) {\n\n if (bytestream2_get_bytes_left(gb) <= 0) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (i + 16 > w)\n\n bw = w - i;\n\n flags = bytestream2_get_byte(gb);\n\n if (flags & HT_RAW) {\n\n if (bytestream2_get_bytes_left(gb) < bw * bh * bpp) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n paint_raw(dst2, bw, bh, gb, bpp, c->bigendian, stride);\n\n } else {\n\n if (flags & HT_BKG)\n\n bg = vmnc_get_pixel(gb, bpp, c->bigendian);\n\n if (flags & HT_FG)\n\n fg = vmnc_get_pixel(gb, bpp, c->bigendian);\n\n rects = 0;\n\n if (flags & HT_SUB)\n\n rects = bytestream2_get_byte(gb);\n\n color = !!(flags & HT_CLR);\n\n\n\n paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);\n\n\n\n if (bytestream2_get_bytes_left(gb) < rects * (color * bpp + 2)) {\n\n av_log(c->avctx, AV_LOG_ERROR, \"Premature end of data!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n for (k = 0; k < rects; k++) {\n\n if (color)\n\n fg = vmnc_get_pixel(gb, bpp, c->bigendian);\n\n xy = bytestream2_get_byte(gb);\n\n wh = bytestream2_get_byte(gb);\n\n paint_rect(dst2, xy >> 4, xy & 0xF,\n\n (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride);\n\n }\n\n }\n\n }\n\n dst += stride * 16;\n\n }\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f5d46d332258dcd8ca623019ece1d5e5bb74142b", + "length": 625 + }, + { + "index": 17658, + "code": "static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs,\n\n int num_reqs, MultiwriteCB *mcb)\n\n{\n\n int i, outidx;\n\n\n\n // Sort requests by start sector\n\n qsort(reqs, num_reqs, sizeof(*reqs), &multiwrite_req_compare);\n\n\n\n // Check if adjacent requests touch the same clusters. If so, combine them,\n\n // filling up gaps with zero sectors.\n\n outidx = 0;\n\n for (i = 1; i < num_reqs; i++) {\n\n int merge = 0;\n\n int64_t oldreq_last = reqs[outidx].sector + reqs[outidx].nb_sectors;\n\n\n\n // This handles the cases that are valid for all block drivers, namely\n\n // exactly sequential writes and overlapping writes.\n\n if (reqs[i].sector <= oldreq_last) {\n\n merge = 1;\n\n }\n\n\n\n // The block driver may decide that it makes sense to combine requests\n\n // even if there is a gap of some sectors between them. In this case,\n\n // the gap is filled with zeros (therefore only applicable for yet\n\n // unused space in format like qcow2).\n\n if (!merge && bs->drv->bdrv_merge_requests) {\n\n merge = bs->drv->bdrv_merge_requests(bs, &reqs[outidx], &reqs[i]);\n\n }\n\n\n\n if (reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1 > IOV_MAX) {\n\n merge = 0;\n\n }\n\n\n\n if (merge) {\n\n size_t size;\n\n QEMUIOVector *qiov = qemu_mallocz(sizeof(*qiov));\n\n qemu_iovec_init(qiov,\n\n reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1);\n\n\n\n // Add the first request to the merged one. If the requests are\n\n // overlapping, drop the last sectors of the first request.\n\n size = (reqs[i].sector - reqs[outidx].sector) << 9;\n\n qemu_iovec_concat(qiov, reqs[outidx].qiov, size);\n\n\n\n // We might need to add some zeros between the two requests\n\n if (reqs[i].sector > oldreq_last) {\n\n size_t zero_bytes = (reqs[i].sector - oldreq_last) << 9;\n\n uint8_t *buf = qemu_blockalign(bs, zero_bytes);\n\n memset(buf, 0, zero_bytes);\n\n qemu_iovec_add(qiov, buf, zero_bytes);\n\n mcb->callbacks[i].free_buf = buf;\n\n }\n\n\n\n // Add the second request\n\n qemu_iovec_concat(qiov, reqs[i].qiov, reqs[i].qiov->size);\n\n\n\n reqs[outidx].nb_sectors += reqs[i].nb_sectors;\n\n reqs[outidx].qiov = qiov;\n\n\n\n mcb->callbacks[i].free_qiov = reqs[outidx].qiov;\n\n } else {\n\n outidx++;\n\n reqs[outidx].sector = reqs[i].sector;\n\n reqs[outidx].nb_sectors = reqs[i].nb_sectors;\n\n reqs[outidx].qiov = reqs[i].qiov;\n\n }\n\n }\n\n\n\n return outidx + 1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "3e39789b64b01444b6377a043894e6b9a3ba6cbb", + "length": 719 + }, + { + "index": 23763, + "code": "void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,\n\n const char *boot_device,\n\n ISADevice *floppy, BusState *idebus0, BusState *idebus1,\n\n ISADevice *s)\n\n{\n\n int val, nb, i;\n\n FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };\n\n static pc_cmos_init_late_arg arg;\n\n\n\n /* various important CMOS locations needed by PC/Bochs bios */\n\n\n\n /* memory size */\n\n val = 640; /* base memory in K */\n\n rtc_set_memory(s, 0x15, val);\n\n rtc_set_memory(s, 0x16, val >> 8);\n\n\n\n val = (ram_size / 1024) - 1024;\n\n if (val > 65535)\n\n val = 65535;\n\n rtc_set_memory(s, 0x17, val);\n\n rtc_set_memory(s, 0x18, val >> 8);\n\n rtc_set_memory(s, 0x30, val);\n\n rtc_set_memory(s, 0x31, val >> 8);\n\n\n\n if (above_4g_mem_size) {\n\n rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);\n\n rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);\n\n rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);\n\n }\n\n\n\n if (ram_size > (16 * 1024 * 1024))\n\n val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);\n\n else\n\n val = 0;\n\n if (val > 65535)\n\n val = 65535;\n\n rtc_set_memory(s, 0x34, val);\n\n rtc_set_memory(s, 0x35, val >> 8);\n\n\n\n /* set the number of CPU */\n\n rtc_set_memory(s, 0x5f, smp_cpus - 1);\n\n\n\n /* set boot devices, and disable floppy signature check if requested */\n\n if (set_boot_dev(s, boot_device, fd_bootchk)) {\n\n exit(1);\n\n }\n\n\n\n /* floppy type */\n\n if (floppy) {\n\n for (i = 0; i < 2; i++) {\n\n fd_type[i] = isa_fdc_get_drive_type(floppy, i);\n\n }\n\n }\n\n val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |\n\n cmos_get_fd_drive_type(fd_type[1]);\n\n rtc_set_memory(s, 0x10, val);\n\n\n\n val = 0;\n\n nb = 0;\n\n if (fd_type[0] < FDRIVE_DRV_NONE) {\n\n nb++;\n\n }\n\n if (fd_type[1] < FDRIVE_DRV_NONE) {\n\n nb++;\n\n }\n\n switch (nb) {\n\n case 0:\n\n break;\n\n case 1:\n\n val |= 0x01; /* 1 drive, ready for boot */\n\n break;\n\n case 2:\n\n val |= 0x41; /* 2 drives, ready for boot */\n\n break;\n\n }\n\n val |= 0x02; /* FPU is there */\n\n val |= 0x04; /* PS/2 mouse installed */\n\n rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);\n\n\n\n /* hard drives */\n\n arg.rtc_state = s;\n\n arg.idebus[0] = idebus0;\n\n arg.idebus[1] = idebus1;\n\n qemu_register_reset(pc_cmos_init_late, &arg);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "e89001f72edde37fb36fa7c964daa1bbeb2eca26", + "length": 815 + }, + { + "index": 24241, + "code": "static inline void qtrle_decode_2n4bpp(QtrleContext *s, int stream_ptr,\n\n int row_ptr, int lines_to_change, int bpp)\n\n{\n\n int rle_code, i;\n\n int pixel_ptr;\n\n int row_inc = s->frame.linesize[0];\n\n unsigned char pi[16]; /* 16 palette indices */\n\n unsigned char *rgb = s->frame.data[0];\n\n int pixel_limit = s->frame.linesize[0] * s->avctx->height;\n\n int num_pixels = (bpp == 4) ? 8 : 16;\n\n\n\n while (lines_to_change--) {\n\n CHECK_STREAM_PTR(2);\n\n pixel_ptr = row_ptr + (num_pixels * (s->buf[stream_ptr++] - 1));\n\n\n\n\n while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {\n\n if (rle_code == 0) {\n\n /* there's another skip code in the stream */\n\n CHECK_STREAM_PTR(1);\n\n pixel_ptr += (num_pixels * (s->buf[stream_ptr++] - 1));\n\n\n } else if (rle_code < 0) {\n\n /* decode the run length code */\n\n rle_code = -rle_code;\n\n /* get the next 4 bytes from the stream, treat them as palette\n\n * indexes, and output them rle_code times */\n\n CHECK_STREAM_PTR(4);\n\n for (i = num_pixels-1; i >= 0; i--) {\n\n pi[num_pixels-1-i] = (s->buf[stream_ptr] >> ((i*bpp) & 0x07)) & ((1<>2)-1)) == 0);\n\n }\n\n CHECK_PIXEL_PTR(rle_code * num_pixels);\n\n while (rle_code--) {\n\n for (i = 0; i < num_pixels; i++)\n\n rgb[pixel_ptr++] = pi[i];\n\n }\n\n } else {\n\n /* copy the same pixel directly to output 4 times */\n\n rle_code *= 4;\n\n CHECK_STREAM_PTR(rle_code);\n\n CHECK_PIXEL_PTR(rle_code*(num_pixels>>2));\n\n while (rle_code--) {\n\n if(bpp == 4) {\n\n rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x0f;\n\n rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x0f;\n\n } else {\n\n rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 6) & 0x03;\n\n rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 4) & 0x03;\n\n rgb[pixel_ptr++] = ((s->buf[stream_ptr]) >> 2) & 0x03;\n\n rgb[pixel_ptr++] = (s->buf[stream_ptr++]) & 0x03;\n\n }\n\n }\n\n }\n\n }\n\n row_ptr += row_inc;\n\n }\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "7fb92be7e50ea4ba5712804326c6814ae02dd190", + "length": 662 + }, + { + "index": 3749, + "code": "static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)\n\n{\n\n struct vmsvga_state_s *s = opaque;\n\n switch (s->index) {\n\n case SVGA_REG_ID:\n\n if (value == SVGA_ID_2 || value == SVGA_ID_1 || value == SVGA_ID_0)\n\n s->svgaid = value;\n\n break;\n\n\n\n case SVGA_REG_ENABLE:\n\n s->enable = value;\n\n s->config &= !!value;\n\n s->width = -1;\n\n s->height = -1;\n\n s->invalidated = 1;\n\n s->vga.invalidate(&s->vga);\n\n if (s->enable) {\n\n s->fb_size = ((s->depth + 7) >> 3) * s->new_width * s->new_height;\n\n vga_dirty_log_stop(&s->vga);\n\n } else {\n\n vga_dirty_log_start(&s->vga);\n\n }\n\n break;\n\n\n\n case SVGA_REG_WIDTH:\n\n s->new_width = value;\n\n s->invalidated = 1;\n\n break;\n\n\n\n case SVGA_REG_HEIGHT:\n\n s->new_height = value;\n\n s->invalidated = 1;\n\n break;\n\n\n\n case SVGA_REG_DEPTH:\n\n case SVGA_REG_BITS_PER_PIXEL:\n\n if (value != s->depth) {\n\n printf(\"%s: Bad colour depth: %i bits\\n\", __FUNCTION__, value);\n\n s->config = 0;\n\n }\n\n break;\n\n\n\n case SVGA_REG_CONFIG_DONE:\n\n if (value) {\n\n s->fifo = (uint32_t *) s->fifo_ptr;\n\n /* Check range and alignment. */\n\n if ((CMD(min) | CMD(max) |\n\n CMD(next_cmd) | CMD(stop)) & 3)\n\n break;\n\n if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo)\n\n break;\n\n if (CMD(max) > SVGA_FIFO_SIZE)\n\n break;\n\n if (CMD(max) < CMD(min) + 10 * 1024)\n\n break;\n\n }\n\n s->config = !!value;\n\n break;\n\n\n\n case SVGA_REG_SYNC:\n\n s->syncing = 1;\n\n vmsvga_fifo_run(s); /* Or should we just wait for update_display? */\n\n break;\n\n\n\n case SVGA_REG_GUEST_ID:\n\n s->guest = value;\n\n#ifdef VERBOSE\n\n if (value >= GUEST_OS_BASE && value < GUEST_OS_BASE +\n\n ARRAY_SIZE(vmsvga_guest_id))\n\n printf(\"%s: guest runs %s.\\n\", __FUNCTION__,\n\n vmsvga_guest_id[value - GUEST_OS_BASE]);\n\n#endif\n\n break;\n\n\n\n case SVGA_REG_CURSOR_ID:\n\n s->cursor.id = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_X:\n\n s->cursor.x = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_Y:\n\n s->cursor.y = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_ON:\n\n s->cursor.on |= (value == SVGA_CURSOR_ON_SHOW);\n\n s->cursor.on &= (value != SVGA_CURSOR_ON_HIDE);\n\n#ifdef HW_MOUSE_ACCEL\n\n if (value <= SVGA_CURSOR_ON_SHOW) {\n\n dpy_mouse_set(s->vga.ds, s->cursor.x, s->cursor.y, s->cursor.on);\n\n }\n\n#endif\n\n break;\n\n\n\n case SVGA_REG_MEM_REGS:\n\n case SVGA_REG_NUM_DISPLAYS:\n\n case SVGA_REG_PITCHLOCK:\n\n case SVGA_PALETTE_BASE ... SVGA_PALETTE_END:\n\n break;\n\n\n\n default:\n\n if (s->index >= SVGA_SCRATCH_BASE &&\n\n s->index < SVGA_SCRATCH_BASE + s->scratch_size) {\n\n s->scratch[s->index - SVGA_SCRATCH_BASE] = value;\n\n break;\n\n }\n\n printf(\"%s: Bad register %02x\\n\", __FUNCTION__, s->index);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "0d7937974cd0504f30ad483c3368b21da426ddf9", + "length": 862 + }, + { + "index": 26481, + "code": "static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,\n\n AVDictionary *opts, AVDictionary *opts2, int *is_http)\n\n{\n\n HLSContext *c = s->priv_data;\n\n AVDictionary *tmp = NULL;\n\n const char *proto_name = NULL;\n\n int ret;\n\n\n\n av_dict_copy(&tmp, opts, 0);\n\n av_dict_copy(&tmp, opts2, 0);\n\n\n\n if (av_strstart(url, \"crypto\", NULL)) {\n\n if (url[6] == '+' || url[6] == ':')\n\n proto_name = avio_find_protocol_name(url + 7);\n\n }\n\n\n\n if (!proto_name)\n\n proto_name = avio_find_protocol_name(url);\n\n\n\n if (!proto_name)\n\n return AVERROR_INVALIDDATA;\n\n\n\n // only http(s) & file are allowed\n\n if (av_strstart(proto_name, \"file\", NULL)) {\n\n if (strcmp(c->allowed_extensions, \"ALL\") && !av_match_ext(url, c->allowed_extensions)) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Filename extension of \\'%s\\' is not a common multimedia extension, blocked for security reasons.\\n\"\n\n \"If you wish to override this adjust allowed_extensions, you can set it to \\'ALL\\' to allow all\\n\",\n\n url);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n } else if (av_strstart(proto_name, \"http\", NULL)) {\n\n ;\n\n } else\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')\n\n ;\n\n else if (av_strstart(url, \"crypto\", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')\n\n ;\n\n else if (strcmp(proto_name, \"file\") || !strncmp(url, \"file,\", 5))\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (c->http_persistent && *pb && av_strstart(proto_name, \"http\", NULL)) {\n\n ret = open_url_keepalive(c->ctx, pb, url);\n\n if (ret == AVERROR_EXIT) {\n\n return ret;\n\n } else if (ret < 0) {\n\n if (ret != AVERROR_EOF)\n\n av_log(s, AV_LOG_WARNING,\n\n \"keepalive request failed for '%s', retrying with new connection: %s\\n\",\n\n url, av_err2str(ret));\n\n ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);\n\n }\n\n } else {\n\n ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);\n\n }\n\n if (ret >= 0) {\n\n // update cookies on http response with setcookies.\n\n char *new_cookies = NULL;\n\n\n\n if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))\n\n av_opt_get(*pb, \"cookies\", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);\n\n\n\n if (new_cookies) {\n\n av_free(c->cookies);\n\n c->cookies = new_cookies;\n\n }\n\n\n\n av_dict_set(&opts, \"cookies\", c->cookies, 0);\n\n }\n\n\n\n av_dict_free(&tmp);\n\n\n\n if (is_http)\n\n *is_http = av_strstart(proto_name, \"http\", NULL);\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2f9ca64556cba9a7edcca9a1c55923a60022937d", + "length": 725 + }, + { + "index": 457, + "code": "static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,\n\n VAAPIEncodePicture *pic,\n\n VAAPIEncodeSlice *slice)\n\n{\n\n VAAPIEncodeContext *ctx = avctx->priv_data;\n\n VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;\n\n VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;\n\n VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;\n\n VAAPIEncodeH264Context *priv = ctx->priv_data;\n\n VAAPIEncodeH264Slice *pslice;\n\n VAAPIEncodeH264MiscSliceParams *mslice;\n\n int i;\n\n\n\n slice->priv_data = av_mallocz(sizeof(*pslice));\n\n if (!slice->priv_data)\n\n return AVERROR(ENOMEM);\n\n pslice = slice->priv_data;\n\n mslice = &pslice->misc_slice_params;\n\n\n\n if (pic->type == PICTURE_TYPE_IDR)\n\n mslice->nal_unit_type = H264_NAL_IDR_SLICE;\n\n else\n\n mslice->nal_unit_type = H264_NAL_SLICE;\n\n\n\n switch (pic->type) {\n\n case PICTURE_TYPE_IDR:\n\n vslice->slice_type = SLICE_TYPE_I;\n\n mslice->nal_ref_idc = 3;\n\n break;\n\n case PICTURE_TYPE_I:\n\n vslice->slice_type = SLICE_TYPE_I;\n\n mslice->nal_ref_idc = 2;\n\n break;\n\n case PICTURE_TYPE_P:\n\n vslice->slice_type = SLICE_TYPE_P;\n\n mslice->nal_ref_idc = 1;\n\n break;\n\n case PICTURE_TYPE_B:\n\n vslice->slice_type = SLICE_TYPE_B;\n\n mslice->nal_ref_idc = 0;\n\n break;\n\n default:\n\n av_assert0(0 && \"invalid picture type\");\n\n }\n\n\n\n // Only one slice per frame.\n\n vslice->macroblock_address = 0;\n\n vslice->num_macroblocks = priv->mb_width * priv->mb_height;\n\n\n\n vslice->macroblock_info = VA_INVALID_ID;\n\n\n\n vslice->pic_parameter_set_id = vpic->pic_parameter_set_id;\n\n vslice->idr_pic_id = priv->idr_pic_count++;\n\n\n\n vslice->pic_order_cnt_lsb = pic->display_order &\n\n ((1 << (4 + vseq->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4)) - 1);\n\n\n\n for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {\n\n vslice->RefPicList0[i].picture_id = VA_INVALID_ID;\n\n vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;\n\n vslice->RefPicList1[i].picture_id = VA_INVALID_ID;\n\n vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;\n\n }\n\n\n\n av_assert0(pic->nb_refs <= 2);\n\n if (pic->nb_refs >= 1) {\n\n // Backward reference for P- or B-frame.\n\n av_assert0(pic->type == PICTURE_TYPE_P ||\n\n pic->type == PICTURE_TYPE_B);\n\n\n\n vslice->num_ref_idx_l0_active_minus1 = 0;\n\n vslice->RefPicList0[0] = vpic->ReferenceFrames[0];\n\n }\n\n if (pic->nb_refs >= 2) {\n\n // Forward reference for B-frame.\n\n av_assert0(pic->type == PICTURE_TYPE_B);\n\n\n\n vslice->num_ref_idx_l1_active_minus1 = 0;\n\n vslice->RefPicList1[0] = vpic->ReferenceFrames[1];\n\n }\n\n\n\n if (pic->type == PICTURE_TYPE_B)\n\n vslice->slice_qp_delta = priv->fixed_qp_b - vpic->pic_init_qp;\n\n else if (pic->type == PICTURE_TYPE_P)\n\n vslice->slice_qp_delta = priv->fixed_qp_p - vpic->pic_init_qp;\n\n else\n\n vslice->slice_qp_delta = priv->fixed_qp_idr - vpic->pic_init_qp;\n\n\n\n vslice->direct_spatial_mv_pred_flag = 1;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e72662e131e5099e34d5a7519c5690d2fff7b83f", + "length": 932 + }, + { + "index": 1601, + "code": "static int huf_decode(const uint64_t *hcode, const HufDec *hdecod,\n\n GetByteContext *gb, int nbits,\n\n int rlc, int no, uint16_t *out)\n\n{\n\n uint64_t c = 0;\n\n uint16_t *outb = out;\n\n uint16_t *oe = out + no;\n\n const uint8_t *ie = gb->buffer + (nbits + 7) / 8; // input byte size\n\n uint8_t cs, s;\n\n int i, lc = 0;\n\n\n\n while (gb->buffer < ie) {\n\n get_char(c, lc, gb);\n\n\n\n while (lc >= HUF_DECBITS) {\n\n const HufDec pl = hdecod[(c >> (lc - HUF_DECBITS)) & HUF_DECMASK];\n\n\n\n if (pl.len) {\n\n lc -= pl.len;\n\n get_code(pl.lit, rlc, c, lc, gb, out, oe);\n\n } else {\n\n int j;\n\n\n\n if (!pl.p)\n\n return AVERROR_INVALIDDATA;\n\n\n\n for (j = 0; j < pl.lit; j++) {\n\n int l = hcode[pl.p[j]] & 63;\n\n\n\n while (lc < l && bytestream2_get_bytes_left(gb) > 0)\n\n get_char(c, lc, gb);\n\n\n\n if (lc >= l) {\n\n if ((hcode[pl.p[j]] >> 6) ==\n\n ((c >> (lc - l)) & ((1LL << l) - 1))) {\n\n lc -= l;\n\n get_code(pl.p[j], rlc, c, lc, gb, out, oe);\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (j == pl.lit)\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n }\n\n\n\n i = (8 - nbits) & 7;\n\n c >>= i;\n\n lc -= i;\n\n\n\n while (lc > 0) {\n\n const HufDec pl = hdecod[(c << (HUF_DECBITS - lc)) & HUF_DECMASK];\n\n\n\n if (pl.len) {\n\n lc -= pl.len;\n\n get_code(pl.lit, rlc, c, lc, gb, out, oe);\n\n } else {\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n if (out - outb != no)\n\n return AVERROR_INVALIDDATA;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "5ea59b1f424f0efc7805d837e6fdb80561fb0f3a", + "length": 539 + }, + { + "index": 10453, + "code": "static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *int_mask)\n\n{\n\n UHCIAsync *async;\n\n int len = 0, max_len;\n\n uint8_t pid;\n\n USBDevice *dev;\n\n USBEndpoint *ep;\n\n\n\n /* Is active ? */\n\n if (!(td->ctrl & TD_CTRL_ACTIVE))\n\n return TD_RESULT_NEXT_QH;\n\n\n\n async = uhci_async_find_td(s, addr, td);\n\n if (async) {\n\n /* Already submitted */\n\n async->queue->valid = 32;\n\n\n\n if (!async->done)\n\n return TD_RESULT_ASYNC_CONT;\n\n\n\n uhci_async_unlink(async);\n\n goto done;\n\n }\n\n\n\n /* Allocate new packet */\n\n async = uhci_async_alloc(uhci_queue_get(s, td), addr);\n\n if (!async)\n\n return TD_RESULT_NEXT_QH;\n\n\n\n /* valid needs to be large enough to handle 10 frame delay\n\n * for initial isochronous requests\n\n */\n\n async->queue->valid = 32;\n\n async->isoc = td->ctrl & TD_CTRL_IOS;\n\n\n\n max_len = ((td->token >> 21) + 1) & 0x7ff;\n\n pid = td->token & 0xff;\n\n\n\n dev = uhci_find_device(s, (td->token >> 8) & 0x7f);\n\n ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf);\n\n usb_packet_setup(&async->packet, pid, ep);\n\n qemu_sglist_add(&async->sgl, td->buffer, max_len);\n\n usb_packet_map(&async->packet, &async->sgl);\n\n\n\n switch(pid) {\n\n case USB_TOKEN_OUT:\n\n case USB_TOKEN_SETUP:\n\n len = usb_handle_packet(dev, &async->packet);\n\n if (len >= 0)\n\n len = max_len;\n\n break;\n\n\n\n case USB_TOKEN_IN:\n\n len = usb_handle_packet(dev, &async->packet);\n\n break;\n\n\n\n default:\n\n /* invalid pid : frame interrupted */\n\n uhci_async_free(async);\n\n s->status |= UHCI_STS_HCPERR;\n\n uhci_update_irq(s);\n\n return TD_RESULT_STOP_FRAME;\n\n }\n\n \n\n if (len == USB_RET_ASYNC) {\n\n uhci_async_link(async);\n\n return TD_RESULT_ASYNC_START;\n\n }\n\n\n\n async->packet.result = len;\n\n\n\ndone:\n\n len = uhci_complete_td(s, td, async, int_mask);\n\n usb_packet_unmap(&async->packet);\n\n uhci_async_free(async);\n\n return len;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "6c60134091cb2754d810b012773754967d8bbf92", + "length": 560 + }, + { + "index": 5432, + "code": "static int oggvorbis_encode_frame(AVCodecContext *avccontext,\n\n\t\t\t\t unsigned char *packets,\n\n\t\t\t int buf_size, void *data)\n\n{\n\n OggVorbisContext *context = avccontext->priv_data ;\n\n float **buffer ;\n\n ogg_packet op ;\n\n signed char *audio = data ;\n\n int l, samples = OGGVORBIS_FRAME_SIZE ;\n\n\n\n buffer = vorbis_analysis_buffer(&context->vd, samples) ;\n\n\n\n if(context->vi.channels == 1) {\n\n\tfor(l = 0 ; l < samples ; l++)\n\n\t buffer[0][l]=((audio[l*2+1]<<8)|(0x00ff&(int)audio[l*2]))/32768.f;\n\n } else {\n\n\tfor(l = 0 ; l < samples ; l++){\n\n\t buffer[0][l]=((audio[l*4+1]<<8)|(0x00ff&(int)audio[l*4]))/32768.f;\n\n\t buffer[1][l]=((audio[l*4+3]<<8)|(0x00ff&(int)audio[l*4+2]))/32768.f;\n\n\t}\n\n }\n\n \n\n vorbis_analysis_wrote(&context->vd, samples) ; \n\n\n\n while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {\n\n\tvorbis_analysis(&context->vb, NULL);\n\n\tvorbis_bitrate_addblock(&context->vb) ;\n\n\n\n\twhile(vorbis_bitrate_flushpacket(&context->vd, &op)) {\n\n memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));\n\n context->buffer_index += sizeof(ogg_packet);\n\n memcpy(context->buffer + context->buffer_index, op.packet, op.bytes);\n\n context->buffer_index += op.bytes;\n\n// av_log(avccontext, AV_LOG_DEBUG, \"e%d / %d\\n\", context->buffer_index, op.bytes);\n\n\t}\n\n }\n\n\n\n if(context->buffer_index){\n\n ogg_packet *op2= (ogg_packet*)context->buffer;\n\n op2->packet = context->buffer + sizeof(ogg_packet);\n\n l= op2->bytes;\n\n \n\n memcpy(packets, op2->packet, l);\n\n context->buffer_index -= l + sizeof(ogg_packet);\n\n memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index);\n\n \n\n// av_log(avccontext, AV_LOG_DEBUG, \"E%d\\n\", l);\n\n return l;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3f4993f19b609180ff0f92486ea8bbac9e531db2", + "length": 546 + }, + { + "index": 203, + "code": "int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame,\n\n int64_t pts, AVRational pixel_aspect, int width,\n\n int height, enum PixelFormat pix_fmt,\n\n const char *sws_param)\n\n{\n\n BufferSourceContext *c = buffer_filter->priv;\n\n int ret;\n\n\n\n if (c->has_frame) {\n\n av_log(buffer_filter, AV_LOG_ERROR,\n\n \"Buffering several frames is not supported. \"\n\n \"Please consume all available frames before adding a new one.\\n\"\n\n );\n\n //return -1;\n\n }\n\n\n\n if(width != c->w || height != c->h || pix_fmt != c->pix_fmt){\n\n AVFilterContext *scale= buffer_filter->outputs[0]->dst;\n\n AVFilterLink *link;\n\n\n\n av_log(buffer_filter, AV_LOG_INFO, \"Changing filter graph input to accept %dx%d %d (%d %d)\\n\",\n\n width,height,pix_fmt, c->pix_fmt, scale->outputs[0]->format);\n\n\n\n if(!scale || strcmp(scale->filter->name,\"scale\")){\n\n AVFilter *f= avfilter_get_by_name(\"scale\");\n\n\n\n av_log(buffer_filter, AV_LOG_INFO, \"Inserting scaler filter\\n\");\n\n if(avfilter_open(&scale, f, \"Input equalizer\") < 0)\n\n return -1;\n\n\n\n if((ret=avfilter_init_filter(scale, sws_param, NULL))<0){\n\n avfilter_free(scale);\n\n return ret;\n\n }\n\n\n\n if((ret=avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0))<0){\n\n avfilter_free(scale);\n\n return ret;\n\n }\n\n\n\n scale->outputs[0]->format= c->pix_fmt;\n\n }\n\n\n\n c->pix_fmt= scale->inputs[0]->format= pix_fmt;\n\n c->w= scale->inputs[0]->w= width;\n\n c->h= scale->inputs[0]->h= height;\n\n\n\n link= scale->outputs[0];\n\n if ((ret = link->srcpad->config_props(link)) < 0)\n\n return ret;\n\n }\n\n\n\n memcpy(c->frame.data , frame->data , sizeof(frame->data));\n\n memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));\n\n c->frame.interlaced_frame= frame->interlaced_frame;\n\n c->frame.top_field_first = frame->top_field_first;\n\n c->frame.key_frame = frame->key_frame;\n\n c->frame.pict_type = frame->pict_type;\n\n c->pts = pts;\n\n c->pixel_aspect = pixel_aspect;\n\n c->has_frame = 1;\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ad0193bf9cb258695a7f929954edd6e2e51de4d9", + "length": 584 + }, + { + "index": 10753, + "code": "static int encode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])\n\n{\n\n int x, y, p, i;\n\n const int ring_size = s->avctx->context_model ? 3 : 2;\n\n int16_t *sample[4][3];\n\n int lbd = s->bits_per_raw_sample <= 8;\n\n int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;\n\n int offset = 1 << bits;\n\n\n\n s->run_index = 0;\n\n\n\n memset(s->sample_buffer, 0, ring_size * MAX_PLANES *\n\n (w + 6) * sizeof(*s->sample_buffer));\n\n\n\n for (y = 0; y < h; y++) {\n\n for (i = 0; i < ring_size; i++)\n\n for (p = 0; p < MAX_PLANES; p++)\n\n sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;\n\n\n\n for (x = 0; x < w; x++) {\n\n int b, g, r, av_uninit(a);\n\n if (lbd) {\n\n unsigned v = *((uint32_t*)(src[0] + x*4 + stride[0]*y));\n\n b = v & 0xFF;\n\n g = (v >> 8) & 0xFF;\n\n r = (v >> 16) & 0xFF;\n\n a = v >> 24;\n\n } else {\n\n b = *((uint16_t*)(src[0] + x*2 + stride[0]*y));\n\n g = *((uint16_t*)(src[1] + x*2 + stride[1]*y));\n\n r = *((uint16_t*)(src[2] + x*2 + stride[2]*y));\n\n }\n\n\n\n b -= g;\n\n r -= g;\n\n g += (b + r) >> 2;\n\n b += offset;\n\n r += offset;\n\n\n\n sample[0][0][x] = g;\n\n sample[1][0][x] = b;\n\n sample[2][0][x] = r;\n\n sample[3][0][x] = a;\n\n }\n\n for (p = 0; p < 3 + s->transparency; p++) {\n\n int ret;\n\n sample[p][0][-1] = sample[p][1][0 ];\n\n sample[p][1][ w] = sample[p][1][w-1];\n\n if (lbd)\n\n ret = encode_line(s, w, sample[p], (p + 1) / 2, 9);\n\n else\n\n ret = encode_line(s, w, sample[p], (p + 1) / 2, bits + 1);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3576b564ec4ffa98402b02b3a69171cefd103eb0", + "length": 660 + }, + { + "index": 4999, + "code": "static void tcg_out_qemu_st (TCGContext *s, const TCGArg *args, int opc)\n\n{\n\n int addr_reg, r0, r1, data_reg, data_reg2, bswap, rbase;\n\n#ifdef CONFIG_SOFTMMU\n\n int mem_index, r2, addr_reg2;\n\n uint8_t *label_ptr;\n\n#endif\n\n\n\n data_reg = *args++;\n\n if (opc == 3)\n\n data_reg2 = *args++;\n\n else\n\n data_reg2 = 0;\n\n addr_reg = *args++;\n\n\n\n#ifdef CONFIG_SOFTMMU\n\n#if TARGET_LONG_BITS == 64\n\n addr_reg2 = *args++;\n\n#else\n\n addr_reg2 = 0;\n\n#endif\n\n mem_index = *args;\n\n r0 = 3;\n\n r1 = 4;\n\n r2 = 0;\n\n rbase = 0;\n\n\n\n tcg_out_tlb_check (\n\n s, r0, r1, r2, addr_reg, addr_reg2, opc & 3,\n\n offsetof (CPUArchState, tlb_table[mem_index][0].addr_write),\n\n offsetof (CPUTLBEntry, addend) - offsetof (CPUTLBEntry, addr_write),\n\n &label_ptr\n\n );\n\n#else /* !CONFIG_SOFTMMU */\n\n r0 = addr_reg;\n\n r1 = 3;\n\n rbase = GUEST_BASE ? TCG_GUEST_BASE_REG : 0;\n\n#endif\n\n\n\n#ifdef TARGET_WORDS_BIGENDIAN\n\n bswap = 0;\n\n#else\n\n bswap = 1;\n\n#endif\n\n switch (opc) {\n\n case 0:\n\n tcg_out32 (s, STBX | SAB (data_reg, rbase, r0));\n\n break;\n\n case 1:\n\n if (bswap)\n\n tcg_out32 (s, STHBRX | SAB (data_reg, rbase, r0));\n\n else\n\n tcg_out32 (s, STHX | SAB (data_reg, rbase, r0));\n\n break;\n\n case 2:\n\n if (bswap)\n\n tcg_out32 (s, STWBRX | SAB (data_reg, rbase, r0));\n\n else\n\n tcg_out32 (s, STWX | SAB (data_reg, rbase, r0));\n\n break;\n\n case 3:\n\n if (bswap) {\n\n tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);\n\n tcg_out32 (s, STWBRX | SAB (data_reg, rbase, r0));\n\n tcg_out32 (s, STWBRX | SAB (data_reg2, rbase, r1));\n\n }\n\n else {\n\n#ifdef CONFIG_USE_GUEST_BASE\n\n tcg_out32 (s, STWX | SAB (data_reg2, rbase, r0));\n\n tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);\n\n tcg_out32 (s, STWX | SAB (data_reg, rbase, r1));\n\n#else\n\n tcg_out32 (s, STW | RS (data_reg2) | RA (r0));\n\n tcg_out32 (s, STW | RS (data_reg) | RA (r0) | 4);\n\n#endif\n\n }\n\n break;\n\n }\n\n\n\n#ifdef CONFIG_SOFTMMU\n\n add_qemu_ldst_label (s,\n\n 0,\n\n opc,\n\n data_reg,\n\n data_reg2,\n\n addr_reg,\n\n addr_reg2,\n\n mem_index,\n\n s->code_ptr,\n\n label_ptr);\n\n#endif\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "8f50c841b374dc90ea604888ca92c37f469c428a", + "length": 800 + }, + { + "index": 15125, + "code": "static int latm_write_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n AVIOContext *pb = s->pb;\n\n PutBitContext bs;\n\n int i, len;\n\n uint8_t loas_header[] = \"\\x56\\xe0\\x00\";\n\n uint8_t *buf = NULL;\n\n\n\n if (s->streams[0]->codec->codec_id == CODEC_ID_AAC_LATM)\n\n return ff_raw_write_packet(s, pkt);\n\n\n\n if (pkt->size > 2 && pkt->data[0] == 0xff && (pkt->data[1] >> 4) == 0xf) {\n\n av_log(s, AV_LOG_ERROR, \"ADTS header detected - ADTS will not be incorrectly muxed into LATM\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (pkt->size > 0x1fff)\n\n goto too_large;\n\n\n\n buf = av_malloc(pkt->size+1024);\n\n if (!buf)\n\n return AVERROR(ENOMEM);\n\n\n\n init_put_bits(&bs, buf, pkt->size+1024);\n\n\n\n latm_write_frame_header(s, &bs);\n\n\n\n /* PayloadLengthInfo() */\n\n for (i = 0; i <= pkt->size-255; i+=255)\n\n put_bits(&bs, 8, 255);\n\n\n\n put_bits(&bs, 8, pkt->size-i);\n\n\n\n /* The LATM payload is written unaligned */\n\n\n\n /* PayloadMux() */\n\n if (pkt->size && (pkt->data[0] & 0xe1) == 0x81) {\n\n // Convert byte-aligned DSE to non-aligned.\n\n // Due to the input format encoding we know that\n\n // it is naturally byte-aligned in the input stream,\n\n // so there are no padding bits to account for.\n\n // To avoid having to add padding bits and rearrange\n\n // the whole stream we just remove the byte-align flag.\n\n // This allows us to remux our FATE AAC samples into latm\n\n // files that are still playable with minimal effort.\n\n put_bits(&bs, 8, pkt->data[0] & 0xfe);\n\n avpriv_copy_bits(&bs, pkt->data + 1, 8*pkt->size - 8);\n\n } else\n\n avpriv_copy_bits(&bs, pkt->data, 8*pkt->size);\n\n\n\n avpriv_align_put_bits(&bs);\n\n flush_put_bits(&bs);\n\n\n\n len = put_bits_count(&bs) >> 3;\n\n\n\n if (len > 0x1fff)\n\n goto too_large;\n\n\n\n loas_header[1] |= (len >> 8) & 0x1f;\n\n loas_header[2] |= len & 0xff;\n\n\n\n avio_write(pb, loas_header, 3);\n\n avio_write(pb, buf, len);\n\n\n\n av_free(buf);\n\n\n\n return 0;\n\n\n\ntoo_large:\n\n av_log(s, AV_LOG_ERROR, \"LATM packet size larger than maximum size 0x1fff\\n\");\n\n av_free(buf);\n\n return AVERROR_INVALIDDATA;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "d1a58afb95f68c5375b4a7556317d835108509ed", + "length": 666 + }, + { + "index": 20625, + "code": "static void put_codebook_header(PutBitContext * pb, codebook_t * cb) {\n\n int i;\n\n int ordered = 0;\n\n\n\n put_bits(pb, 24, 0x564342); //magic\n\n put_bits(pb, 16, cb->ndimentions);\n\n put_bits(pb, 24, cb->nentries);\n\n\n\n for (i = 1; i < cb->nentries; i++) if (cb->entries[i].len < cb->entries[i-1].len) break;\n\n if (i == cb->nentries) ordered = 1;\n\n\n\n put_bits(pb, 1, ordered);\n\n if (ordered) {\n\n int len = cb->entries[0].len;\n\n put_bits(pb, 5, len);\n\n i = 0;\n\n while (i < cb->nentries) {\n\n int j;\n\n for (j = 0; j+i < cb->nentries; j++) if (cb->entries[j+i].len != len) break;\n\n put_bits(pb, ilog(cb->nentries - i), j);\n\n i += j;\n\n len++;\n\n }\n\n } else {\n\n int sparse = 0;\n\n for (i = 0; i < cb->nentries; i++) if (!cb->entries[i].len) break;\n\n if (i != cb->nentries) sparse = 1;\n\n put_bits(pb, 1, sparse);\n\n\n\n for (i = 0; i < cb->nentries; i++) {\n\n if (sparse) put_bits(pb, 1, !!cb->entries[i].len);\n\n if (cb->entries[i].len) put_bits(pb, 5, cb->entries[i].len - 1);\n\n }\n\n }\n\n\n\n put_bits(pb, 4, cb->lookup);\n\n if (cb->lookup) {\n\n int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n\n int bits = ilog(cb->quantlist[0]);\n\n\n\n for (i = 1; i < tmp; i++) bits = FFMAX(bits, ilog(cb->quantlist[i]));\n\n\n\n put_float(pb, cb->min);\n\n put_float(pb, cb->delta);\n\n\n\n put_bits(pb, 4, bits - 1);\n\n put_bits(pb, 1, cb->seq_p);\n\n\n\n for (i = 0; i < tmp; i++) put_bits(pb, bits, cb->quantlist[i]);\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "0e6fd0f12f90ba6a2edf79a398186293f2ab6334", + "length": 536 + }, + { + "index": 24989, + "code": "static void uhci_process_frame(UHCIState *s)\n\n{\n\n uint32_t frame_addr, link, old_td_ctrl, val, int_mask;\n\n uint32_t curr_qh, td_count = 0;\n\n int cnt, ret;\n\n UHCI_TD td;\n\n UHCI_QH qh;\n\n QhDb qhdb;\n\n\n\n frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2);\n\n\n\n pci_dma_read(&s->dev, frame_addr, &link, 4);\n\n le32_to_cpus(&link);\n\n\n\n int_mask = 0;\n\n curr_qh = 0;\n\n\n\n qhdb_reset(&qhdb);\n\n\n\n for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) {\n\n if (s->frame_bytes >= s->frame_bandwidth) {\n\n /* We've reached the usb 1.1 bandwidth, which is\n\n 1280 bytes/frame, stop processing */\n\n trace_usb_uhci_frame_stop_bandwidth();\n\n break;\n\n }\n\n if (is_qh(link)) {\n\n /* QH */\n\n trace_usb_uhci_qh_load(link & ~0xf);\n\n\n\n if (qhdb_insert(&qhdb, link)) {\n\n /*\n\n * We're going in circles. Which is not a bug because\n\n * HCD is allowed to do that as part of the BW management.\n\n *\n\n * Stop processing here if no transaction has been done\n\n * since we've been here last time.\n\n */\n\n if (td_count == 0) {\n\n trace_usb_uhci_frame_loop_stop_idle();\n\n break;\n\n } else {\n\n trace_usb_uhci_frame_loop_continue();\n\n td_count = 0;\n\n qhdb_reset(&qhdb);\n\n qhdb_insert(&qhdb, link);\n\n }\n\n }\n\n\n\n pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh));\n\n le32_to_cpus(&qh.link);\n\n le32_to_cpus(&qh.el_link);\n\n\n\n if (!is_valid(qh.el_link)) {\n\n /* QH w/o elements */\n\n curr_qh = 0;\n\n link = qh.link;\n\n } else {\n\n /* QH with elements */\n\n \tcurr_qh = link;\n\n \tlink = qh.el_link;\n\n }\n\n continue;\n\n }\n\n\n\n /* TD */\n\n uhci_read_td(s, &td, link);\n\n trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token);\n\n\n\n old_td_ctrl = td.ctrl;\n\n ret = uhci_handle_td(s, NULL, &td, link, &int_mask);\n\n if (old_td_ctrl != td.ctrl) {\n\n /* update the status bits of the TD */\n\n val = cpu_to_le32(td.ctrl);\n\n pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val));\n\n }\n\n\n\n switch (ret) {\n\n case TD_RESULT_STOP_FRAME: /* interrupted frame */\n\n goto out;\n\n\n\n case TD_RESULT_NEXT_QH:\n\n case TD_RESULT_ASYNC_CONT:\n\n trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf);\n\n link = curr_qh ? qh.link : td.link;\n\n continue;\n\n\n\n case TD_RESULT_ASYNC_START:\n\n trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf);\n\n link = curr_qh ? qh.link : td.link;\n\n continue;\n\n\n\n case TD_RESULT_COMPLETE:\n\n trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf);\n\n link = td.link;\n\n td_count++;\n\n s->frame_bytes += (td.ctrl & 0x7ff) + 1;\n\n\n\n if (curr_qh) {\n\n /* update QH element link */\n\n qh.el_link = link;\n\n val = cpu_to_le32(qh.el_link);\n\n pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val));\n\n\n\n if (!depth_first(link)) {\n\n /* done with this QH */\n\n curr_qh = 0;\n\n link = qh.link;\n\n }\n\n }\n\n break;\n\n\n\n default:\n\n assert(!\"unknown return code\");\n\n }\n\n\n\n /* go to the next entry */\n\n }\n\n\n\nout:\n\n s->pending_int_mask |= int_mask;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "66a08cbe6ad1aebec8eecf58b3ba042e19dd1649", + "length": 950 + }, + { + "index": 22676, + "code": "static void fill_prefetch_fifo(struct omap_gpmc_s *s)\n{\n /* Fill the prefetch FIFO by reading data from NAND.\n * We do this synchronously, unlike the hardware which\n * will do this asynchronously. We refill when the\n * FIFO has THRESHOLD bytes free, and we always refill\n * as much data as possible starting at the top end\n * of the FIFO.\n * (We have to refill at THRESHOLD rather than waiting\n * for the FIFO to empty to allow for the case where\n * the FIFO size isn't an exact multiple of THRESHOLD\n * and we're doing DMA transfers.)\n * This means we never need to handle wrap-around in\n * the fifo-reading code, and the next byte of data\n * to read is always fifo[63 - fifopointer].\n */\n int fptr;\n int cs = prefetch_cs(s->prefetch.config1);\n int is16bit = (((s->cs_file[cs].config[0] >> 12) & 3) != 0);\n int bytes;\n /* Don't believe the bit of the OMAP TRM that says that COUNTVALUE\n * and TRANSFERCOUNT are in units of 16 bit words for 16 bit NAND.\n * Instead believe the bit that says it is always a byte count.\n */\n bytes = 64 - s->prefetch.fifopointer;\n if (bytes > s->prefetch.count) {\n bytes = s->prefetch.count;\n s->prefetch.count -= bytes;\n s->prefetch.fifopointer += bytes;\n fptr = 64 - s->prefetch.fifopointer;\n /* Move the existing data in the FIFO so it sits just\n * before what we're about to read in\n */\n while (fptr < (64 - bytes)) {\n s->prefetch.fifo[fptr] = s->prefetch.fifo[fptr + bytes];\n fptr++;\n while (fptr < 64) {\n uint32_t v = omap_nand_read(&s->cs_file[cs], 0, 2);\n s->prefetch.fifo[fptr++] = v & 0xff;\n s->prefetch.fifo[fptr++] = (v >> 8) & 0xff;\n } else {\n s->prefetch.fifo[fptr++] = omap_nand_read(&s->cs_file[cs], 0, 1);\n if (s->prefetch.startengine && (s->prefetch.count == 0)) {\n /* This was the final transfer: raise TERMINALCOUNTSTATUS */\n s->irqst |= 2;\n s->prefetch.startengine = 0;\n /* If there are any bytes in the FIFO at this point then\n * we must raise a DMA request (either this is a final part\n * transfer, or we filled the FIFO in which case we certainly\n * have THRESHOLD bytes available)\n */\n if (s->prefetch.fifopointer != 0) {\n omap_gpmc_dma_update(s, 1);\n omap_gpmc_int_update(s);", + "label": 1, + "project": "qemu", + "commit_id": "89f26e6b7b5e5c9657f2abd6ef5a336bea11add2", + "length": 690 + }, + { + "index": 16856, + "code": "static int msrle_decode_pal4(AVCodecContext *avctx, AVPicture *pic,\n\n GetByteContext *gb)\n\n{\n\n unsigned char rle_code;\n\n unsigned char extra_byte, odd_pixel;\n\n unsigned char stream_byte;\n\n unsigned int pixel_ptr = 0;\n\n int row_dec = pic->linesize[0];\n\n int row_ptr = (avctx->height - 1) * row_dec;\n\n int frame_size = row_dec * avctx->height;\n\n int i;\n\n\n\n while (row_ptr >= 0) {\n\n if (bytestream2_get_bytes_left(gb) <= 0) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"MS RLE: bytestream overrun, %d rows left\\n\",\n\n row_ptr);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n rle_code = stream_byte = bytestream2_get_byteu(gb);\n\n if (rle_code == 0) {\n\n /* fetch the next byte to see how to handle escape code */\n\n stream_byte = bytestream2_get_byte(gb);\n\n if (stream_byte == 0) {\n\n /* line is done, goto the next one */\n\n row_ptr -= row_dec;\n\n pixel_ptr = 0;\n\n } else if (stream_byte == 1) {\n\n /* decode is done */\n\n return 0;\n\n } else if (stream_byte == 2) {\n\n /* reposition frame decode coordinates */\n\n stream_byte = bytestream2_get_byte(gb);\n\n pixel_ptr += stream_byte;\n\n stream_byte = bytestream2_get_byte(gb);\n\n row_ptr -= stream_byte * row_dec;\n\n } else {\n\n // copy pixels from encoded stream\n\n odd_pixel = stream_byte & 1;\n\n rle_code = (stream_byte + 1) / 2;\n\n extra_byte = rle_code & 0x01;\n\n if (row_ptr + pixel_ptr + stream_byte > frame_size ||\n\n bytestream2_get_bytes_left(gb) < rle_code) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"MS RLE: frame/stream ptr just went out of bounds (copy)\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n for (i = 0; i < rle_code; i++) {\n\n if (pixel_ptr >= avctx->width)\n\n break;\n\n stream_byte = bytestream2_get_byteu(gb);\n\n pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4;\n\n pixel_ptr++;\n\n if (i + 1 == rle_code && odd_pixel)\n\n break;\n\n if (pixel_ptr >= avctx->width)\n\n break;\n\n pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;\n\n pixel_ptr++;\n\n }\n\n\n\n // if the RLE code is odd, skip a byte in the stream\n\n if (extra_byte)\n\n bytestream2_skip(gb, 1);\n\n }\n\n } else {\n\n // decode a run of data\n\n if (row_ptr + pixel_ptr + stream_byte > frame_size) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"MS RLE: frame ptr just went out of bounds (run)\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n stream_byte = bytestream2_get_byte(gb);\n\n for (i = 0; i < rle_code; i++) {\n\n if (pixel_ptr >= avctx->width)\n\n break;\n\n if ((i & 1) == 0)\n\n pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4;\n\n else\n\n pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;\n\n pixel_ptr++;\n\n }\n\n }\n\n }\n\n\n\n /* one last sanity check on the way out */\n\n if (bytestream2_get_bytes_left(gb)) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"MS RLE: ended frame decode with %d bytes left over\\n\",\n\n bytestream2_get_bytes_left(gb));\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f7e1367f58263593e6cee3c282f7277d7ee9d553", + "length": 898 + }, + { + "index": 4070, + "code": "static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)\n\n{\n\n AVBitStreamFilterContext *bsfc = ost->bitstream_filters;\n\n AVCodecContext *avctx = ost->st->codec;\n\n int ret;\n\n\n\n if ((avctx->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) ||\n\n (avctx->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))\n\n pkt->pts = pkt->dts = AV_NOPTS_VALUE;\n\n\n\n if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pkt->dts != AV_NOPTS_VALUE) {\n\n int64_t max = ost->st->cur_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);\n\n if (ost->st->cur_dts && ost->st->cur_dts != AV_NOPTS_VALUE && max > pkt->dts) {\n\n av_log(s, max - pkt->dts > 2 ? AV_LOG_WARNING : AV_LOG_DEBUG, \"Audio timestamp %\"PRId64\" < %\"PRId64\" invalid, cliping\\n\", pkt->dts, max);\n\n pkt->pts = pkt->dts = max;\n\n\n\n\n\n /*\n\n * Audio encoders may split the packets -- #frames in != #packets out.\n\n * But there is no reordering, so we can limit the number of output packets\n\n * by simply dropping them here.\n\n * Counting encoded video frames needs to be done separately because of\n\n * reordering, see do_video_out()\n\n */\n\n if (!(avctx->codec_type == AVMEDIA_TYPE_VIDEO && avctx->codec)) {\n\n if (ost->frame_number >= ost->max_frames) {\n\n av_free_packet(pkt);\n\n return;\n\n\n ost->frame_number++;\n\n\n\n\n while (bsfc) {\n\n AVPacket new_pkt = *pkt;\n\n int a = av_bitstream_filter_filter(bsfc, avctx, NULL,\n\n &new_pkt.data, &new_pkt.size,\n\n pkt->data, pkt->size,\n\n pkt->flags & AV_PKT_FLAG_KEY);\n\n\n\n\n\n\n\n\n\n\n\n if (a > 0) {\n\n av_free_packet(pkt);\n\n new_pkt.destruct = av_destruct_packet;\n\n } else if (a < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Failed to open bitstream filter %s for stream %d with codec %s\",\n\n bsfc->filter->name, pkt->stream_index,\n\n avctx->codec ? avctx->codec->name : \"copy\");\n\n print_error(\"\", a);\n\n if (exit_on_error)\n\n exit_program(1);\n\n\n *pkt = new_pkt;\n\n\n\n bsfc = bsfc->next;\n\n\n\n\n pkt->stream_index = ost->index;\n\n ret = av_interleaved_write_frame(s, pkt);\n\n if (ret < 0) {\n\n print_error(\"av_interleaved_write_frame()\", ret);\n\n exit_program(1);\n\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "969267482de97b08503d27d2fe090ec820273e40", + "length": 641 + }, + { + "index": 9612, + "code": "static void search_for_ms(AACEncContext *s, ChannelElement *cpe,\n\n const float lambda)\n\n{\n\n int start = 0, i, w, w2, g;\n\n float M[128], S[128];\n\n float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;\n\n SingleChannelElement *sce0 = &cpe->ch[0];\n\n SingleChannelElement *sce1 = &cpe->ch[1];\n\n if (!cpe->common_window)\n\n return;\n\n for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {\n\n for (g = 0; g < sce0->ics.num_swb; g++) {\n\n if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {\n\n float dist1 = 0.0f, dist2 = 0.0f;\n\n for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {\n\n FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];\n\n FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];\n\n float minthr = FFMIN(band0->threshold, band1->threshold);\n\n float maxthr = FFMAX(band0->threshold, band1->threshold);\n\n for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {\n\n M[i] = (sce0->coeffs[start+w2*128+i]\n\n + sce1->coeffs[start+w2*128+i]) * 0.5;\n\n S[i] = M[i]\n\n - sce1->coeffs[start+w2*128+i];\n\n }\n\n abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);\n\n abs_pow34_v(R34, sce1->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);\n\n abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);\n\n abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);\n\n dist1 += quantize_band_cost(s, sce0->coeffs + start + w2*128,\n\n L34,\n\n sce0->ics.swb_sizes[g],\n\n sce0->sf_idx[(w+w2)*16+g],\n\n sce0->band_type[(w+w2)*16+g],\n\n lambda / band0->threshold, INFINITY, NULL);\n\n dist1 += quantize_band_cost(s, sce1->coeffs + start + w2*128,\n\n R34,\n\n sce1->ics.swb_sizes[g],\n\n sce1->sf_idx[(w+w2)*16+g],\n\n sce1->band_type[(w+w2)*16+g],\n\n lambda / band1->threshold, INFINITY, NULL);\n\n dist2 += quantize_band_cost(s, M,\n\n M34,\n\n sce0->ics.swb_sizes[g],\n\n sce0->sf_idx[(w+w2)*16+g],\n\n sce0->band_type[(w+w2)*16+g],\n\n lambda / maxthr, INFINITY, NULL);\n\n dist2 += quantize_band_cost(s, S,\n\n S34,\n\n sce1->ics.swb_sizes[g],\n\n sce1->sf_idx[(w+w2)*16+g],\n\n sce1->band_type[(w+w2)*16+g],\n\n lambda / minthr, INFINITY, NULL);\n\n }\n\n cpe->ms_mask[w*16+g] = dist2 < dist1;\n\n }\n\n start += sce0->ics.swb_sizes[g];\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6394acaf36da3106f4793bda32730f8ff6b0ddb1", + "length": 902 + }, + { + "index": 3805, + "code": "static int readv_f(BlockBackend *blk, int argc, char **argv)\n\n{\n\n struct timeval t1, t2;\n\n int Cflag = 0, qflag = 0, vflag = 0;\n\n int c, cnt;\n\n char *buf;\n\n int64_t offset;\n\n /* Some compilers get confused and warn if this is not initialized. */\n\n int total = 0;\n\n int nr_iov;\n\n QEMUIOVector qiov;\n\n int pattern = 0;\n\n int Pflag = 0;\n\n\n\n while ((c = getopt(argc, argv, \"CP:qv\")) != EOF) {\n\n switch (c) {\n\n case 'C':\n\n Cflag = 1;\n\n break;\n\n case 'P':\n\n Pflag = 1;\n\n pattern = parse_pattern(optarg);\n\n if (pattern < 0) {\n\n return 0;\n\n }\n\n break;\n\n case 'q':\n\n qflag = 1;\n\n break;\n\n case 'v':\n\n vflag = 1;\n\n break;\n\n default:\n\n return qemuio_command_usage(&readv_cmd);\n\n }\n\n }\n\n\n\n if (optind > argc - 2) {\n\n return qemuio_command_usage(&readv_cmd);\n\n }\n\n\n\n\n\n offset = cvtnum(argv[optind]);\n\n if (offset < 0) {\n\n printf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n return 0;\n\n }\n\n optind++;\n\n\n\n if (offset & 0x1ff) {\n\n printf(\"offset %\" PRId64 \" is not sector aligned\\n\",\n\n offset);\n\n return 0;\n\n }\n\n\n\n nr_iov = argc - optind;\n\n buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab);\n\n if (buf == NULL) {\n\n return 0;\n\n }\n\n\n\n gettimeofday(&t1, NULL);\n\n cnt = do_aio_readv(blk, &qiov, offset, &total);\n\n gettimeofday(&t2, NULL);\n\n\n\n if (cnt < 0) {\n\n printf(\"readv failed: %s\\n\", strerror(-cnt));\n\n goto out;\n\n }\n\n\n\n if (Pflag) {\n\n void *cmp_buf = g_malloc(qiov.size);\n\n memset(cmp_buf, pattern, qiov.size);\n\n if (memcmp(buf, cmp_buf, qiov.size)) {\n\n printf(\"Pattern verification failed at offset %\"\n\n PRId64 \", %zd bytes\\n\", offset, qiov.size);\n\n }\n\n g_free(cmp_buf);\n\n }\n\n\n\n if (qflag) {\n\n goto out;\n\n }\n\n\n\n if (vflag) {\n\n dump_buffer(buf, offset, qiov.size);\n\n }\n\n\n\n /* Finally, report back -- -C gives a parsable format */\n\n t2 = tsub(t2, t1);\n\n print_report(\"read\", &t2, offset, qiov.size, total, cnt, Cflag);\n\n\n\nout:\n\n qemu_iovec_destroy(&qiov);\n\n qemu_io_free(buf);\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b062ad86dcd33ab39be5060b0655d8e13834b167", + "length": 657 + }, + { + "index": 18640, + "code": "static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)\n\n{\n\n NE2000State *s = opaque;\n\n int offset, page;\n\n\n\n addr &= 0xf;\n\n#ifdef DEBUG_NE2000\n\n printf(\"NE2000: write addr=0x%x val=0x%02x\\n\", addr, val);\n\n#endif\n\n if (addr == E8390_CMD) {\n\n /* control register */\n\n s->cmd = val;\n\n if (val & E8390_START) {\n\n s->isr &= ~ENISR_RESET;\n\n /* test specific case: zero length transfert */\n\n if ((val & (E8390_RREAD | E8390_RWRITE)) &&\n\n s->rcnt == 0) {\n\n s->isr |= ENISR_RDC;\n\n ne2000_update_irq(s);\n\n }\n\n if (val & E8390_TRANS) {\n\n qemu_send_packet(s->nd, s->mem + (s->tpsr << 8), s->tcnt);\n\n /* signal end of transfert */\n\n s->tsr = ENTSR_PTX;\n\n s->isr |= ENISR_TX;\n\n ne2000_update_irq(s);\n\n }\n\n }\n\n } else {\n\n page = s->cmd >> 6;\n\n offset = addr | (page << 4);\n\n switch(offset) {\n\n case EN0_STARTPG:\n\n s->start = val << 8;\n\n break;\n\n case EN0_STOPPG:\n\n s->stop = val << 8;\n\n break;\n\n case EN0_BOUNDARY:\n\n s->boundary = val;\n\n break;\n\n case EN0_IMR:\n\n s->imr = val;\n\n ne2000_update_irq(s);\n\n break;\n\n case EN0_TPSR:\n\n s->tpsr = val;\n\n break;\n\n case EN0_TCNTLO:\n\n s->tcnt = (s->tcnt & 0xff00) | val;\n\n break;\n\n case EN0_TCNTHI:\n\n s->tcnt = (s->tcnt & 0x00ff) | (val << 8);\n\n break;\n\n case EN0_RSARLO:\n\n s->rsar = (s->rsar & 0xff00) | val;\n\n break;\n\n case EN0_RSARHI:\n\n s->rsar = (s->rsar & 0x00ff) | (val << 8);\n\n break;\n\n case EN0_RCNTLO:\n\n s->rcnt = (s->rcnt & 0xff00) | val;\n\n break;\n\n case EN0_RCNTHI:\n\n s->rcnt = (s->rcnt & 0x00ff) | (val << 8);\n\n break;\n\n case EN0_DCFG:\n\n s->dcfg = val;\n\n break;\n\n case EN0_ISR:\n\n s->isr &= ~(val & 0x7f);\n\n ne2000_update_irq(s);\n\n break;\n\n case EN1_PHYS ... EN1_PHYS + 5:\n\n s->phys[offset - EN1_PHYS] = val;\n\n break;\n\n case EN1_CURPAG:\n\n s->curpag = val;\n\n break;\n\n case EN1_MULT ... EN1_MULT + 7:\n\n s->mult[offset - EN1_MULT] = val;\n\n break;\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "40545f84cfcbe4b73cca040b3043a1c2de935762", + "length": 734 + }, + { + "index": 13812, + "code": "static void parse_numa_node(NumaNodeOptions *node, QemuOpts *opts, Error **errp)\n\n{\n\n uint16_t nodenr;\n\n uint16List *cpus = NULL;\n\n\n\n if (node->has_nodeid) {\n\n nodenr = node->nodeid;\n\n } else {\n\n nodenr = nb_numa_nodes;\n\n }\n\n\n\n if (nodenr >= MAX_NODES) {\n\n error_setg(errp, \"Max number of NUMA nodes reached: %\"\n\n PRIu16 \"\", nodenr);\n\n return;\n\n }\n\n\n\n if (numa_info[nodenr].present) {\n\n error_setg(errp, \"Duplicate NUMA nodeid: %\" PRIu16, nodenr);\n\n return;\n\n }\n\n\n\n for (cpus = node->cpus; cpus; cpus = cpus->next) {\n\n if (cpus->value >= max_cpus) {\n\n error_setg(errp,\n\n \"CPU index (%\" PRIu16 \")\"\n\n \" should be smaller than maxcpus (%d)\",\n\n cpus->value, max_cpus);\n\n return;\n\n }\n\n bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1);\n\n }\n\n\n\n if (node->has_mem && node->has_memdev) {\n\n error_setg(errp, \"qemu: cannot specify both mem= and memdev=\");\n\n return;\n\n }\n\n\n\n if (have_memdevs == -1) {\n\n have_memdevs = node->has_memdev;\n\n }\n\n if (node->has_memdev != have_memdevs) {\n\n error_setg(errp, \"qemu: memdev option must be specified for either \"\n\n \"all or no nodes\");\n\n return;\n\n }\n\n\n\n if (node->has_mem) {\n\n uint64_t mem_size = node->mem;\n\n const char *mem_str = qemu_opt_get(opts, \"mem\");\n\n /* Fix up legacy suffix-less format */\n\n if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {\n\n mem_size <<= 20;\n\n }\n\n numa_info[nodenr].node_mem = mem_size;\n\n }\n\n if (node->has_memdev) {\n\n Object *o;\n\n o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);\n\n if (!o) {\n\n error_setg(errp, \"memdev=%s is ambiguous\", node->memdev);\n\n return;\n\n }\n\n\n\n object_ref(o);\n\n numa_info[nodenr].node_mem = object_property_get_int(o, \"size\", NULL);\n\n numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);\n\n }\n\n numa_info[nodenr].present = true;\n\n max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "64c2a8f6d3facc2f758907c3b95686fe9e999590", + "length": 608 + }, + { + "index": 108, + "code": "aio_write_f(int argc, char **argv)\n\n{\n\n\tchar *p;\n\n\tint count = 0;\n\n\tint nr_iov, i, c;\n\n\tint pattern = 0xcd;\n\n\tstruct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));\n\n\tBlockDriverAIOCB *acb;\n\n\n\n\twhile ((c = getopt(argc, argv, \"CqP:\")) != EOF) {\n\n\t\tswitch (c) {\n\n\t\tcase 'C':\n\n\t\t\tctx->Cflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 'q':\n\n\t\t\tctx->qflag = 1;\n\n\t\t\tbreak;\n\n\t\tcase 'P':\n\n\t\t\tpattern = atoi(optarg);\n\n\t\t\tbreak;\n\n\t\tdefault:\n\n\t\t\treturn command_usage(&aio_write_cmd);\n\n\t\t}\n\n\t}\n\n\n\n\tif (optind > argc - 2)\n\n\t\treturn command_usage(&aio_write_cmd);\n\n\n\n\tctx->offset = cvtnum(argv[optind]);\n\n\tif (ctx->offset < 0) {\n\n\t\tprintf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n\t\treturn 0;\n\n\t}\n\n\toptind++;\n\n\n\n\tif (ctx->offset & 0x1ff) {\n\n\t\tprintf(\"offset %lld is not sector aligned\\n\",\n\n\t\t\t(long long)ctx->offset);\n\n\t\treturn 0;\n\n\t}\n\n\n\n\tif (count & 0x1ff) {\n\n\t\tprintf(\"count %d is not sector aligned\\n\",\n\n\t\t\tcount);\n\n\t\treturn 0;\n\n\t}\n\n\n\n\tfor (i = optind; i < argc; i++) {\n\n\t size_t len;\n\n\n\n\t\tlen = cvtnum(argv[optind]);\n\n\t\tif (len < 0) {\n\n\t\t\tprintf(\"non-numeric length argument -- %s\\n\", argv[i]);\n\n\t\t\treturn 0;\n\n\t\t}\n\n\t\tcount += len;\n\n\t}\n\n\n\n\tnr_iov = argc - optind;\n\n\tqemu_iovec_init(&ctx->qiov, nr_iov);\n\n\tctx->buf = p = qemu_io_alloc(count, pattern);\n\n\tfor (i = 0; i < nr_iov; i++) {\n\n\t size_t len;\n\n\n\n\t\tlen = cvtnum(argv[optind]);\n\n\t\tif (len < 0) {\n\n\t\t\tprintf(\"non-numeric length argument -- %s\\n\",\n\n\t\t\t\targv[optind]);\n\n\t\t\treturn 0;\n\n\t\t}\n\n\n\n\t\tqemu_iovec_add(&ctx->qiov, p, len);\n\n\t\tp += len;\n\n\t\toptind++;\n\n\t}\n\n\n\n\tgettimeofday(&ctx->t1, NULL);\n\n\tacb = bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,\n\n\t\t\t ctx->qiov.size >> 9, aio_write_done, ctx);\n\n\tif (!acb)\n\n\t\treturn -EIO;\n\n\n\n\treturn 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "cf57298af5336df2aece47ef16c290a3a81457dd", + "length": 563 + }, + { + "index": 18600, + "code": "static void g364fb_ctrl_write(void *opaque,\n\n target_phys_addr_t addr,\n\n uint64_t val,\n\n unsigned int size)\n\n{\n\n G364State *s = opaque;\n\n\n\n trace_g364fb_write(addr, val);\n\n\n\n if (addr >= REG_CLR_PAL && addr < REG_CLR_PAL + 0x800) {\n\n /* color palette */\n\n int idx = (addr - REG_CLR_PAL) >> 3;\n\n s->color_palette[idx][0] = (val >> 16) & 0xff;\n\n s->color_palette[idx][1] = (val >> 8) & 0xff;\n\n s->color_palette[idx][2] = val & 0xff;\n\n g364fb_invalidate_display(s);\n\n } else if (addr >= REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) {\n\n /* cursor pattern */\n\n int idx = (addr - REG_CURS_PAT) >> 3;\n\n s->cursor[idx] = val;\n\n g364fb_invalidate_display(s);\n\n } else if (addr >= REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) {\n\n /* cursor palette */\n\n int idx = (addr - REG_CURS_PAL) >> 3;\n\n s->cursor_palette[idx][0] = (val >> 16) & 0xff;\n\n s->cursor_palette[idx][1] = (val >> 8) & 0xff;\n\n s->cursor_palette[idx][2] = val & 0xff;\n\n g364fb_invalidate_display(s);\n\n } else {\n\n switch (addr) {\n\n case REG_BOOT: /* Boot timing */\n\n case 0x00108: /* Line timing: half sync */\n\n case 0x00110: /* Line timing: back porch */\n\n case 0x00120: /* Line timing: short display */\n\n case 0x00128: /* Frame timing: broad pulse */\n\n case 0x00130: /* Frame timing: v sync */\n\n case 0x00138: /* Frame timing: v preequalise */\n\n case 0x00140: /* Frame timing: v postequalise */\n\n case 0x00148: /* Frame timing: v blank */\n\n case 0x00158: /* Line timing: line time */\n\n case 0x00160: /* Frame store: line start */\n\n case 0x00168: /* vram cycle: mem init */\n\n case 0x00170: /* vram cycle: transfer delay */\n\n case 0x00200: /* vram cycle: mask register */\n\n /* ignore */\n\n break;\n\n case REG_TOP:\n\n s->top_of_screen = val;\n\n g364fb_invalidate_display(s);\n\n break;\n\n case REG_DISPLAY:\n\n s->width = val * 4;\n\n break;\n\n case REG_VDISPLAY:\n\n s->height = val / 2;\n\n break;\n\n case REG_CTLA:\n\n s->ctla = val;\n\n g364fb_update_depth(s);\n\n g364fb_invalidate_display(s);\n\n break;\n\n case REG_CURS_POS:\n\n g364_invalidate_cursor_position(s);\n\n s->cursor_position = val;\n\n g364_invalidate_cursor_position(s);\n\n break;\n\n case REG_RESET:\n\n g364fb_reset(s);\n\n break;\n\n default:\n\n error_report(\"g364: invalid write of 0x%\" PRIx64\n\n \" at [\" TARGET_FMT_plx \"]\", val, addr);\n\n break;\n\n }\n\n }\n\n qemu_irq_lower(s->irq);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a8170e5e97ad17ca169c64ba87ae2f53850dab4c", + "length": 773 + }, + { + "index": 22972, + "code": "static void apply_dependent_coupling_fixed(AACContext *ac,\n\n SingleChannelElement *target,\n\n ChannelElement *cce, int index)\n\n{\n\n IndividualChannelStream *ics = &cce->ch[0].ics;\n\n const uint16_t *offsets = ics->swb_offset;\n\n int *dest = target->coeffs;\n\n const int *src = cce->ch[0].coeffs;\n\n int g, i, group, k, idx = 0;\n\n if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {\n\n av_log(ac->avctx, AV_LOG_ERROR,\n\n \"Dependent coupling is not supported together with LTP\\n\");\n\n return;\n\n }\n\n for (g = 0; g < ics->num_window_groups; g++) {\n\n for (i = 0; i < ics->max_sfb; i++, idx++) {\n\n if (cce->ch[0].band_type[idx] != ZERO_BT) {\n\n const int gain = cce->coup.gain[index][idx];\n\n int shift, round, c, tmp;\n\n\n\n if (gain < 0) {\n\n c = -cce_scale_fixed[-gain & 7];\n\n shift = (-gain-1024) >> 3;\n\n }\n\n else {\n\n c = cce_scale_fixed[gain & 7];\n\n shift = (gain-1024) >> 3;\n\n }\n\n\n\n if (shift < -31) {\n\n // Nothing to do\n\n } else if (shift < 0) {\n\n shift = -shift;\n\n round = 1 << (shift - 1);\n\n\n\n for (group = 0; group < ics->group_len[g]; group++) {\n\n for (k = offsets[i]; k < offsets[i + 1]; k++) {\n\n tmp = (int)(((int64_t)src[group * 128 + k] * c + \\\n\n (int64_t)0x1000000000) >> 37);\n\n dest[group * 128 + k] += (tmp + round) >> shift;\n\n }\n\n }\n\n }\n\n else {\n\n for (group = 0; group < ics->group_len[g]; group++) {\n\n for (k = offsets[i]; k < offsets[i + 1]; k++) {\n\n tmp = (int)(((int64_t)src[group * 128 + k] * c + \\\n\n (int64_t)0x1000000000) >> 37);\n\n dest[group * 128 + k] += tmp << shift;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n dest += ics->group_len[g] * 128;\n\n src += ics->group_len[g] * 128;\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6d499ecef9c2467772b6066176ffda0b7ab27cc2", + "length": 596 + }, + { + "index": 25690, + "code": "static int aasc_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n AascContext *s = avctx->priv_data;\n int compr, i, stride, psize;\n s->frame.reference = 3;\n s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;\n if (avctx->reget_buffer(avctx, &s->frame)) {\n av_log(avctx, AV_LOG_ERROR, \"reget_buffer() failed\\n\");\n return -1;\n compr = AV_RL32(buf);\n buf += 4;\n buf_size -= 4;\n psize = avctx->bits_per_coded_sample / 8;\n switch (avctx->codec_tag) {\n case MKTAG('A', 'A', 'S', '4'):\n bytestream2_init(&s->gb, buf - 4, buf_size + 4);\n ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);\n break;\n case MKTAG('A', 'A', 'S', 'C'):\n switch(compr){\n case 0:\n stride = (avctx->width * psize + psize) & ~psize;\n for(i = avctx->height - 1; i >= 0; i--){\n if(avctx->width * psize > buf_size){\n av_log(avctx, AV_LOG_ERROR, \"Next line is beyond buffer bounds\\n\");\n break;\n memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width * psize);\n buf += stride;\n buf_size -= stride;\n break;\n case 1:\n bytestream2_init(&s->gb, buf, buf_size);\n ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, \"Unknown compression type %d\\n\", compr);\n return -1;\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, \"Unknown FourCC: %X\\n\", avctx->codec_tag);\n return -1;\n if (avctx->pix_fmt == AV_PIX_FMT_PAL8)\n memcpy(s->frame.data[1], s->palette, s->palette_size);\n *data_size = sizeof(AVFrame);\n *(AVFrame*)data = s->frame;\n /* report that the buffer was completely consumed */\n return buf_size;", + "label": 1, + "project": "FFmpeg", + "commit_id": "e1631f8ebe9a8f2a9cca85d60160b9be94eb63f3", + "length": 600 + }, + { + "index": 13885, + "code": "static int v4l2_try_start(AVCodecContext *avctx)\n\n{\n\n V4L2m2mContext *s = avctx->priv_data;\n\n V4L2Context *const capture = &s->capture;\n\n V4L2Context *const output = &s->output;\n\n struct v4l2_selection selection;\n\n int ret;\n\n\n\n /* 1. start the output process */\n\n if (!output->streamon) {\n\n ret = ff_v4l2_context_set_status(output, VIDIOC_STREAMON);\n\n if (ret < 0) {\n\n av_log(avctx, AV_LOG_DEBUG, \"VIDIOC_STREAMON on output context\\n\");\n\n return ret;\n\n }\n\n }\n\n\n\n if (capture->streamon)\n\n return 0;\n\n\n\n /* 2. get the capture format */\n\n capture->format.type = capture->type;\n\n ret = ioctl(s->fd, VIDIOC_G_FMT, &capture->format);\n\n if (ret) {\n\n av_log(avctx, AV_LOG_WARNING, \"VIDIOC_G_FMT ioctl\\n\");\n\n return ret;\n\n }\n\n\n\n /* 2.1 update the AVCodecContext */\n\n avctx->pix_fmt = ff_v4l2_format_v4l2_to_avfmt(capture->format.fmt.pix_mp.pixelformat, AV_CODEC_ID_RAWVIDEO);\n\n capture->av_pix_fmt = avctx->pix_fmt;\n\n\n\n /* 3. set the crop parameters */\n\n selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;\n\n selection.r.height = avctx->coded_height;\n\n selection.r.width = avctx->coded_width;\n\n ret = ioctl(s->fd, VIDIOC_S_SELECTION, &selection);\n\n if (!ret) {\n\n ret = ioctl(s->fd, VIDIOC_G_SELECTION, &selection);\n\n if (ret) {\n\n av_log(avctx, AV_LOG_WARNING, \"VIDIOC_G_SELECTION ioctl\\n\");\n\n } else {\n\n av_log(avctx, AV_LOG_DEBUG, \"crop output %dx%d\\n\", selection.r.width, selection.r.height);\n\n /* update the size of the resulting frame */\n\n capture->height = selection.r.height;\n\n capture->width = selection.r.width;\n\n }\n\n }\n\n\n\n /* 4. init the capture context now that we have the capture format */\n\n if (!capture->buffers) {\n\n ret = ff_v4l2_context_init(capture);\n\n if (ret) {\n\n av_log(avctx, AV_LOG_DEBUG, \"can't request output buffers\\n\");\n\n return ret;\n\n }\n\n }\n\n\n\n /* 5. start the capture process */\n\n ret = ff_v4l2_context_set_status(capture, VIDIOC_STREAMON);\n\n if (ret) {\n\n av_log(avctx, AV_LOG_DEBUG, \"VIDIOC_STREAMON, on capture context\\n\");\n\n return ret;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "a0c624e299730c8c5800375c2f5f3c6c200053ff", + "length": 606 + }, + { + "index": 6359, + "code": "static int decode_band(IVI5DecContext *ctx, int plane_num,\n\n IVIBandDesc *band, AVCodecContext *avctx)\n\n{\n\n int result, i, t, idx1, idx2;\n\n IVITile *tile;\n\n uint16_t chksum;\n\n\n\n band->buf = band->bufs[ctx->dst_buf];\n\n band->ref_buf = band->bufs[ctx->ref_buf];\n\n band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);\n\n\n\n result = decode_band_hdr(ctx, band, avctx);\n\n if (result) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error while decoding band header: %d\\n\",\n\n result);\n\n return -1;\n\n }\n\n\n\n if (band->is_empty) {\n\n av_log(avctx, AV_LOG_ERROR, \"Empty band encountered!\\n\");\n\n return -1;\n\n }\n\n\n\n band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel];\n\n\n\n /* apply corrections to the selected rvmap table if present */\n\n for (i = 0; i < band->num_corr; i++) {\n\n idx1 = band->corr[i*2];\n\n idx2 = band->corr[i*2+1];\n\n FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);\n\n FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);\n\n }\n\n\n\n for (t = 0; t < band->num_tiles; t++) {\n\n tile = &band->tiles[t];\n\n\n\n tile->is_empty = get_bits1(&ctx->gb);\n\n if (tile->is_empty) {\n\n ff_ivi_process_empty_tile(avctx, band, tile,\n\n (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));\n\n align_get_bits(&ctx->gb);\n\n } else {\n\n tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb);\n\n\n\n result = decode_mb_info(ctx, band, tile, avctx);\n\n if (result < 0)\n\n break;\n\n\n\n if (band->blk_size == 8) {\n\n band->intra_base = &ivi5_base_quant_8x8_intra[band->quant_mat][0];\n\n band->inter_base = &ivi5_base_quant_8x8_inter[band->quant_mat][0];\n\n band->intra_scale = &ivi5_scale_quant_8x8_intra[band->quant_mat][0];\n\n band->inter_scale = &ivi5_scale_quant_8x8_inter[band->quant_mat][0];\n\n } else {\n\n band->intra_base = ivi5_base_quant_4x4_intra;\n\n band->inter_base = ivi5_base_quant_4x4_inter;\n\n band->intra_scale = ivi5_scale_quant_4x4_intra;\n\n band->inter_scale = ivi5_scale_quant_4x4_inter;\n\n }\n\n\n\n result = ff_ivi_decode_blocks(&ctx->gb, band, tile);\n\n if (result < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Corrupted blocks data encountered!\\n\");\n\n break;\n\n }\n\n }\n\n }\n\n\n\n /* restore the selected rvmap table by applying its corrections in reverse order */\n\n for (i = band->num_corr-1; i >= 0; i--) {\n\n idx1 = band->corr[i*2];\n\n idx2 = band->corr[i*2+1];\n\n FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);\n\n FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);\n\n }\n\n\n\n if (IVI_DEBUG && band->checksum_present) {\n\n chksum = ivi_calc_band_checksum(band);\n\n if (chksum != band->checksum) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\\n\",\n\n band->plane, band->band_num, band->checksum, chksum);\n\n }\n\n }\n\n\n\n return result;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f7d649185b62a83ab58514207151f2a8059090fb", + "length": 958 + }, + { + "index": 25277, + "code": "size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,\n\n int bswap, const char *fmt, ...)\n\n{\n\n int i;\n\n va_list ap;\n\n size_t old_offset = offset;\n\n\n\n va_start(ap, fmt);\n\n for (i = 0; fmt[i]; i++) {\n\n switch (fmt[i]) {\n\n case 'b': {\n\n uint8_t *valp = va_arg(ap, uint8_t *);\n\n offset += v9fs_unpack(valp, out_sg, out_num, offset, sizeof(*valp));\n\n break;\n\n }\n\n case 'w': {\n\n uint16_t val, *valp;\n\n valp = va_arg(ap, uint16_t *);\n\n offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val));\n\n if (bswap) {\n\n *valp = le16_to_cpu(val);\n\n } else {\n\n *valp = val;\n\n }\n\n break;\n\n }\n\n case 'd': {\n\n uint32_t val, *valp;\n\n valp = va_arg(ap, uint32_t *);\n\n offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val));\n\n if (bswap) {\n\n *valp = le32_to_cpu(val);\n\n } else {\n\n *valp = val;\n\n }\n\n break;\n\n }\n\n case 'q': {\n\n uint64_t val, *valp;\n\n valp = va_arg(ap, uint64_t *);\n\n offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val));\n\n if (bswap) {\n\n *valp = le64_to_cpu(val);\n\n } else {\n\n *valp = val;\n\n }\n\n break;\n\n }\n\n case 's': {\n\n V9fsString *str = va_arg(ap, V9fsString *);\n\n offset += v9fs_unmarshal(out_sg, out_num, offset, bswap,\n\n \"w\", &str->size);\n\n /* FIXME: sanity check str->size */\n\n str->data = g_malloc(str->size + 1);\n\n offset += v9fs_unpack(str->data, out_sg, out_num, offset,\n\n str->size);\n\n str->data[str->size] = 0;\n\n break;\n\n }\n\n case 'Q': {\n\n V9fsQID *qidp = va_arg(ap, V9fsQID *);\n\n offset += v9fs_unmarshal(out_sg, out_num, offset, bswap, \"bdq\",\n\n &qidp->type, &qidp->version, &qidp->path);\n\n break;\n\n }\n\n case 'S': {\n\n V9fsStat *statp = va_arg(ap, V9fsStat *);\n\n offset += v9fs_unmarshal(out_sg, out_num, offset, bswap,\n\n \"wwdQdddqsssssddd\",\n\n &statp->size, &statp->type, &statp->dev,\n\n &statp->qid, &statp->mode, &statp->atime,\n\n &statp->mtime, &statp->length,\n\n &statp->name, &statp->uid, &statp->gid,\n\n &statp->muid, &statp->extension,\n\n &statp->n_uid, &statp->n_gid,\n\n &statp->n_muid);\n\n break;\n\n }\n\n case 'I': {\n\n V9fsIattr *iattr = va_arg(ap, V9fsIattr *);\n\n offset += v9fs_unmarshal(out_sg, out_num, offset, bswap,\n\n \"ddddqqqqq\",\n\n &iattr->valid, &iattr->mode,\n\n &iattr->uid, &iattr->gid, &iattr->size,\n\n &iattr->atime_sec, &iattr->atime_nsec,\n\n &iattr->mtime_sec, &iattr->mtime_nsec);\n\n break;\n\n }\n\n default:\n\n break;\n\n }\n\n }\n\n\n\n va_end(ap);\n\n\n\n return offset - old_offset;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ddca7f86ac022289840e0200fd4050b2b58e9176", + "length": 888 + }, + { + "index": 1500, + "code": "static target_ulong h_enter(CPUState *env, sPAPREnvironment *spapr,\n\n target_ulong opcode, target_ulong *args)\n\n{\n\n target_ulong flags = args[0];\n\n target_ulong pte_index = args[1];\n\n target_ulong pteh = args[2];\n\n target_ulong ptel = args[3];\n\n target_ulong i;\n\n uint8_t *hpte;\n\n\n\n /* only handle 4k and 16M pages for now */\n\n if (pteh & HPTE_V_LARGE) {\n\n#if 0 /* We don't support 64k pages yet */\n\n if ((ptel & 0xf000) == 0x1000) {\n\n /* 64k page */\n\n } else\n\n#endif\n\n if ((ptel & 0xff000) == 0) {\n\n /* 16M page */\n\n /* lowest AVA bit must be 0 for 16M pages */\n\n if (pteh & 0x80) {\n\n return H_PARAMETER;\n\n }\n\n } else {\n\n return H_PARAMETER;\n\n }\n\n }\n\n\n\n /* FIXME: bounds check the pa? */\n\n\n\n /* Check WIMG */\n\n if ((ptel & HPTE_R_WIMG) != HPTE_R_M) {\n\n return H_PARAMETER;\n\n }\n\n pteh &= ~0x60ULL;\n\n\n\n if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {\n\n return H_PARAMETER;\n\n }\n\n if (likely((flags & H_EXACT) == 0)) {\n\n pte_index &= ~7ULL;\n\n hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);\n\n for (i = 0; ; ++i) {\n\n if (i == 8) {\n\n return H_PTEG_FULL;\n\n }\n\n if (((ldq_p(hpte) & HPTE_V_VALID) == 0) &&\n\n lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID)) {\n\n break;\n\n }\n\n hpte += HASH_PTE_SIZE_64;\n\n }\n\n } else {\n\n i = 0;\n\n hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);\n\n if (!lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID)) {\n\n return H_PTEG_FULL;\n\n }\n\n }\n\n stq_p(hpte + (HASH_PTE_SIZE_64/2), ptel);\n\n /* eieio(); FIXME: need some sort of barrier for smp? */\n\n stq_p(hpte, pteh);\n\n\n\n assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));\n\n args[0] = pte_index + i;\n\n return H_SUCCESS;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "f73a2575a3bce8a3c487331c918d2c0f9b2e489d", + "length": 600 + }, + { + "index": 11984, + "code": "int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int64_t size;\n\n int nb_clusters, refcount1, refcount2, i;\n\n QCowSnapshot *sn;\n\n uint16_t *refcount_table;\n\n int ret;\n\n\n\n size = bdrv_getlength(bs->file);\n\n nb_clusters = size_to_clusters(s, size);\n\n refcount_table = qemu_mallocz(nb_clusters * sizeof(uint16_t));\n\n\n\n /* header */\n\n inc_refcounts(bs, res, refcount_table, nb_clusters,\n\n 0, s->cluster_size);\n\n\n\n /* current L1 table */\n\n ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,\n\n s->l1_table_offset, s->l1_size, 1);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n /* snapshots */\n\n for(i = 0; i < s->nb_snapshots; i++) {\n\n sn = s->snapshots + i;\n\n ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,\n\n sn->l1_table_offset, sn->l1_size, 0);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n inc_refcounts(bs, res, refcount_table, nb_clusters,\n\n s->snapshots_offset, s->snapshots_size);\n\n\n\n /* refcount data */\n\n inc_refcounts(bs, res, refcount_table, nb_clusters,\n\n s->refcount_table_offset,\n\n s->refcount_table_size * sizeof(uint64_t));\n\n\n\n for(i = 0; i < s->refcount_table_size; i++) {\n\n uint64_t offset, cluster;\n\n offset = s->refcount_table[i];\n\n cluster = offset >> s->cluster_bits;\n\n\n\n /* Refcount blocks are cluster aligned */\n\n if (offset & (s->cluster_size - 1)) {\n\n fprintf(stderr, \"ERROR refcount block %d is not \"\n\n \"cluster aligned; refcount table entry corrupted\\n\", i);\n\n res->corruptions++;\n\n continue;\n\n }\n\n\n\n if (cluster >= nb_clusters) {\n\n fprintf(stderr, \"ERROR refcount block %d is outside image\\n\", i);\n\n res->corruptions++;\n\n continue;\n\n }\n\n\n\n if (offset != 0) {\n\n inc_refcounts(bs, res, refcount_table, nb_clusters,\n\n offset, s->cluster_size);\n\n if (refcount_table[cluster] != 1) {\n\n fprintf(stderr, \"ERROR refcount block %d refcount=%d\\n\",\n\n i, refcount_table[cluster]);\n\n res->corruptions++;\n\n }\n\n }\n\n }\n\n\n\n /* compare ref counts */\n\n for(i = 0; i < nb_clusters; i++) {\n\n refcount1 = get_refcount(bs, i);\n\n if (refcount1 < 0) {\n\n fprintf(stderr, \"Can't get refcount for cluster %d: %s\\n\",\n\n i, strerror(-refcount1));\n\n res->check_errors++;\n\n continue;\n\n }\n\n\n\n refcount2 = refcount_table[i];\n\n if (refcount1 != refcount2) {\n\n fprintf(stderr, \"%s cluster %d refcount=%d reference=%d\\n\",\n\n refcount1 < refcount2 ? \"ERROR\" : \"Leaked\",\n\n i, refcount1, refcount2);\n\n if (refcount1 < refcount2) {\n\n res->corruptions++;\n\n } else {\n\n res->leaks++;\n\n }\n\n }\n\n }\n\n\n\n qemu_free(refcount_table);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "80fa3341a70151d250be92ae900e3c1580817540", + "length": 787 + }, + { + "index": 15490, + "code": "if_output(struct socket *so, struct mbuf *ifm)\n\n{\n\n\tstruct mbuf *ifq;\n\n\tint on_fastq = 1;\n\n\n\n\tDEBUG_CALL(\"if_output\");\n\n\tDEBUG_ARG(\"so = %lx\", (long)so);\n\n\tDEBUG_ARG(\"ifm = %lx\", (long)ifm);\n\n\n\n\t/*\n\n\t * First remove the mbuf from m_usedlist,\n\n\t * since we're gonna use m_next and m_prev ourselves\n\n\t * XXX Shouldn't need this, gotta change dtom() etc.\n\n\t */\n\n\tif (ifm->m_flags & M_USEDLIST) {\n\n\t\tremque(ifm);\n\n\t\tifm->m_flags &= ~M_USEDLIST;\n\n\t}\n\n\n\n\t/*\n\n\t * See if there's already a batchq list for this session.\n\n\t * This can include an interactive session, which should go on fastq,\n\n\t * but gets too greedy... hence it'll be downgraded from fastq to batchq.\n\n\t * We mustn't put this packet back on the fastq (or we'll send it out of order)\n\n\t * XXX add cache here?\n\n\t */\n\n\tfor (ifq = if_batchq.ifq_prev; ifq != &if_batchq; ifq = ifq->ifq_prev) {\n\n\t\tif (so == ifq->ifq_so) {\n\n\t\t\t/* A match! */\n\n\t\t\tifm->ifq_so = so;\n\n\t\t\tifs_insque(ifm, ifq->ifs_prev);\n\n\t\t\tgoto diddit;\n\n\t\t}\n\n\t}\n\n\n\n\t/* No match, check which queue to put it on */\n\n\tif (so && (so->so_iptos & IPTOS_LOWDELAY)) {\n\n\t\tifq = if_fastq.ifq_prev;\n\n\t\ton_fastq = 1;\n\n\t\t/*\n\n\t\t * Check if this packet is a part of the last\n\n\t\t * packet's session\n\n\t\t */\n\n\t\tif (ifq->ifq_so == so) {\n\n\t\t\tifm->ifq_so = so;\n\n\t\t\tifs_insque(ifm, ifq->ifs_prev);\n\n\t\t\tgoto diddit;\n\n\t\t}\n\n\t} else\n\n\t\tifq = if_batchq.ifq_prev;\n\n\n\n\t/* Create a new doubly linked list for this session */\n\n\tifm->ifq_so = so;\n\n\tifs_init(ifm);\n\n\tinsque(ifm, ifq);\n\n\n\ndiddit:\n\n\t++if_queued;\n\n\n\n\tif (so) {\n\n\t\t/* Update *_queued */\n\n\t\tso->so_queued++;\n\n\t\tso->so_nqueued++;\n\n\t\t/*\n\n\t\t * Check if the interactive session should be downgraded to\n\n\t\t * the batchq. A session is downgraded if it has queued 6\n\n\t\t * packets without pausing, and at least 3 of those packets\n\n\t\t * have been sent over the link\n\n\t\t * (XXX These are arbitrary numbers, probably not optimal..)\n\n\t\t */\n\n\t\tif (on_fastq && ((so->so_nqueued >= 6) &&\n\n\t\t\t\t (so->so_nqueued - so->so_queued) >= 3)) {\n\n\n\n\t\t\t/* Remove from current queue... */\n\n\t\t\tremque(ifm->ifs_next);\n\n\n\n\t\t\t/* ...And insert in the new. That'll teach ya! */\n\n\t\t\tinsque(ifm->ifs_next, &if_batchq);\n\n\t\t}\n\n\t}\n\n\n\n#ifndef FULL_BOLT\n\n\t/*\n\n\t * This prevents us from malloc()ing too many mbufs\n\n\t */\n\n\tif (link_up) {\n\n\t\t/* if_start will check towrite */\n\n\t\tif_start();\n\n\t}\n\n#endif\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "b5302e1a9d8a47bd29a3e1876fba34be111728a2", + "length": 745 + }, + { + "index": 7272, + "code": "static inline void dv_guess_qnos(EncBlockInfo* blks, int* qnos)\n\n{\n\n int size[5];\n\n int i, j, k, a, prev, a2;\n\n EncBlockInfo* b;\n\n\n\n size[0] = size[1] = size[2] = size[3] = size[4] = 1<<24;\n\n do {\n\n b = blks;\n\n for (i=0; i<5; i++) {\n\n if (!qnos[i])\n\n continue;\n\n\n\n qnos[i]--;\n\n size[i] = 0;\n\n for (j=0; j<6; j++, b++) {\n\n for (a=0; a<4; a++) {\n\n if (b->area_q[a] != dv_quant_shifts[qnos[i] + dv_quant_offset[b->cno]][a]) {\n\n b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)\n\n b->area_q[a]++;\n\n prev= b->prev[a];\n\n for (k= b->next[prev] ; knext[k]) {\n\n b->mb[k] >>= 1;\n\n if (b->mb[k]) {\n\n b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);\n\n prev= k;\n\n } else {\n\n if(b->next[k] >= mb_area_start[a+1] && b->next[k]<64){\n\n for(a2=a+1; b->next[k] >= mb_area_start[a2+1]; a2++)\n\n b->prev[a2] = prev;\n\n assert(a2<4);\n\n assert(b->mb[b->next[k]]);\n\n b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]])\n\n -dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]);\n\n for(; (b->prev[a2]==k) && (a2<4); a2++)\n\n b->prev[a2] = prev;\n\n }\n\n b->next[prev] = b->next[k];\n\n }\n\n }\n\n b->prev[a+1]= prev;\n\n }\n\n size[i] += b->bit_size[a];\n\n }\n\n }\n\n if(vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])\n\n return;\n\n }\n\n } while (qnos[0]|qnos[1]|qnos[2]|qnos[3]|qnos[4]);\n\n\n\n\n\n for(a=2; a==2 || vs_total_ac_bits < size[0]; a+=a){\n\n b = blks;\n\n size[0] = 5*6*4; //EOB\n\n for (j=0; j<6*5; j++, b++) {\n\n prev= b->prev[0];\n\n for (k= b->next[prev]; k<64; k= b->next[k]) {\n\n if(b->mb[k] < a && b->mb[k] > -a){\n\n b->next[prev] = b->next[k];\n\n }else{\n\n size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);\n\n prev= k;\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d676478c8d29a48f67526afef44c323b74946488", + "length": 760 + }, + { + "index": 3108, + "code": "static int display_end_segment(AVCodecContext *avctx, void *data,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n AVSubtitle *sub = data;\n\n PGSSubContext *ctx = avctx->priv_data;\n\n\n\n /*\n\n * The end display time is a timeout value and is only reached\n\n * if the next subtitle is later then timeout or subtitle has\n\n * not been cleared by a subsequent empty display command.\n\n */\n\n\n\n memset(sub, 0, sizeof(*sub));\n\n // Blank if last object_number was 0.\n\n // Note that this may be wrong for more complex subtitles.\n\n if (!ctx->presentation.object_number)\n\n return 1;\n\n sub->start_display_time = 0;\n\n sub->end_display_time = 20000;\n\n sub->format = 0;\n\n\n\n sub->rects = av_mallocz(sizeof(*sub->rects));\n\n sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));\n\n sub->num_rects = 1;\n\n\n\n sub->rects[0]->x = ctx->presentation.x;\n\n sub->rects[0]->y = ctx->presentation.y;\n\n sub->rects[0]->w = ctx->picture.w;\n\n sub->rects[0]->h = ctx->picture.h;\n\n sub->rects[0]->type = SUBTITLE_BITMAP;\n\n\n\n /* Process bitmap */\n\n sub->rects[0]->pict.linesize[0] = ctx->picture.w;\n\n\n\n if (ctx->picture.rle) {\n\n if (ctx->picture.rle_remaining_len)\n\n av_log(avctx, AV_LOG_ERROR, \"RLE data length %u is %u bytes shorter than expected\\n\",\n\n ctx->picture.rle_data_len, ctx->picture.rle_remaining_len);\n\n if(decode_rle(avctx, sub, ctx->picture.rle, ctx->picture.rle_data_len) < 0)\n\n return 0;\n\n }\n\n /* Allocate memory for colors */\n\n sub->rects[0]->nb_colors = 256;\n\n sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);\n\n\n\n memcpy(sub->rects[0]->pict.data[1], ctx->clut, sub->rects[0]->nb_colors * sizeof(uint32_t));\n\n\n\n return 1;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3ee8ca9b0894df3aaf5086c643283cb58ef9763d", + "length": 524 + }, + { + "index": 976, + "code": "static int commit_direntries(BDRVVVFATState* s,\n\n\tint dir_index, int parent_mapping_index)\n\n{\n\n direntry_t* direntry = array_get(&(s->directory), dir_index);\n\n uint32_t first_cluster = dir_index == 0 ? 0 : begin_of_direntry(direntry);\n\n mapping_t* mapping = find_mapping_for_cluster(s, first_cluster);\n\n\n\n int factor = 0x10 * s->sectors_per_cluster;\n\n int old_cluster_count, new_cluster_count;\n\n int current_dir_index = mapping->info.dir.first_dir_index;\n\n int first_dir_index = current_dir_index;\n\n int ret, i;\n\n uint32_t c;\n\n\n\nDLOG(fprintf(stderr, \"commit_direntries for %s, parent_mapping_index %d\\n\", mapping->path, parent_mapping_index));\n\n\n\n assert(direntry);\n\n assert(mapping);\n\n assert(mapping->begin == first_cluster);\n\n assert(mapping->info.dir.first_dir_index < s->directory.next);\n\n assert(mapping->mode & MODE_DIRECTORY);\n\n assert(dir_index == 0 || is_directory(direntry));\n\n\n\n mapping->info.dir.parent_mapping_index = parent_mapping_index;\n\n\n\n if (first_cluster == 0) {\n\n\told_cluster_count = new_cluster_count =\n\n\t s->last_cluster_of_root_directory;\n\n } else {\n\n\tfor (old_cluster_count = 0, c = first_cluster; !fat_eof(s, c);\n\n\t\tc = fat_get(s, c))\n\n\t old_cluster_count++;\n\n\n\n\tfor (new_cluster_count = 0, c = first_cluster; !fat_eof(s, c);\n\n\t\tc = modified_fat_get(s, c))\n\n\t new_cluster_count++;\n\n }\n\n\n\n if (new_cluster_count > old_cluster_count) {\n\n\tif (insert_direntries(s,\n\n\t\tcurrent_dir_index + factor * old_cluster_count,\n\n\t\tfactor * (new_cluster_count - old_cluster_count)) == NULL)\n\n\t return -1;\n\n } else if (new_cluster_count < old_cluster_count)\n\n\tremove_direntries(s,\n\n\t\tcurrent_dir_index + factor * new_cluster_count,\n\n\t\tfactor * (old_cluster_count - new_cluster_count));\n\n\n\n for (c = first_cluster; !fat_eof(s, c); c = modified_fat_get(s, c)) {\n\n\tvoid* direntry = array_get(&(s->directory), current_dir_index);\n\n\tint ret = vvfat_read(s->bs, cluster2sector(s, c), direntry,\n\n\t\ts->sectors_per_cluster);\n\n\tif (ret)\n\n\t return ret;\n\n\tassert(!strncmp(s->directory.pointer, \"QEMU\", 4));\n\n\tcurrent_dir_index += factor;\n\n }\n\n\n\n ret = commit_mappings(s, first_cluster, dir_index);\n\n if (ret)\n\n\treturn ret;\n\n\n\n /* recurse */\n\n for (i = 0; i < factor * new_cluster_count; i++) {\n\n\tdirentry = array_get(&(s->directory), first_dir_index + i);\n\n\tif (is_directory(direntry) && !is_dot(direntry)) {\n\n\t mapping = find_mapping_for_cluster(s, first_cluster);\n\n\t assert(mapping->mode & MODE_DIRECTORY);\n\n\t ret = commit_direntries(s, first_dir_index + i,\n\n\t\tarray_index(&(s->mapping), mapping));\n\n\t if (ret)\n\n\t\treturn ret;\n\n\t}\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "ebb72c9f066e5f85259e1541a6d3fb5bfd6e73ff", + "length": 694 + }, + { + "index": 1402, + "code": "static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n AVStream *st;\n\n int len, ret;\n\n\n\n for(;;) {\n\n /* select current input stream component */\n\n st = s->cur_st;\n\n if (st) {\n\n if (!st->parser) {\n\n /* no parsing needed: we just output the packet as is */\n\n /* raw data support */\n\n *pkt = s->cur_pkt;\n\n compute_pkt_fields(s, st, NULL, pkt);\n\n s->cur_st = NULL;\n\n return 0;\n\n } else if (s->cur_len > 0) {\n\n /* we use the MPEG semantics: the pts and dts in a\n\n packet are given from the first frame beginning in\n\n it */\n\n if (!st->got_frame) {\n\n st->cur_frame_pts = s->cur_pkt.pts;\n\n st->cur_frame_dts = s->cur_pkt.dts;\n\n s->cur_pkt.pts = AV_NOPTS_VALUE;\n\n s->cur_pkt.dts = AV_NOPTS_VALUE;\n\n st->got_frame = 1;\n\n }\n\n len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, \n\n s->cur_ptr, s->cur_len);\n\n /* increment read pointer */\n\n s->cur_ptr += len;\n\n s->cur_len -= len;\n\n \n\n /* return packet if any */\n\n if (pkt->size) {\n\n pkt->duration = 0;\n\n pkt->stream_index = st->index;\n\n pkt->pts = st->cur_frame_pts;\n\n pkt->dts = st->cur_frame_dts;\n\n pkt->destruct = av_destruct_packet_nofree;\n\n compute_pkt_fields(s, st, st->parser, pkt);\n\n st->got_frame = 0;\n\n return 0;\n\n }\n\n } else {\n\n s->cur_st = NULL;\n\n }\n\n } else {\n\n /* free previous packet */\n\n if (s->cur_st && s->cur_st->parser)\n\n av_free_packet(&s->cur_pkt); \n\n\n\n /* read next packet */\n\n ret = av_read_packet(s, &s->cur_pkt);\n\n if (ret < 0)\n\n return ret;\n\n\n\n /* convert the packet time stamp units and handle wrapping */\n\n s->cur_pkt.pts = convert_timestamp_units(s, \n\n &s->last_pkt_pts, &s->last_pkt_pts_frac,\n\n &s->last_pkt_stream_pts,\n\n s->cur_pkt.pts);\n\n s->cur_pkt.dts = convert_timestamp_units(s, \n\n &s->last_pkt_dts, &s->last_pkt_dts_frac,\n\n &s->last_pkt_stream_dts,\n\n s->cur_pkt.dts);\n\n#if 0\n\n if (s->cur_pkt.stream_index == 1) {\n\n if (s->cur_pkt.pts != AV_NOPTS_VALUE) \n\n printf(\"PACKET pts=%0.3f\\n\", \n\n (double)s->cur_pkt.pts / AV_TIME_BASE);\n\n if (s->cur_pkt.dts != AV_NOPTS_VALUE) \n\n printf(\"PACKET dts=%0.3f\\n\", \n\n (double)s->cur_pkt.dts / AV_TIME_BASE);\n\n }\n\n#endif\n\n \n\n /* duration field */\n\n if (s->cur_pkt.duration != 0) {\n\n s->cur_pkt.duration = ((int64_t)s->cur_pkt.duration * AV_TIME_BASE * s->pts_num) / \n\n s->pts_den;\n\n }\n\n\n\n st = s->streams[s->cur_pkt.stream_index];\n\n s->cur_st = st;\n\n s->cur_ptr = s->cur_pkt.data;\n\n s->cur_len = s->cur_pkt.size;\n\n if (st->need_parsing && !st->parser) {\n\n st->parser = av_parser_init(st->codec.codec_id);\n\n if (!st->parser) {\n\n /* no parser available : just output the raw packets */\n\n st->need_parsing = 0;\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "bcbecff13f2d9c8af19039fa82703efd4c04eb97", + "length": 872 + }, + { + "index": 25144, + "code": "static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,\n\n const AVFrame *frame, int *got_packet)\n\n{\n\n VP8Context *ctx = avctx->priv_data;\n\n struct vpx_image *rawimg = NULL;\n\n struct vpx_image *rawimg_alpha = NULL;\n\n int64_t timestamp = 0;\n\n int res, coded_size;\n\n vpx_enc_frame_flags_t flags = 0;\n\n\n\n if (frame) {\n\n rawimg = &ctx->rawimg;\n\n rawimg->planes[VPX_PLANE_Y] = frame->data[0];\n\n rawimg->planes[VPX_PLANE_U] = frame->data[1];\n\n rawimg->planes[VPX_PLANE_V] = frame->data[2];\n\n rawimg->stride[VPX_PLANE_Y] = frame->linesize[0];\n\n rawimg->stride[VPX_PLANE_U] = frame->linesize[1];\n\n rawimg->stride[VPX_PLANE_V] = frame->linesize[2];\n\n if (ctx->is_alpha) {\n\n uint8_t *u_plane, *v_plane;\n\n rawimg_alpha = &ctx->rawimg_alpha;\n\n rawimg_alpha->planes[VPX_PLANE_Y] = frame->data[3];\n\n u_plane = av_malloc(frame->linesize[1] * frame->height);\n\n memset(u_plane, 0x80, frame->linesize[1] * frame->height);\n\n rawimg_alpha->planes[VPX_PLANE_U] = u_plane;\n\n v_plane = av_malloc(frame->linesize[2] * frame->height);\n\n memset(v_plane, 0x80, frame->linesize[2] * frame->height);\n\n rawimg_alpha->planes[VPX_PLANE_V] = v_plane;\n\n rawimg_alpha->stride[VPX_PLANE_Y] = frame->linesize[0];\n\n rawimg_alpha->stride[VPX_PLANE_U] = frame->linesize[1];\n\n rawimg_alpha->stride[VPX_PLANE_V] = frame->linesize[2];\n\n }\n\n timestamp = frame->pts;\n\n if (frame->pict_type == AV_PICTURE_TYPE_I)\n\n flags |= VPX_EFLAG_FORCE_KF;\n\n }\n\n\n\n res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,\n\n avctx->ticks_per_frame, flags, ctx->deadline);\n\n if (res != VPX_CODEC_OK) {\n\n log_encoder_error(avctx, \"Error encoding frame\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (ctx->is_alpha) {\n\n res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,\n\n avctx->ticks_per_frame, flags, ctx->deadline);\n\n if (res != VPX_CODEC_OK) {\n\n log_encoder_error(avctx, \"Error encoding alpha frame\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n coded_size = queue_frames(avctx, pkt, avctx->coded_frame);\n\n\n\n if (!frame && avctx->flags & CODEC_FLAG_PASS1) {\n\n unsigned int b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);\n\n\n\n avctx->stats_out = av_malloc(b64_size);\n\n if (!avctx->stats_out) {\n\n av_log(avctx, AV_LOG_ERROR, \"Stat buffer alloc (%d bytes) failed\\n\",\n\n b64_size);\n\n return AVERROR(ENOMEM);\n\n }\n\n av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,\n\n ctx->twopass_stats.sz);\n\n }\n\n\n\n if (rawimg_alpha) {\n\n av_freep(&rawimg_alpha->planes[VPX_PLANE_U]);\n\n av_freep(&rawimg_alpha->planes[VPX_PLANE_V]);\n\n }\n\n\n\n *got_packet = !!coded_size;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "21518f5a0a6b644d1dedda5650c15bc3df62a567", + "length": 841 + }, + { + "index": 5599, + "code": "static void query_facilities(void)\n\n{\n\n struct sigaction sa_old, sa_new;\n\n register int r0 __asm__(\"0\");\n\n register void *r1 __asm__(\"1\");\n\n int fail;\n\n\n\n memset(&sa_new, 0, sizeof(sa_new));\n\n sa_new.sa_handler = sigill_handler;\n\n sigaction(SIGILL, &sa_new, &sa_old);\n\n\n\n /* First, try STORE FACILITY LIST EXTENDED. If this is present, then\n\n we need not do any more probing. Unfortunately, this itself is an\n\n extension and the original STORE FACILITY LIST instruction is\n\n kernel-only, storing its results at absolute address 200. */\n\n /* stfle 0(%r1) */\n\n r1 = &facilities;\n\n asm volatile(\".word 0xb2b0,0x1000\"\n\n : \"=r\"(r0) : \"0\"(0), \"r\"(r1) : \"memory\", \"cc\");\n\n\n\n if (got_sigill) {\n\n /* STORE FACILITY EXTENDED is not available. Probe for one of each\n\n kind of instruction that we're interested in. */\n\n /* ??? Possibly some of these are in practice never present unless\n\n the store-facility-extended facility is also present. But since\n\n that isn't documented it's just better to probe for each. */\n\n\n\n /* Test for z/Architecture. Required even in 31-bit mode. */\n\n got_sigill = 0;\n\n /* agr %r0,%r0 */\n\n asm volatile(\".word 0xb908,0x0000\" : \"=r\"(r0) : : \"cc\");\n\n if (!got_sigill) {\n\n facilities |= FACILITY_ZARCH_ACTIVE;\n\n }\n\n\n\n /* Test for long displacement. */\n\n got_sigill = 0;\n\n /* ly %r0,0(%r1) */\n\n r1 = &facilities;\n\n asm volatile(\".word 0xe300,0x1000,0x0058\"\n\n : \"=r\"(r0) : \"r\"(r1) : \"cc\");\n\n if (!got_sigill) {\n\n facilities |= FACILITY_LONG_DISP;\n\n }\n\n\n\n /* Test for extended immediates. */\n\n got_sigill = 0;\n\n /* afi %r0,0 */\n\n asm volatile(\".word 0xc209,0x0000,0x0000\" : : : \"cc\");\n\n if (!got_sigill) {\n\n facilities |= FACILITY_EXT_IMM;\n\n }\n\n\n\n /* Test for general-instructions-extension. */\n\n got_sigill = 0;\n\n /* msfi %r0,1 */\n\n asm volatile(\".word 0xc201,0x0000,0x0001\");\n\n if (!got_sigill) {\n\n facilities |= FACILITY_GEN_INST_EXT;\n\n }\n\n }\n\n\n\n sigaction(SIGILL, &sa_old, NULL);\n\n\n\n /* The translator currently uses these extensions unconditionally.\n\n Pruning this back to the base ESA/390 architecture doesn't seem\n\n worthwhile, since even the KVM target requires z/Arch. */\n\n fail = 0;\n\n if ((facilities & FACILITY_ZARCH_ACTIVE) == 0) {\n\n fprintf(stderr, \"TCG: z/Arch facility is required.\\n\");\n\n fprintf(stderr, \"TCG: Boot with a 64-bit enabled kernel.\\n\");\n\n fail = 1;\n\n }\n\n if ((facilities & FACILITY_LONG_DISP) == 0) {\n\n fprintf(stderr, \"TCG: long-displacement facility is required.\\n\");\n\n fail = 1;\n\n }\n\n\n\n /* So far there's just enough support for 31-bit mode to let the\n\n compile succeed. This is good enough to run QEMU with KVM. */\n\n if (sizeof(void *) != 8) {\n\n fprintf(stderr, \"TCG: 31-bit mode is not supported.\\n\");\n\n fail = 1;\n\n }\n\n\n\n if (fail) {\n\n exit(-1);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "c9baa30f42a87f61627391698f63fa4d1566d9d8", + "length": 866 + }, + { + "index": 21443, + "code": "static void ehci_advance_state(EHCIState *ehci,\n\n int async)\n\n{\n\n EHCIQueue *q = NULL;\n\n int again;\n\n int iter = 0;\n\n\n\n do {\n\n if (ehci_get_state(ehci, async) == EST_FETCHQH) {\n\n iter++;\n\n /* if we are roaming a lot of QH without executing a qTD\n\n * something is wrong with the linked list. TO-DO: why is\n\n * this hack needed?\n\n */\n\n assert(iter < MAX_ITERATIONS);\n\n#if 0\n\n if (iter > MAX_ITERATIONS) {\n\n DPRINTF(\"\\n*** advance_state: bailing on MAX ITERATIONS***\\n\");\n\n ehci_set_state(ehci, async, EST_ACTIVE);\n\n break;\n\n }\n\n#endif\n\n }\n\n switch(ehci_get_state(ehci, async)) {\n\n case EST_WAITLISTHEAD:\n\n again = ehci_state_waitlisthead(ehci, async);\n\n break;\n\n\n\n case EST_FETCHENTRY:\n\n again = ehci_state_fetchentry(ehci, async);\n\n break;\n\n\n\n case EST_FETCHQH:\n\n q = ehci_state_fetchqh(ehci, async);\n\n again = q ? 1 : 0;\n\n break;\n\n\n\n case EST_FETCHITD:\n\n again = ehci_state_fetchitd(ehci, async);\n\n break;\n\n\n\n case EST_FETCHSITD:\n\n again = ehci_state_fetchsitd(ehci, async);\n\n break;\n\n\n\n case EST_ADVANCEQUEUE:\n\n again = ehci_state_advqueue(q, async);\n\n break;\n\n\n\n case EST_FETCHQTD:\n\n again = ehci_state_fetchqtd(q, async);\n\n break;\n\n\n\n case EST_HORIZONTALQH:\n\n again = ehci_state_horizqh(q, async);\n\n break;\n\n\n\n case EST_EXECUTE:\n\n iter = 0;\n\n again = ehci_state_execute(q, async);\n\n break;\n\n\n\n case EST_EXECUTING:\n\n assert(q != NULL);\n\n again = ehci_state_executing(q, async);\n\n break;\n\n\n\n case EST_WRITEBACK:\n\n assert(q != NULL);\n\n again = ehci_state_writeback(q, async);\n\n break;\n\n\n\n default:\n\n fprintf(stderr, \"Bad state!\\n\");\n\n again = -1;\n\n assert(0);\n\n break;\n\n }\n\n\n\n if (again < 0) {\n\n fprintf(stderr, \"processing error - resetting ehci HC\\n\");\n\n ehci_reset(ehci);\n\n again = 0;\n\n }\n\n }\n\n while (again);\n\n\n\n ehci_commit_interrupt(ehci);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "e59a8cf1eb2196cdaded214ccd1b819c8faad238", + "length": 541 + }, + { + "index": 13349, + "code": "static inline int64_t get_sector_offset(BlockDriverState *bs,\n\n int64_t sector_num, int write)\n\n{\n\n BDRVVPCState *s = bs->opaque;\n\n uint64_t offset = sector_num * 512;\n\n uint64_t bitmap_offset, block_offset;\n\n uint32_t pagetable_index, pageentry_index;\n\n\n\n pagetable_index = offset / s->block_size;\n\n pageentry_index = (offset % s->block_size) / 512;\n\n\n\n if (pagetable_index >= s->max_table_entries || s->pagetable[pagetable_index] == 0xffffffff)\n\n return -1; // not allocated\n\n\n\n bitmap_offset = 512 * (uint64_t) s->pagetable[pagetable_index];\n\n block_offset = bitmap_offset + s->bitmap_size + (512 * pageentry_index);\n\n\n\n // We must ensure that we don't write to any sectors which are marked as\n\n // unused in the bitmap. We get away with setting all bits in the block\n\n // bitmap each time we write to a new block. This might cause Virtual PC to\n\n // miss sparse read optimization, but it's not a problem in terms of\n\n // correctness.\n\n if (write && (s->last_bitmap_offset != bitmap_offset)) {\n\n uint8_t bitmap[s->bitmap_size];\n\n\n\n s->last_bitmap_offset = bitmap_offset;\n\n memset(bitmap, 0xff, s->bitmap_size);\n\n bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size);\n\n }\n\n\n\n// printf(\"sector: %\" PRIx64 \", index: %x, offset: %x, bioff: %\" PRIx64 \", bloff: %\" PRIx64 \"\\n\",\n\n//\tsector_num, pagetable_index, pageentry_index,\n\n//\tbitmap_offset, block_offset);\n\n\n\n// disabled by reason\n\n#if 0\n\n#ifdef CACHE\n\n if (bitmap_offset != s->last_bitmap)\n\n {\n\n\tlseek(s->fd, bitmap_offset, SEEK_SET);\n\n\n\n\ts->last_bitmap = bitmap_offset;\n\n\n\n\t// Scary! Bitmap is stored as big endian 32bit entries,\n\n\t// while we used to look it up byte by byte\n\n\tread(s->fd, s->pageentry_u8, 512);\n\n\tfor (i = 0; i < 128; i++)\n\n\t be32_to_cpus(&s->pageentry_u32[i]);\n\n }\n\n\n\n if ((s->pageentry_u8[pageentry_index / 8] >> (pageentry_index % 8)) & 1)\n\n\treturn -1;\n\n#else\n\n lseek(s->fd, bitmap_offset + (pageentry_index / 8), SEEK_SET);\n\n\n\n read(s->fd, &bitmap_entry, 1);\n\n\n\n if ((bitmap_entry >> (pageentry_index % 8)) & 1)\n\n\treturn -1; // not allocated\n\n#endif\n\n#endif\n\n\n\n return block_offset;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "304ee9174f4761d3f4da611352a815ab27baba06", + "length": 612 + }, + { + "index": 9748, + "code": "static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)\n\n{\n\n struct v4l2_plane planes[VIDEO_MAX_PLANES];\n\n struct v4l2_buffer buf = { 0 };\n\n V4L2Buffer* avbuf = NULL;\n\n struct pollfd pfd = {\n\n .events = POLLIN | POLLRDNORM | POLLPRI | POLLOUT | POLLWRNORM, /* default blocking capture */\n\n .fd = ctx_to_m2mctx(ctx)->fd,\n\n };\n\n int ret;\n\n\n\n if (V4L2_TYPE_IS_OUTPUT(ctx->type))\n\n pfd.events = POLLOUT | POLLWRNORM;\n\n\n\n for (;;) {\n\n ret = poll(&pfd, 1, timeout);\n\n if (ret > 0)\n\n break;\n\n if (errno == EINTR)\n\n continue;\n\n\n\n /* timeout is being used to indicate last valid bufer when draining */\n\n if (ctx_to_m2mctx(ctx)->draining)\n\n ctx->done = 1;\n\n\n\n return NULL;\n\n }\n\n\n\n /* 0. handle errors */\n\n if (pfd.revents & POLLERR) {\n\n av_log(logger(ctx), AV_LOG_WARNING, \"%s POLLERR\\n\", ctx->name);\n\n return NULL;\n\n }\n\n\n\n /* 1. handle resolution changes */\n\n if (pfd.revents & POLLPRI) {\n\n ret = v4l2_handle_event(ctx);\n\n if (ret < 0) {\n\n /* if re-init failed, abort */\n\n ctx->done = EINVAL;\n\n return NULL;\n\n }\n\n if (ret) {\n\n /* if re-init was successful drop the buffer (if there was one)\n\n * since we had to reconfigure capture (unmap all buffers)\n\n */\n\n return NULL;\n\n }\n\n }\n\n\n\n /* 2. dequeue the buffer */\n\n if (pfd.revents & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM)) {\n\n\n\n if (!V4L2_TYPE_IS_OUTPUT(ctx->type)) {\n\n /* there is a capture buffer ready */\n\n if (pfd.revents & (POLLIN | POLLRDNORM))\n\n goto dequeue;\n\n\n\n /* the driver is ready to accept more input; instead of waiting for the capture\n\n * buffer to complete we return NULL so input can proceed (we are single threaded)\n\n */\n\n if (pfd.revents & (POLLOUT | POLLWRNORM))\n\n return NULL;\n\n }\n\n\n\ndequeue:\n\n memset(&buf, 0, sizeof(buf));\n\n buf.memory = V4L2_MEMORY_MMAP;\n\n buf.type = ctx->type;\n\n if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {\n\n memset(planes, 0, sizeof(planes));\n\n buf.length = VIDEO_MAX_PLANES;\n\n buf.m.planes = planes;\n\n }\n\n\n\n ret = ioctl(ctx_to_m2mctx(ctx)->fd, VIDIOC_DQBUF, &buf);\n\n if (ret) {\n\n if (errno != EAGAIN) {\n\n ctx->done = errno;\n\n if (errno != EPIPE)\n\n av_log(logger(ctx), AV_LOG_DEBUG, \"%s VIDIOC_DQBUF, errno (%s)\\n\",\n\n ctx->name, av_err2str(AVERROR(errno)));\n\n }\n\n } else {\n\n avbuf = &ctx->buffers[buf.index];\n\n avbuf->status = V4L2BUF_AVAILABLE;\n\n avbuf->buf = buf;\n\n if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {\n\n memcpy(avbuf->planes, planes, sizeof(planes));\n\n avbuf->buf.m.planes = avbuf->planes;\n\n }\n\n }\n\n }\n\n\n\n return avbuf;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5d5de3eba4c7890c2e8077f5b4ae569671d11cf8", + "length": 810 + }, + { + "index": 14064, + "code": "void cpu_loop(CPUM68KState *env)\n\n{\n\n CPUState *cs = CPU(m68k_env_get_cpu(env));\n\n int trapnr;\n\n unsigned int n;\n\n target_siginfo_t info;\n\n TaskState *ts = cs->opaque;\n\n\n\n for(;;) {\n\n cpu_exec_start(cs);\n\n trapnr = cpu_exec(cs);\n\n cpu_exec_end(cs);\n\n process_queued_cpu_work(cs);\n\n\n\n switch(trapnr) {\n\n case EXCP_ILLEGAL:\n\n {\n\n if (ts->sim_syscalls) {\n\n uint16_t nr;\n\n get_user_u16(nr, env->pc + 2);\n\n env->pc += 4;\n\n do_m68k_simcall(env, nr);\n\n } else {\n\n goto do_sigill;\n\n }\n\n }\n\n\n case EXCP_HALT_INSN:\n\n /* Semihosing syscall. */\n\n env->pc += 4;\n\n do_m68k_semihosting(env, env->dregs[0]);\n\n\n case EXCP_LINEA:\n\n case EXCP_LINEF:\n\n case EXCP_UNSUPPORTED:\n\n do_sigill:\n\n info.si_signo = TARGET_SIGILL;\n\n\n info.si_code = TARGET_ILL_ILLOPN;\n\n\n\n\n\n\n\n\n\n\n\n case EXCP_TRAP0:\n\n {\n\n abi_long ret;\n\n ts->sim_syscalls = 0;\n\n n = env->dregs[0];\n\n env->pc += 2;\n\n ret = do_syscall(env,\n\n n,\n\n env->dregs[1],\n\n env->dregs[2],\n\n env->dregs[3],\n\n env->dregs[4],\n\n env->dregs[5],\n\n env->aregs[0],\n\n 0, 0);\n\n if (ret == -TARGET_ERESTARTSYS) {\n\n env->pc -= 2;\n\n } else if (ret != -TARGET_QEMU_ESIGRETURN) {\n\n env->dregs[0] = ret;\n\n }\n\n }\n\n\n case EXCP_INTERRUPT:\n\n /* just indicate that signals should be handled asap */\n\n\n case EXCP_ACCESS:\n\n {\n\n info.si_signo = TARGET_SIGSEGV;\n\n\n /* XXX: check env->error_code */\n\n info.si_code = TARGET_SEGV_MAPERR;\n\n info._sifields._sigfault._addr = env->mmu.ar;\n\n\n }\n\n\n case EXCP_DEBUG:\n\n {\n\n int sig;\n\n\n\n sig = gdb_handlesig(cs, TARGET_SIGTRAP);\n\n if (sig)\n\n {\n\n info.si_signo = sig;\n\n\n info.si_code = TARGET_TRAP_BRKPT;\n\n\n }\n\n }\n\n\n case EXCP_ATOMIC:\n\n cpu_exec_step_atomic(cs);\n\n\n default:\n\n EXCP_DUMP(env, \"qemu: unhandled CPU exception 0x%x - aborting\\n\", trapnr);\n\n abort();\n\n }\n\n process_pending_signals(env);\n\n }\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "0ccb9c1d8128a020720d5c6abf99a470742a1b94", + "length": 613 + }, + { + "index": 1239, + "code": "RGB_FUNCTIONS(rgb565)\n\n\n\n#undef RGB_IN\n\n#undef RGB_OUT\n\n#undef BPP\n\n\n\n/* bgr24 handling */\n\n\n\n#define RGB_IN(r, g, b, s)\\\n\n{\\\n\n b = (s)[0];\\\n\n g = (s)[1];\\\n\n r = (s)[2];\\\n\n}\n\n\n\n#define RGB_OUT(d, r, g, b)\\\n\n{\\\n\n (d)[0] = b;\\\n\n (d)[1] = g;\\\n\n (d)[2] = r;\\\n\n}\n\n\n\n#define BPP 3\n\n\n\nRGB_FUNCTIONS(bgr24)\n\n\n\n#undef RGB_IN\n\n#undef RGB_OUT\n\n#undef BPP\n\n\n\n/* rgb24 handling */\n\n\n\n#define RGB_IN(r, g, b, s)\\\n\n{\\\n\n r = (s)[0];\\\n\n g = (s)[1];\\\n\n b = (s)[2];\\\n\n}\n\n\n\n#define RGB_OUT(d, r, g, b)\\\n\n{\\\n\n (d)[0] = r;\\\n\n (d)[1] = g;\\\n\n (d)[2] = b;\\\n\n}\n\n\n\n#define BPP 3\n\n\n\nRGB_FUNCTIONS(rgb24)\n\n\n\nstatic void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,\n\n int width, int height)\n\n{\n\n uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;\n\n int w, y, cb, cr, r_add, g_add, b_add;\n\n uint8_t *cm = cropTbl + MAX_NEG_CROP;\n\n unsigned int r, g, b;\n\n\n\n d = dst->data[0];\n\n y1_ptr = src->data[0];\n\n cb_ptr = src->data[1];\n\n cr_ptr = src->data[2];\n\n for(;height > 0; height --) {\n\n d1 = d;\n\n for(w = width; w > 0; w--) {\n\n YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);\n\n\n\n YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);\n\n RGB_OUT(d1, r, g, b);\n\n d1 += BPP;\n\n\n\n y1_ptr++;\n\n cb_ptr++;\n\n cr_ptr++;\n\n }\n\n d += dst->linesize[0];\n\n y1_ptr += src->linesize[0] - width;\n\n cb_ptr += src->linesize[1] - width;\n\n cr_ptr += src->linesize[2] - width;\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "7e7e59409294af9caa63808e56c5cc824c98b4fc", + "length": 540 + }, + { + "index": 5419, + "code": "static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,\n\n const AVFrame *pic, int *got_packet)\n\n{\n\n libx265Context *ctx = avctx->priv_data;\n\n x265_picture x265pic;\n\n x265_picture x265pic_out = { { 0 } };\n\n x265_nal *nal;\n\n uint8_t *dst;\n\n int payload = 0;\n\n int nnal;\n\n int ret;\n\n int i;\n\n\n\n x265_picture_init(ctx->params, &x265pic);\n\n\n\n if (pic) {\n\n for (i = 0; i < 3; i++) {\n\n x265pic.planes[i] = pic->data[i];\n\n x265pic.stride[i] = pic->linesize[i];\n\n }\n\n\n\n x265pic.pts = pic->pts;\n\n x265pic.bitDepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1;\n\n\n\n x265pic.sliceType = pic->pict_type == AV_PICTURE_TYPE_I ? X265_TYPE_I :\n\n pic->pict_type == AV_PICTURE_TYPE_P ? X265_TYPE_P :\n\n pic->pict_type == AV_PICTURE_TYPE_B ? X265_TYPE_B :\n\n X265_TYPE_AUTO;\n\n }\n\n\n\n ret = x265_encoder_encode(ctx->encoder, &nal, &nnal,\n\n pic ? &x265pic : NULL, &x265pic_out);\n\n if (ret < 0)\n\n return AVERROR_UNKNOWN;\n\n\n\n if (!nnal)\n\n return 0;\n\n\n\n for (i = 0; i < nnal; i++)\n\n payload += nal[i].sizeBytes;\n\n\n\n ret = ff_alloc_packet(pkt, payload);\n\n if (ret < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error getting output packet.\\n\");\n\n return ret;\n\n }\n\n dst = pkt->data;\n\n\n\n for (i = 0; i < nnal; i++) {\n\n memcpy(dst, nal[i].payload, nal[i].sizeBytes);\n\n dst += nal[i].sizeBytes;\n\n\n\n if (is_keyframe(nal[i].type))\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n }\n\n\n\n pkt->pts = x265pic_out.pts;\n\n pkt->dts = x265pic_out.dts;\n\n\n\n switch (x265pic_out.sliceType) {\n\n case X265_TYPE_IDR:\n\n case X265_TYPE_I:\n\n avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;\n\n break;\n\n case X265_TYPE_P:\n\n avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;\n\n break;\n\n case X265_TYPE_B:\n\n avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;\n\n break;\n\n }\n\n\n\n *got_packet = 1;\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "04070dbca0688ab1e24528ce5c135254a9a79c47", + "length": 614 + }, + { + "index": 4749, + "code": "static int tcp_open(URLContext *h, const char *uri, int flags)\n\n{\n\n struct sockaddr_in dest_addr;\n\n char hostname[1024], *q;\n\n int port, fd = -1;\n\n TCPContext *s;\n\n const char *p;\n\n fd_set wfds;\n\n int fd_max, ret;\n\n struct timeval tv;\n\n socklen_t optlen;\n\n \n\n s = av_malloc(sizeof(TCPContext));\n\n if (!s)\n\n return -ENOMEM;\n\n h->priv_data = s;\n\n p = uri;\n\n if (!strstart(p, \"tcp://\", &p))\n\n goto fail;\n\n q = hostname;\n\n while (*p != ':' && *p != '/' && *p != '\\0') {\n\n if ((q - hostname) < sizeof(hostname) - 1)\n\n *q++ = *p;\n\n p++;\n\n }\n\n *q = '\\0';\n\n if (*p != ':')\n\n goto fail;\n\n p++;\n\n port = strtoul(p, (char **)&p, 10);\n\n if (port <= 0 || port >= 65536)\n\n goto fail;\n\n \n\n dest_addr.sin_family = AF_INET;\n\n dest_addr.sin_port = htons(port);\n\n if (resolve_host(&dest_addr.sin_addr, hostname) < 0)\n\n goto fail;\n\n\n\n fd = socket(PF_INET, SOCK_STREAM, 0);\n\n if (fd < 0)\n\n goto fail;\n\n fcntl(fd, F_SETFL, O_NONBLOCK);\n\n \n\n redo:\n\n ret = connect(fd, (struct sockaddr *)&dest_addr, \n\n sizeof(dest_addr));\n\n if (ret < 0) {\n\n if (errno == EINTR)\n\n goto redo;\n\n if (errno != EINPROGRESS)\n\n goto fail;\n\n\n\n /* wait until we are connected or until abort */\n\n for(;;) {\n\n if (url_interrupt_cb()) {\n\n ret = -EINTR;\n\n goto fail1;\n\n }\n\n fd_max = fd;\n\n FD_ZERO(&wfds);\n\n FD_SET(fd, &wfds);\n\n tv.tv_sec = 0;\n\n tv.tv_usec = 100 * 1000;\n\n ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);\n\n if (ret > 0 && FD_ISSET(fd, &wfds))\n\n break;\n\n }\n\n \n\n /* test error */\n\n optlen = sizeof(ret);\n\n getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);\n\n if (ret != 0)\n\n goto fail;\n\n }\n\n s->fd = fd;\n\n return 0;\n\n\n\n fail:\n\n ret = AVERROR_IO;\n\n fail1:\n\n if (fd >= 0)\n\n close(fd);\n\n av_free(s);\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "6ba5cbc699e77cae66bb719354fa142114b64eab", + "length": 592 + }, + { + "index": 7917, + "code": "static void nand_command(NANDFlashState *s)\n\n{\n\n unsigned int offset;\n\n switch (s->cmd) {\n\n case NAND_CMD_READ0:\n\n s->iolen = 0;\n\n break;\n\n\n\n case NAND_CMD_READID:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n nand_pushio_byte(s, s->manf_id);\n\n nand_pushio_byte(s, s->chip_id);\n\n nand_pushio_byte(s, 'Q'); /* Don't-care byte (often 0xa5) */\n\n if (nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP) {\n\n /* Page Size, Block Size, Spare Size; bit 6 indicates\n\n * 8 vs 16 bit width NAND.\n\n */\n\n nand_pushio_byte(s, (s->buswidth == 2) ? 0x55 : 0x15);\n\n } else {\n\n nand_pushio_byte(s, 0xc0); /* Multi-plane */\n\n }\n\n break;\n\n\n\n case NAND_CMD_RANDOMREAD2:\n\n case NAND_CMD_NOSERIALREAD2:\n\n if (!(nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP))\n\n break;\n\n offset = s->addr & ((1 << s->addr_shift) - 1);\n\n s->blk_load(s, s->addr, offset);\n\n if (s->gnd)\n\n s->iolen = (1 << s->page_shift) - offset;\n\n else\n\n s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset;\n\n break;\n\n\n\n case NAND_CMD_RESET:\n\n nand_reset(&s->busdev.qdev);\n\n break;\n\n\n\n case NAND_CMD_PAGEPROGRAM1:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n break;\n\n\n\n case NAND_CMD_PAGEPROGRAM2:\n\n if (s->wp) {\n\n s->blk_write(s);\n\n }\n\n break;\n\n\n\n case NAND_CMD_BLOCKERASE1:\n\n break;\n\n\n\n case NAND_CMD_BLOCKERASE2:\n\n s->addr &= (1ull << s->addrlen * 8) - 1;\n\n if (nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP)\n\n s->addr <<= 16;\n\n else\n\n s->addr <<= 8;\n\n\n\n if (s->wp) {\n\n s->blk_erase(s);\n\n }\n\n break;\n\n\n\n case NAND_CMD_READSTATUS:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n nand_pushio_byte(s, s->status);\n\n break;\n\n\n\n default:\n\n printf(\"%s: Unknown NAND command 0x%02x\\n\", __FUNCTION__, s->cmd);\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "1984745ea8ad309a06690a83e91d031d21d709ff", + "length": 609 + }, + { + "index": 3470, + "code": "static int frame_thread_init(AVCodecContext *avctx)\n\n{\n\n int thread_count = avctx->thread_count;\n\n AVCodec *codec = avctx->codec;\n\n AVCodecContext *src = avctx;\n\n FrameThreadContext *fctx;\n\n int i, err = 0;\n\n\n\n if (!thread_count) {\n\n int nb_cpus = get_logical_cpus(avctx);\n\n // use number of cores + 1 as thread count if there is motre than one\n\n if (nb_cpus > 1)\n\n thread_count = avctx->thread_count = nb_cpus + 1;\n\n }\n\n\n\n if (thread_count <= 1) {\n\n avctx->active_thread_type = 0;\n\n return 0;\n\n }\n\n\n\n avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));\n\n\n\n fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);\n\n pthread_mutex_init(&fctx->buffer_mutex, NULL);\n\n fctx->delaying = 1;\n\n\n\n for (i = 0; i < thread_count; i++) {\n\n AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));\n\n PerThreadContext *p = &fctx->threads[i];\n\n\n\n pthread_mutex_init(&p->mutex, NULL);\n\n pthread_mutex_init(&p->progress_mutex, NULL);\n\n pthread_cond_init(&p->input_cond, NULL);\n\n pthread_cond_init(&p->progress_cond, NULL);\n\n pthread_cond_init(&p->output_cond, NULL);\n\n\n\n p->parent = fctx;\n\n p->avctx = copy;\n\n\n\n if (!copy) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n\n\n *copy = *src;\n\n copy->thread_opaque = p;\n\n copy->pkt = &p->avpkt;\n\n\n\n if (!i) {\n\n src = copy;\n\n\n\n if (codec->init)\n\n err = codec->init(copy);\n\n\n\n update_context_from_thread(avctx, copy, 1);\n\n } else {\n\n copy->priv_data = av_malloc(codec->priv_data_size);\n\n if (!copy->priv_data) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);\n\n copy->internal = av_malloc(sizeof(AVCodecInternal));\n\n if (!copy->internal) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n *(copy->internal) = *(src->internal);\n\n copy->internal->is_copy = 1;\n\n\n\n if (codec->init_thread_copy)\n\n err = codec->init_thread_copy(copy);\n\n }\n\n\n\n if (err) goto error;\n\n\n\n if (!pthread_create(&p->thread, NULL, frame_worker_thread, p))\n\n p->thread_init = 1;\n\n }\n\n\n\n return 0;\n\n\n\nerror:\n\n frame_thread_free(avctx, i+1);\n\n\n\n return err;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "b12d21733975f9001eecb480fc28e5e4473b1327", + "length": 626 + }, + { + "index": 10806, + "code": "static int ffmal_update_format(AVCodecContext *avctx)\n\n{\n\n MMALDecodeContext *ctx = avctx->priv_data;\n\n MMAL_STATUS_T status;\n\n int ret = 0;\n\n MMAL_COMPONENT_T *decoder = ctx->decoder;\n\n MMAL_ES_FORMAT_T *format_out = decoder->output[0]->format;\n\n\n\n ffmmal_poolref_unref(ctx->pool_out);\n\n if (!(ctx->pool_out = av_mallocz(sizeof(*ctx->pool_out)))) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n atomic_store(&ctx->pool_out->refcount, 1);\n\n\n\n if (!format_out)\n\n goto fail;\n\n\n\n if ((status = mmal_port_parameter_set_uint32(decoder->output[0], MMAL_PARAMETER_EXTRA_BUFFERS, ctx->extra_buffers)))\n\n goto fail;\n\n\n\n if ((status = mmal_port_parameter_set_boolean(decoder->output[0], MMAL_PARAMETER_VIDEO_INTERPOLATE_TIMESTAMPS, 0)))\n\n goto fail;\n\n\n\n if (avctx->pix_fmt == AV_PIX_FMT_MMAL) {\n\n format_out->encoding = MMAL_ENCODING_OPAQUE;\n\n } else {\n\n format_out->encoding_variant = format_out->encoding = MMAL_ENCODING_I420;\n\n }\n\n\n\n if ((status = mmal_port_format_commit(decoder->output[0])))\n\n goto fail;\n\n\n\n if ((ret = ff_set_dimensions(avctx, format_out->es->video.crop.x + format_out->es->video.crop.width,\n\n format_out->es->video.crop.y + format_out->es->video.crop.height)) < 0)\n\n goto fail;\n\n\n\n if (format_out->es->video.par.num && format_out->es->video.par.den) {\n\n avctx->sample_aspect_ratio.num = format_out->es->video.par.num;\n\n avctx->sample_aspect_ratio.den = format_out->es->video.par.den;\n\n }\n\n\n\n avctx->colorspace = ffmmal_csp_to_av_csp(format_out->es->video.color_space);\n\n\n\n decoder->output[0]->buffer_size =\n\n FFMAX(decoder->output[0]->buffer_size_min, decoder->output[0]->buffer_size_recommended);\n\n decoder->output[0]->buffer_num =\n\n FFMAX(decoder->output[0]->buffer_num_min, decoder->output[0]->buffer_num_recommended) + ctx->extra_buffers;\n\n ctx->pool_out->pool = mmal_pool_create(decoder->output[0]->buffer_num,\n\n decoder->output[0]->buffer_size);\n\n if (!ctx->pool_out->pool) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n return 0;\n\n\n\nfail:\n\n return ret < 0 ? ret : AVERROR_UNKNOWN;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d82d5379caca21005d8906829b35361c4a65408e", + "length": 586 + }, + { + "index": 571, + "code": "static void setup_rt_frame(int sig, struct target_sigaction *ka,\n\n target_siginfo_t *info,\n\n target_sigset_t *set, CPUS390XState *env)\n\n{\n\n int i;\n\n rt_sigframe *frame;\n\n abi_ulong frame_addr;\n\n\n\n frame_addr = get_sigframe(ka, env, sizeof *frame);\n\n qemu_log(\"%s: frame_addr 0x%llx\\n\", __FUNCTION__,\n\n (unsigned long long)frame_addr);\n\n if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n qemu_log(\"%s: 1\\n\", __FUNCTION__);\n\n copy_siginfo_to_user(&frame->info, info);\n\n\n\n /* Create the ucontext. */\n\n __put_user(0, &frame->uc.tuc_flags);\n\n __put_user((abi_ulong)0, (abi_ulong *)&frame->uc.tuc_link);\n\n __put_user(target_sigaltstack_used.ss_sp, &frame->uc.tuc_stack.ss_sp);\n\n __put_user(sas_ss_flags(get_sp_from_cpustate(env)),\n\n &frame->uc.tuc_stack.ss_flags);\n\n __put_user(target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);\n\n save_sigregs(env, &frame->uc.tuc_mcontext);\n\n for (i = 0; i < TARGET_NSIG_WORDS; i++) {\n\n __put_user((abi_ulong)set->sig[i],\n\n (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);\n\n }\n\n\n\n /* Set up to return from userspace. If provided, use a stub\n\n already in userspace. */\n\n if (ka->sa_flags & TARGET_SA_RESTORER) {\n\n env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;\n\n } else {\n\n env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;\n\n if (__put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,\n\n (uint16_t *)(frame->retcode))) {\n\n goto give_sigsegv;\n\n }\n\n }\n\n\n\n /* Set up backchain. */\n\n if (__put_user(env->regs[15], (abi_ulong *) frame)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n /* Set up registers for signal handler */\n\n env->regs[15] = frame_addr;\n\n env->psw.addr = (target_ulong) ka->_sa_handler | PSW_ADDR_AMODE;\n\n\n\n env->regs[2] = sig; //map_signal(sig);\n\n env->regs[3] = frame_addr + offsetof(typeof(*frame), info);\n\n env->regs[4] = frame_addr + offsetof(typeof(*frame), uc);\n\n return;\n\n\n\ngive_sigsegv:\n\n qemu_log(\"%s: give_sigsegv\\n\", __FUNCTION__);\n\n unlock_user_struct(frame, frame_addr, 1);\n\n force_sig(TARGET_SIGSEGV);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "0188fadb7fe460d8c4c743372b1f7b25773e183e", + "length": 639 + }, + { + "index": 14026, + "code": "static int ehci_state_fetchqtd(EHCIQueue *q)\n\n{\n\n EHCIqtd qtd;\n\n EHCIPacket *p;\n\n int again = 0;\n\n\n\n get_dwords(q->ehci, NLPTR_GET(q->qtdaddr), (uint32_t *) &qtd,\n\n sizeof(EHCIqtd) >> 2);\n\n ehci_trace_qtd(q, NLPTR_GET(q->qtdaddr), &qtd);\n\n\n\n p = QTAILQ_FIRST(&q->packets);\n\n if (p != NULL) {\n\n if (p->qtdaddr != q->qtdaddr ||\n\n (!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) ||\n\n (!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) ||\n\n p->qtd.bufptr[0] != qtd.bufptr[0]) {\n\n ehci_cancel_queue(q);\n\n ehci_trace_guest_bug(q->ehci, \"guest updated active QH or qTD\");\n\n p = NULL;\n\n } else {\n\n p->qtd = qtd;\n\n ehci_qh_do_overlay(q);\n\n }\n\n }\n\n\n\n if (!(qtd.token & QTD_TOKEN_ACTIVE)) {\n\n if (p != NULL) {\n\n /* transfer canceled by guest (clear active) */\n\n ehci_cancel_queue(q);\n\n p = NULL;\n\n }\n\n ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);\n\n again = 1;\n\n } else if (p != NULL) {\n\n switch (p->async) {\n\n case EHCI_ASYNC_NONE:\n\n /* Previously nacked packet (likely interrupt ep) */\n\n ehci_set_state(q->ehci, q->async, EST_EXECUTE);\n\n break;\n\n case EHCI_ASYNC_INFLIGHT:\n\n /* Unfinyshed async handled packet, go horizontal */\n\n ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);\n\n break;\n\n case EHCI_ASYNC_FINISHED:\n\n /* Should never happen, as this case is caught by fetchqh */\n\n ehci_set_state(q->ehci, q->async, EST_EXECUTING);\n\n break;\n\n }\n\n again = 1;\n\n } else {\n\n p = ehci_alloc_packet(q);\n\n p->qtdaddr = q->qtdaddr;\n\n p->qtd = qtd;\n\n ehci_set_state(q->ehci, q->async, EST_EXECUTE);\n\n again = 1;\n\n }\n\n\n\n return again;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "ef5b234477df80700b128f561f5877a0688a70c8", + "length": 565 + }, + { + "index": 18815, + "code": "static int decode_frame(FLACContext *s)\n\n{\n\n int i, ret;\n\n GetBitContext *gb = &s->gb;\n\n FLACFrameInfo fi;\n\n\n\n if ((ret = ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) < 0) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"invalid frame header\\n\");\n\n return ret;\n\n }\n\n\n\n if (s->channels && fi.channels != s->channels && s->got_streaminfo) {\n\n s->channels = s->avctx->channels = fi.channels;\n\n ff_flac_set_channel_layout(s->avctx);\n\n ret = allocate_buffers(s);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n s->channels = s->avctx->channels = fi.channels;\n\n if (!s->avctx->channel_layout)\n\n ff_flac_set_channel_layout(s->avctx);\n\n s->ch_mode = fi.ch_mode;\n\n\n\n if (!s->bps && !fi.bps) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"bps not found in STREAMINFO or frame header\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (!fi.bps) {\n\n fi.bps = s->bps;\n\n } else if (s->bps && fi.bps != s->bps) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"switching bps mid-stream is not \"\n\n \"supported\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (!s->bps) {\n\n s->bps = s->avctx->bits_per_raw_sample = fi.bps;\n\n flac_set_bps(s);\n\n }\n\n\n\n if (!s->max_blocksize)\n\n s->max_blocksize = FLAC_MAX_BLOCKSIZE;\n\n if (fi.blocksize > s->max_blocksize) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"blocksize %d > %d\\n\", fi.blocksize,\n\n s->max_blocksize);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n s->blocksize = fi.blocksize;\n\n\n\n if (!s->samplerate && !fi.samplerate) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"sample rate not found in STREAMINFO\"\n\n \" or frame header\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (fi.samplerate == 0)\n\n fi.samplerate = s->samplerate;\n\n s->samplerate = s->avctx->sample_rate = fi.samplerate;\n\n\n\n if (!s->got_streaminfo) {\n\n ret = allocate_buffers(s);\n\n if (ret < 0)\n\n return ret;\n\n ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->channels, s->bps);\n\n s->got_streaminfo = 1;\n\n dump_headers(s->avctx, (FLACStreaminfo *)s);\n\n }\n\n\n\n// dump_headers(s->avctx, (FLACStreaminfo *)s);\n\n\n\n /* subframes */\n\n for (i = 0; i < s->channels; i++) {\n\n if ((ret = decode_subframe(s, i)) < 0)\n\n return ret;\n\n }\n\n\n\n align_get_bits(gb);\n\n\n\n /* frame footer */\n\n skip_bits(gb, 16); /* data crc */\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e5c01ccdf5a9a330d4c51a9b9ea721fd8f1fb70b", + "length": 720 + }, + { + "index": 1632, + "code": "av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)\n\n{\n\n const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;\n\n\n\n if (avctx->lowres==1) {\n\n c->idct_put = ff_jref_idct4_put;\n\n c->idct_add = ff_jref_idct4_add;\n\n c->idct = ff_j_rev_dct4;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else if (avctx->lowres==2) {\n\n c->idct_put = ff_jref_idct2_put;\n\n c->idct_add = ff_jref_idct2_add;\n\n c->idct = ff_j_rev_dct2;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else if (avctx->lowres==3) {\n\n c->idct_put = ff_jref_idct1_put;\n\n c->idct_add = ff_jref_idct1_add;\n\n c->idct = ff_j_rev_dct1;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else {\n\n if (avctx->bits_per_raw_sample == 10) {\n\n c->idct_put = ff_simple_idct_put_10;\n\n c->idct_add = ff_simple_idct_add_10;\n\n c->idct = ff_simple_idct_10;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else if (avctx->bits_per_raw_sample == 12) {\n\n c->idct_put = ff_simple_idct_put_12;\n\n c->idct_add = ff_simple_idct_add_12;\n\n c->idct = ff_simple_idct_12;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else {\n\n if (avctx->idct_algo == FF_IDCT_INT) {\n\n c->idct_put = ff_jref_idct_put;\n\n c->idct_add = ff_jref_idct_add;\n\n c->idct = ff_j_rev_dct;\n\n c->perm_type = FF_IDCT_PERM_LIBMPEG2;\n\n } else if (avctx->idct_algo == FF_IDCT_FAAN) {\n\n c->idct_put = ff_faanidct_put;\n\n c->idct_add = ff_faanidct_add;\n\n c->idct = ff_faanidct;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n } else { // accurate/default\n\n c->idct_put = ff_simple_idct_put_8;\n\n c->idct_add = ff_simple_idct_add_8;\n\n c->idct = ff_simple_idct_8;\n\n c->perm_type = FF_IDCT_PERM_NONE;\n\n }\n\n }\n\n }\n\n\n\n c->put_pixels_clamped = put_pixels_clamped_c;\n\n c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;\n\n c->add_pixels_clamped = add_pixels_clamped_c;\n\n\n\n ff_put_pixels_clamped = c->put_pixels_clamped;\n\n ff_add_pixels_clamped = c->add_pixels_clamped;\n\n\n\n if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)\n\n ff_xvid_idct_init(c, avctx);\n\n\n\n if (ARCH_ALPHA)\n\n ff_idctdsp_init_alpha(c, avctx, high_bit_depth);\n\n if (ARCH_ARM)\n\n ff_idctdsp_init_arm(c, avctx, high_bit_depth);\n\n if (ARCH_PPC)\n\n ff_idctdsp_init_ppc(c, avctx, high_bit_depth);\n\n if (ARCH_X86)\n\n ff_idctdsp_init_x86(c, avctx, high_bit_depth);\n\n\n\n ff_init_scantable_permutation(c->idct_permutation,\n\n c->perm_type);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "928cb84b32b639841ac1ec2957155a6abd53309f", + "length": 867 + }, + { + "index": 26495, + "code": "static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,\n\n int64_t offset_in_cluster, QEMUIOVector *qiov,\n\n uint64_t qiov_offset, uint64_t n_bytes,\n\n uint64_t offset)\n\n{\n\n int ret;\n\n VmdkGrainMarker *data = NULL;\n\n uLongf buf_len;\n\n QEMUIOVector local_qiov;\n\n struct iovec iov;\n\n int64_t write_offset;\n\n int64_t write_end_sector;\n\n\n\n if (extent->compressed) {\n\n void *compressed_data;\n\n\n\n if (!extent->has_marker) {\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n buf_len = (extent->cluster_sectors << 9) * 2;\n\n data = g_malloc(buf_len + sizeof(VmdkGrainMarker));\n\n\n\n compressed_data = g_malloc(n_bytes);\n\n qemu_iovec_to_buf(qiov, qiov_offset, compressed_data, n_bytes);\n\n ret = compress(data->data, &buf_len, compressed_data, n_bytes);\n\n g_free(compressed_data);\n\n\n\n if (ret != Z_OK || buf_len == 0) {\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n data->lba = offset >> BDRV_SECTOR_BITS;\n\n data->size = buf_len;\n\n\n\n n_bytes = buf_len + sizeof(VmdkGrainMarker);\n\n iov = (struct iovec) {\n\n .iov_base = data,\n\n .iov_len = n_bytes,\n\n };\n\n qemu_iovec_init_external(&local_qiov, &iov, 1);\n\n } else {\n\n qemu_iovec_init(&local_qiov, qiov->niov);\n\n qemu_iovec_concat(&local_qiov, qiov, qiov_offset, n_bytes);\n\n }\n\n\n\n write_offset = cluster_offset + offset_in_cluster,\n\n ret = bdrv_co_pwritev(extent->file->bs, write_offset, n_bytes,\n\n &local_qiov, 0);\n\n\n\n write_end_sector = DIV_ROUND_UP(write_offset + n_bytes, BDRV_SECTOR_SIZE);\n\n\n\n if (extent->compressed) {\n\n extent->next_cluster_sector = write_end_sector;\n\n } else {\n\n extent->next_cluster_sector = MAX(extent->next_cluster_sector,\n\n write_end_sector);\n\n }\n\n\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n ret = 0;\n\n out:\n\n g_free(data);\n\n if (!extent->compressed) {\n\n qemu_iovec_destroy(&local_qiov);\n\n }\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a03ef88f77af045a2eb9629b5ce774a3fb973c5e", + "length": 549 + }, + { + "index": 21254, + "code": "static int ffm_read_data(AVFormatContext *s,\n\n uint8_t *buf, int size, int header)\n\n{\n\n FFMContext *ffm = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n int len, fill_size, size1, frame_offset, id;\n\n int64_t last_pos = -1;\n\n\n\n size1 = size;\n\n while (size > 0) {\n\n redo:\n\n len = ffm->packet_end - ffm->packet_ptr;\n\n if (len < 0)\n\n return -1;\n\n if (len > size)\n\n len = size;\n\n if (len == 0) {\n\n if (avio_tell(pb) == ffm->file_size)\n\n avio_seek(pb, ffm->packet_size, SEEK_SET);\n\n retry_read:\n\n if (pb->buffer_size != ffm->packet_size) {\n\n int64_t tell = avio_tell(pb);\n\n ffio_set_buf_size(pb, ffm->packet_size);\n\n avio_seek(pb, tell, SEEK_SET);\n\n }\n\n id = avio_rb16(pb); /* PACKET_ID */\n\n if (id != PACKET_ID) {\n\n if (ffm_resync(s, id) < 0)\n\n return -1;\n\n last_pos = avio_tell(pb);\n\n }\n\n fill_size = avio_rb16(pb);\n\n ffm->dts = avio_rb64(pb);\n\n frame_offset = avio_rb16(pb);\n\n avio_read(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);\n\n ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);\n\n if (ffm->packet_end < ffm->packet || frame_offset < 0)\n\n return -1;\n\n /* if first packet or resynchronization packet, we must\n\n handle it specifically */\n\n if (ffm->first_packet || (frame_offset & 0x8000)) {\n\n if (!frame_offset) {\n\n /* This packet has no frame headers in it */\n\n if (avio_tell(pb) >= ffm->packet_size * 3LL) {\n\n int64_t seekback = FFMIN(ffm->packet_size * 2LL, avio_tell(pb) - last_pos);\n\n seekback = FFMAX(seekback, 0);\n\n avio_seek(pb, -seekback, SEEK_CUR);\n\n goto retry_read;\n\n }\n\n /* This is bad, we cannot find a valid frame header */\n\n return 0;\n\n }\n\n ffm->first_packet = 0;\n\n if ((frame_offset & 0x7fff) < FFM_HEADER_SIZE)\n\n return -1;\n\n ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;\n\n if (!header)\n\n break;\n\n } else {\n\n ffm->packet_ptr = ffm->packet;\n\n }\n\n goto redo;\n\n }\n\n memcpy(buf, ffm->packet_ptr, len);\n\n buf += len;\n\n ffm->packet_ptr += len;\n\n size -= len;\n\n header = 0;\n\n }\n\n return size1 - size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "dc55477a64cefebf8dcc611f026be71382814ae2", + "length": 673 + }, + { + "index": 17765, + "code": "int show_license(void *optctx, const char *opt, const char *arg)\n\n{\n\n printf(\n\n#if CONFIG_NONFREE\n\n \"This version of %s has nonfree parts compiled in.\\n\"\n\n \"Therefore it is not legally redistributable.\\n\",\n\n program_name\n\n#elif CONFIG_GPLV3\n\n \"%s is free software; you can redistribute it and/or modify\\n\"\n\n \"it under the terms of the GNU General Public License as published by\\n\"\n\n \"the Free Software Foundation; either version 3 of the License, or\\n\"\n\n \"(at your option) any later version.\\n\"\n\n \"\\n\"\n\n \"%s is distributed in the hope that it will be useful,\\n\"\n\n \"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\"\n\n \"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\\n\"\n\n \"GNU General Public License for more details.\\n\"\n\n \"\\n\"\n\n \"You should have received a copy of the GNU General Public License\\n\"\n\n \"along with %s. If not, see .\\n\",\n\n program_name, program_name, program_name\n\n#elif CONFIG_GPL\n\n \"%s is free software; you can redistribute it and/or modify\\n\"\n\n \"it under the terms of the GNU General Public License as published by\\n\"\n\n \"the Free Software Foundation; either version 2 of the License, or\\n\"\n\n \"(at your option) any later version.\\n\"\n\n \"\\n\"\n\n \"%s is distributed in the hope that it will be useful,\\n\"\n\n \"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\"\n\n \"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\\n\"\n\n \"GNU General Public License for more details.\\n\"\n\n \"\\n\"\n\n \"You should have received a copy of the GNU General Public License\\n\"\n\n \"along with %s; if not, write to the Free Software\\n\"\n\n \"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\\n\",\n\n program_name, program_name, program_name\n\n#elif CONFIG_LGPLV3\n\n \"%s is free software; you can redistribute it and/or modify\\n\"\n\n \"it under the terms of the GNU Lesser General Public License as published by\\n\"\n\n \"the Free Software Foundation; either version 3 of the License, or\\n\"\n\n \"(at your option) any later version.\\n\"\n\n \"\\n\"\n\n \"%s is distributed in the hope that it will be useful,\\n\"\n\n \"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\"\n\n \"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\\n\"\n\n \"GNU Lesser General Public License for more details.\\n\"\n\n \"\\n\"\n\n \"You should have received a copy of the GNU Lesser General Public License\\n\"\n\n \"along with %s. If not, see .\\n\",\n\n program_name, program_name, program_name\n\n#else\n\n \"%s is free software; you can redistribute it and/or\\n\"\n\n \"modify it under the terms of the GNU Lesser General Public\\n\"\n\n \"License as published by the Free Software Foundation; either\\n\"\n\n \"version 2.1 of the License, or (at your option) any later version.\\n\"\n\n \"\\n\"\n\n \"%s is distributed in the hope that it will be useful,\\n\"\n\n \"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\"\n\n \"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\\n\"\n\n \"Lesser General Public License for more details.\\n\"\n\n \"\\n\"\n\n \"You should have received a copy of the GNU Lesser General Public\\n\"\n\n \"License along with %s; if not, write to the Free Software\\n\"\n\n \"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\\n\",\n\n program_name, program_name, program_name\n\n#endif\n\n );\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "c5be6192f0a50eb8a2134c32b7d57f1d88736adf", + "length": 854 + }, + { + "index": 26203, + "code": "static void vfio_iommu_map_notify(Notifier *n, void *data)\n\n{\n\n VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);\n\n VFIOContainer *container = giommu->container;\n\n IOMMUTLBEntry *iotlb = data;\n\n hwaddr iova = iotlb->iova + giommu->iommu_offset;\n\n MemoryRegion *mr;\n\n hwaddr xlat;\n\n hwaddr len = iotlb->addr_mask + 1;\n\n void *vaddr;\n\n int ret;\n\n\n\n trace_vfio_iommu_map_notify(iova, iova + iotlb->addr_mask);\n\n\n\n if (iotlb->target_as != &address_space_memory) {\n\n error_report(\"Wrong target AS \\\"%s\\\", only system memory is allowed\",\n\n iotlb->target_as->name ? iotlb->target_as->name : \"none\");\n\n return;\n\n }\n\n\n\n /*\n\n * The IOMMU TLB entry we have just covers translation through\n\n * this IOMMU to its immediate target. We need to translate\n\n * it the rest of the way through to memory.\n\n */\n\n rcu_read_lock();\n\n mr = address_space_translate(&address_space_memory,\n\n iotlb->translated_addr,\n\n &xlat, &len, iotlb->perm & IOMMU_WO);\n\n if (!memory_region_is_ram(mr)) {\n\n error_report(\"iommu map to non memory area %\"HWADDR_PRIx\"\",\n\n xlat);\n\n goto out;\n\n }\n\n /*\n\n * Translation truncates length to the IOMMU page size,\n\n * check that it did not truncate too much.\n\n */\n\n if (len & iotlb->addr_mask) {\n\n error_report(\"iommu has granularity incompatible with target AS\");\n\n goto out;\n\n }\n\n\n\n if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {\n\n vaddr = memory_region_get_ram_ptr(mr) + xlat;\n\n ret = vfio_dma_map(container, iova,\n\n iotlb->addr_mask + 1, vaddr,\n\n !(iotlb->perm & IOMMU_WO) || mr->readonly);\n\n if (ret) {\n\n error_report(\"vfio_dma_map(%p, 0x%\"HWADDR_PRIx\", \"\n\n \"0x%\"HWADDR_PRIx\", %p) = %d (%m)\",\n\n container, iova,\n\n iotlb->addr_mask + 1, vaddr, ret);\n\n }\n\n } else {\n\n ret = vfio_dma_unmap(container, iova, iotlb->addr_mask + 1);\n\n if (ret) {\n\n error_report(\"vfio_dma_unmap(%p, 0x%\"HWADDR_PRIx\", \"\n\n \"0x%\"HWADDR_PRIx\") = %d (%m)\",\n\n container, iova,\n\n iotlb->addr_mask + 1, ret);\n\n }\n\n }\n\nout:\n\n rcu_read_unlock();\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "cdb3081269347fd9271fd1b7a9df312e2953bdd9", + "length": 661 + }, + { + "index": 2322, + "code": "static av_cold void compute_alpha_vlcs(void)\n\n{\n\n uint16_t run_code[129], level_code[256];\n\n uint8_t run_bits[129], level_bits[256];\n\n int run, level;\n\n\n\n for (run = 0; run < 128; run++) {\n\n if (!run) {\n\n /* 0 -> 0. */\n\n run_code[run] = 0;\n\n run_bits[run] = 1;\n\n } else if (run <= 4) {\n\n /* 10xx -> xx plus 1. */\n\n run_code[run] = ((run - 1) << 2) | 1;\n\n run_bits[run] = 4;\n\n } else {\n\n /* 111xxxxxxx -> xxxxxxxx. */\n\n run_code[run] = (run << 3) | 7;\n\n run_bits[run] = 10;\n\n }\n\n }\n\n\n\n /* 110 -> EOB. */\n\n run_code[128] = 3;\n\n run_bits[128] = 3;\n\n\n\n INIT_LE_VLC_STATIC(&ff_dc_alpha_run_vlc_le, ALPHA_VLC_BITS, 129,\n\n run_bits, 1, 1,\n\n run_code, 2, 2, 160);\n\n\n\n for (level = 0; level < 256; level++) {\n\n int8_t signed_level = (int8_t)level;\n\n int abs_signed_level = abs(signed_level);\n\n int sign = (signed_level < 0) ? 1 : 0;\n\n\n\n if (abs_signed_level == 1) {\n\n /* 1s -> -1 or +1 (depending on sign bit). */\n\n level_code[level] = (sign << 1) | 1;\n\n level_bits[level] = 2;\n\n } else if (abs_signed_level >= 2 && abs_signed_level <= 5) {\n\n /* 01sxx -> xx plus 2 (2..5 or -2..-5, depending on sign bit). */\n\n level_code[level] = ((abs_signed_level - 2) << 3) | (sign << 2) | 2;\n\n level_bits[level] = 5;\n\n } else {\n\n /*\n\n * 00xxxxxxxx -> xxxxxxxx, in two's complement. 0 is technically an\n\n * illegal code (that would be encoded by increasing run), but it\n\n * doesn't hurt and simplifies indexing.\n\n */\n\n level_code[level] = level << 2;\n\n level_bits[level] = 10;\n\n }\n\n }\n\n\n\n INIT_LE_VLC_STATIC(&ff_dc_alpha_level_vlc_le, ALPHA_VLC_BITS, 256,\n\n level_bits, 1, 1,\n\n level_code, 2, 2, 288);\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "08b098169be079c4f124a351fda6764fbcd10e79", + "length": 601 + }, + { + "index": 13788, + "code": "static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)\n\n{\n\n MovieContext *movie = ctx->priv;\n\n AVPacket *pkt = &movie->pkt;\n\n enum AVMediaType frame_type;\n\n MovieStream *st;\n\n int ret, got_frame = 0, pkt_out_id;\n\n AVFilterLink *outlink;\n\n\n\n if (!pkt->size) {\n\n if (movie->eof) {\n\n if (movie->st[out_id].done) {\n\n if (movie->loop_count != 1) {\n\n ret = rewind_file(ctx);\n\n if (ret < 0)\n\n return ret;\n\n movie->loop_count -= movie->loop_count > 1;\n\n av_log(ctx, AV_LOG_VERBOSE, \"Stream finished, looping.\\n\");\n\n return 0; /* retry */\n\n }\n\n return AVERROR_EOF;\n\n }\n\n pkt->stream_index = movie->st[out_id].st->index;\n\n /* packet is already ready for flushing */\n\n } else {\n\n ret = av_read_frame(movie->format_ctx, &movie->pkt0);\n\n if (ret < 0) {\n\n av_init_packet(&movie->pkt0); /* ready for flushing */\n\n *pkt = movie->pkt0;\n\n if (ret == AVERROR_EOF) {\n\n movie->eof = 1;\n\n return 0; /* start flushing */\n\n }\n\n return ret;\n\n }\n\n *pkt = movie->pkt0;\n\n }\n\n }\n\n\n\n pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :\n\n movie->out_index[pkt->stream_index];\n\n if (pkt_out_id < 0) {\n\n av_free_packet(&movie->pkt0);\n\n pkt->size = 0; /* ready for next run */\n\n pkt->data = NULL;\n\n return 0;\n\n }\n\n st = &movie->st[pkt_out_id];\n\n outlink = ctx->outputs[pkt_out_id];\n\n\n\n movie->frame = av_frame_alloc();\n\n if (!movie->frame)\n\n return AVERROR(ENOMEM);\n\n\n\n frame_type = st->st->codec->codec_type;\n\n switch (frame_type) {\n\n case AVMEDIA_TYPE_VIDEO:\n\n ret = avcodec_decode_video2(st->st->codec, movie->frame, &got_frame, pkt);\n\n break;\n\n case AVMEDIA_TYPE_AUDIO:\n\n ret = avcodec_decode_audio4(st->st->codec, movie->frame, &got_frame, pkt);\n\n break;\n\n default:\n\n ret = AVERROR(ENOSYS);\n\n break;\n\n }\n\n if (ret < 0) {\n\n av_log(ctx, AV_LOG_WARNING, \"Decode error: %s\\n\", av_err2str(ret));\n\n av_frame_free(&movie->frame);\n\n av_free_packet(&movie->pkt0);\n\n movie->pkt.size = 0;\n\n movie->pkt.data = NULL;\n\n return 0;\n\n }\n\n if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)\n\n ret = pkt->size;\n\n\n\n pkt->data += ret;\n\n pkt->size -= ret;\n\n if (pkt->size <= 0) {\n\n av_free_packet(&movie->pkt0);\n\n pkt->size = 0; /* ready for next run */\n\n pkt->data = NULL;\n\n }\n\n if (!got_frame) {\n\n if (!ret)\n\n st->done = 1;\n\n av_frame_free(&movie->frame);\n\n return 0;\n\n }\n\n\n\n movie->frame->pts = av_frame_get_best_effort_timestamp(movie->frame);\n\n av_dlog(ctx, \"movie_push_frame(): file:'%s' %s\\n\", movie->file_name,\n\n describe_frame_to_str((char[1024]){0}, 1024, movie->frame, frame_type, outlink));\n\n\n\n if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n\n if (movie->frame->format != outlink->format) {\n\n av_log(ctx, AV_LOG_ERROR, \"Format changed %s -> %s, discarding frame\\n\",\n\n av_get_pix_fmt_name(outlink->format),\n\n av_get_pix_fmt_name(movie->frame->format)\n\n );\n\n av_frame_free(&movie->frame);\n\n return 0;\n\n }\n\n }\n\n ret = ff_filter_frame(outlink, movie->frame);\n\n movie->frame = NULL;\n\n\n\n if (ret < 0)\n\n return ret;\n\n return pkt_out_id == out_id;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "97392553656a7f4fabde9ded4d2b7f538d98ee17", + "length": 955 + }, + { + "index": 6482, + "code": "static void postfilter(EVRCContext *e, float *in, const float *coeff,\n\n float *out, int idx, const struct PfCoeff *pfc,\n\n int length)\n\n{\n\n float wcoef1[FILTER_ORDER], wcoef2[FILTER_ORDER],\n\n scratch[SUBFRAME_SIZE], temp[SUBFRAME_SIZE],\n\n mem[SUBFRAME_SIZE];\n\n float sum1 = 0.0, sum2 = 0.0, gamma, gain;\n\n float tilt = pfc->tilt;\n\n int i, n, best;\n\n\n\n bandwidth_expansion(wcoef1, coeff, pfc->p1);\n\n bandwidth_expansion(wcoef2, coeff, pfc->p2);\n\n\n\n /* Tilt compensation filter, TIA/IS-127 5.9.1 */\n\n for (i = 0; i < length - 1; i++)\n\n sum2 += in[i] * in[i + 1];\n\n if (sum2 < 0.0)\n\n tilt = 0.0;\n\n\n\n for (i = 0; i < length; i++) {\n\n scratch[i] = in[i] - tilt * e->last;\n\n e->last = in[i];\n\n }\n\n\n\n /* Short term residual filter, TIA/IS-127 5.9.2 */\n\n residual_filter(&e->postfilter_residual[ACB_SIZE], scratch, wcoef1, e->postfilter_fir, length);\n\n\n\n /* Long term postfilter */\n\n best = idx;\n\n for (i = FFMIN(MIN_DELAY, idx - 3); i <= FFMAX(MAX_DELAY, idx + 3); i++) {\n\n for (n = ACB_SIZE, sum2 = 0; n < ACB_SIZE + length; n++)\n\n sum2 += e->postfilter_residual[n] * e->postfilter_residual[n - i];\n\n if (sum2 > sum1) {\n\n sum1 = sum2;\n\n best = i;\n\n }\n\n }\n\n\n\n for (i = ACB_SIZE, sum1 = 0; i < ACB_SIZE + length; i++)\n\n sum1 += e->postfilter_residual[i - best] * e->postfilter_residual[i - best];\n\n for (i = ACB_SIZE, sum2 = 0; i < ACB_SIZE + length; i++)\n\n sum2 += e->postfilter_residual[i] * e->postfilter_residual[i - best];\n\n\n\n if (sum2 * sum1 == 0 || e->bitrate == RATE_QUANT) {\n\n memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));\n\n } else {\n\n gamma = sum2 / sum1;\n\n if (gamma < 0.5)\n\n memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));\n\n else {\n\n gamma = FFMIN(gamma, 1.0);\n\n\n\n for (i = 0; i < length; i++) {\n\n temp[i] = e->postfilter_residual[ACB_SIZE + i] + gamma *\n\n pfc->ltgain * e->postfilter_residual[ACB_SIZE + i - best];\n\n }\n\n }\n\n }\n\n\n\n memcpy(scratch, temp, length * sizeof(float));\n\n memcpy(mem, e->postfilter_iir, FILTER_ORDER * sizeof(float));\n\n synthesis_filter(scratch, wcoef2, mem, length, scratch);\n\n\n\n /* Gain computation, TIA/IS-127 5.9.4-2 */\n\n for (i = 0, sum1 = 0, sum2 = 0; i < length; i++) {\n\n sum1 += in[i] * in[i];\n\n sum2 += scratch[i] * scratch[i];\n\n }\n\n gain = sum2 ? sqrt(sum1 / sum2) : 1.0;\n\n\n\n for (i = 0; i < length; i++)\n\n temp[i] *= gain;\n\n\n\n /* Short term postfilter */\n\n synthesis_filter(temp, wcoef2, e->postfilter_iir, length, out);\n\n\n\n memcpy(e->postfilter_residual,\n\n e->postfilter_residual + length, ACB_SIZE * sizeof(float));\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5ae484e350e4f1b20b31802dac59ca3519627c0a", + "length": 893 + }, + { + "index": 26664, + "code": "static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,\n\n AVFilterInOut *in)\n\n{\n\n AVFilterContext *last_filter;\n\n const AVFilter *abuffer_filt = avfilter_get_by_name(\"abuffer\");\n\n InputStream *ist = ifilter->ist;\n\n InputFile *f = input_files[ist->file_index];\n\n char args[255], name[255];\n\n int ret, pad_idx = 0;\n\n\n\n snprintf(args, sizeof(args), \"time_base=%d/%d:sample_rate=%d:sample_fmt=%s\"\n\n \":channel_layout=0x%\"PRIx64,\n\n 1, ist->st->codec->sample_rate,\n\n ist->st->codec->sample_rate,\n\n av_get_sample_fmt_name(ist->st->codec->sample_fmt),\n\n ist->st->codec->channel_layout);\n\n snprintf(name, sizeof(name), \"graph %d input from stream %d:%d\", fg->index,\n\n ist->file_index, ist->st->index);\n\n\n\n if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,\n\n name, args, NULL,\n\n fg->graph)) < 0)\n\n return ret;\n\n last_filter = ifilter->filter;\n\n\n\n if (audio_sync_method > 0) {\n\n AVFilterContext *async;\n\n int len = 0;\n\n\n\n av_log(NULL, AV_LOG_WARNING, \"-async has been deprecated. Used the \"\n\n \"asyncts audio filter instead.\\n\");\n\n\n\n if (audio_sync_method > 1)\n\n len += snprintf(args + len, sizeof(args) - len, \"compensate=1:\"\n\n \"max_comp=%d:\", audio_sync_method);\n\n snprintf(args + len, sizeof(args) - len, \"min_delta=%f\",\n\n audio_drift_threshold);\n\n\n\n snprintf(name, sizeof(name), \"graph %d audio sync for input stream %d:%d\",\n\n fg->index, ist->file_index, ist->st->index);\n\n ret = avfilter_graph_create_filter(&async,\n\n avfilter_get_by_name(\"asyncts\"),\n\n name, args, NULL, fg->graph);\n\n if (ret < 0)\n\n return ret;\n\n\n\n ret = avfilter_link(last_filter, 0, async, 0);\n\n if (ret < 0)\n\n return ret;\n\n\n\n last_filter = async;\n\n }\n\n if (audio_volume != 256) {\n\n AVFilterContext *volume;\n\n\n\n av_log(NULL, AV_LOG_WARNING, \"-vol has been deprecated. Use the volume \"\n\n \"audio filter instead.\\n\");\n\n\n\n snprintf(args, sizeof(args), \"volume=%f\", audio_volume / 256.0);\n\n\n\n snprintf(name, sizeof(name), \"graph %d volume for input stream %d:%d\",\n\n fg->index, ist->file_index, ist->st->index);\n\n ret = avfilter_graph_create_filter(&volume,\n\n avfilter_get_by_name(\"volume\"),\n\n name, args, NULL, fg->graph);\n\n if (ret < 0)\n\n return ret;\n\n\n\n ret = avfilter_link(last_filter, 0, volume, 0);\n\n if (ret < 0)\n\n return ret;\n\n\n\n last_filter = volume;\n\n }\n\n\n\n snprintf(name, sizeof(name), \"trim for input stream %d:%d\",\n\n ist->file_index, ist->st->index);\n\n ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?\n\n AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)\n\n return ret;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "488a0fa68973d48e264d54f1722f7afb18afbea7", + "length": 817 + }, + { + "index": 23031, + "code": "static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,\n\n const uint16_t *ubuf0, const uint16_t *ubuf1,\n\n const uint16_t *vbuf0, const uint16_t *vbuf1,\n\n const uint16_t *abuf0, uint8_t *dest,\n\n int dstW, int uvalpha, enum PixelFormat dstFormat,\n\n int flags, int y)\n\n{\n\n x86_reg uv_off = c->uv_off << 1;\n\n const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1\n\n\n\n if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2PACKED1(%%REGBP, %5, %6)\n\n WRITEYUY2(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n } else {\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2PACKED1b(%%REGBP, %5, %6)\n\n WRITEYUY2(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "009f829dde811af654af7110326aea3a72c05d5e", + "length": 562 + }, + { + "index": 3172, + "code": "static int webm_dash_manifest_cues(AVFormatContext *s)\n\n{\n\n MatroskaDemuxContext *matroska = s->priv_data;\n\n EbmlList *seekhead_list = &matroska->seekhead;\n\n MatroskaSeekhead *seekhead = seekhead_list->elem;\n\n char *buf;\n\n int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth;\n\n int i;\n\n\n\n // determine cues start and end positions\n\n for (i = 0; i < seekhead_list->nb_elem; i++)\n\n if (seekhead[i].id == MATROSKA_ID_CUES)\n\n break;\n\n\n\n if (i >= seekhead_list->nb_elem) return -1;\n\n\n\n before_pos = avio_tell(matroska->ctx->pb);\n\n cues_start = seekhead[i].pos + matroska->segment_start;\n\n if (avio_seek(matroska->ctx->pb, cues_start, SEEK_SET) == cues_start) {\n\n // cues_end is computed as cues_start + cues_length + length of the\n\n // Cues element ID + EBML length of the Cues element. cues_end is\n\n // inclusive and the above sum is reduced by 1.\n\n uint64_t cues_length = 0, cues_id = 0, bytes_read = 0;\n\n bytes_read += ebml_read_num(matroska, matroska->ctx->pb, 4, &cues_id);\n\n bytes_read += ebml_read_length(matroska, matroska->ctx->pb, &cues_length);\n\n cues_end = cues_start + cues_length + bytes_read - 1;\n\n }\n\n avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);\n\n if (cues_start == -1 || cues_end == -1) return -1;\n\n\n\n // parse the cues\n\n matroska_parse_cues(matroska);\n\n\n\n // cues start\n\n av_dict_set_int(&s->streams[0]->metadata, CUES_START, cues_start, 0);\n\n\n\n // cues end\n\n av_dict_set_int(&s->streams[0]->metadata, CUES_END, cues_end, 0);\n\n\n\n // bandwidth\n\n bandwidth = webm_dash_manifest_compute_bandwidth(s, cues_start);\n\n if (bandwidth < 0) return -1;\n\n av_dict_set_int(&s->streams[0]->metadata, BANDWIDTH, bandwidth, 0);\n\n\n\n // check if all clusters start with key frames\n\n av_dict_set_int(&s->streams[0]->metadata, CLUSTER_KEYFRAME, webm_clusters_start_with_keyframe(s), 0);\n\n\n\n // store cue point timestamps as a comma separated list for checking subsegment alignment in\n\n // the muxer. assumes that each timestamp cannot be more than 20 characters long.\n\n buf = av_malloc_array(s->streams[0]->nb_index_entries, 20 * sizeof(char));\n\n if (!buf) return -1;\n\n strcpy(buf, \"\");\n\n for (i = 0; i < s->streams[0]->nb_index_entries; i++) {\n\n snprintf(buf, (i + 1) * 20 * sizeof(char),\n\n \"%s%\" PRId64, buf, s->streams[0]->index_entries[i].timestamp);\n\n if (i != s->streams[0]->nb_index_entries - 1)\n\n strncat(buf, \",\", sizeof(char));\n\n }\n\n av_dict_set(&s->streams[0]->metadata, CUE_TIMESTAMPS, buf, 0);\n\n av_free(buf);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "8e6b9ef4733be91b32c8b7becd95124340b92334", + "length": 774 + }, + { + "index": 25157, + "code": "gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,\n\n int search_pc)\n\n{\n\n\tuint16_t *gen_opc_end;\n\n \tuint32_t pc_start;\n\n\tunsigned int insn_len;\n\n\tint j, lj;\n\n\tstruct DisasContext *dc = &ctx;\n\n\tuint32_t next_page_start;\n\n\n\n\tpc_start = tb->pc;\n\n\tdc->env = env;\n\n\tdc->tb = tb;\n\n\n\n\tgen_opc_end = gen_opc_buf + OPC_MAX_SIZE;\n\n\n\n\tdc->is_jmp = DISAS_NEXT;\n\n\tdc->pc = pc_start;\n\n\tdc->singlestep_enabled = env->singlestep_enabled;\n\n\tdc->flagx_live = 0;\n\n\tdc->flags_x = 0;\n\n\tnext_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;\n\n\tlj = -1;\n\n\tdo\n\n\t{\n\n\t\tcheck_breakpoint(env, dc);\n\n\t\tif (dc->is_jmp == DISAS_JUMP)\n\n\t\t\tgoto done;\n\n\n\n\t\tif (search_pc) {\n\n\t\t\tj = gen_opc_ptr - gen_opc_buf;\n\n\t\t\tif (lj < j) {\n\n\t\t\t\tlj++;\n\n\t\t\t\twhile (lj < j)\n\n\t\t\t\t\tgen_opc_instr_start[lj++] = 0;\n\n\t\t\t}\n\n\t\t\tgen_opc_pc[lj] = dc->pc;\n\n\t\t\tgen_opc_instr_start[lj] = 1;\n\n\t\t}\n\n\n\n\t\tinsn_len = cris_decoder(dc);\n\n\t\tSTATS(gen_op_exec_insn());\n\n\t\tdc->pc += insn_len;\n\n\t\tif (!dc->flagx_live\n\n\t\t || (dc->flagx_live &&\n\n\t\t\t!(dc->cc_op == CC_OP_FLAGS && dc->flags_x))) {\n\n\t\t\tgen_movl_T0_preg[PR_CCS]();\n\n\t\t\tgen_op_andl_T0_im(~X_FLAG);\n\n\t\t\tgen_movl_preg_T0[PR_CCS]();\n\n\t\t\tdc->flagx_live = 1;\n\n\t\t\tdc->flags_x = 0;\n\n\t\t}\n\n\n\n\t\t/* Check for delayed branches here. If we do it before\n\n\t\t actually genereating any host code, the simulator will just\n\n\t\t loop doing nothing for on this program location. */\n\n\t\tif (dc->delayed_branch) {\n\n\t\t\tdc->delayed_branch--;\n\n\t\t\tif (dc->delayed_branch == 0)\n\n\t\t\t{\n\n\t\t\t\tif (dc->bcc == CC_A) {\n\n\t\t\t\t\tgen_op_jmp1 ();\n\n\t\t\t\t\tdc->is_jmp = DISAS_UPDATE;\n\n\t\t\t\t}\n\n\t\t\t\telse {\n\n\t\t\t\t\t/* Conditional jmp. */\n\n\t\t\t\t\tgen_op_cc_jmp (dc->delayed_pc, dc->pc);\n\n\t\t\t\t\tdc->is_jmp = DISAS_UPDATE;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\n\n\t\tif (env->singlestep_enabled)\n\n\t\t\tbreak;\n\n\t} while (!dc->is_jmp && gen_opc_ptr < gen_opc_end\n\n\t\t && dc->pc < next_page_start);\n\n\n\n\tif (!dc->is_jmp) {\n\n\t\tgen_op_movl_T0_im((long)dc->pc);\n\n\t\tgen_op_movl_pc_T0();\n\n\t}\n\n\n\n\tcris_evaluate_flags (dc);\n\n done:\n\n\tif (__builtin_expect(env->singlestep_enabled, 0)) {\n\n\t\tgen_op_debug();\n\n\t} else {\n\n\t\tswitch(dc->is_jmp) {\n\n\t\t\tcase DISAS_NEXT:\n\n\t\t\t\tgen_goto_tb(dc, 1, dc->pc);\n\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\n\t\t\tcase DISAS_JUMP:\n\n\t\t\tcase DISAS_UPDATE:\n\n\t\t\t\t/* indicate that the hash table must be used\n\n\t\t\t\t to find the next TB */\n\n\t\t\t\ttcg_gen_exit_tb(0);\n\n\t\t\t\tbreak;\n\n\t\t\tcase DISAS_TB_JUMP:\n\n\t\t\t\t/* nothing more to generate */\n\n\t\t\t\tbreak;\n\n\t\t}\n\n\t}\n\n\t*gen_opc_ptr = INDEX_op_end;\n\n\tif (search_pc) {\n\n\t\tj = gen_opc_ptr - gen_opc_buf;\n\n\t\tlj++;\n\n\t\twhile (lj <= j)\n\n\t\t\tgen_opc_instr_start[lj++] = 0;\n\n\t} else {\n\n\t\ttb->size = dc->pc - pc_start;\n\n\t}\n\n\n\n#ifdef DEBUG_DISAS\n\n\tif (loglevel & CPU_LOG_TB_IN_ASM) {\n\n\t\tfprintf(logfile, \"--------------\\n\");\n\n\t\tfprintf(logfile, \"IN: %s\\n\", lookup_symbol(pc_start));\n\n\t\ttarget_disas(logfile, pc_start, dc->pc + 4 - pc_start, 0);\n\n\t\tfprintf(logfile, \"\\n\");\n\n\t}\n\n#endif\n\n\treturn 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "4f400ab52009ed8f76fa541454a4368f9515f897", + "length": 926 + }, + { + "index": 21293, + "code": "static int idcin_read_header(AVFormatContext *s)\n{\n AVIOContext *pb = s->pb;\n IdcinDemuxContext *idcin = s->priv_data;\n AVStream *st;\n unsigned int width, height;\n unsigned int sample_rate, bytes_per_sample, channels;\n /* get the 5 header parameters */\n width = avio_rl32(pb);\n height = avio_rl32(pb);\n sample_rate = avio_rl32(pb);\n bytes_per_sample = avio_rl32(pb);\n channels = avio_rl32(pb);\n st = avformat_new_stream(s, NULL);\n if (!st)\n return AVERROR(ENOMEM);\n avpriv_set_pts_info(st, 33, 1, IDCIN_FPS);\n idcin->video_stream_index = st->index;\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n st->codec->codec_id = AV_CODEC_ID_IDCIN;\n st->codec->codec_tag = 0; /* no fourcc */\n st->codec->width = width;\n st->codec->height = height;\n /* load up the Huffman tables into extradata */\n st->codec->extradata_size = HUFFMAN_TABLE_SIZE;\n st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE);\n if (avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) !=\n HUFFMAN_TABLE_SIZE)\n return AVERROR(EIO);\n /* if sample rate is 0, assume no audio */\n if (sample_rate) {\n idcin->audio_present = 1;\n st = avformat_new_stream(s, NULL);\n if (!st)\n return AVERROR(ENOMEM);\n avpriv_set_pts_info(st, 33, 1, IDCIN_FPS);\n idcin->audio_stream_index = st->index;\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_tag = 1;\n st->codec->channels = channels;\n st->codec->sample_rate = sample_rate;\n st->codec->bits_per_coded_sample = bytes_per_sample * 8;\n st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels;\n st->codec->block_align = bytes_per_sample * channels;\n if (bytes_per_sample == 1)\n st->codec->codec_id = AV_CODEC_ID_PCM_U8;\n else\n st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;\n if (sample_rate % 14 != 0) {\n idcin->audio_chunk_size1 = (sample_rate / 14) *\n bytes_per_sample * channels;\n idcin->audio_chunk_size2 = (sample_rate / 14 + 1) *\n bytes_per_sample * channels;\n } else {\n idcin->audio_chunk_size1 = idcin->audio_chunk_size2 =\n (sample_rate / 14) * bytes_per_sample * channels;\n idcin->current_audio_chunk = 0;\n } else\n idcin->audio_present = 1;\n idcin->next_chunk_is_video = 1;\n idcin->pts = 0;\n return 0;", + "label": 1, + "project": "FFmpeg", + "commit_id": "b0c96e06134d5c2aa3fa4f0951834c982ee99e3b", + "length": 695 + }, + { + "index": 13551, + "code": "static inline int check_bidir_mv(MpegEncContext * s,\n\n int motion_fx, int motion_fy,\n\n int motion_bx, int motion_by,\n\n int pred_fx, int pred_fy,\n\n int pred_bx, int pred_by,\n\n int size, int h)\n\n{\n\n //FIXME optimize?\n\n //FIXME better f_code prediction (max mv & distance)\n\n //FIXME pointers\n\n MotionEstContext * const c= &s->me;\n\n uint8_t * const mv_penalty_f= c->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame\n\n uint8_t * const mv_penalty_b= c->mv_penalty[s->b_code] + MAX_MV; // f_code of the prev frame\n\n int stride= c->stride;\n\n uint8_t *dest_y = c->scratchpad;\n\n uint8_t *ptr;\n\n int dxy;\n\n int src_x, src_y;\n\n int fbmin;\n\n uint8_t **src_data= c->src[0];\n\n uint8_t **ref_data= c->ref[0];\n\n uint8_t **ref2_data= c->ref[2];\n\n\n\n if(s->quarter_sample){\n\n dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);\n\n src_x = motion_fx >> 2;\n\n src_y = motion_fy >> 2;\n\n\n\n ptr = ref_data[0] + (src_y * stride) + src_x;\n\n s->qdsp.put_qpel_pixels_tab[0][dxy](dest_y, ptr, stride);\n\n\n\n dxy = ((motion_by & 3) << 2) | (motion_bx & 3);\n\n src_x = motion_bx >> 2;\n\n src_y = motion_by >> 2;\n\n\n\n ptr = ref2_data[0] + (src_y * stride) + src_x;\n\n s->qdsp.avg_qpel_pixels_tab[size][dxy](dest_y, ptr, stride);\n\n }else{\n\n dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);\n\n src_x = motion_fx >> 1;\n\n src_y = motion_fy >> 1;\n\n\n\n ptr = ref_data[0] + (src_y * stride) + src_x;\n\n s->hdsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h);\n\n\n\n dxy = ((motion_by & 1) << 1) | (motion_bx & 1);\n\n src_x = motion_bx >> 1;\n\n src_y = motion_by >> 1;\n\n\n\n ptr = ref2_data[0] + (src_y * stride) + src_x;\n\n s->hdsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h);\n\n }\n\n\n\n fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor\n\n +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor\n\n + s->mecc.mb_cmp[size](s, src_data[0], dest_y, stride, h); // FIXME new_pic\n\n\n\n if(c->avctx->mb_cmp&FF_CMP_CHROMA){\n\n }\n\n //FIXME CHROMA !!!\n\n\n\n return fbmin;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5b4da8a38a5ed211df9504c85ce401c30af86b97", + "length": 743 + }, + { + "index": 25343, + "code": "static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) {\n\n int i;\n\n for( i = 0; i < 8; i++, pix += stride) {\n\n int index_a;\n\n int alpha;\n\n int beta;\n\n\n\n int qp_index;\n\n int bS_index = i;\n\n\n\n if( bS[bS_index] == 0 ) {\n\n continue;\n\n }\n\n\n\n qp_index = MB_FIELD ? (i >> 2) : (i & 1);\n\n index_a = qp[qp_index] + h->slice_alpha_c0_offset;\n\n alpha = (alpha_table+52)[index_a];\n\n beta = (beta_table+52)[qp[qp_index] + h->slice_beta_offset];\n\n\n\n if( bS[bS_index] < 4 ) {\n\n const int tc = (tc0_table+52)[index_a][bS[bS_index]] + 1;\n\n const int p0 = pix[-1];\n\n const int p1 = pix[-2];\n\n const int q0 = pix[0];\n\n const int q1 = pix[1];\n\n\n\n if( FFABS( p0 - q0 ) < alpha &&\n\n FFABS( p1 - p0 ) < beta &&\n\n FFABS( q1 - q0 ) < beta ) {\n\n const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );\n\n\n\n pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */\n\n pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */\n\n tprintf(h->s.avctx, \"filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\\n\", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);\n\n }\n\n }else{\n\n const int p0 = pix[-1];\n\n const int p1 = pix[-2];\n\n const int q0 = pix[0];\n\n const int q1 = pix[1];\n\n\n\n if( FFABS( p0 - q0 ) < alpha &&\n\n FFABS( p1 - p0 ) < beta &&\n\n FFABS( q1 - q0 ) < beta ) {\n\n\n\n pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */\n\n pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */\n\n tprintf(h->s.avctx, \"filter_mb_mbaff_edgecv i:%d\\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\\n\", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);\n\n }\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "082cf97106e2e94a969877d4f8c05c1e526acf54", + "length": 825 + }, + { + "index": 8052, + "code": "uint32_t ide_ioport_read(void *opaque, uint32_t addr1)\n\n{\n\n IDEBus *bus = opaque;\n\n IDEState *s = idebus_active_if(bus);\n\n uint32_t addr;\n\n int ret, hob;\n\n\n\n addr = addr1 & 7;\n\n /* FIXME: HOB readback uses bit 7, but it's always set right now */\n\n //hob = s->select & (1 << 7);\n\n hob = 0;\n\n switch(addr) {\n\n case 0:\n\n ret = 0xff;\n\n break;\n\n case 1:\n\n if ((!bus->ifs[0].bs && !bus->ifs[1].bs) ||\n\n (s != bus->ifs && !s->bs))\n\n ret = 0;\n\n else if (!hob)\n\n ret = s->error;\n\n\telse\n\n\t ret = s->hob_feature;\n\n break;\n\n case 2:\n\n if (!bus->ifs[0].bs && !bus->ifs[1].bs)\n\n ret = 0;\n\n else if (!hob)\n\n ret = s->nsector & 0xff;\n\n\telse\n\n\t ret = s->hob_nsector;\n\n break;\n\n case 3:\n\n if (!bus->ifs[0].bs && !bus->ifs[1].bs)\n\n ret = 0;\n\n else if (!hob)\n\n ret = s->sector;\n\n\telse\n\n\t ret = s->hob_sector;\n\n break;\n\n case 4:\n\n if (!bus->ifs[0].bs && !bus->ifs[1].bs)\n\n ret = 0;\n\n else if (!hob)\n\n ret = s->lcyl;\n\n\telse\n\n\t ret = s->hob_lcyl;\n\n break;\n\n case 5:\n\n if (!bus->ifs[0].bs && !bus->ifs[1].bs)\n\n ret = 0;\n\n else if (!hob)\n\n ret = s->hcyl;\n\n\telse\n\n\t ret = s->hob_hcyl;\n\n break;\n\n case 6:\n\n if (!bus->ifs[0].bs && !bus->ifs[1].bs)\n\n ret = 0;\n\n else\n\n ret = s->select;\n\n break;\n\n default:\n\n case 7:\n\n if ((!bus->ifs[0].bs && !bus->ifs[1].bs) ||\n\n (s != bus->ifs && !s->bs))\n\n ret = 0;\n\n else\n\n ret = s->status;\n\n qemu_irq_lower(bus->irq);\n\n break;\n\n }\n\n#ifdef DEBUG_IDE\n\n printf(\"ide: read addr=0x%x val=%02x\\n\", addr1, ret);\n\n#endif\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4be746345f13e99e468c60acbd3a355e8183e3ce", + "length": 593 + }, + { + "index": 26742, + "code": "static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,\n\n int num_ports, dma_addr_t localmem_base,\n\n char *masterbus, uint32_t firstport,\n\n AddressSpace *as, Error **errp)\n\n{\n\n Error *err = NULL;\n\n int i;\n\n\n\n ohci->as = as;\n\n\n\n if (usb_frame_time == 0) {\n\n#ifdef OHCI_TIME_WARP\n\n usb_frame_time = get_ticks_per_sec();\n\n usb_bit_time = muldiv64(1, get_ticks_per_sec(), USB_HZ/1000);\n\n#else\n\n usb_frame_time = muldiv64(1, get_ticks_per_sec(), 1000);\n\n if (get_ticks_per_sec() >= USB_HZ) {\n\n usb_bit_time = muldiv64(1, get_ticks_per_sec(), USB_HZ);\n\n } else {\n\n usb_bit_time = 1;\n\n }\n\n#endif\n\n trace_usb_ohci_init_time(usb_frame_time, usb_bit_time);\n\n }\n\n\n\n ohci->num_ports = num_ports;\n\n if (masterbus) {\n\n USBPort *ports[OHCI_MAX_PORTS];\n\n for(i = 0; i < num_ports; i++) {\n\n ports[i] = &ohci->rhport[i].port;\n\n }\n\n usb_register_companion(masterbus, ports, num_ports,\n\n firstport, ohci, &ohci_port_ops,\n\n USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,\n\n &err);\n\n if (err) {\n\n error_propagate(errp, err);\n\n return;\n\n }\n\n } else {\n\n usb_bus_new(&ohci->bus, sizeof(ohci->bus), &ohci_bus_ops, dev);\n\n for (i = 0; i < num_ports; i++) {\n\n usb_register_port(&ohci->bus, &ohci->rhport[i].port,\n\n ohci, i, &ohci_port_ops,\n\n USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);\n\n }\n\n }\n\n\n\n memory_region_init_io(&ohci->mem, OBJECT(dev), &ohci_mem_ops,\n\n ohci, \"ohci\", 256);\n\n ohci->localmem_base = localmem_base;\n\n\n\n ohci->name = object_get_typename(OBJECT(dev));\n\n usb_packet_init(&ohci->usb_packet);\n\n\n\n ohci->async_td = 0;\n\n qemu_register_reset(ohci_reset, ohci);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "88dd1b8d0063ff16c54dc19c8b52508a00108f50", + "length": 521 + }, + { + "index": 23268, + "code": "static int handle_packet(MpegTSContext *ts, const uint8_t *packet)\n\n{\n\n AVFormatContext *s = ts->stream;\n\n MpegTSFilter *tss;\n\n int len, pid, cc, cc_ok, afc, is_start;\n\n const uint8_t *p, *p_end;\n\n int64_t pos;\n\n\n\n pid = AV_RB16(packet + 1) & 0x1fff;\n\n if(pid && discard_pid(ts, pid))\n\n return 0;\n\n is_start = packet[1] & 0x40;\n\n tss = ts->pids[pid];\n\n if (ts->auto_guess && tss == NULL && is_start) {\n\n add_pes_stream(ts, pid, -1, 0);\n\n tss = ts->pids[pid];\n\n }\n\n if (!tss)\n\n return 0;\n\n\n\n /* continuity check (currently not used) */\n\n cc = (packet[3] & 0xf);\n\n cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));\n\n tss->last_cc = cc;\n\n\n\n /* skip adaptation field */\n\n afc = (packet[3] >> 4) & 3;\n\n p = packet + 4;\n\n if (afc == 0) /* reserved value */\n\n return 0;\n\n if (afc == 2) /* adaptation field only */\n\n return 0;\n\n if (afc == 3) {\n\n /* skip adapation field */\n\n p += p[0] + 1;\n\n }\n\n /* if past the end of packet, ignore */\n\n p_end = packet + TS_PACKET_SIZE;\n\n if (p >= p_end)\n\n return 0;\n\n\n\n pos = url_ftell(ts->stream->pb);\n\n ts->pos47= pos % ts->raw_packet_size;\n\n\n\n if (tss->type == MPEGTS_SECTION) {\n\n if (is_start) {\n\n /* pointer field present */\n\n len = *p++;\n\n if (p + len > p_end)\n\n return 0;\n\n if (len && cc_ok) {\n\n /* write remaining section bytes */\n\n write_section_data(s, tss,\n\n p, len, 0);\n\n /* check whether filter has been closed */\n\n if (!ts->pids[pid])\n\n return 0;\n\n }\n\n p += len;\n\n if (p < p_end) {\n\n write_section_data(s, tss,\n\n p, p_end - p, 1);\n\n }\n\n } else {\n\n if (cc_ok) {\n\n write_section_data(s, tss,\n\n p, p_end - p, 0);\n\n }\n\n }\n\n } else {\n\n int ret;\n\n // Note: The position here points actually behind the current packet.\n\n if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,\n\n pos - ts->raw_packet_size)) < 0)\n\n return ret;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "b3f9f7a33337e9b64e6044b0010e2722fa0b2f9c", + "length": 662 + }, + { + "index": 1015, + "code": "static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,\n\n unsigned position, unsigned size)\n\n{\n\n const H264Context *h = avctx->priv_data;\n\n struct dxva_context *ctx = avctx->hwaccel_context;\n\n unsigned list;\n\n\n\n memset(slice, 0, sizeof(*slice));\n\n slice->BSNALunitDataLocation = position;\n\n slice->SliceBytesInBuffer = size;\n\n slice->wBadSliceChopping = 0;\n\n\n\n slice->first_mb_in_slice = (h->mb_y >> FIELD_OR_MBAFF_PICTURE(h)) * h->mb_width + h->mb_x;\n\n slice->NumMbsForSlice = 0; /* XXX it is set once we have all slices */\n\n slice->BitOffsetToSliceData = get_bits_count(&h->gb);\n\n slice->slice_type = ff_h264_get_slice_type(h);\n\n if (h->slice_type_fixed)\n\n slice->slice_type += 5;\n\n slice->luma_log2_weight_denom = h->luma_log2_weight_denom;\n\n slice->chroma_log2_weight_denom = h->chroma_log2_weight_denom;\n\n if (h->list_count > 0)\n\n slice->num_ref_idx_l0_active_minus1 = h->ref_count[0] - 1;\n\n if (h->list_count > 1)\n\n slice->num_ref_idx_l1_active_minus1 = h->ref_count[1] - 1;\n\n slice->slice_alpha_c0_offset_div2 = h->slice_alpha_c0_offset / 2;\n\n slice->slice_beta_offset_div2 = h->slice_beta_offset / 2;\n\n slice->Reserved8Bits = 0;\n\n\n\n for (list = 0; list < 2; list++) {\n\n unsigned i;\n\n for (i = 0; i < FF_ARRAY_ELEMS(slice->RefPicList[list]); i++) {\n\n if (list < h->list_count && i < h->ref_count[list]) {\n\n const Picture *r = &h->ref_list[list][i];\n\n unsigned plane;\n\n fill_picture_entry(&slice->RefPicList[list][i],\n\n ff_dxva2_get_surface_index(ctx, r),\n\n r->reference == PICT_BOTTOM_FIELD);\n\n for (plane = 0; plane < 3; plane++) {\n\n int w, o;\n\n if (plane == 0 && h->luma_weight_flag[list]) {\n\n w = h->luma_weight[i][list][0];\n\n o = h->luma_weight[i][list][1];\n\n } else if (plane >= 1 && h->chroma_weight_flag[list]) {\n\n w = h->chroma_weight[i][list][plane-1][0];\n\n o = h->chroma_weight[i][list][plane-1][1];\n\n } else {\n\n w = 1 << (plane == 0 ? h->luma_log2_weight_denom :\n\n h->chroma_log2_weight_denom);\n\n o = 0;\n\n }\n\n slice->Weights[list][i][plane][0] = w;\n\n slice->Weights[list][i][plane][1] = o;\n\n }\n\n } else {\n\n unsigned plane;\n\n slice->RefPicList[list][i].bPicEntry = 0xff;\n\n for (plane = 0; plane < 3; plane++) {\n\n slice->Weights[list][i][plane][0] = 0;\n\n slice->Weights[list][i][plane][1] = 0;\n\n }\n\n }\n\n }\n\n }\n\n slice->slice_qs_delta = 0; /* XXX not implemented by FFmpeg */\n\n slice->slice_qp_delta = h->qscale - h->pps.init_qp;\n\n slice->redundant_pic_cnt = h->redundant_pic_count;\n\n if (h->slice_type == AV_PICTURE_TYPE_B)\n\n slice->direct_spatial_mv_pred_flag = h->direct_spatial_mv_pred;\n\n slice->cabac_init_idc = h->pps.cabac ? h->cabac_init_idc : 0;\n\n if (h->deblocking_filter < 2)\n\n slice->disable_deblocking_filter_idc = 1 - h->deblocking_filter;\n\n else\n\n slice->disable_deblocking_filter_idc = h->deblocking_filter;\n\n slice->slice_id = h->current_slice - 1;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "276839b8de7ff836a529bbd6221f615a343b23e1", + "length": 966 + }, + { + "index": 4383, + "code": "void cpu_reset(CPUX86State *env)\n{\n int i;\n memset(env, 0, offsetof(CPUX86State, breakpoints));\n tlb_flush(env, 1);\n env->old_exception = -1;\n /* init to reset state */\n#ifdef CONFIG_SOFTMMU\n env->hflags |= HF_SOFTMMU_MASK;\n#endif\n env->hflags2 |= HF2_GIF_MASK;\n cpu_x86_update_cr0(env, 0x60000010);\n env->a20_mask = ~0x0;\n env->smbase = 0x30000;\n env->idt.limit = 0xffff;\n env->gdt.limit = 0xffff;\n env->ldt.limit = 0xffff;\n env->ldt.flags = DESC_P_MASK | (2 << DESC_TYPE_SHIFT);\n env->tr.limit = 0xffff;\n env->tr.flags = DESC_P_MASK | (11 << DESC_TYPE_SHIFT);\n cpu_x86_load_seg_cache(env, R_CS, 0xf000, 0xffff0000, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | DESC_R_MASK);\n cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_W_MASK);\n cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_W_MASK);\n cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_W_MASK);\n cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_W_MASK);\n cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffff,\n DESC_P_MASK | DESC_S_MASK | DESC_W_MASK);\n env->eip = 0xfff0;\n env->regs[R_EDX] = env->cpuid_version;\n env->eflags = 0x2;\n /* FPU init */\n for(i = 0;i < 8; i++)\n env->fptags[i] = 1;\n env->fpuc = 0x37f;\n env->mxcsr = 0x1f80;\n memset(env->dr, 0, sizeof(env->dr));\n env->dr[6] = DR6_FIXED_1;\n env->dr[7] = DR7_FIXED_1;\n cpu_breakpoint_remove_all(env, BP_CPU);\n cpu_watchpoint_remove_all(env, BP_CPU);", + "label": 1, + "project": "qemu", + "commit_id": "eca1bdf415c454093dfc7eb983cd49287c043967", + "length": 587 + }, + { + "index": 26948, + "code": "static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)\n\n{\n\n int class;\n\n QObject *obj;\n\n\n\n obj = qobject_from_jsonf(\"{ 'bus': %d, 'slot': %d, 'function': %d,\" \"'class_info': %p, 'id': %p, 'regions': %p,\"\n\n \" 'qdev_id': %s }\",\n\n bus_num,\n\n PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),\n\n pci_get_dev_class(dev), pci_get_dev_id(dev),\n\n pci_get_regions_list(dev),\n\n dev->qdev.id ? dev->qdev.id : \"\");\n\n\n\n if (dev->config[PCI_INTERRUPT_PIN] != 0) {\n\n QDict *qdict = qobject_to_qdict(obj);\n\n qdict_put(qdict, \"irq\", qint_from_int(dev->config[PCI_INTERRUPT_LINE]));\n\n }\n\n\n\n class = pci_get_word(dev->config + PCI_CLASS_DEVICE);\n\n if (class == 0x0604) {\n\n QDict *qdict;\n\n QObject *pci_bridge;\n\n\n\n pci_bridge = qobject_from_jsonf(\"{ 'bus': \"\n\n \"{ 'number': %d, 'secondary': %d, 'subordinate': %d }, \"\n\n \"'io_range': { 'base': %\" PRId64 \", 'limit': %\" PRId64 \"}, \"\n\n \"'memory_range': { 'base': %\" PRId64 \", 'limit': %\" PRId64 \"}, \"\n\n \"'prefetchable_range': { 'base': %\" PRId64 \", 'limit': %\" PRId64 \"} }\",\n\n dev->config[0x19], dev->config[PCI_SECONDARY_BUS],\n\n dev->config[PCI_SUBORDINATE_BUS],\n\n pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO),\n\n pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO),\n\n pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY),\n\n pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY),\n\n pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY |\n\n PCI_BASE_ADDRESS_MEM_PREFETCH),\n\n pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY |\n\n PCI_BASE_ADDRESS_MEM_PREFETCH));\n\n\n\n if (dev->config[0x19] != 0) {\n\n qdict = qobject_to_qdict(pci_bridge);\n\n qdict_put_obj(qdict, \"devices\",\n\n pci_get_devices_list(bus, dev->config[0x19]));\n\n }\n\n\n\n qdict = qobject_to_qdict(obj);\n\n qdict_put_obj(qdict, \"pci_bridge\", pci_bridge);\n\n }\n\n\n\n return obj;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "c021f8e65f5009a5ab5711d9d5326fcab553ef1c", + "length": 564 + }, + { + "index": 15151, + "code": "static bool s390_gen_initial_iplb(S390IPLState *ipl)\n{\n DeviceState *dev_st;\n dev_st = get_boot_device(0);\n if (dev_st) {\n VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *)\n object_dynamic_cast(OBJECT(qdev_get_parent_bus(dev_st)->parent),\n TYPE_VIRTIO_CCW_DEVICE);\n SCSIDevice *sd = (SCSIDevice *) object_dynamic_cast(OBJECT(dev_st),\n TYPE_SCSI_DEVICE);\n if (virtio_ccw_dev) {\n CcwDevice *ccw_dev = CCW_DEVICE(virtio_ccw_dev);\n ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);\n ipl->iplb.blk0_len =\n cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN);\n ipl->iplb.pbt = S390_IPL_TYPE_CCW;\n ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);\n ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;\n return true;\n } else if (sd) {\n SCSIBus *bus = scsi_bus_from_device(sd);\n VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus);\n VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw, vdev);\n CcwDevice *ccw_dev = CCW_DEVICE(scsi_ccw);\n ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);\n ipl->iplb.blk0_len =\n cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN);\n ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI;\n ipl->iplb.scsi.lun = cpu_to_be32(sd->lun);\n ipl->iplb.scsi.target = cpu_to_be16(sd->id);\n ipl->iplb.scsi.channel = cpu_to_be16(sd->channel);\n ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno);\n ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3;\n return true;\n return false;", + "label": 1, + "project": "qemu", + "commit_id": "f38b5b7fc4e27724afc72b91efa2bc82f84bb25e", + "length": 540 + }, + { + "index": 14158, + "code": "static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, int * posts, float * floor, int samples) {\n\n int range = 255 / fc->multiplier + 1;\n\n int coded[fc->values]; // first 2 values are unused\n\n int i, counter;\n\n int lx, ly;\n\n\n\n put_bits(pb, 1, 1); // non zero\n\n put_bits(pb, ilog(range - 1), posts[0]);\n\n put_bits(pb, ilog(range - 1), posts[1]);\n\n\n\n for (i = 2; i < fc->values; i++) {\n\n int predicted = render_point(fc->list[fc->list[i].low].x,\n\n posts[fc->list[i].low],\n\n fc->list[fc->list[i].high].x,\n\n posts[fc->list[i].high],\n\n fc->list[i].x);\n\n int highroom = range - predicted;\n\n int lowroom = predicted;\n\n int room = FFMIN(highroom, lowroom);\n\n if (predicted == posts[i]) {\n\n coded[i] = 0; // must be used later as flag!\n\n continue;\n\n } else {\n\n if (!coded[fc->list[i].low]) coded[fc->list[i].low] = -1;\n\n if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;\n\n }\n\n if (posts[i] > predicted) {\n\n if (posts[i] - predicted > room) coded[i] = posts[i] - predicted + lowroom;\n\n else coded[i] = (posts[i] - predicted) << 1;\n\n } else {\n\n if (predicted - posts[i] > room) coded[i] = predicted - posts[i] + highroom - 1;\n\n else coded[i] = ((predicted - posts[i]) << 1) - 1;\n\n }\n\n }\n\n\n\n counter = 2;\n\n for (i = 0; i < fc->partitions; i++) {\n\n floor_class_t * c = &fc->classes[fc->partition_to_class[i]];\n\n int k, cval = 0, csub = 1<subclass;\n\n if (c->subclass) {\n\n codebook_t * book = &venc->codebooks[c->masterbook];\n\n int cshift = 0;\n\n for (k = 0; k < c->dim; k++) {\n\n int l;\n\n for (l = 0; l < csub; l++) {\n\n int maxval = 1;\n\n if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries;\n\n // coded could be -1, but this still works, cause thats 0\n\n if (coded[counter + k] < maxval) break;\n\n }\n\n assert(l != csub);\n\n cval |= l << cshift;\n\n cshift += c->subclass;\n\n }\n\n assert(cval < book->nentries);\n\n put_bits(pb, book->entries[cval].len, book->entries[cval].codeword);\n\n }\n\n for (k = 0; k < c->dim; k++) {\n\n int book = c->books[cval & (csub-1)];\n\n int entry = coded[counter++];\n\n cval >>= c->subclass;\n\n if (book == -1) continue;\n\n if (entry == -1) entry = 0;\n\n assert(entry < venc->codebooks[book].nentries);\n\n assert(entry >= 0);\n\n put_bits(pb, venc->codebooks[book].entries[entry].len, venc->codebooks[book].entries[entry].codeword);\n\n }\n\n }\n\n\n\n lx = 0;\n\n ly = posts[0] * fc->multiplier; // sorted 0 is still 0\n\n coded[0] = coded[1] = 1;\n\n for (i = 1; i < fc->values; i++) {\n\n int pos = fc->list[i].sort;\n\n if (coded[pos]) {\n\n render_line(lx, ly, fc->list[pos].x, posts[pos] * fc->multiplier, floor, samples);\n\n lx = fc->list[pos].x;\n\n ly = posts[pos] * fc->multiplier;\n\n }\n\n if (lx >= samples) break;\n\n }\n\n if (lx < samples) render_line(lx, ly, samples, ly, floor, samples);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "40b6c7213356693a98c90746f5665da581e0135d", + "length": 984 + }, + { + "index": 15849, + "code": "static void v9fs_walk(void *opaque)\n\n{\n\n int name_idx;\n\n V9fsQID *qids = NULL;\n\n int i, err = 0;\n\n V9fsPath dpath, path;\n\n uint16_t nwnames;\n\n struct stat stbuf;\n\n size_t offset = 7;\n\n int32_t fid, newfid;\n\n V9fsString *wnames = NULL;\n\n V9fsFidState *fidp;\n\n V9fsFidState *newfidp = NULL;\n\n V9fsPDU *pdu = opaque;\n\n V9fsState *s = pdu->s;\n\n\n\n err = pdu_unmarshal(pdu, offset, \"ddw\", &fid, &newfid, &nwnames);\n\n if (err < 0) {\n\n pdu_complete(pdu, err);\n\n return ;\n\n\n offset += err;\n\n\n\n trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);\n\n\n\n if (nwnames && nwnames <= P9_MAXWELEM) {\n\n wnames = g_malloc0(sizeof(wnames[0]) * nwnames);\n\n qids = g_malloc0(sizeof(qids[0]) * nwnames);\n\n for (i = 0; i < nwnames; i++) {\n\n err = pdu_unmarshal(pdu, offset, \"s\", &wnames[i]);\n\n if (err < 0) {\n\n\n\n\n\n\n\n offset += err;\n\n\n } else if (nwnames > P9_MAXWELEM) {\n\n err = -EINVAL;\n\n\n\n fidp = get_fid(pdu, fid);\n\n if (fidp == NULL) {\n\n\n\n\n v9fs_path_init(&dpath);\n\n v9fs_path_init(&path);\n\n /*\n\n * Both dpath and path initially poin to fidp.\n\n * Needed to handle request with nwnames == 0\n\n */\n\n v9fs_path_copy(&dpath, &fidp->path);\n\n v9fs_path_copy(&path, &fidp->path);\n\n for (name_idx = 0; name_idx < nwnames; name_idx++) {\n\n err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data, &path);\n\n if (err < 0) {\n\n goto out;\n\n\n err = v9fs_co_lstat(pdu, &path, &stbuf);\n\n if (err < 0) {\n\n goto out;\n\n\n stat_to_qid(&stbuf, &qids[name_idx]);\n\n v9fs_path_copy(&dpath, &path);\n\n\n if (fid == newfid) {\n\n BUG_ON(fidp->fid_type != P9_FID_NONE);\n\n v9fs_path_copy(&fidp->path, &path);\n\n } else {\n\n newfidp = alloc_fid(s, newfid);\n\n if (newfidp == NULL) {\n\n err = -EINVAL;\n\n goto out;\n\n\n newfidp->uid = fidp->uid;\n\n v9fs_path_copy(&newfidp->path, &path);\n\n\n err = v9fs_walk_marshal(pdu, nwnames, qids);\n\n trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids);\n\nout:\n\n put_fid(pdu, fidp);\n\n if (newfidp) {\n\n put_fid(pdu, newfidp);\n\n\n v9fs_path_free(&dpath);\n\n v9fs_path_free(&path);\n\nout_nofid:\n\n pdu_complete(pdu, err);\n\n if (nwnames && nwnames <= P9_MAXWELEM) {\n\n for (name_idx = 0; name_idx < nwnames; name_idx++) {\n\n v9fs_string_free(&wnames[name_idx]);\n\n\n g_free(wnames);\n\n g_free(qids);\n\n", + "label": 1, + "project": "qemu", + "commit_id": "fff39a7ad09da07ef490de05c92c91f22f8002f2", + "length": 838 + }, + { + "index": 21259, + "code": "static void v9fs_walk(void *opaque)\n\n{\n\n int name_idx;\n\n V9fsQID *qids = NULL;\n\n int i, err = 0;\n\n V9fsPath dpath, path;\n\n uint16_t nwnames;\n\n struct stat stbuf;\n\n size_t offset = 7;\n\n int32_t fid, newfid;\n\n V9fsString *wnames = NULL;\n\n V9fsFidState *fidp;\n\n V9fsFidState *newfidp = NULL;\n\n V9fsPDU *pdu = opaque;\n\n V9fsState *s = pdu->s;\n\n\n\n offset += pdu_unmarshal(pdu, offset, \"ddw\", &fid,\n\n &newfid, &nwnames);\n\n\n\n trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);\n\n\n\n if (nwnames && nwnames <= P9_MAXWELEM) {\n\n wnames = g_malloc0(sizeof(wnames[0]) * nwnames);\n\n qids = g_malloc0(sizeof(qids[0]) * nwnames);\n\n for (i = 0; i < nwnames; i++) {\n\n offset += pdu_unmarshal(pdu, offset, \"s\", &wnames[i]);\n\n }\n\n } else if (nwnames > P9_MAXWELEM) {\n\n err = -EINVAL;\n\n goto out_nofid;\n\n }\n\n fidp = get_fid(pdu, fid);\n\n if (fidp == NULL) {\n\n err = -ENOENT;\n\n goto out_nofid;\n\n }\n\n v9fs_path_init(&dpath);\n\n v9fs_path_init(&path);\n\n /*\n\n * Both dpath and path initially poin to fidp.\n\n * Needed to handle request with nwnames == 0\n\n */\n\n v9fs_path_copy(&dpath, &fidp->path);\n\n v9fs_path_copy(&path, &fidp->path);\n\n for (name_idx = 0; name_idx < nwnames; name_idx++) {\n\n err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data, &path);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n err = v9fs_co_lstat(pdu, &path, &stbuf);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n stat_to_qid(&stbuf, &qids[name_idx]);\n\n v9fs_path_copy(&dpath, &path);\n\n }\n\n if (fid == newfid) {\n\n BUG_ON(fidp->fid_type != P9_FID_NONE);\n\n v9fs_path_copy(&fidp->path, &path);\n\n } else {\n\n newfidp = alloc_fid(s, newfid);\n\n if (newfidp == NULL) {\n\n err = -EINVAL;\n\n goto out;\n\n }\n\n newfidp->uid = fidp->uid;\n\n v9fs_path_copy(&newfidp->path, &path);\n\n }\n\n err = v9fs_walk_marshal(pdu, nwnames, qids);\n\n trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids);\n\nout:\n\n put_fid(pdu, fidp);\n\n if (newfidp) {\n\n put_fid(pdu, newfidp);\n\n }\n\n v9fs_path_free(&dpath);\n\n v9fs_path_free(&path);\n\nout_nofid:\n\n complete_pdu(s, pdu, err);\n\n if (nwnames && nwnames <= P9_MAXWELEM) {\n\n for (name_idx = 0; name_idx < nwnames; name_idx++) {\n\n v9fs_string_free(&wnames[name_idx]);\n\n }\n\n g_free(wnames);\n\n g_free(qids);\n\n }\n\n return;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "ddca7f86ac022289840e0200fd4050b2b58e9176", + "length": 845 + }, + { + "index": 9461, + "code": "static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val)\n\n{\n\n sh_serial_state *s = opaque;\n\n unsigned char ch;\n\n\n\n#ifdef DEBUG_SERIAL\n\n printf(\"sh_serial: write offs=0x%02x val=0x%02x\\n\",\n\n\t offs, val);\n\n#endif\n\n switch(offs) {\n\n case 0x00: /* SMR */\n\n s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);\n\n return;\n\n case 0x04: /* BRR */\n\n s->brr = val;\n\n\treturn;\n\n case 0x08: /* SCR */\n\n /* TODO : For SH7751, SCIF mask should be 0xfb. */\n\n s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);\n\n if (!(val & (1 << 5)))\n\n s->flags |= SH_SERIAL_FLAG_TEND;\n\n if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {\n\n\t qemu_set_irq(s->txi, val & (1 << 7));\n\n }\n\n if (!(val & (1 << 6))) {\n\n\t qemu_set_irq(s->rxi, 0);\n\n }\n\n return;\n\n case 0x0c: /* FTDR / TDR */\n\n if (s->chr) {\n\n ch = val;\n\n qemu_chr_write(s->chr, &ch, 1);\n\n\t}\n\n\ts->dr = val;\n\n\ts->flags &= ~SH_SERIAL_FLAG_TDE;\n\n return;\n\n#if 0\n\n case 0x14: /* FRDR / RDR */\n\n ret = 0;\n\n break;\n\n#endif\n\n }\n\n if (s->feat & SH_SERIAL_FEAT_SCIF) {\n\n switch(offs) {\n\n case 0x10: /* FSR */\n\n if (!(val & (1 << 6)))\n\n s->flags &= ~SH_SERIAL_FLAG_TEND;\n\n if (!(val & (1 << 5)))\n\n s->flags &= ~SH_SERIAL_FLAG_TDE;\n\n if (!(val & (1 << 4)))\n\n s->flags &= ~SH_SERIAL_FLAG_BRK;\n\n if (!(val & (1 << 1)))\n\n s->flags &= ~SH_SERIAL_FLAG_RDF;\n\n if (!(val & (1 << 0)))\n\n s->flags &= ~SH_SERIAL_FLAG_DR;\n\n\n\n if (!(val & (1 << 1)) || !(val & (1 << 0))) {\n\n if (s->rxi) {\n\n qemu_set_irq(s->rxi, 0);\n\n }\n\n }\n\n return;\n\n case 0x18: /* FCR */\n\n s->fcr = val;\n\n switch ((val >> 6) & 3) {\n\n case 0:\n\n s->rtrg = 1;\n\n break;\n\n case 1:\n\n s->rtrg = 4;\n\n break;\n\n case 2:\n\n s->rtrg = 8;\n\n break;\n\n case 3:\n\n s->rtrg = 14;\n\n break;\n\n }\n\n if (val & (1 << 1)) {\n\n sh_serial_clear_fifo(s);\n\n s->sr &= ~(1 << 1);\n\n }\n\n\n\n return;\n\n case 0x20: /* SPTR */\n\n s->sptr = val & 0xf3;\n\n return;\n\n case 0x24: /* LSR */\n\n return;\n\n }\n\n }\n\n else {\n\n#if 0\n\n switch(offs) {\n\n case 0x0c:\n\n ret = s->dr;\n\n break;\n\n case 0x10:\n\n ret = 0;\n\n break;\n\n case 0x1c:\n\n ret = s->sptr;\n\n break;\n\n }\n\n#endif\n\n }\n\n\n\n fprintf(stderr, \"sh_serial: unsupported write to 0x%02x\\n\", offs);\n\n assert(0);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "d1f193b0edb919ab109f88c53469ec9073f2e142", + "length": 867 + }, + { + "index": 26891, + "code": "POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data)\n\n{\n\n DeviceClass *dc = DEVICE_CLASS(oc);\n\n PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);\n\n\n\n dc->fw_name = \"PowerPC,POWER5\";\n\n dc->desc = \"POWER5+\";\n\n pcc->init_proc = init_proc_power5plus;\n\n pcc->check_pow = check_pow_970FX;\n\n pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |\n\n PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |\n\n PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |\n\n PPC_FLOAT_STFIWX |\n\n PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |\n\n PPC_MEM_SYNC | PPC_MEM_EIEIO |\n\n PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |\n\n PPC_64B |\n\n PPC_SEGMENT_64B | PPC_SLBI;\n\n pcc->msr_mask = (1ull << MSR_SF) |\n\n (1ull << MSR_VR) |\n\n (1ull << MSR_POW) |\n\n (1ull << MSR_EE) |\n\n (1ull << MSR_PR) |\n\n (1ull << MSR_FP) |\n\n (1ull << MSR_ME) |\n\n (1ull << MSR_FE0) |\n\n (1ull << MSR_SE) |\n\n (1ull << MSR_DE) |\n\n (1ull << MSR_FE1) |\n\n (1ull << MSR_IR) |\n\n (1ull << MSR_DR) |\n\n (1ull << MSR_PMM) |\n\n (1ull << MSR_RI);\n\n pcc->mmu_model = POWERPC_MMU_64B;\n\n#if defined(CONFIG_SOFTMMU)\n\n pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;\n\n#endif\n\n pcc->excp_model = POWERPC_EXCP_970;\n\n pcc->bus_model = PPC_FLAGS_INPUT_970;\n\n pcc->bfd_mach = bfd_mach_ppc64;\n\n pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |\n\n POWERPC_FLAG_BE | POWERPC_FLAG_PMM |\n\n POWERPC_FLAG_BUS_CLK;\n\n pcc->l1_dcache_size = 0x8000;\n\n pcc->l1_icache_size = 0x10000;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "90618f4f4d1e7b5b9fe40834646adac1e21d1b07", + "length": 512 + }, + { + "index": 6527, + "code": "void qmp_blockdev_change_medium(const char *device, const char *filename,\n\n bool has_format, const char *format,\n\n bool has_read_only,\n\n BlockdevChangeReadOnlyMode read_only,\n\n Error **errp)\n\n{\n\n BlockBackend *blk;\n\n BlockDriverState *medium_bs = NULL;\n\n int bdrv_flags, ret;\n\n QDict *options = NULL;\n\n Error *err = NULL;\n\n\n\n blk = blk_by_name(device);\n\n if (!blk) {\n\n error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,\n\n \"Device '%s' not found\", device);\n\n goto fail;\n\n }\n\n\n\n if (blk_bs(blk)) {\n\n blk_update_root_state(blk);\n\n }\n\n\n\n bdrv_flags = blk_get_open_flags_from_root_state(blk);\n\n bdrv_flags &= ~(BDRV_O_TEMPORARY | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING |\n\n BDRV_O_PROTOCOL);\n\n\n\n if (!has_read_only) {\n\n read_only = BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN;\n\n }\n\n\n\n switch (read_only) {\n\n case BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN:\n\n break;\n\n\n\n case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_ONLY:\n\n bdrv_flags &= ~BDRV_O_RDWR;\n\n break;\n\n\n\n case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_WRITE:\n\n bdrv_flags |= BDRV_O_RDWR;\n\n break;\n\n\n\n default:\n\n abort();\n\n }\n\n\n\n if (has_format) {\n\n options = qdict_new();\n\n qdict_put(options, \"driver\", qstring_from_str(format));\n\n }\n\n\n\n assert(!medium_bs);\n\n ret = bdrv_open(&medium_bs, filename, NULL, options, bdrv_flags, errp);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n blk_apply_root_state(blk, medium_bs);\n\n\n\n bdrv_add_key(medium_bs, NULL, &err);\n\n if (err) {\n\n error_propagate(errp, err);\n\n goto fail;\n\n }\n\n\n\n qmp_blockdev_open_tray(device, false, false, &err);\n\n if (err) {\n\n error_propagate(errp, err);\n\n goto fail;\n\n }\n\n\n\n qmp_x_blockdev_remove_medium(device, &err);\n\n if (err) {\n\n error_propagate(errp, err);\n\n goto fail;\n\n }\n\n\n\n qmp_blockdev_insert_anon_medium(device, medium_bs, &err);\n\n if (err) {\n\n error_propagate(errp, err);\n\n goto fail;\n\n }\n\n\n\n qmp_blockdev_close_tray(device, errp);\n\n\n\nfail:\n\n /* If the medium has been inserted, the device has its own reference, so\n\n * ours must be relinquished; and if it has not been inserted successfully,\n\n * the reference must be relinquished anyway */\n\n bdrv_unref(medium_bs);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a5614993d79584af93bb845f69f59872b3f76cf8", + "length": 599 + }, + { + "index": 24909, + "code": "static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n const uint8_t *s = src;\n\n const uint8_t *end;\n\n#if COMPILE_TEMPLATE_MMX\n\n const uint8_t *mm_end;\n\n#endif\n\n uint16_t *d = (uint16_t *)dst;\n\n end = s + src_size;\n\n#if COMPILE_TEMPLATE_MMX\n\n __asm__ volatile(PREFETCH\" %0\"::\"m\"(*src):\"memory\");\n\n __asm__ volatile(\n\n \"movq %0, %%mm7 \\n\\t\"\n\n \"movq %1, %%mm6 \\n\\t\"\n\n ::\"m\"(red_16mask),\"m\"(green_16mask));\n\n mm_end = end - 15;\n\n while (s < mm_end) {\n\n __asm__ volatile(\n\n PREFETCH\" 32%1 \\n\\t\"\n\n \"movd %1, %%mm0 \\n\\t\"\n\n \"movd 4%1, %%mm3 \\n\\t\"\n\n \"punpckldq 8%1, %%mm0 \\n\\t\"\n\n \"punpckldq 12%1, %%mm3 \\n\\t\"\n\n \"movq %%mm0, %%mm1 \\n\\t\"\n\n \"movq %%mm0, %%mm2 \\n\\t\"\n\n \"movq %%mm3, %%mm4 \\n\\t\"\n\n \"movq %%mm3, %%mm5 \\n\\t\"\n\n \"psllq $8, %%mm0 \\n\\t\"\n\n \"psllq $8, %%mm3 \\n\\t\"\n\n \"pand %%mm7, %%mm0 \\n\\t\"\n\n \"pand %%mm7, %%mm3 \\n\\t\"\n\n \"psrlq $5, %%mm1 \\n\\t\"\n\n \"psrlq $5, %%mm4 \\n\\t\"\n\n \"pand %%mm6, %%mm1 \\n\\t\"\n\n \"pand %%mm6, %%mm4 \\n\\t\"\n\n \"psrlq $19, %%mm2 \\n\\t\"\n\n \"psrlq $19, %%mm5 \\n\\t\"\n\n \"pand %2, %%mm2 \\n\\t\"\n\n \"pand %2, %%mm5 \\n\\t\"\n\n \"por %%mm1, %%mm0 \\n\\t\"\n\n \"por %%mm4, %%mm3 \\n\\t\"\n\n \"por %%mm2, %%mm0 \\n\\t\"\n\n \"por %%mm5, %%mm3 \\n\\t\"\n\n \"psllq $16, %%mm3 \\n\\t\"\n\n \"por %%mm3, %%mm0 \\n\\t\"\n\n MOVNTQ\" %%mm0, %0 \\n\\t\"\n\n :\"=m\"(*d):\"m\"(*s),\"m\"(blue_16mask):\"memory\");\n\n d += 4;\n\n s += 16;\n\n }\n\n __asm__ volatile(SFENCE:::\"memory\");\n\n __asm__ volatile(EMMS:::\"memory\");\n\n#endif\n\n while (s < end) {\n\n register int rgb = *(const uint32_t*)s; s += 4;\n\n *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19);\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "d1adad3cca407f493c3637e20ecd4f7124e69212", + "length": 800 + }, + { + "index": 10078, + "code": "static void usb_host_speed_compat(USBHostDevice *s)\n\n{\n\n USBDevice *udev = USB_DEVICE(s);\n\n struct libusb_config_descriptor *conf;\n\n const struct libusb_interface_descriptor *intf;\n\n const struct libusb_endpoint_descriptor *endp;\n\n#ifdef HAVE_STREAMS\n\n struct libusb_ss_endpoint_companion_descriptor *endp_ss_comp;\n\n#endif\n\n bool compat_high = true;\n\n bool compat_full = true;\n\n uint8_t type;\n\n int rc, c, i, a, e;\n\n\n\n for (c = 0;; c++) {\n\n rc = libusb_get_config_descriptor(s->dev, c, &conf);\n\n if (rc != 0) {\n\n break;\n\n }\n\n for (i = 0; i < conf->bNumInterfaces; i++) {\n\n for (a = 0; a < conf->interface[i].num_altsetting; a++) {\n\n intf = &conf->interface[i].altsetting[a];\n\n for (e = 0; e < intf->bNumEndpoints; e++) {\n\n endp = &intf->endpoint[e];\n\n type = endp->bmAttributes & 0x3;\n\n switch (type) {\n\n case 0x01: /* ISO */\n\n compat_full = false;\n\n compat_high = false;\n\n break;\n\n case 0x02: /* BULK */\n\n#ifdef HAVE_STREAMS\n\n rc = libusb_get_ss_endpoint_companion_descriptor\n\n (ctx, endp, &endp_ss_comp);\n\n if (rc == LIBUSB_SUCCESS) {\n\n libusb_free_ss_endpoint_companion_descriptor\n\n (endp_ss_comp);\n\n compat_full = false;\n\n compat_high = false;\n\n }\n\n#endif\n\n break;\n\n case 0x03: /* INTERRUPT */\n\n if (endp->wMaxPacketSize > 64) {\n\n compat_full = false;\n\n }\n\n if (endp->wMaxPacketSize > 1024) {\n\n compat_high = false;\n\n }\n\n break;\n\n }\n\n }\n\n }\n\n }\n\n libusb_free_config_descriptor(conf);\n\n }\n\n\n\n udev->speedmask = (1 << udev->speed);\n\n if (udev->speed == USB_SPEED_SUPER && compat_high) {\n\n udev->speedmask |= USB_SPEED_MASK_HIGH;\n\n }\n\n if (udev->speed == USB_SPEED_SUPER && compat_full) {\n\n udev->speedmask |= USB_SPEED_MASK_FULL;\n\n }\n\n if (udev->speed == USB_SPEED_HIGH && compat_full) {\n\n udev->speedmask |= USB_SPEED_MASK_FULL;\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "6a71123469e0c9286354c6655440da51566c1763", + "length": 550 + }, + { + "index": 18890, + "code": "POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)\n\n{\n\n DeviceClass *dc = DEVICE_CLASS(oc);\n\n PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);\n\n\n\n dc->fw_name = \"PowerPC,POWER7\";\n\n dc->desc = \"POWER7\";\n\n dc->props = powerpc_servercpu_properties;\n\n pcc->pvr_match = ppc_pvr_match_power7;\n\n pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;\n\n pcc->init_proc = init_proc_POWER7;\n\n pcc->check_pow = check_pow_nocheck;\n\n pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |\n\n PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |\n\n PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |\n\n PPC_FLOAT_FRSQRTES |\n\n PPC_FLOAT_STFIWX |\n\n PPC_FLOAT_EXT |\n\n PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |\n\n PPC_MEM_SYNC | PPC_MEM_EIEIO |\n\n PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |\n\n PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |\n\n PPC_SEGMENT_64B | PPC_SLBI |\n\n PPC_POPCNTB | PPC_POPCNTWD;\n\n pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX | PPC2_ISA205 |\n\n PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |\n\n PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |\n\n PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64;\n\n pcc->msr_mask = (1ull << MSR_SF) |\n\n (1ull << MSR_VR) |\n\n (1ull << MSR_VSX) |\n\n (1ull << MSR_EE) |\n\n (1ull << MSR_PR) |\n\n (1ull << MSR_FP) |\n\n (1ull << MSR_ME) |\n\n (1ull << MSR_FE0) |\n\n (1ull << MSR_SE) |\n\n (1ull << MSR_DE) |\n\n (1ull << MSR_FE1) |\n\n (1ull << MSR_IR) |\n\n (1ull << MSR_DR) |\n\n (1ull << MSR_PMM) |\n\n (1ull << MSR_RI) |\n\n (1ull << MSR_LE);\n\n pcc->mmu_model = POWERPC_MMU_2_06;\n\n#if defined(CONFIG_SOFTMMU)\n\n pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;\n\n pcc->sps = &POWER7_POWER8_sps;\n\n#endif\n\n pcc->excp_model = POWERPC_EXCP_POWER7;\n\n pcc->bus_model = PPC_FLAGS_INPUT_POWER7;\n\n pcc->bfd_mach = bfd_mach_ppc64;\n\n pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |\n\n POWERPC_FLAG_BE | POWERPC_FLAG_PMM |\n\n POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |\n\n POWERPC_FLAG_VSX;\n\n pcc->l1_dcache_size = 0x8000;\n\n pcc->l1_icache_size = 0x8000;\n\n pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "8cd2ce7aaa3c3fadc561f40045d4d53ff72e94ef", + "length": 742 + }, + { + "index": 14335, + "code": "static int process_input(void)\n\n{\n\n InputFile *ifile;\n\n AVFormatContext *is;\n\n InputStream *ist;\n\n AVPacket pkt;\n\n int ret, i, j;\n\n\n\n /* select the stream that we must read now */\n\n ifile = select_input_file();\n\n /* if none, if is finished */\n\n if (!ifile) {\n\n if (got_eagain()) {\n\n reset_eagain();\n\n av_usleep(10000);\n\n return AVERROR(EAGAIN);\n\n }\n\n av_log(NULL, AV_LOG_VERBOSE, \"No more inputs to read from.\\n\");\n\n return AVERROR_EOF;\n\n }\n\n\n\n is = ifile->ctx;\n\n ret = get_input_packet(ifile, &pkt);\n\n\n\n if (ret == AVERROR(EAGAIN)) {\n\n ifile->eagain = 1;\n\n return ret;\n\n }\n\n if (ret < 0) {\n\n if (ret != AVERROR_EOF) {\n\n print_error(is->filename, ret);\n\n if (exit_on_error)\n\n exit(1);\n\n }\n\n ifile->eof_reached = 1;\n\n\n\n for (i = 0; i < ifile->nb_streams; i++) {\n\n ist = input_streams[ifile->ist_index + i];\n\n if (ist->decoding_needed)\n\n output_packet(ist, NULL);\n\n\n\n /* mark all outputs that don't go through lavfi as finished */\n\n for (j = 0; j < nb_output_streams; j++) {\n\n OutputStream *ost = output_streams[j];\n\n\n\n if (ost->source_index == ifile->ist_index + i &&\n\n (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE))\n\n ost->finished= 1;\n\n }\n\n }\n\n\n\n return AVERROR(EAGAIN);\n\n }\n\n\n\n reset_eagain();\n\n\n\n if (do_pkt_dump) {\n\n av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,\n\n is->streams[pkt.stream_index]);\n\n }\n\n /* the following test is needed in case new streams appear\n\n dynamically in stream : we ignore them */\n\n if (pkt.stream_index >= ifile->nb_streams)\n\n goto discard_packet;\n\n\n\n ist = input_streams[ifile->ist_index + pkt.stream_index];\n\n if (ist->discard)\n\n goto discard_packet;\n\n\n\n if (pkt.dts != AV_NOPTS_VALUE)\n\n pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);\n\n if (pkt.pts != AV_NOPTS_VALUE)\n\n pkt.pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);\n\n\n\n if (pkt.pts != AV_NOPTS_VALUE)\n\n pkt.pts *= ist->ts_scale;\n\n if (pkt.dts != AV_NOPTS_VALUE)\n\n pkt.dts *= ist->ts_scale;\n\n\n\n if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&\n\n (is->iformat->flags & AVFMT_TS_DISCONT)) {\n\n int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);\n\n int64_t delta = pkt_dts - ist->next_dts;\n\n\n\n if ((FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + 1 < ist->last_dts) && !copy_ts) {\n\n ifile->ts_offset -= delta;\n\n av_log(NULL, AV_LOG_DEBUG,\n\n \"timestamp discontinuity %\"PRId64\", new offset= %\"PRId64\"\\n\",\n\n delta, ifile->ts_offset);\n\n pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);\n\n if (pkt.pts != AV_NOPTS_VALUE)\n\n pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);\n\n }\n\n }\n\n\n\n ret = output_packet(ist, &pkt);\n\n if (ret < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error while decoding stream #%d:%d\\n\",\n\n ist->file_index, ist->st->index);\n\n if (exit_on_error)\n\n exit(1);\n\n }\n\n\n\ndiscard_packet:\n\n av_free_packet(&pkt);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "636ced8e1dc8248a1353b416240b93d70ad03edb", + "length": 933 + }, + { + "index": 8712, + "code": "static av_cold int iss_read_header(AVFormatContext *s)\n\n{\n\n IssDemuxContext *iss = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n AVStream *st;\n\n char token[MAX_TOKEN_SIZE];\n\n int stereo, rate_divisor;\n\n\n\n get_token(pb, token, sizeof(token)); //\"IMA_ADPCM_Sound\"\n\n get_token(pb, token, sizeof(token)); //packet size\n\n sscanf(token, \"%d\", &iss->packet_size);\n\n get_token(pb, token, sizeof(token)); //File ID\n\n get_token(pb, token, sizeof(token)); //out size\n\n get_token(pb, token, sizeof(token)); //stereo\n\n sscanf(token, \"%d\", &stereo);\n\n get_token(pb, token, sizeof(token)); //Unknown1\n\n get_token(pb, token, sizeof(token)); //RateDivisor\n\n sscanf(token, \"%d\", &rate_divisor);\n\n get_token(pb, token, sizeof(token)); //Unknown2\n\n get_token(pb, token, sizeof(token)); //Version ID\n\n get_token(pb, token, sizeof(token)); //Size\n\n\n\n if (iss->packet_size <= 0) {\n\n av_log(s, AV_LOG_ERROR, \"packet_size %d is invalid\\n\", iss->packet_size);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n iss->sample_start_pos = avio_tell(pb);\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS;\n\n if (stereo) {\n\n st->codec->channels = 2;\n\n st->codec->channel_layout = AV_CH_LAYOUT_STEREO;\n\n } else {\n\n st->codec->channels = 1;\n\n st->codec->channel_layout = AV_CH_LAYOUT_MONO;\n\n }\n\n st->codec->sample_rate = 44100;\n\n if(rate_divisor > 0)\n\n st->codec->sample_rate /= rate_divisor;\n\n st->codec->bits_per_coded_sample = 4;\n\n st->codec->bit_rate = st->codec->channels * st->codec->sample_rate\n\n * st->codec->bits_per_coded_sample;\n\n st->codec->block_align = iss->packet_size;\n\n avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "5c3079aaa94ba8140fc727b5533b75b5b337b2bb", + "length": 536 + }, + { + "index": 8619, + "code": "abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,\n\n abi_ulong new_size, unsigned long flags,\n\n abi_ulong new_addr)\n\n{\n\n int prot;\n\n void *host_addr;\n\n\n\n mmap_lock();\n\n\n\n if (flags & MREMAP_FIXED) {\n\n host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),\n\n old_size, new_size,\n\n flags,\n\n g2h(new_addr));\n\n\n\n if (RESERVED_VA && host_addr != MAP_FAILED) {\n\n /* If new and old addresses overlap then the above mremap will\n\n already have failed with EINVAL. */\n\n mmap_reserve(old_addr, old_size);\n\n }\n\n } else if (flags & MREMAP_MAYMOVE) {\n\n abi_ulong mmap_start;\n\n\n\n mmap_start = mmap_find_vma(0, new_size);\n\n\n\n if (mmap_start == -1) {\n\n errno = ENOMEM;\n\n host_addr = MAP_FAILED;\n\n } else {\n\n host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),\n\n old_size, new_size,\n\n flags | MREMAP_FIXED,\n\n g2h(mmap_start));\n\n mmap_reserve(old_addr, old_size);\n\n }\n\n } else {\n\n int prot = 0;\n\n if (RESERVED_VA && old_size < new_size) {\n\n abi_ulong addr;\n\n for (addr = old_addr + old_size;\n\n addr < old_addr + new_size;\n\n addr++) {\n\n prot |= page_get_flags(addr);\n\n }\n\n }\n\n if (prot == 0) {\n\n host_addr = mremap(g2h(old_addr), old_size, new_size, flags);\n\n if (host_addr != MAP_FAILED && RESERVED_VA && old_size > new_size) {\n\n mmap_reserve(old_addr + old_size, new_size - old_size);\n\n }\n\n } else {\n\n errno = ENOMEM;\n\n host_addr = MAP_FAILED;\n\n }\n\n /* Check if address fits target address space */\n\n if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {\n\n /* Revert mremap() changes */\n\n host_addr = mremap(g2h(old_addr), new_size, old_size, flags);\n\n errno = ENOMEM;\n\n host_addr = MAP_FAILED;\n\n }\n\n }\n\n\n\n if (host_addr == MAP_FAILED) {\n\n new_addr = -1;\n\n } else {\n\n new_addr = h2g(host_addr);\n\n prot = page_get_flags(old_addr);\n\n page_set_flags(old_addr, old_addr + old_size, 0);\n\n page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);\n\n }\n\n mmap_unlock();\n\n return new_addr;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "c65ffe6d6ca8b156e729e81054ca7597864354a9", + "length": 581 + }, + { + "index": 6398, + "code": "static av_cold int MP3lame_encode_init(AVCodecContext *avctx)\n\n{\n\n Mp3AudioContext *s = avctx->priv_data;\n\n\n\n if (avctx->channels > 2)\n\n return -1;\n\n\n\n s->stereo = avctx->channels > 1 ? 1 : 0;\n\n\n\n if ((s->gfp = lame_init()) == NULL)\n\n goto err;\n\n lame_set_in_samplerate(s->gfp, avctx->sample_rate);\n\n lame_set_out_samplerate(s->gfp, avctx->sample_rate);\n\n lame_set_num_channels(s->gfp, avctx->channels);\n\n if(avctx->compression_level == FF_COMPRESSION_DEFAULT) {\n\n lame_set_quality(s->gfp, 5);\n\n } else {\n\n lame_set_quality(s->gfp, avctx->compression_level);\n\n }\n\n lame_set_mode(s->gfp, s->stereo ? JOINT_STEREO : MONO);\n\n lame_set_brate(s->gfp, avctx->bit_rate/1000);\n\n if(avctx->flags & CODEC_FLAG_QSCALE) {\n\n lame_set_brate(s->gfp, 0);\n\n lame_set_VBR(s->gfp, vbr_default);\n\n lame_set_VBR_quality(s->gfp, avctx->global_quality/(float)FF_QP2LAMBDA);\n\n }\n\n lame_set_bWriteVbrTag(s->gfp,0);\n\n#if FF_API_LAME_GLOBAL_OPTS\n\n s->reservoir = avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR;\n\n#endif\n\n lame_set_disable_reservoir(s->gfp, !s->reservoir);\n\n if (lame_init_params(s->gfp) < 0)\n\n goto err_close;\n\n\n\n avctx->frame_size = lame_get_framesize(s->gfp);\n\n\n\n if(!(avctx->coded_frame= avcodec_alloc_frame())) {\n\n lame_close(s->gfp);\n\n\n\n return AVERROR(ENOMEM);\n\n }\n\n avctx->coded_frame->key_frame= 1;\n\n\n\n if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) {\n\n int nelem = 2 * avctx->frame_size;\n\n\n\n if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) {\n\n av_freep(&avctx->coded_frame);\n\n lame_close(s->gfp);\n\n\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n s->s32_data.right = s->s32_data.left + avctx->frame_size;\n\n }\n\n\n\n return 0;\n\n\n\nerr_close:\n\n lame_close(s->gfp);\n\nerr:\n\n return -1;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5b1a06b1c9c596b3c406ea632a252dcccbee25ed", + "length": 573 + }, + { + "index": 14028, + "code": "static av_always_inline int encode_line(FFV1Context *s, int w,\n\n int16_t *sample[3],\n\n int plane_index, int bits)\n\n{\n\n PlaneContext *const p = &s->plane[plane_index];\n\n RangeCoder *const c = &s->c;\n\n int x;\n\n int run_index = s->run_index;\n\n int run_count = 0;\n\n int run_mode = 0;\n\n\n\n if (s->ac) {\n\n if (c->bytestream_end - c->bytestream < w * 20) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"encoded frame too large\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n } else {\n\n if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"encoded frame too large\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n for (x = 0; x < w; x++) {\n\n int diff, context;\n\n\n\n context = get_context(p, sample[0] + x, sample[1] + x, sample[2] + x);\n\n diff = sample[0][x] - predict(sample[0] + x, sample[1] + x);\n\n\n\n if (context < 0) {\n\n context = -context;\n\n diff = -diff;\n\n }\n\n\n\n diff = fold(diff, bits);\n\n\n\n if (s->ac) {\n\n if (s->flags & CODEC_FLAG_PASS1) {\n\n put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,\n\n s->rc_stat2[p->quant_table_index][context]);\n\n } else {\n\n put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);\n\n }\n\n } else {\n\n if (context == 0)\n\n run_mode = 1;\n\n\n\n if (run_mode) {\n\n if (diff) {\n\n while (run_count >= 1 << ff_log2_run[run_index]) {\n\n run_count -= 1 << ff_log2_run[run_index];\n\n run_index++;\n\n put_bits(&s->pb, 1, 1);\n\n }\n\n\n\n put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);\n\n if (run_index)\n\n run_index--;\n\n run_count = 0;\n\n run_mode = 0;\n\n if (diff > 0)\n\n diff--;\n\n } else {\n\n run_count++;\n\n }\n\n }\n\n\n\n av_dlog(s->avctx, \"count:%d index:%d, mode:%d, x:%d pos:%d\\n\",\n\n run_count, run_index, run_mode, x,\n\n (int)put_bits_count(&s->pb));\n\n\n\n if (run_mode == 0)\n\n put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);\n\n }\n\n }\n\n if (run_mode) {\n\n while (run_count >= 1 << ff_log2_run[run_index]) {\n\n run_count -= 1 << ff_log2_run[run_index];\n\n run_index++;\n\n put_bits(&s->pb, 1, 1);\n\n }\n\n\n\n if (run_count)\n\n put_bits(&s->pb, 1, 1);\n\n }\n\n s->run_index = run_index;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "3728603f1854b5c79d1a64dd3b41b80640ef1e7f", + "length": 756 + }, + { + "index": 5025, + "code": "CharDriverState *qemu_chr_open(const char *filename)\n\n{\n\n const char *p;\n\n\n\n if (!strcmp(filename, \"vc\")) {\n\n return text_console_init(&display_state);\n\n } else if (!strcmp(filename, \"null\")) {\n\n return qemu_chr_open_null();\n\n } else \n\n if (strstart(filename, \"tcp:\", &p)) {\n\n return qemu_chr_open_tcp(p, 0, 0);\n\n } else\n\n if (strstart(filename, \"telnet:\", &p)) {\n\n return qemu_chr_open_tcp(p, 1, 0);\n\n } else\n\n if (strstart(filename, \"udp:\", &p)) {\n\n return qemu_chr_open_udp(p);\n\n } else\n\n if (strstart(filename, \"mon:\", &p)) {\n\n CharDriverState *drv = qemu_chr_open(p);\n\n if (drv) {\n\n drv = qemu_chr_open_mux(drv);\n\n monitor_init(drv, !nographic);\n\n return drv;\n\n }\n\n printf(\"Unable to open driver: %s\\n\", p);\n\n return 0;\n\n } else\n\n#ifndef _WIN32\n\n if (strstart(filename, \"unix:\", &p)) {\n\n\treturn qemu_chr_open_tcp(p, 0, 1);\n\n } else if (strstart(filename, \"file:\", &p)) {\n\n return qemu_chr_open_file_out(p);\n\n } else if (strstart(filename, \"pipe:\", &p)) {\n\n return qemu_chr_open_pipe(p);\n\n } else if (!strcmp(filename, \"pty\")) {\n\n return qemu_chr_open_pty();\n\n } else if (!strcmp(filename, \"stdio\")) {\n\n return qemu_chr_open_stdio();\n\n } else \n\n#if defined(__linux__)\n\n if (strstart(filename, \"/dev/parport\", NULL)) {\n\n return qemu_chr_open_pp(filename);\n\n } else \n\n#endif\n\n if (strstart(filename, \"/dev/\", NULL)) {\n\n return qemu_chr_open_tty(filename);\n\n } else \n\n#else /* !_WIN32 */\n\n if (strstart(filename, \"COM\", NULL)) {\n\n return qemu_chr_open_win(filename);\n\n } else\n\n if (strstart(filename, \"pipe:\", &p)) {\n\n return qemu_chr_open_win_pipe(p);\n\n } else\n\n if (strstart(filename, \"con:\", NULL)) {\n\n return qemu_chr_open_win_con(filename);\n\n } else\n\n if (strstart(filename, \"file:\", &p)) {\n\n return qemu_chr_open_win_file_out(p);\n\n }\n\n#endif\n\n {\n\n return NULL;\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "3fda388a1c19bef4aa8615d91693260e74564bd8", + "length": 541 + }, + { + "index": 13896, + "code": "int net_init_slirp(QemuOpts *opts, const char *name, VLANState *vlan)\n\n{\n\n struct slirp_config_str *config;\n\n const char *vhost;\n\n const char *vhostname;\n\n const char *vdhcp_start;\n\n const char *vnamesrv;\n\n const char *tftp_export;\n\n const char *bootfile;\n\n const char *smb_export;\n\n const char *vsmbsrv;\n\n const char *restrict_opt;\n\n char *vnet = NULL;\n\n int restricted = 0;\n\n int ret;\n\n\n\n vhost = qemu_opt_get(opts, \"host\");\n\n vhostname = qemu_opt_get(opts, \"hostname\");\n\n vdhcp_start = qemu_opt_get(opts, \"dhcpstart\");\n\n vnamesrv = qemu_opt_get(opts, \"dns\");\n\n tftp_export = qemu_opt_get(opts, \"tftp\");\n\n bootfile = qemu_opt_get(opts, \"bootfile\");\n\n smb_export = qemu_opt_get(opts, \"smb\");\n\n vsmbsrv = qemu_opt_get(opts, \"smbserver\");\n\n\n\n restrict_opt = qemu_opt_get(opts, \"restrict\");\n\n if (restrict_opt) {\n\n if (!strcmp(restrict_opt, \"on\") ||\n\n !strcmp(restrict_opt, \"yes\") || !strcmp(restrict_opt, \"y\")) {\n\n restricted = 1;\n\n } else if (strcmp(restrict_opt, \"off\") &&\n\n strcmp(restrict_opt, \"no\") && strcmp(restrict_opt, \"n\")) {\n\n error_report(\"invalid option: 'restrict=%s'\", restrict_opt);\n\n return -1;\n\n }\n\n }\n\n\n\n if (qemu_opt_get(opts, \"ip\")) {\n\n const char *ip = qemu_opt_get(opts, \"ip\");\n\n int l = strlen(ip) + strlen(\"/24\") + 1;\n\n\n\n vnet = g_malloc(l);\n\n\n\n /* emulate legacy ip= parameter */\n\n pstrcpy(vnet, l, ip);\n\n pstrcat(vnet, l, \"/24\");\n\n }\n\n\n\n if (qemu_opt_get(opts, \"net\")) {\n\n if (vnet) {\n\n g_free(vnet);\n\n }\n\n vnet = g_strdup(qemu_opt_get(opts, \"net\"));\n\n }\n\n\n\n qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0);\n\n\n\n ret = net_slirp_init(vlan, \"user\", name, restricted, vnet, vhost,\n\n vhostname, tftp_export, bootfile, vdhcp_start,\n\n vnamesrv, smb_export, vsmbsrv);\n\n\n\n while (slirp_configs) {\n\n config = slirp_configs;\n\n slirp_configs = config->next;\n\n g_free(config);\n\n }\n\n\n\n g_free(vnet);\n\n\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "6687b79d636cd60ed9adb1177d0d946b58fa7717", + "length": 597 + }, + { + "index": 13642, + "code": "static int bfi_read_header(AVFormatContext * s)\n\n{\n\n BFIContext *bfi = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n AVStream *vstream;\n\n AVStream *astream;\n\n int fps, chunk_header;\n\n\n\n /* Initialize the video codec... */\n\n vstream = avformat_new_stream(s, NULL);\n\n if (!vstream)\n\n return AVERROR(ENOMEM);\n\n\n\n /* Initialize the audio codec... */\n\n astream = avformat_new_stream(s, NULL);\n\n if (!astream)\n\n return AVERROR(ENOMEM);\n\n\n\n /* Set the total number of frames. */\n\n avio_skip(pb, 8);\n\n chunk_header = avio_rl32(pb);\n\n bfi->nframes = avio_rl32(pb);\n\n avio_rl32(pb);\n\n avio_rl32(pb);\n\n avio_rl32(pb);\n\n fps = avio_rl32(pb);\n\n avio_skip(pb, 12);\n\n vstream->codecpar->width = avio_rl32(pb);\n\n vstream->codecpar->height = avio_rl32(pb);\n\n\n\n /*Load the palette to extradata */\n\n avio_skip(pb, 8);\n\n vstream->codecpar->extradata = av_malloc(768);\n\n if (!vstream->codecpar->extradata)\n\n return AVERROR(ENOMEM);\n\n vstream->codecpar->extradata_size = 768;\n\n avio_read(pb, vstream->codecpar->extradata,\n\n vstream->codecpar->extradata_size);\n\n\n\n astream->codecpar->sample_rate = avio_rl32(pb);\n\n if (astream->codecpar->sample_rate <= 0) {\n\n av_log(s, AV_LOG_ERROR, \"Invalid sample rate %d\\n\", astream->codecpar->sample_rate);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n /* Set up the video codec... */\n\n avpriv_set_pts_info(vstream, 32, 1, fps);\n\n vstream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;\n\n vstream->codecpar->codec_id = AV_CODEC_ID_BFI;\n\n vstream->codecpar->format = AV_PIX_FMT_PAL8;\n\n vstream->nb_frames =\n\n vstream->duration = bfi->nframes;\n\n\n\n /* Set up the audio codec now... */\n\n astream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;\n\n astream->codecpar->codec_id = AV_CODEC_ID_PCM_U8;\n\n astream->codecpar->channels = 1;\n\n astream->codecpar->channel_layout = AV_CH_LAYOUT_MONO;\n\n astream->codecpar->bits_per_coded_sample = 8;\n\n astream->codecpar->bit_rate =\n\n astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample;\n\n avio_seek(pb, chunk_header - 3, SEEK_SET);\n\n avpriv_set_pts_info(astream, 64, 1, astream->codecpar->sample_rate);\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ad5807f8aa883bee5431186dc1f24c5435d722d3", + "length": 667 + }, + { + "index": 4255, + "code": "static int parse_adaptation_sets(AVFormatContext *s)\n\n{\n\n WebMDashMuxContext *w = s->priv_data;\n\n char *p = w->adaptation_sets;\n\n char *q;\n\n enum { new_set, parsed_id, parsing_streams } state;\n\n if (!w->adaptation_sets) {\n\n av_log(s, AV_LOG_ERROR, \"The 'adaptation_sets' option must be set.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n // syntax id=0,streams=0,1,2 id=1,streams=3,4 and so on\n\n state = new_set;\n\n while (p < w->adaptation_sets + strlen(w->adaptation_sets)) {\n\n if (*p == ' ')\n\n continue;\n\n else if (state == new_set && !strncmp(p, \"id=\", 3)) {\n\n void *mem = av_realloc(w->as, sizeof(*w->as) * (w->nb_as + 1));\n\n if (mem == NULL)\n\n return AVERROR(ENOMEM);\n\n w->as = mem;\n\n ++w->nb_as;\n\n w->as[w->nb_as - 1].nb_streams = 0;\n\n w->as[w->nb_as - 1].streams = NULL;\n\n p += 3; // consume \"id=\"\n\n q = w->as[w->nb_as - 1].id;\n\n while (*p != ',') *q++ = *p++;\n\n *q = 0;\n\n p++;\n\n state = parsed_id;\n\n } else if (state == parsed_id && !strncmp(p, \"streams=\", 8)) {\n\n p += 8; // consume \"streams=\"\n\n state = parsing_streams;\n\n } else if (state == parsing_streams) {\n\n struct AdaptationSet *as = &w->as[w->nb_as - 1];\n\n q = p;\n\n while (*q != '\\0' && *q != ',' && *q != ' ') q++;\n\n as->streams = av_realloc(as->streams, sizeof(*as->streams) * ++as->nb_streams);\n\n if (as->streams == NULL)\n\n return AVERROR(ENOMEM);\n\n as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1);\n\n if (as->streams[as->nb_streams - 1] < 0) return -1;\n\n if (*q == '\\0') break;\n\n if (*q == ' ') state = new_set;\n\n p = ++q;\n\n } else {\n\n return -1;\n\n }\n\n }\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ec07efa70012845e8642df67a4a773f510a17088", + "length": 565 + }, + { + "index": 24063, + "code": "static void lz_unpack(const unsigned char *src, int src_len,\n\n unsigned char *dest, int dest_len)\n\n{\n\n const unsigned char *s;\n\n const unsigned char *s_end;\n\n unsigned char *d;\n\n unsigned char *d_end;\n\n unsigned char queue[QUEUE_SIZE];\n\n unsigned int qpos;\n\n unsigned int dataleft;\n\n unsigned int chainofs;\n\n unsigned int chainlen;\n\n unsigned int speclen;\n\n unsigned char tag;\n\n unsigned int i, j;\n\n\n\n s = src;\n\n s_end = src + src_len;\n\n d = dest;\n\n d_end = d + dest_len;\n\n\n\n if (s_end - s < 8)\n\n return;\n\n dataleft = AV_RL32(s);\n\n s += 4;\n\n memset(queue, 0x20, QUEUE_SIZE);\n\n if (AV_RL32(s) == 0x56781234) {\n\n s += 4;\n\n qpos = 0x111;\n\n speclen = 0xF + 3;\n\n } else {\n\n qpos = 0xFEE;\n\n speclen = 100; /* no speclen */\n\n }\n\n\n\n while (s_end - s > 0 && dataleft > 0) {\n\n tag = *s++;\n\n if ((tag == 0xFF) && (dataleft > 8)) {\n\n if (d + 8 > d_end || s_end - s < 8)\n\n return;\n\n for (i = 0; i < 8; i++) {\n\n queue[qpos++] = *d++ = *s++;\n\n qpos &= QUEUE_MASK;\n\n }\n\n dataleft -= 8;\n\n } else {\n\n for (i = 0; i < 8; i++) {\n\n if (dataleft == 0)\n\n break;\n\n if (tag & 0x01) {\n\n if (d + 1 > d_end || s_end - s < 1)\n\n return;\n\n queue[qpos++] = *d++ = *s++;\n\n qpos &= QUEUE_MASK;\n\n dataleft--;\n\n } else {\n\n if (s_end - s < 2)\n\n return;\n\n chainofs = *s++;\n\n chainofs |= ((*s & 0xF0) << 4);\n\n chainlen = (*s++ & 0x0F) + 3;\n\n if (chainlen == speclen) {\n\n if (s_end - s < 1)\n\n return;\n\n chainlen = *s++ + 0xF + 3;\n\n }\n\n if (d + chainlen > d_end)\n\n return;\n\n for (j = 0; j < chainlen; j++) {\n\n *d = queue[chainofs++ & QUEUE_MASK];\n\n queue[qpos++] = *d++;\n\n qpos &= QUEUE_MASK;\n\n }\n\n dataleft -= chainlen;\n\n }\n\n tag >>= 1;\n\n }\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "78cb39d2b2ad731dd3b984b0c0711b9f1d6de004", + "length": 632 + }, + { + "index": 14023, + "code": "static void ne2000_receive(void *opaque, const uint8_t *buf, int size)\n\n{\n\n NE2000State *s = opaque;\n\n uint8_t *p;\n\n int total_len, next, avail, len, index, mcast_idx;\n\n uint8_t buf1[60];\n\n static const uint8_t broadcast_macaddr[6] = \n\n { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\n\n \n\n#if defined(DEBUG_NE2000)\n\n printf(\"NE2000: received len=%d\\n\", size);\n\n#endif\n\n\n\n if (!ne2000_can_receive(s))\n\n return;\n\n \n\n /* XXX: check this */\n\n if (s->rxcr & 0x10) {\n\n /* promiscuous: receive all */\n\n } else {\n\n if (!memcmp(buf, broadcast_macaddr, 6)) {\n\n /* broadcast address */\n\n if (!(s->rxcr & 0x04))\n\n return;\n\n } else if (buf[0] & 0x01) {\n\n /* multicast */\n\n if (!(s->rxcr & 0x08))\n\n return;\n\n mcast_idx = compute_mcast_idx(buf);\n\n if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))\n\n return;\n\n } else if (s->mem[0] == buf[0] &&\n\n s->mem[2] == buf[1] && \n\n s->mem[4] == buf[2] && \n\n s->mem[6] == buf[3] && \n\n s->mem[8] == buf[4] && \n\n s->mem[10] == buf[5]) {\n\n /* match */\n\n } else {\n\n return;\n\n }\n\n }\n\n\n\n\n\n /* if too small buffer, then expand it */\n\n if (size < MIN_BUF_SIZE) {\n\n memcpy(buf1, buf, size);\n\n memset(buf1 + size, 0, MIN_BUF_SIZE - size);\n\n buf = buf1;\n\n size = MIN_BUF_SIZE;\n\n }\n\n\n\n index = s->curpag << 8;\n\n /* 4 bytes for header */\n\n total_len = size + 4;\n\n /* address for next packet (4 bytes for CRC) */\n\n next = index + ((total_len + 4 + 255) & ~0xff);\n\n if (next >= s->stop)\n\n next -= (s->stop - s->start);\n\n /* prepare packet header */\n\n p = s->mem + index;\n\n s->rsr = ENRSR_RXOK; /* receive status */\n\n /* XXX: check this */\n\n if (buf[0] & 0x01)\n\n s->rsr |= ENRSR_PHY;\n\n p[0] = s->rsr;\n\n p[1] = next >> 8;\n\n p[2] = total_len;\n\n p[3] = total_len >> 8;\n\n index += 4;\n\n\n\n /* write packet data */\n\n while (size > 0) {\n\n avail = s->stop - index;\n\n len = size;\n\n if (len > avail)\n\n len = avail;\n\n memcpy(s->mem + index, buf, len);\n\n buf += len;\n\n index += len;\n\n if (index == s->stop)\n\n index = s->start;\n\n size -= len;\n\n }\n\n s->curpag = next >> 8;\n\n\n\n /* now we can signal we have receive something */\n\n s->isr |= ENISR_RX;\n\n ne2000_update_irq(s);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "d861b05ea30e6ac177de9b679da96194ebe21afc", + "length": 773 + }, + { + "index": 5466, + "code": "static void nvdimm_build_ssdt(GSList *device_list, GArray *table_offsets,\n\n GArray *table_data, BIOSLinker *linker,\n\n GArray *dsm_dma_arrea)\n\n{\n\n Aml *ssdt, *sb_scope, *dev;\n\n int mem_addr_offset, nvdimm_ssdt;\n\n\n\n acpi_add_table(table_offsets, table_data);\n\n\n\n ssdt = init_aml_allocator();\n\n acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));\n\n\n\n sb_scope = aml_scope(\"\\\\_SB\");\n\n\n\n dev = aml_device(\"NVDR\");\n\n\n\n /*\n\n * ACPI 6.0: 9.20 NVDIMM Devices:\n\n *\n\n * The ACPI Name Space device uses _HID of ACPI0012 to identify the root\n\n * NVDIMM interface device. Platform firmware is required to contain one\n\n * such device in _SB scope if NVDIMMs support is exposed by platform to\n\n * OSPM.\n\n * For each NVDIMM present or intended to be supported by platform,\n\n * platform firmware also exposes an ACPI Namespace Device under the\n\n * root device.\n\n */\n\n aml_append(dev, aml_name_decl(\"_HID\", aml_string(\"ACPI0012\")));\n\n\n\n nvdimm_build_common_dsm(dev);\n\n\n\n /* 0 is reserved for root device. */\n\n nvdimm_build_device_dsm(dev, 0);\n\n\n\n nvdimm_build_nvdimm_devices(device_list, dev);\n\n\n\n aml_append(sb_scope, dev);\n\n aml_append(ssdt, sb_scope);\n\n\n\n nvdimm_ssdt = table_data->len;\n\n\n\n /* copy AML table into ACPI tables blob and patch header there */\n\n g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);\n\n mem_addr_offset = build_append_named_dword(table_data,\n\n NVDIMM_ACPI_MEM_ADDR);\n\n\n\n bios_linker_loader_alloc(linker,\n\n NVDIMM_DSM_MEM_FILE, dsm_dma_arrea,\n\n sizeof(NvdimmDsmIn), false /* high memory */);\n\n bios_linker_loader_add_pointer(linker,\n\n ACPI_BUILD_TABLE_FILE, mem_addr_offset, sizeof(uint32_t),\n\n NVDIMM_DSM_MEM_FILE, 0);\n\n build_header(linker, table_data,\n\n (void *)(table_data->data + nvdimm_ssdt),\n\n \"SSDT\", table_data->len - nvdimm_ssdt, 1, NULL, \"NVDIMM\");\n\n free_aml_allocator();\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "bdfd065b1f75cacca21af0b8d4811c64cc48d04c", + "length": 555 + }, + { + "index": 18416, + "code": "static int get_packet(URLContext *s, int for_header)\n\n{\n\n RTMPContext *rt = s->priv_data;\n\n int ret;\n\n uint8_t *p;\n\n const uint8_t *next;\n\n uint32_t data_size;\n\n uint32_t ts, cts, pts=0;\n\n\n\n if (rt->state == STATE_STOPPED)\n\n return AVERROR_EOF;\n\n\n\n for (;;) {\n\n RTMPPacket rpkt = { 0 };\n\n if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,\n\n rt->chunk_size, rt->prev_pkt[0])) <= 0) {\n\n if (ret == 0) {\n\n return AVERROR(EAGAIN);\n\n } else {\n\n return AVERROR(EIO);\n\n }\n\n }\n\n rt->bytes_read += ret;\n\n if (rt->bytes_read > rt->last_bytes_read + rt->client_report_size) {\n\n av_log(s, AV_LOG_DEBUG, \"Sending bytes read report\\n\");\n\n gen_bytes_read(s, rt, rpkt.timestamp + 1);\n\n rt->last_bytes_read = rt->bytes_read;\n\n }\n\n\n\n ret = rtmp_parse_result(s, rt, &rpkt);\n\n if (ret < 0) {//serious error in current packet\n\n ff_rtmp_packet_destroy(&rpkt);\n\n return -1;\n\n }\n\n if (rt->state == STATE_STOPPED) {\n\n ff_rtmp_packet_destroy(&rpkt);\n\n return AVERROR_EOF;\n\n }\n\n if (for_header && (rt->state == STATE_PLAYING || rt->state == STATE_PUBLISHING)) {\n\n ff_rtmp_packet_destroy(&rpkt);\n\n return 0;\n\n }\n\n if (!rpkt.data_size || !rt->is_input) {\n\n ff_rtmp_packet_destroy(&rpkt);\n\n continue;\n\n }\n\n if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO ||\n\n (rpkt.type == RTMP_PT_NOTIFY && !memcmp(\"\\002\\000\\012onMetaData\", rpkt.data, 13))) {\n\n ts = rpkt.timestamp;\n\n\n\n // generate packet header and put data into buffer for FLV demuxer\n\n rt->flv_off = 0;\n\n rt->flv_size = rpkt.data_size + 15;\n\n rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);\n\n bytestream_put_byte(&p, rpkt.type);\n\n bytestream_put_be24(&p, rpkt.data_size);\n\n bytestream_put_be24(&p, ts);\n\n bytestream_put_byte(&p, ts >> 24);\n\n bytestream_put_be24(&p, 0);\n\n bytestream_put_buffer(&p, rpkt.data, rpkt.data_size);\n\n bytestream_put_be32(&p, 0);\n\n ff_rtmp_packet_destroy(&rpkt);\n\n return 0;\n\n } else if (rpkt.type == RTMP_PT_METADATA) {\n\n // we got raw FLV data, make it available for FLV demuxer\n\n rt->flv_off = 0;\n\n rt->flv_size = rpkt.data_size;\n\n rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);\n\n /* rewrite timestamps */\n\n next = rpkt.data;\n\n ts = rpkt.timestamp;\n\n while (next - rpkt.data < rpkt.data_size - 11) {\n\n next++;\n\n data_size = bytestream_get_be24(&next);\n\n p=next;\n\n cts = bytestream_get_be24(&next);\n\n cts |= bytestream_get_byte(&next) << 24;\n\n if (pts==0)\n\n pts=cts;\n\n ts += cts - pts;\n\n pts = cts;\n\n bytestream_put_be24(&p, ts);\n\n bytestream_put_byte(&p, ts >> 24);\n\n next += data_size + 3 + 4;\n\n }\n\n memcpy(rt->flv_data, rpkt.data, rpkt.data_size);\n\n ff_rtmp_packet_destroy(&rpkt);\n\n return 0;\n\n }\n\n ff_rtmp_packet_destroy(&rpkt);\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "add41decd94b2d3581a3715ba10f27168b8cdb1b", + "length": 912 + }, + { + "index": 15387, + "code": "static void pci_update_mappings(PCIDevice *d)\n\n{\n\n PCIIORegion *r;\n\n int cmd, i;\n\n uint32_t last_addr, new_addr, config_ofs;\n\n\n\n cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND));\n\n for(i = 0; i < PCI_NUM_REGIONS; i++) {\n\n r = &d->io_regions[i];\n\n if (i == PCI_ROM_SLOT) {\n\n config_ofs = 0x30;\n\n } else {\n\n config_ofs = 0x10 + i * 4;\n\n }\n\n if (r->size != 0) {\n\n if (r->type & PCI_ADDRESS_SPACE_IO) {\n\n if (cmd & PCI_COMMAND_IO) {\n\n new_addr = le32_to_cpu(*(uint32_t *)(d->config +\n\n config_ofs));\n\n new_addr = new_addr & ~(r->size - 1);\n\n last_addr = new_addr + r->size - 1;\n\n /* NOTE: we have only 64K ioports on PC */\n\n if (last_addr <= new_addr || new_addr == 0 ||\n\n last_addr >= 0x10000) {\n\n new_addr = -1;\n\n }\n\n } else {\n\n new_addr = -1;\n\n }\n\n } else {\n\n if (cmd & PCI_COMMAND_MEMORY) {\n\n new_addr = le32_to_cpu(*(uint32_t *)(d->config +\n\n config_ofs));\n\n /* the ROM slot has a specific enable bit */\n\n if (i == PCI_ROM_SLOT && !(new_addr & 1))\n\n goto no_mem_map;\n\n new_addr = new_addr & ~(r->size - 1);\n\n last_addr = new_addr + r->size - 1;\n\n /* NOTE: we do not support wrapping */\n\n /* XXX: as we cannot support really dynamic\n\n mappings, we handle specific values as invalid\n\n mappings. */\n\n if (last_addr <= new_addr || new_addr == 0 ||\n\n last_addr == -1) {\n\n new_addr = -1;\n\n }\n\n } else {\n\n no_mem_map:\n\n new_addr = -1;\n\n }\n\n }\n\n /* now do the real mapping */\n\n if (new_addr != r->addr) {\n\n if (r->addr != -1) {\n\n if (r->type & PCI_ADDRESS_SPACE_IO) {\n\n int class;\n\n /* NOTE: specific hack for IDE in PC case:\n\n only one byte must be mapped. */\n\n class = d->config[0x0a] | (d->config[0x0b] << 8);\n\n if (class == 0x0101 && r->size == 4) {\n\n isa_unassign_ioport(r->addr + 2, 1);\n\n } else {\n\n isa_unassign_ioport(r->addr, r->size);\n\n }\n\n } else {\n\n cpu_register_physical_memory(pci_to_cpu_addr(r->addr),\n\n r->size,\n\n IO_MEM_UNASSIGNED);\n\n\n }\n\n }\n\n r->addr = new_addr;\n\n if (r->addr != -1) {\n\n r->map_func(d, i, r->addr, r->size, r->type);\n\n }\n\n }\n\n }\n\n }\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "f65ed4c1529f29a7d62d6733eaa50bed24a4b2ed", + "length": 695 + }, + { + "index": 12556, + "code": "int ff_nvdec_decode_init(AVCodecContext *avctx, unsigned int dpb_size)\n\n{\n\n NVDECContext *ctx = avctx->internal->hwaccel_priv_data;\n\n\n\n NVDECFramePool *pool;\n\n AVHWFramesContext *frames_ctx;\n\n const AVPixFmtDescriptor *sw_desc;\n\n\n\n CUVIDDECODECREATEINFO params = { 0 };\n\n\n\n int cuvid_codec_type, cuvid_chroma_format;\n\n int ret = 0;\n\n\n\n sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);\n\n if (!sw_desc)\n\n return AVERROR_BUG;\n\n\n\n cuvid_codec_type = map_avcodec_id(avctx->codec_id);\n\n if (cuvid_codec_type < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Unsupported codec ID\\n\");\n\n return AVERROR_BUG;\n\n }\n\n\n\n cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);\n\n if (cuvid_chroma_format < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Unsupported chroma format\\n\");\n\n return AVERROR(ENOSYS);\n\n }\n\n\n\n if (avctx->thread_type & FF_THREAD_FRAME)\n\n dpb_size += avctx->thread_count;\n\n\n\n if (!avctx->hw_frames_ctx) {\n\n AVHWFramesContext *frames_ctx;\n\n\n\n if (!avctx->hw_device_ctx) {\n\n av_log(avctx, AV_LOG_ERROR, \"A hardware device or frames context \"\n\n \"is required for CUVID decoding.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);\n\n if (!avctx->hw_frames_ctx)\n\n return AVERROR(ENOMEM);\n\n frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;\n\n\n\n frames_ctx->format = AV_PIX_FMT_CUDA;\n\n frames_ctx->width = avctx->coded_width;\n\n frames_ctx->height = avctx->coded_height;\n\n frames_ctx->sw_format = AV_PIX_FMT_NV12;\n\n frames_ctx->sw_format = sw_desc->comp[0].depth > 8 ?\n\n AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;\n\n frames_ctx->initial_pool_size = dpb_size;\n\n\n\n ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);\n\n if (ret < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error initializing internal frames context\\n\");\n\n return ret;\n\n }\n\n }\n\n frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;\n\n\n\n params.ulWidth = avctx->coded_width;\n\n params.ulHeight = avctx->coded_height;\n\n params.ulTargetWidth = avctx->coded_width;\n\n params.ulTargetHeight = avctx->coded_height;\n\n params.bitDepthMinus8 = sw_desc->comp[0].depth - 8;\n\n params.OutputFormat = params.bitDepthMinus8 ?\n\n cudaVideoSurfaceFormat_P016 : cudaVideoSurfaceFormat_NV12;\n\n params.CodecType = cuvid_codec_type;\n\n params.ChromaFormat = cuvid_chroma_format;\n\n params.ulNumDecodeSurfaces = dpb_size;\n\n params.ulNumOutputSurfaces = 1;\n\n\n\n ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, ¶ms, avctx);\n\n if (ret < 0)\n\n return ret;\n\n\n\n pool = av_mallocz(sizeof(*pool));\n\n if (!pool) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n pool->dpb_size = dpb_size;\n\n\n\n ctx->decoder_pool = av_buffer_pool_init2(sizeof(int), pool,\n\n nvdec_decoder_frame_alloc, av_free);\n\n if (!ctx->decoder_pool) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n return 0;\n\nfail:\n\n ff_nvdec_decode_uninit(avctx);\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "7546964f96168cd6ac819ef4c3212ee586619f1a", + "length": 856 + }, + { + "index": 19192, + "code": "static void vfio_add_ext_cap(VFIOPCIDevice *vdev)\n\n{\n\n PCIDevice *pdev = &vdev->pdev;\n\n uint32_t header;\n\n uint16_t cap_id, next, size;\n\n uint8_t cap_ver;\n\n uint8_t *config;\n\n\n\n /* Only add extended caps if we have them and the guest can see them */\n\n if (!pci_is_express(pdev) || !pci_bus_is_express(pdev->bus) ||\n\n !pci_get_long(pdev->config + PCI_CONFIG_SPACE_SIZE)) {\n\n return;\n\n }\n\n\n\n /*\n\n * pcie_add_capability always inserts the new capability at the tail\n\n * of the chain. Therefore to end up with a chain that matches the\n\n * physical device, we cache the config space to avoid overwriting\n\n * the original config space when we parse the extended capabilities.\n\n */\n\n config = g_memdup(pdev->config, vdev->config_size);\n\n\n\n /*\n\n * Extended capabilities are chained with each pointing to the next, so we\n\n * can drop anything other than the head of the chain simply by modifying\n\n * the previous next pointer. For the head of the chain, we can modify the\n\n * capability ID to something that cannot match a valid capability. ID\n\n * 0 is reserved for this since absence of capabilities is indicated by\n\n * 0 for the ID, version, AND next pointer. However, pcie_add_capability()\n\n * uses ID 0 as reserved for list management and will incorrectly match and\n\n * assert if we attempt to pre-load the head of the chain with this ID.\n\n * Use ID 0xFFFF temporarily since it is also seems to be reserved in\n\n * part for identifying absence of capabilities in a root complex register\n\n * block. If the ID still exists after adding capabilities, switch back to\n\n * zero. We'll mark this entire first dword as emulated for this purpose.\n\n */\n\n pci_set_long(pdev->config + PCI_CONFIG_SPACE_SIZE,\n\n PCI_EXT_CAP(0xFFFF, 0, 0));\n\n pci_set_long(pdev->wmask + PCI_CONFIG_SPACE_SIZE, 0);\n\n pci_set_long(vdev->emulated_config_bits + PCI_CONFIG_SPACE_SIZE, ~0);\n\n\n\n for (next = PCI_CONFIG_SPACE_SIZE; next;\n\n next = PCI_EXT_CAP_NEXT(pci_get_long(config + next))) {\n\n header = pci_get_long(config + next);\n\n cap_id = PCI_EXT_CAP_ID(header);\n\n cap_ver = PCI_EXT_CAP_VER(header);\n\n\n\n /*\n\n * If it becomes important to configure extended capabilities to their\n\n * actual size, use this as the default when it's something we don't\n\n * recognize. Since QEMU doesn't actually handle many of the config\n\n * accesses, exact size doesn't seem worthwhile.\n\n */\n\n size = vfio_ext_cap_max_size(config, next);\n\n\n\n /* Use emulated next pointer to allow dropping extended caps */\n\n pci_long_test_and_set_mask(vdev->emulated_config_bits + next,\n\n PCI_EXT_CAP_NEXT_MASK);\n\n\n\n switch (cap_id) {\n\n case PCI_EXT_CAP_ID_SRIOV: /* Read-only VF BARs confuse OVMF */\n\n case PCI_EXT_CAP_ID_ARI: /* XXX Needs next function virtualization */\n\n trace_vfio_add_ext_cap_dropped(vdev->vbasedev.name, cap_id, next);\n\n break;\n\n default:\n\n pcie_add_capability(pdev, cap_id, cap_ver, next, size);\n\n }\n\n\n\n }\n\n\n\n /* Cleanup chain head ID if necessary */\n\n if (pci_get_word(pdev->config + PCI_CONFIG_SPACE_SIZE) == 0xFFFF) {\n\n pci_set_word(pdev->config + PCI_CONFIG_SPACE_SIZE, 0);\n\n }\n\n\n\n g_free(config);\n\n return;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d0d1cd70d10639273e2a23870e7e7d80b2bc4e21", + "length": 805 + }, + { + "index": 17780, + "code": "static void check_native_list(QObject *qobj,\n\n UserDefNativeListUnionKind kind)\n\n{\n\n QDict *qdict;\n\n QList *qlist;\n\n int i;\n\n\n\n qdict = qobject_to_qdict(qobj);\n\n g_assert(qdict);\n\n g_assert(qdict_haskey(qdict, \"data\"));\n\n qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, \"data\")));\n\n\n\n switch (kind) {\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_S8:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_S16:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_S32:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_S64:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_U8:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_U16:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_U32:\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_U64:\n\n /*\n\n * All integer elements in JSON arrays get stored into QNums\n\n * when we convert to QObjects, so we can check them all in\n\n * the same fashion, so simply fall through here.\n\n */\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:\n\n for (i = 0; i < 32; i++) {\n\n QObject *tmp;\n\n QNum *qvalue;\n\n int64_t val;\n\n\n\n tmp = qlist_peek(qlist);\n\n g_assert(tmp);\n\n qvalue = qobject_to_qnum(tmp);\n\n g_assert(qnum_get_try_int(qvalue, &val));\n\n g_assert_cmpint(val, ==, i);\n\n qobject_decref(qlist_pop(qlist));\n\n }\n\n break;\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:\n\n for (i = 0; i < 32; i++) {\n\n QObject *tmp;\n\n QBool *qvalue;\n\n tmp = qlist_peek(qlist);\n\n g_assert(tmp);\n\n qvalue = qobject_to_qbool(tmp);\n\n g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);\n\n qobject_decref(qlist_pop(qlist));\n\n }\n\n break;\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:\n\n for (i = 0; i < 32; i++) {\n\n QObject *tmp;\n\n QString *qvalue;\n\n gchar str[8];\n\n tmp = qlist_peek(qlist);\n\n g_assert(tmp);\n\n qvalue = qobject_to_qstring(tmp);\n\n sprintf(str, \"%d\", i);\n\n g_assert_cmpstr(qstring_get_str(qvalue), ==, str);\n\n qobject_decref(qlist_pop(qlist));\n\n }\n\n break;\n\n case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:\n\n for (i = 0; i < 32; i++) {\n\n QObject *tmp;\n\n QNum *qvalue;\n\n GString *double_expected = g_string_new(\"\");\n\n GString *double_actual = g_string_new(\"\");\n\n\n\n tmp = qlist_peek(qlist);\n\n g_assert(tmp);\n\n qvalue = qobject_to_qnum(tmp);\n\n g_string_printf(double_expected, \"%.6f\", (double)i / 3);\n\n g_string_printf(double_actual, \"%.6f\", qnum_get_double(qvalue));\n\n g_assert_cmpstr(double_actual->str, ==, double_expected->str);\n\n\n\n qobject_decref(qlist_pop(qlist));\n\n g_string_free(double_expected, true);\n\n g_string_free(double_actual, true);\n\n }\n\n break;\n\n default:\n\n g_assert_not_reached();\n\n }\n\n QDECREF(qlist);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "5923f85fb82df7c8c60a89458a5ae856045e5ab1", + "length": 780 + }, + { + "index": 19009, + "code": "int update_dimensions(VP8Context *s, int width, int height, int is_vp7)\n\n{\n\n AVCodecContext *avctx = s->avctx;\n\n int i, ret;\n\n\n\n if (width != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||\n\n height != s->avctx->height) {\n\n vp8_decode_flush_impl(s->avctx, 1);\n\n\n\n ret = ff_set_dimensions(s->avctx, width, height);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n\n\n s->mb_width = (s->avctx->coded_width + 15) / 16;\n\n s->mb_height = (s->avctx->coded_height + 15) / 16;\n\n\n\n s->mb_layout = is_vp7 || avctx->active_thread_type == FF_THREAD_SLICE &&\n\n FFMIN(s->num_coeff_partitions, avctx->thread_count) > 1;\n\n if (!s->mb_layout) { // Frame threading and one thread\n\n s->macroblocks_base = av_mallocz((s->mb_width + s->mb_height * 2 + 1) *\n\n sizeof(*s->macroblocks));\n\n s->intra4x4_pred_mode_top = av_mallocz(s->mb_width * 4);\n\n } else // Sliced threading\n\n s->macroblocks_base = av_mallocz((s->mb_width + 2) * (s->mb_height + 2) *\n\n sizeof(*s->macroblocks));\n\n s->top_nnz = av_mallocz(s->mb_width * sizeof(*s->top_nnz));\n\n s->top_border = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));\n\n s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));\n\n\n\n if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||\n\n !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {\n\n free_buffers(s);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n for (i = 0; i < MAX_THREADS; i++) {\n\n s->thread_data[i].filter_strength =\n\n av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));\n\n if (!s->thread_data[i].filter_strength) {\n\n free_buffers(s);\n\n return AVERROR(ENOMEM);\n\n }\n\n#if HAVE_THREADS\n\n pthread_mutex_init(&s->thread_data[i].lock, NULL);\n\n pthread_cond_init(&s->thread_data[i].cond, NULL);\n\n#endif\n\n }\n\n\n\n s->macroblocks = s->macroblocks_base + 1;\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "dabea74d0e82ea80cd344f630497cafcb3ef872c", + "length": 618 + }, + { + "index": 6510, + "code": "static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,\n\n int *got_frame_ptr, AVPacket *avpkt)\n\n{\n\n WMAVoiceContext *s = ctx->priv_data;\n\n GetBitContext *gb = &s->gb;\n\n int size, res, pos;\n\n\n\n /* Packets are sometimes a multiple of ctx->block_align, with a packet\n\n * header at each ctx->block_align bytes. However, FFmpeg's ASF demuxer\n\n * feeds us ASF packets, which may concatenate multiple \"codec\" packets\n\n * in a single \"muxer\" packet, so we artificially emulate that by\n\n * capping the packet size at ctx->block_align. */\n\n for (size = avpkt->size; size > ctx->block_align; size -= ctx->block_align);\n\n if (!size) {\n\n *got_frame_ptr = 0;\n\n return 0;\n\n }\n\n init_get_bits(&s->gb, avpkt->data, size << 3);\n\n\n\n /* size == ctx->block_align is used to indicate whether we are dealing with\n\n * a new packet or a packet of which we already read the packet header\n\n * previously. */\n\n if (size == ctx->block_align) { // new packet header\n\n if ((res = parse_packet_header(s)) < 0)\n\n return res;\n\n\n\n /* If the packet header specifies a s->spillover_nbits, then we want\n\n * to push out all data of the previous packet (+ spillover) before\n\n * continuing to parse new superframes in the current packet. */\n\n if (s->spillover_nbits > 0) {\n\n if (s->sframe_cache_size > 0) {\n\n int cnt = get_bits_count(gb);\n\n copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits);\n\n flush_put_bits(&s->pb);\n\n s->sframe_cache_size += s->spillover_nbits;\n\n if ((res = synth_superframe(ctx, data, got_frame_ptr)) == 0 &&\n\n *got_frame_ptr) {\n\n cnt += s->spillover_nbits;\n\n s->skip_bits_next = cnt & 7;\n\n return cnt >> 3;\n\n } else\n\n skip_bits_long (gb, s->spillover_nbits - cnt +\n\n get_bits_count(gb)); // resync\n\n } else\n\n skip_bits_long(gb, s->spillover_nbits); // resync\n\n }\n\n } else if (s->skip_bits_next)\n\n skip_bits(gb, s->skip_bits_next);\n\n\n\n /* Try parsing superframes in current packet */\n\n s->sframe_cache_size = 0;\n\n s->skip_bits_next = 0;\n\n pos = get_bits_left(gb);\n\n if ((res = synth_superframe(ctx, data, got_frame_ptr)) < 0) {\n\n return res;\n\n } else if (*got_frame_ptr) {\n\n int cnt = get_bits_count(gb);\n\n s->skip_bits_next = cnt & 7;\n\n return cnt >> 3;\n\n } else if ((s->sframe_cache_size = pos) > 0) {\n\n /* rewind bit reader to start of last (incomplete) superframe... */\n\n init_get_bits(gb, avpkt->data, size << 3);\n\n skip_bits_long(gb, (size << 3) - pos);\n\n av_assert1(get_bits_left(gb) == pos);\n\n\n\n /* ...and cache it for spillover in next packet */\n\n init_put_bits(&s->pb, s->sframe_cache, SFRAME_CACHE_MAXSIZE);\n\n copy_bits(&s->pb, avpkt->data, size, gb, s->sframe_cache_size);\n\n // FIXME bad - just copy bytes as whole and add use the\n\n // skip_bits_next field\n\n }\n\n\n\n return size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2a4700a4f03280fa8ba4fc0f8a9987bb550f0d1e", + "length": 846 + }, + { + "index": 5155, + "code": "int inet_listen_opts(QemuOpts *opts, int port_offset)\n\n{\n\n struct addrinfo ai,*res,*e;\n\n const char *addr;\n\n char port[33];\n\n char uaddr[INET6_ADDRSTRLEN+1];\n\n char uport[33];\n\n int slisten,rc,to,try_next;\n\n\n\n memset(&ai,0, sizeof(ai));\n\n ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;\n\n ai.ai_family = PF_UNSPEC;\n\n ai.ai_socktype = SOCK_STREAM;\n\n\n\n if (qemu_opt_get(opts, \"port\") == NULL) {\n\n fprintf(stderr, \"%s: host and/or port not specified\\n\", __FUNCTION__);\n\n return -1;\n\n }\n\n pstrcpy(port, sizeof(port), qemu_opt_get(opts, \"port\"));\n\n addr = qemu_opt_get(opts, \"host\");\n\n\n\n to = qemu_opt_get_number(opts, \"to\", 0);\n\n if (qemu_opt_get_bool(opts, \"ipv4\", 0))\n\n ai.ai_family = PF_INET;\n\n if (qemu_opt_get_bool(opts, \"ipv6\", 0))\n\n ai.ai_family = PF_INET6;\n\n\n\n /* lookup */\n\n if (port_offset)\n\n snprintf(port, sizeof(port), \"%d\", atoi(port) + port_offset);\n\n rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);\n\n if (rc != 0) {\n\n fprintf(stderr,\"getaddrinfo(%s,%s): %s\\n\", addr, port,\n\n gai_strerror(rc));\n\n return -1;\n\n }\n\n if (sockets_debug)\n\n inet_print_addrinfo(__FUNCTION__, res);\n\n\n\n /* create socket + bind */\n\n for (e = res; e != NULL; e = e->ai_next) {\n\n getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,\n\n\t\t uaddr,INET6_ADDRSTRLEN,uport,32,\n\n\t\t NI_NUMERICHOST | NI_NUMERICSERV);\n\n slisten = socket(e->ai_family, e->ai_socktype, e->ai_protocol);\n\n if (slisten < 0) {\n\n fprintf(stderr,\"%s: socket(%s): %s\\n\", __FUNCTION__,\n\n inet_strfamily(e->ai_family), strerror(errno));\n\n continue;\n\n }\n\n\n\n setsockopt(slisten,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on));\n\n#ifdef IPV6_V6ONLY\n\n if (e->ai_family == PF_INET6) {\n\n /* listen on both ipv4 and ipv6 */\n\n setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off,\n\n sizeof(off));\n\n }\n\n#endif\n\n\n\n for (;;) {\n\n if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {\n\n if (sockets_debug)\n\n fprintf(stderr,\"%s: bind(%s,%s,%d): OK\\n\", __FUNCTION__,\n\n inet_strfamily(e->ai_family), uaddr, inet_getport(e));\n\n goto listen;\n\n }\n\n try_next = to && (inet_getport(e) <= to + port_offset);\n\n if (!try_next || sockets_debug)\n\n fprintf(stderr,\"%s: bind(%s,%s,%d): %s\\n\", __FUNCTION__,\n\n inet_strfamily(e->ai_family), uaddr, inet_getport(e),\n\n strerror(errno));\n\n if (try_next) {\n\n inet_setport(e, inet_getport(e) + 1);\n\n continue;\n\n }\n\n break;\n\n }\n\n closesocket(slisten);\n\n }\n\n fprintf(stderr, \"%s: FAILED\\n\", __FUNCTION__);\n\n freeaddrinfo(res);\n\n return -1;\n\n\n\nlisten:\n\n if (listen(slisten,1) != 0) {\n\n perror(\"listen\");\n\n closesocket(slisten);\n\n freeaddrinfo(res);\n\n return -1;\n\n }\n\n snprintf(uport, sizeof(uport), \"%d\", inet_getport(e) - port_offset);\n\n qemu_opt_set(opts, \"host\", uaddr);\n\n qemu_opt_set(opts, \"port\", uport);\n\n qemu_opt_set(opts, \"ipv6\", (e->ai_family == PF_INET6) ? \"on\" : \"off\");\n\n qemu_opt_set(opts, \"ipv4\", (e->ai_family != PF_INET6) ? \"on\" : \"off\");\n\n freeaddrinfo(res);\n\n return slisten;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4", + "length": 931 + }, + { + "index": 3488, + "code": "static void init_proc_970MP (CPUPPCState *env)\n\n{\n\n gen_spr_ne_601(env);\n\n gen_spr_7xx(env);\n\n /* Time base */\n\n gen_tbl(env);\n\n /* Hardware implementation registers */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID0, \"HID0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_clear,\n\n 0x60000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID1, \"HID1\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_750_HID2, \"HID2\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_970_HID5, \"HID5\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n POWERPC970_HID5_INIT);\n\n /* Memory management */\n\n /* XXX: not correct */\n\n gen_low_BATs(env);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCFG, \"MMUCFG\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, SPR_NOACCESS,\n\n 0x00000000); /* TOFIX */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCSR0, \"MMUCSR0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000); /* TOFIX */\n\n spr_register(env, SPR_HIOR, \"SPR_HIOR\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0xFFF00000); /* XXX: This is a hack */\n\n#if !defined(CONFIG_USER_ONLY)\n\n env->excp_prefix = 0xFFF00000;\n\n#endif\n\n#if !defined(CONFIG_USER_ONLY)\n\n env->slb_nr = 32;\n\n#endif\n\n init_excp_970(env);\n\n env->dcache_line_size = 128;\n\n env->icache_line_size = 128;\n\n /* Allocate hardware IRQ controller */\n\n ppc970_irq_init(env);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "faadf50e2962dd54175647a80bd6fc4319c91973", + "length": 522 + }, + { + "index": 25430, + "code": "static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters)\n\n{\n\n static const enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };\n\n char sws_flags_str[128];\n\n char buffersrc_args[256];\n\n int ret;\n\n AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();\n\n AVFilterContext *filt_src = NULL, *filt_out = NULL, *filt_format;\n\n AVCodecContext *codec = is->video_st->codec;\n\n\n\n snprintf(sws_flags_str, sizeof(sws_flags_str), \"flags=%d\", sws_flags);\n\n graph->scale_sws_opts = av_strdup(sws_flags_str);\n\n\n\n snprintf(buffersrc_args, sizeof(buffersrc_args),\n\n \"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d\",\n\n codec->width, codec->height, codec->pix_fmt,\n\n is->video_st->time_base.num, is->video_st->time_base.den,\n\n codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den);\n\n\n\n if ((ret = avfilter_graph_create_filter(&filt_src,\n\n avfilter_get_by_name(\"buffer\"),\n\n \"ffplay_buffer\", buffersrc_args, NULL,\n\n graph)) < 0)\n\n return ret;\n\n\n\n buffersink_params->pixel_fmts = pix_fmts;\n\n ret = avfilter_graph_create_filter(&filt_out,\n\n avfilter_get_by_name(\"buffersink\"),\n\n \"ffplay_buffersink\", NULL, buffersink_params, graph);\n\n av_freep(&buffersink_params);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if ((ret = avfilter_graph_create_filter(&filt_format,\n\n avfilter_get_by_name(\"format\"),\n\n \"format\", \"yuv420p\", NULL, graph)) < 0)\n\n return ret;\n\n if ((ret = avfilter_link(filt_format, 0, filt_out, 0)) < 0)\n\n return ret;\n\n\n\n\n\n if (vfilters) {\n\n AVFilterInOut *outputs = avfilter_inout_alloc();\n\n AVFilterInOut *inputs = avfilter_inout_alloc();\n\n\n\n outputs->name = av_strdup(\"in\");\n\n outputs->filter_ctx = filt_src;\n\n outputs->pad_idx = 0;\n\n outputs->next = NULL;\n\n\n\n inputs->name = av_strdup(\"out\");\n\n inputs->filter_ctx = filt_format;\n\n inputs->pad_idx = 0;\n\n inputs->next = NULL;\n\n\n\n if ((ret = avfilter_graph_parse(graph, vfilters, &inputs, &outputs, NULL)) < 0)\n\n return ret;\n\n } else {\n\n if ((ret = avfilter_link(filt_src, 0, filt_format, 0)) < 0)\n\n return ret;\n\n }\n\n\n\n if ((ret = avfilter_graph_config(graph, NULL)) < 0)\n\n return ret;\n\n\n\n is->in_video_filter = filt_src;\n\n is->out_video_filter = filt_out;\n\n\n\n if (codec->codec->capabilities & CODEC_CAP_DR1) {\n\n is->use_dr1 = 1;\n\n codec->get_buffer = codec_get_buffer;\n\n codec->release_buffer = codec_release_buffer;\n\n codec->opaque = &is->buffer_pool;\n\n }\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "79a7451d069f17c72e566d8e76a75c15cc25c515", + "length": 716 + }, + { + "index": 11644, + "code": "static int roq_encode_video(RoqContext *enc)\n\n{\n\n RoqTempdata *tempData = enc->tmpData;\n\n int i, ret;\n\n\n\n memset(tempData, 0, sizeof(*tempData));\n\n\n\n ret = create_cel_evals(enc, tempData);\n\n if (ret < 0)\n\n return ret;\n\n\n\n ret = generate_new_codebooks(enc, tempData);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if (enc->framesSinceKeyframe >= 1) {\n\n motion_search(enc, 8);\n\n motion_search(enc, 4);\n\n }\n\n\n\n retry_encode:\n\n for (i=0; iwidth*enc->height/64; i++)\n\n gather_data_for_cel(tempData->cel_evals + i, enc, tempData);\n\n\n\n /* Quake 3 can't handle chunks bigger than 65535 bytes */\n\n if (tempData->mainChunkSize/8 > 65535) {\n\n av_log(enc->avctx, AV_LOG_ERROR,\n\n \"Warning, generated a frame too big (%d > 65535), \"\n\n \"try using a smaller qscale value.\\n\",\n\n tempData->mainChunkSize/8);\n\n enc->lambda *= 1.5;\n\n tempData->mainChunkSize = 0;\n\n memset(tempData->used_option, 0, sizeof(tempData->used_option));\n\n memset(tempData->codebooks.usedCB4, 0,\n\n sizeof(tempData->codebooks.usedCB4));\n\n memset(tempData->codebooks.usedCB2, 0,\n\n sizeof(tempData->codebooks.usedCB2));\n\n\n\n goto retry_encode;\n\n }\n\n\n\n remap_codebooks(enc, tempData);\n\n\n\n write_codebooks(enc, tempData);\n\n\n\n reconstruct_and_encode_image(enc, tempData, enc->width, enc->height,\n\n enc->width*enc->height/64);\n\n\n\n enc->avctx->coded_frame = enc->current_frame;\n\n\n\n /* Rotate frame history */\n\n FFSWAP(AVFrame *, enc->current_frame, enc->last_frame);\n\n FFSWAP(motion_vect *, enc->last_motion4, enc->this_motion4);\n\n FFSWAP(motion_vect *, enc->last_motion8, enc->this_motion8);\n\n\n\n av_free(tempData->cel_evals);\n\n av_free(tempData->closest_cb2);\n\n\n\n enc->framesSinceKeyframe++;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "95e2317ed85502dd8d96bcd9b12084dbfb8f9e8e", + "length": 520 + }, + { + "index": 26893, + "code": "bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,\n\n int len, bool is_write)\n\n{\n\n hwaddr l;\n\n uint8_t *ptr;\n\n uint64_t val;\n\n hwaddr addr1;\n\n MemoryRegion *mr;\n\n bool error = false;\n\n\n\n while (len > 0) {\n\n l = len;\n\n mr = address_space_translate(as, addr, &addr1, &l, is_write);\n\n\n\n if (is_write) {\n\n if (!memory_access_is_direct(mr, is_write)) {\n\n l = memory_access_size(mr, l, addr1);\n\n /* XXX: could force current_cpu to NULL to avoid\n\n potential bugs */\n\n if (l == 4) {\n\n /* 32 bit write access */\n\n val = ldl_p(buf);\n\n error |= io_mem_write(mr, addr1, val, 4);\n\n } else if (l == 2) {\n\n /* 16 bit write access */\n\n val = lduw_p(buf);\n\n error |= io_mem_write(mr, addr1, val, 2);\n\n } else {\n\n /* 8 bit write access */\n\n val = ldub_p(buf);\n\n error |= io_mem_write(mr, addr1, val, 1);\n\n }\n\n } else {\n\n addr1 += memory_region_get_ram_addr(mr);\n\n /* RAM case */\n\n ptr = qemu_get_ram_ptr(addr1);\n\n memcpy(ptr, buf, l);\n\n invalidate_and_set_dirty(addr1, l);\n\n }\n\n } else {\n\n if (!memory_access_is_direct(mr, is_write)) {\n\n /* I/O case */\n\n l = memory_access_size(mr, l, addr1);\n\n if (l == 4) {\n\n /* 32 bit read access */\n\n error |= io_mem_read(mr, addr1, &val, 4);\n\n stl_p(buf, val);\n\n } else if (l == 2) {\n\n /* 16 bit read access */\n\n error |= io_mem_read(mr, addr1, &val, 2);\n\n stw_p(buf, val);\n\n } else {\n\n /* 8 bit read access */\n\n error |= io_mem_read(mr, addr1, &val, 1);\n\n stb_p(buf, val);\n\n }\n\n } else {\n\n /* RAM case */\n\n ptr = qemu_get_ram_ptr(mr->ram_addr + addr1);\n\n memcpy(buf, ptr, l);\n\n }\n\n }\n\n len -= l;\n\n buf += l;\n\n addr += l;\n\n }\n\n\n\n return error;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "23326164ae6fe8d94b7eff123e03f97ca6978d33", + "length": 553 + }, + { + "index": 1004, + "code": "static int GLZWDecode(GifState * s, uint8_t * buf, int len)\n\n{\n\n int l, c, code, oc, fc;\n\n uint8_t *sp;\n\n\n\n if (s->end_code < 0)\n\n return 0;\n\n\n\n l = len;\n\n sp = s->sp;\n\n oc = s->oc;\n\n fc = s->fc;\n\n\n\n while (sp > s->stack) {\n\n *buf++ = *(--sp);\n\n if ((--l) == 0)\n\n goto the_end;\n\n }\n\n\n\n for (;;) {\n\n c = GetCode(s);\n\n if (c == s->end_code) {\n\n s->end_code = -1;\n\n break;\n\n } else if (c == s->clear_code) {\n\n s->cursize = s->codesize + 1;\n\n s->curmask = mask[s->cursize];\n\n s->slot = s->newcodes;\n\n s->top_slot = 1 << s->cursize;\n\n while ((c = GetCode(s)) == s->clear_code);\n\n if (c == s->end_code) {\n\n s->end_code = -1;\n\n break;\n\n }\n\n /* test error */\n\n if (c >= s->slot)\n\n c = 0;\n\n fc = oc = c;\n\n *buf++ = c;\n\n if ((--l) == 0)\n\n break;\n\n } else {\n\n code = c;\n\n if (code >= s->slot) {\n\n *sp++ = fc;\n\n code = oc;\n\n }\n\n while (code >= s->newcodes) {\n\n *sp++ = s->suffix[code];\n\n code = s->prefix[code];\n\n }\n\n *sp++ = code;\n\n if (s->slot < s->top_slot) {\n\n s->suffix[s->slot] = fc = code;\n\n s->prefix[s->slot++] = oc;\n\n oc = c;\n\n }\n\n if (s->slot >= s->top_slot) {\n\n if (s->cursize < MAXBITS) {\n\n s->top_slot <<= 1;\n\n s->curmask = mask[++s->cursize];\n\n }\n\n }\n\n while (sp > s->stack) {\n\n *buf++ = *(--sp);\n\n if ((--l) == 0)\n\n goto the_end;\n\n }\n\n }\n\n }\n\n the_end:\n\n s->sp = sp;\n\n s->oc = oc;\n\n s->fc = fc;\n\n return len - l;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "0b54f3c0878a3acaa9142e4f24942e762d97e350", + "length": 546 + }, + { + "index": 13075, + "code": "static int smvjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size,\n AVPacket *avpkt)\n{\n const AVPixFmtDescriptor *desc;\n SMVJpegDecodeContext *s = avctx->priv_data;\n AVFrame* mjpeg_data = s->picture[0];\n int i, cur_frame = 0, ret = 0;\n cur_frame = avpkt->pts % s->frames_per_jpeg;\n /* Are we at the start of a block? */\n if (!cur_frame) {\n av_frame_unref(mjpeg_data);\n ret = avcodec_decode_video2(s->avctx, mjpeg_data, &s->mjpeg_data_size, avpkt);\n if (ret < 0) {\n s->mjpeg_data_size = 0;\n return ret;\n }\n } else if (!s->mjpeg_data_size)\n return AVERROR(EINVAL);\n desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);\n av_assert0(desc);\n if (mjpeg_data->height % (s->frames_per_jpeg << desc->log2_chroma_h)) {\n av_log(avctx, AV_LOG_ERROR, \"Invalid height\\n\");\n return AVERROR_INVALIDDATA;\n }\n /*use the last lot... */\n *data_size = s->mjpeg_data_size;\n avctx->pix_fmt = s->avctx->pix_fmt;\n /* We shouldn't get here if frames_per_jpeg <= 0 because this was rejected\n in init */\n ret = ff_set_dimensions(avctx, mjpeg_data->width, mjpeg_data->height / s->frames_per_jpeg);\n if (ret < 0) {\n av_log(s, AV_LOG_ERROR, \"Failed to set dimensions\\n\");\n return ret;\n }\n if (*data_size) {\n s->picture[1]->extended_data = NULL;\n s->picture[1]->width = avctx->width;\n s->picture[1]->height = avctx->height;\n s->picture[1]->format = avctx->pix_fmt;\n /* ff_init_buffer_info(avctx, &s->picture[1]); */\n smv_img_pnt(s->picture[1]->data, mjpeg_data->data, mjpeg_data->linesize,\n avctx->pix_fmt, avctx->width, avctx->height, cur_frame);\n for (i = 0; i < AV_NUM_DATA_POINTERS; i++)\n s->picture[1]->linesize[i] = mjpeg_data->linesize[i];\n ret = av_frame_ref(data, s->picture[1]);\n }\n return ret;\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "360bc0d90aa66cf21e9f488e77d21db18e01ec9c", + "length": 581 + }, + { + "index": 18838, + "code": "static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc)\n\n{\n\n uint64_t VCO_out, PLL_out;\n\n uint32_t CPU_clk, TMR_clk, SDRAM_clk, PLB_clk, OPB_clk, EXT_clk, UART_clk;\n\n int M, D0, D1, D2;\n\n\n\n D0 = ((cpc->pllmr >> 26) & 0x3) + 1; /* CBDV */\n\n if (cpc->pllmr & 0x80000000) {\n\n D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */\n\n D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */\n\n M = D0 * D1 * D2;\n\n VCO_out = cpc->sysclk * M;\n\n if (VCO_out < 400000000 || VCO_out > 800000000) {\n\n /* PLL cannot lock */\n\n cpc->pllmr &= ~0x80000000;\n\n goto bypass_pll;\n\n }\n\n PLL_out = VCO_out / D2;\n\n } else {\n\n /* Bypass PLL */\n\n bypass_pll:\n\n M = D0;\n\n PLL_out = cpc->sysclk * M;\n\n }\n\n CPU_clk = PLL_out;\n\n if (cpc->cr1 & 0x00800000)\n\n TMR_clk = cpc->sysclk; /* Should have a separate clock */\n\n else\n\n TMR_clk = CPU_clk;\n\n PLB_clk = CPU_clk / D0;\n\n SDRAM_clk = PLB_clk;\n\n D0 = ((cpc->pllmr >> 10) & 0x3) + 1;\n\n OPB_clk = PLB_clk / D0;\n\n D0 = ((cpc->pllmr >> 24) & 0x3) + 2;\n\n EXT_clk = PLB_clk / D0;\n\n D0 = ((cpc->cr0 >> 1) & 0x1F) + 1;\n\n UART_clk = CPU_clk / D0;\n\n /* Setup CPU clocks */\n\n clk_setup(&cpc->clk_setup[PPC405CR_CPU_CLK], CPU_clk);\n\n /* Setup time-base clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_TMR_CLK], TMR_clk);\n\n /* Setup PLB clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_PLB_CLK], PLB_clk);\n\n /* Setup SDRAM clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_SDRAM_CLK], SDRAM_clk);\n\n /* Setup OPB clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_OPB_CLK], OPB_clk);\n\n /* Setup external clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_EXT_CLK], EXT_clk);\n\n /* Setup UART clock */\n\n clk_setup(&cpc->clk_setup[PPC405CR_UART_CLK], UART_clk);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "fb6971c110387cf597b58c411658e3d15cc6c6fb", + "length": 679 + }, + { + "index": 14477, + "code": "int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,\n\n AVPacket *avpkt,\n\n const AVFrame *frame,\n\n int *got_packet_ptr)\n\n{\n\n int ret;\n\n AVPacket user_pkt = *avpkt;\n\n\n\n *got_packet_ptr = 0;\n\n\n\n if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {\n\n av_free_packet(avpkt);\n\n av_init_packet(avpkt);\n\n avpkt->size = 0;\n\n return 0;\n\n }\n\n\n\n if (av_image_check_size(avctx->width, avctx->height, 0, avctx))\n\n return AVERROR(EINVAL);\n\n\n\n av_assert0(avctx->codec->encode2);\n\n\n\n ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);\n\n av_assert0(ret <= 0);\n\n\n\n if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {\n\n if (user_pkt.data) {\n\n if (user_pkt.size >= avpkt->size) {\n\n memcpy(user_pkt.data, avpkt->data, avpkt->size);\n\n } else {\n\n av_log(avctx, AV_LOG_ERROR, \"Provided packet is too small, needs to be %d\\n\", avpkt->size);\n\n avpkt->size = user_pkt.size;\n\n ret = -1;\n\n }\n\n avpkt->data = user_pkt.data;\n\n avpkt->destruct = user_pkt.destruct;\n\n } else {\n\n if (av_dup_packet(avpkt) < 0) {\n\n ret = AVERROR(ENOMEM);\n\n }\n\n }\n\n }\n\n\n\n if (!ret) {\n\n if (!*got_packet_ptr)\n\n avpkt->size = 0;\n\n else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))\n\n avpkt->pts = avpkt->dts = frame->pts;\n\n\n\n if (!user_pkt.data && avpkt->data &&\n\n avpkt->destruct == av_destruct_packet) {\n\n uint8_t *new_data = av_realloc(avpkt->data, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (new_data)\n\n avpkt->data = new_data;\n\n }\n\n\n\n avctx->frame_number++;\n\n }\n\n\n\n if (ret < 0 || !*got_packet_ptr)\n\n av_free_packet(avpkt);\n\n\n\n emms_c();\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "532f1c7aa7390af5e5de2892481041000e4d872b", + "length": 516 + }, + { + "index": 4626, + "code": "long do_sigreturn(CPUSPARCState *env)\n\n{\n\n abi_ulong sf_addr;\n\n struct target_signal_frame *sf;\n\n uint32_t up_psr, pc, npc;\n\n target_sigset_t set;\n\n sigset_t host_set;\n\n int err=0, i;\n\n\n\n sf_addr = env->regwptr[UREG_FP];\n\n trace_user_do_sigreturn(env, sf_addr);\n\n if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {\n\n goto segv_and_exit;\n\n }\n\n\n\n /* 1. Make sure we are not getting garbage from the user */\n\n\n\n if (sf_addr & 3)\n\n goto segv_and_exit;\n\n\n\n __get_user(pc, &sf->info.si_regs.pc);\n\n __get_user(npc, &sf->info.si_regs.npc);\n\n\n\n if ((pc | npc) & 3) {\n\n goto segv_and_exit;\n\n }\n\n\n\n /* 2. Restore the state */\n\n __get_user(up_psr, &sf->info.si_regs.psr);\n\n\n\n /* User can only change condition codes and FPU enabling in %psr. */\n\n env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))\n\n | (env->psr & ~(PSR_ICC /* | PSR_EF */));\n\n\n\n env->pc = pc;\n\n env->npc = npc;\n\n __get_user(env->y, &sf->info.si_regs.y);\n\n for (i=0; i < 8; i++) {\n\n __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);\n\n }\n\n for (i=0; i < 8; i++) {\n\n __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);\n\n }\n\n\n\n /* FIXME: implement FPU save/restore:\n\n * __get_user(fpu_save, &sf->fpu_save);\n\n * if (fpu_save)\n\n * err |= restore_fpu_state(env, fpu_save);\n\n */\n\n\n\n /* This is pretty much atomic, no amount locking would prevent\n\n * the races which exist anyways.\n\n */\n\n __get_user(set.sig[0], &sf->info.si_mask);\n\n for(i = 1; i < TARGET_NSIG_WORDS; i++) {\n\n __get_user(set.sig[i], &sf->extramask[i - 1]);\n\n }\n\n\n\n target_to_host_sigset_internal(&host_set, &set);\n\n do_sigprocmask(SIG_SETMASK, &host_set, NULL);\n\n\n\n if (err) {\n\n goto segv_and_exit;\n\n }\n\n unlock_user_struct(sf, sf_addr, 0);\n\n return env->regwptr[0];\n\n\n\nsegv_and_exit:\n\n unlock_user_struct(sf, sf_addr, 0);\n\n force_sig(TARGET_SIGSEGV);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "c0bea68f9ea48f0dea7a06a259a613bfd3a7e35e", + "length": 627 + }, + { + "index": 7166, + "code": "static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int depth, AVFormatContext *s)\n\n{\n\n AVIOContext *pb;\n\n WtvFile *wf;\n\n uint8_t *buffer;\n\n\n\n if (avio_seek(s->pb, (int64_t)first_sector << WTV_SECTOR_BITS, SEEK_SET) < 0)\n\n return NULL;\n\n\n\n wf = av_mallocz(sizeof(WtvFile));\n\n if (!wf)\n\n return NULL;\n\n\n\n if (depth == 0) {\n\n wf->sectors = av_malloc(sizeof(uint32_t));\n\n if (!wf->sectors) {\n\n av_free(wf);\n\n return NULL;\n\n }\n\n wf->sectors[0] = first_sector;\n\n wf->nb_sectors = 1;\n\n } else if (depth == 1) {\n\n wf->sectors = av_malloc(WTV_SECTOR_SIZE);\n\n if (!wf->sectors) {\n\n av_free(wf);\n\n return NULL;\n\n }\n\n wf->nb_sectors = read_ints(s->pb, wf->sectors, WTV_SECTOR_SIZE / 4);\n\n } else if (depth == 2) {\n\n uint32_t sectors1[WTV_SECTOR_SIZE / 4];\n\n int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4);\n\n int i;\n\n\n\n wf->sectors = av_malloc(nb_sectors1 << WTV_SECTOR_BITS);\n\n if (!wf->sectors) {\n\n av_free(wf);\n\n return NULL;\n\n }\n\n wf->nb_sectors = 0;\n\n for (i = 0; i < nb_sectors1; i++) {\n\n if (avio_seek(s->pb, (int64_t)sectors1[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)\n\n break;\n\n wf->nb_sectors += read_ints(s->pb, wf->sectors + i * WTV_SECTOR_SIZE / 4, WTV_SECTOR_SIZE / 4);\n\n }\n\n } else {\n\n av_log(s, AV_LOG_ERROR, \"unsupported file allocation table depth (0x%x)\\n\", depth);\n\n av_free(wf);\n\n return NULL;\n\n }\n\n wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS;\n\n\n\n if (!wf->nb_sectors) {\n\n av_free(wf->sectors);\n\n av_free(wf);\n\n return NULL;\n\n }\n\n\n\n if (wf->sectors[wf->nb_sectors - 1] << WTV_SECTOR_BITS > avio_tell(s->pb))\n\n av_log(s, AV_LOG_WARNING, \"truncated file\\n\");\n\n\n\n /* check length */\n\n length &= 0xFFFFFFFFFFFF;\n\n if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) {\n\n av_log(s, AV_LOG_WARNING, \"reported file length (0x%\"PRIx64\") exceeds number of available sectors (0x%\"PRIx64\")\\n\", length, (int64_t)wf->nb_sectors << wf->sector_bits);\n\n length = (int64_t)wf->nb_sectors << wf->sector_bits;\n\n }\n\n wf->length = length;\n\n\n\n /* seek to initial sector */\n\n wf->position = 0;\n\n if (avio_seek(s->pb, (int64_t)wf->sectors[0] << WTV_SECTOR_BITS, SEEK_SET) < 0) {\n\n av_free(wf->sectors);\n\n av_free(wf);\n\n return NULL;\n\n }\n\n\n\n wf->pb_filesystem = s->pb;\n\n buffer = av_malloc(1 << wf->sector_bits);\n\n if (!buffer) {\n\n av_free(wf->sectors);\n\n av_free(wf);\n\n return NULL;\n\n }\n\n\n\n pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf,\n\n wtvfile_read_packet, NULL, wtvfile_seek);\n\n if (!pb) {\n\n av_free(buffer);\n\n av_free(wf->sectors);\n\n av_free(wf);\n\n }\n\n return pb;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "3317414fc11a9a187b474141f4ac13f895c0b493", + "length": 909 + }, + { + "index": 13891, + "code": "static void gmc_motion(MpegEncContext *s,\n\n uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,\n\n uint8_t **ref_picture)\n\n{\n\n uint8_t *ptr;\n\n int linesize, uvlinesize;\n\n const int a = s->sprite_warping_accuracy;\n\n int ox, oy;\n\n\n\n linesize = s->linesize;\n\n uvlinesize = s->uvlinesize;\n\n\n\n ptr = ref_picture[0];\n\n\n\n ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +\n\n s->sprite_delta[0][1] * s->mb_y * 16;\n\n oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +\n\n s->sprite_delta[1][1] * s->mb_y * 16;\n\n\n\n s->mdsp.gmc(dest_y, ptr, linesize, 16,\n\n ox, oy,\n\n s->sprite_delta[0][0], s->sprite_delta[0][1],\n\n s->sprite_delta[1][0], s->sprite_delta[1][1],\n\n a + 1, (1 << (2 * a + 1)) - s->no_rounding,\n\n s->h_edge_pos, s->v_edge_pos);\n\n s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,\n\n ox + s->sprite_delta[0][0] * 8,\n\n oy + s->sprite_delta[1][0] * 8,\n\n s->sprite_delta[0][0], s->sprite_delta[0][1],\n\n s->sprite_delta[1][0], s->sprite_delta[1][1],\n\n a + 1, (1 << (2 * a + 1)) - s->no_rounding,\n\n s->h_edge_pos, s->v_edge_pos);\n\n\n\n if (CONFIG_GRAY && s->flags & CODEC_FLAG_GRAY)\n\n return;\n\n\n\n ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +\n\n s->sprite_delta[0][1] * s->mb_y * 8;\n\n oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +\n\n s->sprite_delta[1][1] * s->mb_y * 8;\n\n\n\n ptr = ref_picture[1];\n\n s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,\n\n ox, oy,\n\n s->sprite_delta[0][0], s->sprite_delta[0][1],\n\n s->sprite_delta[1][0], s->sprite_delta[1][1],\n\n a + 1, (1 << (2 * a + 1)) - s->no_rounding,\n\n s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n\n\n\n ptr = ref_picture[2];\n\n s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,\n\n ox, oy,\n\n s->sprite_delta[0][0], s->sprite_delta[0][1],\n\n s->sprite_delta[1][0], s->sprite_delta[1][1],\n\n a + 1, (1 << (2 * a + 1)) - s->no_rounding,\n\n s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "fd52d2d3d1ee41822a9801dffd41c0e1a2db32a8", + "length": 780 + }, + { + "index": 27226, + "code": "static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,\n\n unsigned segment_width)\n\n{\n\n#define TOP_HBAR 1\n\n#define MID_HBAR 2\n\n#define BOT_HBAR 4\n\n#define LEFT_TOP_VBAR 8\n\n#define LEFT_BOT_VBAR 16\n\n#define RIGHT_TOP_VBAR 32\n\n#define RIGHT_BOT_VBAR 64\n\n struct {\n\n int x, y, w, h;\n\n } segments[] = {\n\n { 1, 0, 5, 1 }, /* TOP_HBAR */\n\n { 1, 6, 5, 1 }, /* MID_HBAR */\n\n { 1, 12, 5, 1 }, /* BOT_HBAR */\n\n { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */\n\n { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */\n\n { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */\n\n { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */\n\n };\n\n static const unsigned char masks[10] = {\n\n /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,\n\n /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,\n\n /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,\n\n /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,\n\n };\n\n unsigned mask = masks[digit];\n\n int i;\n\n\n\n draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);\n\n for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)\n\n if (mask & (1<intra_scantable.permutated;\n\n const int qscale = s->qscale;\n\n OPEN_READER(re, &s->gb);\n\n i = -1;\n\n\n\n // special case for first coefficient, no need to add second VLC table\n\n UPDATE_CACHE(re, &s->gb);\n\n if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {\n\n level = (3 * qscale) >> 1;\n\n if (GET_CACHE(re, &s->gb) & 0x40000000)\n\n level = -level;\n\n block[0] = level;\n\n i++;\n\n SKIP_BITS(re, &s->gb, 2);\n\n if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)\n\n goto end;\n\n }\n\n\n\n /* now quantify & encode AC coefficients */\n\n for (;;) {\n\n GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);\n\n\n\n if (level != 0) {\n\n i += run;\n\n check_scantable_index(s, i);\n\n j = scantable[i];\n\n level = ((level * 2 + 1) * qscale) >> 1;\n\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n\n SKIP_BITS(re, &s->gb, 1);\n\n } else {\n\n /* escape */\n\n run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);\n\n UPDATE_CACHE(re, &s->gb);\n\n level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);\n\n\n\n i += run;\n\n check_scantable_index(s, i);\n\n j = scantable[i];\n\n if (level < 0) {\n\n level = ((-level * 2 + 1) * qscale) >> 1;\n\n level = -level;\n\n } else {\n\n level = ((level * 2 + 1) * qscale) >> 1;\n\n }\n\n }\n\n\n\n block[j] = level;\n\n if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)\n\n break;\n\n\n\n UPDATE_CACHE(re, &s->gb);\n\n }\n\nend:\n\n LAST_SKIP_BITS(re, &s->gb, 2);\n\n CLOSE_READER(re, &s->gb);\n\n s->block_last_index[n] = i;\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "7667afffb8dd54595ef2a959c385babd4c9c94cf", + "length": 653 + }, + { + "index": 10406, + "code": "PCIBus *pci_prep_init(qemu_irq *pic)\n\n{\n\n PREPPCIState *s;\n\n PCIDevice *d;\n\n int PPC_io_memory;\n\n\n\n s = qemu_mallocz(sizeof(PREPPCIState));\n\n s->bus = pci_register_bus(prep_set_irq, prep_map_irq, pic, 0, 2);\n\n\n\n register_ioport_write(0xcf8, 4, 4, pci_prep_addr_writel, s);\n\n register_ioport_read(0xcf8, 4, 4, pci_prep_addr_readl, s);\n\n\n\n register_ioport_write(0xcfc, 4, 1, pci_host_data_writeb, s);\n\n register_ioport_write(0xcfc, 4, 2, pci_host_data_writew, s);\n\n register_ioport_write(0xcfc, 4, 4, pci_host_data_writel, s);\n\n register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);\n\n register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);\n\n register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);\n\n\n\n PPC_io_memory = cpu_register_io_memory(0, PPC_PCIIO_read,\n\n PPC_PCIIO_write, s);\n\n cpu_register_physical_memory(0x80800000, 0x00400000, PPC_io_memory);\n\n\n\n /* PCI host bridge */\n\n d = pci_register_device(s->bus, \"PREP Host Bridge - Motorola Raven\",\n\n sizeof(PCIDevice), 0, NULL, NULL);\n\n d->config[0x00] = 0x57; // vendor_id : Motorola\n\n d->config[0x01] = 0x10;\n\n d->config[0x02] = 0x01; // device_id : Raven\n\n d->config[0x03] = 0x48;\n\n d->config[0x08] = 0x00; // revision\n\n d->config[0x0A] = 0x00; // class_sub = pci host\n\n d->config[0x0B] = 0x06; // class_base = PCI_bridge\n\n d->config[0x0C] = 0x08; // cache_line_size\n\n d->config[0x0D] = 0x10; // latency_timer\n\n d->config[0x0E] = 0x00; // header_type\n\n d->config[0x34] = 0x00; // capabilities_pointer\n\n\n\n return s->bus;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "a01d8cadadf4c0dad8fc5157ee56aea8ec323982", + "length": 576 + }, + { + "index": 21523, + "code": "static void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,\n\n const uint16_t *ubuf0, const uint16_t *ubuf1,\n\n const uint16_t *vbuf0, const uint16_t *vbuf1,\n\n const uint16_t *abuf0, uint8_t *dest,\n\n int dstW, int uvalpha, enum PixelFormat dstFormat,\n\n int flags, int y)\n\n{\n\n const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1\n\n\n\n if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1(%%REGBP, %5)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB16(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither)\n\n );\n\n } else {\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1b(%%REGBP, %5)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB16(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither)\n\n );\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "13a099799e89a76eb921ca452e1b04a7a28a9855", + "length": 746 + }, + { + "index": 4611, + "code": "static void ide_atapi_identify(IDEState *s)\n\n{\n\n uint16_t *p;\n\n\n\n if (s->identify_set) {\n\n\tmemcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data));\n\n\treturn;\n\n }\n\n\n\n memset(s->io_buffer, 0, 512);\n\n p = (uint16_t *)s->io_buffer;\n\n /* Removable CDROM, 50us response, 12 byte packets */\n\n put_le16(p + 0, (2 << 14) | (5 << 8) | (1 << 7) | (2 << 5) | (0 << 0));\n\n padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */\n\n put_le16(p + 20, 3); /* buffer type */\n\n put_le16(p + 21, 512); /* cache size in sectors */\n\n put_le16(p + 22, 4); /* ecc bytes */\n\n padstr((char *)(p + 23), s->version, 8); /* firmware version */\n\n padstr((char *)(p + 27), \"QEMU DVD-ROM\", 40); /* model */\n\n put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */\n\n#ifdef USE_DMA_CDROM\n\n put_le16(p + 49, 1 << 9 | 1 << 8); /* DMA and LBA supported */\n\n put_le16(p + 53, 7); /* words 64-70, 54-58, 88 valid */\n\n put_le16(p + 62, 7); /* single word dma0-2 supported */\n\n put_le16(p + 63, 7); /* mdma0-2 supported */\n\n#else\n\n put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */\n\n put_le16(p + 53, 3); /* words 64-70, 54-58 valid */\n\n put_le16(p + 63, 0x103); /* DMA modes XXX: may be incorrect */\n\n#endif\n\n put_le16(p + 64, 3); /* pio3-4 supported */\n\n put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */\n\n put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */\n\n put_le16(p + 67, 0x12c); /* minimum PIO cycle time without flow control */\n\n put_le16(p + 68, 0xb4); /* minimum PIO cycle time with IORDY flow control */\n\n\n\n put_le16(p + 71, 30); /* in ns */\n\n put_le16(p + 72, 30); /* in ns */\n\n\n\n if (s->ncq_queues) {\n\n put_le16(p + 75, s->ncq_queues - 1);\n\n /* NCQ supported */\n\n put_le16(p + 76, (1 << 8));\n\n }\n\n\n\n put_le16(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */\n\n#ifdef USE_DMA_CDROM\n\n put_le16(p + 88, 0x3f | (1 << 13)); /* udma5 set and supported */\n\n#endif\n\n memcpy(s->identify_data, p, sizeof(s->identify_data));\n\n s->identify_set = 1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "27e0c9a1bbd166a67c16291016fba298a8e47140", + "length": 752 + }, + { + "index": 5596, + "code": "static float128 addFloat128Sigs( float128 a, float128 b, flag zSign STATUS_PARAM)\n\n{\n\n int32 aExp, bExp, zExp;\n\n uint64_t aSig0, aSig1, bSig0, bSig1, zSig0, zSig1, zSig2;\n\n int32 expDiff;\n\n\n\n aSig1 = extractFloat128Frac1( a );\n\n aSig0 = extractFloat128Frac0( a );\n\n aExp = extractFloat128Exp( a );\n\n bSig1 = extractFloat128Frac1( b );\n\n bSig0 = extractFloat128Frac0( b );\n\n bExp = extractFloat128Exp( b );\n\n expDiff = aExp - bExp;\n\n if ( 0 < expDiff ) {\n\n if ( aExp == 0x7FFF ) {\n\n if ( aSig0 | aSig1 ) return propagateFloat128NaN( a, b STATUS_VAR );\n\n return a;\n\n }\n\n if ( bExp == 0 ) {\n\n --expDiff;\n\n }\n\n else {\n\n bSig0 |= LIT64( 0x0001000000000000 );\n\n }\n\n shift128ExtraRightJamming(\n\n bSig0, bSig1, 0, expDiff, &bSig0, &bSig1, &zSig2 );\n\n zExp = aExp;\n\n }\n\n else if ( expDiff < 0 ) {\n\n if ( bExp == 0x7FFF ) {\n\n if ( bSig0 | bSig1 ) return propagateFloat128NaN( a, b STATUS_VAR );\n\n return packFloat128( zSign, 0x7FFF, 0, 0 );\n\n }\n\n if ( aExp == 0 ) {\n\n ++expDiff;\n\n }\n\n else {\n\n aSig0 |= LIT64( 0x0001000000000000 );\n\n }\n\n shift128ExtraRightJamming(\n\n aSig0, aSig1, 0, - expDiff, &aSig0, &aSig1, &zSig2 );\n\n zExp = bExp;\n\n }\n\n else {\n\n if ( aExp == 0x7FFF ) {\n\n if ( aSig0 | aSig1 | bSig0 | bSig1 ) {\n\n return propagateFloat128NaN( a, b STATUS_VAR );\n\n }\n\n return a;\n\n }\n\n add128( aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1 );\n\n if ( aExp == 0 ) {\n\n if ( STATUS(flush_to_zero) ) return packFloat128( zSign, 0, 0, 0 );\n\n return packFloat128( zSign, 0, zSig0, zSig1 );\n\n }\n\n zSig2 = 0;\n\n zSig0 |= LIT64( 0x0002000000000000 );\n\n zExp = aExp;\n\n goto shiftRight1;\n\n }\n\n aSig0 |= LIT64( 0x0001000000000000 );\n\n add128( aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1 );\n\n --zExp;\n\n if ( zSig0 < LIT64( 0x0002000000000000 ) ) goto roundAndPack;\n\n ++zExp;\n\n shiftRight1:\n\n shift128ExtraRightJamming(\n\n zSig0, zSig1, zSig2, 1, &zSig0, &zSig1, &zSig2 );\n\n roundAndPack:\n\n return roundAndPackFloat128( zSign, zExp, zSig0, zSig1, zSig2 STATUS_VAR );\n\n\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "e6afc87f804abee7d0479be5e8e31c56d885fafb", + "length": 813 + }, + { + "index": 1167, + "code": "static void slavio_timer_mem_writel(void *opaque, target_phys_addr_t addr,\n\n uint32_t val)\n\n{\n\n SLAVIO_TIMERState *s = opaque;\n\n uint32_t saddr;\n\n int reload = 0;\n\n\n\n DPRINTF(\"write \" TARGET_FMT_plx \" %08x\\n\", addr, val);\n\n saddr = (addr & TIMER_MAXADDR) >> 2;\n\n switch (saddr) {\n\n case TIMER_LIMIT:\n\n if (slavio_timer_is_user(s)) {\n\n // set user counter MSW, reset counter\n\n qemu_irq_lower(s->irq);\n\n s->limit = TIMER_MAX_COUNT64;\n\n DPRINTF(\"processor %d user timer reset\\n\", s->slave_index);\n\n ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);\n\n } else {\n\n // set limit, reset counter\n\n qemu_irq_lower(s->irq);\n\n s->limit = val & TIMER_MAX_COUNT32;\n\n if (!s->limit)\n\n s->limit = TIMER_MAX_COUNT32;\n\n ptimer_set_limit(s->timer, s->limit >> 9, 1);\n\n }\n\n break;\n\n case TIMER_COUNTER:\n\n if (slavio_timer_is_user(s)) {\n\n // set user counter LSW, reset counter\n\n qemu_irq_lower(s->irq);\n\n s->limit = TIMER_MAX_COUNT64;\n\n DPRINTF(\"processor %d user timer reset\\n\", s->slave_index);\n\n ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);\n\n } else\n\n DPRINTF(\"not user timer\\n\");\n\n break;\n\n case TIMER_COUNTER_NORST:\n\n // set limit without resetting counter\n\n s->limit = val & TIMER_MAX_COUNT32;\n\n if (!s->limit)\n\n s->limit = TIMER_MAX_COUNT32;\n\n ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), reload);\n\n break;\n\n case TIMER_STATUS:\n\n if (slavio_timer_is_user(s)) {\n\n // start/stop user counter\n\n if ((val & 1) && !s->running) {\n\n DPRINTF(\"processor %d user timer started\\n\", s->slave_index);\n\n ptimer_run(s->timer, 0);\n\n s->running = 1;\n\n } else if (!(val & 1) && s->running) {\n\n DPRINTF(\"processor %d user timer stopped\\n\", s->slave_index);\n\n ptimer_stop(s->timer);\n\n s->running = 0;\n\n }\n\n }\n\n break;\n\n case TIMER_MODE:\n\n if (s->master == NULL) {\n\n unsigned int i;\n\n\n\n for (i = 0; i < s->num_slaves; i++) {\n\n if (val & (1 << i)) {\n\n qemu_irq_lower(s->slave[i]->irq);\n\n s->slave[i]->limit = -1ULL;\n\n }\n\n if ((val & (1 << i)) != (s->slave_mode & (1 << i))) {\n\n ptimer_stop(s->slave[i]->timer);\n\n ptimer_set_limit(s->slave[i]->timer,\n\n LIMIT_TO_PERIODS(s->slave[i]->limit), 1);\n\n DPRINTF(\"processor %d timer changed\\n\",\n\n s->slave[i]->slave_index);\n\n ptimer_run(s->slave[i]->timer, 0);\n\n }\n\n }\n\n s->slave_mode = val & ((1 << s->num_slaves) - 1);\n\n } else\n\n DPRINTF(\"not system timer\\n\");\n\n break;\n\n default:\n\n DPRINTF(\"invalid write address \" TARGET_FMT_plx \"\\n\", addr);\n\n break;\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "6240d6467077a12c24878bab645d8e2983e4975a", + "length": 784 + }, + { + "index": 2403, + "code": "static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s,\n\n VHDXLogSequence *logs)\n\n{\n\n int ret = 0;\n\n int i;\n\n uint32_t cnt, sectors_read;\n\n uint64_t new_file_size;\n\n void *data = NULL;\n\n VHDXLogDescEntries *desc_entries = NULL;\n\n VHDXLogEntryHeader hdr_tmp = { 0 };\n\n\n\n cnt = logs->count;\n\n\n\n data = qemu_blockalign(bs, VHDX_LOG_SECTOR_SIZE);\n\n\n\n ret = vhdx_user_visible_write(bs, s);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\n /* each iteration represents one log sequence, which may span multiple\n\n * sectors */\n\n while (cnt--) {\n\n ret = vhdx_log_peek_hdr(bs, &logs->log, &hdr_tmp);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n /* if the log shows a FlushedFileOffset larger than our current file\n\n * size, then that means the file has been truncated / corrupted, and\n\n * we must refused to open it / use it */\n\n if (hdr_tmp.flushed_file_offset > bdrv_getlength(bs->file->bs)) {\n\n ret = -EINVAL;\n\n goto exit;\n\n }\n\n\n\n ret = vhdx_log_read_desc(bs, s, &logs->log, &desc_entries, true);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\n for (i = 0; i < desc_entries->hdr.descriptor_count; i++) {\n\n if (desc_entries->desc[i].signature == VHDX_LOG_DESC_SIGNATURE) {\n\n /* data sector, so read a sector to flush */\n\n ret = vhdx_log_read_sectors(bs, &logs->log, §ors_read,\n\n data, 1, false);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n if (sectors_read != 1) {\n\n ret = -EINVAL;\n\n goto exit;\n\n }\n\n vhdx_log_data_le_import(data);\n\n }\n\n\n\n ret = vhdx_log_flush_desc(bs, &desc_entries->desc[i], data);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n }\n\n if (bdrv_getlength(bs->file->bs) < desc_entries->hdr.last_file_offset) {\n\n new_file_size = desc_entries->hdr.last_file_offset;\n\n if (new_file_size % (1024*1024)) {\n\n /* round up to nearest 1MB boundary */\n\n new_file_size = ((new_file_size >> 20) + 1) << 20;\n\n bdrv_truncate(bs->file, new_file_size, PREALLOC_MODE_OFF, NULL);\n\n }\n\n }\n\n qemu_vfree(desc_entries);\n\n desc_entries = NULL;\n\n }\n\n\n\n bdrv_flush(bs);\n\n /* once the log is fully flushed, indicate that we have an empty log\n\n * now. This also sets the log guid to 0, to indicate an empty log */\n\n vhdx_log_reset(bs, s);\n\n\n\nexit:\n\n qemu_vfree(data);\n\n qemu_vfree(desc_entries);\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "3f910692c287e1c611c00e763ebeb95ed0e017f8", + "length": 676 + }, + { + "index": 16042, + "code": "int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,\n\n int byterange_mode,\n\n double duration, int round_duration,\n\n int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set\n\n char *baseurl, //Ignored if NULL\n\n char *filename, double *prog_date_time) {\n\n if (!out || !filename)\n\n return AVERROR(EINVAL);\n\n\n\n if (insert_discont) {\n\n avio_printf(out, \"#EXT-X-DISCONTINUITY\\n\");\n\n }\n\n if (round_duration)\n\n avio_printf(out, \"#EXTINF:%ld,\\n\", lrint(duration));\n\n else\n\n avio_printf(out, \"#EXTINF:%f,\\n\", duration);\n\n if (byterange_mode)\n\n avio_printf(out, \"#EXT-X-BYTERANGE:%\"PRId64\"@%\"PRId64\"\\n\", size, pos);\n\n\n\n if (prog_date_time) {\n\n time_t tt, wrongsecs;\n\n int milli;\n\n struct tm *tm, tmpbuf;\n\n char buf0[128], buf1[128];\n\n tt = (int64_t)*prog_date_time;\n\n milli = av_clip(lrint(1000*(*prog_date_time - tt)), 0, 999);\n\n tm = localtime_r(&tt, &tmpbuf);\n\n strftime(buf0, sizeof(buf0), \"%Y-%m-%dT%H:%M:%S\", tm);\n\n if (!strftime(buf1, sizeof(buf1), \"%z\", tm) || buf1[1]<'0' ||buf1[1]>'2') {\n\n int tz_min, dst = tm->tm_isdst;\n\n tm = gmtime_r(&tt, &tmpbuf);\n\n tm->tm_isdst = dst;\n\n wrongsecs = mktime(tm);\n\n tz_min = (FFABS(wrongsecs - tt) + 30) / 60;\n\n snprintf(buf1, sizeof(buf1),\n\n \"%c%02d%02d\",\n\n wrongsecs <= tt ? '+' : '-',\n\n tz_min / 60,\n\n tz_min % 60);\n\n }\n\n avio_printf(out, \"#EXT-X-PROGRAM-DATE-TIME:%s.%03d%s\\n\", buf0, milli, buf1);\n\n *prog_date_time += duration;\n\n }\n\n if (baseurl)\n\n avio_printf(out, \"%s\", baseurl);\n\n avio_printf(out, \"%s\\n\", filename);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "ad6946b8189e5e17796f1d5bf86d97ee619009b8", + "length": 535 + }, + { + "index": 4861, + "code": "static int advanced_decode_picture_primary_header(VC9Context *v)\n\n{\n\n GetBitContext *gb = &v->s.gb;\n\n static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };\n\n int type, i;\n\n\n\n if (v->interlace)\n\n {\n\n v->fcm = get_bits(gb, 1);\n\n if (v->fcm) v->fcm = 2+get_bits(gb, 1);\n\n }\n\n\n\n type = get_prefix(gb, 0, 4);\n\n if (type > 4 || type < 0) return FRAME_SKIPED;\n\n v->s.pict_type = type_table[type];\n\n av_log(v->s.avctx, AV_LOG_INFO, \"AP Frame Type: %i\\n\", v->s.pict_type);\n\n\n\n if (v->tfcntrflag) v->tfcntr = get_bits(gb, 8);\n\n if (v->broadcast)\n\n {\n\n if (!v->interlace) v->rptfrm = get_bits(gb, 2);\n\n else\n\n {\n\n v->tff = get_bits(gb, 1);\n\n v->rff = get_bits(gb, 1);\n\n }\n\n }\n\n\n\n if (v->panscanflag)\n\n {\n\n#if 0\n\n for (i=0; inumpanscanwin; i++)\n\n {\n\n v->topleftx[i] = get_bits(gb, 16);\n\n v->toplefty[i] = get_bits(gb, 16);\n\n v->bottomrightx[i] = get_bits(gb, 16);\n\n v->bottomrighty[i] = get_bits(gb, 16);\n\n }\n\n#else\n\n skip_bits(gb, 16*4*v->numpanscanwin);\n\n#endif\n\n }\n\n v->s.no_rounding = !get_bits(gb, 1);\n\n v->uvsamp = get_bits(gb, 1);\n\n if (v->finterpflag == 1) v->interpfrm = get_bits(gb, 1);\n\n\n\n switch(v->s.pict_type)\n\n {\n\n case I_TYPE: if (decode_i_picture_header(v) < 0) return -1;\n\n case P_TYPE: if (decode_p_picture_primary_header(v) < 0) return -1;\n\n case BI_TYPE:\n\n case B_TYPE: if (decode_b_picture_primary_header(v) < 0) return FRAME_SKIPED;\n\n default: break;\n\n }\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "bf2bc926f04dcdde0a22c137d08a0bb546e0179e", + "length": 556 + }, + { + "index": 22302, + "code": "static int h264_set_parameter_from_sps(H264Context *h)\n{\n if (h->flags & CODEC_FLAG_LOW_DELAY ||\n (h->sps.bitstream_restriction_flag &&\n !h->sps.num_reorder_frames)) {\n if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])\n av_log(h->avctx, AV_LOG_WARNING, \"Delayed frames seen. \"\n \"Reenabling low delay requires a codec flush.\\n\");\n else\n h->low_delay = 1;\n if (h->avctx->has_b_frames < 2)\n h->avctx->has_b_frames = !h->low_delay;\n if (h->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||\n h->cur_chroma_format_idc != h->sps.chroma_format_idc) {\n if (h->avctx->codec &&\n h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU &&\n (h->sps.bit_depth_luma != 8 || h->sps.chroma_format_idc > 1)) {\n av_log(h->avctx, AV_LOG_ERROR,\n \"VDPAU decoding does not support video colorspace.\\n\");\n return AVERROR_INVALIDDATA;\n if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {\n h->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;\n h->cur_chroma_format_idc = h->sps.chroma_format_idc;\n h->pixel_shift = h->sps.bit_depth_luma > 8;\n ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma,\n h->sps.chroma_format_idc);\n ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma);\n ff_h264qpel_init(&h->h264qpel, h->sps.bit_depth_luma);\n ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma,\n h->sps.chroma_format_idc);\n h->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;\n ff_dsputil_init(&h->dsp, h->avctx);\n ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma);\n } else {\n av_log(h->avctx, AV_LOG_ERROR, \"Unsupported bit depth: %d\\n\",\n h->sps.bit_depth_luma);\n return AVERROR_INVALIDDATA;\n return 0;", + "label": 1, + "project": "FFmpeg", + "commit_id": "4987faee78b9869f8f4646b8dd971d459df218a5", + "length": 609 + }, + { + "index": 6146, + "code": "static void vga_reset(void *opaque)\n\n{\n\n VGAState *s = (VGAState *) opaque;\n\n\n\n s->lfb_addr = 0;\n\n s->lfb_end = 0;\n\n s->map_addr = 0;\n\n s->map_end = 0;\n\n s->lfb_vram_mapped = 0;\n\n s->bios_offset = 0;\n\n s->bios_size = 0;\n\n s->sr_index = 0;\n\n memset(s->sr, '\\0', sizeof(s->sr));\n\n s->gr_index = 0;\n\n memset(s->gr, '\\0', sizeof(s->gr));\n\n s->ar_index = 0;\n\n memset(s->ar, '\\0', sizeof(s->ar));\n\n s->ar_flip_flop = 0;\n\n s->cr_index = 0;\n\n memset(s->cr, '\\0', sizeof(s->cr));\n\n s->msr = 0;\n\n s->fcr = 0;\n\n s->st00 = 0;\n\n s->st01 = 0;\n\n s->dac_state = 0;\n\n s->dac_sub_index = 0;\n\n s->dac_read_index = 0;\n\n s->dac_write_index = 0;\n\n memset(s->dac_cache, '\\0', sizeof(s->dac_cache));\n\n s->dac_8bit = 0;\n\n memset(s->palette, '\\0', sizeof(s->palette));\n\n s->bank_offset = 0;\n\n#ifdef CONFIG_BOCHS_VBE\n\n s->vbe_index = 0;\n\n memset(s->vbe_regs, '\\0', sizeof(s->vbe_regs));\n\n s->vbe_regs[VBE_DISPI_INDEX_ID] = VBE_DISPI_ID0;\n\n s->vbe_start_addr = 0;\n\n s->vbe_line_offset = 0;\n\n s->vbe_bank_mask = (s->vram_size >> 16) - 1;\n\n#endif\n\n memset(s->font_offsets, '\\0', sizeof(s->font_offsets));\n\n s->graphic_mode = -1; /* force full update */\n\n s->shift_control = 0;\n\n s->double_scan = 0;\n\n s->line_offset = 0;\n\n s->line_compare = 0;\n\n s->start_addr = 0;\n\n s->plane_updated = 0;\n\n s->last_cw = 0;\n\n s->last_ch = 0;\n\n s->last_width = 0;\n\n s->last_height = 0;\n\n s->last_scr_width = 0;\n\n s->last_scr_height = 0;\n\n s->cursor_start = 0;\n\n s->cursor_end = 0;\n\n s->cursor_offset = 0;\n\n memset(s->invalidated_y_table, '\\0', sizeof(s->invalidated_y_table));\n\n memset(s->last_palette, '\\0', sizeof(s->last_palette));\n\n memset(s->last_ch_attr, '\\0', sizeof(s->last_ch_attr));\n\n switch (vga_retrace_method) {\n\n case VGA_RETRACE_DUMB:\n\n break;\n\n case VGA_RETRACE_PRECISE:\n\n memset(&s->retrace_info, 0, sizeof (s->retrace_info));\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "4abc796d41ee01a698032e74ac17c1cdc5d290c3", + "length": 701 + }, + { + "index": 395, + "code": "static int fourxm_read_packet(AVFormatContext *s,\n\n AVPacket *pkt)\n\n{\n\n FourxmDemuxContext *fourxm = s->priv_data;\n\n ByteIOContext *pb = &s->pb;\n\n unsigned int fourcc_tag;\n\n unsigned int size, out_size;\n\n int ret = 0;\n\n int track_number;\n\n int packet_read = 0;\n\n unsigned char header[8];\n\n int64_t pts_inc;\n\n int audio_frame_count;\n\n\n\n while (!packet_read) {\n\n\n\n if ((ret = get_buffer(&s->pb, header, 8)) < 0)\n\n return ret;\n\n fourcc_tag = LE_32(&header[0]);\n\n size = LE_32(&header[4]);\n\n if (url_feof(pb))\n\n return AVERROR_IO;\n\n switch (fourcc_tag) {\n\n\n\n case LIST_TAG:\n\n /* this is a good time to bump the video pts */\n\n fourxm->video_pts += fourxm->video_pts_inc;\n\n\n\n /* skip the LIST-* tag and move on to the next fourcc */\n\n get_le32(pb);\n\n break;\n\n\n\n case ifrm_TAG:\n\n case pfrm_TAG:\n\n case cfrm_TAG:{\n\n\n\n /* allocate 8 more bytes than 'size' to account for fourcc\n\n * and size */\n\n if (av_new_packet(pkt, size + 8))\n\n return AVERROR_IO;\n\n pkt->stream_index = fourxm->video_stream_index;\n\n pkt->pts = fourxm->video_pts;\n\n memcpy(pkt->data, header, 8);\n\n ret = get_buffer(&s->pb, &pkt->data[8], size);\n\n\n\n if (ret < 0)\n\n av_free_packet(pkt);\n\n else\n\n packet_read = 1;\n\n break;\n\n }\n\n\n\n case snd__TAG:\n\n track_number = get_le32(pb);\n\n out_size= get_le32(pb);\n\n size-=8;\n\n\n\n if (track_number == fourxm->selected_track) {\n\n if (av_new_packet(pkt, size))\n\n return AVERROR_IO;\n\n pkt->stream_index = \n\n fourxm->tracks[fourxm->selected_track].stream_index;\n\n pkt->pts = fourxm->audio_pts;\n\n ret = get_buffer(&s->pb, pkt->data, size);\n\n if (ret < 0)\n\n av_free_packet(pkt);\n\n else\n\n packet_read = 1;\n\n\n\n /* pts accounting */\n\n audio_frame_count = size;\n\n if (fourxm->tracks[fourxm->selected_track].adpcm)\n\n audio_frame_count -= \n\n 2 * (fourxm->tracks[fourxm->selected_track].channels);\n\n audio_frame_count /=\n\n fourxm->tracks[fourxm->selected_track].channels;\n\n if (fourxm->tracks[fourxm->selected_track].adpcm)\n\n audio_frame_count *= 2;\n\n else \n\n audio_frame_count /=\n\n (fourxm->tracks[fourxm->selected_track].bits / 8);\n\n pts_inc = audio_frame_count;\n\n pts_inc *= 90000;\n\n pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;\n\n fourxm->audio_pts += pts_inc;\n\n\n\n } else {\n\n url_fseek(pb, size, SEEK_CUR);\n\n }\n\n break;\n\n\n\n default:\n\n url_fseek(pb, size, SEEK_CUR);\n\n break;\n\n }\n\n }\n\n return ret;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "0ecca7a49f8e254c12a3a1de048d738bfbb614c6", + "length": 727 + }, + { + "index": 9286, + "code": "static int decode_band(IVI45DecContext *ctx,\n\n IVIBandDesc *band, AVCodecContext *avctx)\n\n{\n\n int result, i, t, idx1, idx2, pos;\n\n IVITile *tile;\n\n\n\n band->buf = band->bufs[ctx->dst_buf];\n\n if (!band->buf) {\n\n av_log(avctx, AV_LOG_ERROR, \"Band buffer points to no data!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n band->ref_buf = band->bufs[ctx->ref_buf];\n\n band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);\n\n\n\n result = ctx->decode_band_hdr(ctx, band, avctx);\n\n if (result) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error while decoding band header: %d\\n\",\n\n result);\n\n return result;\n\n }\n\n\n\n if (band->is_empty) {\n\n av_log(avctx, AV_LOG_ERROR, \"Empty band encountered!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel];\n\n\n\n /* apply corrections to the selected rvmap table if present */\n\n for (i = 0; i < band->num_corr; i++) {\n\n idx1 = band->corr[i * 2];\n\n idx2 = band->corr[i * 2 + 1];\n\n FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);\n\n FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);\n\n }\n\n\n\n pos = get_bits_count(&ctx->gb);\n\n\n\n for (t = 0; t < band->num_tiles; t++) {\n\n tile = &band->tiles[t];\n\n\n\n if (tile->mb_size != band->mb_size) {\n\n av_log(avctx, AV_LOG_ERROR, \"MB sizes mismatch: %d vs. %d\\n\",\n\n band->mb_size, tile->mb_size);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n tile->is_empty = get_bits1(&ctx->gb);\n\n if (tile->is_empty) {\n\n result = ivi_process_empty_tile(avctx, band, tile,\n\n (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));\n\n if (result < 0)\n\n break;\n\n av_dlog(avctx, \"Empty tile encountered!\\n\");\n\n } else {\n\n tile->data_size = ivi_dec_tile_data_size(&ctx->gb);\n\n if (!tile->data_size) {\n\n av_log(avctx, AV_LOG_ERROR, \"Tile data size is zero!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n result = ctx->decode_mb_info(ctx, band, tile, avctx);\n\n if (result < 0)\n\n break;\n\n\n\n result = ivi_decode_blocks(&ctx->gb, band, tile, avctx);\n\n if (result < 0 || ((get_bits_count(&ctx->gb) - pos) >> 3) != tile->data_size) {\n\n av_log(avctx, AV_LOG_ERROR, \"Corrupted tile data encountered!\\n\");\n\n break;\n\n }\n\n\n\n pos += tile->data_size << 3; // skip to next tile\n\n }\n\n }\n\n\n\n /* restore the selected rvmap table by applying its corrections in reverse order */\n\n for (i = band->num_corr-1; i >= 0; i--) {\n\n idx1 = band->corr[i*2];\n\n idx2 = band->corr[i*2+1];\n\n FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);\n\n FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);\n\n }\n\n\n\n#ifdef DEBUG\n\n if (band->checksum_present) {\n\n uint16_t chksum = ivi_calc_band_checksum(band);\n\n if (chksum != band->checksum) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\\n\",\n\n band->plane, band->band_num, band->checksum, chksum);\n\n }\n\n }\n\n#endif\n\n\n\n align_get_bits(&ctx->gb);\n\n\n\n return result;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "7388c0c58601477db076e2e74e8b11f8a644384a", + "length": 974 + }, + { + "index": 6898, + "code": "static int copy_cell(Indeo3DecodeContext *ctx, Plane *plane, Cell *cell)\n\n{\n\n int h, w, mv_x, mv_y, offset, offset_dst;\n\n uint8_t *src, *dst;\n\n\n\n /* setup output and reference pointers */\n\n offset_dst = (cell->ypos << 2) * plane->pitch + (cell->xpos << 2);\n\n dst = plane->pixels[ctx->buf_sel] + offset_dst;\n\n mv_y = cell->mv_ptr[0];\n\n mv_x = cell->mv_ptr[1];\n\n\n\n /* -1 because there is an extra line on top for prediction */\n\n if ((cell->ypos << 2) + mv_y < -1 || (cell->xpos << 2) + mv_x < 0 ||\n\n ((cell->ypos + cell->height) << 2) + mv_y >= plane->height ||\n\n ((cell->xpos + cell->width) << 2) + mv_x >= plane->width) {\n\n av_log(ctx->avctx, AV_LOG_ERROR,\n\n \"Motion vectors point out of the frame.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n offset = offset_dst + mv_y * plane->pitch + mv_x;\n\n src = plane->pixels[ctx->buf_sel ^ 1] + offset;\n\n\n\n h = cell->height << 2;\n\n\n\n for (w = cell->width; w > 0;) {\n\n /* copy using 16xH blocks */\n\n if (!((cell->xpos << 2) & 15) && w >= 4) {\n\n for (; w >= 4; src += 16, dst += 16, w -= 4)\n\n ctx->hdsp.put_no_rnd_pixels_tab[0][0](dst, src, plane->pitch, h);\n\n }\n\n\n\n /* copy using 8xH blocks */\n\n if (!((cell->xpos << 2) & 7) && w >= 2) {\n\n ctx->hdsp.put_no_rnd_pixels_tab[1][0](dst, src, plane->pitch, h);\n\n w -= 2;\n\n src += 8;\n\n dst += 8;\n\n }\n\n\n\n if (w >= 1) {\n\n ctx->hdsp.put_no_rnd_pixels_tab[2][0](dst, src, plane->pitch, h);\n\n w--;\n\n src += 4;\n\n dst += 4;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "95220be1faac628d849a004644c0d102df0aa98b", + "length": 544 + }, + { + "index": 16353, + "code": "static int aiff_read_header(AVFormatContext *s,\n\n AVFormatParameters *ap)\n\n{\n\n int size, filesize;\n\n offset_t offset = 0;\n\n uint32_t tag;\n\n unsigned version = AIFF_C_VERSION1;\n\n ByteIOContext *pb = s->pb;\n\n AVStream * st = s->streams[0];\n\n\n\n /* check FORM header */\n\n filesize = get_tag(pb, &tag);\n\n if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))\n\n return AVERROR_INVALIDDATA;\n\n\n\n /* AIFF data type */\n\n tag = get_le32(pb);\n\n if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */\n\n version = AIFF;\n\n else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */\n\n return AVERROR_INVALIDDATA;\n\n\n\n filesize -= 4;\n\n\n\n st = av_new_stream(s, 0);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n while (filesize > 0) {\n\n /* parse different chunks */\n\n size = get_tag(pb, &tag);\n\n if (size < 0)\n\n return size;\n\n\n\n filesize -= size + 8;\n\n\n\n switch (tag) {\n\n case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */\n\n /* Then for the complete header info */\n\n st->nb_frames = get_aiff_header (pb, st->codec, size, version);\n\n if (st->nb_frames < 0)\n\n return st->nb_frames;\n\n if (offset > 0) // COMM is after SSND\n\n goto got_sound;\n\n break;\n\n case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */\n\n version = get_be32(pb);\n\n break;\n\n case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */\n\n get_meta (pb, s->title, sizeof(s->title), size);\n\n break;\n\n case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */\n\n get_meta (pb, s->author, sizeof(s->author), size);\n\n break;\n\n case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */\n\n get_meta (pb, s->copyright, sizeof(s->copyright), size);\n\n break;\n\n case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */\n\n get_meta (pb, s->comment, sizeof(s->comment), size);\n\n break;\n\n case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */\n\n offset = get_be32(pb); /* Offset of sound data */\n\n get_be32(pb); /* BlockSize... don't care */\n\n offset += url_ftell(pb); /* Compute absolute data offset */\n\n if (st->codec->codec_id) /* Assume COMM already parsed */\n\n goto got_sound;\n\n if (url_is_streamed(pb)) {\n\n av_log(s, AV_LOG_ERROR, \"file is not seekable\\n\");\n\n\n }\n\n url_fskip(pb, size - 8);\n\n break;\n\n case MKTAG('w', 'a', 'v', 'e'):\n\n\n\n st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata)\n\n return AVERROR(ENOMEM);\n\n st->codec->extradata_size = size;\n\n get_buffer(pb, st->codec->extradata, size);\n\n break;\n\n default: /* Jump */\n\n if (size & 1) /* Always even aligned */\n\n size++;\n\n url_fskip (pb, size);\n\n }\n\n }\n\n\n\n /* End of loop and didn't get sound */\n\n return AVERROR_INVALIDDATA;\n\n\n\ngot_sound:\n\n /* Now positioned, get the sound data start and end */\n\n if (st->nb_frames)\n\n s->file_size = st->nb_frames * st->codec->block_align;\n\n\n\n av_set_pts_info(st, 64, 1, st->codec->sample_rate);\n\n st->start_time = 0;\n\n st->duration = st->codec->frame_size ?\n\n st->nb_frames * st->codec->frame_size : st->nb_frames;\n\n\n\n /* Position the stream at the first block */\n\n url_fseek(pb, offset, SEEK_SET);\n\n\n\n return 0;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "9c7fd997f794d3180ef4cbde019e4827ff309988", + "length": 970 + }, + { + "index": 16762, + "code": "static int dmg_open(BlockDriverState *bs, int flags)\n\n{\n\n BDRVDMGState *s = bs->opaque;\n\n off_t info_begin,info_end,last_in_offset,last_out_offset;\n\n uint32_t count;\n\n uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;\n\n int64_t offset;\n\n\n\n bs->read_only = 1;\n\n s->n_chunks = 0;\n\n s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;\n\n\n\n /* read offset of info blocks */\n\n offset = bdrv_getlength(bs->file);\n\n if (offset < 0) {\n\n goto fail;\n\n }\n\n offset -= 0x1d8;\n\n\n\n info_begin = read_off(bs, offset);\n\n if (info_begin == 0) {\n\n\tgoto fail;\n\n }\n\n\n\n if (read_uint32(bs, info_begin) != 0x100) {\n\n goto fail;\n\n }\n\n\n\n count = read_uint32(bs, info_begin + 4);\n\n if (count == 0) {\n\n goto fail;\n\n }\n\n info_end = info_begin + count;\n\n\n\n offset = info_begin + 0x100;\n\n\n\n /* read offsets */\n\n last_in_offset = last_out_offset = 0;\n\n while (offset < info_end) {\n\n uint32_t type;\n\n\n\n\tcount = read_uint32(bs, offset);\n\n\tif(count==0)\n\n\t goto fail;\n\n offset += 4;\n\n\n\n\ttype = read_uint32(bs, offset);\n\n\tif (type == 0x6d697368 && count >= 244) {\n\n\t int new_size, chunk_count;\n\n\n\n offset += 4;\n\n offset += 200;\n\n\n\n\t chunk_count = (count-204)/40;\n\n\t new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);\n\n\t s->types = g_realloc(s->types, new_size/2);\n\n\t s->offsets = g_realloc(s->offsets, new_size);\n\n\t s->lengths = g_realloc(s->lengths, new_size);\n\n\t s->sectors = g_realloc(s->sectors, new_size);\n\n\t s->sectorcounts = g_realloc(s->sectorcounts, new_size);\n\n\n\n\t for(i=s->n_chunks;in_chunks+chunk_count;i++) {\n\n\t\ts->types[i] = read_uint32(bs, offset);\n\n\t\toffset += 4;\n\n\t\tif(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {\n\n\t\t if(s->types[i]==0xffffffff) {\n\n\t\t\tlast_in_offset = s->offsets[i-1]+s->lengths[i-1];\n\n\t\t\tlast_out_offset = s->sectors[i-1]+s->sectorcounts[i-1];\n\n\t\t }\n\n\t\t chunk_count--;\n\n\t\t i--;\n\n\t\t offset += 36;\n\n\t\t continue;\n\n\t\t}\n\n\t\toffset += 4;\n\n\n\n\t\ts->sectors[i] = last_out_offset+read_off(bs, offset);\n\n\t\toffset += 8;\n\n\n\n\t\ts->sectorcounts[i] = read_off(bs, offset);\n\n\t\toffset += 8;\n\n\n\n\t\ts->offsets[i] = last_in_offset+read_off(bs, offset);\n\n\t\toffset += 8;\n\n\n\n\t\ts->lengths[i] = read_off(bs, offset);\n\n\t\toffset += 8;\n\n\n\n\t\tif(s->lengths[i]>max_compressed_size)\n\n\t\t max_compressed_size = s->lengths[i];\n\n\t\tif(s->sectorcounts[i]>max_sectors_per_chunk)\n\n\t\t max_sectors_per_chunk = s->sectorcounts[i];\n\n\t }\n\n\t s->n_chunks+=chunk_count;\n\n\t}\n\n }\n\n\n\n /* initialize zlib engine */\n\n s->compressed_chunk = g_malloc(max_compressed_size+1);\n\n s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk);\n\n if(inflateInit(&s->zstream) != Z_OK)\n\n\tgoto fail;\n\n\n\n s->current_chunk = s->n_chunks;\n\n\n\n qemu_co_mutex_init(&s->lock);\n\n return 0;\n\nfail:\n\n return -1;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "69d34a360dfe773e17e72c76d15931c9b9d190f6", + "length": 867 + }, + { + "index": 2450, + "code": "void ff_mdct_calcw_c(FFTContext *s, FFTDouble *out, const FFTSample *input)\n\n{\n\n int i, j, n, n8, n4, n2, n3;\n\n FFTDouble re, im;\n\n const uint16_t *revtab = s->revtab;\n\n const FFTSample *tcos = s->tcos;\n\n const FFTSample *tsin = s->tsin;\n\n FFTComplex *x = s->tmp_buf;\n\n FFTDComplex *o = (FFTDComplex *)out;\n\n\n\n n = 1 << s->mdct_bits;\n\n n2 = n >> 1;\n\n n4 = n >> 2;\n\n n8 = n >> 3;\n\n n3 = 3 * n4;\n\n\n\n /* pre rotation */\n\n for(i=0;ifft_calc(s, x);\n\n\n\n /* post rotation */\n\n for(i=0;iavctx, AV_LOG_ERROR, \"Reserved bit set.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n ics->window_sequence[1] = ics->window_sequence[0];\n\n ics->window_sequence[0] = get_bits(gb, 2);\n\n ics->use_kb_window[1] = ics->use_kb_window[0];\n\n ics->use_kb_window[0] = get_bits1(gb);\n\n ics->num_window_groups = 1;\n\n ics->group_len[0] = 1;\n\n if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {\n\n int i;\n\n ics->max_sfb = get_bits(gb, 4);\n\n for (i = 0; i < 7; i++) {\n\n if (get_bits1(gb)) {\n\n ics->group_len[ics->num_window_groups - 1]++;\n\n } else {\n\n ics->num_window_groups++;\n\n ics->group_len[ics->num_window_groups - 1] = 1;\n\n }\n\n }\n\n ics->num_windows = 8;\n\n ics->swb_offset = ff_swb_offset_128[ac->m4ac.sampling_index];\n\n ics->num_swb = ff_aac_num_swb_128[ac->m4ac.sampling_index];\n\n ics->tns_max_bands = ff_tns_max_bands_128[ac->m4ac.sampling_index];\n\n ics->predictor_present = 0;\n\n } else {\n\n ics->max_sfb = get_bits(gb, 6);\n\n ics->num_windows = 1;\n\n ics->swb_offset = ff_swb_offset_1024[ac->m4ac.sampling_index];\n\n ics->num_swb = ff_aac_num_swb_1024[ac->m4ac.sampling_index];\n\n ics->tns_max_bands = ff_tns_max_bands_1024[ac->m4ac.sampling_index];\n\n ics->predictor_present = get_bits1(gb);\n\n ics->predictor_reset_group = 0;\n\n if (ics->predictor_present) {\n\n if (ac->m4ac.object_type == AOT_AAC_MAIN) {\n\n if (decode_prediction(ac, ics, gb)) {\n\n return AVERROR_INVALIDDATA;\n\n }\n\n } else if (ac->m4ac.object_type == AOT_AAC_LC) {\n\n av_log(ac->avctx, AV_LOG_ERROR, \"Prediction is not allowed in AAC-LC.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n } else {\n\n if ((ics->ltp.present = get_bits(gb, 1)))\n\n decode_ltp(ac, &ics->ltp, gb, ics->max_sfb);\n\n }\n\n }\n\n }\n\n\n\n if (ics->max_sfb > ics->num_swb) {\n\n av_log(ac->avctx, AV_LOG_ERROR,\n\n \"Number of scalefactor bands in group (%d) exceeds limit (%d).\\n\",\n\n ics->max_sfb, ics->num_swb);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "5a4af049b1a84ee09aba3745678797fce82c4a1e", + "length": 760 + }, + { + "index": 10760, + "code": "static int read_f(BlockBackend *blk, int argc, char **argv)\n\n{\n\n struct timeval t1, t2;\n\n bool Cflag = false, qflag = false, vflag = false;\n\n bool Pflag = false, sflag = false, lflag = false, bflag = false;\n\n int c, cnt;\n\n char *buf;\n\n int64_t offset;\n\n int64_t count;\n\n /* Some compilers get confused and warn if this is not initialized. */\n\n int64_t total = 0;\n\n int pattern = 0;\n\n int64_t pattern_offset = 0, pattern_count = 0;\n\n\n\n while ((c = getopt(argc, argv, \"bCl:pP:qs:v\")) != -1) {\n\n switch (c) {\n\n case 'b':\n\n bflag = true;\n\n break;\n\n case 'C':\n\n Cflag = true;\n\n break;\n\n case 'l':\n\n lflag = true;\n\n pattern_count = cvtnum(optarg);\n\n if (pattern_count < 0) {\n\n print_cvtnum_err(pattern_count, optarg);\n\n return 0;\n\n }\n\n break;\n\n case 'p':\n\n /* Ignored for backwards compatibility */\n\n break;\n\n case 'P':\n\n Pflag = true;\n\n pattern = parse_pattern(optarg);\n\n if (pattern < 0) {\n\n return 0;\n\n }\n\n break;\n\n case 'q':\n\n qflag = true;\n\n break;\n\n case 's':\n\n sflag = true;\n\n pattern_offset = cvtnum(optarg);\n\n if (pattern_offset < 0) {\n\n print_cvtnum_err(pattern_offset, optarg);\n\n return 0;\n\n }\n\n break;\n\n case 'v':\n\n vflag = true;\n\n break;\n\n default:\n\n return qemuio_command_usage(&read_cmd);\n\n }\n\n }\n\n\n\n if (optind != argc - 2) {\n\n return qemuio_command_usage(&read_cmd);\n\n }\n\n\n\n offset = cvtnum(argv[optind]);\n\n if (offset < 0) {\n\n print_cvtnum_err(offset, argv[optind]);\n\n return 0;\n\n }\n\n\n\n optind++;\n\n count = cvtnum(argv[optind]);\n\n if (count < 0) {\n\n print_cvtnum_err(count, argv[optind]);\n\n return 0;\n\n } else if (count > SIZE_MAX) {\n\n printf(\"length cannot exceed %\" PRIu64 \", given %s\\n\",\n\n (uint64_t) SIZE_MAX, argv[optind]);\n\n return 0;\n\n }\n\n\n\n if (!Pflag && (lflag || sflag)) {\n\n return qemuio_command_usage(&read_cmd);\n\n }\n\n\n\n if (!lflag) {\n\n pattern_count = count - pattern_offset;\n\n }\n\n\n\n if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {\n\n printf(\"pattern verification range exceeds end of read data\\n\");\n\n return 0;\n\n }\n\n\n\n if (bflag) {\n\n if (offset & 0x1ff) {\n\n printf(\"offset %\" PRId64 \" is not sector aligned\\n\",\n\n offset);\n\n return 0;\n\n }\n\n if (count & 0x1ff) {\n\n printf(\"count %\"PRId64\" is not sector aligned\\n\",\n\n count);\n\n return 0;\n\n }\n\n }\n\n\n\n buf = qemu_io_alloc(blk, count, 0xab);\n\n\n\n gettimeofday(&t1, NULL);\n\n if (bflag) {\n\n cnt = do_load_vmstate(blk, buf, offset, count, &total);\n\n } else {\n\n cnt = do_pread(blk, buf, offset, count, &total);\n\n }\n\n gettimeofday(&t2, NULL);\n\n\n\n if (cnt < 0) {\n\n printf(\"read failed: %s\\n\", strerror(-cnt));\n\n goto out;\n\n }\n\n\n\n if (Pflag) {\n\n void *cmp_buf = g_malloc(pattern_count);\n\n memset(cmp_buf, pattern, pattern_count);\n\n if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {\n\n printf(\"Pattern verification failed at offset %\"\n\n PRId64 \", %\"PRId64\" bytes\\n\",\n\n offset + pattern_offset, pattern_count);\n\n }\n\n g_free(cmp_buf);\n\n }\n\n\n\n if (qflag) {\n\n goto out;\n\n }\n\n\n\n if (vflag) {\n\n dump_buffer(buf, offset, count);\n\n }\n\n\n\n /* Finally, report back -- -C gives a parsable format */\n\n t2 = tsub(t2, t1);\n\n print_report(\"read\", &t2, offset, count, total, cnt, Cflag);\n\n\n\nout:\n\n qemu_io_free(buf);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "3026c4688ca80d9c5cc1606368c4a1009a6f507d", + "length": 1001 + }, + { + "index": 9421, + "code": "static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb,\n\n void *logctx)\n\n{\n\n H264PredWeightTable pwt;\n\n int slice_type_nos = s->pict_type & 3;\n\n H264ParseContext *p = s->priv_data;\n\n int list_count, ref_count[2];\n\n\n\n\n\n if (p->ps.pps->redundant_pic_cnt_present)\n\n get_ue_golomb(gb); // redundant_pic_count\n\n\n\n if (slice_type_nos == AV_PICTURE_TYPE_B)\n\n get_bits1(gb); // direct_spatial_mv_pred\n\n\n\n if (ff_h264_parse_ref_count(&list_count, ref_count, gb, p->ps.pps,\n\n slice_type_nos, p->picture_structure, logctx) < 0)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (slice_type_nos != AV_PICTURE_TYPE_I) {\n\n int list;\n\n for (list = 0; list < list_count; list++) {\n\n if (get_bits1(gb)) {\n\n int index;\n\n for (index = 0; ; index++) {\n\n unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(gb);\n\n\n\n if (reordering_of_pic_nums_idc < 3)\n\n get_ue_golomb_long(gb);\n\n else if (reordering_of_pic_nums_idc > 3) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"illegal reordering_of_pic_nums_idc %d\\n\",\n\n reordering_of_pic_nums_idc);\n\n return AVERROR_INVALIDDATA;\n\n } else\n\n break;\n\n\n\n if (index >= ref_count[list]) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"reference count %d overflow\\n\", index);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n\n\n if ((p->ps.pps->weighted_pred && slice_type_nos == AV_PICTURE_TYPE_P) ||\n\n (p->ps.pps->weighted_bipred_idc == 1 && slice_type_nos == AV_PICTURE_TYPE_B))\n\n ff_h264_pred_weight_table(gb, p->ps.sps, ref_count, slice_type_nos,\n\n &pwt, logctx);\n\n\n\n if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag\n\n int i;\n\n for (i = 0; i < MAX_MMCO_COUNT; i++) {\n\n MMCOOpcode opcode = get_ue_golomb_31(gb);\n\n if (opcode > (unsigned) MMCO_LONG) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"illegal memory management control operation %d\\n\",\n\n opcode);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (opcode == MMCO_END)\n\n return 0;\n\n else if (opcode == MMCO_RESET)\n\n return 1;\n\n\n\n if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG)\n\n get_ue_golomb_long(gb); // difference_of_pic_nums_minus1\n\n if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||\n\n opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG)\n\n get_ue_golomb_31(gb);\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "09096fb68713089a8f97c8fa24e9d7f3bb9231d5", + "length": 709 + }, + { + "index": 21269, + "code": "vnc_display_setup_auth(VncDisplay *vs,\n\n bool password,\n\n bool sasl,\n\n bool tls,\n\n bool x509)\n\n{\n\n /*\n\n * We have a choice of 3 authentication options\n\n *\n\n * 1. none\n\n * 2. vnc\n\n * 3. sasl\n\n *\n\n * The channel can be run in 2 modes\n\n *\n\n * 1. clear\n\n * 2. tls\n\n *\n\n * And TLS can use 2 types of credentials\n\n *\n\n * 1. anon\n\n * 2. x509\n\n *\n\n * We thus have 9 possible logical combinations\n\n *\n\n * 1. clear + none\n\n * 2. clear + vnc\n\n * 3. clear + sasl\n\n * 4. tls + anon + none\n\n * 5. tls + anon + vnc\n\n * 6. tls + anon + sasl\n\n * 7. tls + x509 + none\n\n * 8. tls + x509 + vnc\n\n * 9. tls + x509 + sasl\n\n *\n\n * These need to be mapped into the VNC auth schemes\n\n * in an appropriate manner. In regular VNC, all the\n\n * TLS options get mapped into VNC_AUTH_VENCRYPT\n\n * sub-auth types.\n\n */\n\n if (password) {\n\n if (tls) {\n\n vs->auth = VNC_AUTH_VENCRYPT;\n\n if (x509) {\n\n VNC_DEBUG(\"Initializing VNC server with x509 password auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_X509VNC;\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with TLS password auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_TLSVNC;\n\n }\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with password auth\\n\");\n\n vs->auth = VNC_AUTH_VNC;\n\n vs->subauth = VNC_AUTH_INVALID;\n\n }\n\n } else if (sasl) {\n\n if (tls) {\n\n vs->auth = VNC_AUTH_VENCRYPT;\n\n if (x509) {\n\n VNC_DEBUG(\"Initializing VNC server with x509 SASL auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_X509SASL;\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with TLS SASL auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_TLSSASL;\n\n }\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with SASL auth\\n\");\n\n vs->auth = VNC_AUTH_SASL;\n\n vs->subauth = VNC_AUTH_INVALID;\n\n }\n\n } else {\n\n if (tls) {\n\n vs->auth = VNC_AUTH_VENCRYPT;\n\n if (x509) {\n\n VNC_DEBUG(\"Initializing VNC server with x509 no auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_X509NONE;\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with TLS no auth\\n\");\n\n vs->subauth = VNC_AUTH_VENCRYPT_TLSNONE;\n\n }\n\n } else {\n\n VNC_DEBUG(\"Initializing VNC server with no auth\\n\");\n\n vs->auth = VNC_AUTH_NONE;\n\n vs->subauth = VNC_AUTH_INVALID;\n\n }\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "f9148c8ae7b1515776699387b4d59864f302c77d", + "length": 755 + }, + { + "index": 21941, + "code": "ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_)\n\n{\n\n NE2000State *s = qemu_get_nic_opaque(nc);\n\n int size = size_;\n\n uint8_t *p;\n\n unsigned int total_len, next, avail, len, index, mcast_idx;\n\n uint8_t buf1[60];\n\n static const uint8_t broadcast_macaddr[6] =\n\n { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\n\n\n\n#if defined(DEBUG_NE2000)\n\n printf(\"NE2000: received len=%d\\n\", size);\n\n#endif\n\n\n\n if (s->cmd & E8390_STOP || ne2000_buffer_full(s))\n\n return -1;\n\n\n\n /* XXX: check this */\n\n if (s->rxcr & 0x10) {\n\n /* promiscuous: receive all */\n\n } else {\n\n if (!memcmp(buf, broadcast_macaddr, 6)) {\n\n /* broadcast address */\n\n if (!(s->rxcr & 0x04))\n\n return size;\n\n } else if (buf[0] & 0x01) {\n\n /* multicast */\n\n if (!(s->rxcr & 0x08))\n\n return size;\n\n mcast_idx = compute_mcast_idx(buf);\n\n if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))\n\n return size;\n\n } else if (s->mem[0] == buf[0] &&\n\n s->mem[2] == buf[1] &&\n\n s->mem[4] == buf[2] &&\n\n s->mem[6] == buf[3] &&\n\n s->mem[8] == buf[4] &&\n\n s->mem[10] == buf[5]) {\n\n /* match */\n\n } else {\n\n return size;\n\n }\n\n }\n\n\n\n\n\n /* if too small buffer, then expand it */\n\n if (size < MIN_BUF_SIZE) {\n\n memcpy(buf1, buf, size);\n\n memset(buf1 + size, 0, MIN_BUF_SIZE - size);\n\n buf = buf1;\n\n size = MIN_BUF_SIZE;\n\n }\n\n\n\n index = s->curpag << 8;\n\n if (index >= NE2000_PMEM_END) {\n\n index = s->start;\n\n }\n\n /* 4 bytes for header */\n\n total_len = size + 4;\n\n /* address for next packet (4 bytes for CRC) */\n\n next = index + ((total_len + 4 + 255) & ~0xff);\n\n if (next >= s->stop)\n\n next -= (s->stop - s->start);\n\n /* prepare packet header */\n\n p = s->mem + index;\n\n s->rsr = ENRSR_RXOK; /* receive status */\n\n /* XXX: check this */\n\n if (buf[0] & 0x01)\n\n s->rsr |= ENRSR_PHY;\n\n p[0] = s->rsr;\n\n p[1] = next >> 8;\n\n p[2] = total_len;\n\n p[3] = total_len >> 8;\n\n index += 4;\n\n\n\n /* write packet data */\n\n while (size > 0) {\n\n if (index <= s->stop)\n\n avail = s->stop - index;\n\n else\n\n avail = 0;\n\n len = size;\n\n if (len > avail)\n\n len = avail;\n\n memcpy(s->mem + index, buf, len);\n\n buf += len;\n\n index += len;\n\n if (index == s->stop)\n\n index = s->start;\n\n size -= len;\n\n }\n\n s->curpag = next >> 8;\n\n\n\n /* now we can signal we have received something */\n\n s->isr |= ENISR_RX;\n\n ne2000_update_irq(s);\n\n\n\n return size_;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "737d2b3c41d59eb8f94ab7eb419b957938f24943", + "length": 847 + }, + { + "index": 7824, + "code": "static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,\n\n Error **errp)\n\n{\n\n nbd_opt_reply reply;\n\n uint32_t len;\n\n uint32_t namelen;\n\n char name[NBD_MAX_NAME_SIZE + 1];\n\n int error;\n\n\n\n if (nbd_receive_option_reply(ioc, NBD_OPT_LIST, &reply, errp) < 0) {\n\n return -1;\n\n }\n\n error = nbd_handle_reply_err(ioc, &reply, errp);\n\n if (error <= 0) {\n\n /* The server did not support NBD_OPT_LIST, so set *match on\n\n * the assumption that any name will be accepted. */\n\n *match = true;\n\n return error;\n\n }\n\n len = reply.length;\n\n\n\n if (reply.type == NBD_REP_ACK) {\n\n if (len != 0) {\n\n error_setg(errp, \"length too long for option end\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n return 0;\n\n } else if (reply.type != NBD_REP_SERVER) {\n\n error_setg(errp, \"Unexpected reply type %\" PRIx32 \" expected %x\",\n\n reply.type, NBD_REP_SERVER);\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n\n\n if (len < sizeof(namelen) || len > NBD_MAX_BUFFER_SIZE) {\n\n error_setg(errp, \"incorrect option length %\" PRIu32, len);\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n if (read_sync(ioc, &namelen, sizeof(namelen), errp) < 0) {\n\n error_prepend(errp, \"failed to read option name length\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n namelen = be32_to_cpu(namelen);\n\n len -= sizeof(namelen);\n\n if (len < namelen) {\n\n error_setg(errp, \"incorrect option name length\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n if (namelen != strlen(want)) {\n\n if (drop_sync(ioc, len, errp) < 0) {\n\n error_prepend(errp, \"failed to skip export name with wrong length\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n return 1;\n\n }\n\n\n\n assert(namelen < sizeof(name));\n\n if (read_sync(ioc, name, namelen, errp) < 0) {\n\n error_prepend(errp, \"failed to read export name\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n name[namelen] = '\\0';\n\n len -= namelen;\n\n if (drop_sync(ioc, len, errp) < 0) {\n\n error_prepend(errp, \"failed to read export description\");\n\n nbd_send_opt_abort(ioc);\n\n return -1;\n\n }\n\n if (!strcmp(name, want)) {\n\n *match = true;\n\n }\n\n return 1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d1fdf257d52822695f5ace6c586e059aa17d4b79", + "length": 677 + }, + { + "index": 17397, + "code": "static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size)\n\n{\n\n\tconst uint8_t *s = src;\n\n\tconst uint8_t *end;\n\n#ifdef HAVE_MMX\n\n\tconst uint8_t *mm_end;\n\n#endif\n\n\tuint16_t *d = (uint16_t *)dst;\n\n\tend = s + src_size;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(PREFETCH\"\t%0\"::\"m\"(*src):\"memory\");\n\n\t__asm __volatile(\n\n\t \"movq\t%0, %%mm7\\n\\t\"\n\n\t \"movq\t%1, %%mm6\\n\\t\"\n\n\t ::\"m\"(red_15mask),\"m\"(green_15mask));\n\n\tmm_end = end - 15;\n\n\twhile(s < mm_end)\n\n\t{\n\n\t __asm __volatile(\n\n\t\tPREFETCH\" 32%1\\n\\t\"\n\n\t\t\"movd\t%1, %%mm0\\n\\t\"\n\n\t\t\"movd\t3%1, %%mm3\\n\\t\"\n\n\t\t\"punpckldq 6%1, %%mm0\\n\\t\"\n\n\t\t\"punpckldq 9%1, %%mm3\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm1\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm2\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm4\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm5\\n\\t\"\n\n\t\t\"psllq\t$7, %%mm0\\n\\t\"\n\n\t\t\"psllq\t$7, %%mm3\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm0\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm3\\n\\t\"\n\n\t\t\"psrlq\t$6, %%mm1\\n\\t\"\n\n\t\t\"psrlq\t$6, %%mm4\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm1\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm4\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm2\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm5\\n\\t\"\n\n\t\t\"pand\t%2, %%mm2\\n\\t\"\n\n\t\t\"pand\t%2, %%mm5\\n\\t\"\n\n\t\t\"por\t%%mm1, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm4, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm2, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm5, %%mm3\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm3, %%mm0\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\t\t:\"=m\"(*d):\"m\"(*s),\"m\"(blue_15mask):\"memory\");\n\n\t\td += 4;\n\n\t\ts += 12;\n\n\t}\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n\twhile(s < end)\n\n\t{\n\n\t\tconst int r= *s++;\n\n\t\tconst int g= *s++;\n\n\t\tconst int b= *s++;\n\n\t\t*d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);\n\n\t}\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "7f526efd17973ec6d2204f7a47b6923e2be31363", + "length": 755 + }, + { + "index": 12192, + "code": "static int parse(AVCodecParserContext *ctx,\n\n AVCodecContext *avctx,\n\n const uint8_t **out_data, int *out_size,\n\n const uint8_t *data, int size)\n\n{\n\n VP9ParseContext *s = ctx->priv_data;\n\n int marker;\n\n\n\n if (size <= 0) {\n\n *out_size = 0;\n\n *out_data = data;\n\n\n\n return 0;\n\n }\n\n\n\n if (s->n_frames > 0) {\n\n *out_data = data;\n\n *out_size = s->size[--s->n_frames];\n\n parse_frame(ctx, *out_data, *out_size);\n\n\n\n return s->n_frames > 0 ? *out_size : size /* i.e. include idx tail */;\n\n }\n\n\n\n marker = data[size - 1];\n\n if ((marker & 0xe0) == 0xc0) {\n\n int nbytes = 1 + ((marker >> 3) & 0x3);\n\n int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;\n\n\n\n if (size >= idx_sz && data[size - idx_sz] == marker) {\n\n const uint8_t *idx = data + size + 1 - idx_sz;\n\n int first = 1;\n\n\n\n switch (nbytes) {\n\n#define case_n(a, rd) \\\n\n case a: \\\n\n while (n_frames--) { \\\n\n int sz = rd; \\\n\n idx += a; \\\n\n if (sz > size) { \\\n\n s->n_frames = 0; \\\n\n av_log(avctx, AV_LOG_ERROR, \\\n\n \"Superframe packet size too big: %d > %d\\n\", \\\n\n sz, size); \\\n\n return AVERROR_INVALIDDATA; \\\n\n } \\\n\n if (first) { \\\n\n first = 0; \\\n\n *out_data = data; \\\n\n *out_size = sz; \\\n\n s->n_frames = n_frames; \\\n\n } else { \\\n\n s->size[n_frames] = sz; \\\n\n } \\\n\n data += sz; \\\n\n size -= sz; \\\n\n } \\\n\n parse_frame(ctx, *out_data, *out_size); \\\n\n return *out_size\n\n\n\n case_n(1, *idx);\n\n case_n(2, AV_RL16(idx));\n\n case_n(3, AV_RL24(idx));\n\n case_n(4, AV_RL32(idx));\n\n }\n\n }\n\n }\n\n\n\n *out_data = data;\n\n *out_size = size;\n\n parse_frame(ctx, data, size);\n\n\n\n return size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "0065d2d520caab2321b35a7bec5d62564913238b", + "length": 559 + }, + { + "index": 13521, + "code": "static int find_smallest_bounding_rectangle(AVSubtitle *s)\n\n{\n\n uint8_t transp_color[256] = { 0 };\n\n int y1, y2, x1, x2, y, w, h, i;\n\n uint8_t *bitmap;\n\n\n\n if (s->num_rects == 0 || s->rects == NULL || s->rects[0]->w <= 0 || s->rects[0]->h <= 0)\n\n return 0;\n\n\n\n for(i = 0; i < s->rects[0]->nb_colors; i++) {\n\n if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)\n\n transp_color[i] = 1;\n\n }\n\n y1 = 0;\n\n while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],\n\n 1, s->rects[0]->w, transp_color))\n\n y1++;\n\n if (y1 == s->rects[0]->h) {\n\n av_freep(&s->rects[0]->pict.data[0]);\n\n s->rects[0]->w = s->rects[0]->h = 0;\n\n return 0;\n\n }\n\n\n\n y2 = s->rects[0]->h - 1;\n\n while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,\n\n s->rects[0]->w, transp_color))\n\n y2--;\n\n x1 = 0;\n\n while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],\n\n s->rects[0]->h, transp_color))\n\n x1++;\n\n x2 = s->rects[0]->w - 1;\n\n while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,\n\n transp_color))\n\n x2--;\n\n w = x2 - x1 + 1;\n\n h = y2 - y1 + 1;\n\n bitmap = av_malloc(w * h);\n\n if (!bitmap)\n\n return 1;\n\n for(y = 0; y < h; y++) {\n\n memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);\n\n }\n\n av_freep(&s->rects[0]->pict.data[0]);\n\n s->rects[0]->pict.data[0] = bitmap;\n\n s->rects[0]->pict.linesize[0] = w;\n\n s->rects[0]->w = w;\n\n s->rects[0]->h = h;\n\n s->rects[0]->x += x1;\n\n s->rects[0]->y += y1;\n\n return 1;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f929ab0569ff31ed5a59b0b0adb7ce09df3fca39", + "length": 764 + }, + { + "index": 11198, + "code": "void ff_xface_generate_face(uint8_t *dst, uint8_t * const src)\n\n{\n\n int h, i, j, k, l, m;\n\n\n\n for (j = 0; j < XFACE_HEIGHT; j++) {\n\n for (i = 0; i < XFACE_WIDTH; i++) {\n\n h = i + j * XFACE_WIDTH;\n\n k = 0;\n\n\n\n /*\n\n Compute k, encoding the bits *before* the current one, contained in the\n\n image buffer. That is, given the grid:\n\n\n\n l i\n\n | |\n\n v v\n\n +--+--+--+--+--+\n\n m -> | 1| 2| 3| 4| 5|\n\n +--+--+--+--+--+\n\n | 6| 7| 8| 9|10|\n\n +--+--+--+--+--+\n\n j -> |11|12| *| | |\n\n +--+--+--+--+--+\n\n\n\n the value k for the pixel marked as \"*\" will contain the bit encoding of\n\n the values in the matrix marked from \"1\" to \"12\". In case the pixel is\n\n near the border of the grid, the number of values contained within the\n\n grid will be lesser than 12.\n\n */\n\n\n\n for (l = i - 2; l <= i + 2; l++) {\n\n for (m = j - 2; m <= j; m++) {\n\n if (l >= i && m == j)\n\n continue;\n\n if (l > 0 && l <= XFACE_WIDTH && m > 0)\n\n k = 2*k + src[l + m * XFACE_WIDTH];\n\n }\n\n }\n\n\n\n /*\n\n Use the guess for the given position and the computed value of k.\n\n\n\n The following table shows the number of digits in k, depending on\n\n the position of the pixel, and shows the corresponding guess table\n\n to use:\n\n\n\n i=1 i=2 i=3 i=w-1 i=w\n\n +----+----+----+ ... +----+----+\n\n j=1 | 0 | 1 | 2 | | 2 | 2 |\n\n |g22 |g12 |g02 | |g42 |g32 |\n\n +----+----+----+ ... +----+----+\n\n j=2 | 3 | 5 | 7 | | 6 | 5 |\n\n |g21 |g11 |g01 | |g41 |g31 |\n\n +----+----+----+ ... +----+----+\n\n j=3 | 5 | 9 | 12 | | 10 | 8 |\n\n |g20 |g10 |g00 | |g40 |g30 |\n\n +----+----+----+ ... +----+----+\n\n */\n\n\n\n#define GEN(table) dst[h] ^= (table[k>>3]>>(7-(k&7)))&1\n\n\n\n switch (i) {\n\n case 1:\n\n switch (j) {\n\n case 1: GEN(g_22); break;\n\n case 2: GEN(g_21); break;\n\n default: GEN(g_20); break;\n\n }\n\n break;\n\n case 2:\n\n switch (j) {\n\n case 1: GEN(g_12); break;\n\n case 2: GEN(g_11); break;\n\n default: GEN(g_10); break;\n\n }\n\n break;\n\n case XFACE_WIDTH - 1:\n\n switch (j) {\n\n case 1: GEN(g_42); break;\n\n case 2: GEN(g_41); break;\n\n default: GEN(g_40); break;\n\n }\n\n break;\n\n case XFACE_WIDTH:\n\n switch (j) {\n\n case 1: GEN(g_32); break;\n\n case 2: GEN(g_31); break;\n\n default: GEN(g_30); break;\n\n }\n\n break;\n\n default:\n\n switch (j) {\n\n case 1: GEN(g_02); break;\n\n case 2: GEN(g_01); break;\n\n default: GEN(g_00); break;\n\n }\n\n break;\n\n }\n\n }\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "66c1c9b2774968dc26017269ac175b356592f878", + "length": 933 + }, + { + "index": 21409, + "code": "static int configure_video_filters(FilterGraph *fg)\n\n{\n\n InputStream *ist = fg->inputs[0]->ist;\n\n OutputStream *ost = fg->outputs[0]->ost;\n\n AVFilterContext *in_filter, *out_filter, *filter;\n\n AVCodecContext *codec = ost->st->codec;\n\n AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();\n\n char *pix_fmts;\n\n AVRational sample_aspect_ratio;\n\n char args[255];\n\n int ret;\n\n\n\n avfilter_graph_free(&fg->graph);\n\n fg->graph = avfilter_graph_alloc();\n\n if (!fg->graph)\n\n return AVERROR(ENOMEM);\n\n\n\n if (ist->st->sample_aspect_ratio.num) {\n\n sample_aspect_ratio = ist->st->sample_aspect_ratio;\n\n } else\n\n sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;\n\n\n\n snprintf(args, 255, \"%d:%d:%d:%d:%d:%d:%d:flags=%d\", ist->st->codec->width,\n\n ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,\n\n sample_aspect_ratio.num, sample_aspect_ratio.den, SWS_BILINEAR + ((ist->st->codec->flags&CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));\n\n\n\n ret = avfilter_graph_create_filter(&fg->inputs[0]->filter,\n\n avfilter_get_by_name(\"buffer\"),\n\n \"src\", args, NULL, fg->graph);\n\n if (ret < 0)\n\n return ret;\n\n\n\n#if FF_API_OLD_VSINK_API\n\n ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,\n\n avfilter_get_by_name(\"buffersink\"),\n\n \"out\", NULL, NULL, fg->graph);\n\n#else\n\n ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,\n\n avfilter_get_by_name(\"buffersink\"),\n\n \"out\", NULL, buffersink_params, fg->graph);\n\n#endif\n\n av_freep(&buffersink_params);\n\n\n\n if (ret < 0)\n\n return ret;\n\n in_filter = fg->inputs[0]->filter;\n\n out_filter = fg->outputs[0]->filter;\n\n\n\n if (codec->width || codec->height) {\n\n snprintf(args, 255, \"%d:%d:flags=0x%X\",\n\n codec->width,\n\n codec->height,\n\n (unsigned)ost->sws_flags);\n\n if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name(\"scale\"),\n\n NULL, args, NULL, fg->graph)) < 0)\n\n return ret;\n\n if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)\n\n return ret;\n\n in_filter = filter;\n\n }\n\n\n\n if ((pix_fmts = choose_pixel_fmts(ost))) {\n\n if ((ret = avfilter_graph_create_filter(&filter,\n\n avfilter_get_by_name(\"format\"),\n\n \"format\", pix_fmts, NULL,\n\n fg->graph)) < 0)\n\n return ret;\n\n if ((ret = avfilter_link(filter, 0, out_filter, 0)) < 0)\n\n return ret;\n\n\n\n out_filter = filter;\n\n av_freep(&pix_fmts);\n\n }\n\n\n\n snprintf(args, sizeof(args), \"flags=0x%X\", (unsigned)ost->sws_flags);\n\n fg->graph->scale_sws_opts = av_strdup(args);\n\n\n\n if (ost->avfilter) {\n\n AVFilterInOut *outputs = avfilter_inout_alloc();\n\n AVFilterInOut *inputs = avfilter_inout_alloc();\n\n\n\n outputs->name = av_strdup(\"in\");\n\n outputs->filter_ctx = in_filter;\n\n outputs->pad_idx = 0;\n\n outputs->next = NULL;\n\n\n\n inputs->name = av_strdup(\"out\");\n\n inputs->filter_ctx = out_filter;\n\n inputs->pad_idx = 0;\n\n inputs->next = NULL;\n\n\n\n if ((ret = avfilter_graph_parse(fg->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)\n\n return ret;\n\n av_freep(&ost->avfilter);\n\n } else {\n\n if ((ret = avfilter_link(in_filter, 0, out_filter, 0)) < 0)\n\n return ret;\n\n }\n\n\n\n if (ost->keep_pix_fmt)\n\n avfilter_graph_set_auto_convert(fg->graph,\n\n AVFILTER_AUTO_CONVERT_NONE);\n\n\n\n if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)\n\n return ret;\n\n\n\n ost->filter = fg->outputs[0];\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "fc49f22c3b735db5aaac5f98e40b7124a2be13b8", + "length": 1002 + }, + { + "index": 15074, + "code": "static void end_frame(AVFilterLink *inlink)\n\n{\n\n TransContext *trans = inlink->dst->priv;\n\n AVFilterBufferRef *inpic = inlink->cur_buf;\n\n AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;\n\n AVFilterLink *outlink = inlink->dst->outputs[0];\n\n int plane;\n\n\n\n for (plane = 0; outpic->data[plane]; plane++) {\n\n int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;\n\n int vsub = plane == 1 || plane == 2 ? trans->vsub : 0;\n\n int pixstep = trans->pixsteps[plane];\n\n int inh = inpic->video->h>>vsub;\n\n int outw = outpic->video->w>>hsub;\n\n int outh = outpic->video->h>>vsub;\n\n uint8_t *out, *in;\n\n int outlinesize, inlinesize;\n\n int x, y;\n\n\n\n out = outpic->data[plane]; outlinesize = outpic->linesize[plane];\n\n in = inpic ->data[plane]; inlinesize = inpic ->linesize[plane];\n\n\n\n if (trans->dir&1) {\n\n in += inpic->linesize[plane] * (inh-1);\n\n inlinesize *= -1;\n\n }\n\n\n\n if (trans->dir&2) {\n\n out += outpic->linesize[plane] * (outh-1);\n\n outlinesize *= -1;\n\n }\n\n\n\n for (y = 0; y < outh; y++) {\n\n switch (pixstep) {\n\n case 1:\n\n for (x = 0; x < outw; x++)\n\n out[x] = in[x*inlinesize + y];\n\n break;\n\n case 2:\n\n for (x = 0; x < outw; x++)\n\n *((uint16_t *)(out + 2*x)) = *((uint16_t *)(in + x*inlinesize + y*2));\n\n break;\n\n case 3:\n\n for (x = 0; x < outw; x++) {\n\n int32_t v = AV_RB24(in + x*inlinesize + y*3);\n\n AV_WB24(out + 3*x, v);\n\n }\n\n break;\n\n case 4:\n\n for (x = 0; x < outw; x++)\n\n *((uint32_t *)(out + 4*x)) = *((uint32_t *)(in + x*inlinesize + y*4));\n\n break;\n\n }\n\n out += outlinesize;\n\n }\n\n }\n\n\n\n avfilter_unref_buffer(inpic);\n\n ff_draw_slice(outlink, 0, outpic->video->h, 1);\n\n ff_end_frame(outlink);\n\n avfilter_unref_buffer(outpic);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "07bad27810cdd7d3171cbd542119aa051646377c", + "length": 636 + }, + { + "index": 10714, + "code": "static QString *qstring_from_escaped_str(JSONParserContext *ctxt, QObject *token)\n\n{\n\n const char *ptr = token_get_value(token);\n\n QString *str;\n\n int double_quote = 1;\n\n\n\n if (*ptr == '\"') {\n\n double_quote = 1;\n\n } else {\n\n double_quote = 0;\n\n }\n\n ptr++;\n\n\n\n str = qstring_new();\n\n while (*ptr && \n\n ((double_quote && *ptr != '\"') || (!double_quote && *ptr != '\\''))) {\n\n if (*ptr == '\\\\') {\n\n ptr++;\n\n\n\n switch (*ptr) {\n\n case '\"':\n\n qstring_append(str, \"\\\"\");\n\n ptr++;\n\n break;\n\n case '\\'':\n\n qstring_append(str, \"'\");\n\n ptr++;\n\n break;\n\n case '\\\\':\n\n qstring_append(str, \"\\\\\");\n\n ptr++;\n\n break;\n\n case '/':\n\n qstring_append(str, \"/\");\n\n ptr++;\n\n break;\n\n case 'b':\n\n qstring_append(str, \"\\b\");\n\n ptr++;\n\n break;\n\n case 'f':\n\n qstring_append(str, \"\\f\");\n\n ptr++;\n\n break;\n\n case 'n':\n\n qstring_append(str, \"\\n\");\n\n ptr++;\n\n break;\n\n case 'r':\n\n qstring_append(str, \"\\r\");\n\n ptr++;\n\n break;\n\n case 't':\n\n qstring_append(str, \"\\t\");\n\n ptr++;\n\n break;\n\n case 'u': {\n\n uint16_t unicode_char = 0;\n\n char utf8_char[4];\n\n int i = 0;\n\n\n\n ptr++;\n\n\n\n for (i = 0; i < 4; i++) {\n\n if (qemu_isxdigit(*ptr)) {\n\n unicode_char |= hex2decimal(*ptr) << ((3 - i) * 4);\n\n } else {\n\n parse_error(ctxt, token,\n\n \"invalid hex escape sequence in string\");\n\n goto out;\n\n }\n\n ptr++;\n\n }\n\n\n\n wchar_to_utf8(unicode_char, utf8_char, sizeof(utf8_char));\n\n qstring_append(str, utf8_char);\n\n } break;\n\n default:\n\n parse_error(ctxt, token, \"invalid escape sequence in string\");\n\n goto out;\n\n }\n\n } else {\n\n char dummy[2];\n\n\n\n dummy[0] = *ptr++;\n\n dummy[1] = 0;\n\n\n\n qstring_append(str, dummy);\n\n }\n\n }\n\n\n\n return str;\n\n\n\nout:\n\n QDECREF(str);\n\n return NULL;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "9bada8971173345ceb37ed1a47b00a01a4dd48cf", + "length": 530 + }, + { + "index": 13823, + "code": "static void imx_timerg_write(void *opaque, target_phys_addr_t offset,\n\n uint64_t value, unsigned size)\n\n{\n\n IMXTimerGState *s = (IMXTimerGState *)opaque;\n\n DPRINTF(\"g-write(offset=%x, value = 0x%x)\\n\", (unsigned int)offset >> 2,\n\n (unsigned int)value);\n\n\n\n switch (offset >> 2) {\n\n case 0: {\n\n uint32_t oldcr = s->cr;\n\n /* CR */\n\n if (value & GPT_CR_SWR) { /* force reset */\n\n value &= ~GPT_CR_SWR;\n\n imx_timerg_reset(&s->busdev.qdev);\n\n imx_timerg_update(s);\n\n }\n\n\n\n s->cr = value & ~0x7c00;\n\n imx_timerg_set_freq(s);\n\n if ((oldcr ^ value) & GPT_CR_EN) {\n\n if (value & GPT_CR_EN) {\n\n if (value & GPT_CR_ENMOD) {\n\n ptimer_set_count(s->timer, s->ocr1);\n\n s->cnt = 0;\n\n }\n\n ptimer_run(s->timer,\n\n (value & GPT_CR_FRR) && (s->ocr1 != TIMER_MAX));\n\n } else {\n\n ptimer_stop(s->timer);\n\n };\n\n }\n\n return;\n\n }\n\n\n\n case 1: /* Prescaler */\n\n s->pr = value & 0xfff;\n\n imx_timerg_set_freq(s);\n\n return;\n\n\n\n case 2: /* SR */\n\n /*\n\n * No point in implementing the status register bits to do with\n\n * external interrupt sources.\n\n */\n\n value &= GPT_SR_OF1 | GPT_SR_ROV;\n\n s->sr &= ~value;\n\n imx_timerg_update(s);\n\n return;\n\n\n\n case 3: /* IR -- interrupt register */\n\n s->ir = value & 0x3f;\n\n imx_timerg_update(s);\n\n return;\n\n\n\n case 4: /* OCR1 -- output compare register */\n\n /* In non-freerun mode, reset count when this register is written */\n\n if (!(s->cr & GPT_CR_FRR)) {\n\n s->waiting_rov = 0;\n\n ptimer_set_limit(s->timer, value, 1);\n\n } else {\n\n imx_timerg_update_counts(s);\n\n if (value > s->cnt) {\n\n s->waiting_rov = 0;\n\n imx_timerg_reload(s, value);\n\n } else {\n\n s->waiting_rov = 1;\n\n imx_timerg_reload(s, TIMER_MAX - s->cnt);\n\n }\n\n }\n\n s->ocr1 = value;\n\n return;\n\n\n\n default:\n\n IPRINTF(\"imx_timerg_write: Bad offset %x\\n\",\n\n (int)offset >> 2);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "a8170e5e97ad17ca169c64ba87ae2f53850dab4c", + "length": 615 + }, + { + "index": 14504, + "code": "static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,\n\n Error **errp)\n\n{\n\n bool is_listen = qemu_opt_get_bool(opts, \"server\", false);\n\n bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, \"wait\", true);\n\n bool is_telnet = qemu_opt_get_bool(opts, \"telnet\", false);\n\n bool is_tn3270 = qemu_opt_get_bool(opts, \"tn3270\", false);\n\n bool do_nodelay = !qemu_opt_get_bool(opts, \"delay\", true);\n\n int64_t reconnect = qemu_opt_get_number(opts, \"reconnect\", 0);\n\n const char *path = qemu_opt_get(opts, \"path\");\n\n const char *host = qemu_opt_get(opts, \"host\");\n\n const char *port = qemu_opt_get(opts, \"port\");\n\n const char *tls_creds = qemu_opt_get(opts, \"tls-creds\");\n\n SocketAddress *addr;\n\n ChardevSocket *sock;\n\n\n\n backend->type = CHARDEV_BACKEND_KIND_SOCKET;\n\n if (!path) {\n\n if (!host) {\n\n error_setg(errp, \"chardev: socket: no host given\");\n\n return;\n\n }\n\n if (!port) {\n\n error_setg(errp, \"chardev: socket: no port given\");\n\n return;\n\n }\n\n } else {\n\n if (tls_creds) {\n\n error_setg(errp, \"TLS can only be used over TCP socket\");\n\n return;\n\n }\n\n }\n\n\n\n sock = backend->u.socket.data = g_new0(ChardevSocket, 1);\n\n qemu_chr_parse_common(opts, qapi_ChardevSocket_base(sock));\n\n\n\n sock->has_nodelay = true;\n\n sock->nodelay = do_nodelay;\n\n sock->has_server = true;\n\n sock->server = is_listen;\n\n sock->has_telnet = true;\n\n sock->telnet = is_telnet;\n\n sock->has_tn3270 = true;\n\n sock->tn3270 = is_tn3270;\n\n sock->has_wait = true;\n\n sock->wait = is_waitconnect;\n\n sock->has_reconnect = true;\n\n sock->reconnect = reconnect;\n\n sock->tls_creds = g_strdup(tls_creds);\n\n\n\n addr = g_new0(SocketAddress, 1);\n\n if (path) {\n\n UnixSocketAddress *q_unix;\n\n addr->type = SOCKET_ADDRESS_KIND_UNIX;\n\n q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);\n\n q_unix->path = g_strdup(path);\n\n } else {\n\n addr->type = SOCKET_ADDRESS_KIND_INET;\n\n addr->u.inet.data = g_new(InetSocketAddress, 1);\n\n *addr->u.inet.data = (InetSocketAddress) {\n\n .host = g_strdup(host),\n\n .port = g_strdup(port),\n\n .has_to = qemu_opt_get(opts, \"to\"),\n\n .to = qemu_opt_get_number(opts, \"to\", 0),\n\n .has_ipv4 = qemu_opt_get(opts, \"ipv4\"),\n\n .ipv4 = qemu_opt_get_bool(opts, \"ipv4\", 0),\n\n .has_ipv6 = qemu_opt_get(opts, \"ipv6\"),\n\n .ipv6 = qemu_opt_get_bool(opts, \"ipv6\", 0),\n\n };\n\n }\n\n sock->addr = addr;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "dfd100f242370886bb6732f70f1f7cbd8eb9fedc", + "length": 724 + }, + { + "index": 24120, + "code": "static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom)\n\n{\n\n int64_t offset = avio_tell(pb) + atom.size, pts, timestamp;\n\n uint8_t version;\n\n unsigned i, j, track_id, item_count;\n\n AVStream *st = NULL;\n\n AVStream *ref_st = NULL;\n\n MOVStreamContext *sc, *ref_sc = NULL;\n\n AVRational timescale;\n\n\n\n version = avio_r8(pb);\n\n if (version > 1) {\n\n avpriv_request_sample(c->fc, \"sidx version %u\", version);\n\n return 0;\n\n }\n\n\n\n avio_rb24(pb); // flags\n\n\n\n track_id = avio_rb32(pb); // Reference ID\n\n for (i = 0; i < c->fc->nb_streams; i++) {\n\n if (c->fc->streams[i]->id == track_id) {\n\n st = c->fc->streams[i];\n\n break;\n\n }\n\n }\n\n if (!st) {\n\n av_log(c->fc, AV_LOG_WARNING, \"could not find corresponding track id %d\\n\", track_id);\n\n return 0;\n\n }\n\n\n\n sc = st->priv_data;\n\n\n\n timescale = av_make_q(1, avio_rb32(pb));\n\n\n\n if (timescale.den <= 0) {\n\n av_log(c->fc, AV_LOG_ERROR, \"Invalid sidx timescale 1/%d\\n\", timescale.den);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (version == 0) {\n\n pts = avio_rb32(pb);\n\n offset += avio_rb32(pb);\n\n } else {\n\n pts = avio_rb64(pb);\n\n offset += avio_rb64(pb);\n\n }\n\n\n\n avio_rb16(pb); // reserved\n\n\n\n item_count = avio_rb16(pb);\n\n\n\n for (i = 0; i < item_count; i++) {\n\n int index;\n\n MOVFragmentStreamInfo * frag_stream_info;\n\n uint32_t size = avio_rb32(pb);\n\n uint32_t duration = avio_rb32(pb);\n\n if (size & 0x80000000) {\n\n avpriv_request_sample(c->fc, \"sidx reference_type 1\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n avio_rb32(pb); // sap_flags\n\n timestamp = av_rescale_q(pts, st->time_base, timescale);\n\n\n\n index = update_frag_index(c, offset);\n\n frag_stream_info = get_frag_stream_info(&c->frag_index, index, track_id);\n\n if (frag_stream_info)\n\n frag_stream_info->sidx_pts = timestamp;\n\n\n\n offset += size;\n\n pts += duration;\n\n }\n\n\n\n st->duration = sc->track_end = pts;\n\n\n\n sc->has_sidx = 1;\n\n\n\n if (offset == avio_size(pb)) {\n\n // Find first entry in fragment index that came from an sidx.\n\n // This will pretty much always be the first entry.\n\n for (i = 0; i < c->frag_index.nb_items; i++) {\n\n MOVFragmentIndexItem * item = &c->frag_index.item[i];\n\n for (j = 0; ref_st == NULL && j < item->nb_stream_info; j++) {\n\n MOVFragmentStreamInfo * si;\n\n si = &item->stream_info[j];\n\n if (si->sidx_pts != AV_NOPTS_VALUE) {\n\n ref_st = c->fc->streams[i];\n\n ref_sc = ref_st->priv_data;\n\n break;\n\n }\n\n }\n\n }\n\n for (i = 0; i < c->fc->nb_streams; i++) {\n\n st = c->fc->streams[i];\n\n sc = st->priv_data;\n\n if (!sc->has_sidx) {\n\n st->duration = sc->track_end = av_rescale(ref_st->duration, sc->time_scale, ref_sc->time_scale);\n\n }\n\n }\n\n\n\n c->frag_index.complete = 1;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "bdddcb7b030d075dffa2989222d687106c06d50c", + "length": 863 + }, + { + "index": 21028, + "code": "static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)\n\n{\n\n int last_index = gb->size_in_bits;\n\n const uint8_t *scan_table = mb->scan_table;\n\n const uint32_t *factor_table = mb->factor_table;\n\n int pos = mb->pos;\n\n int partial_bit_count = mb->partial_bit_count;\n\n int level, run, vlc_len, index;\n\n\n\n OPEN_READER(re, gb);\n\n UPDATE_CACHE(re, gb);\n\n\n\n /* if we must parse a partial VLC, we do it here */\n\n if (partial_bit_count > 0) {\n\n re_cache = ((unsigned)re_cache >> partial_bit_count) |\n\n (mb->partial_bit_buffer << (sizeof(re_cache) * 8 - partial_bit_count));\n\n re_index -= partial_bit_count;\n\n mb->partial_bit_count = 0;\n\n }\n\n\n\n /* get the AC coefficients until last_index is reached */\n\n for (;;) {\n\n av_dlog(NULL, \"%2d: bits=%04x index=%d\\n\", pos, SHOW_UBITS(re, gb, 16),\n\n re_index);\n\n /* our own optimized GET_RL_VLC */\n\n index = NEG_USR32(re_cache, TEX_VLC_BITS);\n\n vlc_len = dv_rl_vlc[index].len;\n\n if (vlc_len < 0) {\n\n index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level;\n\n vlc_len = TEX_VLC_BITS - vlc_len;\n\n }\n\n level = dv_rl_vlc[index].level;\n\n run = dv_rl_vlc[index].run;\n\n\n\n /* gotta check if we're still within gb boundaries */\n\n if (re_index + vlc_len > last_index) {\n\n /* should be < 16 bits otherwise a codeword could have been parsed */\n\n mb->partial_bit_count = last_index - re_index;\n\n mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count);\n\n re_index = last_index;\n\n break;\n\n }\n\n re_index += vlc_len;\n\n\n\n av_dlog(NULL, \"run=%d level=%d\\n\", run, level);\n\n pos += run;\n\n if (pos >= 64)\n\n break;\n\n\n\n level = (level * factor_table[pos] + (1 << (dv_iweight_bits - 1))) >> dv_iweight_bits;\n\n block[scan_table[pos]] = level;\n\n\n\n UPDATE_CACHE(re, gb);\n\n }\n\n CLOSE_READER(re, gb);\n\n mb->pos = pos;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "b6ae0866821df5f3b83f6b7f5c281d9a3e36b7ee", + "length": 564 + }, + { + "index": 26075, + "code": "static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)\n\n{\n\n int resx = page->columns * BITMAP_CHAR_WIDTH;\n\n int resy = (page->rows - chop_top) * BITMAP_CHAR_HEIGHT;\n\n uint8_t ci, cmax = 0;\n\n int ret;\n\n vbi_char *vc = page->text + (chop_top * page->columns);\n\n vbi_char *vcend = page->text + (page->rows * page->columns);\n\n\n\n for (; vc < vcend; vc++) {\n\n if (vc->opacity != VBI_TRANSPARENT_SPACE) {\n\n cmax = VBI_NB_COLORS;\n\n break;\n\n }\n\n }\n\n\n\n if (cmax == 0) {\n\n av_log(ctx, AV_LOG_DEBUG, \"dropping empty page %3x\\n\", page->pgno);\n\n sub_rect->type = SUBTITLE_NONE;\n\n return 0;\n\n }\n\n\n\n if ((ret = avpicture_alloc(&sub_rect->pict, AV_PIX_FMT_PAL8, resx, resy)) < 0)\n\n return ret;\n\n // Yes, we want to allocate the palette on our own because AVSubtitle works this way\n\n sub_rect->pict.data[1] = NULL;\n\n\n\n vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,\n\n sub_rect->pict.data[0], sub_rect->pict.linesize[0],\n\n 0, chop_top, page->columns, page->rows - chop_top,\n\n /*reveal*/ 1, /*flash*/ 1);\n\n\n\n fix_transparency(ctx, sub_rect, page, chop_top, cmax, resx, resy);\n\n sub_rect->x = ctx->x_offset;\n\n sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT;\n\n sub_rect->w = resx;\n\n sub_rect->h = resy;\n\n sub_rect->nb_colors = (int)cmax + 1;\n\n sub_rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);\n\n if (!sub_rect->pict.data[1]) {\n\n av_freep(&sub_rect->pict.data[0]);\n\n return AVERROR(ENOMEM);\n\n }\n\n for (ci = 0; ci < cmax; ci++) {\n\n int r, g, b, a;\n\n\n\n r = VBI_R(page->color_map[ci]);\n\n g = VBI_G(page->color_map[ci]);\n\n b = VBI_B(page->color_map[ci]);\n\n a = VBI_A(page->color_map[ci]);\n\n ((uint32_t *)sub_rect->pict.data[1])[ci] = RGBA(r, g, b, a);\n\n av_dlog(ctx, \"palette %0x\\n\", ((uint32_t *)sub_rect->pict.data[1])[ci]);\n\n }\n\n ((uint32_t *)sub_rect->pict.data[1])[cmax] = RGBA(0, 0, 0, 0);\n\n sub_rect->type = SUBTITLE_BITMAP;\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "229843aa359ae0c9519977d7fa952688db63f559", + "length": 678 + }, + { + "index": 14894, + "code": "static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)\n\n{\n\n bool page_aligned = false;\n\n unsigned int n, begin;\n\n const uint16_t block_size = s->blksize & 0x0fff;\n\n uint32_t boundary_chk = 1 << (((s->blksize & 0xf000) >> 12) + 12);\n\n uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);\n\n\n\n /* XXX: Some sd/mmc drivers (for example, u-boot-slp) do not account for\n\n * possible stop at page boundary if initial address is not page aligned,\n\n * allow them to work properly */\n\n if ((s->sdmasysad % boundary_chk) == 0) {\n\n page_aligned = true;\n\n }\n\n\n\n if (s->trnmod & SDHC_TRNS_READ) {\n\n s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |\n\n SDHC_DAT_LINE_ACTIVE;\n\n while (s->blkcnt) {\n\n if (s->data_count == 0) {\n\n for (n = 0; n < block_size; n++) {\n\n s->fifo_buffer[n] = sdbus_read_data(&s->sdbus);\n\n }\n\n }\n\n begin = s->data_count;\n\n if (((boundary_count + begin) < block_size) && page_aligned) {\n\n s->data_count = boundary_count + begin;\n\n boundary_count = 0;\n\n } else {\n\n s->data_count = block_size;\n\n boundary_count -= block_size - begin;\n\n if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {\n\n s->blkcnt--;\n\n }\n\n }\n\n dma_memory_write(&address_space_memory, s->sdmasysad,\n\n &s->fifo_buffer[begin], s->data_count - begin);\n\n s->sdmasysad += s->data_count - begin;\n\n if (s->data_count == block_size) {\n\n s->data_count = 0;\n\n }\n\n if (page_aligned && boundary_count == 0) {\n\n break;\n\n }\n\n }\n\n } else {\n\n s->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT |\n\n SDHC_DAT_LINE_ACTIVE;\n\n while (s->blkcnt) {\n\n begin = s->data_count;\n\n if (((boundary_count + begin) < block_size) && page_aligned) {\n\n s->data_count = boundary_count + begin;\n\n boundary_count = 0;\n\n } else {\n\n s->data_count = block_size;\n\n boundary_count -= block_size - begin;\n\n }\n\n dma_memory_read(&address_space_memory, s->sdmasysad,\n\n &s->fifo_buffer[begin], s->data_count);\n\n s->sdmasysad += s->data_count - begin;\n\n if (s->data_count == block_size) {\n\n for (n = 0; n < block_size; n++) {\n\n sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);\n\n }\n\n s->data_count = 0;\n\n if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {\n\n s->blkcnt--;\n\n }\n\n }\n\n if (page_aligned && boundary_count == 0) {\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (s->blkcnt == 0) {\n\n sdhci_end_transfer(s);\n\n } else {\n\n if (s->norintstsen & SDHC_NISEN_DMA) {\n\n s->norintsts |= SDHC_NIS_DMA;\n\n }\n\n sdhci_update_irq(s);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "42922105beb14c2fc58185ea022b9f72fb5465e9", + "length": 781 + }, + { + "index": 26822, + "code": "static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)\n\n{\n\n struct video_data *s = ctx->priv_data;\n\n struct v4l2_buffer buf = {\n\n .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,\n\n .memory = V4L2_MEMORY_MMAP\n\n };\n\n struct pollfd p = { .fd = s->fd, .events = POLLIN };\n\n int res;\n\n\n\n res = poll(&p, 1, s->timeout);\n\n if (res < 0)\n\n return AVERROR(errno);\n\n\n\n if (!(p.revents & (POLLIN | POLLERR | POLLHUP)))\n\n return AVERROR(EAGAIN);\n\n\n\n /* FIXME: Some special treatment might be needed in case of loss of signal... */\n\n while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));\n\n if (res < 0) {\n\n if (errno == EAGAIN) {\n\n pkt->size = 0;\n\n\n\n return AVERROR(EAGAIN);\n\n }\n\n av_log(ctx, AV_LOG_ERROR, \"ioctl(VIDIOC_DQBUF): %s\\n\",\n\n strerror(errno));\n\n\n\n return AVERROR(errno);\n\n }\n\n\n\n if (buf.index >= s->buffers) {\n\n av_log(ctx, AV_LOG_ERROR, \"Invalid buffer index received.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n avpriv_atomic_int_add_and_fetch(&s->buffers_queued, -1);\n\n // always keep at least one buffer queued\n\n av_assert0(avpriv_atomic_int_get(&s->buffers_queued) >= 1);\n\n\n\n if (s->frame_size > 0 && buf.bytesused != s->frame_size) {\n\n av_log(ctx, AV_LOG_ERROR,\n\n \"The v4l2 frame is %d bytes, but %d bytes are expected\\n\",\n\n buf.bytesused, s->frame_size);\n\n\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n /* Image is at s->buff_start[buf.index] */\n\n if (avpriv_atomic_int_get(&s->buffers_queued) == FFMAX(s->buffers / 8, 1)) {\n\n /* when we start getting low on queued buffers, fall back on copying data */\n\n res = av_new_packet(pkt, buf.bytesused);\n\n if (res < 0) {\n\n av_log(ctx, AV_LOG_ERROR, \"Error allocating a packet.\\n\");\n\n return res;\n\n }\n\n memcpy(pkt->data, s->buf_start[buf.index], buf.bytesused);\n\n\n\n res = ioctl(s->fd, VIDIOC_QBUF, &buf);\n\n if (res < 0) {\n\n av_log(ctx, AV_LOG_ERROR, \"ioctl(VIDIOC_QBUF)\\n\");\n\n av_free_packet(pkt);\n\n return AVERROR(errno);\n\n }\n\n avpriv_atomic_int_add_and_fetch(&s->buffers_queued, 1);\n\n } else {\n\n struct buff_data *buf_descriptor;\n\n\n\n pkt->data = s->buf_start[buf.index];\n\n pkt->size = buf.bytesused;\n\n#if FF_API_DESTRUCT_PACKET\n\nFF_DISABLE_DEPRECATION_WARNINGS\n\n pkt->destruct = dummy_release_buffer;\n\nFF_ENABLE_DEPRECATION_WARNINGS\n\n#endif\n\n\n\n buf_descriptor = av_malloc(sizeof(struct buff_data));\n\n if (buf_descriptor == NULL) {\n\n /* Something went wrong... Since av_malloc() failed, we cannot even\n\n * allocate a buffer for memcpying into it\n\n */\n\n av_log(ctx, AV_LOG_ERROR, \"Failed to allocate a buffer descriptor\\n\");\n\n res = ioctl(s->fd, VIDIOC_QBUF, &buf);\n\n\n\n return AVERROR(ENOMEM);\n\n }\n\n buf_descriptor->fd = s->fd;\n\n buf_descriptor->index = buf.index;\n\n buf_descriptor->s = s;\n\n\n\n pkt->buf = av_buffer_create(pkt->data, pkt->size, mmap_release_buffer,\n\n buf_descriptor, 0);\n\n if (!pkt->buf) {\n\n av_freep(&buf_descriptor);\n\n return AVERROR(ENOMEM);\n\n }\n\n }\n\n pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;\n\n\n\n return s->buf_len[buf.index];\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f929ab0569ff31ed5a59b0b0adb7ce09df3fca39", + "length": 895 + }, + { + "index": 18203, + "code": "ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb,\n\n AVStream *st, RMStream *rst, int codec_data_size)\n\n{\n\n unsigned int v;\n\n int size;\n\n int64_t codec_pos;\n\n int ret;\n\n\n\n avpriv_set_pts_info(st, 64, 1, 1000);\n\n codec_pos = avio_tell(pb);\n\n v = avio_rb32(pb);\n\n if (v == MKTAG(0xfd, 'a', 'r', '.')) {\n\n /* ra type header */\n\n if (rm_read_audio_stream_info(s, pb, st, rst, 0))\n\n return -1;\n\n } else if (v == MKBETAG('L', 'S', 'D', ':')) {\n\n avio_seek(pb, -4, SEEK_CUR);\n\n if ((ret = rm_read_extradata(pb, st->codec, codec_data_size)) < 0)\n\n return ret;\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_tag = AV_RL32(st->codec->extradata);\n\n st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags,\n\n st->codec->codec_tag);\n\n } else {\n\n int fps;\n\n if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) {\n\n fail1:\n\n av_log(st->codec, AV_LOG_ERROR, \"Unsupported video codec\\n\");\n\n goto skip;\n\n }\n\n st->codec->codec_tag = avio_rl32(pb);\n\n st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags,\n\n st->codec->codec_tag);\n\n// av_log(s, AV_LOG_DEBUG, \"%X %X\\n\", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));\n\n if (st->codec->codec_id == CODEC_ID_NONE)\n\n goto fail1;\n\n st->codec->width = avio_rb16(pb);\n\n st->codec->height = avio_rb16(pb);\n\n avio_skip(pb, 2); // looks like bits per sample\n\n avio_skip(pb, 4); // always zero?\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;\n\n fps = avio_rb32(pb);\n\n\n\n if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0)\n\n return ret;\n\n\n\n av_reduce(&st->r_frame_rate.den, &st->r_frame_rate.num,\n\n 0x10000, fps, (1 << 30) - 1);\n\n st->avg_frame_rate = st->r_frame_rate;\n\n }\n\n\n\nskip:\n\n /* skip codec info */\n\n size = avio_tell(pb) - codec_pos;\n\n avio_skip(pb, codec_data_size - size);\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "aba232cfa9b193604ed98f3fa505378d006b1b3b", + "length": 650 + }, + { + "index": 25183, + "code": "static void parse_str(StringInputVisitor *siv, Error **errp)\n\n{\n\n char *str = (char *) siv->string;\n\n long long start, end;\n\n Range *cur;\n\n char *endptr;\n\n\n\n if (siv->ranges) {\n\n return;\n\n }\n\n\n\n do {\n\n errno = 0;\n\n start = strtoll(str, &endptr, 0);\n\n if (errno == 0 && endptr > str) {\n\n if (*endptr == '\\0') {\n\n cur = g_malloc0(sizeof(*cur));\n\n cur->begin = start;\n\n cur->end = start + 1;\n\n siv->ranges = g_list_insert_sorted_merged(siv->ranges, cur,\n\n range_compare);\n\n cur = NULL;\n\n str = NULL;\n\n } else if (*endptr == '-') {\n\n str = endptr + 1;\n\n errno = 0;\n\n end = strtoll(str, &endptr, 0);\n\n if (errno == 0 && endptr > str && start <= end &&\n\n (start > INT64_MAX - 65536 ||\n\n end < start + 65536)) {\n\n if (*endptr == '\\0') {\n\n cur = g_malloc0(sizeof(*cur));\n\n cur->begin = start;\n\n cur->end = end + 1;\n\n siv->ranges =\n\n g_list_insert_sorted_merged(siv->ranges,\n\n cur,\n\n range_compare);\n\n cur = NULL;\n\n str = NULL;\n\n } else if (*endptr == ',') {\n\n str = endptr + 1;\n\n cur = g_malloc0(sizeof(*cur));\n\n cur->begin = start;\n\n cur->end = end + 1;\n\n siv->ranges =\n\n g_list_insert_sorted_merged(siv->ranges,\n\n cur,\n\n range_compare);\n\n cur = NULL;\n\n } else {\n\n goto error;\n\n }\n\n } else {\n\n goto error;\n\n }\n\n } else if (*endptr == ',') {\n\n str = endptr + 1;\n\n cur = g_malloc0(sizeof(*cur));\n\n cur->begin = start;\n\n cur->end = start + 1;\n\n siv->ranges = g_list_insert_sorted_merged(siv->ranges,\n\n cur,\n\n range_compare);\n\n cur = NULL;\n\n } else {\n\n goto error;\n\n }\n\n } else {\n\n goto error;\n\n }\n\n } while (str);\n\n\n\n return;\n\nerror:\n\n g_list_foreach(siv->ranges, free_range, NULL);\n\n g_list_free(siv->ranges);\n\n siv->ranges = NULL;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "74f24cb6306d065045d0e2215a7d10533fa59c57", + "length": 555 + }, + { + "index": 19475, + "code": "int load_vmstate(const char *name)\n\n{\n\n BlockDriverState *bs, *bs_vm_state;\n\n QEMUSnapshotInfo sn;\n\n QEMUFile *f;\n\n int ret;\n\n\n\n if (!bdrv_all_can_snapshot(&bs)) {\n\n error_report(\"Device '%s' is writable but does not support snapshots.\",\n\n bdrv_get_device_name(bs));\n\n return -ENOTSUP;\n\n }\n\n\n\n bs_vm_state = find_vmstate_bs();\n\n if (!bs_vm_state) {\n\n error_report(\"No block device supports snapshots\");\n\n return -ENOTSUP;\n\n }\n\n\n\n /* Don't even try to load empty VM states */\n\n ret = bdrv_snapshot_find(bs_vm_state, &sn, name);\n\n if (ret < 0) {\n\n return ret;\n\n } else if (sn.vm_state_size == 0) {\n\n error_report(\"This is a disk-only snapshot. Revert to it offline \"\n\n \"using qemu-img.\");\n\n return -EINVAL;\n\n }\n\n\n\n /* Verify if there is any device that doesn't support snapshots and is\n\n writable and check if the requested snapshot is available too. */\n\n bs = NULL;\n\n while ((bs = bdrv_next(bs))) {\n\n if (!bdrv_can_snapshot(bs)) {\n\n continue;\n\n }\n\n\n\n ret = bdrv_snapshot_find(bs, &sn, name);\n\n if (ret < 0) {\n\n error_report(\"Device '%s' does not have the requested snapshot '%s'\",\n\n bdrv_get_device_name(bs), name);\n\n return ret;\n\n }\n\n }\n\n\n\n /* Flush all IO requests so they don't interfere with the new state. */\n\n bdrv_drain_all();\n\n\n\n ret = bdrv_all_goto_snapshot(name, &bs);\n\n if (ret < 0) {\n\n error_report(\"Error %d while activating snapshot '%s' on '%s'\",\n\n ret, name, bdrv_get_device_name(bs));\n\n return ret;\n\n }\n\n\n\n /* restore the VM state */\n\n f = qemu_fopen_bdrv(bs_vm_state, 0);\n\n if (!f) {\n\n error_report(\"Could not open VM state file\");\n\n return -EINVAL;\n\n }\n\n\n\n qemu_system_reset(VMRESET_SILENT);\n\n migration_incoming_state_new(f);\n\n ret = qemu_loadvm_state(f);\n\n\n\n qemu_fclose(f);\n\n migration_incoming_state_destroy();\n\n if (ret < 0) {\n\n error_report(\"Error %d while loading VM state\", ret);\n\n return ret;\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "723ccda1a0eecece8e70dbcdd35a603f6c41a475", + "length": 534 + }, + { + "index": 19267, + "code": "static void tcg_out_modrm_sib_offset(TCGContext *s, int opc, int r, int rm,\n\n int index, int shift, intptr_t offset)\n\n{\n\n int mod, len;\n\n\n\n if (index < 0 && rm < 0) {\n\n if (TCG_TARGET_REG_BITS == 64) {\n\n /* Try for a rip-relative addressing mode. This has replaced\n\n the 32-bit-mode absolute addressing encoding. */\n\n intptr_t pc = (intptr_t)s->code_ptr + 5 + ~rm;\n\n intptr_t disp = offset - pc;\n\n if (disp == (int32_t)disp) {\n\n tcg_out_opc(s, opc, r, 0, 0);\n\n tcg_out8(s, (LOWREGMASK(r) << 3) | 5);\n\n tcg_out32(s, disp);\n\n return;\n\n }\n\n\n\n /* Try for an absolute address encoding. This requires the\n\n use of the MODRM+SIB encoding and is therefore larger than\n\n rip-relative addressing. */\n\n if (offset == (int32_t)offset) {\n\n tcg_out_opc(s, opc, r, 0, 0);\n\n tcg_out8(s, (LOWREGMASK(r) << 3) | 4);\n\n tcg_out8(s, (4 << 3) | 5);\n\n tcg_out32(s, offset);\n\n return;\n\n }\n\n\n\n /* ??? The memory isn't directly addressable. */\n\n tcg_abort();\n\n } else {\n\n /* Absolute address. */\n\n tcg_out_opc(s, opc, r, 0, 0);\n\n tcg_out8(s, (r << 3) | 5);\n\n tcg_out32(s, offset);\n\n return;\n\n }\n\n }\n\n\n\n /* Find the length of the immediate addend. Note that the encoding\n\n that would be used for (%ebp) indicates absolute addressing. */\n\n if (rm < 0) {\n\n mod = 0, len = 4, rm = 5;\n\n } else if (offset == 0 && LOWREGMASK(rm) != TCG_REG_EBP) {\n\n mod = 0, len = 0;\n\n } else if (offset == (int8_t)offset) {\n\n mod = 0x40, len = 1;\n\n } else {\n\n mod = 0x80, len = 4;\n\n }\n\n\n\n /* Use a single byte MODRM format if possible. Note that the encoding\n\n that would be used for %esp is the escape to the two byte form. */\n\n if (index < 0 && LOWREGMASK(rm) != TCG_REG_ESP) {\n\n /* Single byte MODRM format. */\n\n tcg_out_opc(s, opc, r, rm, 0);\n\n tcg_out8(s, mod | (LOWREGMASK(r) << 3) | LOWREGMASK(rm));\n\n } else {\n\n /* Two byte MODRM+SIB format. */\n\n\n\n /* Note that the encoding that would place %esp into the index\n\n field indicates no index register. In 64-bit mode, the REX.X\n\n bit counts, so %r12 can be used as the index. */\n\n if (index < 0) {\n\n index = 4;\n\n } else {\n\n assert(index != TCG_REG_ESP);\n\n }\n\n\n\n tcg_out_opc(s, opc, r, rm, index);\n\n tcg_out8(s, mod | (LOWREGMASK(r) << 3) | 4);\n\n tcg_out8(s, (shift << 6) | (LOWREGMASK(index) << 3) | LOWREGMASK(rm));\n\n }\n\n\n\n if (len == 1) {\n\n tcg_out8(s, offset);\n\n } else if (len == 4) {\n\n tcg_out32(s, offset);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "eabb7b91b36b202b4dac2df2d59d698e3aff197a", + "length": 853 + }, + { + "index": 9356, + "code": "static int http_connect(URLContext *h, const char *path, const char *hoststr,\n\n const char *auth, int *new_location)\n\n{\n\n HTTPContext *s = h->priv_data;\n\n int post, err;\n\n char line[1024];\n\n char headers[1024] = \"\";\n\n char *authstr = NULL;\n\n int64_t off = s->off;\n\n int len = 0;\n\n\n\n\n\n /* send http header */\n\n post = h->flags & URL_WRONLY;\n\n authstr = ff_http_auth_create_response(&s->auth_state, auth, path,\n\n post ? \"POST\" : \"GET\");\n\n\n\n /* set default headers if needed */\n\n if (!has_header(s->headers, \"\\r\\nUser-Agent: \"))\n\n len += av_strlcatf(headers + len, sizeof(headers) - len,\n\n \"User-Agent: %s\\r\\n\", LIBAVFORMAT_IDENT);\n\n if (!has_header(s->headers, \"\\r\\nAccept: \"))\n\n len += av_strlcpy(headers + len, \"Accept: */*\\r\\n\",\n\n sizeof(headers) - len);\n\n if (!has_header(s->headers, \"\\r\\nRange: \"))\n\n len += av_strlcatf(headers + len, sizeof(headers) - len,\n\n \"Range: bytes=%\"PRId64\"-\\r\\n\", s->off);\n\n if (!has_header(s->headers, \"\\r\\nConnection: \"))\n\n len += av_strlcpy(headers + len, \"Connection: close\\r\\n\",\n\n sizeof(headers)-len);\n\n if (!has_header(s->headers, \"\\r\\nHost: \"))\n\n len += av_strlcatf(headers + len, sizeof(headers) - len,\n\n \"Host: %s\\r\\n\", hoststr);\n\n\n\n /* now add in custom headers */\n\n av_strlcpy(headers+len, s->headers, sizeof(headers)-len);\n\n\n\n snprintf(s->buffer, sizeof(s->buffer),\n\n \"%s %s HTTP/1.1\\r\\n\"\n\n \"%s\"\n\n \"%s\"\n\n \"%s\"\n\n \"\\r\\n\",\n\n post ? \"POST\" : \"GET\",\n\n path,\n\n post && s->is_chunked ? \"Transfer-Encoding: chunked\\r\\n\" : \"\",\n\n headers,\n\n authstr ? authstr : \"\");\n\n\n\n av_freep(&authstr);\n\n if (http_write(h, s->buffer, strlen(s->buffer)) < 0)\n\n return AVERROR(EIO);\n\n\n\n /* init input buffer */\n\n s->buf_ptr = s->buffer;\n\n s->buf_end = s->buffer;\n\n s->line_count = 0;\n\n s->off = 0;\n\n s->filesize = -1;\n\n if (post) {\n\n /* always use chunked encoding for upload data */\n\n s->chunksize = 0;\n\n /* Pretend that it did work. We didn't read any header yet, since\n\n * we've still to send the POST data, but the code calling this\n\n * function will check http_code after we return. */\n\n s->http_code = 200;\n\n return 0;\n\n }\n\n\n\n /* wait for header */\n\n for(;;) {\n\n if (http_get_line(s, line, sizeof(line)) < 0)\n\n return AVERROR(EIO);\n\n\n\n dprintf(NULL, \"header='%s'\\n\", line);\n\n\n\n err = process_line(h, line, s->line_count, new_location);\n\n if (err < 0)\n\n return err;\n\n if (err == 0)\n\n break;\n\n s->line_count++;\n\n }\n\n\n\n return (off == s->off) ? 0 : -1;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f37246952a65c675c1e4a229ea95a0f82f32b084", + "length": 780 + }, + { + "index": 7177, + "code": "static int mtv_read_header(AVFormatContext *s)\n\n{\n\n MTVDemuxContext *mtv = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n AVStream *st;\n\n unsigned int audio_subsegments;\n\n\n\n avio_skip(pb, 3);\n\n mtv->file_size = avio_rl32(pb);\n\n mtv->segments = avio_rl32(pb);\n\n avio_skip(pb, 32);\n\n mtv->audio_identifier = avio_rl24(pb);\n\n mtv->audio_br = avio_rl16(pb);\n\n mtv->img_colorfmt = avio_rl24(pb);\n\n mtv->img_bpp = avio_r8(pb);\n\n mtv->img_width = avio_rl16(pb);\n\n mtv->img_height = avio_rl16(pb);\n\n mtv->img_segment_size = avio_rl16(pb);\n\n\n\n /* Calculate width and height if missing from header */\n\n\n\n if(mtv->img_bpp>>3){\n\n if(!mtv->img_width && mtv->img_height)\n\n mtv->img_width=mtv->img_segment_size / (mtv->img_bpp>>3)\n\n / mtv->img_height;\n\n\n\n if(!mtv->img_height && mtv->img_width)\n\n mtv->img_height=mtv->img_segment_size / (mtv->img_bpp>>3)\n\n / mtv->img_width;\n\n }\n\n if(!mtv->img_height || !mtv->img_width || !mtv->img_segment_size){\n\n av_log(s, AV_LOG_ERROR, \"width or height or segment_size is invalid and I cannot calculate them from other information\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n avio_skip(pb, 4);\n\n audio_subsegments = avio_rl16(pb);\n\n\n\n if (audio_subsegments == 0) {\n\n avpriv_request_sample(s, \"MTV files without audio\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n\n\n mtv->full_segment_size =\n\n audio_subsegments * (MTV_AUDIO_PADDING_SIZE + MTV_ASUBCHUNK_DATA_SIZE) +\n\n mtv->img_segment_size;\n\n mtv->video_fps = (mtv->audio_br / 4) / audio_subsegments;\n\n\n\n // FIXME Add sanity check here\n\n\n\n // all systems go! init decoders\n\n\n\n // video - raw rgb565\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if(!st)\n\n return AVERROR(ENOMEM);\n\n\n\n avpriv_set_pts_info(st, 64, 1, mtv->video_fps);\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;\n\n st->codec->pix_fmt = AV_PIX_FMT_RGB565BE;\n\n st->codec->width = mtv->img_width;\n\n st->codec->height = mtv->img_height;\n\n st->codec->sample_rate = mtv->video_fps;\n\n st->codec->extradata = av_strdup(\"BottomUp\");\n\n st->codec->extradata_size = 9;\n\n\n\n // audio - mp3\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if(!st)\n\n return AVERROR(ENOMEM);\n\n\n\n avpriv_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE);\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = AV_CODEC_ID_MP3;\n\n st->codec->bit_rate = mtv->audio_br;\n\n st->need_parsing = AVSTREAM_PARSE_FULL;\n\n\n\n // Jump over header\n\n\n\n if(avio_seek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE)\n\n return AVERROR(EIO);\n\n\n\n return 0;\n\n\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "ba15aab4a4a296c632bd8d3428b002055109c7d1", + "length": 829 + }, + { + "index": 13845, + "code": "static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,\n\n uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int l2_index;\n\n uint64_t *l2_table;\n\n uint64_t entry;\n\n unsigned int nb_clusters;\n\n int ret;\n\n\n\n uint64_t alloc_cluster_offset;\n\n\n\n trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,\n\n *bytes);\n\n assert(*bytes > 0);\n\n\n\n /*\n\n * Calculate the number of clusters to look for. We stop at L2 table\n\n * boundaries to keep things simple.\n\n */\n\n nb_clusters =\n\n size_to_clusters(s, offset_into_cluster(s, guest_offset) + *bytes);\n\n\n\n l2_index = offset_to_l2_index(s, guest_offset);\n\n nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);\n\n\n\n /* Find L2 entry for the first involved cluster */\n\n ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n entry = be64_to_cpu(l2_table[l2_index]);\n\n\n\n /* For the moment, overwrite compressed clusters one by one */\n\n if (entry & QCOW_OFLAG_COMPRESSED) {\n\n nb_clusters = 1;\n\n } else {\n\n nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index);\n\n }\n\n\n\n ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n if (nb_clusters == 0) {\n\n *bytes = 0;\n\n return 0;\n\n }\n\n\n\n /* Allocate, if necessary at a given offset in the image file */\n\n alloc_cluster_offset = start_of_cluster(s, *host_offset);\n\n ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,\n\n &nb_clusters);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Can't extend contiguous allocation */\n\n if (nb_clusters == 0) {\n\n *bytes = 0;\n\n return 0;\n\n }\n\n\n\n /*\n\n * Save info needed for meta data update.\n\n *\n\n * requested_sectors: Number of sectors from the start of the first\n\n * newly allocated cluster to the end of the (possibly shortened\n\n * before) write request.\n\n *\n\n * avail_sectors: Number of sectors from the start of the first\n\n * newly allocated to the end of the last newly allocated cluster.\n\n *\n\n * nb_sectors: The number of sectors from the start of the first\n\n * newly allocated cluster to the end of the area that the write\n\n * request actually writes to (excluding COW at the end)\n\n */\n\n int requested_sectors =\n\n (*bytes + offset_into_cluster(s, guest_offset))\n\n >> BDRV_SECTOR_BITS;\n\n int avail_sectors = nb_clusters\n\n << (s->cluster_bits - BDRV_SECTOR_BITS);\n\n int alloc_n_start = offset_into_cluster(s, guest_offset)\n\n >> BDRV_SECTOR_BITS;\n\n int nb_sectors = MIN(requested_sectors, avail_sectors);\n\n QCowL2Meta *old_m = *m;\n\n\n\n *m = g_malloc0(sizeof(**m));\n\n\n\n **m = (QCowL2Meta) {\n\n .next = old_m,\n\n\n\n .alloc_offset = alloc_cluster_offset,\n\n .offset = start_of_cluster(s, guest_offset),\n\n .nb_clusters = nb_clusters,\n\n .nb_available = nb_sectors,\n\n\n\n .cow_start = {\n\n .offset = 0,\n\n .nb_sectors = alloc_n_start,\n\n },\n\n .cow_end = {\n\n .offset = nb_sectors * BDRV_SECTOR_SIZE,\n\n .nb_sectors = avail_sectors - nb_sectors,\n\n },\n\n };\n\n qemu_co_queue_init(&(*m)->dependent_requests);\n\n QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight);\n\n\n\n *host_offset = alloc_cluster_offset + offset_into_cluster(s, guest_offset);\n\n *bytes = MIN(*bytes, (nb_sectors * BDRV_SECTOR_SIZE)\n\n - offset_into_cluster(s, guest_offset));\n\n assert(*bytes != 0);\n\n\n\n return 1;\n\n\n\nfail:\n\n if (*m && (*m)->nb_clusters > 0) {\n\n QLIST_REMOVE(*m, next_in_flight);\n\n }\n\n return ret;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "ecdd5333ab9ed3f2b848066aaaef02c027b25e36", + "length": 993 + }, + { + "index": 25701, + "code": "static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf)\n\n{\n\n SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);\n\n uint64_t nb_sectors;\n\n bool dbd;\n\n int page, buflen, ret, page_control;\n\n uint8_t *p;\n\n uint8_t dev_specific_param;\n\n\n\n dbd = (r->req.cmd.buf[1] & 0x8) != 0;\n\n page = r->req.cmd.buf[2] & 0x3f;\n\n page_control = (r->req.cmd.buf[2] & 0xc0) >> 6;\n\n DPRINTF(\"Mode Sense(%d) (page %d, xfer %zd, page_control %d)\\n\",\n\n (r->req.cmd.buf[0] == MODE_SENSE) ? 6 : 10, page, r->req.cmd.xfer, page_control);\n\n memset(outbuf, 0, r->req.cmd.xfer);\n\n p = outbuf;\n\n\n\n if (s->qdev.type == TYPE_DISK) {\n\n dev_specific_param = s->features & (1 << SCSI_DISK_F_DPOFUA) ? 0x10 : 0;\n\n if (bdrv_is_read_only(s->qdev.conf.bs)) {\n\n dev_specific_param |= 0x80; /* Readonly. */\n\n }\n\n } else {\n\n /* MMC prescribes that CD/DVD drives have no block descriptors,\n\n * and defines no device-specific parameter. */\n\n dev_specific_param = 0x00;\n\n dbd = true;\n\n }\n\n\n\n if (r->req.cmd.buf[0] == MODE_SENSE) {\n\n p[1] = 0; /* Default media type. */\n\n p[2] = dev_specific_param;\n\n p[3] = 0; /* Block descriptor length. */\n\n p += 4;\n\n } else { /* MODE_SENSE_10 */\n\n p[2] = 0; /* Default media type. */\n\n p[3] = dev_specific_param;\n\n p[6] = p[7] = 0; /* Block descriptor length. */\n\n p += 8;\n\n }\n\n\n\n bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);\n\n if (!dbd && nb_sectors) {\n\n if (r->req.cmd.buf[0] == MODE_SENSE) {\n\n outbuf[3] = 8; /* Block descriptor length */\n\n } else { /* MODE_SENSE_10 */\n\n outbuf[7] = 8; /* Block descriptor length */\n\n }\n\n nb_sectors /= (s->qdev.blocksize / 512);\n\n if (nb_sectors > 0xffffff) {\n\n nb_sectors = 0;\n\n }\n\n p[0] = 0; /* media density code */\n\n p[1] = (nb_sectors >> 16) & 0xff;\n\n p[2] = (nb_sectors >> 8) & 0xff;\n\n p[3] = nb_sectors & 0xff;\n\n p[4] = 0; /* reserved */\n\n p[5] = 0; /* bytes 5-7 are the sector size in bytes */\n\n p[6] = s->qdev.blocksize >> 8;\n\n p[7] = 0;\n\n p += 8;\n\n }\n\n\n\n if (page_control == 3) {\n\n /* Saved Values */\n\n scsi_check_condition(r, SENSE_CODE(SAVING_PARAMS_NOT_SUPPORTED));\n\n return -1;\n\n }\n\n\n\n if (page == 0x3f) {\n\n for (page = 0; page <= 0x3e; page++) {\n\n mode_sense_page(s, page, &p, page_control);\n\n }\n\n } else {\n\n ret = mode_sense_page(s, page, &p, page_control);\n\n if (ret == -1) {\n\n return -1;\n\n }\n\n }\n\n\n\n buflen = p - outbuf;\n\n /*\n\n * The mode data length field specifies the length in bytes of the\n\n * following data that is available to be transferred. The mode data\n\n * length does not include itself.\n\n */\n\n if (r->req.cmd.buf[0] == MODE_SENSE) {\n\n outbuf[0] = buflen - 1;\n\n } else { /* MODE_SENSE_10 */\n\n outbuf[0] = ((buflen - 2) >> 8) & 0xff;\n\n outbuf[1] = (buflen - 2) & 0xff;\n\n }\n\n return buflen;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4be746345f13e99e468c60acbd3a355e8183e3ce", + "length": 1015 + }, + { + "index": 13340, + "code": "int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,\n\n int bytes)\n\n{\n\n BdrvTrackedRequest req;\n\n int max_pdiscard, ret;\n\n int head, tail, align;\n\n\n\n\n return -ENOMEDIUM;\n\n\n\n\n if (bdrv_has_readonly_bitmaps(bs)) {\n\n return -EPERM;\n\n\n\n\n ret = bdrv_check_byte_request(bs, offset, bytes);\n\n if (ret < 0) {\n\n return ret;\n\n } else if (bs->read_only) {\n\n return -EPERM;\n\n\n assert(!(bs->open_flags & BDRV_O_INACTIVE));\n\n\n\n /* Do nothing if disabled. */\n\n if (!(bs->open_flags & BDRV_O_UNMAP)) {\n\n return 0;\n\n\n\n\n if (!bs->drv->bdrv_co_pdiscard && !bs->drv->bdrv_aio_pdiscard) {\n\n return 0;\n\n\n\n\n /* Discard is advisory, but some devices track and coalesce\n\n * unaligned requests, so we must pass everything down rather than\n\n * round here. Still, most devices will just silently ignore\n\n * unaligned requests (by returning -ENOTSUP), so we must fragment\n\n * the request accordingly. */\n\n align = MAX(bs->bl.pdiscard_alignment, bs->bl.request_alignment);\n\n assert(align % bs->bl.request_alignment == 0);\n\n head = offset % align;\n\n tail = (offset + bytes) % align;\n\n\n\n bdrv_inc_in_flight(bs);\n\n tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD);\n\n\n\n ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req);\n\n if (ret < 0) {\n\n\n\n\n\n max_pdiscard = QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_pdiscard, INT_MAX),\n\n align);\n\n assert(max_pdiscard >= bs->bl.request_alignment);\n\n\n\n while (bytes > 0) {\n\n int num = bytes;\n\n\n\n if (head) {\n\n /* Make small requests to get to alignment boundaries. */\n\n num = MIN(bytes, align - head);\n\n if (!QEMU_IS_ALIGNED(num, bs->bl.request_alignment)) {\n\n num %= bs->bl.request_alignment;\n\n\n head = (head + num) % align;\n\n assert(num < max_pdiscard);\n\n } else if (tail) {\n\n if (num > align) {\n\n /* Shorten the request to the last aligned cluster. */\n\n num -= tail;\n\n } else if (!QEMU_IS_ALIGNED(tail, bs->bl.request_alignment) &&\n\n tail > bs->bl.request_alignment) {\n\n tail %= bs->bl.request_alignment;\n\n num -= tail;\n\n\n\n /* limit request size */\n\n if (num > max_pdiscard) {\n\n num = max_pdiscard;\n\n\n\n\n\n\n\n\n if (bs->drv->bdrv_co_pdiscard) {\n\n ret = bs->drv->bdrv_co_pdiscard(bs, offset, num);\n\n } else {\n\n BlockAIOCB *acb;\n\n CoroutineIOCompletion co = {\n\n .coroutine = qemu_coroutine_self(),\n\n };\n\n\n\n acb = bs->drv->bdrv_aio_pdiscard(bs, offset, num,\n\n bdrv_co_io_em_complete, &co);\n\n if (acb == NULL) {\n\n ret = -EIO;\n\n\n } else {\n\n qemu_coroutine_yield();\n\n ret = co.ret;\n\n\n\n if (ret && ret != -ENOTSUP) {\n\n\n\n\n\n offset += num;\n\n bytes -= num;\n\n\n ret = 0;\n\nout:\n\n atomic_inc(&bs->write_gen);\n\n bdrv_set_dirty(bs, req.offset, req.bytes);\n\n tracked_request_end(&req);\n\n bdrv_dec_in_flight(bs);\n\n return ret;\n", + "label": 1, + "project": "qemu", + "commit_id": "d470ad42acfc73c45d3e8ed5311a491160b4c100", + "length": 800 + }, + { + "index": 22649, + "code": "static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s)\n\n{\n\n AVStream *video_st = s->streams[0];\n\n AVCodecParameters *video_par = s->streams[0]->codecpar;\n\n AVCodecParameters *audio_par = s->streams[1]->codecpar;\n\n int audio_rate = audio_par->sample_rate;\n\n int64_t frame_rate = (video_st->avg_frame_rate.num * 0x10000LL) / video_st->avg_frame_rate.den;\n\n int audio_kbitrate = audio_par->bit_rate / 1000;\n\n int video_kbitrate = FFMIN(video_par->bit_rate / 1000, 800 - audio_kbitrate);\n\n\n\n avio_wb32(pb, 0x94); /* size */\n\n ffio_wfourcc(pb, \"uuid\");\n\n ffio_wfourcc(pb, \"PROF\");\n\n\n\n avio_wb32(pb, 0x21d24fce); /* 96 bit UUID */\n\n avio_wb32(pb, 0xbb88695c);\n\n avio_wb32(pb, 0xfac9c740);\n\n\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x3); /* 3 sections ? */\n\n\n\n avio_wb32(pb, 0x14); /* size */\n\n ffio_wfourcc(pb, \"FPRF\");\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x0); /* ? */\n\n\n\n avio_wb32(pb, 0x2c); /* size */\n\n ffio_wfourcc(pb, \"APRF\"); /* audio */\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, 0x2); /* TrackID */\n\n ffio_wfourcc(pb, \"mp4a\");\n\n avio_wb32(pb, 0x20f);\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, audio_kbitrate);\n\n avio_wb32(pb, audio_kbitrate);\n\n avio_wb32(pb, audio_rate);\n\n avio_wb32(pb, audio_par->channels);\n\n\n\n avio_wb32(pb, 0x34); /* size */\n\n ffio_wfourcc(pb, \"VPRF\"); /* video */\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, 0x1); /* TrackID */\n\n if (video_par->codec_id == AV_CODEC_ID_H264) {\n\n ffio_wfourcc(pb, \"avc1\");\n\n avio_wb16(pb, 0x014D);\n\n avio_wb16(pb, 0x0015);\n\n } else {\n\n ffio_wfourcc(pb, \"mp4v\");\n\n avio_wb16(pb, 0x0000);\n\n avio_wb16(pb, 0x0103);\n\n }\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, video_kbitrate);\n\n avio_wb32(pb, video_kbitrate);\n\n avio_wb32(pb, frame_rate);\n\n avio_wb32(pb, frame_rate);\n\n avio_wb16(pb, video_par->width);\n\n avio_wb16(pb, video_par->height);\n\n avio_wb32(pb, 0x010001); /* ? */\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "ed2112fb36d7407d960b4f44475a700a7c44344c", + "length": 796 + }, + { + "index": 16467, + "code": "static int qemu_rdma_unregister_waiting(RDMAContext *rdma)\n\n{\n\n while (rdma->unregistrations[rdma->unregister_current]) {\n\n int ret;\n\n uint64_t wr_id = rdma->unregistrations[rdma->unregister_current];\n\n uint64_t chunk =\n\n (wr_id & RDMA_WRID_CHUNK_MASK) >> RDMA_WRID_CHUNK_SHIFT;\n\n uint64_t index =\n\n (wr_id & RDMA_WRID_BLOCK_MASK) >> RDMA_WRID_BLOCK_SHIFT;\n\n RDMALocalBlock *block =\n\n &(rdma->local_ram_blocks.block[index]);\n\n RDMARegister reg = { .current_index = index };\n\n RDMAControlHeader resp = { .type = RDMA_CONTROL_UNREGISTER_FINISHED,\n\n };\n\n RDMAControlHeader head = { .len = sizeof(RDMARegister),\n\n .type = RDMA_CONTROL_UNREGISTER_REQUEST,\n\n .repeat = 1,\n\n };\n\n\n\n DDPRINTF(\"Processing unregister for chunk: %\" PRIu64\n\n \" at position %d\\n\", chunk, rdma->unregister_current);\n\n\n\n rdma->unregistrations[rdma->unregister_current] = 0;\n\n rdma->unregister_current++;\n\n\n\n if (rdma->unregister_current == RDMA_SIGNALED_SEND_MAX) {\n\n rdma->unregister_current = 0;\n\n }\n\n\n\n\n\n /*\n\n * Unregistration is speculative (because migration is single-threaded\n\n * and we cannot break the protocol's inifinband message ordering).\n\n * Thus, if the memory is currently being used for transmission,\n\n * then abort the attempt to unregister and try again\n\n * later the next time a completion is received for this memory.\n\n */\n\n clear_bit(chunk, block->unregister_bitmap);\n\n\n\n if (test_bit(chunk, block->transit_bitmap)) {\n\n DDPRINTF(\"Cannot unregister inflight chunk: %\" PRIu64 \"\\n\", chunk);\n\n continue;\n\n }\n\n\n\n DDPRINTF(\"Sending unregister for chunk: %\" PRIu64 \"\\n\", chunk);\n\n\n\n ret = ibv_dereg_mr(block->pmr[chunk]);\n\n block->pmr[chunk] = NULL;\n\n block->remote_keys[chunk] = 0;\n\n\n\n if (ret != 0) {\n\n perror(\"unregistration chunk failed\");\n\n return -ret;\n\n }\n\n rdma->total_registrations--;\n\n\n\n reg.key.chunk = chunk;\n\n register_to_network(®);\n\n ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®,\n\n &resp, NULL, NULL);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n DDPRINTF(\"Unregister for chunk: %\" PRIu64 \" complete.\\n\", chunk);\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "60fe637bf0e4d7989e21e50f52526444765c63b4", + "length": 594 + }, + { + "index": 23654, + "code": "static inline void RENAME(yuv2yuvX)(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,\n\n\t\t\t\t int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,\n\n\t\t\t\t uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW,\n\n\t\t\t\t int16_t * lumMmxFilter, int16_t * chrMmxFilter)\n\n{\n\n#ifdef HAVE_MMX\n\n\tif(uDest != NULL)\n\n\t{\n\n\t\tasm volatile(\n\n\t\t\t\tYSCALEYUV2YV12X(0)\n\n\t\t\t\t:: \"m\" (-chrFilterSize), \"r\" (chrSrc+chrFilterSize),\n\n\t\t\t\t\"r\" (chrMmxFilter+chrFilterSize*4), \"r\" (uDest), \"m\" (dstW>>1)\n\n\t\t\t\t: \"%eax\", \"%edx\", \"%esi\"\n\n\t\t\t);\n\n\n\n\t\tasm volatile(\n\n\t\t\t\tYSCALEYUV2YV12X(4096)\n\n\t\t\t\t:: \"m\" (-chrFilterSize), \"r\" (chrSrc+chrFilterSize),\n\n\t\t\t\t\"r\" (chrMmxFilter+chrFilterSize*4), \"r\" (vDest), \"m\" (dstW>>1)\n\n\t\t\t\t: \"%eax\", \"%edx\", \"%esi\"\n\n\t\t\t);\n\n\t}\n\n\n\n\tasm volatile(\n\n\t\t\tYSCALEYUV2YV12X(0)\n\n\t\t\t:: \"m\" (-lumFilterSize), \"r\" (lumSrc+lumFilterSize),\n\n\t\t\t \"r\" (lumMmxFilter+lumFilterSize*4), \"r\" (dest), \"m\" (dstW)\n\n\t\t\t: \"%eax\", \"%edx\", \"%esi\"\n\n\t\t);\n\n#else\n\n\t//FIXME Optimize (just quickly writen not opti..)\n\n\tint i;\n\n\tfor(i=0; i>19, 0), 255);\n\n\t}\n\n\n\n\tif(uDest != NULL)\n\n\t\tfor(i=0; i<(dstW>>1); i++)\n\n\t\t{\n\n\t\t\tint u=0;\n\n\t\t\tint v=0;\n\n\t\t\tint j;\n\n\t\t\tfor(j=0; j>19, 0), 255);\n\n\t\t\tvDest[i]= MIN(MAX(v>>19, 0), 255);\n\n\t\t}\n\n#endif\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "e3d2500fe498289a878b956f6efb4995438c9515", + "length": 599 + }, + { + "index": 11703, + "code": "static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n\tlong idx = 15 - src_size;\n\n\tuint8_t *s = (uint8_t *) src-idx, *d = dst-idx;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(\n\n\t\t\"test %0, %0\t\t\t\\n\\t\"\n\n\t\t\"jns 2f\t\t\t\t\\n\\t\"\n\n\t\tPREFETCH\" (%1, %0)\t\t\\n\\t\"\n\n\t\t\"movq %3, %%mm7\t\t\t\\n\\t\"\n\n\t\t\"pxor %4, %%mm7\t\t\t\\n\\t\"\n\n\t\t\"movq %%mm7, %%mm6\t\t\\n\\t\"\n\n\t\t\"pxor %5, %%mm7\t\t\t\\n\\t\"\n\n\t\tASMALIGN(4)\n\n\t\t\"1:\t\t\t\t\\n\\t\"\n\n\t\tPREFETCH\" 32(%1, %0)\t\t\\n\\t\"\n\n\t\t\"movq (%1, %0), %%mm0\t\t\\n\\t\"\n\n\t\t\"movq 8(%1, %0), %%mm1\t\t\\n\\t\"\n\n# ifdef HAVE_MMX2\n\n\t\t\"pshufw $177, %%mm0, %%mm3\t\\n\\t\"\n\n\t\t\"pshufw $177, %%mm1, %%mm5\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm0\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm3\t\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm5\t\t\\n\\t\"\n\n\t\t\"por %%mm3, %%mm0\t\t\\n\\t\"\n\n\t\t\"por %%mm5, %%mm1\t\t\\n\\t\"\n\n# else\n\n\t\t\"movq %%mm0, %%mm2\t\t\\n\\t\"\n\n\t\t\"movq %%mm1, %%mm4\t\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm0\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm2\t\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm4\t\t\\n\\t\"\n\n\t\t\"movq %%mm2, %%mm3\t\t\\n\\t\"\n\n\t\t\"movq %%mm4, %%mm5\t\t\\n\\t\"\n\n\t\t\"pslld $16, %%mm2\t\t\\n\\t\"\n\n\t\t\"psrld $16, %%mm3\t\t\\n\\t\"\n\n\t\t\"pslld $16, %%mm4\t\t\\n\\t\"\n\n\t\t\"psrld $16, %%mm5\t\t\\n\\t\"\n\n\t\t\"por %%mm2, %%mm0\t\t\\n\\t\"\n\n\t\t\"por %%mm4, %%mm1\t\t\\n\\t\"\n\n\t\t\"por %%mm3, %%mm0\t\t\\n\\t\"\n\n\t\t\"por %%mm5, %%mm1\t\t\\n\\t\"\n\n# endif\n\n\t\tMOVNTQ\" %%mm0, (%2, %0)\t\t\\n\\t\"\n\n\t\tMOVNTQ\" %%mm1, 8(%2, %0)\t\\n\\t\"\n\n\t\t\"add $16, %0\t\t\t\\n\\t\"\n\n\t\t\"js 1b\t\t\t\t\\n\\t\"\n\n\t\tSFENCE\"\t\t\t\t\\n\\t\"\n\n\t\tEMMS\"\t\t\t\t\\n\\t\"\n\n\t\t\"2:\t\t\t\t\\n\\t\"\n\n\t\t: \"+&r\"(idx)\n\n\t\t: \"r\" (s), \"r\" (d), \"m\" (mask32b), \"m\" (mask32r), \"m\" (mmx_one)\n\n\t\t: \"memory\");\n\n#endif\n\n\tfor (; idx<15; idx+=4) {\n\n\t\tregister int v = *(uint32_t *)&s[idx], g = v & 0xff00ff00;\n\n\t\tv &= 0xff00ff;\n\n\t\t*(uint32_t *)&d[idx] = (v>>16) + g + (v<<16);\n\n\t}\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "6e42e6c4b410dbef8b593c2d796a5dad95f89ee4", + "length": 903 + }, + { + "index": 17635, + "code": "static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)\n\n{\n\n PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);\n\n uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;\n\n\n\n trace_loadvm_postcopy_handle_advise();\n\n if (ps != POSTCOPY_INCOMING_NONE) {\n\n error_report(\"CMD_POSTCOPY_ADVISE in wrong postcopy state (%d)\", ps);\n\n return -1;\n\n }\n\n\n\n if (!migrate_postcopy_ram()) {\n\n return 0;\n\n }\n\n\n\n if (!postcopy_ram_supported_by_host()) {\n\n postcopy_state_set(POSTCOPY_INCOMING_NONE);\n\n return -1;\n\n }\n\n\n\n remote_pagesize_summary = qemu_get_be64(mis->from_src_file);\n\n local_pagesize_summary = ram_pagesize_summary();\n\n\n\n if (remote_pagesize_summary != local_pagesize_summary) {\n\n /*\n\n * This detects two potential causes of mismatch:\n\n * a) A mismatch in host page sizes\n\n * Some combinations of mismatch are probably possible but it gets\n\n * a bit more complicated. In particular we need to place whole\n\n * host pages on the dest at once, and we need to ensure that we\n\n * handle dirtying to make sure we never end up sending part of\n\n * a hostpage on it's own.\n\n * b) The use of different huge page sizes on source/destination\n\n * a more fine grain test is performed during RAM block migration\n\n * but this test here causes a nice early clear failure, and\n\n * also fails when passed to an older qemu that doesn't\n\n * do huge pages.\n\n */\n\n error_report(\"Postcopy needs matching RAM page sizes (s=%\" PRIx64\n\n \" d=%\" PRIx64 \")\",\n\n remote_pagesize_summary, local_pagesize_summary);\n\n return -1;\n\n }\n\n\n\n remote_tps = qemu_get_be64(mis->from_src_file);\n\n if (remote_tps != qemu_target_page_size()) {\n\n /*\n\n * Again, some differences could be dealt with, but for now keep it\n\n * simple.\n\n */\n\n error_report(\"Postcopy needs matching target page sizes (s=%d d=%zd)\",\n\n (int)remote_tps, qemu_target_page_size());\n\n return -1;\n\n }\n\n\n\n if (ram_postcopy_incoming_init(mis)) {\n\n return -1;\n\n }\n\n\n\n postcopy_state_set(POSTCOPY_INCOMING_ADVISE);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d7651f150d61936344c4fab45eaeb0716c606af2", + "length": 553 + }, + { + "index": 8511, + "code": "static void coroutine_fn v9fs_open(void *opaque)\n\n{\n\n int flags;\n\n int32_t fid;\n\n int32_t mode;\n\n V9fsQID qid;\n\n int iounit = 0;\n\n ssize_t err = 0;\n\n size_t offset = 7;\n\n struct stat stbuf;\n\n V9fsFidState *fidp;\n\n V9fsPDU *pdu = opaque;\n\n V9fsState *s = pdu->s;\n\n\n\n if (s->proto_version == V9FS_PROTO_2000L) {\n\n err = pdu_unmarshal(pdu, offset, \"dd\", &fid, &mode);\n\n } else {\n\n uint8_t modebyte;\n\n err = pdu_unmarshal(pdu, offset, \"db\", &fid, &modebyte);\n\n mode = modebyte;\n\n }\n\n if (err < 0) {\n\n goto out_nofid;\n\n }\n\n trace_v9fs_open(pdu->tag, pdu->id, fid, mode);\n\n\n\n fidp = get_fid(pdu, fid);\n\n if (fidp == NULL) {\n\n err = -ENOENT;\n\n goto out_nofid;\n\n }\n\n BUG_ON(fidp->fid_type != P9_FID_NONE);\n\n\n\n err = v9fs_co_lstat(pdu, &fidp->path, &stbuf);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n stat_to_qid(&stbuf, &qid);\n\n if (S_ISDIR(stbuf.st_mode)) {\n\n err = v9fs_co_opendir(pdu, fidp);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n fidp->fid_type = P9_FID_DIR;\n\n err = pdu_marshal(pdu, offset, \"Qd\", &qid, 0);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n err += offset;\n\n } else {\n\n if (s->proto_version == V9FS_PROTO_2000L) {\n\n flags = get_dotl_openflags(s, mode);\n\n } else {\n\n flags = omode_to_uflags(mode);\n\n }\n\n if (is_ro_export(&s->ctx)) {\n\n if (mode & O_WRONLY || mode & O_RDWR ||\n\n mode & O_APPEND || mode & O_TRUNC) {\n\n err = -EROFS;\n\n goto out;\n\n }\n\n }\n\n err = v9fs_co_open(pdu, fidp, flags);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n fidp->fid_type = P9_FID_FILE;\n\n fidp->open_flags = flags;\n\n if (flags & O_EXCL) {\n\n /*\n\n * We let the host file system do O_EXCL check\n\n * We should not reclaim such fd\n\n */\n\n fidp->flags |= FID_NON_RECLAIMABLE;\n\n }\n\n iounit = get_iounit(pdu, &fidp->path);\n\n err = pdu_marshal(pdu, offset, \"Qd\", &qid, iounit);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n err += offset;\n\n }\n\n trace_v9fs_open_return(pdu->tag, pdu->id,\n\n qid.type, qid.version, qid.path, iounit);\n\nout:\n\n put_fid(pdu, fidp);\n\nout_nofid:\n\n pdu_complete(pdu, err);\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "49dd946bb5419681c8668b09a6d10f42bc707b78", + "length": 745 + }, + { + "index": 16686, + "code": "static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst, int width, int height) {\n\n unsigned char *dst_end = dst + width*height;\n\n int size,size1,size2,offset,run;\n\n unsigned char *dst_start = dst;\n\n\n\n if (src[0] & 0x01)\n\n src += 5;\n\n else\n\n src += 2;\n\n\n\n if (src+3>src_end)\n\n return -1;\n\n size = AV_RB24(src);\n\n src += 3;\n\n\n\n while(size>0 && src> 6 );\n\n offset = (AV_RB16(&src[1]) & 0x3FFF) + 1;\n\n size2 = (src[0] & 0x3F) + 4;\n\n src += 3;\n\n }\n\n } else { // 0\n\n offset = ((src[0] & 0x60) << 3) + src[1] + 1;\n\n size2 = ((src[0] & 0x1C) >> 2) + 3;\n\n src += 2;\n\n }\n\n\n\n\n\n /* fetch strip from src */\n\n if (size1>src_end-src)\n\n break;\n\n\n\n if (size1>0) {\n\n size -= size1;\n\n run = FFMIN(size1, dst_end-dst);\n\n memcpy(dst, src, run);\n\n dst += run;\n\n src += run;\n\n }\n\n\n\n if (size2>0) {\n\n if (dst-dst_starteof_reached) {\n\n int size, subtype;\n\n\n\n frametype = avio_r8(pb);\n\n switch (frametype) {\n\n case NUV_EXTRADATA:\n\n subtype = avio_r8(pb);\n\n avio_skip(pb, 6);\n\n size = PKTSIZE(avio_rl32(pb));\n\n if (vst && subtype == 'R') {\n\n vst->codec->extradata_size = size;\n\n vst->codec->extradata = av_malloc(size);\n\n avio_read(pb, vst->codec->extradata, size);\n\n size = 0;\n\n if (!myth)\n\n return 1;\n\n }\n\n break;\n\n case NUV_MYTHEXT:\n\n avio_skip(pb, 7);\n\n size = PKTSIZE(avio_rl32(pb));\n\n if (size != 128 * 4)\n\n break;\n\n avio_rl32(pb); // version\n\n if (vst) {\n\n vst->codec->codec_tag = avio_rl32(pb);\n\n vst->codec->codec_id =\n\n ff_codec_get_id(ff_codec_bmp_tags, vst->codec->codec_tag);\n\n if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G'))\n\n vst->codec->codec_id = AV_CODEC_ID_NUV;\n\n } else\n\n avio_skip(pb, 4);\n\n\n\n if (ast) {\n\n int id;\n\n\n\n ast->codec->codec_tag = avio_rl32(pb);\n\n ast->codec->sample_rate = avio_rl32(pb);\n\n ast->codec->bits_per_coded_sample = avio_rl32(pb);\n\n ast->codec->channels = avio_rl32(pb);\n\n ast->codec->channel_layout = 0;\n\n\n\n id = ff_wav_codec_get_id(ast->codec->codec_tag,\n\n ast->codec->bits_per_coded_sample);\n\n if (id == AV_CODEC_ID_NONE) {\n\n id = ff_codec_get_id(nuv_audio_tags, ast->codec->codec_tag);\n\n if (id == AV_CODEC_ID_PCM_S16LE)\n\n id = ff_get_pcm_codec_id(ast->codec->bits_per_coded_sample,\n\n 0, 0, ~1);\n\n }\n\n ast->codec->codec_id = id;\n\n\n\n ast->need_parsing = AVSTREAM_PARSE_FULL;\n\n } else\n\n avio_skip(pb, 4 * 4);\n\n\n\n size -= 6 * 4;\n\n avio_skip(pb, size);\n\n return 1;\n\n case NUV_SEEKP:\n\n size = 11;\n\n break;\n\n default:\n\n avio_skip(pb, 7);\n\n size = PKTSIZE(avio_rl32(pb));\n\n break;\n\n }\n\n avio_skip(pb, size);\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ab87d9b6677c5757d467f532e681b056d3e77e6b", + "length": 667 + }, + { + "index": 3469, + "code": "static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)\n\n{\n\n VC1Context *v = avctx->priv_data;\n\n MpegEncContext *s = &v->s;\n\n\n\n NVDECContext *ctx = avctx->internal->hwaccel_priv_data;\n\n CUVIDPICPARAMS *pp = &ctx->pic_params;\n\n FrameDecodeData *fdd;\n\n NVDECFrame *cf;\n\n AVFrame *cur_frame = s->current_picture.f;\n\n\n\n int ret;\n\n\n\n ret = ff_nvdec_start_frame(avctx, cur_frame);\n\n if (ret < 0)\n\n return ret;\n\n\n\n fdd = (FrameDecodeData*)cur_frame->private_ref->data;\n\n cf = (NVDECFrame*)fdd->hwaccel_priv;\n\n\n\n *pp = (CUVIDPICPARAMS) {\n\n .PicWidthInMbs = (cur_frame->width + 15) / 16,\n\n .FrameHeightInMbs = (cur_frame->height + 15) / 16,\n\n .CurrPicIdx = cf->idx,\n\n .field_pic_flag = v->field_mode,\n\n .bottom_field_flag = v->cur_field_type,\n\n .second_field = v->second_field,\n\n\n\n .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||\n\n s->pict_type == AV_PICTURE_TYPE_BI,\n\n .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||\n\n s->pict_type == AV_PICTURE_TYPE_P,\n\n\n\n .CodecSpecific.vc1 = {\n\n .ForwardRefIdx = get_ref_idx(s->last_picture.f),\n\n .BackwardRefIdx = get_ref_idx(s->next_picture.f),\n\n .FrameWidth = cur_frame->width,\n\n .FrameHeight = cur_frame->height,\n\n\n\n .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||\n\n s->pict_type == AV_PICTURE_TYPE_BI,\n\n .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||\n\n s->pict_type == AV_PICTURE_TYPE_P,\n\n .progressive_fcm = v->fcm == 0,\n\n\n\n .profile = v->profile,\n\n .postprocflag = v->postprocflag,\n\n .pulldown = v->broadcast,\n\n .interlace = v->interlace,\n\n .tfcntrflag = v->tfcntrflag,\n\n .finterpflag = v->finterpflag,\n\n .psf = v->psf,\n\n .multires = v->multires,\n\n .syncmarker = v->resync_marker,\n\n .rangered = v->rangered,\n\n .maxbframes = s->max_b_frames,\n\n\n\n .panscan_flag = v->panscanflag,\n\n .refdist_flag = v->refdist_flag,\n\n .extended_mv = v->extended_mv,\n\n .dquant = v->dquant,\n\n .vstransform = v->vstransform,\n\n .loopfilter = v->s.loop_filter,\n\n .fastuvmc = v->fastuvmc,\n\n .overlap = v->overlap,\n\n .quantizer = v->quantizer_mode,\n\n .extended_dmv = v->extended_dmv,\n\n .range_mapy_flag = v->range_mapy_flag,\n\n .range_mapy = v->range_mapy,\n\n .range_mapuv_flag = v->range_mapuv_flag,\n\n .range_mapuv = v->range_mapuv,\n\n .rangeredfrm = v->rangeredfrm,\n\n }\n\n };\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "4c7b023d56e09a78a587d036db1b64bf7c493b3d", + "length": 829 + }, + { + "index": 4347, + "code": "static void fft(AC3MDCTContext *mdct, IComplex *z, int ln)\n\n{\n\n int j, l, np, np2;\n\n int nblocks, nloops;\n\n register IComplex *p,*q;\n\n int tmp_re, tmp_im;\n\n\n\n np = 1 << ln;\n\n\n\n /* reverse */\n\n for (j = 0; j < np; j++) {\n\n int k = av_reverse[j] >> (8 - ln);\n\n if (k < j)\n\n FFSWAP(IComplex, z[k], z[j]);\n\n }\n\n\n\n /* pass 0 */\n\n\n\n p = &z[0];\n\n j = np >> 1;\n\n do {\n\n BF(p[0].re, p[0].im, p[1].re, p[1].im,\n\n p[0].re, p[0].im, p[1].re, p[1].im);\n\n p += 2;\n\n } while (--j);\n\n\n\n /* pass 1 */\n\n\n\n p = &z[0];\n\n j = np >> 2;\n\n do {\n\n BF(p[0].re, p[0].im, p[2].re, p[2].im,\n\n p[0].re, p[0].im, p[2].re, p[2].im);\n\n BF(p[1].re, p[1].im, p[3].re, p[3].im,\n\n p[1].re, p[1].im, p[3].im, -p[3].re);\n\n p+=4;\n\n } while (--j);\n\n\n\n /* pass 2 .. ln-1 */\n\n\n\n nblocks = np >> 3;\n\n nloops = 1 << 2;\n\n np2 = np >> 1;\n\n do {\n\n p = z;\n\n q = z + nloops;\n\n for (j = 0; j < nblocks; j++) {\n\n BF(p->re, p->im, q->re, q->im,\n\n p->re, p->im, q->re, q->im);\n\n p++;\n\n q++;\n\n for(l = nblocks; l < np2; l += nblocks) {\n\n CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im, 15);\n\n BF(p->re, p->im, q->re, q->im,\n\n p->re, p->im, tmp_re, tmp_im);\n\n p++;\n\n q++;\n\n }\n\n p += nloops;\n\n q += nloops;\n\n }\n\n nblocks = nblocks >> 1;\n\n nloops = nloops << 1;\n\n } while (nblocks);\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "79997def65fd2313b48a5f3c3a884c6149ae9b5d", + "length": 607 + }, + { + "index": 7273, + "code": "static int vtenc_cm_to_avpacket(\n\n AVCodecContext *avctx,\n\n CMSampleBufferRef sample_buffer,\n\n AVPacket *pkt,\n\n ExtraSEI *sei)\n\n{\n\n VTEncContext *vtctx = avctx->priv_data;\n\n\n\n int status;\n\n bool is_key_frame;\n\n bool add_header;\n\n size_t length_code_size;\n\n size_t header_size = 0;\n\n size_t in_buf_size;\n\n size_t out_buf_size;\n\n size_t sei_nalu_size = 0;\n\n int64_t dts_delta;\n\n int64_t time_base_num;\n\n int nalu_count;\n\n CMTime pts;\n\n CMTime dts;\n\n CMVideoFormatDescriptionRef vid_fmt;\n\n\n\n\n\n vtenc_get_frame_info(sample_buffer, &is_key_frame);\n\n status = get_length_code_size(avctx, sample_buffer, &length_code_size);\n\n if (status) return status;\n\n\n\n add_header = is_key_frame && !(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER);\n\n\n\n if (add_header) {\n\n vid_fmt = CMSampleBufferGetFormatDescription(sample_buffer);\n\n if (!vid_fmt) {\n\n av_log(avctx, AV_LOG_ERROR, \"Cannot get format description.\\n\");\n\n return AVERROR_EXTERNAL;\n\n }\n\n\n\n int status = get_params_size(avctx, vid_fmt, &header_size);\n\n if (status) return status;\n\n }\n\n\n\n status = count_nalus(length_code_size, sample_buffer, &nalu_count);\n\n if(status)\n\n return status;\n\n\n\n if (sei) {\n\n sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;\n\n }\n\n\n\n in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);\n\n out_buf_size = header_size +\n\n in_buf_size +\n\n sei_nalu_size +\n\n nalu_count * ((int)sizeof(start_code) - (int)length_code_size);\n\n\n\n status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);\n\n if (status < 0)\n\n return status;\n\n\n\n if (add_header) {\n\n status = copy_param_sets(avctx, vid_fmt, pkt->data, out_buf_size);\n\n if(status) return status;\n\n }\n\n\n\n status = copy_replace_length_codes(\n\n avctx,\n\n length_code_size,\n\n sample_buffer,\n\n pkt->data + header_size,\n\n pkt->size - header_size - sei_nalu_size\n\n );\n\n\n\n if (status) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error copying packet data: %d\", status);\n\n return status;\n\n }\n\n\n\n if (sei_nalu_size > 0) {\n\n uint8_t *sei_nalu = pkt->data + pkt->size - sei_nalu_size;\n\n memcpy(sei_nalu, start_code, sizeof(start_code));\n\n sei_nalu += sizeof(start_code);\n\n sei_nalu[0] = H264_NAL_SEI;\n\n sei_nalu[1] = SEI_TYPE_USER_DATA_REGISTERED;\n\n sei_nalu[2] = sei->size;\n\n sei_nalu += 3;\n\n memcpy(sei_nalu, sei->data, sei->size);\n\n sei_nalu += sei->size;\n\n sei_nalu[0] = 1; // RBSP\n\n }\n\n\n\n if (is_key_frame) {\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n }\n\n\n\n pts = CMSampleBufferGetPresentationTimeStamp(sample_buffer);\n\n dts = CMSampleBufferGetDecodeTimeStamp (sample_buffer);\n\n\n\n if (CMTIME_IS_INVALID(dts)) {\n\n if (!vtctx->has_b_frames) {\n\n dts = pts;\n\n } else {\n\n av_log(avctx, AV_LOG_ERROR, \"DTS is invalid.\\n\");\n\n return AVERROR_EXTERNAL;\n\n }\n\n }\n\n\n\n dts_delta = vtctx->dts_delta >= 0 ? vtctx->dts_delta : 0;\n\n time_base_num = avctx->time_base.num;\n\n pkt->pts = pts.value / time_base_num;\n\n pkt->dts = dts.value / time_base_num - dts_delta;\n\n pkt->size = out_buf_size;\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "9875695e2ceec413f072ac2ef7e8fbc6a4980294", + "length": 901 + }, + { + "index": 5504, + "code": "static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)\n\n{\n\n XanContext *s = avctx->priv_data;\n\n uint8_t *U, *V;\n\n int val, uval, vval;\n\n int i, j;\n\n const uint8_t *src, *src_end;\n\n const uint8_t *table;\n\n int mode, offset, dec_size;\n\n\n\n if (!chroma_off)\n\n return 0;\n\n if (chroma_off + 4 >= bytestream2_get_bytes_left(&s->gb)) {\n\n av_log(avctx, AV_LOG_ERROR, \"Invalid chroma block position\\n\");\n\n return -1;\n\n }\n\n bytestream2_seek(&s->gb, chroma_off + 4, SEEK_SET);\n\n mode = bytestream2_get_le16(&s->gb);\n\n table = s->gb.buffer;\n\n offset = bytestream2_get_le16(&s->gb) * 2;\n\n\n\n if (offset >= bytestream2_get_bytes_left(&s->gb)) {\n\n av_log(avctx, AV_LOG_ERROR, \"Invalid chroma block offset\\n\");\n\n return -1;\n\n }\n\n\n\n bytestream2_skip(&s->gb, offset);\n\n memset(s->scratch_buffer, 0, s->buffer_size);\n\n dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);\n\n if (dec_size < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Chroma unpacking failed\\n\");\n\n return -1;\n\n }\n\n\n\n U = s->pic.data[1];\n\n V = s->pic.data[2];\n\n src = s->scratch_buffer;\n\n src_end = src + dec_size;\n\n if (mode) {\n\n for (j = 0; j < avctx->height >> 1; j++) {\n\n for (i = 0; i < avctx->width >> 1; i++) {\n\n val = *src++;\n\n if (val) {\n\n val = AV_RL16(table + (val << 1));\n\n uval = (val >> 3) & 0xF8;\n\n vval = (val >> 8) & 0xF8;\n\n U[i] = uval | (uval >> 5);\n\n V[i] = vval | (vval >> 5);\n\n }\n\n if (src == src_end)\n\n return 0;\n\n }\n\n U += s->pic.linesize[1];\n\n V += s->pic.linesize[2];\n\n }\n\n } else {\n\n uint8_t *U2 = U + s->pic.linesize[1];\n\n uint8_t *V2 = V + s->pic.linesize[2];\n\n\n\n for (j = 0; j < avctx->height >> 2; j++) {\n\n for (i = 0; i < avctx->width >> 1; i += 2) {\n\n val = *src++;\n\n if (val) {\n\n val = AV_RL16(table + (val << 1));\n\n uval = (val >> 3) & 0xF8;\n\n vval = (val >> 8) & 0xF8;\n\n U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5);\n\n V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);\n\n }\n\n }\n\n U += s->pic.linesize[1] * 2;\n\n V += s->pic.linesize[2] * 2;\n\n U2 += s->pic.linesize[1] * 2;\n\n V2 += s->pic.linesize[2] * 2;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "f77bfa837636a99a4034d31916a76f7d1688cf5a", + "length": 847 + }, + { + "index": 10221, + "code": "static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic,\n\n int trellis_node, int x, int y, int mbs_per_slice)\n\n{\n\n ProresContext *ctx = avctx->priv_data;\n\n int i, q, pq, xp, yp;\n\n const uint16_t *src;\n\n int slice_width_factor = av_log2(mbs_per_slice);\n\n int num_cblocks[MAX_PLANES], pwidth;\n\n int plane_factor[MAX_PLANES], is_chroma[MAX_PLANES];\n\n const int min_quant = ctx->profile_info->min_quant;\n\n const int max_quant = ctx->profile_info->max_quant;\n\n int error, bits, bits_limit;\n\n int mbs, prev, cur, new_score;\n\n int slice_bits[TRELLIS_WIDTH], slice_score[TRELLIS_WIDTH];\n\n\n\n mbs = x + mbs_per_slice;\n\n\n\n for (i = 0; i < ctx->num_planes; i++) {\n\n is_chroma[i] = (i == 1 || i == 2);\n\n plane_factor[i] = slice_width_factor + 2;\n\n if (is_chroma[i])\n\n plane_factor[i] += ctx->chroma_factor - 3;\n\n if (!is_chroma[i] || ctx->chroma_factor == CFACTOR_Y444) {\n\n xp = x << 4;\n\n yp = y << 4;\n\n num_cblocks[i] = 4;\n\n pwidth = avctx->width;\n\n } else {\n\n xp = x << 3;\n\n yp = y << 4;\n\n num_cblocks[i] = 2;\n\n pwidth = avctx->width >> 1;\n\n }\n\n src = (const uint16_t*)(pic->data[i] + yp * pic->linesize[i]) + xp;\n\n\n\n get_slice_data(ctx, src, pic->linesize[i], xp, yp,\n\n pwidth, avctx->height, ctx->blocks[i],\n\n mbs_per_slice, num_cblocks[i]);\n\n }\n\n\n\n for (q = min_quant; q <= max_quant; q++) {\n\n ctx->nodes[trellis_node + q].prev_node = -1;\n\n ctx->nodes[trellis_node + q].quant = q;\n\n }\n\n\n\n // todo: maybe perform coarser quantising to fit into frame size when needed\n\n for (q = min_quant; q <= max_quant; q++) {\n\n bits = 0;\n\n error = 0;\n\n for (i = 0; i < ctx->num_planes; i++) {\n\n bits += estimate_slice_plane(ctx, &error, i,\n\n src, pic->linesize[i],\n\n mbs_per_slice,\n\n num_cblocks[i], plane_factor[i],\n\n ctx->quants[q]);\n\n }\n\n if (bits > 65000 * 8) {\n\n error = SCORE_LIMIT;\n\n break;\n\n }\n\n slice_bits[q] = bits;\n\n slice_score[q] = error;\n\n }\n\n\n\n bits_limit = mbs * ctx->bits_per_mb;\n\n for (pq = min_quant; pq <= max_quant; pq++) {\n\n prev = trellis_node - TRELLIS_WIDTH + pq;\n\n\n\n for (q = min_quant; q <= max_quant; q++) {\n\n cur = trellis_node + q;\n\n\n\n bits = ctx->nodes[prev].bits + slice_bits[q];\n\n error = slice_score[q];\n\n if (bits > bits_limit)\n\n error = SCORE_LIMIT;\n\n\n\n if (ctx->nodes[prev].score < SCORE_LIMIT && error < SCORE_LIMIT)\n\n new_score = ctx->nodes[prev].score + error;\n\n else\n\n new_score = SCORE_LIMIT;\n\n if (ctx->nodes[cur].prev_node == -1 ||\n\n ctx->nodes[cur].score >= new_score) {\n\n\n\n ctx->nodes[cur].bits = bits;\n\n ctx->nodes[cur].score = new_score;\n\n ctx->nodes[cur].prev_node = prev;\n\n }\n\n }\n\n }\n\n\n\n error = ctx->nodes[trellis_node + min_quant].score;\n\n pq = trellis_node + min_quant;\n\n for (q = min_quant + 1; q <= max_quant; q++) {\n\n if (ctx->nodes[trellis_node + q].score <= error) {\n\n error = ctx->nodes[trellis_node + q].score;\n\n pq = trellis_node + q;\n\n }\n\n }\n\n\n\n return pq;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "6d702dc072ffc255cd0f709132e55661698313e7", + "length": 972 + }, + { + "index": 10502, + "code": "void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,\n\n uint8_t *segment, uint8_t *ref, int layout)\n\n{\n\n VP56RangeCoder *c = &s->c;\n\n\n\n if (s->segmentation.update_map)\n\n *segment = vp8_rac_get_tree(c, vp8_segmentid_tree, s->prob->segmentid);\n\n else if (s->segmentation.enabled)\n\n *segment = ref ? *ref : *segment;\n\n mb->segment = *segment;\n\n\n\n mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;\n\n\n\n if (s->keyframe) {\n\n mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra,\n\n vp8_pred16x16_prob_intra);\n\n\n\n if (mb->mode == MODE_I4x4) {\n\n decode_intra4x4_modes(s, c, mb, mb_x, 1, layout);\n\n } else {\n\n const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;\n\n if (s->mb_layout == 1)\n\n AV_WN32A(mb->intra4x4_pred_mode_top, modes);\n\n else\n\n AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);\n\n AV_WN32A(s->intra4x4_pred_mode_left, modes);\n\n }\n\n\n\n mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,\n\n vp8_pred8x8c_prob_intra);\n\n mb->ref_frame = VP56_FRAME_CURRENT;\n\n } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {\n\n // inter MB, 16.2\n\n if (vp56_rac_get_prob_branchy(c, s->prob->last))\n\n mb->ref_frame =\n\n vp56_rac_get_prob(c, s->prob->golden) ? VP56_FRAME_GOLDEN2 /* altref */\n\n : VP56_FRAME_GOLDEN;\n\n else\n\n mb->ref_frame = VP56_FRAME_PREVIOUS;\n\n s->ref_count[mb->ref_frame - 1]++;\n\n\n\n // motion vectors, 16.3\n\n decode_mvs(s, mb, mb_x, mb_y, layout);\n\n } else {\n\n // intra MB, 16.1\n\n mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);\n\n\n\n if (mb->mode == MODE_I4x4)\n\n decode_intra4x4_modes(s, c, mb, mb_x, 0, layout);\n\n\n\n mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,\n\n s->prob->pred8x8c);\n\n mb->ref_frame = VP56_FRAME_CURRENT;\n\n mb->partitioning = VP8_SPLITMVMODE_NONE;\n\n AV_ZERO32(&mb->bmv[0]);\n\n }\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "ac4b32df71bd932838043a4838b86d11e169707f", + "length": 702 + }, + { + "index": 7498, + "code": "static int qesd_init_out (HWVoiceOut *hw, audsettings_t *as)\n\n{\n\n ESDVoiceOut *esd = (ESDVoiceOut *) hw;\n\n audsettings_t obt_as = *as;\n\n int esdfmt = ESD_STREAM | ESD_PLAY;\n\n int err;\n\n sigset_t set, old_set;\n\n\n\n sigfillset (&set);\n\n\n\n esdfmt |= (as->nchannels == 2) ? ESD_STEREO : ESD_MONO;\n\n switch (as->fmt) {\n\n case AUD_FMT_S8:\n\n case AUD_FMT_U8:\n\n esdfmt |= ESD_BITS8;\n\n obt_as.fmt = AUD_FMT_U8;\n\n break;\n\n\n\n case AUD_FMT_S32:\n\n case AUD_FMT_U32:\n\n dolog (\"Will use 16 instead of 32 bit samples\\n\");\n\n\n\n case AUD_FMT_S16:\n\n case AUD_FMT_U16:\n\n deffmt:\n\n esdfmt |= ESD_BITS16;\n\n obt_as.fmt = AUD_FMT_S16;\n\n break;\n\n\n\n default:\n\n dolog (\"Internal logic error: Bad audio format %d\\n\", as->fmt);\n\n goto deffmt;\n\n\n\n }\n\n obt_as.endianness = AUDIO_HOST_ENDIANNESS;\n\n\n\n audio_pcm_init_info (&hw->info, &obt_as);\n\n\n\n hw->samples = conf.samples;\n\n esd->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);\n\n if (!esd->pcm_buf) {\n\n dolog (\"Could not allocate buffer (%d bytes)\\n\",\n\n hw->samples << hw->info.shift);\n\n return -1;\n\n }\n\n\n\n esd->fd = -1;\n\n err = pthread_sigmask (SIG_BLOCK, &set, &old_set);\n\n if (err) {\n\n qesd_logerr (err, \"pthread_sigmask failed\\n\");\n\n goto fail1;\n\n }\n\n\n\n esd->fd = esd_play_stream (esdfmt, as->freq, conf.dac_host, NULL);\n\n if (esd->fd < 0) {\n\n qesd_logerr (errno, \"esd_play_stream failed\\n\");\n\n goto fail2;\n\n }\n\n\n\n if (audio_pt_init (&esd->pt, qesd_thread_out, esd, AUDIO_CAP, AUDIO_FUNC)) {\n\n goto fail3;\n\n }\n\n\n\n err = pthread_sigmask (SIG_SETMASK, &old_set, NULL);\n\n if (err) {\n\n qesd_logerr (err, \"pthread_sigmask(restore) failed\\n\");\n\n }\n\n\n\n return 0;\n\n\n\n fail3:\n\n if (close (esd->fd)) {\n\n qesd_logerr (errno, \"%s: close on esd socket(%d) failed\\n\",\n\n AUDIO_FUNC, esd->fd);\n\n }\n\n esd->fd = -1;\n\n\n\n fail2:\n\n err = pthread_sigmask (SIG_SETMASK, &old_set, NULL);\n\n if (err) {\n\n qesd_logerr (err, \"pthread_sigmask(restore) failed\\n\");\n\n }\n\n\n\n fail1:\n\n qemu_free (esd->pcm_buf);\n\n esd->pcm_buf = NULL;\n\n return -1;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "1ea879e5580f63414693655fcf0328559cdce138", + "length": 694 + }, + { + "index": 4657, + "code": "static int field_end(H264Context *h, int in_setup)\n\n{\n\n MpegEncContext *const s = &h->s;\n\n AVCodecContext *const avctx = s->avctx;\n\n int err = 0;\n\n s->mb_y = 0;\n\n\n\n if (!in_setup && !s->dropable)\n\n ff_thread_report_progress(&s->current_picture_ptr->f,\n\n (16 * s->mb_height >> FIELD_PICTURE) - 1,\n\n s->picture_structure == PICT_BOTTOM_FIELD);\n\n\n\n if (CONFIG_H264_VDPAU_DECODER &&\n\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n\n ff_vdpau_h264_set_reference_frames(s);\n\n\n\n if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n\n if (!s->dropable) {\n\n err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n\n h->prev_poc_msb = h->poc_msb;\n\n h->prev_poc_lsb = h->poc_lsb;\n\n }\n\n h->prev_frame_num_offset = h->frame_num_offset;\n\n h->prev_frame_num = h->frame_num;\n\n h->outputed_poc = h->next_outputed_poc;\n\n }\n\n\n\n if (avctx->hwaccel) {\n\n if (avctx->hwaccel->end_frame(avctx) < 0)\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"hardware accelerator failed to decode picture\\n\");\n\n }\n\n\n\n if (CONFIG_H264_VDPAU_DECODER &&\n\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n\n ff_vdpau_h264_picture_complete(s);\n\n\n\n /*\n\n * FIXME: Error handling code does not seem to support interlaced\n\n * when slices span multiple rows\n\n * The ff_er_add_slice calls don't work right for bottom\n\n * fields; they cause massive erroneous error concealing\n\n * Error marking covers both fields (top and bottom).\n\n * This causes a mismatched s->error_count\n\n * and a bad error table. Further, the error count goes to\n\n * INT_MAX when called for bottom field, because mb_y is\n\n * past end by one (callers fault) and resync_mb_y != 0\n\n * causes problems for the first MB line, too.\n\n */\n\n if (!FIELD_PICTURE)\n\n ff_er_frame_end(s);\n\n\n\n ff_MPV_frame_end(s);\n\n\n\n h->current_slice = 0;\n\n\n\n return err;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "1e26a48fa23ef8e1cbc424667d387184d8155f15", + "length": 569 + }, + { + "index": 26376, + "code": "void opt_input_file(const char *filename)\n\n{\n\n AVFormatContext *ic;\n\n AVFormatParameters params, *ap = ¶ms;\n\n int err, i, ret, rfps;\n\n\n\n /* get default parameters from command line */\n\n memset(ap, 0, sizeof(*ap));\n\n ap->sample_rate = audio_sample_rate;\n\n ap->channels = audio_channels;\n\n ap->frame_rate = frame_rate;\n\n ap->width = frame_width;\n\n ap->height = frame_height;\n\n\n\n /* open the input file with generic libav function */\n\n err = av_open_input_file(&ic, filename, file_iformat, 0, ap);\n\n if (err < 0) {\n\n print_error(filename, err);\n\n exit(1);\n\n }\n\n \n\n /* If not enough info to get the stream parameters, we decode the\n\n first frames to get it. (used in mpeg case for example) */\n\n ret = av_find_stream_info(ic);\n\n if (ret < 0) {\n\n fprintf(stderr, \"%s: could not find codec parameters\\n\", filename);\n\n exit(1);\n\n }\n\n\n\n /* update the current parameters so that they match the one of the input stream */\n\n for(i=0;inb_streams;i++) {\n\n AVCodecContext *enc = &ic->streams[i]->codec;\n\n switch(enc->codec_type) {\n\n case CODEC_TYPE_AUDIO:\n\n //fprintf(stderr, \"\\nInput Audio channels: %d\", enc->channels);\n\n audio_channels = enc->channels;\n\n audio_sample_rate = enc->sample_rate;\n\n break;\n\n case CODEC_TYPE_VIDEO:\n\n frame_height = enc->height;\n\n frame_width = enc->width;\n\n rfps = ic->streams[i]->r_frame_rate;\n\n if (enc->frame_rate != rfps) {\n\n fprintf(stderr,\"\\nSeems that stream %d comes from film source: %2.2f->%2.2f\\n\",\n\n i, (float)enc->frame_rate / FRAME_RATE_BASE,\n\n (float)rfps / FRAME_RATE_BASE);\n\n }\n\n /* update the current frame rate to match the stream frame rate */\n\n frame_rate = rfps;\n\n break;\n\n default:\n\n abort();\n\n }\n\n }\n\n \n\n input_files[nb_input_files] = ic;\n\n /* dump the file content */\n\n dump_format(ic, nb_input_files, filename, 0);\n\n nb_input_files++;\n\n file_iformat = NULL;\n\n file_oformat = NULL;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "c04643a2c24564aed96a5b0760de8bf02eb305c6", + "length": 529 + }, + { + "index": 26587, + "code": "if_start(Slirp *slirp)\n\n{\n\n uint64_t now = qemu_get_clock_ns(rt_clock);\n\n int requeued = 0;\n\n\tstruct mbuf *ifm, *ifqt;\n\n\n\n\tDEBUG_CALL(\"if_start\");\n\n\n\n\tif (slirp->if_queued == 0)\n\n\t return; /* Nothing to do */\n\n\n\n again:\n\n /* check if we can really output */\n\n if (!slirp_can_output(slirp->opaque))\n\n return;\n\n\n\n\t/*\n\n\t * See which queue to get next packet from\n\n\t * If there's something in the fastq, select it immediately\n\n\t */\n\n\tif (slirp->if_fastq.ifq_next != &slirp->if_fastq) {\n\n\t\tifm = slirp->if_fastq.ifq_next;\n\n\t} else {\n\n\t\t/* Nothing on fastq, see if next_m is valid */\n\n\t\tif (slirp->next_m != &slirp->if_batchq)\n\n\t\t ifm = slirp->next_m;\n\n\t\telse\n\n\t\t ifm = slirp->if_batchq.ifq_next;\n\n\n\n\t\t/* Set which packet to send on next iteration */\n\n\t\tslirp->next_m = ifm->ifq_next;\n\n\t}\n\n\t/* Remove it from the queue */\n\n\tifqt = ifm->ifq_prev;\n\n\tremque(ifm);\n\n\tslirp->if_queued--;\n\n\n\n\t/* If there are more packets for this session, re-queue them */\n\n\tif (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) {\n\n\t\tinsque(ifm->ifs_next, ifqt);\n\n\t\tifs_remque(ifm);\n\n\t}\n\n\n\n\t/* Update so_queued */\n\n\tif (ifm->ifq_so) {\n\n\t\tif (--ifm->ifq_so->so_queued == 0)\n\n\t\t /* If there's no more queued, reset nqueued */\n\n\t\t ifm->ifq_so->so_nqueued = 0;\n\n\t}\n\n\n\n if (ifm->expiration_date < now) {\n\n /* Expired */\n\n m_free(ifm);\n\n } else {\n\n /* Encapsulate the packet for sending */\n\n if (if_encap(slirp, ifm)) {\n\n m_free(ifm);\n\n } else {\n\n /* re-queue */\n\n insque(ifm, ifqt);\n\n requeued++;\n\n }\n\n }\n\n\n\n\tif (slirp->if_queued)\n\n\t goto again;\n\n\n\n slirp->if_queued = requeued;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "b248ede2ef2792d364bd305e5e92e24921c924a8", + "length": 532 + }, + { + "index": 15924, + "code": "static void usb_uas_task(UASDevice *uas, uas_ui *ui)\n\n{\n\n uint16_t tag = be16_to_cpu(ui->hdr.tag);\n\n uint64_t lun64 = be64_to_cpu(ui->task.lun);\n\n SCSIDevice *dev = usb_uas_get_dev(uas, lun64);\n\n int lun = usb_uas_get_lun(lun64);\n\n UASRequest *req;\n\n uint16_t task_tag;\n\n\n\n req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag));\n\n if (req) {\n\n goto overlapped_tag;\n\n }\n\n\n\n switch (ui->task.function) {\n\n case UAS_TMF_ABORT_TASK:\n\n task_tag = be16_to_cpu(ui->task.task_tag);\n\n trace_usb_uas_tmf_abort_task(uas->dev.addr, tag, task_tag);\n\n if (dev == NULL) {\n\n goto bad_target;\n\n }\n\n if (dev->lun != lun) {\n\n goto incorrect_lun;\n\n }\n\n req = usb_uas_find_request(uas, task_tag);\n\n if (req && req->dev == dev) {\n\n scsi_req_cancel(req->req);\n\n }\n\n usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);\n\n break;\n\n\n\n case UAS_TMF_LOGICAL_UNIT_RESET:\n\n trace_usb_uas_tmf_logical_unit_reset(uas->dev.addr, tag, lun);\n\n if (dev == NULL) {\n\n goto bad_target;\n\n }\n\n if (dev->lun != lun) {\n\n goto incorrect_lun;\n\n }\n\n qdev_reset_all(&dev->qdev);\n\n usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);\n\n break;\n\n\n\n default:\n\n trace_usb_uas_tmf_unsupported(uas->dev.addr, tag, ui->task.function);\n\n usb_uas_queue_response(uas, tag, UAS_RC_TMF_NOT_SUPPORTED, 0);\n\n break;\n\n }\n\n return;\n\n\n\noverlapped_tag:\n\n usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0);\n\n return;\n\n\n\nbad_target:\n\n /* FIXME: correct? [see long comment in usb_uas_command()] */\n\n usb_uas_queue_response(uas, tag, UAS_RC_INVALID_INFO_UNIT, 0);\n\n return;\n\n\n\nincorrect_lun:\n\n usb_uas_queue_response(uas, tag, UAS_RC_INCORRECT_LUN, 0);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "5eb6d9e3ef1fac096ab5b3f5c14e1f4079dd7367", + "length": 539 + }, + { + "index": 6808, + "code": "static int tta_read_header(AVFormatContext *s)\n\n{\n\n TTAContext *c = s->priv_data;\n\n AVStream *st;\n\n int i, channels, bps, samplerate;\n\n uint64_t framepos, start_offset;\n\n uint32_t datalen;\n\n\n\n if (!av_dict_get(s->metadata, \"\", NULL, AV_DICT_IGNORE_SUFFIX))\n\n ff_id3v1_read(s);\n\n\n\n start_offset = avio_tell(s->pb);\n\n if (avio_rl32(s->pb) != AV_RL32(\"TTA1\"))\n\n return -1; // not tta file\n\n\n\n avio_skip(s->pb, 2); // FIXME: flags\n\n channels = avio_rl16(s->pb);\n\n bps = avio_rl16(s->pb);\n\n samplerate = avio_rl32(s->pb);\n\n if(samplerate <= 0 || samplerate > 1000000){\n\n av_log(s, AV_LOG_ERROR, \"nonsense samplerate\\n\");\n\n return -1;\n\n }\n\n\n\n datalen = avio_rl32(s->pb);\n\n if (!datalen) {\n\n av_log(s, AV_LOG_ERROR, \"invalid datalen\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n avio_skip(s->pb, 4); // header crc\n\n\n\n c->frame_size = samplerate * 256 / 245;\n\n c->last_frame_size = datalen % c->frame_size;\n\n if (!c->last_frame_size)\n\n c->last_frame_size = c->frame_size;\n\n c->totalframes = datalen / c->frame_size + (c->last_frame_size < c->frame_size);\n\n c->currentframe = 0;\n\n\n\n if(c->totalframes >= UINT_MAX/sizeof(uint32_t) || c->totalframes <= 0){\n\n av_log(s, AV_LOG_ERROR, \"totalframes %d invalid\\n\", c->totalframes);\n\n return -1;\n\n }\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n avpriv_set_pts_info(st, 64, 1, samplerate);\n\n st->start_time = 0;\n\n st->duration = datalen;\n\n\n\n framepos = avio_tell(s->pb) + 4*c->totalframes + 4;\n\n\n\n for (i = 0; i < c->totalframes; i++) {\n\n uint32_t size = avio_rl32(s->pb);\n\n av_add_index_entry(st, framepos, i * c->frame_size, size, 0,\n\n AVINDEX_KEYFRAME);\n\n framepos += size;\n\n }\n\n avio_skip(s->pb, 4); // seektable crc\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = AV_CODEC_ID_TTA;\n\n st->codec->channels = channels;\n\n st->codec->sample_rate = samplerate;\n\n st->codec->bits_per_coded_sample = bps;\n\n\n\n st->codec->extradata_size = avio_tell(s->pb) - start_offset;\n\n if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){\n\n //this check is redundant as avio_read should fail\n\n av_log(s, AV_LOG_ERROR, \"extradata_size too large\\n\");\n\n return -1;\n\n }\n\n st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata) {\n\n st->codec->extradata_size = 0;\n\n return AVERROR(ENOMEM);\n\n }\n\n avio_seek(s->pb, start_offset, SEEK_SET);\n\n avio_read(s->pb, st->codec->extradata, st->codec->extradata_size);\n\n\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "c4e0e314248865830ec073e5a3ef08e0a40aabf2", + "length": 833 + }, + { + "index": 20920, + "code": "static void tcx_update_display(void *opaque)\n\n{\n\n TCXState *ts = opaque;\n\n ram_addr_t page, page_min, page_max;\n\n int y, y_start, dd, ds;\n\n uint8_t *d, *s;\n\n void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width);\n\n\n\n if (ts->ds->depth == 0)\n\n return;\n\n\n\n page = ts->vram_offset;\n\n y_start = -1;\n\n page_min = 0xffffffff;\n\n page_max = 0;\n\n d = ts->ds->data;\n\n s = ts->vram;\n\n dd = ts->ds->linesize;\n\n ds = 1024;\n\n\n\n switch (ts->ds->depth) {\n\n case 32:\n\n f = tcx_draw_line32;\n\n break;\n\n case 15:\n\n case 16:\n\n f = tcx_draw_line16;\n\n break;\n\n default:\n\n case 8:\n\n f = tcx_draw_line8;\n\n break;\n\n case 0:\n\n return;\n\n }\n\n\n\n for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) {\n\n if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) {\n\n if (y_start < 0)\n\n y_start = y;\n\n if (page < page_min)\n\n page_min = page;\n\n if (page > page_max)\n\n page_max = page;\n\n f(ts, d, s, ts->width);\n\n d += dd;\n\n s += ds;\n\n f(ts, d, s, ts->width);\n\n d += dd;\n\n s += ds;\n\n f(ts, d, s, ts->width);\n\n d += dd;\n\n s += ds;\n\n f(ts, d, s, ts->width);\n\n d += dd;\n\n s += ds;\n\n } else {\n\n if (y_start >= 0) {\n\n /* flush to display */\n\n dpy_update(ts->ds, 0, y_start,\n\n ts->width, y - y_start);\n\n y_start = -1;\n\n }\n\n d += dd * 4;\n\n s += ds * 4;\n\n }\n\n }\n\n if (y_start >= 0) {\n\n /* flush to display */\n\n dpy_update(ts->ds, 0, y_start,\n\n ts->width, y - y_start);\n\n }\n\n /* reset modified pages */\n\n if (page_min <= page_max) {\n\n cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,\n\n VGA_DIRTY_FLAG);\n\n }\n\n}", + "label": 1, + "project": "qemu", + "commit_id": "33b6939fcb932a73965dc545c907f8e6bdd1b0cf", + "length": 569 + }, + { + "index": 11083, + "code": "static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame,\n\n AVPacket *avpkt)\n\n{\n\n KmvcContext *const ctx = avctx->priv_data;\n\n AVFrame *frame = data;\n\n uint8_t *out, *src;\n\n int i, ret;\n\n int header;\n\n int blocksize;\n\n const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);\n\n\n\n bytestream2_init(&ctx->g, avpkt->data, avpkt->size);\n\n\n\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)\n\n return ret;\n\n\n\n header = bytestream2_get_byte(&ctx->g);\n\n\n\n /* blocksize 127 is really palette change event */\n\n if (bytestream2_peek_byte(&ctx->g) == 127) {\n\n bytestream2_skip(&ctx->g, 3);\n\n for (i = 0; i < 127; i++) {\n\n ctx->pal[i + (header & 0x81)] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g);\n\n bytestream2_skip(&ctx->g, 1);\n\n }\n\n bytestream2_seek(&ctx->g, -127 * 4 - 3, SEEK_CUR);\n\n }\n\n\n\n if (header & KMVC_KEYFRAME) {\n\n frame->key_frame = 1;\n\n frame->pict_type = AV_PICTURE_TYPE_I;\n\n } else {\n\n frame->key_frame = 0;\n\n frame->pict_type = AV_PICTURE_TYPE_P;\n\n }\n\n\n\n if (header & KMVC_PALETTE) {\n\n frame->palette_has_changed = 1;\n\n // palette starts from index 1 and has 127 entries\n\n for (i = 1; i <= ctx->palsize; i++) {\n\n ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g);\n\n }\n\n }\n\n\n\n if (pal) {\n\n frame->palette_has_changed = 1;\n\n memcpy(ctx->pal, pal, AVPALETTE_SIZE);\n\n }\n\n\n\n if (ctx->setpal) {\n\n ctx->setpal = 0;\n\n frame->palette_has_changed = 1;\n\n }\n\n\n\n /* make the palette available on the way out */\n\n memcpy(frame->data[1], ctx->pal, 1024);\n\n\n\n blocksize = bytestream2_get_byte(&ctx->g);\n\n\n\n if (blocksize != 8 && blocksize != 127) {\n\n av_log(avctx, AV_LOG_ERROR, \"Block size = %i\\n\", blocksize);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n memset(ctx->cur, 0, 320 * 200);\n\n switch (header & KMVC_METHOD) {\n\n case 0:\n\n case 1: // used in palette changed event\n\n memcpy(ctx->cur, ctx->prev, 320 * 200);\n\n break;\n\n case 3:\n\n kmvc_decode_intra_8x8(ctx, avctx->width, avctx->height);\n\n break;\n\n case 4:\n\n kmvc_decode_inter_8x8(ctx, avctx->width, avctx->height);\n\n break;\n\n default:\n\n av_log(avctx, AV_LOG_ERROR, \"Unknown compression method %i\\n\", header & KMVC_METHOD);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n out = frame->data[0];\n\n src = ctx->cur;\n\n for (i = 0; i < avctx->height; i++) {\n\n memcpy(out, src, avctx->width);\n\n src += 320;\n\n out += frame->linesize[0];\n\n }\n\n\n\n /* flip buffers */\n\n if (ctx->cur == ctx->frm0) {\n\n ctx->cur = ctx->frm1;\n\n ctx->prev = ctx->frm0;\n\n } else {\n\n ctx->cur = ctx->frm0;\n\n ctx->prev = ctx->frm1;\n\n }\n\n\n\n *got_frame = 1;\n\n\n\n /* always report that the buffer was completely consumed */\n\n return avpkt->size;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "2d99101d0964f754822fb4af121c4abc69047dba", + "length": 901 + }, + { + "index": 10147, + "code": "static int w64_read_header(AVFormatContext *s)\n\n{\n\n int64_t size, data_ofs = 0;\n\n AVIOContext *pb = s->pb;\n\n WAVDemuxContext *wav = s->priv_data;\n\n AVStream *st;\n\n uint8_t guid[16];\n\n int ret;\n\n\n\n avio_read(pb, guid, 16);\n\n if (memcmp(guid, ff_w64_guid_riff, 16))\n\n\n\n\n /* riff + wave + fmt + sizes */\n\n if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8)\n\n\n\n\n avio_read(pb, guid, 16);\n\n if (memcmp(guid, ff_w64_guid_wave, 16)) {\n\n av_log(s, AV_LOG_ERROR, \"could not find wave guid\\n\");\n\n\n }\n\n\n\n wav->w64 = 1;\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n while (!avio_feof(pb)) {\n\n if (avio_read(pb, guid, 16) != 16)\n\n break;\n\n size = avio_rl64(pb);\n\n if (size <= 24 || INT64_MAX - size < avio_tell(pb))\n\n\n\n\n if (!memcmp(guid, ff_w64_guid_fmt, 16)) {\n\n /* subtract chunk header size - normal wav file doesn't count it */\n\n ret = ff_get_wav_header(s, pb, st->codecpar, size - 24, 0);\n\n if (ret < 0)\n\n return ret;\n\n avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);\n\n\n\n avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);\n\n } else if (!memcmp(guid, ff_w64_guid_fact, 16)) {\n\n int64_t samples;\n\n\n\n samples = avio_rl64(pb);\n\n if (samples > 0)\n\n st->duration = samples;\n\n } else if (!memcmp(guid, ff_w64_guid_data, 16)) {\n\n wav->data_end = avio_tell(pb) + size - 24;\n\n\n\n data_ofs = avio_tell(pb);\n\n if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))\n\n break;\n\n\n\n avio_skip(pb, size - 24);\n\n } else if (!memcmp(guid, ff_w64_guid_summarylist, 16)) {\n\n int64_t start, end, cur;\n\n uint32_t count, chunk_size, i;\n\n\n\n start = avio_tell(pb);\n\n end = start + FFALIGN(size, INT64_C(8)) - 24;\n\n count = avio_rl32(pb);\n\n\n\n for (i = 0; i < count; i++) {\n\n char chunk_key[5], *value;\n\n\n\n if (avio_feof(pb) || (cur = avio_tell(pb)) < 0 || cur > end - 8 /* = tag + size */)\n\n break;\n\n\n\n chunk_key[4] = 0;\n\n avio_read(pb, chunk_key, 4);\n\n chunk_size = avio_rl32(pb);\n\n\n\n\n\n value = av_mallocz(chunk_size + 1);\n\n if (!value)\n\n return AVERROR(ENOMEM);\n\n\n\n ret = avio_get_str16le(pb, chunk_size, value, chunk_size);\n\n avio_skip(pb, chunk_size - ret);\n\n\n\n av_dict_set(&s->metadata, chunk_key, value, AV_DICT_DONT_STRDUP_VAL);\n\n }\n\n\n\n avio_skip(pb, end - avio_tell(pb));\n\n } else {\n\n av_log(s, AV_LOG_DEBUG, \"unknown guid: \"FF_PRI_GUID\"\\n\", FF_ARG_GUID(guid));\n\n avio_skip(pb, FFALIGN(size, INT64_C(8)) - 24);\n\n }\n\n }\n\n\n\n if (!data_ofs)\n\n return AVERROR_EOF;\n\n\n\n ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);\n\n ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);\n\n\n\n handle_stream_probing(st);\n\n st->need_parsing = AVSTREAM_PARSE_FULL_RAW;\n\n\n\n avio_seek(pb, data_ofs, SEEK_SET);\n\n\n\n set_spdif(s, wav);\n\n\n\n return 0;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "3d232196372f309a75ed074c4cef30578eec1782", + "length": 916 + }, + { + "index": 26922, + "code": "static int decode_ref_pic_marking(H264Context *h, GetBitContext *gb){\n\n MpegEncContext * const s = &h->s;\n\n int i;\n\n\n\n\n if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields\n\n s->broken_link= get_bits1(gb) -1;\n\n h->mmco[0].long_arg= get_bits1(gb) - 1; // current_long_term_idx\n\n if(h->mmco[0].long_arg == -1)\n\n\n else{\n\n h->mmco[0].opcode= MMCO_LONG;\n\n h->mmco_index= 1;\n\n }\n\n }else{\n\n if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag\n\n for(i= 0; immco[i].opcode= opcode;\n\n if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){\n\n h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1);\n\n/* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){\n\n av_log(s->avctx, AV_LOG_ERROR, \"illegal short ref in memory management control operation %d\\n\", mmco);\n\n return -1;\n\n }*/\n\n }\n\n if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){\n\n unsigned int long_arg= get_ue_golomb(gb);\n\n if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){\n\n av_log(h->s.avctx, AV_LOG_ERROR, \"illegal long ref in memory management control operation %d\\n\", opcode);\n\n return -1;\n\n }\n\n h->mmco[i].long_arg= long_arg;\n\n }\n\n\n\n if(opcode > (unsigned)MMCO_LONG){\n\n av_log(h->s.avctx, AV_LOG_ERROR, \"illegal memory management control operation %d\\n\", opcode);\n\n return -1;\n\n }\n\n if(opcode == MMCO_END)\n\n break;\n\n }\n\n h->mmco_index= i;\n\n }else{\n\n assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count);\n\n\n\n if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count &&\n\n !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->reference)) {\n\n h->mmco[0].opcode= MMCO_SHORT2UNUSED;\n\n h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num;\n\n h->mmco_index= 1;\n\n if (FIELD_PICTURE) {\n\n h->mmco[0].short_pic_num *= 2;\n\n h->mmco[1].opcode= MMCO_SHORT2UNUSED;\n\n h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1;\n\n h->mmco_index= 2;\n\n }\n\n }else\n\n\n }\n\n }\n\n\n\n return 0;\n\n}", + "label": 1, + "project": "FFmpeg", + "commit_id": "d9fe1749fc1009b14252030dda9142de624670c0", + "length": 749 + }, + { + "index": 24288, + "code": "static int find_and_decode_index(NUTContext *nut){\n\n AVFormatContext *s= nut->avf;\n\n ByteIOContext *bc = s->pb;\n\n uint64_t tmp, end;\n\n int i, j, syncpoint_count;\n\n int64_t filesize= url_fsize(bc);\n\n int64_t *syncpoints;\n\n int8_t *has_keyframe;\n\n\n\n url_fseek(bc, filesize-12, SEEK_SET);\n\n url_fseek(bc, filesize-get_be64(bc), SEEK_SET);\n\n if(get_be64(bc) != INDEX_STARTCODE){\n\n av_log(s, AV_LOG_ERROR, \"no index at the end\\n\");\n\n return -1;\n\n }\n\n\n\n end= get_packetheader(nut, bc, 1, INDEX_STARTCODE);\n\n end += url_ftell(bc);\n\n\n\n ff_get_v(bc); //max_pts\n\n GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0)\n\n syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count);\n\n has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1));\n\n for(i=0; i0)\n\n if(i)\n\n syncpoints[i] += syncpoints[i-1];\n\n }\n\n\n\n for(i=0; inb_streams; i++){\n\n int64_t last_pts= -1;\n\n for(j=0; j>=1;\n\n if(type){\n\n int flag= x&1;\n\n x>>=1;\n\n if(n+x >= syncpoint_count + 1){\n\n av_log(s, AV_LOG_ERROR, \"index overflow A\\n\");\n\n return -1;\n\n }\n\n while(x--)\n\n has_keyframe[n++]= flag;\n\n has_keyframe[n++]= !flag;\n\n }else{\n\n while(x != 1){\n\n if(n>=syncpoint_count + 1){\n\n av_log(s, AV_LOG_ERROR, \"index overflow B\\n\");\n\n return -1;\n\n }\n\n has_keyframe[n++]= x&1;\n\n x>>=1;\n\n }\n\n }\n\n if(has_keyframe[0]){\n\n av_log(s, AV_LOG_ERROR, \"keyframe before first syncpoint in index\\n\");\n\n return -1;\n\n }\n\n assert(n<=syncpoint_count+1);\n\n for(; jstreams[i],\n\n 16*syncpoints[j-1],\n\n last_pts + A,\n\n 0,\n\n 0,\n\n AVINDEX_KEYFRAME);\n\n last_pts += A + B;\n\n }\n\n }\n\n }\n\n }\n\n\n\n if(skip_reserved(bc, end) || get_checksum(bc)){\n\n av_log(s, AV_LOG_ERROR, \"index checksum mismatch\\n\");\n\n return -1;\n\n }\n\n return 0;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "b19e3983cfb157751301aec87237ea28676665f0", + "length": 704 + }, + { + "index": 1889, + "code": "static void dvbsub_parse_region_segment(AVCodecContext *avctx,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n DVBSubContext *ctx = avctx->priv_data;\n\n\n\n const uint8_t *buf_end = buf + buf_size;\n\n int region_id, object_id;\n\n DVBSubRegion *region;\n\n DVBSubObject *object;\n\n DVBSubObjectDisplay *display;\n\n int fill;\n\n\n\n if (buf_size < 10)\n\n return;\n\n\n\n region_id = *buf++;\n\n\n\n region = get_region(ctx, region_id);\n\n\n\n if (!region) {\n\n region = av_mallocz(sizeof(DVBSubRegion));\n\n\n\n region->id = region_id;\n\n\n\n region->next = ctx->region_list;\n\n ctx->region_list = region;\n\n }\n\n\n\n fill = ((*buf++) >> 3) & 1;\n\n\n\n region->width = AV_RB16(buf);\n\n buf += 2;\n\n region->height = AV_RB16(buf);\n\n buf += 2;\n\n\n\n if (region->width * region->height != region->buf_size) {\n\n av_free(region->pbuf);\n\n\n\n region->buf_size = region->width * region->height;\n\n\n\n region->pbuf = av_malloc(region->buf_size);\n\n\n\n fill = 1;\n\n }\n\n\n\n region->depth = 1 << (((*buf++) >> 2) & 7);\n\n if(region->depth<2 || region->depth>8){\n\n av_log(avctx, AV_LOG_ERROR, \"region depth %d is invalid\\n\", region->depth);\n\n region->depth= 4;\n\n }\n\n region->clut = *buf++;\n\n\n\n if (region->depth == 8)\n\n region->bgcolor = *buf++;\n\n else {\n\n buf += 1;\n\n\n\n if (region->depth == 4)\n\n region->bgcolor = (((*buf++) >> 4) & 15);\n\n else\n\n region->bgcolor = (((*buf++) >> 2) & 3);\n\n }\n\n\n\n av_dlog(avctx, \"Region %d, (%dx%d)\\n\", region_id, region->width, region->height);\n\n\n\n if (fill) {\n\n memset(region->pbuf, region->bgcolor, region->buf_size);\n\n av_dlog(avctx, \"Fill region (%d)\\n\", region->bgcolor);\n\n }\n\n\n\n delete_region_display_list(ctx, region);\n\n\n\n while (buf + 5 < buf_end) {\n\n object_id = AV_RB16(buf);\n\n buf += 2;\n\n\n\n object = get_object(ctx, object_id);\n\n\n\n if (!object) {\n\n object = av_mallocz(sizeof(DVBSubObject));\n\n\n\n object->id = object_id;\n\n object->next = ctx->object_list;\n\n ctx->object_list = object;\n\n }\n\n\n\n object->type = (*buf) >> 6;\n\n\n\n display = av_mallocz(sizeof(DVBSubObjectDisplay));\n\n\n\n display->object_id = object_id;\n\n display->region_id = region_id;\n\n\n\n display->x_pos = AV_RB16(buf) & 0xfff;\n\n buf += 2;\n\n display->y_pos = AV_RB16(buf) & 0xfff;\n\n buf += 2;\n\n\n\n if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {\n\n display->fgcolor = *buf++;\n\n display->bgcolor = *buf++;\n\n }\n\n\n\n display->region_list_next = region->display_list;\n\n region->display_list = display;\n\n\n\n display->object_list_next = object->display_list;\n\n object->display_list = display;\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "607ad990d31e6be52980970e5ce8cd25ab3de812", + "length": 771 + }, + { + "index": 2165, + "code": "static void avc_wgt_16width_msa(uint8_t *data,\n\n int32_t stride,\n\n int32_t height,\n\n int32_t log2_denom,\n\n int32_t src_weight,\n\n int32_t offset_in)\n\n{\n\n uint8_t cnt;\n\n v16u8 zero = { 0 };\n\n v16u8 src0, src1, src2, src3;\n\n v16u8 dst0, dst1, dst2, dst3;\n\n v8u16 src0_l, src1_l, src2_l, src3_l;\n\n v8u16 src0_r, src1_r, src2_r, src3_r;\n\n v8u16 temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;\n\n v8u16 wgt, denom, offset;\n\n\n\n offset_in <<= (log2_denom);\n\n\n\n if (log2_denom) {\n\n offset_in += (1 << (log2_denom - 1));\n\n }\n\n\n\n wgt = (v8u16) __msa_fill_h(src_weight);\n\n offset = (v8u16) __msa_fill_h(offset_in);\n\n denom = (v8u16) __msa_fill_h(log2_denom);\n\n\n\n for (cnt = height / 4; cnt--;) {\n\n LOAD_4VECS_UB(data, stride, src0, src1, src2, src3);\n\n\n\n ILV_B_LRLR_UH(src0, zero, src1, zero, src0_l, src0_r, src1_l, src1_r);\n\n ILV_B_LRLR_UH(src2, zero, src3, zero, src2_l, src2_r, src3_l, src3_r);\n\n\n\n temp0 = wgt * src0_r;\n\n temp1 = wgt * src0_l;\n\n temp2 = wgt * src1_r;\n\n temp3 = wgt * src1_l;\n\n temp4 = wgt * src2_r;\n\n temp5 = wgt * src2_l;\n\n temp6 = wgt * src3_r;\n\n temp7 = wgt * src3_l;\n\n\n\n ADDS_S_H_4VECS_UH(temp0, offset, temp1, offset,\n\n temp2, offset, temp3, offset,\n\n temp0, temp1, temp2, temp3);\n\n\n\n ADDS_S_H_4VECS_UH(temp4, offset, temp5, offset,\n\n temp6, offset, temp7, offset,\n\n temp4, temp5, temp6, temp7);\n\n\n\n MAXI_S_H_4VECS_UH(temp0, temp1, temp2, temp3, 0);\n\n MAXI_S_H_4VECS_UH(temp4, temp5, temp6, temp7, 0);\n\n\n\n SRL_H_4VECS_UH(temp0, temp1, temp2, temp3,\n\n temp0, temp1, temp2, temp3, denom);\n\n\n\n SRL_H_4VECS_UH(temp4, temp5, temp6, temp7,\n\n temp4, temp5, temp6, temp7, denom);\n\n\n\n SAT_U_H_4VECS_UH(temp0, temp1, temp2, temp3, 7);\n\n SAT_U_H_4VECS_UH(temp4, temp5, temp6, temp7, 7);\n\n\n\n PCKEV_B_4VECS_UB(temp1, temp3, temp5, temp7, temp0, temp2, temp4, temp6,\n\n dst0, dst1, dst2, dst3);\n\n\n\n STORE_4VECS_UB(data, stride, dst0, dst1, dst2, dst3);\n\n data += 4 * stride;\n\n }\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "bcd7bf7eeb09a395cc01698842d1b8be9af483fc", + "length": 824 + }, + { + "index": 525, + "code": "static MMSSCPacketType get_tcp_server_response(MMSContext *mms)\n\n{\n\n int read_result;\n\n MMSSCPacketType packet_type= -1;\n\n\n\n for(;;) {\n\n if((read_result= url_read_complete(mms->mms_hd, mms->in_buffer, 8))==8) {\n\n // handle command packet.\n\n if(AV_RL32(mms->in_buffer + 4)==0xb00bface) {\n\n mms->incoming_flags= mms->in_buffer[3];\n\n read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4);\n\n if(read_result == 4) {\n\n int length_remaining= AV_RL32(mms->in_buffer+8) + 4;\n\n int hr;\n\n\n\n dprintf(NULL, \"Length remaining is %d\\n\", length_remaining);\n\n // read the rest of the packet.\n\n if (length_remaining < 0\n\n || length_remaining > sizeof(mms->in_buffer) - 12) {\n\n dprintf(NULL, \"Incoming message len %d exceeds buffer len %d\\n\",\n\n length_remaining, sizeof(mms->in_buffer) - 12);\n\n\n\n read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12,\n\n length_remaining) ;\n\n if (read_result == length_remaining) {\n\n packet_type= AV_RL16(mms->in_buffer+36);\n\n } else {\n\n dprintf(NULL, \"read for packet type failed%d!\\n\", read_result);\n\n\n\n\n\n\n\n\n } else {\n\n dprintf(NULL, \"read for length remaining failed%d!\\n\", read_result);\n\n\n\n } else {\n\n int length_remaining;\n\n int packet_id_type;\n\n int tmp;\n\n\n\n assert(mms->remaining_in_len==0);\n\n\n\n // note we cache the first 8 bytes,\n\n // then fill up the buffer with the others\n\n tmp = AV_RL16(mms->in_buffer + 6);\n\n length_remaining = (tmp - 8) & 0xffff;\n\n mms->incoming_packet_seq = AV_RL32(mms->in_buffer);\n\n packet_id_type = mms->in_buffer[4];\n\n mms->incoming_flags = mms->in_buffer[5];\n\n\n\n if (length_remaining < 0\n\n || length_remaining > sizeof(mms->in_buffer) - 8) {\n\n dprintf(NULL, \"Incoming data len %d exceeds buffer len %d\\n\",\n\n length_remaining, sizeof(mms->in_buffer));\n\n\n\n mms->remaining_in_len = length_remaining;\n\n mms->read_in_ptr = mms->in_buffer;\n\n read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);\n\n if(read_result != length_remaining) {\n\n dprintf(NULL, \"read_bytes result: %d asking for %d\\n\",\n\n read_result, length_remaining);\n\n\n } else {\n\n // if we successfully read everything.\n\n if(packet_id_type == mms->header_packet_id) {\n\n packet_type = SC_PKT_ASF_HEADER;\n\n // Store the asf header\n\n if(!mms->header_parsed) {\n\n void *p = av_realloc(mms->asf_header,\n\n mms->asf_header_size\n\n + mms->remaining_in_len);\n\n if (!p) {\n\n av_freep(&mms->asf_header);\n\n return AVERROR(ENOMEM);\n\n\n mms->asf_header = p;\n\n memcpy(mms->asf_header + mms->asf_header_size,\n\n mms->read_in_ptr,\n\n mms->remaining_in_len);\n\n mms->asf_header_size += mms->remaining_in_len;\n\n\n } else if(packet_id_type == mms->packet_id) {\n\n packet_type = SC_PKT_ASF_MEDIA;\n\n } else {\n\n dprintf(NULL, \"packet id type %d is old.\", packet_id_type);\n\n continue;\n\n\n\n\n\n\n // preprocess some packet type\n\n if(packet_type == SC_PKT_KEEPALIVE) {\n\n send_keepalive_packet(mms);\n\n continue;\n\n } else if(packet_type == SC_PKT_STREAM_CHANGING) {\n\n handle_packet_stream_changing_type(mms);\n\n } else if(packet_type == SC_PKT_ASF_MEDIA) {\n\n pad_media_packet(mms);\n\n\n return packet_type;\n\n } else {\n\n if(read_result<0) {\n\n dprintf(NULL, \"Read error (or cancelled) returned %d!\\n\", read_result);\n\n packet_type = SC_PKT_CANCEL;\n\n } else {\n\n dprintf(NULL, \"Read result of zero?!\\n\");\n\n packet_type = SC_PKT_NO_DATA;\n\n\n return packet_type;\n\n\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "9078eba062f5e0463d4029aa42b7b0026f42bed3", + "length": 1007 + }, + { + "index": 16306, + "code": "static void IRQ_local_pipe(OpenPICState *opp, int n_CPU, int n_IRQ)\n\n{\n\n IRQDest *dst;\n\n IRQSource *src;\n\n int priority;\n\n\n\n dst = &opp->dst[n_CPU];\n\n src = &opp->src[n_IRQ];\n\n\n\n if (src->output != OPENPIC_OUTPUT_INT) {\n\n /* On Freescale MPIC, critical interrupts ignore priority,\n\n * IACK, EOI, etc. Before MPIC v4.1 they also ignore\n\n * masking.\n\n */\n\n src->ivpr |= IVPR_ACTIVITY_MASK;\n\n DPRINTF(\"%s: Raise OpenPIC output %d cpu %d irq %d\\n\",\n\n __func__, src->output, n_CPU, n_IRQ);\n\n qemu_irq_raise(opp->dst[n_CPU].irqs[src->output]);\n\n return;\n\n }\n\n\n\n priority = IVPR_PRIORITY(src->ivpr);\n\n if (priority <= dst->ctpr) {\n\n /* Too low priority */\n\n DPRINTF(\"%s: IRQ %d has too low priority on CPU %d\\n\",\n\n __func__, n_IRQ, n_CPU);\n\n return;\n\n }\n\n if (IRQ_testbit(&dst->raised, n_IRQ)) {\n\n /* Interrupt miss */\n\n DPRINTF(\"%s: IRQ %d was missed on CPU %d\\n\",\n\n __func__, n_IRQ, n_CPU);\n\n return;\n\n }\n\n src->ivpr |= IVPR_ACTIVITY_MASK;\n\n IRQ_setbit(&dst->raised, n_IRQ);\n\n if (priority < dst->raised.priority) {\n\n /* An higher priority IRQ is already raised */\n\n DPRINTF(\"%s: IRQ %d is hidden by raised IRQ %d on CPU %d\\n\",\n\n __func__, n_IRQ, dst->raised.next, n_CPU);\n\n return;\n\n }\n\n IRQ_check(opp, &dst->raised);\n\n if (IRQ_get_next(opp, &dst->servicing) != -1 &&\n\n priority <= dst->servicing.priority) {\n\n DPRINTF(\"%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\\n\",\n\n __func__, n_IRQ, dst->servicing.next, n_CPU);\n\n /* Already servicing a higher priority IRQ */\n\n return;\n\n }\n\n DPRINTF(\"Raise OpenPIC INT output cpu %d irq %d\\n\", n_CPU, n_IRQ);\n\n qemu_irq_raise(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]);\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "9f1d4b1d6939d39fe570d886f6a651f4764bcbcb", + "length": 517 + }, + { + "index": 8686, + "code": "int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n AVStream *st;\n enum CodecID id;\n st = avformat_new_stream(s, NULL);\n if (!st)\n return AVERROR(ENOMEM);\n id = s->iformat->value;\n if (id == CODEC_ID_RAWVIDEO) {\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n } else {\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_id = id;\n switch(st->codec->codec_type) {\n case AVMEDIA_TYPE_AUDIO: {\n RawAudioDemuxerContext *s1 = s->priv_data;\n st->codec->channels = 1;\n if (id == CODEC_ID_ADPCM_G722)\n st->codec->sample_rate = 16000;\n if (s1 && s1->sample_rate)\n st->codec->sample_rate = s1->sample_rate;\n if (s1 && s1->channels)\n st->codec->channels = s1->channels;\n st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);\n assert(st->codec->bits_per_coded_sample > 0);\n st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;\n av_set_pts_info(st, 64, 1, st->codec->sample_rate);\n break;\n case AVMEDIA_TYPE_VIDEO: {\n FFRawVideoDemuxerContext *s1 = s->priv_data;\n int width = 0, height = 0, ret = 0;\n enum PixelFormat pix_fmt;\n AVRational framerate;\n if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {\n av_log(s, AV_LOG_ERROR, \"Couldn't parse video size.\\n\");\n goto fail;\n if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) {\n av_log(s, AV_LOG_ERROR, \"No such pixel format: %s.\\n\", s1->pixel_format);\n ret = AVERROR(EINVAL);\n goto fail;\n if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {\n av_log(s, AV_LOG_ERROR, \"Could not parse framerate: %s.\\n\", s1->framerate);\n goto fail;\n av_set_pts_info(st, 64, framerate.den, framerate.num);\n st->codec->width = width;\n st->codec->height = height;\n st->codec->pix_fmt = pix_fmt;\nfail:\n return ret;\n default:\n return -1;\n return 0;", + "label": 1, + "project": "FFmpeg", + "commit_id": "aa638b4600e1fa7a1b64323b8228c459af644a47", + "length": 616 + }, + { + "index": 13124, + "code": "void main_loop_wait(int nonblocking)\n\n{\n\n IOHandlerRecord *ioh;\n\n fd_set rfds, wfds, xfds;\n\n int ret, nfds;\n\n struct timeval tv;\n\n int timeout;\n\n\n\n if (nonblocking)\n\n timeout = 0;\n\n else {\n\n timeout = qemu_calculate_timeout();\n\n qemu_bh_update_timeout(&timeout);\n\n }\n\n\n\n os_host_main_loop_wait(&timeout);\n\n\n\n /* poll any events */\n\n /* XXX: separate device handlers from system ones */\n\n nfds = -1;\n\n FD_ZERO(&rfds);\n\n FD_ZERO(&wfds);\n\n FD_ZERO(&xfds);\n\n QLIST_FOREACH(ioh, &io_handlers, next) {\n\n if (ioh->deleted)\n\n continue;\n\n if (ioh->fd_read &&\n\n (!ioh->fd_read_poll ||\n\n ioh->fd_read_poll(ioh->opaque) != 0)) {\n\n FD_SET(ioh->fd, &rfds);\n\n if (ioh->fd > nfds)\n\n nfds = ioh->fd;\n\n }\n\n if (ioh->fd_write) {\n\n FD_SET(ioh->fd, &wfds);\n\n if (ioh->fd > nfds)\n\n nfds = ioh->fd;\n\n }\n\n }\n\n\n\n tv.tv_sec = timeout / 1000;\n\n tv.tv_usec = (timeout % 1000) * 1000;\n\n\n\n slirp_select_fill(&nfds, &rfds, &wfds, &xfds);\n\n\n\n qemu_mutex_unlock_iothread();\n\n ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);\n\n qemu_mutex_lock_iothread();\n\n if (ret > 0) {\n\n IOHandlerRecord *pioh;\n\n\n\n QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {\n\n if (ioh->deleted) {\n\n QLIST_REMOVE(ioh, next);\n\n qemu_free(ioh);\n\n continue;\n\n }\n\n if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {\n\n ioh->fd_read(ioh->opaque);\n\n }\n\n if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {\n\n ioh->fd_write(ioh->opaque);\n\n }\n\n }\n\n }\n\n\n\n slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));\n\n\n\n qemu_run_all_timers();\n\n\n\n /* Check bottom-halves last in case any of the earlier events triggered\n\n them. */\n\n qemu_bh_poll();\n\n\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "0290b57bdfec83ca78b6d119ea9847bb17943328", + "length": 563 + }, + { + "index": 1181, + "code": "int kvm_cpu_exec(CPUState *cpu)\n\n{\n\n struct kvm_run *run = cpu->kvm_run;\n\n int ret, run_ret;\n\n\n\n DPRINTF(\"kvm_cpu_exec()\\n\");\n\n\n\n if (kvm_arch_process_async_events(cpu)) {\n\n cpu->exit_request = 0;\n\n return EXCP_HLT;\n\n }\n\n\n\n do {\n\n MemTxAttrs attrs;\n\n\n\n if (cpu->kvm_vcpu_dirty) {\n\n kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE);\n\n cpu->kvm_vcpu_dirty = false;\n\n }\n\n\n\n kvm_arch_pre_run(cpu, run);\n\n if (cpu->exit_request) {\n\n DPRINTF(\"interrupt exit requested\\n\");\n\n /*\n\n * KVM requires us to reenter the kernel after IO exits to complete\n\n * instruction emulation. This self-signal will ensure that we\n\n * leave ASAP again.\n\n */\n\n qemu_cpu_kick_self();\n\n }\n\n qemu_mutex_unlock_iothread();\n\n\n\n run_ret = kvm_vcpu_ioctl(cpu, KVM_RUN, 0);\n\n\n\n qemu_mutex_lock_iothread();\n\n attrs = kvm_arch_post_run(cpu, run);\n\n\n\n if (run_ret < 0) {\n\n if (run_ret == -EINTR || run_ret == -EAGAIN) {\n\n DPRINTF(\"io window exit\\n\");\n\n ret = EXCP_INTERRUPT;\n\n break;\n\n }\n\n fprintf(stderr, \"error: kvm run failed %s\\n\",\n\n strerror(-run_ret));\n\n#ifdef TARGET_PPC\n\n if (run_ret == -EBUSY) {\n\n fprintf(stderr,\n\n \"This is probably because your SMT is enabled.\\n\"\n\n \"VCPU can only run on primary threads with all \"\n\n \"secondary threads offline.\\n\");\n\n }\n\n#endif\n\n ret = -1;\n\n break;\n\n }\n\n\n\n trace_kvm_run_exit(cpu->cpu_index, run->exit_reason);\n\n switch (run->exit_reason) {\n\n case KVM_EXIT_IO:\n\n DPRINTF(\"handle_io\\n\");\n\n kvm_handle_io(run->io.port, attrs,\n\n (uint8_t *)run + run->io.data_offset,\n\n run->io.direction,\n\n run->io.size,\n\n run->io.count);\n\n ret = 0;\n\n break;\n\n case KVM_EXIT_MMIO:\n\n DPRINTF(\"handle_mmio\\n\");\n\n address_space_rw(&address_space_memory,\n\n run->mmio.phys_addr, attrs,\n\n run->mmio.data,\n\n run->mmio.len,\n\n run->mmio.is_write);\n\n ret = 0;\n\n break;\n\n case KVM_EXIT_IRQ_WINDOW_OPEN:\n\n DPRINTF(\"irq_window_open\\n\");\n\n ret = EXCP_INTERRUPT;\n\n break;\n\n case KVM_EXIT_SHUTDOWN:\n\n DPRINTF(\"shutdown\\n\");\n\n qemu_system_reset_request();\n\n ret = EXCP_INTERRUPT;\n\n break;\n\n case KVM_EXIT_UNKNOWN:\n\n fprintf(stderr, \"KVM: unknown exit, hardware reason %\" PRIx64 \"\\n\",\n\n (uint64_t)run->hw.hardware_exit_reason);\n\n ret = -1;\n\n break;\n\n case KVM_EXIT_INTERNAL_ERROR:\n\n ret = kvm_handle_internal_error(cpu, run);\n\n break;\n\n case KVM_EXIT_SYSTEM_EVENT:\n\n switch (run->system_event.type) {\n\n case KVM_SYSTEM_EVENT_SHUTDOWN:\n\n qemu_system_shutdown_request();\n\n ret = EXCP_INTERRUPT;\n\n break;\n\n case KVM_SYSTEM_EVENT_RESET:\n\n qemu_system_reset_request();\n\n ret = EXCP_INTERRUPT;\n\n break;\n\n default:\n\n DPRINTF(\"kvm_arch_handle_exit\\n\");\n\n ret = kvm_arch_handle_exit(cpu, run);\n\n break;\n\n }\n\n break;\n\n default:\n\n DPRINTF(\"kvm_arch_handle_exit\\n\");\n\n ret = kvm_arch_handle_exit(cpu, run);\n\n break;\n\n }\n\n } while (ret == 0);\n\n\n\n if (ret < 0) {\n\n cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_CODE);\n\n vm_stop(RUN_STATE_INTERNAL_ERROR);\n\n }\n\n\n\n cpu->exit_request = 0;\n\n return ret;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "4b8523ee896750c37b4fa224a40d34703cbdf4c6", + "length": 858 + }, + { + "index": 17429, + "code": "static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track)\n\n{\n\n int i;\n\n avio_wb32(pb, 24); /* size */\n\n ffio_wfourcc(pb, \"ACLR\");\n\n ffio_wfourcc(pb, \"ACLR\");\n\n ffio_wfourcc(pb, \"0001\");\n\n if (track->enc->color_range == AVCOL_RANGE_MPEG || /* Legal range (16-235) */\n\n track->enc->color_range == AVCOL_RANGE_UNSPECIFIED) {\n\n avio_wb32(pb, 1); /* Corresponds to 709 in official encoder */\n\n } else { /* Full range (0-255) */\n\n avio_wb32(pb, 2); /* Corresponds to RGB in official encoder */\n\n }\n\n avio_wb32(pb, 0); /* unknown */\n\n\n\n avio_wb32(pb, 24); /* size */\n\n ffio_wfourcc(pb, \"APRG\");\n\n ffio_wfourcc(pb, \"APRG\");\n\n ffio_wfourcc(pb, \"0001\");\n\n avio_wb32(pb, 1); /* unknown */\n\n avio_wb32(pb, 0); /* unknown */\n\n\n\n avio_wb32(pb, 120); /* size */\n\n ffio_wfourcc(pb, \"ARES\");\n\n ffio_wfourcc(pb, \"ARES\");\n\n ffio_wfourcc(pb, \"0001\");\n\n avio_wb32(pb, AV_RB32(track->vos_data + 0x28)); /* dnxhd cid, some id ? */\n\n avio_wb32(pb, track->enc->width);\n\n /* values below are based on samples created with quicktime and avid codecs */\n\n if (track->vos_data[5] & 2) { // interlaced\n\n avio_wb32(pb, track->enc->height / 2);\n\n avio_wb32(pb, 2); /* unknown */\n\n avio_wb32(pb, 0); /* unknown */\n\n avio_wb32(pb, 4); /* unknown */\n\n } else {\n\n avio_wb32(pb, track->enc->height);\n\n avio_wb32(pb, 1); /* unknown */\n\n avio_wb32(pb, 0); /* unknown */\n\n if (track->enc->height == 1080)\n\n avio_wb32(pb, 5); /* unknown */\n\n else\n\n avio_wb32(pb, 6); /* unknown */\n\n }\n\n /* padding */\n\n for (i = 0; i < 10; i++)\n\n avio_wb64(pb, 0);\n\n\n\n /* extra padding for stsd needed */\n\n avio_wb32(pb, 0);\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "31c7c0e156975be615479948824c1528952c0731", + "length": 603 + }, + { + "index": 5264, + "code": "const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,\n\n int *dst_length, int *consumed, int length)\n\n{\n\n int i, si, di;\n\n uint8_t *dst;\n\n int bufidx;\n\n\n\n // src[0]&0x80; // forbidden bit\n\n h->nal_ref_idc = src[0] >> 5;\n\n h->nal_unit_type = src[0] & 0x1F;\n\n\n\n src++;\n\n length--;\n\n\n\n#define STARTCODE_TEST \\\n\n if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \\\n\n if (src[i + 2] != 3) { \\\n\n /* startcode, so we must be past the end */ \\\n\n length = i; \\\n\n } \\\n\n break; \\\n\n }\n\n\n\n#if HAVE_FAST_UNALIGNED\n\n#define FIND_FIRST_ZERO \\\n\n if (i > 0 && !src[i]) \\\n\n i--; \\\n\n while (src[i]) \\\n\n i++\n\n\n\n#if HAVE_FAST_64BIT\n\n for (i = 0; i + 1 < length; i += 9) {\n\n if (!((~AV_RN64A(src + i) &\n\n (AV_RN64A(src + i) - 0x0100010001000101ULL)) &\n\n 0x8000800080008080ULL))\n\n continue;\n\n FIND_FIRST_ZERO;\n\n STARTCODE_TEST;\n\n i -= 7;\n\n }\n\n#else\n\n for (i = 0; i + 1 < length; i += 5) {\n\n if (!((~AV_RN32A(src + i) &\n\n (AV_RN32A(src + i) - 0x01000101U)) &\n\n 0x80008080U))\n\n continue;\n\n FIND_FIRST_ZERO;\n\n STARTCODE_TEST;\n\n i -= 3;\n\n }\n\n#endif\n\n#else\n\n for (i = 0; i + 1 < length; i += 2) {\n\n if (src[i])\n\n continue;\n\n if (i > 0 && src[i - 1] == 0)\n\n i--;\n\n STARTCODE_TEST;\n\n }\n\n#endif\n\n\n\n if (i >= length - 1) { // no escaped 0\n\n *dst_length = length;\n\n *consumed = length + 1; // +1 for the header\n\n return src;\n\n }\n\n\n\n // use second escape buffer for inter data\n\n bufidx = h->nal_unit_type == NAL_DPC ? 1 : 0;\n\n av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx],\n\n length + FF_INPUT_BUFFER_PADDING_SIZE);\n\n dst = h->rbsp_buffer[bufidx];\n\n\n\n if (dst == NULL)\n\n return NULL;\n\n\n\n memcpy(dst, src, i);\n\n si = di = i;\n\n while (si + 2 < length) {\n\n // remove escapes (very rare 1:2^22)\n\n if (src[si + 2] > 3) {\n\n dst[di++] = src[si++];\n\n dst[di++] = src[si++];\n\n } else if (src[si] == 0 && src[si + 1] == 0) {\n\n if (src[si + 2] == 3) { // escape\n\n dst[di++] = 0;\n\n dst[di++] = 0;\n\n si += 3;\n\n continue;\n\n } else // next start code\n\n goto nsc;\n\n }\n\n\n\n dst[di++] = src[si++];\n\n }\n\n while (si < length)\n\n dst[di++] = src[si++];\n\n\n\nnsc:\n\n memset(dst + di, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n\n\n\n *dst_length = di;\n\n *consumed = si + 1; // +1 for the header\n\n /* FIXME store exact number of bits in the getbitcontext\n\n * (it is needed for decoding) */\n\n return dst;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "f929ab0569ff31ed5a59b0b0adb7ce09df3fca39", + "length": 909 + }, + { + "index": 19896, + "code": "static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t size)\n\n{\n\n VirtIONet *n = qemu_get_nic_opaque(nc);\n\n VirtIONetQueue *q = virtio_net_get_subqueue(nc);\n\n VirtIODevice *vdev = VIRTIO_DEVICE(n);\n\n struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE];\n\n struct virtio_net_hdr_mrg_rxbuf mhdr;\n\n unsigned mhdr_cnt = 0;\n\n size_t offset, i, guest_offset;\n\n\n\n if (!virtio_net_can_receive(nc)) {\n\n return -1;\n\n }\n\n\n\n /* hdr_len refers to the header we supply to the guest */\n\n if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {\n\n return 0;\n\n }\n\n\n\n if (!receive_filter(n, buf, size))\n\n return size;\n\n\n\n offset = i = 0;\n\n\n\n while (offset < size) {\n\n VirtQueueElement elem;\n\n int len, total;\n\n const struct iovec *sg = elem.in_sg;\n\n\n\n total = 0;\n\n\n\n if (virtqueue_pop(q->rx_vq, &elem) == 0) {\n\n if (i == 0)\n\n return -1;\n\n error_report(\"virtio-net unexpected empty queue: \"\n\n \"i %zd mergeable %d offset %zd, size %zd, \"\n\n \"guest hdr len %zd, host hdr len %zd \"\n\n \"guest features 0x%\" PRIx64,\n\n i, n->mergeable_rx_bufs, offset, size,\n\n n->guest_hdr_len, n->host_hdr_len,\n\n vdev->guest_features);\n\n exit(1);\n\n }\n\n\n\n if (elem.in_num < 1) {\n\n error_report(\"virtio-net receive queue contains no in buffers\");\n\n exit(1);\n\n }\n\n\n\n if (i == 0) {\n\n assert(offset == 0);\n\n if (n->mergeable_rx_bufs) {\n\n mhdr_cnt = iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg),\n\n sg, elem.in_num,\n\n offsetof(typeof(mhdr), num_buffers),\n\n sizeof(mhdr.num_buffers));\n\n }\n\n\n\n receive_header(n, sg, elem.in_num, buf, size);\n\n offset = n->host_hdr_len;\n\n total += n->guest_hdr_len;\n\n guest_offset = n->guest_hdr_len;\n\n } else {\n\n guest_offset = 0;\n\n }\n\n\n\n /* copy in packet. ugh */\n\n len = iov_from_buf(sg, elem.in_num, guest_offset,\n\n buf + offset, size - offset);\n\n total += len;\n\n offset += len;\n\n /* If buffers can't be merged, at this point we\n\n * must have consumed the complete packet.\n\n * Otherwise, drop it. */\n\n if (!n->mergeable_rx_bufs && offset < size) {\n\n#if 0\n\n error_report(\"virtio-net truncated non-mergeable packet: \"\n\n \"i %zd mergeable %d offset %zd, size %zd, \"\n\n \"guest hdr len %zd, host hdr len %zd\",\n\n i, n->mergeable_rx_bufs,\n\n offset, size, n->guest_hdr_len, n->host_hdr_len);\n\n#endif\n\n return size;\n\n }\n\n\n\n /* signal other side */\n\n virtqueue_fill(q->rx_vq, &elem, total, i++);\n\n }\n\n\n\n if (mhdr_cnt) {\n\n virtio_stw_p(vdev, &mhdr.num_buffers, i);\n\n iov_from_buf(mhdr_sg, mhdr_cnt,\n\n 0,\n\n &mhdr.num_buffers, sizeof mhdr.num_buffers);\n\n }\n\n\n\n virtqueue_flush(q->rx_vq, i);\n\n virtio_notify(vdev, q->rx_vq);\n\n\n\n return size;\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "0cf33fb6b49a19de32859e2cdc6021334f448fb3", + "length": 823 + }, + { + "index": 10629, + "code": "static int get_audio_flags(AVCodecContext *enc){\n\n int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;\n\n\n\n if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters\n\n return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO;\n\n else if (enc->codec_id == CODEC_ID_SPEEX) {\n\n if (enc->sample_rate != 16000) {\n\n av_log(enc, AV_LOG_ERROR, \"flv only supports wideband (16kHz) Speex audio\\n\");\n\n return -1;\n\n }\n\n if (enc->channels != 1) {\n\n av_log(enc, AV_LOG_ERROR, \"flv only supports mono Speex audio\\n\");\n\n return -1;\n\n }\n\n if (enc->frame_size / 320 > 8) {\n\n av_log(enc, AV_LOG_WARNING, \"Warning: Speex stream has more than \"\n\n \"8 frames per packet. Adobe Flash \"\n\n \"Player cannot handle this!\\n\");\n\n }\n\n return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;\n\n } else {\n\n switch (enc->sample_rate) {\n\n case 44100:\n\n flags |= FLV_SAMPLERATE_44100HZ;\n\n break;\n\n case 22050:\n\n flags |= FLV_SAMPLERATE_22050HZ;\n\n break;\n\n case 11025:\n\n flags |= FLV_SAMPLERATE_11025HZ;\n\n break;\n\n case 8000: //nellymoser only\n\n case 5512: //not mp3\n\n if(enc->codec_id != CODEC_ID_MP3){\n\n flags |= FLV_SAMPLERATE_SPECIAL;\n\n break;\n\n }\n\n default:\n\n av_log(enc, AV_LOG_ERROR, \"flv does not support that sample rate, choose from (44100, 22050, 11025).\\n\");\n\n return -1;\n\n }\n\n }\n\n\n\n if (enc->channels > 1) {\n\n flags |= FLV_STEREO;\n\n }\n\n\n\n switch(enc->codec_id){\n\n case CODEC_ID_MP3:\n\n flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT;\n\n break;\n\n case CODEC_ID_PCM_U8:\n\n flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_8BIT;\n\n break;\n\n case CODEC_ID_PCM_S16BE:\n\n flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_16BIT;\n\n break;\n\n case CODEC_ID_PCM_S16LE:\n\n flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;\n\n break;\n\n case CODEC_ID_ADPCM_SWF:\n\n flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;\n\n break;\n\n case CODEC_ID_NELLYMOSER:\n\n if (enc->sample_rate == 8000) {\n\n flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;\n\n } else {\n\n flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;\n\n }\n\n break;\n\n case 0:\n\n flags |= enc->codec_tag<<4;\n\n break;\n\n default:\n\n av_log(enc, AV_LOG_ERROR, \"codec not compatible with flv\\n\");\n\n return -1;\n\n }\n\n\n\n return flags;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "4ee247a2bdf2fbe81026a428d4affc46c81f28db", + "length": 790 + }, + { + "index": 25656, + "code": "static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,\n\n unsigned int substr, unsigned int channel,\n\n unsigned int filter)\n\n{\n\n SubStream *s = &m->substream[substr];\n\n FilterParams *fp = &s->channel_params[channel].filter_params[filter];\n\n const int max_order = filter ? MAX_IIR_ORDER : MAX_FIR_ORDER;\n\n const char fchar = filter ? 'I' : 'F';\n\n int i, order;\n\n\n\n // Filter is 0 for FIR, 1 for IIR.\n\n av_assert0(filter < 2);\n\n\n\n if (m->filter_changed[channel][filter]++ > 1) {\n\n av_log(m->avctx, AV_LOG_ERROR, \"Filters may change only once per access unit.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n order = get_bits(gbp, 4);\n\n if (order > max_order) {\n\n av_log(m->avctx, AV_LOG_ERROR,\n\n \"%cIR filter order %d is greater than maximum %d.\\n\",\n\n fchar, order, max_order);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n fp->order = order;\n\n\n\n if (order > 0) {\n\n int32_t *fcoeff = s->channel_params[channel].coeff[filter];\n\n int coeff_bits, coeff_shift;\n\n\n\n fp->shift = get_bits(gbp, 4);\n\n\n\n coeff_bits = get_bits(gbp, 5);\n\n coeff_shift = get_bits(gbp, 3);\n\n if (coeff_bits < 1 || coeff_bits > 16) {\n\n av_log(m->avctx, AV_LOG_ERROR,\n\n \"%cIR filter coeff_bits must be between 1 and 16.\\n\",\n\n fchar);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (coeff_bits + coeff_shift > 16) {\n\n av_log(m->avctx, AV_LOG_ERROR,\n\n \"Sum of coeff_bits and coeff_shift for %cIR filter must be 16 or less.\\n\",\n\n fchar);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n for (i = 0; i < order; i++)\n\n fcoeff[i] = get_sbits(gbp, coeff_bits) * (1 << coeff_shift);\n\n\n\n if (get_bits1(gbp)) {\n\n int state_bits, state_shift;\n\n\n\n if (filter == FIR) {\n\n av_log(m->avctx, AV_LOG_ERROR,\n\n \"FIR filter has state data specified.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n state_bits = get_bits(gbp, 4);\n\n state_shift = get_bits(gbp, 4);\n\n\n\n /* TODO: Check validity of state data. */\n\n\n\n for (i = 0; i < order; i++)\n\n fp->state[i] = state_bits ? get_sbits(gbp, state_bits) << state_shift : 0;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "552adf1dd3a38fb7a1a6109dd2b517d63290f20e", + "length": 631 + }, + { + "index": 16003, + "code": "static void virtio_pci_common_write(void *opaque, hwaddr addr,\n\n uint64_t val, unsigned size)\n\n{\n\n VirtIOPCIProxy *proxy = opaque;\n\n VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);\n\n\n\n switch (addr) {\n\n case VIRTIO_PCI_COMMON_DFSELECT:\n\n proxy->dfselect = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_GFSELECT:\n\n proxy->gfselect = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_GF:\n\n if (proxy->gfselect <= ARRAY_SIZE(proxy->guest_features)) {\n\n proxy->guest_features[proxy->gfselect] = val;\n\n virtio_set_features(vdev,\n\n (((uint64_t)proxy->guest_features[1]) << 32) |\n\n proxy->guest_features[0]);\n\n }\n\n break;\n\n case VIRTIO_PCI_COMMON_MSIX:\n\n msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);\n\n /* Make it possible for guest to discover an error took place. */\n\n if (msix_vector_use(&proxy->pci_dev, val) < 0) {\n\n val = VIRTIO_NO_VECTOR;\n\n }\n\n vdev->config_vector = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_STATUS:\n\n if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) {\n\n virtio_pci_stop_ioeventfd(proxy);\n\n }\n\n\n\n virtio_set_status(vdev, val & 0xFF);\n\n\n\n if (val & VIRTIO_CONFIG_S_DRIVER_OK) {\n\n virtio_pci_start_ioeventfd(proxy);\n\n }\n\n\n\n if (vdev->status == 0) {\n\n virtio_reset(vdev);\n\n msix_unuse_all_vectors(&proxy->pci_dev);\n\n }\n\n\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_SELECT:\n\n if (val < VIRTIO_QUEUE_MAX) {\n\n vdev->queue_sel = val;\n\n }\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_SIZE:\n\n proxy->vqs[vdev->queue_sel].num = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_MSIX:\n\n msix_vector_unuse(&proxy->pci_dev,\n\n virtio_queue_vector(vdev, vdev->queue_sel));\n\n /* Make it possible for guest to discover an error took place. */\n\n if (msix_vector_use(&proxy->pci_dev, val) < 0) {\n\n val = VIRTIO_NO_VECTOR;\n\n }\n\n virtio_queue_set_vector(vdev, vdev->queue_sel, val);\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_ENABLE:\n\n /* TODO: need a way to put num back on reset. */\n\n virtio_queue_set_num(vdev, vdev->queue_sel,\n\n proxy->vqs[vdev->queue_sel].num);\n\n virtio_queue_set_rings(vdev, vdev->queue_sel,\n\n ((uint64_t)proxy->vqs[vdev->queue_sel].desc[1]) << 32 |\n\n proxy->vqs[vdev->queue_sel].desc[0],\n\n ((uint64_t)proxy->vqs[vdev->queue_sel].avail[1]) << 32 |\n\n proxy->vqs[vdev->queue_sel].avail[0],\n\n ((uint64_t)proxy->vqs[vdev->queue_sel].used[1]) << 32 |\n\n proxy->vqs[vdev->queue_sel].used[0]);\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_DESCLO:\n\n proxy->vqs[vdev->queue_sel].desc[0] = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_DESCHI:\n\n proxy->vqs[vdev->queue_sel].desc[1] = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_AVAILLO:\n\n proxy->vqs[vdev->queue_sel].avail[0] = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_AVAILHI:\n\n proxy->vqs[vdev->queue_sel].avail[1] = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_USEDLO:\n\n proxy->vqs[vdev->queue_sel].used[0] = val;\n\n break;\n\n case VIRTIO_PCI_COMMON_Q_USEDHI:\n\n proxy->vqs[vdev->queue_sel].used[1] = val;\n\n break;\n\n default:\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "3750dabc69d76f0938cc726a64a70e4ae2fe21df", + "length": 939 + }, + { + "index": 16226, + "code": "static int init_output_stream(OutputStream *ost, char *error, int error_len)\n\n{\n\n int ret = 0;\n\n\n\n if (ost->encoding_needed) {\n\n AVCodec *codec = ost->enc;\n\n AVCodecContext *dec = NULL;\n\n InputStream *ist;\n\n\n\n ret = init_output_stream_encode(ost);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if ((ist = get_input_stream(ost)))\n\n dec = ist->dec_ctx;\n\n if (dec && dec->subtitle_header) {\n\n ost->enc_ctx->subtitle_header = av_malloc(dec->subtitle_header_size);\n\n if (!ost->enc_ctx->subtitle_header)\n\n return AVERROR(ENOMEM);\n\n memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);\n\n ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;\n\n }\n\n if (!av_dict_get(ost->encoder_opts, \"threads\", NULL, 0))\n\n av_dict_set(&ost->encoder_opts, \"threads\", \"auto\", 0);\n\n\n\n if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx) {\n\n ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx);\n\n if (!ost->enc_ctx->hw_frames_ctx)\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {\n\n if (ret == AVERROR_EXPERIMENTAL)\n\n abort_codec_experimental(codec, 1);\n\n snprintf(error, error_len,\n\n \"Error while opening encoder for output stream #%d:%d - \"\n\n \"maybe incorrect parameters such as bit_rate, rate, width or height\",\n\n ost->file_index, ost->index);\n\n return ret;\n\n }\n\n assert_avoptions(ost->encoder_opts);\n\n if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000)\n\n av_log(NULL, AV_LOG_WARNING, \"The bitrate parameter is set too low.\"\n\n \"It takes bits/s as argument, not kbits/s\\n\");\n\n\n\n ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx);\n\n if (ret < 0) {\n\n av_log(NULL, AV_LOG_FATAL,\n\n \"Error initializing the output stream codec context.\\n\");\n\n exit_program(1);\n\n }\n\n\n\n if (ost->enc_ctx->nb_coded_side_data) {\n\n int i;\n\n\n\n ost->st->side_data = av_realloc_array(NULL, ost->enc_ctx->nb_coded_side_data,\n\n sizeof(*ost->st->side_data));\n\n if (!ost->st->side_data)\n\n return AVERROR(ENOMEM);\n\n\n\n for (i = 0; i < ost->enc_ctx->nb_coded_side_data; i++) {\n\n const AVPacketSideData *sd_src = &ost->enc_ctx->coded_side_data[i];\n\n AVPacketSideData *sd_dst = &ost->st->side_data[i];\n\n\n\n sd_dst->data = av_malloc(sd_src->size);\n\n if (!sd_dst->data)\n\n return AVERROR(ENOMEM);\n\n memcpy(sd_dst->data, sd_src->data, sd_src->size);\n\n sd_dst->size = sd_src->size;\n\n sd_dst->type = sd_src->type;\n\n ost->st->nb_side_data++;\n\n }\n\n }\n\n\n\n ost->st->time_base = ost->enc_ctx->time_base;\n\n } else if (ost->stream_copy) {\n\n ret = init_output_stream_streamcopy(ost);\n\n if (ret < 0)\n\n return ret;\n\n\n\n /*\n\n * FIXME: will the codec context used by the parser during streamcopy\n\n * This should go away with the new parser API.\n\n */\n\n ret = avcodec_parameters_to_context(ost->parser_avctx, ost->st->codecpar);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n\n\n /* initialize bitstream filters for the output stream\n\n * needs to be done here, because the codec id for streamcopy is not\n\n * known until now */\n\n ret = init_output_bsfs(ost);\n\n if (ret < 0)\n\n return ret;\n\n\n\n ost->mux_timebase = ost->st->time_base;\n\n\n\n ost->initialized = 1;\n\n\n\n ret = check_init_output_file(output_files[ost->file_index], ost->file_index);\n\n if (ret < 0)\n\n return ret;\n\n\n\n return ret;\n\n}\n", + "label": 0, + "project": "FFmpeg", + "commit_id": "e3fb74f7f9a8f1895381355f40c92cac3c1023d9", + "length": 978 + }, + { + "index": 23457, + "code": "static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)\n\n{\n\n CPUX86State *env = &cpu->env;\n\n FeatureWord w;\n\n GList *l;\n\n Error *local_err = NULL;\n\n\n\n /*TODO: cpu->max_features incorrectly overwrites features\n\n * set using \"feat=on|off\". Once we fix this, we can convert\n\n * plus_features & minus_features to global properties\n\n * inside x86_cpu_parse_featurestr() too.\n\n */\n\n if (cpu->max_features) {\n\n for (w = 0; w < FEATURE_WORDS; w++) {\n\n env->features[w] =\n\n x86_cpu_get_supported_feature_word(w, cpu->migratable);\n\n }\n\n }\n\n\n\n for (l = plus_features; l; l = l->next) {\n\n const char *prop = l->data;\n\n object_property_set_bool(OBJECT(cpu), true, prop, &local_err);\n\n if (local_err) {\n\n goto out;\n\n }\n\n }\n\n\n\n for (l = minus_features; l; l = l->next) {\n\n const char *prop = l->data;\n\n object_property_set_bool(OBJECT(cpu), false, prop, &local_err);\n\n if (local_err) {\n\n goto out;\n\n }\n\n }\n\n\n\n if (!kvm_enabled() || !cpu->expose_kvm) {\n\n env->features[FEAT_KVM] = 0;\n\n }\n\n\n\n x86_cpu_enable_xsave_components(cpu);\n\n\n\n /* CPUID[EAX=7,ECX=0].EBX always increased level automatically: */\n\n x86_cpu_adjust_feat_level(cpu, FEAT_7_0_EBX);\n\n if (cpu->full_cpuid_auto_level) {\n\n x86_cpu_adjust_feat_level(cpu, FEAT_1_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_1_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_6_EAX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_7_0_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_ECX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_8000_0007_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_SVM);\n\n x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);\n\n /* SVM requires CPUID[0x8000000A] */\n\n if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {\n\n x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);\n\n }\n\n }\n\n\n\n /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */\n\n if (env->cpuid_level == UINT32_MAX) {\n\n env->cpuid_level = env->cpuid_min_level;\n\n }\n\n if (env->cpuid_xlevel == UINT32_MAX) {\n\n env->cpuid_xlevel = env->cpuid_min_xlevel;\n\n }\n\n if (env->cpuid_xlevel2 == UINT32_MAX) {\n\n env->cpuid_xlevel2 = env->cpuid_min_xlevel2;\n\n }\n\n\n\nout:\n\n if (local_err != NULL) {\n\n error_propagate(errp, local_err);\n\n }\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "d4a606b38b5d4b3689b86cc1575908e82179ecfb", + "length": 763 + }, + { + "index": 17815, + "code": "static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)\n\n{\n\n FramePool *pool = avctx->internal->pool;\n\n int i, ret;\n\n\n\n switch (avctx->codec_type) {\n\n case AVMEDIA_TYPE_VIDEO: {\n\n AVPicture picture;\n\n int size[4] = { 0 };\n\n int w = frame->width;\n\n int h = frame->height;\n\n int tmpsize, unaligned;\n\n\n\n if (pool->format == frame->format &&\n\n pool->width == frame->width && pool->height == frame->height)\n\n return 0;\n\n\n\n avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);\n\n\n\n if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {\n\n w += EDGE_WIDTH * 2;\n\n h += EDGE_WIDTH * 2;\n\n }\n\n\n\n do {\n\n // NOTE: do not align linesizes individually, this breaks e.g. assumptions\n\n // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2\n\n av_image_fill_linesizes(picture.linesize, avctx->pix_fmt, w);\n\n // increase alignment of w for next try (rhs gives the lowest bit set in w)\n\n w += w & ~(w - 1);\n\n\n\n unaligned = 0;\n\n for (i = 0; i < 4; i++)\n\n unaligned |= picture.linesize[i] % pool->stride_align[i];\n\n } while (unaligned);\n\n\n\n tmpsize = av_image_fill_pointers(picture.data, avctx->pix_fmt, h,\n\n NULL, picture.linesize);\n\n if (tmpsize < 0)\n\n return -1;\n\n\n\n for (i = 0; i < 3 && picture.data[i + 1]; i++)\n\n size[i] = picture.data[i + 1] - picture.data[i];\n\n size[i] = tmpsize - (picture.data[i] - picture.data[0]);\n\n\n\n for (i = 0; i < 4; i++) {\n\n av_buffer_pool_uninit(&pool->pools[i]);\n\n pool->linesize[i] = picture.linesize[i];\n\n if (size[i]) {\n\n pool->pools[i] = av_buffer_pool_init(size[i] + 16, NULL);\n\n if (!pool->pools[i]) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n }\n\n }\n\n pool->format = frame->format;\n\n pool->width = frame->width;\n\n pool->height = frame->height;\n\n\n\n break;\n\n }\n\n case AVMEDIA_TYPE_AUDIO: {\n\n int ch = av_frame_get_channels(frame); //av_get_channel_layout_nb_channels(frame->channel_layout);\n\n int planar = av_sample_fmt_is_planar(frame->format);\n\n int planes = planar ? ch : 1;\n\n\n\n if (pool->format == frame->format && pool->planes == planes &&\n\n pool->channels == ch && frame->nb_samples == pool->samples)\n\n return 0;\n\n\n\n av_buffer_pool_uninit(&pool->pools[0]);\n\n ret = av_samples_get_buffer_size(&pool->linesize[0], ch,\n\n frame->nb_samples, frame->format, 0);\n\n if (ret < 0)\n\n goto fail;\n\n\n\n pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);\n\n if (!pool->pools[0]) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n pool->format = frame->format;\n\n pool->planes = planes;\n\n pool->channels = ch;\n\n pool->samples = frame->nb_samples;\n\n break;\n\n }\n\n default: av_assert0(0);\n\n }\n\n return 0;\n\nfail:\n\n for (i = 0; i < 4; i++)\n\n av_buffer_pool_uninit(&pool->pools[i]);\n\n pool->format = -1;\n\n pool->planes = pool->channels = pool->samples = 0;\n\n pool->width = pool->height = 0;\n\n return ret;\n\n}\n", + "label": 1, + "project": "FFmpeg", + "commit_id": "01df2a13c32a28cd5a5b27098aa2b4b32a3d76e4", + "length": 899 + }, + { + "index": 4033, + "code": "vmxnet3_io_bar1_write(void *opaque,\n\n hwaddr addr,\n\n uint64_t val,\n\n unsigned size)\n\n{\n\n VMXNET3State *s = opaque;\n\n\n\n switch (addr) {\n\n /* Vmxnet3 Revision Report Selection */\n\n case VMXNET3_REG_VRRS:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_VRRS] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n break;\n\n\n\n /* UPT Version Report Selection */\n\n case VMXNET3_REG_UVRS:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_UVRS] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n break;\n\n\n\n /* Driver Shared Address Low */\n\n case VMXNET3_REG_DSAL:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_DSAL] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n /*\n\n * Guest driver will first write the low part of the shared\n\n * memory address. We save it to temp variable and set the\n\n * shared address only after we get the high part\n\n */\n\n if (val == 0) {\n\n s->device_active = false;\n\n }\n\n s->temp_shared_guest_driver_memory = val;\n\n s->drv_shmem = 0;\n\n break;\n\n\n\n /* Driver Shared Address High */\n\n case VMXNET3_REG_DSAH:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_DSAH] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n /*\n\n * Set the shared memory between guest driver and device.\n\n * We already should have low address part.\n\n */\n\n s->drv_shmem = s->temp_shared_guest_driver_memory | (val << 32);\n\n break;\n\n\n\n /* Command */\n\n case VMXNET3_REG_CMD:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_CMD] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n vmxnet3_handle_command(s, val);\n\n break;\n\n\n\n /* MAC Address Low */\n\n case VMXNET3_REG_MACL:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_MACL] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n s->temp_mac = val;\n\n break;\n\n\n\n /* MAC Address High */\n\n case VMXNET3_REG_MACH:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_MACH] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n vmxnet3_set_variable_mac(s, val, s->temp_mac);\n\n break;\n\n\n\n /* Interrupt Cause Register */\n\n case VMXNET3_REG_ICR:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_ICR] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n g_assert_not_reached();\n\n break;\n\n\n\n /* Event Cause Register */\n\n case VMXNET3_REG_ECR:\n\n VMW_CBPRN(\"Write BAR1 [VMXNET3_REG_ECR] = %\" PRIx64 \", size %d\",\n\n val, size);\n\n vmxnet3_ack_events(s, val);\n\n break;\n\n\n\n default:\n\n VMW_CBPRN(\"Unknown Write to BAR1 [%\" PRIx64 \"] = %\" PRIx64 \", size %d\",\n\n addr, val, size);\n\n break;\n\n }\n\n}\n", + "label": 1, + "project": "qemu", + "commit_id": "aa4a3dce1c88ed51b616806b8214b7c8428b7470", + "length": 765 + }, + { + "index": 22486, + "code": "static uint64_t lan9118_readl(void *opaque, hwaddr offset,\n\n unsigned size)\n\n{\n\n lan9118_state *s = (lan9118_state *)opaque;\n\n\n\n //DPRINTF(\"Read reg 0x%02x\\n\", (int)offset);\n\n if (offset < 0x20) {\n\n /* RX FIFO */\n\n return rx_fifo_pop(s);\n\n }\n\n switch (offset) {\n\n case 0x40:\n\n return rx_status_fifo_pop(s);\n\n case 0x44:\n\n return s->rx_status_fifo[s->tx_status_fifo_head];\n\n case 0x48:\n\n return tx_status_fifo_pop(s);\n\n case 0x4c:\n\n return s->tx_status_fifo[s->tx_status_fifo_head];\n\n case CSR_ID_REV:\n\n return 0x01180001;\n\n case CSR_IRQ_CFG:\n\n return s->irq_cfg;\n\n case CSR_INT_STS:\n\n return s->int_sts;\n\n case CSR_INT_EN:\n\n return s->int_en;\n\n case CSR_BYTE_TEST:\n\n return 0x87654321;\n\n case CSR_FIFO_INT:\n\n return s->fifo_int;\n\n case CSR_RX_CFG:\n\n return s->rx_cfg;\n\n case CSR_TX_CFG:\n\n return s->tx_cfg;\n\n case CSR_HW_CFG:\n\n return s->hw_cfg;\n\n case CSR_RX_DP_CTRL:\n\n return 0;\n\n case CSR_RX_FIFO_INF:\n\n return (s->rx_status_fifo_used << 16) | (s->rx_fifo_used << 2);\n\n case CSR_TX_FIFO_INF:\n\n return (s->tx_status_fifo_used << 16)\n\n | (s->tx_fifo_size - s->txp->fifo_used);\n\n case CSR_PMT_CTRL:\n\n return s->pmt_ctrl;\n\n case CSR_GPIO_CFG:\n\n return s->gpio_cfg;\n\n case CSR_GPT_CFG:\n\n return s->gpt_cfg;\n\n case CSR_GPT_CNT:\n\n return ptimer_get_count(s->timer);\n\n case CSR_WORD_SWAP:\n\n return s->word_swap;\n\n case CSR_FREE_RUN:\n\n return (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / 40) - s->free_timer_start;\n\n case CSR_RX_DROP:\n\n /* TODO: Implement dropped frames counter. */\n\n return 0;\n\n case CSR_MAC_CSR_CMD:\n\n return s->mac_cmd;\n\n case CSR_MAC_CSR_DATA:\n\n return s->mac_data;\n\n case CSR_AFC_CFG:\n\n return s->afc_cfg;\n\n case CSR_E2P_CMD:\n\n return s->e2p_cmd;\n\n case CSR_E2P_DATA:\n\n return s->e2p_data;\n\n }\n\n hw_error(\"lan9118_read: Bad reg 0x%x\\n\", (int)offset);\n\n return 0;\n\n}\n", + "label": 0, + "project": "qemu", + "commit_id": "52b4bb7383b32e4e7512f98c57738c8fc9cb35ba", + "length": 596 + } +] \ No newline at end of file