id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
24,767
static void pc_init_pci_1_3(QEMUMachineInitArgs *args) { enable_compat_apic_id_mode(); pc_sysfw_flash_vs_rom_bug_compatible = true; has_pvpanic = false; pc_init_pci(args); }
true
qemu
9e1c2ec8fd8d9a9ee299ea86c5f6c986fe25e838
24,769
static uint8_t get_sot(Jpeg2000DecoderContext *s, int n) { Jpeg2000TilePart *tp; uint16_t Isot; uint32_t Psot; uint8_t TPsot; if (s->buf_end - s->buf < 4) return AVERROR(EINVAL); Isot = bytestream_get_be16(&s->buf); // Isot if (Isot) { av_log(s->avctx, AV_LOG_ERROR, "Not a DCINEMA JP2K file: more than one tile\n"); return -1; } Psot = bytestream_get_be32(&s->buf); // Psot TPsot = bytestream_get_byte(&s->buf); // TPsot /* Read TNSot but not used */ bytestream_get_byte(&s->buf); // TNsot tp = s->tile[s->curtileno].tile_part + TPsot; tp->tile_index = Isot; tp->tp_len = Psot; tp->tp_idx = TPsot; /* Start of bit stream. Pointer to SOD marker * Check SOD marker is present. */ if (JPEG2000_SOD == bytestream_get_be16(&s->buf)) tp->tp_start_bstrm = s->buf; else { av_log(s->avctx, AV_LOG_ERROR, "SOD marker not found \n"); return -1; } /* End address of bit stream = * start address + (Psot - size of SOT HEADER(n) * - size of SOT MARKER(2) - size of SOD marker(2) */ tp->tp_end_bstrm = s->buf + (tp->tp_len - n - 4); // set buffer pointer to end of tile part header s->buf = tp->tp_end_bstrm; return 0; }
false
FFmpeg
0b42631641d998e509cde6fa344edc6ab5cb4ac8
24,770
static int xa_probe(AVProbeData *p) { switch(AV_RL32(p->buf)) { case XA00_TAG: case XAI0_TAG: case XAJ0_TAG: return AVPROBE_SCORE_MAX; } return 0; }
true
FFmpeg
ddbb7c9be2f8a006325ec64cd5b90e1ade5bc476
24,772
static void qemu_chr_fe_write_log(CharDriverState *s, const uint8_t *buf, size_t len) { size_t done = 0; ssize_t ret; if (s->logfd < 0) { return; } while (done < len) { do { ret = write(s->logfd, buf + done, len - done); if (ret == -1 && errno == EAGAIN) { g_usleep(100); } } while (ret == -1 && errno == EAGAIN); if (ret <= 0) { return; } done += ret; } }
true
qemu
53628efbc8aa7a7ab5354d24b971f4d69452151d
24,773
void av_vlog(void* avcl, int level, const char *fmt, va_list vl) { if(av_log_callback) av_log_callback(avcl, level, fmt, vl); }
true
FFmpeg
3ed65d98c616d52e2544c8b81aa3997f28bb88f5
24,774
void kvm_setup_guest_memory(void *start, size_t size) { if (!kvm_has_sync_mmu()) { #ifdef MADV_DONTFORK int ret = madvise(start, size, MADV_DONTFORK); if (ret) { perror("madvice"); exit(1); } #else fprintf(stderr, "Need MADV_DONTFORK in absence of synchronous KVM MMU\n"); exit(1); #endif } }
true
qemu
e78815a554adaa551d62a71be10ee2fcf128e473
24,775
static int read_packet(AVFormatContext *s, AVPacket *pkt) { ASSContext *ass = s->priv_data; uint8_t *p, *end; if (ass->event_index >= ass->event_count) return AVERROR(EIO); p = ass->event[ass->event_index]; end = strchr(p, '\n'); av_new_packet(pkt, end ? end - p + 1 : strlen(p)); pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos = p - ass->event_buffer + s->streams[0]->codec->extradata_size; pkt->pts = pkt->dts = get_pts(p); memcpy(pkt->data, p, pkt->size); ass->event_index++; return 0; }
false
FFmpeg
e9ba3098319f78c91470c05da988d865491852c5
24,776
static av_cold int xwd_encode_close(AVCodecContext *avctx) { av_freep(&avctx->coded_frame); return 0; }
false
FFmpeg
d6604b29ef544793479d7fb4e05ef6622bb3e534
24,777
av_cold void ff_idctdsp_init_x86(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth) { int cpu_flags = av_get_cpu_flags(); if (INLINE_MMX(cpu_flags)) { if (!high_bit_depth && avctx->lowres == 0 && (avctx->idct_algo == FF_IDCT_AUTO || avctx->idct_algo == FF_IDCT_SIMPLEAUTO || avctx->idct_algo == FF_IDCT_SIMPLEMMX)) { c->idct_put = ff_simple_idct_put_mmx; c->idct_add = ff_simple_idct_add_mmx; c->idct = ff_simple_idct_mmx; c->perm_type = FF_IDCT_PERM_SIMPLE; } } if (EXTERNAL_MMX(cpu_flags)) { c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx; c->put_pixels_clamped = ff_put_pixels_clamped_mmx; c->add_pixels_clamped = ff_add_pixels_clamped_mmx; } if (EXTERNAL_SSE2(cpu_flags)) { c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_sse2; c->put_pixels_clamped = ff_put_pixels_clamped_sse2; c->add_pixels_clamped = ff_add_pixels_clamped_sse2; } if (ARCH_X86_64 && avctx->bits_per_raw_sample == 10 && avctx->lowres == 0 && (avctx->idct_algo == FF_IDCT_AUTO || avctx->idct_algo == FF_IDCT_SIMPLEAUTO || avctx->idct_algo == FF_IDCT_SIMPLE)) { if (EXTERNAL_SSE2(cpu_flags)) { c->idct_put = ff_simple_idct10_put_sse2; c->idct_add = NULL; c->idct = ff_simple_idct10_sse2; c->perm_type = FF_IDCT_PERM_TRANSPOSE; } if (EXTERNAL_AVX(cpu_flags)) { c->idct_put = ff_simple_idct10_put_avx; c->idct_add = NULL; c->idct = ff_simple_idct10_avx; c->perm_type = FF_IDCT_PERM_TRANSPOSE; } } }
true
FFmpeg
7ece8b50b19e140ace13eda6f1a9f45f868c2528
24,778
static void send_msg(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, uint8_t *rsp, unsigned int *rsp_len, unsigned int max_rsp_len) { IPMIInterface *s = ibs->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); IPMIRcvBufEntry *msg; uint8_t *buf; uint8_t netfn, rqLun, rsLun, rqSeq; IPMI_CHECK_CMD_LEN(3); if (cmd[2] != 0) { /* We only handle channel 0 with no options */ rsp[2] = IPMI_CC_INVALID_DATA_FIELD; return; } IPMI_CHECK_CMD_LEN(10); if (cmd[3] != 0x40) { /* We only emulate a MC at address 0x40. */ rsp[2] = 0x83; /* NAK on write */ return; } cmd += 3; /* Skip the header. */ cmd_len -= 3; /* * At this point we "send" the message successfully. Any error will * be returned in the response. */ if (ipmb_checksum(cmd, cmd_len, 0) != 0 || cmd[3] != 0x20) { /* Improper response address */ return; /* No response */ } netfn = cmd[1] >> 2; rqLun = cmd[4] & 0x3; rsLun = cmd[1] & 0x3; rqSeq = cmd[4] >> 2; if (rqLun != 2) { /* We only support LUN 2 coming back to us. */ return; } msg = g_malloc(sizeof(*msg)); msg->buf[0] = ((netfn | 1) << 2) | rqLun; /* NetFN, and make a response */ msg->buf[1] = ipmb_checksum(msg->buf, 1, 0); msg->buf[2] = cmd[0]; /* rsSA */ msg->buf[3] = (rqSeq << 2) | rsLun; msg->buf[4] = cmd[5]; /* Cmd */ msg->buf[5] = 0; /* Completion Code */ msg->len = 6; if ((cmd[1] >> 2) != IPMI_NETFN_APP || cmd[5] != IPMI_CMD_GET_DEVICE_ID) { /* Not a command we handle. */ msg->buf[5] = IPMI_CC_INVALID_CMD; goto end_msg; } buf = msg->buf + msg->len; /* After the CC */ buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0; buf[4] = 0x51; buf[5] = 0; buf[6] = 0; buf[7] = 0; buf[8] = 0; buf[9] = 0; buf[10] = 0; msg->len += 11; end_msg: msg->buf[msg->len] = ipmb_checksum(msg->buf, msg->len, 0); msg->len++; qemu_mutex_lock(&ibs->lock); QTAILQ_INSERT_TAIL(&ibs->rcvbufs, msg, entry); ibs->msg_flags |= IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE; k->set_atn(s, 1, attn_irq_enabled(ibs)); qemu_mutex_unlock(&ibs->lock); }
true
qemu
4f298a4b2957b7833bc607c951ca27c458d98d88
24,779
static void render_slice(Vp3DecodeContext *s, int slice) { int x, y, i, j, fragment; LOCAL_ALIGNED_16(DCTELEM, block, [64]); int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; int motion_halfpel_index; uint8_t *motion_source; int plane, first_pixel; if (slice >= s->c_superblock_height) return; for (plane = 0; plane < 3; plane++) { uint8_t *output_plane = s->current_frame.data [plane] + s->data_offset[plane]; uint8_t * last_plane = s-> last_frame.data [plane] + s->data_offset[plane]; uint8_t *golden_plane = s-> golden_frame.data [plane] + s->data_offset[plane]; int stride = s->current_frame.linesize[plane]; int plane_width = s->width >> (plane && s->chroma_x_shift); int plane_height = s->height >> (plane && s->chroma_y_shift); int8_t (*motion_val)[2] = s->motion_val[!!plane]; int sb_x, sb_y = slice << (!plane && s->chroma_y_shift); int slice_height = sb_y + 1 + (!plane && s->chroma_y_shift); int slice_width = plane ? s->c_superblock_width : s->y_superblock_width; int fragment_width = s->fragment_width[!!plane]; int fragment_height = s->fragment_height[!!plane]; int fragment_start = s->fragment_start[plane]; int do_await = !plane && HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_FRAME); if (!s->flipped_image) stride = -stride; if (CONFIG_GRAY && plane && (s->avctx->flags & CODEC_FLAG_GRAY)) continue; /* for each superblock row in the slice (both of them)... */ for (; sb_y < slice_height; sb_y++) { /* for each superblock in a row... */ for (sb_x = 0; sb_x < slice_width; sb_x++) { /* for each block in a superblock... */ for (j = 0; j < 16; j++) { x = 4*sb_x + hilbert_offset[j][0]; y = 4*sb_y + hilbert_offset[j][1]; fragment = y*fragment_width + x; i = fragment_start + fragment; // bounds check if (x >= fragment_width || y >= fragment_height) continue; first_pixel = 8*y*stride + 8*x; if (do_await && s->all_fragments[i].coding_method != MODE_INTRA) await_reference_row(s, &s->all_fragments[i], motion_val[fragment][1], (16*y) >> s->chroma_y_shift); /* transform if this block was coded */ if (s->all_fragments[i].coding_method != MODE_COPY) { if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) motion_source= golden_plane; else motion_source= last_plane; motion_source += first_pixel; motion_halfpel_index = 0; /* sort out the motion vector if this fragment is coded * using a motion vector method */ if ((s->all_fragments[i].coding_method > MODE_INTRA) && (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) { int src_x, src_y; motion_x = motion_val[fragment][0]; motion_y = motion_val[fragment][1]; src_x= (motion_x>>1) + 8*x; src_y= (motion_y>>1) + 8*y; motion_halfpel_index = motion_x & 0x01; motion_source += (motion_x >> 1); motion_halfpel_index |= (motion_y & 0x01) << 1; motion_source += ((motion_y >> 1) * stride); if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){ uint8_t *temp= s->edge_emu_buffer; if(stride<0) temp -= 8*stride; s->dsp.emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height); motion_source= temp; } } /* first, take care of copying a block from either the * previous or the golden frame */ if (s->all_fragments[i].coding_method != MODE_INTRA) { /* Note, it is possible to implement all MC cases with put_no_rnd_pixels_l2 which would look more like the VP3 source but this would be slower as put_no_rnd_pixels_tab is better optimzed */ if(motion_halfpel_index != 3){ s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index]( output_plane + first_pixel, motion_source, stride, 8); }else{ int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1 s->dsp.put_no_rnd_pixels_l2[1]( output_plane + first_pixel, motion_source - d, motion_source + stride + 1 + d, stride, 8); } } s->dsp.clear_block(block); /* invert DCT and place (or add) in final output */ if (s->all_fragments[i].coding_method == MODE_INTRA) { int index; index = vp3_dequant(s, s->all_fragments + i, plane, 0, block); if (index > 63) continue; if(s->avctx->idct_algo!=FF_IDCT_VP3) block[0] += 128<<3; s->dsp.idct_put( output_plane + first_pixel, stride, block); } else { int index = vp3_dequant(s, s->all_fragments + i, plane, 1, block); if (index > 63) continue; if (index > 0) { s->dsp.idct_add( output_plane + first_pixel, stride, block); } else { s->dsp.vp3_idct_dc_add(output_plane + first_pixel, stride, block); } } } else { /* copy directly from the previous frame */ s->dsp.put_pixels_tab[1][0]( output_plane + first_pixel, last_plane + first_pixel, stride, 8); } } } // Filter up to the last row in the superblock row if (!s->skip_loop_filter) apply_loop_filter(s, plane, 4*sb_y - !!sb_y, FFMIN(4*sb_y+3, fragment_height-1)); } } /* this looks like a good place for slice dispatch... */ /* algorithm: * if (slice == s->macroblock_height - 1) * dispatch (both last slice & 2nd-to-last slice); * else if (slice > 0) * dispatch (slice - 1); */ vp3_draw_horiz_band(s, FFMIN((32 << s->chroma_y_shift) * (slice + 1) -16, s->height-16)); }
true
FFmpeg
a2a12e3358c3bbdc0246ffc94973e58eba50ee30
24,780
static void disas_xtensa_insn(DisasContext *dc) { #define HAS_OPTION(opt) do { \ if (!option_enabled(dc, opt)) { \ qemu_log("Option %d is not enabled %s:%d\n", \ (opt), __FILE__, __LINE__); \ goto invalid_opcode; \ } \ } while (0) #ifdef TARGET_WORDS_BIGENDIAN #define OP0 (((b0) & 0xf0) >> 4) #define OP1 (((b2) & 0xf0) >> 4) #define OP2 ((b2) & 0xf) #define RRR_R ((b1) & 0xf) #define RRR_S (((b1) & 0xf0) >> 4) #define RRR_T ((b0) & 0xf) #else #define OP0 (((b0) & 0xf)) #define OP1 (((b2) & 0xf)) #define OP2 (((b2) & 0xf0) >> 4) #define RRR_R (((b1) & 0xf0) >> 4) #define RRR_S (((b1) & 0xf)) #define RRR_T (((b0) & 0xf0) >> 4) #endif #define RRRN_R RRR_R #define RRRN_S RRR_S #define RRRN_T RRR_T #define RRI8_R RRR_R #define RRI8_S RRR_S #define RRI8_T RRR_T #define RRI8_IMM8 (b2) #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8) #ifdef TARGET_WORDS_BIGENDIAN #define RI16_IMM16 (((b1) << 8) | (b2)) #else #define RI16_IMM16 (((b2) << 8) | (b1)) #endif #ifdef TARGET_WORDS_BIGENDIAN #define CALL_N (((b0) & 0xc) >> 2) #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2)) #else #define CALL_N (((b0) & 0x30) >> 4) #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10)) #endif #define CALL_OFFSET_SE \ (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET) #define CALLX_N CALL_N #ifdef TARGET_WORDS_BIGENDIAN #define CALLX_M ((b0) & 0x3) #else #define CALLX_M (((b0) & 0xc0) >> 6) #endif #define CALLX_S RRR_S #define BRI12_M CALLX_M #define BRI12_S RRR_S #ifdef TARGET_WORDS_BIGENDIAN #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2)) #else #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4)) #endif #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12) #define BRI8_M BRI12_M #define BRI8_R RRI8_R #define BRI8_S RRI8_S #define BRI8_IMM8 RRI8_IMM8 #define BRI8_IMM8_SE RRI8_IMM8_SE #define RSR_SR (b1) uint8_t b0 = ldub_code(dc->pc); uint8_t b1 = ldub_code(dc->pc + 1); uint8_t b2 = ldub_code(dc->pc + 2); static const uint32_t B4CONST[] = { 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256 }; static const uint32_t B4CONSTU[] = { 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256 }; if (OP0 >= 8) { dc->next_pc = dc->pc + 2; HAS_OPTION(XTENSA_OPTION_CODE_DENSITY); } else { dc->next_pc = dc->pc + 3; } switch (OP0) { case 0: /*QRST*/ switch (OP1) { case 0: /*RST0*/ switch (OP2) { case 0: /*ST0*/ if ((RRR_R & 0xc) == 0x8) { HAS_OPTION(XTENSA_OPTION_BOOLEAN); } switch (RRR_R) { case 0: /*SNM0*/ switch (CALLX_M) { case 0: /*ILL*/ break; case 1: /*reserved*/ break; case 2: /*JR*/ switch (CALLX_N) { case 0: /*RET*/ case 2: /*JX*/ gen_jump(dc, cpu_R[CALLX_S]); break; case 1: /*RETWw*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; case 3: /*reserved*/ break; } break; case 3: /*CALLX*/ switch (CALLX_N) { case 0: /*CALLX0*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]); tcg_gen_movi_i32(cpu_R[0], dc->next_pc); gen_jump(dc, tmp); tcg_temp_free(tmp); } break; case 1: /*CALLX4w*/ case 2: /*CALLX8w*/ case 3: /*CALLX12w*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; } break; } break; case 1: /*MOVSPw*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; case 2: /*SYNC*/ break; case 3: break; } break; case 1: /*AND*/ tcg_gen_and_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); break; case 2: /*OR*/ tcg_gen_or_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); break; case 3: /*XOR*/ tcg_gen_xor_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); break; case 4: /*ST1*/ switch (RRR_R) { case 0: /*SSR*/ gen_right_shift_sar(dc, cpu_R[RRR_S]); break; case 1: /*SSL*/ gen_left_shift_sar(dc, cpu_R[RRR_S]); break; case 2: /*SSA8L*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3); gen_right_shift_sar(dc, tmp); tcg_temp_free(tmp); } break; case 3: /*SSA8B*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3); gen_left_shift_sar(dc, tmp); tcg_temp_free(tmp); } break; case 4: /*SSAI*/ { TCGv_i32 tmp = tcg_const_i32( RRR_S | ((RRR_T & 1) << 4)); gen_right_shift_sar(dc, tmp); tcg_temp_free(tmp); } break; case 6: /*RER*/ break; case 7: /*WER*/ break; case 8: /*ROTWw*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; case 14: /*NSAu*/ HAS_OPTION(XTENSA_OPTION_MISC_OP); gen_helper_nsa(cpu_R[RRR_T], cpu_R[RRR_S]); break; case 15: /*NSAUu*/ HAS_OPTION(XTENSA_OPTION_MISC_OP); gen_helper_nsau(cpu_R[RRR_T], cpu_R[RRR_S]); break; default: /*reserved*/ break; } break; case 5: /*TLB*/ break; case 6: /*RT0*/ switch (RRR_S) { case 0: /*NEG*/ tcg_gen_neg_i32(cpu_R[RRR_R], cpu_R[RRR_T]); break; case 1: /*ABS*/ { int label = gen_new_label(); tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_T]); tcg_gen_brcondi_i32( TCG_COND_GE, cpu_R[RRR_R], 0, label); tcg_gen_neg_i32(cpu_R[RRR_R], cpu_R[RRR_T]); gen_set_label(label); } break; default: /*reserved*/ break; } break; case 7: /*reserved*/ break; case 8: /*ADD*/ tcg_gen_add_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); break; case 9: /*ADD**/ case 10: case 11: { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 8); tcg_gen_add_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]); tcg_temp_free(tmp); } break; case 12: /*SUB*/ tcg_gen_sub_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); break; case 13: /*SUB**/ case 14: case 15: { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 12); tcg_gen_sub_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]); tcg_temp_free(tmp); } break; } break; case 1: /*RST1*/ switch (OP2) { case 0: /*SLLI*/ case 1: tcg_gen_shli_i32(cpu_R[RRR_R], cpu_R[RRR_S], 32 - (RRR_T | ((OP2 & 1) << 4))); break; case 2: /*SRAI*/ case 3: tcg_gen_sari_i32(cpu_R[RRR_R], cpu_R[RRR_T], RRR_S | ((OP2 & 1) << 4)); break; case 4: /*SRLI*/ tcg_gen_shri_i32(cpu_R[RRR_R], cpu_R[RRR_T], RRR_S); break; case 6: /*XSR*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_mov_i32(tmp, cpu_R[RRR_T]); gen_rsr(dc, cpu_R[RRR_T], RSR_SR); gen_wsr(dc, RSR_SR, tmp); tcg_temp_free(tmp); } break; /* * Note: 64 bit ops are used here solely because SAR values * have range 0..63 */ #define gen_shift_reg(cmd, reg) do { \ TCGv_i64 tmp = tcg_temp_new_i64(); \ tcg_gen_extu_i32_i64(tmp, reg); \ tcg_gen_##cmd##_i64(v, v, tmp); \ tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \ tcg_temp_free_i64(v); \ tcg_temp_free_i64(tmp); \ } while (0) #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR]) case 8: /*SRC*/ { TCGv_i64 v = tcg_temp_new_i64(); tcg_gen_concat_i32_i64(v, cpu_R[RRR_T], cpu_R[RRR_S]); gen_shift(shr); } break; case 9: /*SRL*/ if (dc->sar_5bit) { tcg_gen_shr_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]); } else { TCGv_i64 v = tcg_temp_new_i64(); tcg_gen_extu_i32_i64(v, cpu_R[RRR_T]); gen_shift(shr); } break; case 10: /*SLL*/ if (dc->sar_m32_5bit) { tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], dc->sar_m32); } else { TCGv_i64 v = tcg_temp_new_i64(); TCGv_i32 s = tcg_const_i32(32); tcg_gen_sub_i32(s, s, cpu_SR[SAR]); tcg_gen_andi_i32(s, s, 0x3f); tcg_gen_extu_i32_i64(v, cpu_R[RRR_S]); gen_shift_reg(shl, s); tcg_temp_free(s); } break; case 11: /*SRA*/ if (dc->sar_5bit) { tcg_gen_sar_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]); } else { TCGv_i64 v = tcg_temp_new_i64(); tcg_gen_ext_i32_i64(v, cpu_R[RRR_T]); gen_shift(sar); } break; #undef gen_shift #undef gen_shift_reg case 12: /*MUL16U*/ HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL); { TCGv_i32 v1 = tcg_temp_new_i32(); TCGv_i32 v2 = tcg_temp_new_i32(); tcg_gen_ext16u_i32(v1, cpu_R[RRR_S]); tcg_gen_ext16u_i32(v2, cpu_R[RRR_T]); tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2); tcg_temp_free(v2); tcg_temp_free(v1); } break; case 13: /*MUL16S*/ HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL); { TCGv_i32 v1 = tcg_temp_new_i32(); TCGv_i32 v2 = tcg_temp_new_i32(); tcg_gen_ext16s_i32(v1, cpu_R[RRR_S]); tcg_gen_ext16s_i32(v2, cpu_R[RRR_T]); tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2); tcg_temp_free(v2); tcg_temp_free(v1); } break; default: /*reserved*/ break; } break; case 2: /*RST2*/ break; case 3: /*RST3*/ switch (OP2) { case 0: /*RSR*/ gen_rsr(dc, cpu_R[RRR_T], RSR_SR); break; case 1: /*WSR*/ gen_wsr(dc, RSR_SR, cpu_R[RRR_T]); break; case 2: /*SEXTu*/ HAS_OPTION(XTENSA_OPTION_MISC_OP); { int shift = 24 - RRR_T; if (shift == 24) { tcg_gen_ext8s_i32(cpu_R[RRR_R], cpu_R[RRR_S]); } else if (shift == 16) { tcg_gen_ext16s_i32(cpu_R[RRR_R], cpu_R[RRR_S]); } else { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shli_i32(tmp, cpu_R[RRR_S], shift); tcg_gen_sari_i32(cpu_R[RRR_R], tmp, shift); tcg_temp_free(tmp); } } break; case 3: /*CLAMPSu*/ HAS_OPTION(XTENSA_OPTION_MISC_OP); { TCGv_i32 tmp1 = tcg_temp_new_i32(); TCGv_i32 tmp2 = tcg_temp_new_i32(); int label = gen_new_label(); tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 24 - RRR_T); tcg_gen_xor_i32(tmp2, tmp1, cpu_R[RRR_S]); tcg_gen_andi_i32(tmp2, tmp2, 0xffffffff << (RRR_T + 7)); tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_S]); tcg_gen_brcondi_i32(TCG_COND_EQ, tmp2, 0, label); tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 31); tcg_gen_xori_i32(cpu_R[RRR_R], tmp1, 0xffffffff >> (25 - RRR_T)); gen_set_label(label); tcg_temp_free(tmp1); tcg_temp_free(tmp2); } break; case 4: /*MINu*/ case 5: /*MAXu*/ case 6: /*MINUu*/ case 7: /*MAXUu*/ HAS_OPTION(XTENSA_OPTION_MISC_OP); { static const TCGCond cond[] = { TCG_COND_LE, TCG_COND_GE, TCG_COND_LEU, TCG_COND_GEU }; int label = gen_new_label(); if (RRR_R != RRR_T) { tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_S]); tcg_gen_brcond_i32(cond[OP2 - 4], cpu_R[RRR_S], cpu_R[RRR_T], label); tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_T]); } else { tcg_gen_brcond_i32(cond[OP2 - 4], cpu_R[RRR_T], cpu_R[RRR_S], label); tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_S]); } gen_set_label(label); } break; case 8: /*MOVEQZ*/ case 9: /*MOVNEZ*/ case 10: /*MOVLTZ*/ case 11: /*MOVGEZ*/ { static const TCGCond cond[] = { TCG_COND_NE, TCG_COND_EQ, TCG_COND_GE, TCG_COND_LT }; int label = gen_new_label(); tcg_gen_brcondi_i32(cond[OP2 - 8], cpu_R[RRR_T], 0, label); tcg_gen_mov_i32(cpu_R[RRR_R], cpu_R[RRR_S]); gen_set_label(label); } break; case 12: /*MOVFp*/ HAS_OPTION(XTENSA_OPTION_BOOLEAN); break; case 13: /*MOVTp*/ HAS_OPTION(XTENSA_OPTION_BOOLEAN); break; case 14: /*RUR*/ { int st = (RRR_S << 4) + RRR_T; if (uregnames[st]) { tcg_gen_mov_i32(cpu_R[RRR_R], cpu_UR[st]); } else { qemu_log("RUR %d not implemented, ", st); } } break; case 15: /*WUR*/ { if (uregnames[RSR_SR]) { tcg_gen_mov_i32(cpu_UR[RSR_SR], cpu_R[RRR_T]); } else { qemu_log("WUR %d not implemented, ", RSR_SR); } } break; } break; case 4: /*EXTUI*/ case 5: { int shiftimm = RRR_S | (OP1 << 4); int maskimm = (1 << (OP2 + 1)) - 1; TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_shri_i32(tmp, cpu_R[RRR_T], shiftimm); tcg_gen_andi_i32(cpu_R[RRR_R], tmp, maskimm); tcg_temp_free(tmp); } break; case 6: /*CUST0*/ break; case 7: /*CUST1*/ break; case 8: /*LSCXp*/ HAS_OPTION(XTENSA_OPTION_COPROCESSOR); break; case 9: /*LSC4*/ break; case 10: /*FP0*/ HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); break; case 11: /*FP1*/ HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); break; default: /*reserved*/ break; } break; case 1: /*L32R*/ { TCGv_i32 tmp = tcg_const_i32( (0xfffc0000 | (RI16_IMM16 << 2)) + ((dc->pc + 3) & ~3)); /* no ext L32R */ tcg_gen_qemu_ld32u(cpu_R[RRR_T], tmp, 0); tcg_temp_free(tmp); } break; case 2: /*LSAI*/ #define gen_load_store(type, shift) do { \ TCGv_i32 addr = tcg_temp_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, 0); \ tcg_temp_free(addr); \ } while (0) switch (RRI8_R) { case 0: /*L8UI*/ gen_load_store(ld8u, 0); break; case 1: /*L16UI*/ gen_load_store(ld16u, 1); break; case 2: /*L32I*/ gen_load_store(ld32u, 2); break; case 4: /*S8I*/ gen_load_store(st8, 0); break; case 5: /*S16I*/ gen_load_store(st16, 1); break; case 6: /*S32I*/ gen_load_store(st32, 2); break; case 7: /*CACHEc*/ break; case 9: /*L16SI*/ gen_load_store(ld16s, 1); break; case 10: /*MOVI*/ tcg_gen_movi_i32(cpu_R[RRI8_T], RRI8_IMM8 | (RRI8_S << 8) | ((RRI8_S & 0x8) ? 0xfffff000 : 0)); break; case 11: /*L32AIy*/ HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO); gen_load_store(ld32u, 2); /*TODO acquire?*/ break; case 12: /*ADDI*/ tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE); break; case 13: /*ADDMI*/ tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE << 8); break; case 14: /*S32C1Iy*/ HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO); { int label = gen_new_label(); TCGv_i32 tmp = tcg_temp_local_new_i32(); TCGv_i32 addr = tcg_temp_local_new_i32(); tcg_gen_mov_i32(tmp, cpu_R[RRI8_T]); tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); tcg_gen_qemu_ld32u(cpu_R[RRI8_T], addr, 0); tcg_gen_brcond_i32(TCG_COND_NE, cpu_R[RRI8_T], cpu_SR[SCOMPARE1], label); tcg_gen_qemu_st32(tmp, addr, 0); gen_set_label(label); tcg_temp_free(addr); tcg_temp_free(tmp); } break; case 15: /*S32RIy*/ HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO); gen_load_store(st32, 2); /*TODO release?*/ break; default: /*reserved*/ break; } break; #undef gen_load_store case 3: /*LSCIp*/ HAS_OPTION(XTENSA_OPTION_COPROCESSOR); break; case 4: /*MAC16d*/ HAS_OPTION(XTENSA_OPTION_MAC16); break; case 5: /*CALLN*/ switch (CALL_N) { case 0: /*CALL0*/ tcg_gen_movi_i32(cpu_R[0], dc->next_pc); gen_jumpi(dc, (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0); break; case 1: /*CALL4w*/ case 2: /*CALL8w*/ case 3: /*CALL12w*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; } break; case 6: /*SI*/ switch (CALL_N) { case 0: /*J*/ gen_jumpi(dc, dc->pc + 4 + CALL_OFFSET_SE, 0); break; case 1: /*BZ*/ { static const TCGCond cond[] = { TCG_COND_EQ, /*BEQZ*/ TCG_COND_NE, /*BNEZ*/ TCG_COND_LT, /*BLTZ*/ TCG_COND_GE, /*BGEZ*/ }; gen_brcondi(dc, cond[BRI12_M & 3], cpu_R[BRI12_S], 0, 4 + BRI12_IMM12_SE); } break; case 2: /*BI0*/ { static const TCGCond cond[] = { TCG_COND_EQ, /*BEQI*/ TCG_COND_NE, /*BNEI*/ TCG_COND_LT, /*BLTI*/ TCG_COND_GE, /*BGEI*/ }; gen_brcondi(dc, cond[BRI8_M & 3], cpu_R[BRI8_S], B4CONST[BRI8_R], 4 + BRI8_IMM8_SE); } break; case 3: /*BI1*/ switch (BRI8_M) { case 0: /*ENTRYw*/ HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); break; case 1: /*B1*/ switch (BRI8_R) { case 0: /*BFp*/ HAS_OPTION(XTENSA_OPTION_BOOLEAN); break; case 1: /*BTp*/ HAS_OPTION(XTENSA_OPTION_BOOLEAN); break; case 8: /*LOOP*/ break; case 9: /*LOOPNEZ*/ break; case 10: /*LOOPGTZ*/ break; default: /*reserved*/ break; } break; case 2: /*BLTUI*/ case 3: /*BGEUI*/ gen_brcondi(dc, BRI8_M == 2 ? TCG_COND_LTU : TCG_COND_GEU, cpu_R[BRI8_S], B4CONSTU[BRI8_R], 4 + BRI8_IMM8_SE); break; } break; } break; case 7: /*B*/ { TCGCond eq_ne = (RRI8_R & 8) ? TCG_COND_NE : TCG_COND_EQ; switch (RRI8_R & 7) { case 0: /*BNONE*/ /*BANY*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]); gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); tcg_temp_free(tmp); } break; case 1: /*BEQ*/ /*BNE*/ case 2: /*BLT*/ /*BGE*/ case 3: /*BLTU*/ /*BGEU*/ { static const TCGCond cond[] = { [1] = TCG_COND_EQ, [2] = TCG_COND_LT, [3] = TCG_COND_LTU, [9] = TCG_COND_NE, [10] = TCG_COND_GE, [11] = TCG_COND_GEU, }; gen_brcond(dc, cond[RRI8_R], cpu_R[RRI8_S], cpu_R[RRI8_T], 4 + RRI8_IMM8_SE); } break; case 4: /*BALL*/ /*BNALL*/ { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]); gen_brcond(dc, eq_ne, tmp, cpu_R[RRI8_T], 4 + RRI8_IMM8_SE); tcg_temp_free(tmp); } break; case 5: /*BBC*/ /*BBS*/ { TCGv_i32 bit = tcg_const_i32(1); TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_andi_i32(tmp, cpu_R[RRI8_T], 0x1f); tcg_gen_shl_i32(bit, bit, tmp); tcg_gen_and_i32(tmp, cpu_R[RRI8_S], bit); gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); tcg_temp_free(tmp); tcg_temp_free(bit); } break; case 6: /*BBCI*/ /*BBSI*/ case 7: { TCGv_i32 tmp = tcg_temp_new_i32(); tcg_gen_andi_i32(tmp, cpu_R[RRI8_S], 1 << (((RRI8_R & 1) << 4) | RRI8_T)); gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); tcg_temp_free(tmp); } break; } } break; #define gen_narrow_load_store(type) do { \ TCGv_i32 addr = tcg_temp_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \ tcg_temp_free(addr); \ } while (0) case 8: /*L32I.Nn*/ gen_narrow_load_store(ld32u); break; case 9: /*S32I.Nn*/ gen_narrow_load_store(st32); break; #undef gen_narrow_load_store case 10: /*ADD.Nn*/ tcg_gen_add_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], cpu_R[RRRN_T]); break; case 11: /*ADDI.Nn*/ tcg_gen_addi_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], RRRN_T ? RRRN_T : -1); break; case 12: /*ST2n*/ if (RRRN_T < 8) { /*MOVI.Nn*/ tcg_gen_movi_i32(cpu_R[RRRN_S], RRRN_R | (RRRN_T << 4) | ((RRRN_T & 6) == 6 ? 0xffffff80 : 0)); } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/ TCGCond eq_ne = (RRRN_T & 4) ? TCG_COND_NE : TCG_COND_EQ; gen_brcondi(dc, eq_ne, cpu_R[RRRN_S], 0, 4 + (RRRN_R | ((RRRN_T & 3) << 4))); } break; case 13: /*ST3n*/ switch (RRRN_R) { case 0: /*MOV.Nn*/ tcg_gen_mov_i32(cpu_R[RRRN_T], cpu_R[RRRN_S]); break; case 15: /*S3*/ switch (RRRN_T) { case 0: /*RET.Nn*/ gen_jump(dc, cpu_R[0]); break; case 1: /*RETW.Nn*/ break; case 2: /*BREAK.Nn*/ break; case 3: /*NOP.Nn*/ break; case 6: /*ILL.Nn*/ break; default: /*reserved*/ break; } break; default: /*reserved*/ break; } break; default: /*reserved*/ break; } dc->pc = dc->next_pc; return; invalid_opcode: qemu_log("INVALID(pc = %08x)\n", dc->pc); dc->pc = dc->next_pc; #undef HAS_OPTION }
true
qemu
91a5bb76d47e1b06f0b7b67cae8497d8efc6ab87
24,781
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) { BdrvChild *child; Error *local_err = NULL; int ret; if (!bs->drv) { return; } if (!(bs->open_flags & BDRV_O_INACTIVE)) { return; } bs->open_flags &= ~BDRV_O_INACTIVE; if (bs->drv->bdrv_invalidate_cache) { bs->drv->bdrv_invalidate_cache(bs, &local_err); if (local_err) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); return; } } QLIST_FOREACH(child, &bs->children, next) { bdrv_invalidate_cache(child->bs, &local_err); if (local_err) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); return; } } ret = refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { bs->open_flags |= BDRV_O_INACTIVE; error_setg_errno(errp, -ret, "Could not refresh total sector count"); return; } }
true
qemu
16e977d506bcc2d9f7daa4a9f7cc2b48536d9da6
24,782
static int context_init(H264Context *h){ MpegEncContext * const s = &h->s; CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; return 0; fail: return -1; // free_tables will clean up for us }
true
FFmpeg
79db7ac6ef235a06c3049d7792eda39da28ee3fd
24,783
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, AVFrame *pic_arg, int *got_packet) { MpegEncContext *s = avctx->priv_data; int i, stuffing_count, ret; int context_count = s->slice_context_count; s->picture_in_gop_number++; if (load_input_picture(s, pic_arg) < 0) return -1; if (select_input_picture(s) < 0) { return -1; } /* output? */ if (s->new_picture.f.data[0]) { if ((ret = ff_alloc_packet2(avctx, pkt, s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000)) < 0) return ret; if (s->mb_info) { s->mb_info_ptr = av_packet_new_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_width*s->mb_height*12); s->prev_mb_info = s->last_mb_info = s->mb_info_size = 0; } for (i = 0; i < context_count; i++) { int start_y = s->thread_context[i]->start_mb_y; int end_y = s->thread_context[i]-> end_mb_y; int h = s->mb_height; uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h); uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h); init_put_bits(&s->thread_context[i]->pb, start, end - start); } s->pict_type = s->new_picture.f.pict_type; //emms_c(); //printf("qs:%f %f %d\n", s->new_picture.quality, // s->current_picture.quality, s->qscale); ff_MPV_frame_start(s, avctx); vbv_retry: if (encode_picture(s, s->picture_number) < 0) return -1; avctx->header_bits = s->header_bits; avctx->mv_bits = s->mv_bits; avctx->misc_bits = s->misc_bits; avctx->i_tex_bits = s->i_tex_bits; avctx->p_tex_bits = s->p_tex_bits; avctx->i_count = s->i_count; // FIXME f/b_count in avctx avctx->p_count = s->mb_num - s->i_count - s->skip_count; avctx->skip_count = s->skip_count; ff_MPV_frame_end(s); if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) ff_mjpeg_encode_picture_trailer(s); if (avctx->rc_buffer_size) { RateControlContext *rcc = &s->rc_context; int max_size = rcc->buffer_index * avctx->rc_max_available_vbv_use; if (put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax) { s->next_lambda = FFMAX(s->lambda + 1, s->lambda * (s->qscale + 1) / s->qscale); if (s->adaptive_quant) { int i; for (i = 0; i < s->mb_height * s->mb_stride; i++) s->lambda_table[i] = FFMAX(s->lambda_table[i] + 1, s->lambda_table[i] * (s->qscale + 1) / s->qscale); } s->mb_skipped = 0; // done in MPV_frame_start() // done in encode_picture() so we must undo it if (s->pict_type == AV_PICTURE_TYPE_P) { if (s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) s->no_rounding ^= 1; } if (s->pict_type != AV_PICTURE_TYPE_B) { s->time_base = s->last_time_base; s->last_non_b_time = s->time - s->pp_time; } //av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); for (i = 0; i < context_count; i++) { PutBitContext *pb = &s->thread_context[i]->pb; init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); } goto vbv_retry; } assert(s->avctx->rc_max_rate); } if (s->flags & CODEC_FLAG_PASS1) ff_write_pass1_stats(s); for (i = 0; i < 4; i++) { s->current_picture_ptr->f.error[i] = s->current_picture.f.error[i]; avctx->error[i] += s->current_picture_ptr->f.error[i]; } if (s->flags & CODEC_FLAG_PASS1) assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); flush_put_bits(&s->pb); s->frame_bits = put_bits_count(&s->pb); stuffing_count = ff_vbv_update(s, s->frame_bits); if (stuffing_count) { if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < stuffing_count + 50) { av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); return -1; } switch (s->codec_id) { case CODEC_ID_MPEG1VIDEO: case CODEC_ID_MPEG2VIDEO: while (stuffing_count--) { put_bits(&s->pb, 8, 0); } break; case CODEC_ID_MPEG4: put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, 0x1C3); stuffing_count -= 4; while (stuffing_count--) { put_bits(&s->pb, 8, 0xFF); } break; default: av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); } flush_put_bits(&s->pb); s->frame_bits = put_bits_count(&s->pb); } /* update mpeg1/2 vbv_delay for CBR */ if (s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 && 90000LL * (avctx->rc_buffer_size - 1) <= s->avctx->rc_max_rate * 0xFFFFLL) { int vbv_delay, min_delay; double inbits = s->avctx->rc_max_rate * av_q2d(s->avctx->time_base); int minbits = s->frame_bits - 8 * (s->vbv_delay_ptr - s->pb.buf - 1); double bits = s->rc_context.buffer_index + minbits - inbits; if (bits < 0) av_log(s->avctx, AV_LOG_ERROR, "Internal error, negative bits\n"); assert(s->repeat_first_field == 0); vbv_delay = bits * 90000 / s->avctx->rc_max_rate; min_delay = (minbits * 90000LL + s->avctx->rc_max_rate - 1) / s->avctx->rc_max_rate; vbv_delay = FFMAX(vbv_delay, min_delay); assert(vbv_delay < 0xFFFF); s->vbv_delay_ptr[0] &= 0xF8; s->vbv_delay_ptr[0] |= vbv_delay >> 13; s->vbv_delay_ptr[1] = vbv_delay >> 5; s->vbv_delay_ptr[2] &= 0x07; s->vbv_delay_ptr[2] |= vbv_delay << 3; avctx->vbv_delay = vbv_delay * 300; } s->total_bits += s->frame_bits; avctx->frame_bits = s->frame_bits; pkt->pts = s->current_picture.f.pts; if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { if (!s->current_picture.f.coded_picture_number) pkt->dts = pkt->pts - s->dts_delta; else pkt->dts = s->reordered_pts; s->reordered_pts = pkt->pts; } else pkt->dts = pkt->pts; if (s->current_picture.f.key_frame) pkt->flags |= AV_PKT_FLAG_KEY; if (s->mb_info) av_packet_shrink_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_info_size); } else { assert((put_bits_ptr(&s->pb) == s->pb.buf)); s->frame_bits = 0; } assert((s->frame_bits & 7) == 0); pkt->size = s->frame_bits / 8; *got_packet = !!pkt->size; return 0; }
true
FFmpeg
f72e0d9a9f516be77d20c6a37dcd34add8f932e3
24,784
static int check_slice_end(RV34DecContext *r, MpegEncContext *s) { int bits; if(s->mb_y >= s->mb_height) return 1; if(!s->mb_num_left) return 1; if(r->s.mb_skip_run > 1) return 0; bits = get_bits_left(&s->gb); if(bits < 0 || (bits < 8 && !show_bits(&s->gb, bits))) return 1; return 0; }
false
FFmpeg
2d0b4bc4cf92dd961dbafbff3f1f4a9e08a9565b
24,785
static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, ScratchpadContext *sc, int chroma_x_shift, int chroma_y_shift, int linesize, int uvlinesize) { int edges_needed = av_codec_is_encoder(avctx->codec); int r, ret; pic->tf.f = pic->f; if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && avctx->codec_id != AV_CODEC_ID_VC1IMAGE && avctx->codec_id != AV_CODEC_ID_MSS2) { if (edges_needed) { pic->f->width = avctx->width + 2 * EDGE_WIDTH; pic->f->height = avctx->height + 2 * EDGE_WIDTH; } r = ff_thread_get_buffer(avctx, &pic->tf, pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); } else { pic->f->width = avctx->width; pic->f->height = avctx->height; pic->f->format = avctx->pix_fmt; r = avcodec_default_get_buffer2(avctx, pic->f, 0); } if (r < 0 || !pic->f->buf[0]) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n", r, pic->f->data[0]); return -1; } if (edges_needed) { int i; for (i = 0; pic->f->data[i]; i++) { int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) * pic->f->linesize[i] + (EDGE_WIDTH >> (i ? chroma_x_shift : 0)); pic->f->data[i] += offset; } pic->f->width = avctx->width; pic->f->height = avctx->height; } if (avctx->hwaccel) { assert(!pic->hwaccel_picture_private); if (avctx->hwaccel->frame_priv_data_size) { pic->hwaccel_priv_buf = av_buffer_allocz(avctx->hwaccel->frame_priv_data_size); if (!pic->hwaccel_priv_buf) { av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n"); return -1; } pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data; } } if (linesize && (linesize != pic->f->linesize[0] || uvlinesize != pic->f->linesize[1])) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); ff_mpeg_unref_picture(avctx, pic); return -1; } if (pic->f->linesize[1] != pic->f->linesize[2]) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n"); ff_mpeg_unref_picture(avctx, pic); return -1; } if (!sc->edge_emu_buffer && (ret = ff_mpeg_framesize_alloc(avctx, me, sc, pic->f->linesize[0])) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed to allocate context scratch buffers.\n"); ff_mpeg_unref_picture(avctx, pic); return ret; } return 0; }
false
FFmpeg
bb4c9d0a8ead02f7d943c2bae3e36b30e605b30b
24,786
void ff_avg_h264_qpel4_mc32_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_midh_qrt_and_aver_dst_4w_msa(src - (2 * stride) - 2, stride, dst, stride, 4, 1); }
false
FFmpeg
72dbc610be3272ba36603f78a39cc2d2d8fe0cc3
24,788
static void show_programs(WriterContext *w, AVFormatContext *fmt_ctx) { int i; writer_print_section_header(w, SECTION_ID_PROGRAMS); for (i = 0; i < fmt_ctx->nb_programs; i++) { AVProgram *program = fmt_ctx->programs[i]; if (!program) continue; show_program(w, fmt_ctx, program); } writer_print_section_footer(w); }
false
FFmpeg
e87190f5d20d380608f792ceb14d0def1d80e24b
24,789
static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec) { int write_comment = (codec->channel_layout && !(codec->channel_layout & ~0x3ffffULL) && !ff_flac_is_native_layout(codec->channel_layout)); int ret = ff_flac_write_header(pb, codec->extradata, codec->extradata_size, !write_comment); if (ret < 0) return ret; if (write_comment) { const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ? "Lavf" : LIBAVFORMAT_IDENT; AVDictionary *dict = NULL; uint8_t buf[32], *data, *p; int len; snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); len = ff_vorbiscomment_length(dict, vendor); data = av_malloc(len + 4); if (!data) { av_dict_free(&dict); return AVERROR(ENOMEM); } data[0] = 0x84; AV_WB24(data + 1, len); p = data + 4; ff_vorbiscomment_write(&p, &dict, vendor); avio_write(pb, data, len + 4); av_freep(&data); av_dict_free(&dict); } return 0; }
false
FFmpeg
66f26b3e8ec075298e7ba329a55893d085bafe96
24,791
static uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num) { BDRVQcowState *s = bs->opaque; int l1_index, l2_index; uint64_t l2_offset, *l2_table, cluster_offset; int l1_bits, c; int index_in_cluster, nb_available, nb_needed, nb_clusters; index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1); nb_needed = *num + index_in_cluster; l1_bits = s->l2_bits + s->cluster_bits; /* compute how many bytes there are between the offset and * the end of the l1 entry */ nb_available = (1 << l1_bits) - (offset & ((1 << l1_bits) - 1)); /* compute the number of available sectors */ nb_available = (nb_available >> 9) + index_in_cluster; cluster_offset = 0; /* seek the the l2 offset in the l1 table */ l1_index = offset >> l1_bits; if (l1_index >= s->l1_size) goto out; l2_offset = s->l1_table[l1_index]; /* seek the l2 table of the given l2 offset */ if (!l2_offset) goto out; /* load the l2 table in memory */ l2_offset &= ~QCOW_OFLAG_COPIED; l2_table = l2_load(bs, l2_offset); if (l2_table == NULL) return 0; /* find the cluster offset for the given disk offset */ l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1); cluster_offset = be64_to_cpu(l2_table[l2_index]); nb_clusters = size_to_clusters(s, nb_needed << 9); if (!cluster_offset) { /* how many empty clusters ? */ c = count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]); } else { /* how many allocated clusters ? */ c = count_contiguous_clusters(nb_clusters, s->cluster_size, &l2_table[l2_index], 0, QCOW_OFLAG_COPIED); nb_available = (c * s->cluster_sectors); out: if (nb_available > nb_needed) nb_available = nb_needed; *num = nb_available - index_in_cluster; return cluster_offset & ~QCOW_OFLAG_COPIED;
true
qemu
f8de16605cf9864e258d91e95be0ed76bdeac744
24,792
static int rscc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { RsccContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; GetByteContext tiles_gbc; AVFrame *frame = data; const uint8_t *pixels, *raw; uint8_t *inflated_tiles = NULL; int tiles_nb, packed_size, pixel_size = 0; int i, ret = 0; bytestream2_init(gbc, avpkt->data, avpkt->size); /* Size check */ if (bytestream2_get_bytes_left(gbc) < 12) { av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size); return AVERROR_INVALIDDATA; /* Read number of tiles, and allocate the array */ tiles_nb = bytestream2_get_le16(gbc); av_fast_malloc(&ctx->tiles, &ctx->tiles_size, tiles_nb * sizeof(*ctx->tiles)); if (!ctx->tiles) { ret = AVERROR(ENOMEM); av_log(avctx, AV_LOG_DEBUG, "Frame with %d tiles.\n", tiles_nb); /* When there are more than 5 tiles, they are packed together with * a size header. When that size does not match the number of tiles * times the tile size, it means it needs to be inflated as well */ if (tiles_nb > 5) { uLongf packed_tiles_size; if (tiles_nb < 32) packed_tiles_size = bytestream2_get_byte(gbc); else packed_tiles_size = bytestream2_get_le16(gbc); ff_dlog(avctx, "packed tiles of size %lu.\n", packed_tiles_size); /* If necessary, uncompress tiles, and hijack the bytestream reader */ if (packed_tiles_size != tiles_nb * TILE_SIZE) { uLongf length = tiles_nb * TILE_SIZE; inflated_tiles = av_malloc(length); if (!inflated_tiles) { ret = AVERROR(ENOMEM); ret = uncompress(inflated_tiles, &length, gbc->buffer, packed_tiles_size); if (ret) { av_log(avctx, AV_LOG_ERROR, "Tile deflate error %d.\n", ret); ret = AVERROR_UNKNOWN; /* Skip the compressed tile section in the main byte reader, * and point it to read the newly uncompressed data */ bytestream2_skip(gbc, packed_tiles_size); bytestream2_init(&tiles_gbc, inflated_tiles, length); gbc = &tiles_gbc; /* Fill in array of tiles, keeping track of how many pixels are updated */ for (i = 0; i < tiles_nb; i++) { ctx->tiles[i].x = bytestream2_get_le16(gbc); ctx->tiles[i].w = bytestream2_get_le16(gbc); ctx->tiles[i].y = bytestream2_get_le16(gbc); ctx->tiles[i].h = bytestream2_get_le16(gbc); pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * ctx->component_size; ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i, ctx->tiles[i].x, ctx->tiles[i].y, ctx->tiles[i].w, ctx->tiles[i].h); if (ctx->tiles[i].w == 0 || ctx->tiles[i].h == 0) { av_log(avctx, AV_LOG_ERROR, "invalid tile %d at (%d.%d) with size %dx%d.\n", i, ctx->tiles[i].x, ctx->tiles[i].y, ctx->tiles[i].w, ctx->tiles[i].h); } else if (ctx->tiles[i].x + ctx->tiles[i].w > avctx->width || ctx->tiles[i].y + ctx->tiles[i].h > avctx->height) { av_log(avctx, AV_LOG_ERROR, "out of bounds tile %d at (%d.%d) with size %dx%d.\n", i, ctx->tiles[i].x, ctx->tiles[i].y, ctx->tiles[i].w, ctx->tiles[i].h); /* Reset the reader in case it had been modified before */ gbc = &ctx->gbc; /* Extract how much pixel data the tiles contain */ if (pixel_size < 0x100) packed_size = bytestream2_get_byte(gbc); else if (pixel_size < 0x10000) packed_size = bytestream2_get_le16(gbc); else if (pixel_size < 0x1000000) packed_size = bytestream2_get_le24(gbc); else packed_size = bytestream2_get_le32(gbc); ff_dlog(avctx, "pixel_size %d packed_size %d.\n", pixel_size, packed_size); if (packed_size < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid tile size %d\n", packed_size); /* Get pixels buffer, it may be deflated or just raw */ if (pixel_size == packed_size) { if (bytestream2_get_bytes_left(gbc) < pixel_size) { av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", pixel_size); pixels = gbc->buffer; } else { uLongf len = ctx->inflated_size; ret = uncompress(ctx->inflated_buf, &len, gbc->buffer, packed_size); if (ret) { av_log(avctx, AV_LOG_ERROR, "Pixel deflate error %d.\n", ret); ret = AVERROR_UNKNOWN; pixels = ctx->inflated_buf; /* Allocate when needed */ ret = ff_reget_buffer(avctx, ctx->reference); if (ret < 0) /* Pointer to actual pixels, will be updated when data is consumed */ raw = pixels; for (i = 0; i < tiles_nb; i++) { uint8_t *dst = ctx->reference->data[0] + ctx->reference->linesize[0] * (avctx->height - ctx->tiles[i].y - 1) + ctx->tiles[i].x * ctx->component_size; av_image_copy_plane(dst, -1 * ctx->reference->linesize[0], raw, ctx->tiles[i].w * ctx->component_size, ctx->tiles[i].w * ctx->component_size, ctx->tiles[i].h); raw += ctx->tiles[i].w * ctx->component_size * ctx->tiles[i].h; /* Frame is ready to be output */ ret = av_frame_ref(frame, ctx->reference); if (ret < 0) /* Keyframe when the number of pixels updated matches the whole surface */ if (pixel_size == ctx->inflated_size) { frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; } else { frame->pict_type = AV_PICTURE_TYPE_P; *got_frame = 1; end: av_free(inflated_tiles); return ret;
true
FFmpeg
b2244fa0a624f7e38893d58265e9c039bed2e4de
24,793
static int64_t wrap_timestamp(AVStream *st, int64_t timestamp) { if (st->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && st->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { if (st->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && timestamp < st->pts_wrap_reference) return timestamp + (1LL<<st->pts_wrap_bits); else if (st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && timestamp >= st->pts_wrap_reference) return timestamp - (1LL<<st->pts_wrap_bits); } return timestamp; }
true
FFmpeg
1662bd350a470f1cbd5c2cc9a0e1bfaa8543033f
24,795
static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1, const uint8_t *buf, int buf_size, int is_start) { MpegTSContext *ts = s->priv_data; MpegTSSectionFilter *tss = &tss1->u.section_filter; int len; if (is_start) { memcpy(tss->section_buf, buf, buf_size); tss->section_index = buf_size; tss->section_h_size = -1; tss->end_of_section_reached = 0; } else { if (tss->end_of_section_reached) return; len = 4096 - tss->section_index; if (buf_size < len) len = buf_size; memcpy(tss->section_buf + tss->section_index, buf, len); tss->section_index += len; } /* compute section length if possible */ if (tss->section_h_size == -1 && tss->section_index >= 3) { len = (AV_RB16(tss->section_buf + 1) & 0xfff) + 3; if (len > 4096) return; tss->section_h_size = len; } if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) { int crc_valid = 1; tss->end_of_section_reached = 1; if (tss->check_crc) { crc_valid = !av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, tss->section_buf, tss->section_h_size); if (crc_valid) { ts->crc_validity[ tss1->pid ] = 100; }else if (ts->crc_validity[ tss1->pid ] > -10) { ts->crc_validity[ tss1->pid ]--; }else crc_valid = 2; } if (crc_valid) tss->section_cb(tss1, tss->section_buf, tss->section_h_size); } }
true
FFmpeg
8635954335061ea4c03d3f492b7bc803ea740d9c
24,796
bool migrate_auto_converge(void) { MigrationState *s; s = migrate_get_current(); return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE]; }
true
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
24,797
static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; const uint8_t *buf_end = buf + buf_size; DPCMContext *s = avctx->priv_data; int out = 0, ret; int predictor[2]; int ch = 0; int stereo = s->channels - 1; int16_t *output_samples; /* calculate output size */ switch(avctx->codec->id) { case CODEC_ID_ROQ_DPCM: out = buf_size - 8; break; case CODEC_ID_INTERPLAY_DPCM: out = buf_size - 6 - s->channels; break; case CODEC_ID_XAN_DPCM: out = buf_size - 2 * s->channels; break; case CODEC_ID_SOL_DPCM: if (avctx->codec_tag != 3) out = buf_size * 2; else out = buf_size; break; } if (out <= 0) { av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); return AVERROR(EINVAL); } /* get output buffer */ s->frame.nb_samples = out / s->channels; if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } output_samples = (int16_t *)s->frame.data[0]; switch(avctx->codec->id) { case CODEC_ID_ROQ_DPCM: buf += 6; if (stereo) { predictor[1] = (int16_t)(bytestream_get_byte(&buf) << 8); predictor[0] = (int16_t)(bytestream_get_byte(&buf) << 8); } else { predictor[0] = (int16_t)bytestream_get_le16(&buf); } /* decode the samples */ while (buf < buf_end) { predictor[ch] += s->roq_square_array[*buf++]; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; case CODEC_ID_INTERPLAY_DPCM: buf += 6; /* skip over the stream mask and stream length */ for (ch = 0; ch < s->channels; ch++) { predictor[ch] = (int16_t)bytestream_get_le16(&buf); *output_samples++ = predictor[ch]; } ch = 0; while (buf < buf_end) { predictor[ch] += interplay_delta_table[*buf++]; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; case CODEC_ID_XAN_DPCM: { int shift[2] = { 4, 4 }; for (ch = 0; ch < s->channels; ch++) predictor[ch] = (int16_t)bytestream_get_le16(&buf); ch = 0; while (buf < buf_end) { uint8_t n = *buf++; int16_t diff = (n & 0xFC) << 8; if ((n & 0x03) == 3) shift[ch]++; else shift[ch] -= (2 * (n & 3)); /* saturate the shifter to a lower limit of 0 */ if (shift[ch] < 0) shift[ch] = 0; diff >>= shift[ch]; predictor[ch] += diff; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; } case CODEC_ID_SOL_DPCM: if (avctx->codec_tag != 3) { uint8_t *output_samples_u8 = data; while (buf < buf_end) { uint8_t n = *buf++; s->sample[0] += s->sol_table[n >> 4]; s->sample[0] = av_clip_uint8(s->sample[0]); *output_samples_u8++ = s->sample[0]; s->sample[stereo] += s->sol_table[n & 0x0F]; s->sample[stereo] = av_clip_uint8(s->sample[stereo]); *output_samples_u8++ = s->sample[stereo]; } } else { while (buf < buf_end) { uint8_t n = *buf++; if (n & 0x80) s->sample[ch] -= sol_table_16[n & 0x7F]; else s->sample[ch] += sol_table_16[n & 0x7F]; s->sample[ch] = av_clip_int16(s->sample[ch]); *output_samples++ = s->sample[ch]; /* toggle channel */ ch ^= stereo; } } break; } *got_frame_ptr = 1; *(AVFrame *)data = s->frame; return buf_size; }
true
FFmpeg
529a25d6e5c3ff889257a57042872d84dc2312d5
24,798
static int get_cluster_table(BlockDriverState *bs, uint64_t offset, uint64_t **new_l2_table, uint64_t *new_l2_offset, int *new_l2_index) { BDRVQcowState *s = bs->opaque; unsigned int l1_index, l2_index; uint64_t l2_offset; uint64_t *l2_table = NULL; int ret; /* seek the the l2 offset in the l1 table */ l1_index = offset >> (s->l2_bits + s->cluster_bits); if (l1_index >= s->l1_size) { ret = qcow2_grow_l1_table(bs, l1_index + 1, false); if (ret < 0) { return ret; } } l2_offset = s->l1_table[l1_index]; /* seek the l2 table of the given l2 offset */ if (l2_offset & QCOW_OFLAG_COPIED) { /* load the l2 table in memory */ l2_offset &= ~QCOW_OFLAG_COPIED; ret = l2_load(bs, l2_offset, &l2_table); if (ret < 0) { return ret; } } else { /* FIXME Order */ if (l2_offset) qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t)); ret = l2_allocate(bs, l1_index, &l2_table); if (ret < 0) { return ret; } l2_offset = s->l1_table[l1_index] & ~QCOW_OFLAG_COPIED; } /* find the cluster offset for the given disk offset */ l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1); *new_l2_table = l2_table; *new_l2_offset = l2_offset; *new_l2_index = l2_index; return 0; }
true
qemu
16fde5f2c2788232b16c06d34d0459a5c1ec1f6c
24,799
static int decode_dds1(GetByteContext *gb, uint8_t *frame, int width, int height) { const uint8_t *frame_start = frame; const uint8_t *frame_end = frame + width * height; int mask = 0x10000, bitbuf = 0; int i, v, offset, count, segments; segments = bytestream2_get_le16(gb); while (segments--) { if (bytestream2_get_bytes_left(gb) < 2) return AVERROR_INVALIDDATA; if (mask == 0x10000) { bitbuf = bytestream2_get_le16u(gb); mask = 1; } if (bitbuf & mask) { v = bytestream2_get_le16(gb); offset = (v & 0x1FFF) << 2; count = ((v >> 13) + 2) << 1; if (frame - frame_start < offset || frame_end - frame < count*2 + width) return AVERROR_INVALIDDATA; for (i = 0; i < count; i++) { frame[0] = frame[1] = frame[width] = frame[width + 1] = frame[-offset]; frame += 2; } } else if (bitbuf & (mask << 1)) { v = bytestream2_get_le16(gb)*2; if (frame - frame_end < v) return AVERROR_INVALIDDATA; frame += v; } else { if (frame_end - frame < width + 3) return AVERROR_INVALIDDATA; frame[0] = frame[1] = frame[width] = frame[width + 1] = bytestream2_get_byte(gb); frame += 2; frame[0] = frame[1] = frame[width] = frame[width + 1] = bytestream2_get_byte(gb); frame += 2; } mask <<= 2; } return 0; }
true
FFmpeg
f52fbf4f3ed02a7d872d8a102006f29b4421f360
24,800
int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header) { uint8_t rps_predict = 0; int delta_poc; int k0 = 0; int k1 = 0; int k = 0; int i; if (rps != sps->st_rps && sps->nb_st_rps) rps_predict = get_bits1(gb); if (rps_predict) { const ShortTermRPS *rps_ridx; int delta_rps; unsigned abs_delta_rps; uint8_t use_delta_flag = 0; uint8_t delta_rps_sign; if (is_slice_header) { unsigned int delta_idx = get_ue_golomb_long(gb) + 1; if (delta_idx > sps->nb_st_rps) { "Invalid value of delta_idx in slice header RPS: %d > %d.\n", delta_idx, sps->nb_st_rps); rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx]; rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs; } else rps_ridx = &sps->st_rps[rps - sps->st_rps - 1]; delta_rps_sign = get_bits1(gb); abs_delta_rps = get_ue_golomb_long(gb) + 1; if (abs_delta_rps < 1 || abs_delta_rps > 32768) { "Invalid value of abs_delta_rps: %d\n", abs_delta_rps); delta_rps = (1 - (delta_rps_sign << 1)) * abs_delta_rps; for (i = 0; i <= rps_ridx->num_delta_pocs; i++) { int used = rps->used[k] = get_bits1(gb); if (!used) use_delta_flag = get_bits1(gb); if (used || use_delta_flag) { if (i < rps_ridx->num_delta_pocs) delta_poc = delta_rps + rps_ridx->delta_poc[i]; else delta_poc = delta_rps; rps->delta_poc[k] = delta_poc; if (delta_poc < 0) k0++; else k1++; k++; if (k >= FF_ARRAY_ELEMS(rps->used)) { "Invalid num_delta_pocs: %d\n", k); rps->num_delta_pocs = k; rps->num_negative_pics = k0; // sort in increasing order (smallest first) if (rps->num_delta_pocs != 0) { int used, tmp; for (i = 1; i < rps->num_delta_pocs; i++) { delta_poc = rps->delta_poc[i]; used = rps->used[i]; for (k = i - 1; k >= 0; k--) { tmp = rps->delta_poc[k]; if (delta_poc < tmp) { rps->delta_poc[k + 1] = tmp; rps->used[k + 1] = rps->used[k]; rps->delta_poc[k] = delta_poc; rps->used[k] = used; if ((rps->num_negative_pics >> 1) != 0) { int used; k = rps->num_negative_pics - 1; // flip the negative values to largest first for (i = 0; i < rps->num_negative_pics >> 1; i++) { delta_poc = rps->delta_poc[i]; used = rps->used[i]; rps->delta_poc[i] = rps->delta_poc[k]; rps->used[i] = rps->used[k]; rps->delta_poc[k] = delta_poc; rps->used[k] = used; k--; } else { unsigned int prev, nb_positive_pics; rps->num_negative_pics = get_ue_golomb_long(gb); nb_positive_pics = get_ue_golomb_long(gb); if (rps->num_negative_pics >= HEVC_MAX_REFS || nb_positive_pics >= HEVC_MAX_REFS) { av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n"); rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics; if (rps->num_delta_pocs) { prev = 0; for (i = 0; i < rps->num_negative_pics; i++) { delta_poc = get_ue_golomb_long(gb) + 1; prev -= delta_poc; rps->delta_poc[i] = prev; rps->used[i] = get_bits1(gb); prev = 0; for (i = 0; i < nb_positive_pics; i++) { delta_poc = get_ue_golomb_long(gb) + 1; prev += delta_poc; rps->delta_poc[rps->num_negative_pics + i] = prev; rps->used[rps->num_negative_pics + i] = get_bits1(gb); return 0;
true
FFmpeg
2b44dcbc44e99daf9515753e9fd4c2e1ea53a2fa
24,801
static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) { /* TODO: * - Magic packets should set bit 30 in power management driver register. * - Interesting packets should set bit 29 in power management driver register. */ EEPRO100State *s = vc->opaque; uint16_t rfd_status = 0xa000; static const uint8_t broadcast_macaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; /* TODO: check multiple IA bit. */ assert(!(s->configuration[20] & BIT(6))); if (s->configuration[8] & 0x80) { /* CSMA is disabled. */ logout("%p received while CSMA is disabled\n", s); return -1; } else if (size < 64 && (s->configuration[7] & 1)) { /* Short frame and configuration byte 7/0 (discard short receive) set: * Short frame is discarded */ logout("%p received short frame (%zu byte)\n", s, size); s->statistics.rx_short_frame_errors++; //~ return -1; } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) { /* Long frame and configuration byte 18/3 (long receive ok) not set: * Long frames are discarded. */ logout("%p received long frame (%zu byte), ignored\n", s, size); return -1; } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!! /* Frame matches individual address. */ /* TODO: check configuration byte 15/4 (ignore U/L). */ TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size)); } else if (memcmp(buf, broadcast_macaddr, 6) == 0) { /* Broadcast frame. */ TRACE(RXTX, logout("%p received broadcast, len=%zu\n", s, size)); rfd_status |= 0x0002; } else if (buf[0] & 0x01) { // !!! /* Multicast frame. */ TRACE(RXTX, logout("%p received multicast, len=%zu\n", s, size)); /* TODO: check multicast all bit. */ assert(!(s->configuration[21] & BIT(3))); int mcast_idx = compute_mcast_idx(buf); if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) { return size; } rfd_status |= 0x0002; } else if (s->configuration[15] & 1) { /* Promiscuous: receive all. */ TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size)); rfd_status |= 0x0004; } else { TRACE(RXTX, logout("%p received frame, ignored, len=%zu,%s\n", s, size, nic_dump(buf, size))); return size; } if (get_ru_state(s) != ru_ready) { /* No resources available. */ logout("no resources, state=%u\n", get_ru_state(s)); s->statistics.rx_resource_errors++; //~ assert(!"no resources"); return -1; } //~ !!! //~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}} eepro100_rx_t rx; cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx, offsetof(eepro100_rx_t, packet)); uint16_t rfd_command = le16_to_cpu(rx.command); uint16_t rfd_size = le16_to_cpu(rx.size); assert(size <= rfd_size); if (size < 64) { rfd_status |= 0x0080; } TRACE(OTHER, logout("command 0x%04x, link 0x%08x, addr 0x%08x, size %u\n", rfd_command, rx.link, rx.rx_buf_addr, rfd_size)); stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, status), rfd_status); stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size); /* Early receive interrupt not supported. */ //~ eepro100_er_interrupt(s); /* Receive CRC Transfer not supported. */ assert(!(s->configuration[18] & 4)); /* TODO: check stripping enable bit. */ //~ assert(!(s->configuration[17] & 1)); cpu_physical_memory_write(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, packet), buf, size); s->statistics.rx_good_frames++; eepro100_fr_interrupt(s); s->ru_offset = le32_to_cpu(rx.link); if (rfd_command & 0x8000) { /* EL bit is set, so this was the last frame. */ assert(0); } if (rfd_command & 0x4000) { /* S bit is set. */ set_ru_state(s, ru_suspended); } return size; }
true
qemu
7f1e9d4e138f5baf1e862a1221ba13eee7dcce9e
24,802
static BlockAIOCB *read_quorum_children(QuorumAIOCB *acb) { BDRVQuorumState *s = acb->common.bs->opaque; int i; for (i = 0; i < s->num_children; i++) { acb->qcrs[i].buf = qemu_blockalign(s->children[i]->bs, acb->qiov->size); qemu_iovec_init(&acb->qcrs[i].qiov, acb->qiov->niov); qemu_iovec_clone(&acb->qcrs[i].qiov, acb->qiov, acb->qcrs[i].buf); } for (i = 0; i < s->num_children; i++) { bdrv_aio_readv(s->children[i]->bs, acb->sector_num, &acb->qcrs[i].qiov, acb->nb_sectors, quorum_aio_cb, &acb->qcrs[i]); } return &acb->common; }
true
qemu
b9c600d20716b3d942cb07188ff998fb236a8365
24,803
static int flac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { FLACContext *s = avctx->priv_data; int metadata_last, metadata_type, metadata_size; int tmp = 0, i, j = 0, input_buf_size = 0; int16_t *samples = data; if(s->max_framesize == 0){ s->max_framesize= 8192; // should hopefully be enough for the first header s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); } if(1 && s->max_framesize){//FIXME truncated buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); input_buf_size= buf_size; if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ // printf("memmove\n"); memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); s->bitstream_index=0; } memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); buf= &s->bitstream[s->bitstream_index]; buf_size += s->bitstream_size; s->bitstream_size= buf_size; if(buf_size < s->max_framesize){ // printf("wanna more data ...\n"); return input_buf_size; } } init_get_bits(&s->gb, buf, buf_size*8); /* fLaC signature (be) */ if (show_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("fLaC"))) { skip_bits(&s->gb, 32); av_log(s->avctx, AV_LOG_DEBUG, "STREAM HEADER\n"); do { metadata_last = get_bits(&s->gb, 1); metadata_type = get_bits(&s->gb, 7); metadata_size = get_bits_long(&s->gb, 24); av_log(s->avctx, AV_LOG_DEBUG, " metadata block: flag = %d, type = %d, size = %d\n", metadata_last, metadata_type, metadata_size); if(metadata_size){ switch(metadata_type) { case METADATA_TYPE_STREAMINFO:{ int bits_count= get_bits_count(&s->gb); metadata_streaminfo(s); buf= &s->bitstream[s->bitstream_index]; init_get_bits(&s->gb, buf, buf_size*8); skip_bits(&s->gb, bits_count); dump_headers(s); break;} default: for(i=0; i<metadata_size; i++) skip_bits(&s->gb, 8); } } } while(!metadata_last); } else { tmp = show_bits(&s->gb, 16); if(tmp != 0xFFF8){ av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); while(get_bits_count(&s->gb)/8+2 < buf_size && show_bits(&s->gb, 16) != 0xFFF8) skip_bits(&s->gb, 8); goto end; // we may not have enough bits left to decode a frame, so try next time } skip_bits(&s->gb, 16); if (decode_frame(s) < 0){ av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); s->bitstream_size=0; s->bitstream_index=0; return -1; } } #if 0 /* fix the channel order here */ if (s->order == MID_SIDE) { short *left = samples; short *right = samples + s->blocksize; for (i = 0; i < s->blocksize; i += 2) { uint32_t x = s->decoded[0][i]; uint32_t y = s->decoded[0][i+1]; right[i] = x - (y / 2); left[i] = right[i] + y; } *data_size = 2 * s->blocksize; } else { for (i = 0; i < s->channels; i++) { switch(s->order) { case INDEPENDENT: for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[i][j]; break; case LEFT_SIDE: case RIGHT_SIDE: if (i == 0) for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[0][j]; else for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[0][j] - s->decoded[i][j]; break; // case MID_SIDE: // av_log(s->avctx, AV_LOG_DEBUG, "mid-side unsupported\n"); } *data_size += s->blocksize; } } #else switch(s->decorrelation) { case INDEPENDENT: for (j = 0; j < s->blocksize; j++) { for (i = 0; i < s->channels; i++) *(samples++) = s->decoded[i][j]; } break; case LEFT_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { *(samples++) = s->decoded[0][i]; *(samples++) = s->decoded[0][i] - s->decoded[1][i]; } break; case RIGHT_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { *(samples++) = s->decoded[0][i] + s->decoded[1][i]; *(samples++) = s->decoded[1][i]; } break; case MID_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { int mid, side; mid = s->decoded[0][i]; side = s->decoded[1][i]; #if 1 //needs to be checked but IMHO it should be binary identical mid -= side>>1; *(samples++) = mid + side; *(samples++) = mid; #else mid <<= 1; if (side & 1) mid++; *(samples++) = (mid + side) >> 1; *(samples++) = (mid - side) >> 1; #endif } break; } #endif *data_size = (int8_t *)samples - (int8_t *)data; // av_log(s->avctx, AV_LOG_DEBUG, "data size: %d\n", *data_size); // s->last_blocksize = s->blocksize; end: i= (get_bits_count(&s->gb)+7)/8;; if(i > buf_size){ av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); s->bitstream_size=0; s->bitstream_index=0; return -1; } if(s->bitstream_size){ s->bitstream_index += i; s->bitstream_size -= i; return input_buf_size; }else return i; }
true
FFmpeg
09f20d37867baaa0122ffdd75f0481b2b3a08079
24,804
static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, mfxExtBuffer **coding_opts) { mfxInfoMFX *info = &q->param.mfx; mfxExtCodingOption *co = (mfxExtCodingOption*)coding_opts[0]; #if QSV_HAVE_CO2 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1]; #endif #if QSV_HAVE_CO3 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2]; #endif av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n", print_profile(info->CodecProfile), info->CodecLevel); av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: %"PRIu16"; GopOptFlag: ", info->GopPicSize, info->GopRefDist); if (info->GopOptFlag & MFX_GOP_CLOSED) av_log(avctx, AV_LOG_VERBOSE, "closed "); if (info->GopOptFlag & MFX_GOP_STRICT) av_log(avctx, AV_LOG_VERBOSE, "strict "); av_log(avctx, AV_LOG_VERBOSE, "; IdrInterval: %"PRIu16"\n", info->IdrInterval); av_log(avctx, AV_LOG_VERBOSE, "TargetUsage: %"PRIu16"; RateControlMethod: %s\n", info->TargetUsage, print_ratecontrol(info->RateControlMethod)); if (info->RateControlMethod == MFX_RATECONTROL_CBR || info->RateControlMethod == MFX_RATECONTROL_VBR #if QSV_HAVE_VCM || info->RateControlMethod == MFX_RATECONTROL_VCM #endif ) { av_log(avctx, AV_LOG_VERBOSE, "InitialDelayInKB: %"PRIu16"; TargetKbps: %"PRIu16"; MaxKbps: %"PRIu16"\n", info->InitialDelayInKB, info->TargetKbps, info->MaxKbps); } else if (info->RateControlMethod == MFX_RATECONTROL_CQP) { av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16"; QPB: %"PRIu16"\n", info->QPI, info->QPP, info->QPB); } else if (info->RateControlMethod == MFX_RATECONTROL_AVBR) { av_log(avctx, AV_LOG_VERBOSE, "TargetKbps: %"PRIu16"; Accuracy: %"PRIu16"; Convergence: %"PRIu16"\n", info->TargetKbps, info->Accuracy, info->Convergence); } #if QSV_HAVE_LA else if (info->RateControlMethod == MFX_RATECONTROL_LA #if QSV_HAVE_LA_HRD || info->RateControlMethod == MFX_RATECONTROL_LA_HRD #endif ) { av_log(avctx, AV_LOG_VERBOSE, "TargetKbps: %"PRIu16"; LookAheadDepth: %"PRIu16"\n", info->TargetKbps, co2->LookAheadDepth); } #endif #if QSV_HAVE_ICQ else if (info->RateControlMethod == MFX_RATECONTROL_ICQ) { av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"\n", info->ICQQuality); } else if (info->RateControlMethod == MFX_RATECONTROL_LA_ICQ) { av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"; LookAheadDepth: %"PRIu16"\n", info->ICQQuality, co2->LookAheadDepth); } #endif #if QSV_HAVE_QVBR else if (info->RateControlMethod == MFX_RATECONTROL_QVBR) { av_log(avctx, AV_LOG_VERBOSE, "QVBRQuality: %"PRIu16"\n", co3->QVBRQuality); } #endif av_log(avctx, AV_LOG_VERBOSE, "NumSlice: %"PRIu16"; NumRefFrame: %"PRIu16"\n", info->NumSlice, info->NumRefFrame); av_log(avctx, AV_LOG_VERBOSE, "RateDistortionOpt: %s\n", print_threestate(co->RateDistortionOpt)); #if QSV_HAVE_CO2 av_log(avctx, AV_LOG_VERBOSE, "RecoveryPointSEI: %s IntRefType: %"PRIu16"; IntRefCycleSize: %"PRIu16"; IntRefQPDelta: %"PRId16"\n", print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta); av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %"PRIu16"; ", co2->MaxFrameSize); #if QSV_VERSION_ATLEAST(1, 9) av_log(avctx, AV_LOG_VERBOSE, "MaxSliceSize: %"PRIu16"; ", co2->MaxSliceSize); #endif av_log(avctx, AV_LOG_VERBOSE, "\n"); av_log(avctx, AV_LOG_VERBOSE, "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n", print_threestate(co2->BitrateLimit), print_threestate(co2->MBBRC), print_threestate(co2->ExtBRC)); #if QSV_HAVE_TRELLIS av_log(avctx, AV_LOG_VERBOSE, "Trellis: "); if (co2->Trellis & MFX_TRELLIS_OFF) { av_log(avctx, AV_LOG_VERBOSE, "off"); } else if (!co2->Trellis) { av_log(avctx, AV_LOG_VERBOSE, "auto"); } else { if (co2->Trellis & MFX_TRELLIS_I) av_log(avctx, AV_LOG_VERBOSE, "I"); if (co2->Trellis & MFX_TRELLIS_P) av_log(avctx, AV_LOG_VERBOSE, "P"); if (co2->Trellis & MFX_TRELLIS_B) av_log(avctx, AV_LOG_VERBOSE, "B"); } av_log(avctx, AV_LOG_VERBOSE, "\n"); #endif #if QSV_VERSION_ATLEAST(1, 8) av_log(avctx, AV_LOG_VERBOSE, "RepeatPPS: %s; NumMbPerSlice: %"PRIu16"; LookAheadDS: ", print_threestate(co2->RepeatPPS), co2->NumMbPerSlice); switch (co2->LookAheadDS) { case MFX_LOOKAHEAD_DS_OFF: av_log(avctx, AV_LOG_VERBOSE, "off"); break; case MFX_LOOKAHEAD_DS_2x: av_log(avctx, AV_LOG_VERBOSE, "2x"); break; case MFX_LOOKAHEAD_DS_4x: av_log(avctx, AV_LOG_VERBOSE, "4x"); break; default: av_log(avctx, AV_LOG_VERBOSE, "unknown"); break; } av_log(avctx, AV_LOG_VERBOSE, "\n"); av_log(avctx, AV_LOG_VERBOSE, "AdaptiveI: %s; AdaptiveB: %s; BRefType: ", print_threestate(co2->AdaptiveI), print_threestate(co2->AdaptiveB)); switch (co2->BRefType) { case MFX_B_REF_OFF: av_log(avctx, AV_LOG_VERBOSE, "off"); break; case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break; default: av_log(avctx, AV_LOG_VERBOSE, "auto"); break; } av_log(avctx, AV_LOG_VERBOSE, "\n"); #endif #if QSV_VERSION_ATLEAST(1, 9) av_log(avctx, AV_LOG_VERBOSE, "MinQPI: %"PRIu8"; MaxQPI: %"PRIu8"; MinQPP: %"PRIu8"; MaxQPP: %"PRIu8"; MinQPB: %"PRIu8"; MaxQPB: %"PRIu8"\n", co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB); #endif #endif if (avctx->codec_id == AV_CODEC_ID_H264) { av_log(avctx, AV_LOG_VERBOSE, "Entropy coding: %s; MaxDecFrameBuffering: %"PRIu16"\n", co->CAVLC == MFX_CODINGOPTION_ON ? "CAVLC" : "CABAC", co->MaxDecFrameBuffering); av_log(avctx, AV_LOG_VERBOSE, "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n", print_threestate(co->NalHrdConformance), print_threestate(co->SingleSeiNalUnit), print_threestate(co->VuiVclHrdParameters), print_threestate(co->VuiNalHrdParameters)); } }
false
FFmpeg
fc4c27c4edfc6a5f9bc7c696e823652474a65ce8
24,805
static void *alloc_buffer(FFVAContext *vactx, int type, unsigned int size, uint32_t *buf_id) { void *data = NULL; *buf_id = 0; if (vaCreateBuffer(vactx->display, vactx->context_id, type, size, 1, NULL, buf_id) == VA_STATUS_SUCCESS) vaMapBuffer(vactx->display, *buf_id, &data); return data; }
false
FFmpeg
8813d55fa5978660d9f4e7dbe1f50da9922be08d
24,807
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value) { if (!strcmp(key, "WWW-Authenticate") || !strcmp(key, "Proxy-Authenticate")) { const char *p; if (av_stristart(value, "Basic ", &p) && state->auth_type <= HTTP_AUTH_BASIC) { state->auth_type = HTTP_AUTH_BASIC; state->realm[0] = 0; state->stale = 0; ff_parse_key_value(p, (ff_parse_key_val_cb) handle_basic_params, state); } else if (av_stristart(value, "Digest ", &p) && state->auth_type <= HTTP_AUTH_DIGEST) { state->auth_type = HTTP_AUTH_DIGEST; memset(&state->digest_params, 0, sizeof(DigestParams)); state->realm[0] = 0; state->stale = 0; ff_parse_key_value(p, (ff_parse_key_val_cb) handle_digest_params, state); choose_qop(state->digest_params.qop, sizeof(state->digest_params.qop)); if (!av_strcasecmp(state->digest_params.stale, "true")) state->stale = 1; } } else if (!strcmp(key, "Authentication-Info")) { ff_parse_key_value(value, (ff_parse_key_val_cb) handle_digest_update, state); } }
false
FFmpeg
8f0bd1d9bad5b8aa42b5b4cec103cc4afed5eab6
24,808
void ff_thread_report_progress(ThreadFrame *f, int n, int field) { PerThreadContext *p; atomic_int *progress = f->progress ? (atomic_int*)f->progress->data : NULL; if (!progress || atomic_load_explicit(&progress[field], memory_order_acquire) >= n) return; p = f->owner->internal->thread_ctx; if (f->owner->debug&FF_DEBUG_THREADS) av_log(f->owner, AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); pthread_mutex_lock(&p->progress_mutex); atomic_store(&progress[field], n); pthread_cond_broadcast(&p->progress_cond); pthread_mutex_unlock(&p->progress_mutex); }
false
FFmpeg
343e2833994655c252d5236a3394bf6db7a4d8b1
24,809
static void mxf_write_system_item(AVFormatContext *s) { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; unsigned frame; uint32_t time_code; frame = mxf->last_indexed_edit_unit + mxf->edit_units_count; // write system metadata pack avio_write(pb, system_metadata_pack_key, 16); klv_encode_ber4_length(pb, 57); avio_w8(pb, 0x5c); // UL, user date/time stamp, picture and sound item present avio_w8(pb, 0x04); // content package rate avio_w8(pb, 0x00); // content package type avio_wb16(pb, 0x00); // channel handle avio_wb16(pb, mxf->tc.start + frame); // continuity count if (mxf->essence_container_count > 1) avio_write(pb, multiple_desc_ul, 16); else { MXFStreamContext *sc = s->streams[0]->priv_data; avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16); } avio_w8(pb, 0); avio_wb64(pb, 0); avio_wb64(pb, 0); // creation date/time stamp avio_w8(pb, 0x81); // SMPTE 12M time code time_code = av_timecode_get_smpte_from_framenum(&mxf->tc, frame); avio_wb32(pb, time_code); avio_wb32(pb, 0); // binary group data avio_wb64(pb, 0); // write system metadata package set avio_write(pb, system_metadata_package_set_key, 16); klv_encode_ber4_length(pb, 35); avio_w8(pb, 0x83); // UMID avio_wb16(pb, 0x20); mxf_write_umid(s, 1); }
true
FFmpeg
3896cd11a107f241f06b06a336322aef2f372fdd
24,810
petalogix_ml605_init(MachineState *machine) { ram_addr_t ram_size = machine->ram_size; MemoryRegion *address_space_mem = get_system_memory(); DeviceState *dev, *dma, *eth0; Object *ds, *cs; MicroBlazeCPU *cpu; SysBusDevice *busdev; DriveInfo *dinfo; int i; MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1); MemoryRegion *phys_ram = g_new(MemoryRegion, 1); qemu_irq irq[32]; /* init CPUs */ cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU)); /* Use FPU but don't use floating point conversion and square * root instructions */ object_property_set_int(OBJECT(cpu), 1, "use-fpu", &error_abort); object_property_set_bool(OBJECT(cpu), true, "dcache-writeback", &error_abort); object_property_set_bool(OBJECT(cpu), true, "endianness", &error_abort); object_property_set_bool(OBJECT(cpu), true, "realized", &error_abort); /* Attach emulated BRAM through the LMB. */ memory_region_init_ram(phys_lmb_bram, NULL, "petalogix_ml605.lmb_bram", LMB_BRAM_SIZE, &error_abort); vmstate_register_ram_global(phys_lmb_bram); memory_region_add_subregion(address_space_mem, 0x00000000, phys_lmb_bram); memory_region_init_ram(phys_ram, NULL, "petalogix_ml605.ram", ram_size, &error_abort); vmstate_register_ram_global(phys_ram); memory_region_add_subregion(address_space_mem, MEMORY_BASEADDR, phys_ram); dinfo = drive_get(IF_PFLASH, 0, 0); /* 5th parameter 2 means bank-width * 10th paremeter 0 means little-endian */ pflash_cfi01_register(FLASH_BASEADDR, NULL, "petalogix_ml605.flash", FLASH_SIZE, dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, (64 * 1024), FLASH_SIZE >> 16, 2, 0x89, 0x18, 0x0000, 0x0, 0); dev = qdev_create(NULL, "xlnx.xps-intc"); qdev_prop_set_uint32(dev, "kind-of-intr", 1 << TIMER_IRQ); qdev_init_nofail(dev); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, INTC_BASEADDR); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(DEVICE(cpu), MB_CPU_IRQ)); for (i = 0; i < 32; i++) { irq[i] = qdev_get_gpio_in(dev, i); } serial_mm_init(address_space_mem, UART16550_BASEADDR + 0x1000, 2, irq[UART16550_IRQ], 115200, serial_hds[0], DEVICE_LITTLE_ENDIAN); /* 2 timers at irq 2 @ 100 Mhz. */ dev = qdev_create(NULL, "xlnx.xps-timer"); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 100 * 1000000); qdev_init_nofail(dev); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, TIMER_BASEADDR); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]); /* axi ethernet and dma initialization. */ qemu_check_nic_model(&nd_table[0], "xlnx.axi-ethernet"); eth0 = qdev_create(NULL, "xlnx.axi-ethernet"); dma = qdev_create(NULL, "xlnx.axi-dma"); /* FIXME: attach to the sysbus instead */ object_property_add_child(qdev_get_machine(), "xilinx-eth", OBJECT(eth0), NULL); object_property_add_child(qdev_get_machine(), "xilinx-dma", OBJECT(dma), NULL); ds = object_property_get_link(OBJECT(dma), "axistream-connected-target", NULL); cs = object_property_get_link(OBJECT(dma), "axistream-control-connected-target", NULL); qdev_set_nic_properties(eth0, &nd_table[0]); qdev_prop_set_uint32(eth0, "rxmem", 0x1000); qdev_prop_set_uint32(eth0, "txmem", 0x1000); object_property_set_link(OBJECT(eth0), OBJECT(ds), "axistream-connected", &error_abort); object_property_set_link(OBJECT(eth0), OBJECT(cs), "axistream-control-connected", &error_abort); qdev_init_nofail(eth0); sysbus_mmio_map(SYS_BUS_DEVICE(eth0), 0, AXIENET_BASEADDR); sysbus_connect_irq(SYS_BUS_DEVICE(eth0), 0, irq[AXIENET_IRQ]); ds = object_property_get_link(OBJECT(eth0), "axistream-connected-target", NULL); cs = object_property_get_link(OBJECT(eth0), "axistream-control-connected-target", NULL); qdev_prop_set_uint32(dma, "freqhz", 100 * 1000000); object_property_set_link(OBJECT(dma), OBJECT(ds), "axistream-connected", &error_abort); object_property_set_link(OBJECT(dma), OBJECT(cs), "axistream-control-connected", &error_abort); qdev_init_nofail(dma); sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, AXIDMA_BASEADDR); sysbus_connect_irq(SYS_BUS_DEVICE(dma), 0, irq[AXIDMA_IRQ0]); sysbus_connect_irq(SYS_BUS_DEVICE(dma), 1, irq[AXIDMA_IRQ1]); { SSIBus *spi; dev = qdev_create(NULL, "xlnx.xps-spi"); qdev_prop_set_uint8(dev, "num-ss-bits", NUM_SPI_FLASHES); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); sysbus_mmio_map(busdev, 0, SPI_BASEADDR); sysbus_connect_irq(busdev, 0, irq[SPI_IRQ]); spi = (SSIBus *)qdev_get_child_bus(dev, "spi"); for (i = 0; i < NUM_SPI_FLASHES; i++) { qemu_irq cs_line; dev = ssi_create_slave(spi, "n25q128"); cs_line = qdev_get_gpio_in_named(dev, SSI_GPIO_CS, 0); sysbus_connect_irq(busdev, i+1, cs_line); } } /* setup PVR to match kernel settings */ cpu->env.pvr.regs[4] = 0xc56b8000; cpu->env.pvr.regs[5] = 0xc56be000; cpu->env.pvr.regs[10] = 0x0e000000; /* virtex 6 */ microblaze_load_kernel(cpu, MEMORY_BASEADDR, ram_size, machine->initrd_filename, BINARY_DEVICE_TREE_FILE, NULL); }
true
qemu
f8ed85ac992c48814d916d5df4d44f9a971c5de4
24,811
static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep) { FILE *fp = NULL; int fop_ret; int file_size; int file_type = -1; unsigned char buf[2] = {0, 0}; unsigned int filehead_value = 0; int bmp_bpp; fp = fopen(filename, "rb"); if (fp == NULL) { error_report("failed to open file '%s'.", filename); /* check file size */ fseek(fp, 0L, SEEK_END); file_size = ftell(fp); if (file_size < 2) { error_report("file size is less than 2 bytes '%s'.", filename); /* check magic ID */ fseek(fp, 0L, SEEK_SET); fop_ret = fread(buf, 1, 2, fp); filehead_value = (buf[0] + (buf[1] << 8)) & 0xffff; if (filehead_value == 0xd8ff) { file_type = JPG_FILE; } else { if (filehead_value == 0x4d42) { file_type = BMP_FILE; if (file_type < 0) { error_report("'%s' not jpg/bmp file,head:0x%x.", filename, filehead_value); /* check BMP bpp */ if (file_type == BMP_FILE) { fseek(fp, 28, SEEK_SET); fop_ret = fread(buf, 1, 2, fp); bmp_bpp = (buf[0] + (buf[1] << 8)) & 0xffff; if (bmp_bpp != 24) { error_report("only 24bpp bmp file is supported."); /* return values */ *file_sizep = file_size; *file_typep = file_type;
true
qemu
257a7375582e4c3b32687c72d0f52279d28b2d85
24,812
vmxnet3_read_next_rx_descr(VMXNET3State *s, int qidx, int ridx, struct Vmxnet3_RxDesc *dbuf, uint32_t *didx) { Vmxnet3Ring *ring = &s->rxq_descr[qidx].rx_ring[ridx]; *didx = vmxnet3_ring_curr_cell_idx(ring); vmxnet3_ring_read_curr_cell(ring, dbuf); }
true
qemu
c508277335e3b6b20cf18e6ea3a35c1fa835c64a
24,814
static av_cold int aac_encode_end(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; ff_mdct_end(&s->mdct1024); ff_mdct_end(&s->mdct128); ff_psy_end(&s->psy); ff_psy_preprocess_end(s->psypp); av_freep(&s->samples); av_freep(&s->cpe); return 0; }
true
FFmpeg
17ae608127324cabd083202a32a8dc210d30c3a1
24,816
static int rice_count_exact(int32_t *res, int n, int k) { int i; int count = 0; for (i = 0; i < n; i++) { int32_t v = -2 * res[i] - 1; v ^= v >> 31; count += (v >> k) + 1 + k; } return count; }
true
FFmpeg
5ff998a233d759d0de83ea6f95c383d03d25d88e
24,817
static uint64_t boston_lcd_read(void *opaque, hwaddr addr, unsigned size) { BostonState *s = opaque; uint64_t val = 0; switch (size) { case 8: val |= (uint64_t)s->lcd_content[(addr + 7) & 0x7] << 56; val |= (uint64_t)s->lcd_content[(addr + 6) & 0x7] << 48; val |= (uint64_t)s->lcd_content[(addr + 5) & 0x7] << 40; val |= (uint64_t)s->lcd_content[(addr + 4) & 0x7] << 32; /* fall through */ case 4: val |= (uint64_t)s->lcd_content[(addr + 3) & 0x7] << 24; val |= (uint64_t)s->lcd_content[(addr + 2) & 0x7] << 16; /* fall through */ case 2: val |= (uint64_t)s->lcd_content[(addr + 1) & 0x7] << 8; /* fall through */ case 1: val |= (uint64_t)s->lcd_content[(addr + 0) & 0x7]; break; } return val; }
true
qemu
2d896b454a0e19ec4c1ddbb0e0b65b7e54fcedf3
24,819
static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){ #if CONFIG_SMALL #define ROT(x,s) ((x<<s)|(x>>(32-s))) return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24); #else return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d]; #endif }
true
FFmpeg
5d20f19be25c973fe10d0d17db9245002585710d
24,820
void ff_generate_sliding_window_mmcos(H264Context *h) { MpegEncContext * const s = &h->s; assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); h->mmco_index= 0; if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count && !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->f.reference)) { h->mmco[0].opcode= MMCO_SHORT2UNUSED; h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; h->mmco_index= 1; if (FIELD_PICTURE) { h->mmco[0].short_pic_num *= 2; h->mmco[1].opcode= MMCO_SHORT2UNUSED; h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1; h->mmco_index= 2; } } }
true
FFmpeg
bad446e251405dc250c3cbee199072e083a1e4b9
24,821
static unsigned long copy_elf_strings(int argc,char ** argv, void **page, unsigned long p) { char *tmp, *tmp1, *pag = NULL; int len, offset = 0; if (!p) { return 0; /* bullet-proofing */ } while (argc-- > 0) { tmp = argv[argc]; if (!tmp) { fprintf(stderr, "VFS: argc is wrong"); exit(-1); } tmp1 = tmp; while (*tmp++); len = tmp - tmp1; if (p < len) { /* this shouldn't happen - 128kB */ return 0; } while (len) { --p; --tmp; --len; if (--offset < 0) { offset = p % TARGET_PAGE_SIZE; pag = (char *)page[p/TARGET_PAGE_SIZE]; if (!pag) { pag = (char *)malloc(TARGET_PAGE_SIZE); page[p/TARGET_PAGE_SIZE] = pag; if (!pag) return 0; } } if (len == 0 || offset == 0) { *(pag + offset) = *tmp; } else { int bytes_to_copy = (len > offset) ? offset : len; tmp -= bytes_to_copy; p -= bytes_to_copy; offset -= bytes_to_copy; len -= bytes_to_copy; memcpy_fromfs(pag + offset, tmp, bytes_to_copy + 1); } } } return p; }
true
qemu
4118a97030aa9bd1d520d1d06bbe0655d829df04
24,822
void fork_end(int child) { mmap_fork_end(child); if (child) { CPUState *cpu, *next_cpu; /* Child processes created by fork() only have a single thread. Discard information about the parent threads. */ CPU_FOREACH_SAFE(cpu, next_cpu) { if (cpu != thread_cpu) { QTAILQ_REMOVE(&cpus, cpu, node); } } qemu_mutex_init(&tb_ctx.tb_lock); qemu_init_cpu_list(); gdbserver_fork(thread_cpu); } else { qemu_mutex_unlock(&tb_ctx.tb_lock); cpu_list_unlock(); } }
true
qemu
06065c451f10c7ef62cfb575a87f323a70ae1c9e
24,823
static int mpc8_probe(AVProbeData *p) { const uint8_t *bs = p->buf + 4; const uint8_t *bs_end = bs + p->buf_size; int64_t size; if (p->buf_size < 16) return 0; if (AV_RL32(p->buf) != TAG_MPCK) return 0; while (bs < bs_end + 3) { int header_found = (bs[0] == 'S' && bs[1] == 'H'); if (bs[0] < 'A' || bs[0] > 'Z' || bs[1] < 'A' || bs[1] > 'Z') return 0; bs += 2; size = bs_get_v(&bs); if (size < 2) return 0; if (bs + size - 2 >= bs_end) return AVPROBE_SCORE_EXTENSION - 1; // seems to be valid MPC but no header yet if (header_found) { if (size < 11 || size > 28) return 0; if (!AV_RL32(bs)) //zero CRC is invalid return 0; return AVPROBE_SCORE_MAX; } else { bs += size - 2; } } return 0; }
true
FFmpeg
b737a2c52857b214be246ff615c6293730033cfa
24,825
static TranslationBlock *tb_find_slow(target_ulong pc, target_ulong cs_base, uint64_t flags) { TranslationBlock *tb, **ptb1; int code_gen_size; unsigned int h; target_ulong phys_pc, phys_page1, phys_page2, virt_page2; uint8_t *tc_ptr; spin_lock(&tb_lock); tb_invalidated_flag = 0; regs_to_env(); /* XXX: do it just before cpu_gen_code() */ /* find translated block using physical mappings */ phys_pc = get_phys_addr_code(env, pc); phys_page1 = phys_pc & TARGET_PAGE_MASK; phys_page2 = -1; h = tb_phys_hash_func(phys_pc); ptb1 = &tb_phys_hash[h]; for(;;) { tb = *ptb1; if (!tb) goto not_found; if (tb->pc == pc && tb->page_addr[0] == phys_page1 && tb->cs_base == cs_base && tb->flags == flags) { /* check next page if needed */ if (tb->page_addr[1] != -1) { virt_page2 = (pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; phys_page2 = get_phys_addr_code(env, virt_page2); if (tb->page_addr[1] == phys_page2) goto found; } else { goto found; } } ptb1 = &tb->phys_hash_next; } not_found: /* if no translated code available, then translate it now */ tb = tb_alloc(pc); if (!tb) { /* flush must be done */ tb_flush(env); /* cannot fail at this point */ tb = tb_alloc(pc); /* don't forget to invalidate previous TB info */ tb_invalidated_flag = 1; } tc_ptr = code_gen_ptr; tb->tc_ptr = tc_ptr; tb->cs_base = cs_base; tb->flags = flags; cpu_gen_code(env, tb, CODE_GEN_MAX_SIZE, &code_gen_size); code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1)); /* check next page if needed */ virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; phys_page2 = -1; if ((pc & TARGET_PAGE_MASK) != virt_page2) { phys_page2 = get_phys_addr_code(env, virt_page2); } tb_link_phys(tb, phys_pc, phys_page2); found: /* we add the TB in the virtual pc hash table */ env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)] = tb; spin_unlock(&tb_lock); return tb; }
true
qemu
d07bde88a52bf293c3f8846cfd162e0a57e1557c
24,826
static int decode_block(MJpegDecodeContext *s, DCTELEM *block, int component, int dc_index, int ac_index, int16_t *quant_matrix) { int code, i, j, level, val; VLC *ac_vlc; /* DC coef */ val = mjpeg_decode_dc(s, dc_index); if (val == 0xffff) { dprintf("error dc\n"); return -1; } val = val * quant_matrix[0] + s->last_dc[component]; s->last_dc[component] = val; block[0] = val; /* AC coefs */ ac_vlc = &s->vlcs[1][ac_index]; i = 0; {OPEN_READER(re, &s->gb) for(;;) { UPDATE_CACHE(re, &s->gb); GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) /* EOB */ if (code == 0x10) break; if (code == 0x100) { i += 16; } else { i += ((unsigned)code) >> 4; code &= 0xf; if(code > MIN_CACHE_BITS - 16){ UPDATE_CACHE(re, &s->gb) } { int cache=GET_CACHE(re,gb); int sign=(~cache)>>31; level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; } LAST_SKIP_BITS(re, &s->gb, code) if (i >= 63) { if(i == 63){ j = s->scantable.permutated[63]; block[j] = level * quant_matrix[j]; break; } dprintf("error count: %d\n", i); return -1; } j = s->scantable.permutated[i]; block[j] = level * quant_matrix[j]; } } CLOSE_READER(re, &s->gb)} return 0; }
false
FFmpeg
002a7414b5852418f9a66245fc414c0416c4b4c1
24,828
static int gif_read_image(GifState *s, AVFrame *frame) { int left, top, width, height, bits_per_pixel, code_size, flags; int is_interleaved, has_local_palette, y, pass, y1, linesize, n, i; uint8_t *ptr, *spal, *palette, *ptr1; left = bytestream_get_le16(&s->bytestream); top = bytestream_get_le16(&s->bytestream); width = bytestream_get_le16(&s->bytestream); height = bytestream_get_le16(&s->bytestream); flags = bytestream_get_byte(&s->bytestream); is_interleaved = flags & 0x40; has_local_palette = flags & 0x80; bits_per_pixel = (flags & 0x07) + 1; av_dlog(s->avctx, "gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height); if (has_local_palette) { bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel)); palette = s->local_palette; } else { palette = s->global_palette; bits_per_pixel = s->bits_per_pixel; } /* verify that all the image is inside the screen dimensions */ if (left + width > s->screen_width || top + height > s->screen_height) return AVERROR(EINVAL); /* build the palette */ n = (1 << bits_per_pixel); spal = palette; for(i = 0; i < n; i++) { s->image_palette[i] = (0xffu << 24) | AV_RB24(spal); spal += 3; } for(; i < 256; i++) s->image_palette[i] = (0xffu << 24); /* handle transparency */ if (s->transparent_color_index >= 0) s->image_palette[s->transparent_color_index] = 0; /* now get the image data */ code_size = bytestream_get_byte(&s->bytestream); ff_lzw_decode_init(s->lzw, code_size, s->bytestream, s->bytestream_end - s->bytestream, FF_LZW_GIF); /* read all the image */ linesize = frame->linesize[0]; ptr1 = frame->data[0] + top * linesize + left; ptr = ptr1; pass = 0; y1 = 0; for (y = 0; y < height; y++) { ff_lzw_decode(s->lzw, ptr, width); if (is_interleaved) { switch(pass) { default: case 0: case 1: y1 += 8; ptr += linesize * 8; if (y1 >= height) { y1 = pass ? 2 : 4; ptr = ptr1 + linesize * y1; pass++; } break; case 2: y1 += 4; ptr += linesize * 4; if (y1 >= height) { y1 = 1; ptr = ptr1 + linesize; pass++; } break; case 3: y1 += 2; ptr += linesize * 2; break; } } else { ptr += linesize; } } /* read the garbage data until end marker is found */ ff_lzw_decode_tail(s->lzw); s->bytestream = ff_lzw_cur_ptr(s->lzw); return 0; }
false
FFmpeg
c453723ad7d14abc5e82677eebaa6025fa598f08
24,831
static int oss_poll_in (HWVoiceIn *hw) { OSSVoiceIn *oss = (OSSVoiceIn *) hw; return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL); }
true
qemu
b027a538c6790bcfc93ef7f4819fe3e581445959
24,832
static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr) { struct sbg_fade f; if (lex_char(p, '<')) f.in = SBG_FADE_SILENCE; else if (lex_char(p, '-')) f.in = SBG_FADE_SAME; else if (lex_char(p, '=')) f.in = SBG_FADE_ADAPT; else return 0; if (lex_char(p, '>')) f.out = SBG_FADE_SILENCE; else if (lex_char(p, '-')) f.out = SBG_FADE_SAME; else if (lex_char(p, '=')) f.out = SBG_FADE_ADAPT; else return AVERROR_INVALIDDATA; *fr = f; return 1; }
true
FFmpeg
e9b8523d52ca84d5012168db24fec2d50e73cf22
24,833
void qdev_prop_register_global(GlobalProperty *prop) { QTAILQ_INSERT_TAIL(&global_props, prop, next); }
true
qemu
f9a8b5530d438f836f9697639814f585aaec554d
24,834
int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header) { HEVCLocalContext *lc = s->HEVClc; uint8_t rps_predict = 0; int delta_poc; int k0 = 0; int k1 = 0; int k = 0; int i; GetBitContext *gb = &lc->gb; if (rps != sps->st_rps && sps->nb_st_rps) rps_predict = get_bits1(gb); if (rps_predict) { const ShortTermRPS *rps_ridx; int delta_rps, abs_delta_rps; uint8_t use_delta_flag = 0; uint8_t delta_rps_sign; if (is_slice_header) { unsigned int delta_idx = get_ue_golomb_long(gb) + 1; if (delta_idx > sps->nb_st_rps) { av_log(s->avctx, AV_LOG_ERROR, "Invalid value of delta_idx in slice header RPS: %d > %d.\n", delta_idx, sps->nb_st_rps); return AVERROR_INVALIDDATA; } rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx]; } else rps_ridx = &sps->st_rps[rps - sps->st_rps - 1]; delta_rps_sign = get_bits1(gb); abs_delta_rps = get_ue_golomb_long(gb) + 1; delta_rps = (1 - (delta_rps_sign << 1)) * abs_delta_rps; for (i = 0; i <= rps_ridx->num_delta_pocs; i++) { int used = rps->used[k] = get_bits1(gb); if (!used) use_delta_flag = get_bits1(gb); if (used || use_delta_flag) { if (i < rps_ridx->num_delta_pocs) delta_poc = delta_rps + rps_ridx->delta_poc[i]; else delta_poc = delta_rps; rps->delta_poc[k] = delta_poc; if (delta_poc < 0) k0++; else k1++; k++; } } rps->num_delta_pocs = k; rps->num_negative_pics = k0; // sort in increasing order (smallest first) if (rps->num_delta_pocs != 0) { int used, tmp; for (i = 1; i < rps->num_delta_pocs; i++) { delta_poc = rps->delta_poc[i]; used = rps->used[i]; for (k = i - 1; k >= 0; k--) { tmp = rps->delta_poc[k]; if (delta_poc < tmp) { rps->delta_poc[k + 1] = tmp; rps->used[k + 1] = rps->used[k]; rps->delta_poc[k] = delta_poc; rps->used[k] = used; } } } } if ((rps->num_negative_pics >> 1) != 0) { int used; k = rps->num_negative_pics - 1; // flip the negative values to largest first for (i = 0; i < rps->num_negative_pics >> 1; i++) { delta_poc = rps->delta_poc[i]; used = rps->used[i]; rps->delta_poc[i] = rps->delta_poc[k]; rps->used[i] = rps->used[k]; rps->delta_poc[k] = delta_poc; rps->used[k] = used; k--; } } } else { unsigned int prev, nb_positive_pics; rps->num_negative_pics = get_ue_golomb_long(gb); nb_positive_pics = get_ue_golomb_long(gb); if (rps->num_negative_pics >= MAX_REFS || nb_positive_pics >= MAX_REFS) { av_log(s->avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n"); return AVERROR_INVALIDDATA; } rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics; if (rps->num_delta_pocs) { prev = 0; for (i = 0; i < rps->num_negative_pics; i++) { delta_poc = get_ue_golomb_long(gb) + 1; prev -= delta_poc; rps->delta_poc[i] = prev; rps->used[i] = get_bits1(gb); } prev = 0; for (i = 0; i < nb_positive_pics; i++) { delta_poc = get_ue_golomb_long(gb) + 1; prev += delta_poc; rps->delta_poc[rps->num_negative_pics + i] = prev; rps->used[rps->num_negative_pics + i] = get_bits1(gb); } } } return 0; }
true
FFmpeg
d13a731fc149d3fdbe679078479ec1950674e762
24,835
iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque) { IscsiLun *iscsilun = bs->opaque; IscsiAIOCB *acb; acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque); trace_iscsi_aio_readv(iscsilun->iscsi, sector_num, nb_sectors, opaque, acb); acb->nb_sectors = nb_sectors; acb->sector_num = sector_num; acb->iscsilun = iscsilun; acb->qiov = qiov; acb->retries = ISCSI_CMD_RETRIES; if (iscsi_aio_readv_acb(acb) != 0) { qemu_aio_release(acb); iscsi_set_events(iscsilun); return &acb->common;
true
qemu
91bea4e2bb1a5f7954a3b3a4f2e28e96bd25c458
24,836
static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, QemuConsole *con, int idx, GSList *group, GtkWidget *view_menu) { Error *local_err = NULL; Object *obj; obj = object_property_get_link(OBJECT(con), "device", &local_err); if (obj) { vc->label = g_strdup_printf("%s", object_get_typename(obj)); } else { vc->label = g_strdup_printf("VGA"); } vc->s = s; vc->gfx.scale_x = 1.0; vc->gfx.scale_y = 1.0; vc->gfx.drawing_area = gtk_drawing_area_new(); gtk_widget_add_events(vc->gfx.drawing_area, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(vc->gfx.drawing_area, TRUE); vc->type = GD_VC_GFX; vc->tab_item = vc->gfx.drawing_area; gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->tab_item, gtk_label_new(vc->label)); gd_connect_vc_gfx_signals(vc); group = gd_vc_menu_init(s, vc, idx, group, view_menu); vc->gfx.dcl.ops = &dcl_ops; vc->gfx.dcl.con = con; register_displaychangelistener(&vc->gfx.dcl); return group; }
true
qemu
8a0f9b5263bb3a96d574ca78ad3b8f1d7bf8b12b
24,837
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options) { int port; const char *p; char buf[200], opts[50] = ""; struct addrinfo hints = { 0 }, *ai = NULL; const char *proxy_path; int use_proxy; set_options(c, uri); if (c->listen) snprintf(opts, sizeof(opts), "?listen=1"); av_url_split(NULL, 0, NULL, 0, c->host, sizeof(c->host), &port, NULL, 0, uri); p = strchr(uri, '?'); if (!p) { p = opts; } else { if (av_find_info_tag(opts, sizeof(opts), "listen", p)) c->listen = 1; } ff_url_join(buf, sizeof(buf), "tcp", NULL, c->host, port, "%s", p); hints.ai_flags = AI_NUMERICHOST; if (!getaddrinfo(c->host, NULL, &hints, &ai)) { c->numerichost = 1; freeaddrinfo(ai); } proxy_path = getenv("http_proxy"); use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->host) && proxy_path && av_strstart(proxy_path, "http://", NULL); if (use_proxy) { char proxy_host[200], proxy_auth[200], dest[200]; int proxy_port; av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth), proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0, proxy_path); ff_url_join(dest, sizeof(dest), NULL, NULL, c->host, port, NULL); ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host, proxy_port, "/%s", dest); } return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, &parent->interrupt_callback, options); }
true
FFmpeg
6dd5371e34c6602591766f73aa647b369d77853b
24,838
static void x86_cpu_apic_init(X86CPU *cpu, Error **errp) { static int apic_mapped; CPUX86State *env = &cpu->env; APICCommonState *apic; const char *apic_type = "apic"; if (kvm_irqchip_in_kernel()) { apic_type = "kvm-apic"; } else if (xen_enabled()) { apic_type = "xen-apic"; } env->apic_state = qdev_try_create(NULL, apic_type); if (env->apic_state == NULL) { error_setg(errp, "APIC device '%s' could not be created", apic_type); return; } object_property_add_child(OBJECT(cpu), "apic", OBJECT(env->apic_state), NULL); qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id); /* TODO: convert to link<> */ apic = APIC_COMMON(env->apic_state); apic->cpu = cpu; if (qdev_init(env->apic_state)) { error_setg(errp, "APIC device '%s' could not be initialized", object_get_typename(OBJECT(env->apic_state))); return; } /* XXX: mapping more APICs at the same memory location */ if (apic_mapped == 0) { /* NOTE: the APIC is directly connected to the CPU - it is not on the global memory bus. */ /* XXX: what if the base changes? */ sysbus_mmio_map_overlap(SYS_BUS_DEVICE(env->apic_state), 0, APIC_DEFAULT_ADDRESS, 0x1000); apic_mapped = 1; } }
true
qemu
d3c64d6a1874f94246af91963927fb4d924332f1
24,839
static inline int clamp(int value, int min, int max) { if (value < min) return min; else if (value > max) return max; else return value; }
false
FFmpeg
eb5b0422b595d488f5c2f2a37a62cd46dfbb6aa7
24,840
void audio_init(ISABus *isa_bus, PCIBus *pci_bus) { }
false
qemu
ffa48cf5ab719e1e181e51b87bc0f5d397b791fa
24,841
static void nand_command(NANDFlashState *s) { unsigned int offset; switch (s->cmd) { case NAND_CMD_READ0: s->iolen = 0; break; case NAND_CMD_READID: s->ioaddr = s->io; s->iolen = 0; nand_pushio_byte(s, s->manf_id); nand_pushio_byte(s, s->chip_id); nand_pushio_byte(s, 'Q'); /* Don't-care byte (often 0xa5) */ if (nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP) { /* Page Size, Block Size, Spare Size; bit 6 indicates * 8 vs 16 bit width NAND. */ nand_pushio_byte(s, (s->buswidth == 2) ? 0x55 : 0x15); } else { nand_pushio_byte(s, 0xc0); /* Multi-plane */ } break; case NAND_CMD_RANDOMREAD2: case NAND_CMD_NOSERIALREAD2: if (!(nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP)) break; offset = s->addr & ((1 << s->addr_shift) - 1); s->blk_load(s, s->addr, offset); if (s->gnd) s->iolen = (1 << s->page_shift) - offset; else s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset; break; case NAND_CMD_RESET: nand_reset(DEVICE(s)); break; case NAND_CMD_PAGEPROGRAM1: s->ioaddr = s->io; s->iolen = 0; break; case NAND_CMD_PAGEPROGRAM2: if (s->wp) { s->blk_write(s); } break; case NAND_CMD_BLOCKERASE1: break; case NAND_CMD_BLOCKERASE2: s->addr &= (1ull << s->addrlen * 8) - 1; s->addr <<= nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP ? 16 : 8; if (s->wp) { s->blk_erase(s); } break; case NAND_CMD_READSTATUS: s->ioaddr = s->io; s->iolen = 0; nand_pushio_byte(s, s->status); break; default: printf("%s: Unknown NAND command 0x%02x\n", __FUNCTION__, s->cmd); } }
false
qemu
a89f364ae8740dfc31b321eed9ee454e996dc3c1
24,843
int64_t qemu_clock_deadline_ns_all(QEMUClockType type) { int64_t deadline = -1; QEMUTimerList *timer_list; QEMUClock *clock = qemu_clock_ptr(type); QLIST_FOREACH(timer_list, &clock->timerlists, list) { deadline = qemu_soonest_timeout(deadline, timerlist_deadline_ns(timer_list)); } return deadline; }
false
qemu
c2b38b277a7882a592f4f2ec955084b2b756daaa
24,844
UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, bool has_udb1, UserDefOne *ud1b, Error **errp) { UserDefTwo *ret; UserDefOne *ud1c = g_malloc0(sizeof(UserDefOne)); UserDefOne *ud1d = g_malloc0(sizeof(UserDefOne)); ud1c->string = strdup(ud1a->string); ud1c->base = g_new0(UserDefZero, 1); ud1c->base->integer = ud1a->base->integer; ud1d->string = strdup(has_udb1 ? ud1b->string : "blah0"); ud1d->base = g_new0(UserDefZero, 1); ud1d->base->integer = has_udb1 ? ud1b->base->integer : 0; ret = g_new0(UserDefTwo, 1); ret->string0 = strdup("blah1"); ret->dict1 = g_new0(UserDefTwoDict, 1); ret->dict1->string1 = strdup("blah2"); ret->dict1->dict2 = g_new0(UserDefTwoDictDict, 1); ret->dict1->dict2->userdef = ud1c; ret->dict1->dict2->string = strdup("blah3"); ret->dict1->dict3 = g_new0(UserDefTwoDictDict, 1); ret->dict1->has_dict3 = true; ret->dict1->dict3->userdef = ud1d; ret->dict1->dict3->string = strdup("blah4"); return ret; }
false
qemu
ddf21908961073199f3d186204da4810f2ea150b
24,845
static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { int maskshift = extract32(value, 0, 3); if (arm_feature(env, ARM_FEATURE_LPAE) && (value & (1 << 31))) { value &= ~((7 << 19) | (3 << 14) | (0xf << 3)); } else { value &= 7; } /* Note that we always calculate c2_mask and c2_base_mask, but * they are only used for short-descriptor tables (ie if EAE is 0); * for long-descriptor tables the TTBCR fields are used differently * and the c2_mask and c2_base_mask values are meaningless. */ env->cp15.c2_control = value; env->cp15.c2_mask = ~(((uint32_t)0xffffffffu) >> maskshift); env->cp15.c2_base_mask = ~((uint32_t)0x3fffu >> maskshift); }
false
qemu
8d5c773e323b22402abdd0beef4c7d2fc91dd0eb
24,846
static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, int idx) { openpic_t *opp = opaque; IRQ_src_t *src; IRQ_dst_t *dst; uint32_t retval; int n_IRQ; DPRINTF("%s: cpu %d addr " TARGET_FMT_plx "\n", __func__, idx, addr); retval = 0xFFFFFFFF; if (addr & 0xF) return retval; dst = &opp->dst[idx]; addr &= 0xFF0; switch (addr) { case 0x00: /* Block Revision Register1 (BRR1) */ retval = FSL_BRR1_IPID | FSL_BRR1_IPMJ | FSL_BRR1_IPMN; break; case 0x80: /* PCTP */ retval = dst->pctp; break; case 0x90: /* WHOAMI */ retval = idx; break; case 0xA0: /* PIAC */ DPRINTF("Lower OpenPIC INT output\n"); qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]); n_IRQ = IRQ_get_next(opp, &dst->raised); DPRINTF("PIAC: irq=%d\n", n_IRQ); if (n_IRQ == -1) { /* No more interrupt pending */ retval = IPVP_VECTOR(opp->spve); } else { src = &opp->src[n_IRQ]; if (!test_bit(&src->ipvp, IPVP_ACTIVITY) || !(IPVP_PRIORITY(src->ipvp) > dst->pctp)) { /* - Spurious level-sensitive IRQ * - Priorities has been changed * and the pending IRQ isn't allowed anymore */ reset_bit(&src->ipvp, IPVP_ACTIVITY); retval = IPVP_VECTOR(opp->spve); } else { /* IRQ enter servicing state */ IRQ_setbit(&dst->servicing, n_IRQ); retval = IPVP_VECTOR(src->ipvp); } IRQ_resetbit(&dst->raised, n_IRQ); dst->raised.next = -1; if (!test_bit(&src->ipvp, IPVP_SENSE)) { /* edge-sensitive IRQ */ reset_bit(&src->ipvp, IPVP_ACTIVITY); src->pending = 0; } if ((n_IRQ >= opp->irq_ipi0) && (n_IRQ < (opp->irq_ipi0 + MAX_IPI))) { src->ide &= ~(1 << idx); if (src->ide && !test_bit(&src->ipvp, IPVP_SENSE)) { /* trigger on CPUs that didn't know about it yet */ openpic_set_irq(opp, n_IRQ, 1); openpic_set_irq(opp, n_IRQ, 0); /* if all CPUs knew about it, set active bit again */ set_bit(&src->ipvp, IPVP_ACTIVITY); } } } break; case 0xB0: /* PEOI */ retval = 0; break; default: break; } DPRINTF("%s: => %08x\n", __func__, retval); return retval; }
false
qemu
1945dbc15f0f1ffdc9a10526448e9eba7c599d98
24,848
static int faac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { FAACContext *s = (FAACContext *) avctx->priv_data; #ifndef FAAD2_VERSION unsigned long bytesconsumed; short *sample_buffer = NULL; unsigned long samples; int out; #else faacDecFrameInfo frame_info; void *out; #endif if(buf_size == 0) return 0; #ifndef FAAD2_VERSION out = s->faacDecDecode(s->faac_handle, (unsigned char*)buf, &bytesconsumed, data, &samples); samples *= s->sample_size; if (data_size) *data_size = samples; return (buf_size < (int)bytesconsumed) ? buf_size : (int)bytesconsumed; #else if(!s->init){ unsigned long srate; unsigned char channels; int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels); if(r < 0){ av_log(avctx, AV_LOG_ERROR, "faac: codec init failed: %s\n", s->faacDecGetErrorMessage(frame_info.error)); return 0; } avctx->sample_rate = srate; avctx->channels = channels; s->init = 1; } out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); if (frame_info.error > 0) { av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n", s->faacDecGetErrorMessage(frame_info.error)); return 0; } frame_info.samples *= s->sample_size; memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one if (data_size) *data_size = frame_info.samples; return (buf_size < (int)frame_info.bytesconsumed) ? buf_size : (int)frame_info.bytesconsumed; #endif }
false
FFmpeg
980bbb13d653561d83619350db32ccb5e5248f95
24,849
void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr, uint64_t align, Error **errp) { int slot; MachineState *machine = MACHINE(qdev_get_machine()); PCDIMMDevice *dimm = PC_DIMM(dev); Error *local_err = NULL; uint64_t existing_dimms_capacity = 0; uint64_t addr; addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err); if (local_err) { goto out; } addr = pc_dimm_get_free_addr(hpms->base, memory_region_size(&hpms->mr), !addr ? NULL : &addr, align, memory_region_size(mr), &local_err); if (local_err) { goto out; } existing_dimms_capacity = pc_existing_dimms_capacity(&local_err); if (local_err) { goto out; } if (existing_dimms_capacity + memory_region_size(mr) > machine->maxram_size - machine->ram_size) { error_setg(&local_err, "not enough space, currently 0x%" PRIx64 " in use of total hot pluggable 0x" RAM_ADDR_FMT, existing_dimms_capacity, machine->maxram_size - machine->ram_size); goto out; } object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err); if (local_err) { goto out; } trace_mhp_pc_dimm_assigned_address(addr); slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err); if (local_err) { goto out; } slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot, machine->ram_slots, &local_err); if (local_err) { goto out; } object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err); if (local_err) { goto out; } trace_mhp_pc_dimm_assigned_slot(slot); if (kvm_enabled() && !kvm_has_free_slot(machine)) { error_setg(&local_err, "hypervisor has no free memory slots left"); goto out; } if (!vhost_has_free_slot()) { error_setg(&local_err, "a used vhost backend has no free" " memory slots left"); goto out; } memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); vmstate_register_ram(mr, dev); numa_set_mem_node_id(addr, memory_region_size(mr), dimm->node); out: error_propagate(errp, local_err); }
false
qemu
8df1426e44176512be1b6456e90d100d1af907e1
24,850
static BOOL WINAPI qemu_ctrl_handler(DWORD type) { exit(STATUS_CONTROL_C_EXIT); return TRUE; }
false
qemu
b75a02829dde98723dfe16fa098338cb267b28b9
24,851
static int spapr_phb_init(SysBusDevice *s) { sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s); PCIHostState *phb = PCI_HOST_BRIDGE(s); char *namebuf; int i; PCIBus *bus; sphb->dtbusname = g_strdup_printf("pci@%" PRIx64, sphb->buid); namebuf = alloca(strlen(sphb->dtbusname) + 32); /* Initialize memory regions */ sprintf(namebuf, "%s.mmio", sphb->dtbusname); memory_region_init(&sphb->memspace, namebuf, INT64_MAX); sprintf(namebuf, "%s.mmio-alias", sphb->dtbusname); memory_region_init_alias(&sphb->memwindow, namebuf, &sphb->memspace, SPAPR_PCI_MEM_WIN_BUS_OFFSET, sphb->mem_win_size); memory_region_add_subregion(get_system_memory(), sphb->mem_win_addr, &sphb->memwindow); /* On ppc, we only have MMIO no specific IO space from the CPU * perspective. In theory we ought to be able to embed the PCI IO * memory region direction in the system memory space. However, * if any of the IO BAR subregions use the old_portio mechanism, * that won't be processed properly unless accessed from the * system io address space. This hack to bounce things via * system_io works around the problem until all the users of * old_portion are updated */ sprintf(namebuf, "%s.io", sphb->dtbusname); memory_region_init(&sphb->iospace, namebuf, SPAPR_PCI_IO_WIN_SIZE); /* FIXME: fix to support multiple PHBs */ memory_region_add_subregion(get_system_io(), 0, &sphb->iospace); sprintf(namebuf, "%s.io-alias", sphb->dtbusname); memory_region_init_io(&sphb->iowindow, &spapr_io_ops, sphb, namebuf, SPAPR_PCI_IO_WIN_SIZE); memory_region_add_subregion(get_system_memory(), sphb->io_win_addr, &sphb->iowindow); /* As MSI/MSIX interrupts trigger by writing at MSI/MSIX vectors, * we need to allocate some memory to catch those writes coming * from msi_notify()/msix_notify() */ if (msi_supported) { sprintf(namebuf, "%s.msi", sphb->dtbusname); memory_region_init_io(&sphb->msiwindow, &spapr_msi_ops, sphb, namebuf, SPAPR_MSIX_MAX_DEVS * 0x10000); memory_region_add_subregion(get_system_memory(), sphb->msi_win_addr, &sphb->msiwindow); } bus = pci_register_bus(DEVICE(s), sphb->busname ? sphb->busname : sphb->dtbusname, pci_spapr_set_irq, pci_spapr_map_irq, sphb, &sphb->memspace, &sphb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); phb->bus = bus; sphb->dma_liobn = SPAPR_PCI_BASE_LIOBN | (pci_find_domain(bus) << 16); sphb->dma_window_start = 0; sphb->dma_window_size = 0x40000000; sphb->dma = spapr_tce_new_dma_context(sphb->dma_liobn, sphb->dma_window_size); pci_setup_iommu(bus, spapr_pci_dma_context_fn, sphb); QLIST_INSERT_HEAD(&spapr->phbs, sphb, list); /* Initialize the LSI table */ for (i = 0; i < PCI_NUM_PINS; i++) { uint32_t irq; irq = spapr_allocate_lsi(0); if (!irq) { return -1; } sphb->lsi_table[i].irq = irq; } return 0; }
false
qemu
a178274efabcbbc5d44805b51def874e47051325
24,852
static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { IMXEPITState *s = IMX_EPIT(opaque); uint32_t reg = offset >> 2; uint64_t oldcr; DPRINTF("(%s, value = 0x%08x)\n", imx_epit_reg_name(reg), (uint32_t)value); switch (reg) { case 0: /* CR */ oldcr = s->cr; s->cr = value & 0x03ffffff; if (s->cr & CR_SWR) { /* handle the reset */ imx_epit_reset(DEVICE(s)); } else { imx_epit_set_freq(s); } if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) { if (s->cr & CR_ENMOD) { if (s->cr & CR_RLD) { ptimer_set_limit(s->timer_reload, s->lr, 1); ptimer_set_limit(s->timer_cmp, s->lr, 1); } else { ptimer_set_limit(s->timer_reload, TIMER_MAX, 1); ptimer_set_limit(s->timer_cmp, TIMER_MAX, 1); } } imx_epit_reload_compare_timer(s); ptimer_run(s->timer_reload, 0); if (s->cr & CR_OCIEN) { ptimer_run(s->timer_cmp, 0); } else { ptimer_stop(s->timer_cmp); } } else if (!(s->cr & CR_EN)) { /* stop both timers */ ptimer_stop(s->timer_reload); ptimer_stop(s->timer_cmp); } else if (s->cr & CR_OCIEN) { if (!(oldcr & CR_OCIEN)) { imx_epit_reload_compare_timer(s); ptimer_run(s->timer_cmp, 0); } } else { ptimer_stop(s->timer_cmp); } break; case 1: /* SR - ACK*/ /* writing 1 to OCIF clear the OCIF bit */ if (value & 0x01) { s->sr = 0; imx_epit_update_int(s); } break; case 2: /* LR - set ticks */ s->lr = value; if (s->cr & CR_RLD) { /* Also set the limit if the LRD bit is set */ /* If IOVW bit is set then set the timer value */ ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW); ptimer_set_limit(s->timer_cmp, s->lr, 0); } else if (s->cr & CR_IOVW) { /* If IOVW bit is set then set the timer value */ ptimer_set_count(s->timer_reload, s->lr); } imx_epit_reload_compare_timer(s); break; case 3: /* CMP */ s->cmp = value; imx_epit_reload_compare_timer(s); break; default: IPRINTF("Bad offset %x\n", reg); break; } }
false
qemu
203d65a4706be345c209f3408d3a011a3e48f0c9
24,854
uint32_t HELPER(rrbe)(uint32_t r1, uint64_t r2) { if (r2 > ram_size) { return 0; } /* XXX implement */ #if 0 env->storage_keys[r2 / TARGET_PAGE_SIZE] &= ~SK_REFERENCED; #endif /* * cc * * 0 Reference bit zero; change bit zero * 1 Reference bit zero; change bit one * 2 Reference bit one; change bit zero * 3 Reference bit one; change bit one */ return 0; }
false
qemu
17bb18ce16b45e61248c5238074fa9cf8bc547bf
24,856
static void ivshmem_io_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { IVShmemState *s = opaque; uint16_t dest = val >> 16; uint16_t vector = val & 0xff; addr &= 0xfc; IVSHMEM_DPRINTF("writing to addr " TARGET_FMT_plx "\n", addr); switch (addr) { case INTRMASK: ivshmem_IntrMask_write(s, val); break; case INTRSTATUS: ivshmem_IntrStatus_write(s, val); break; case DOORBELL: /* check that dest VM ID is reasonable */ if (dest > s->max_peer) { IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest); break; } /* check doorbell range */ if (vector < s->peers[dest].nb_eventfds) { IVSHMEM_DPRINTF("Notifying VM %d on vector %d\n", dest, vector); event_notifier_set(&s->peers[dest].eventfds[vector]); } break; default: IVSHMEM_DPRINTF("Invalid VM Doorbell VM %d\n", dest); } }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
24,857
SpiceInfo *qmp_query_spice(Error **errp) { QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head); int port, tls_port; const char *addr; SpiceInfo *info; char version_string[20]; /* 12 = |255.255.255\0| is the max */ info = g_malloc0(sizeof(*info)); if (!spice_server || !opts) { info->enabled = false; return info; } info->enabled = true; info->migrated = spice_migration_completed; addr = qemu_opt_get(opts, "addr"); port = qemu_opt_get_number(opts, "port", 0); tls_port = qemu_opt_get_number(opts, "tls-port", 0); info->has_auth = true; info->auth = g_strdup(auth); info->has_host = true; info->host = g_strdup(addr ? addr : "0.0.0.0"); info->has_compiled_version = true; snprintf(version_string, sizeof(version_string), "%d.%d.%d", (SPICE_SERVER_VERSION & 0xff0000) >> 16, (SPICE_SERVER_VERSION & 0xff00) >> 8, SPICE_SERVER_VERSION & 0xff); info->compiled_version = g_strdup(version_string); if (port) { info->has_port = true; info->port = port; } if (tls_port) { info->has_tls_port = true; info->tls_port = tls_port; } info->mouse_mode = spice_server_is_server_mouse(spice_server) ? SPICE_QUERY_MOUSE_MODE_SERVER : SPICE_QUERY_MOUSE_MODE_CLIENT; /* for compatibility with the original command */ info->has_channels = true; info->channels = qmp_query_spice_channels(); return info; }
false
qemu
6735aa99a43c70c09b53af190b24600a61178b95
24,858
void memory_region_init_rom_device(MemoryRegion *mr, const MemoryRegionOps *ops, void *opaque, const char *name, uint64_t size) { memory_region_init(mr, name, size); mr->ops = ops; mr->opaque = opaque; mr->terminates = true; mr->destructor = memory_region_destructor_rom_device; mr->ram_addr = qemu_ram_alloc(size, mr); mr->ram_addr |= cpu_register_io_memory(memory_region_read_thunk, memory_region_write_thunk, mr); mr->ram_addr |= IO_MEM_ROMD; mr->backend_registered = true; }
false
qemu
26a83ad0e793465b74a8b06a65f2f6fdc5615413
24,860
av_cold int ff_rv34_decode_init(AVCodecContext *avctx) { RV34DecContext *r = avctx->priv_data; MpegEncContext *s = &r->s; MPV_decode_defaults(s); s->avctx= avctx; s->out_format = FMT_H263; s->codec_id= avctx->codec_id; s->width = avctx->width; s->height = avctx->height; r->s.avctx = avctx; avctx->flags |= CODEC_FLAG_EMU_EDGE; r->s.flags |= CODEC_FLAG_EMU_EDGE; avctx->pix_fmt = PIX_FMT_YUV420P; avctx->has_b_frames = 1; s->low_delay = 0; if (MPV_common_init(s) < 0) return -1; ff_h264_pred_init(&r->h, CODEC_ID_RV40); r->intra_types_hist = av_malloc(s->b4_stride * 4 * 2 * sizeof(*r->intra_types_hist)); r->intra_types = r->intra_types_hist + s->b4_stride * 4; r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); if(!intra_vlcs[0].cbppattern[0].bits) rv34_init_tables(); return 0; }
false
FFmpeg
3df18b3ed1177037892ce5b3db113d52dcdcdbf3
24,861
static inline void mix_2f_2r_to_stereo(AC3DecodeContext *ctx) { int i; float (*output)[256] = ctx->audio_block.block_output; for (i = 0; i < 256; i++) { output[1][i] += output[3][i]; output[2][i] += output[4][i]; } memset(output[3], 0, sizeof(output[3])); memset(output[4], 0, sizeof(output[4])); }
false
FFmpeg
486637af8ef29ec215e0e0b7ecd3b5470f0e04e5
24,862
void *qemu_vmalloc(size_t size) { void *p; unsigned long addr; mmap_lock(); /* Use map and mark the pages as used. */ p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); addr = (unsigned long)p; if (addr == (target_ulong) addr) { /* Allocated region overlaps guest address space. This may recurse. */ page_set_flags(addr & TARGET_PAGE_MASK, TARGET_PAGE_ALIGN(addr + size), PAGE_RESERVED); } mmap_unlock(); return p; }
false
qemu
b035ffd11813524d7c0e44354f5c4bdd281f4b37
24,864
static void rtas_query_cpu_stopped_state(sPAPREnvironment *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { target_ulong id; CPUState *cpu; if (nargs != 1 || nret != 2) { rtas_st(rets, 0, -3); return; } id = rtas_ld(args, 0); cpu = qemu_get_cpu(id); if (cpu != NULL) { if (cpu->halted) { rtas_st(rets, 1, 0); } else { rtas_st(rets, 1, 2); } rtas_st(rets, 0, 0); return; } /* Didn't find a matching cpu */ rtas_st(rets, 0, -3); }
false
qemu
210b580b106fa798149e28aa13c66b325a43204e
24,866
static void nvic_recompute_state(NVICState *s) { int i; int pend_prio = NVIC_NOEXC_PRIO; int active_prio = NVIC_NOEXC_PRIO; int pend_irq = 0; for (i = 1; i < s->num_irq; i++) { VecInfo *vec = &s->vectors[i]; if (vec->enabled && vec->pending && vec->prio < pend_prio) { pend_prio = vec->prio; pend_irq = i; } if (vec->active && vec->prio < active_prio) { active_prio = vec->prio; } } if (active_prio > 0) { active_prio &= nvic_gprio_mask(s); } s->vectpending = pend_irq; s->exception_prio = active_prio; trace_nvic_recompute_state(s->vectpending, s->exception_prio); }
false
qemu
5255fcf8e47acd059e2f0d414841c40231c1bd22
24,867
static int local_fsync(FsContext *ctx, int fd) { if (0) /* Just to supress the warning. Will be removed in next patch. */ (void)local_set_xattr(NULL, NULL); return fsync(fd); }
false
qemu
e95ead32efc48157de12e0a257ea1c52541a6ce1
24,868
void qmp_blockdev_add(BlockdevOptions *options, Error **errp) { BlockDriverState *bs; QObject *obj; Visitor *v = qmp_output_visitor_new(&obj); QDict *qdict; Error *local_err = NULL; visit_type_BlockdevOptions(v, NULL, &options, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; } visit_complete(v, &obj); qdict = qobject_to_qdict(obj); qdict_flatten(qdict); if (!qdict_get_try_str(qdict, "node-name")) { error_setg(errp, "'node-name' must be specified for the root node"); goto fail; } bs = bds_tree_init(qdict, errp); if (!bs) { goto fail; } QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); if (bs && bdrv_key_required(bs)) { QTAILQ_REMOVE(&monitor_bdrv_states, bs, monitor_list); bdrv_unref(bs); error_setg(errp, "blockdev-add doesn't support encrypted devices"); goto fail; } fail: visit_free(v); }
false
qemu
7d5e199ade76c53ec316ab6779800581bb47c50a
24,869
static int segment_start(AVFormatContext *s) { SegmentContext *seg = s->priv_data; AVFormatContext *oc = seg->avf; int err = 0; if (seg->wrap) seg->number %= seg->wrap; if (av_get_frame_filename(oc->filename, sizeof(oc->filename), s->filename, seg->number++) < 0) return AVERROR(EINVAL); if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL)) < 0) return err; if (!oc->priv_data && oc->oformat->priv_data_size > 0) { oc->priv_data = av_mallocz(oc->oformat->priv_data_size); if (!oc->priv_data) { avio_close(oc->pb); return AVERROR(ENOMEM); } if (oc->oformat->priv_class) { *(const AVClass**)oc->priv_data = oc->oformat->priv_class; av_opt_set_defaults(oc->priv_data); } } if ((err = oc->oformat->write_header(oc)) < 0) { goto fail; } return 0; fail: av_log(oc, AV_LOG_ERROR, "Failure occurred when starting segment '%s'\n", oc->filename); avio_close(oc->pb); av_freep(&oc->priv_data); return err; }
false
FFmpeg
d8013f38ab73b15c5041f2489fc0b8bb45512e24
24,870
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { mp_image_t *dmpi; if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do dmpi = mpi; } else { int out_off_left, out_off_right; int in_off_left = vf->priv->in.row_left * mpi->stride[0] + vf->priv->in.off_left; int in_off_right = vf->priv->in.row_right * mpi->stride[0] + vf->priv->in.off_right; dmpi = ff_vf_get_image(vf->next, IMGFMT_RGB24, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, vf->priv->out.width, vf->priv->out.height); out_off_left = vf->priv->out.row_left * dmpi->stride[0] + vf->priv->out.off_left; out_off_right = vf->priv->out.row_right * dmpi->stride[0] + vf->priv->out.off_right; switch (vf->priv->out.fmt) { case SIDE_BY_SIDE_LR: case SIDE_BY_SIDE_RL: case SIDE_BY_SIDE_2_LR: case SIDE_BY_SIDE_2_RL: case ABOVE_BELOW_LR: case ABOVE_BELOW_RL: case ABOVE_BELOW_2_LR: case ABOVE_BELOW_2_RL: case INTERLEAVE_ROWS_LR: case INTERLEAVE_ROWS_RL: memcpy_pic2(dmpi->planes[0] + out_off_left, mpi->planes[0] + in_off_left, 3 * vf->priv->width, vf->priv->height, dmpi->stride[0] * vf->priv->row_step, mpi->stride[0] * vf->priv->row_step, vf->priv->row_step != 1); memcpy_pic2(dmpi->planes[0] + out_off_right, mpi->planes[0] + in_off_right, 3 * vf->priv->width, vf->priv->height, dmpi->stride[0] * vf->priv->row_step, mpi->stride[0] * vf->priv->row_step, vf->priv->row_step != 1); break; case MONO_L: case MONO_R: memcpy_pic(dmpi->planes[0], mpi->planes[0] + in_off_left, 3 * vf->priv->width, vf->priv->height, dmpi->stride[0], mpi->stride[0]); break; case ANAGLYPH_RC_GRAY: case ANAGLYPH_RC_HALF: case ANAGLYPH_RC_COLOR: case ANAGLYPH_RC_DUBOIS: case ANAGLYPH_GM_GRAY: case ANAGLYPH_GM_HALF: case ANAGLYPH_GM_COLOR: case ANAGLYPH_YB_GRAY: case ANAGLYPH_YB_HALF: case ANAGLYPH_YB_COLOR: { int i,x,y,il,ir,o; unsigned char *source = mpi->planes[0]; unsigned char *dest = dmpi->planes[0]; unsigned int out_width = vf->priv->out.width; int *ana_matrix[3]; for(i = 0; i < 3; i++) ana_matrix[i] = vf->priv->ana_matrix[i]; for (y = 0; y < vf->priv->out.height; y++) { o = dmpi->stride[0] * y; il = in_off_left + y * mpi->stride[0]; ir = in_off_right + y * mpi->stride[0]; for (x = 0; x < out_width; x++) { dest[o ] = ana_convert( ana_matrix[0], source + il, source + ir); //red out dest[o + 1] = ana_convert( ana_matrix[1], source + il, source + ir); //green out dest[o + 2] = ana_convert( ana_matrix[2], source + il, source + ir); //blue out il += 3; ir += 3; o += 3; } } break; } default: ff_mp_msg(MSGT_VFILTER, MSGL_WARN, "[stereo3d] stereo format of output is not supported\n"); return 0; break; } } return ff_vf_next_put_image(vf, dmpi, pts); }
false
FFmpeg
708ed15d8ccd5ae3d073cbd4dc69dafccec3fcc7
24,871
static void vfio_platform_realize(DeviceState *dev, Error **errp) { VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev); SysBusDevice *sbdev = SYS_BUS_DEVICE(dev); VFIODevice *vbasedev = &vdev->vbasedev; int i, ret; vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM; vbasedev->ops = &vfio_platform_ops; trace_vfio_platform_realize(vbasedev->name, vdev->compat); ret = vfio_base_device_init(vbasedev); if (ret) { error_setg(errp, "vfio: vfio_base_device_init failed for %s", vbasedev->name); return; } for (i = 0; i < vbasedev->num_regions; i++) { vfio_map_region(vdev, i); sysbus_init_mmio(sbdev, &vdev->regions[i]->mem); } }
false
qemu
7df9381b7aa56c897e344f3bfe43bf5848bbd3e0
24,873
void json_lexer_destroy(JSONLexer *lexer) { QDECREF(lexer->token); }
false
qemu
d2ca7c0b0d876cf0e219ae7a92252626b0913a28
24,874
static void pcnet_ioport_write(void *opaque, target_phys_addr_t addr, uint64_t data, unsigned size) { PCNetState *d = opaque; if (addr < 16 && size == 1) { return pcnet_aprom_writeb(d, addr, data); } else if (addr >= 0x10 && addr < 0x20 && size == 2) { return pcnet_ioport_writew(d, addr, data); } else if (addr >= 0x10 && addr < 0x20 && size == 4) { return pcnet_ioport_writel(d, addr, data); } }
false
qemu
7ba7974197090285fdb413c6e1c41aaacd44b9c4
24,875
build_hash_table (const sparc_opcode **opcode_table, sparc_opcode_hash **hash_table, int num_opcodes) { int i; int hash_count[HASH_SIZE]; static sparc_opcode_hash *hash_buf = NULL; /* Start at the end of the table and work backwards so that each chain is sorted. */ memset (hash_table, 0, HASH_SIZE * sizeof (hash_table[0])); memset (hash_count, 0, HASH_SIZE * sizeof (hash_count[0])); if (hash_buf != NULL) free (hash_buf); hash_buf = malloc (sizeof (* hash_buf) * num_opcodes); for (i = num_opcodes - 1; i >= 0; --i) { int hash = HASH_INSN (opcode_table[i]->match); sparc_opcode_hash *h = &hash_buf[i]; h->next = hash_table[hash]; h->opcode = opcode_table[i]; hash_table[hash] = h; ++hash_count[hash]; } #if 0 /* for debugging */ { int min_count = num_opcodes, max_count = 0; int total; for (i = 0; i < HASH_SIZE; ++i) { if (hash_count[i] < min_count) min_count = hash_count[i]; if (hash_count[i] > max_count) max_count = hash_count[i]; total += hash_count[i]; } printf ("Opcode hash table stats: min %d, max %d, ave %f\n", min_count, max_count, (double) total / HASH_SIZE); } #endif }
false
qemu
ef1e1e0782e99c9dcf2b35e5310cdd8ca9211374
24,876
void nbd_export_close(NBDExport *exp) { NBDClient *client, *next; nbd_export_get(exp); QTAILQ_FOREACH_SAFE(client, &exp->clients, next, next) { nbd_client_close(client); } nbd_export_set_name(exp, NULL); nbd_export_put(exp); if (exp->blk) { blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, exp); blk_unref(exp->blk); exp->blk = NULL; } }
false
qemu
f53a829bb9ef14be800556cbc02d8b20fc1050a7
24,877
static void gen_spr_power8_book4(CPUPPCState *env) { /* Add a number of P8 book4 registers */ #if !defined(CONFIG_USER_ONLY) spr_register_kvm(env, SPR_ACOP, "ACOP", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, KVM_REG_PPC_ACOP, 0); spr_register_kvm(env, SPR_BOOKS_PID, "PID", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, KVM_REG_PPC_PID, 0); spr_register_kvm(env, SPR_WORT, "WORT", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, KVM_REG_PPC_WORT, 0); #endif }
false
qemu
31b2b0f8463533c32b5ad76e73668e2e9fca8ae2
24,878
int cpu_m68k_handle_mmu_fault (CPUState *env, target_ulong address, int rw, int mmu_idx, int is_softmmu) { int prot; address &= TARGET_PAGE_MASK; prot = PAGE_READ | PAGE_WRITE; return tlb_set_page(env, address, address, prot, mmu_idx, is_softmmu); }
false
qemu
d4c430a80f000d722bb70287af4d4c184a8d7006
24,879
void helper_movl_crN_T0(int reg) { env->cr[reg] = T0; switch(reg) { case 0: cpu_x86_update_cr0(env); break; case 3: cpu_x86_update_cr3(env); break; } }
false
qemu
1ac157da77c863b62b1d2f467626a440d57cf17d
24,882
static bool pmsav7_needed(void *opaque) { ARMCPU *cpu = opaque; CPUARMState *env = &cpu->env; return arm_feature(env, ARM_FEATURE_PMSA) && arm_feature(env, ARM_FEATURE_V7); }
false
qemu
0e1a46bbd2d6c39614b87f4e88ea305acce8a35f
24,883
int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong address, int rw, int access_type) { ppcemb_tlb_t *tlb; target_phys_addr_t raddr; int i, ret, zsel, zpr; ret = -1; raddr = -1; for (i = 0; i < env->nb_tlb; i++) { tlb = &env->tlb[i].tlbe; if (ppcemb_tlb_check(env, tlb, &raddr, address, env->spr[SPR_40x_PID], 0, i) < 0) continue; zsel = (tlb->attr >> 4) & 0xF; zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3; #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: TLB %d zsel %d zpr %d rw %d attr %08x\n", __func__, i, zsel, zpr, rw, tlb->attr); } #endif if (access_type == ACCESS_CODE) { /* Check execute enable bit */ switch (zpr) { case 0x2: if (msr_pr) goto check_exec_perm; goto exec_granted; case 0x0: if (msr_pr) { ctx->prot = 0; ret = -3; break; } /* No break here */ case 0x1: check_exec_perm: /* Check from TLB entry */ if (!(tlb->prot & PAGE_EXEC)) { ret = -3; } else { if (tlb->prot & PAGE_WRITE) { ctx->prot = PAGE_READ | PAGE_WRITE; } else { ctx->prot = PAGE_READ; } ret = 0; } break; case 0x3: exec_granted: /* All accesses granted */ ctx->prot = PAGE_READ | PAGE_WRITE; ret = 0; break; } } else { switch (zpr) { case 0x2: if (msr_pr) goto check_rw_perm; goto rw_granted; case 0x0: if (msr_pr) { ctx->prot = 0; ret = -2; break; } /* No break here */ case 0x1: check_rw_perm: /* Check from TLB entry */ /* Check write protection bit */ if (tlb->prot & PAGE_WRITE) { ctx->prot = PAGE_READ | PAGE_WRITE; ret = 0; } else { ctx->prot = PAGE_READ; if (rw) ret = -2; else ret = 0; } break; case 0x3: rw_granted: /* All accesses granted */ ctx->prot = PAGE_READ | PAGE_WRITE; ret = 0; break; } } if (ret >= 0) { ctx->raddr = raddr; #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: access granted " ADDRX " => " REGX " %d %d\n", __func__, address, ctx->raddr, ctx->prot, ret); } #endif return 0; } } #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: access refused " ADDRX " => " REGX " %d %d\n", __func__, address, raddr, ctx->prot, ret); } #endif return ret; }
false
qemu
b227a8e9aa5f27d29f77ba90d5eb9d0662a1175e
24,884
static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) { struct dirent *entry; again: entry = readdir(fs->dir.stream); if (!entry) { return NULL; } if (ctx->export_flags & V9FS_SM_MAPPED) { entry->d_type = DT_UNKNOWN; } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { if (local_is_mapped_file_metadata(ctx, entry->d_name)) { /* skip the meta data directory */ goto again; } entry->d_type = DT_UNKNOWN; } return entry; }
false
qemu
81ffbf5ab1458e357a761f1272105a55829b351e
24,886
static void tricore_cpu_class_init(ObjectClass *c, void *data) { TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c); CPUClass *cc = CPU_CLASS(c); DeviceClass *dc = DEVICE_CLASS(c); mcc->parent_realize = dc->realize; dc->realize = tricore_cpu_realizefn; mcc->parent_reset = cc->reset; cc->reset = tricore_cpu_reset; cc->class_by_name = tricore_cpu_class_by_name; cc->has_work = tricore_cpu_has_work; cc->dump_state = tricore_cpu_dump_state; cc->set_pc = tricore_cpu_set_pc; cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; }
true
qemu
b190f477e29c7cd03a8fee49c96d27f160e3f5b0
24,887
static int udp_open(URLContext *h, const char *uri, int flags) { char hostname[1024], localaddr[1024] = ""; int port, udp_fd = -1, tmp, bind_ret = -1; UDPContext *s = h->priv_data; int is_output; const char *p; char buf[256]; struct sockaddr_storage my_addr; int len; int reuse_specified = 0; int i, include = 0, num_sources = 0; char *sources[32]; h->is_streamed = 1; h->max_packet_size = 1472; is_output = !(flags & AVIO_FLAG_READ); s->ttl = 16; s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; s->circular_buffer_size = 7*188*4096; p = strchr(uri, '?'); if (p) { if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) { char *endptr = NULL; s->reuse_socket = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ if (buf == endptr) s->reuse_socket = 1; reuse_specified = 1; } if (av_find_info_tag(buf, sizeof(buf), "overrun_nonfatal", p)) { char *endptr = NULL; s->overrun_nonfatal = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ if (buf == endptr) s->overrun_nonfatal = 1; } if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { s->ttl = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { s->local_port = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { h->max_packet_size = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) { s->buffer_size = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { s->is_connected = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) { s->circular_buffer_size = strtol(buf, NULL, 10)*188; "'circular_buffer_size' option was set but it is not supported " } if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { av_strlcpy(localaddr, buf, sizeof(localaddr)); } if (av_find_info_tag(buf, sizeof(buf), "sources", p)) include = 1; if (include || av_find_info_tag(buf, sizeof(buf), "block", p)) { char *source_start; source_start = buf; while (1) { char *next = strchr(source_start, ','); if (next) *next = '\0'; sources[num_sources] = av_strdup(source_start); if (!sources[num_sources]) goto fail; source_start = next + 1; num_sources++; if (num_sources >= FF_ARRAY_ELEMS(sources) || !next) break; } } } /* fill the dest addr */ av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); /* XXX: fix av_url_split */ if (hostname[0] == '\0' || hostname[0] == '?') { /* only accepts null hostname if input */ if (!(flags & AVIO_FLAG_READ)) goto fail; } else { if (ff_udp_set_remote_url(h, uri) < 0) goto fail; } if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ)) s->local_port = port; udp_fd = udp_socket_create(s, &my_addr, &len, localaddr); if (udp_fd < 0) goto fail; /* Follow the requested reuse option, unless it's multicast in which * case enable reuse unless explicitly disabled. */ if (s->reuse_socket || (s->is_multicast && !reuse_specified)) { s->reuse_socket = 1; if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0) goto fail; } /* If multicast, try binding the multicast address first, to avoid * receiving UDP packets from other sources aimed at the same UDP * port. This fails on windows. This makes sending to the same address * using sendto() fail, so only do it if we're opened in read-only mode. */ if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) { bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); } /* bind to the local address if not multicast or if the multicast * bind failed */ /* the bind is needed to give a port to the socket now */ if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) { log_net_error(h, AV_LOG_ERROR, "bind failed"); goto fail; } len = sizeof(my_addr); getsockname(udp_fd, (struct sockaddr *)&my_addr, &len); s->local_port = udp_port(&my_addr, len); if (s->is_multicast) { if (h->flags & AVIO_FLAG_WRITE) { /* output */ if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) goto fail; } if (h->flags & AVIO_FLAG_READ) { /* input */ if (num_sources == 0 || !include) { if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) goto fail; if (num_sources) { if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, sources, num_sources, 0) < 0) goto fail; } } else if (include && num_sources) { if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, sources, num_sources, 1) < 0) goto fail; } else { av_log(NULL, AV_LOG_ERROR, "invalid udp settings: inclusive multicast but no sources given\n"); goto fail; } } } if (is_output) { /* limit the tx buf size to limit latency */ tmp = s->buffer_size; if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { log_net_error(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF)"); goto fail; } } else { /* set udp recv buffer size to the largest possible udp packet size to * avoid losing data on OSes that set this too low by default. */ tmp = s->buffer_size; if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)"); } /* make the socket non-blocking */ ff_socket_nonblock(udp_fd, 1); } if (s->is_connected) { if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) { log_net_error(h, AV_LOG_ERROR, "connect"); goto fail; } } for (i = 0; i < num_sources; i++) av_freep(&sources[i]); s->udp_fd = udp_fd; #if HAVE_PTHREAD_CANCEL if (!is_output && s->circular_buffer_size) { int ret; /* start the task going */ s->fifo = av_fifo_alloc(s->circular_buffer_size); ret = pthread_mutex_init(&s->mutex, NULL); if (ret != 0) { av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret)); goto fail; } ret = pthread_cond_init(&s->cond, NULL); if (ret != 0) { av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", strerror(ret)); goto cond_fail; } ret = pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h); if (ret != 0) { av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", strerror(ret)); goto thread_fail; } s->thread_started = 1; } #endif return 0; #if HAVE_PTHREAD_CANCEL thread_fail: pthread_cond_destroy(&s->cond); cond_fail: pthread_mutex_destroy(&s->mutex); #endif fail: if (udp_fd >= 0) closesocket(udp_fd); av_fifo_free(s->fifo); for (i = 0; i < num_sources; i++) av_freep(&sources[i]); return AVERROR(EIO); }
true
FFmpeg
a8d8e868c6154f63a9229f913434aaa21833e488
24,888
static int vc1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size, n_slices = 0, i; VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; AVFrame *pict = data; uint8_t *buf2 = NULL; const uint8_t *buf_start = buf; int mb_height, n_slices1; struct { uint8_t *buf; GetBitContext gb; int mby_start; } *slices = NULL, *tmp; /* no supplementary picture */ if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) { /* special case for last picture */ if (s->low_delay == 0 && s->next_picture_ptr) { *pict = s->next_picture_ptr->f; s->next_picture_ptr = NULL; *data_size = sizeof(AVFrame); } return 0; } if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) { if (v->profile < PROFILE_ADVANCED) avctx->pix_fmt = AV_PIX_FMT_VDPAU_WMV3; else avctx->pix_fmt = AV_PIX_FMT_VDPAU_VC1; } //for advanced profile we may need to parse and unescape data if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { int buf_size2 = 0; buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ const uint8_t *start, *end, *next; int size; next = buf; for (start = buf, end = buf + buf_size; next < end; start = next) { next = find_next_marker(start + 4, end); size = next - start - 4; if (size <= 0) continue; switch (AV_RB32(start)) { case VC1_CODE_FRAME: if (avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) buf_start = start; buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); break; case VC1_CODE_FIELD: { int buf_size3; tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); if (!tmp) goto err; slices = tmp; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; buf_size3 = vc1_unescape_buffer(start + 4, size, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); /* assuming that the field marker is at the exact middle, hope it's correct */ slices[n_slices].mby_start = s->mb_height >> 1; n_slices1 = n_slices - 1; // index of the last slice of the first field n_slices++; break; } case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&s->gb, buf2, buf_size2 * 8); ff_vc1_decode_entry_point(avctx, v, &s->gb); break; case VC1_CODE_SLICE: { int buf_size3; tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); if (!tmp) goto err; slices = tmp; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; buf_size3 = vc1_unescape_buffer(start + 4, size, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9); n_slices++; break; } } } } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */ const uint8_t *divider; int buf_size3; divider = find_next_marker(buf, buf + buf_size); if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) { av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n"); goto err; } else { // found field marker, unescape second field tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); if (!tmp) goto err; slices = tmp; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = s->mb_height >> 1; n_slices1 = n_slices - 1; n_slices++; } buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2); } else { buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2); } init_get_bits(&s->gb, buf2, buf_size2*8); } else init_get_bits(&s->gb, buf, buf_size*8); if (v->res_sprite) { v->new_sprite = !get_bits1(&s->gb); v->two_sprites = get_bits1(&s->gb); /* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means we're using the sprite compositor. These are intentionally kept separate so you can get the raw sprites by using the wmv3 decoder for WMVP or the vc1 one for WVP2 */ if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { if (v->new_sprite) { // switch AVCodecContext parameters to those of the sprites avctx->width = avctx->coded_width = v->sprite_width; avctx->height = avctx->coded_height = v->sprite_height; } else { goto image; } } } if (s->context_initialized && (s->width != avctx->coded_width || s->height != avctx->coded_height)) { ff_vc1_decode_end(avctx); } if (!s->context_initialized) { if (ff_msmpeg4_decode_init(avctx) < 0 || ff_vc1_decode_init_alloc_tables(v) < 0) return -1; s->low_delay = !avctx->has_b_frames || v->res_sprite; if (v->profile == PROFILE_ADVANCED) { s->h_edge_pos = avctx->coded_width; s->v_edge_pos = avctx->coded_height; } } /* We need to set current_picture_ptr before reading the header, * otherwise we cannot store anything in there. */ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { int i = ff_find_unused_picture(s, 0); if (i < 0) goto err; s->current_picture_ptr = &s->picture[i]; } // do parse frame header v->pic_header_flag = 0; if (v->profile < PROFILE_ADVANCED) { if (ff_vc1_parse_frame_header(v, &s->gb) == -1) { goto err; } } else { if (ff_vc1_parse_frame_header_adv(v, &s->gb) == -1) { goto err; } } if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) && s->pict_type != AV_PICTURE_TYPE_I) { av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n"); goto err; } // process pulldown flags s->current_picture_ptr->f.repeat_pict = 0; // Pulldown flags are only valid when 'broadcast' has been set. // So ticks_per_frame will be 2 if (v->rff) { // repeat field s->current_picture_ptr->f.repeat_pict = 1; } else if (v->rptfrm) { // repeat frames s->current_picture_ptr->f.repeat_pict = v->rptfrm * 2; } // for skipping the frame s->current_picture.f.pict_type = s->pict_type; s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; /* skip B-frames if we don't have reference frames */ if (s->last_picture_ptr == NULL && (s->pict_type == AV_PICTURE_TYPE_B || s->dropable)) { goto err; } if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) { goto end; } if (s->next_p_frame_damaged) { if (s->pict_type == AV_PICTURE_TYPE_B) goto end; else s->next_p_frame_damaged = 0; } if (ff_MPV_frame_start(s, avctx) < 0) { goto err; } s->me.qpel_put = s->dsp.put_qpel_pixels_tab; s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab; if ((CONFIG_VC1_VDPAU_DECODER) &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start); else if (avctx->hwaccel) { if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) goto err; if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0) goto err; if (avctx->hwaccel->end_frame(avctx) < 0) goto err; } else { ff_er_frame_start(s); v->bits = buf_size * 8; v->end_mb_x = s->mb_width; if (v->field_mode) { uint8_t *tmp[2]; s->current_picture.f.linesize[0] <<= 1; s->current_picture.f.linesize[1] <<= 1; s->current_picture.f.linesize[2] <<= 1; s->linesize <<= 1; s->uvlinesize <<= 1; tmp[0] = v->mv_f_last[0]; tmp[1] = v->mv_f_last[1]; v->mv_f_last[0] = v->mv_f_next[0]; v->mv_f_last[1] = v->mv_f_next[1]; v->mv_f_next[0] = v->mv_f[0]; v->mv_f_next[1] = v->mv_f[1]; v->mv_f[0] = tmp[0]; v->mv_f[1] = tmp[1]; } mb_height = s->mb_height >> v->field_mode; for (i = 0; i <= n_slices; i++) { if (i > 0 && slices[i - 1].mby_start >= mb_height) { if (v->field_mode <= 0) { av_log(v->s.avctx, AV_LOG_ERROR, "Slice %d starts beyond " "picture boundary (%d >= %d)\n", i, slices[i - 1].mby_start, mb_height); continue; } v->second_field = 1; v->blocks_off = s->mb_width * s->mb_height << 1; v->mb_off = s->mb_stride * s->mb_height >> 1; } else { v->second_field = 0; v->blocks_off = 0; v->mb_off = 0; } if (i) { v->pic_header_flag = 0; if (v->field_mode && i == n_slices1 + 2) { if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) { av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n"); continue; } } else if (get_bits1(&s->gb)) { v->pic_header_flag = 1; if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) { av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n"); continue; } } } s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height); if (!v->field_mode || v->second_field) s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height); else s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height); ff_vc1_decode_blocks(v); if (i != n_slices) s->gb = slices[i].gb; } if (v->field_mode) { v->second_field = 0; if (s->pict_type == AV_PICTURE_TYPE_B) { memcpy(v->mv_f_base, v->mv_f_next_base, 2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); } s->current_picture.f.linesize[0] >>= 1; s->current_picture.f.linesize[1] >>= 1; s->current_picture.f.linesize[2] >>= 1; s->linesize >>= 1; s->uvlinesize >>= 1; } av_dlog(s->avctx, "Consumed %i/%i bits\n", get_bits_count(&s->gb), s->gb.size_in_bits); // if (get_bits_count(&s->gb) > buf_size * 8) // return -1; ff_er_frame_end(s); } ff_MPV_frame_end(s); if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { image: avctx->width = avctx->coded_width = v->output_width; avctx->height = avctx->coded_height = v->output_height; if (avctx->skip_frame >= AVDISCARD_NONREF) goto end; #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER if (vc1_decode_sprites(v, &s->gb)) goto err; #endif *pict = v->sprite_output_frame; *data_size = sizeof(AVFrame); } else { if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { *pict = s->current_picture_ptr->f; } else if (s->last_picture_ptr != NULL) { *pict = s->last_picture_ptr->f; } if (s->last_picture_ptr || s->low_delay) { *data_size = sizeof(AVFrame); ff_print_debug_info(s, pict); } } end: av_free(buf2); for (i = 0; i < n_slices; i++) av_free(slices[i].buf); av_free(slices); return buf_size; err: av_free(buf2); for (i = 0; i < n_slices; i++) av_free(slices[i].buf); av_free(slices); return -1; }
true
FFmpeg
6f8ef5320f4d435803482ed322f3de45e6ea125c
24,889
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MpegEncContext *s = avctx->priv_data; int ret; AVFrame *pict = data; s->flags= avctx->flags; s->flags2= avctx->flags2; /* no supplementary picture */ if (buf_size == 0) { /* special case for last picture */ if (s->low_delay==0 && s->next_picture_ptr) { if ((ret = av_frame_ref(pict, &s->next_picture_ptr->f)) < 0) return ret; s->next_picture_ptr= NULL; *got_frame = 1; } return 0; } if(s->flags&CODEC_FLAG_TRUNCATED){ int next; if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4){ next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size); }else if(CONFIG_H263_DECODER && s->codec_id==AV_CODEC_ID_H263){ next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size); }else if(CONFIG_H263P_DECODER && s->codec_id==AV_CODEC_ID_H263P){ next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size); }else{ av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n"); return AVERROR(EINVAL); } if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; } retry: if(s->divx_packed && s->bitstream_buffer_size){ int i; for(i=0; i<buf_size-3; i++){ if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1){ if(buf[i+3]==0xB0){ av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n"); s->bitstream_buffer_size=0; } break; } } } if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8); }else init_get_bits(&s->gb, buf, buf_size*8); s->bitstream_buffer_size=0; if (!s->context_initialized) { if ((ret = ff_MPV_common_init(s)) < 0) //we need the idct permutaton for reading a custom matrix return ret; } /* We need to set current_picture_ptr before reading the header, * otherwise we cannot store anyting in there */ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { int i= ff_find_unused_picture(s, 0); if (i < 0) return i; s->current_picture_ptr= &s->picture[i]; } /* let's go :-) */ if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) { ret= ff_wmv2_decode_picture_header(s); } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) { ret = ff_msmpeg4_decode_picture_header(s); } else if (CONFIG_MPEG4_DECODER && s->h263_pred) { if(s->avctx->extradata_size && s->picture_number==0){ GetBitContext gb; init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8); ret = ff_mpeg4_decode_picture_header(s, &gb); } ret = ff_mpeg4_decode_picture_header(s, &s->gb); } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) { ret = ff_intel_h263_decode_picture_header(s); } else if (CONFIG_FLV_DECODER && s->h263_flv) { ret = ff_flv_decode_picture_header(s); } else { ret = ff_h263_decode_picture_header(s); } if (ret < 0 || ret==FRAME_SKIPPED) { if ( s->width != avctx->coded_width || s->height != avctx->coded_height) { av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); s->width = avctx->coded_width; s->height= avctx->coded_height; } } if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size); /* skip if the header was thrashed */ if (ret < 0){ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); return ret; } avctx->has_b_frames= !s->low_delay; if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ if(s->stream_codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") || s->codec_tag == AV_RL32("RMP4") || s->codec_tag == AV_RL32("ZMP4") || s->codec_tag == AV_RL32("SIPP") ) s->xvid_build= 0; #if 0 if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1 && s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc s->xvid_build= 0; #endif } if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0) s->divx_version= 400; //divx 4 } if(s->xvid_build>=0 && s->divx_version>=0){ s->divx_version= s->divx_build= -1; } if(s->workaround_bugs&FF_BUG_AUTODETECT){ if(s->codec_tag == AV_RL32("XVIX")) s->workaround_bugs|= FF_BUG_XVID_ILACE; if(s->codec_tag == AV_RL32("UMP4")){ s->workaround_bugs|= FF_BUG_UMP4; } if(s->divx_version>=500 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA; } if(s->divx_version>502 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA2; } if(s->xvid_build<=3U) s->padding_bug_score= 256*256*256*64; if(s->xvid_build<=1U) s->workaround_bugs|= FF_BUG_QPEL_CHROMA; if(s->xvid_build<=12U) s->workaround_bugs|= FF_BUG_EDGE; if(s->xvid_build<=32U) s->workaround_bugs|= FF_BUG_DC_CLIP; #define SET_QPEL_FUNC(postfix1, postfix2) \ s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\ s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\ s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2; if(s->lavc_build<4653U) s->workaround_bugs|= FF_BUG_STD_QPEL; if(s->lavc_build<4655U) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; if(s->lavc_build<4670U){ s->workaround_bugs|= FF_BUG_EDGE; } if(s->lavc_build<=4712U) s->workaround_bugs|= FF_BUG_DC_CLIP; if(s->divx_version>=0) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; if(s->divx_version==501 && s->divx_build==20020416) s->padding_bug_score= 256*256*256*64; if(s->divx_version<500U){ s->workaround_bugs|= FF_BUG_EDGE; } if(s->divx_version>=0) s->workaround_bugs|= FF_BUG_HPEL_CHROMA; #if 0 if(s->divx_version==500) s->padding_bug_score= 256*256*256*64; /* very ugly XVID padding bug detection FIXME/XXX solve this differently * Let us hope this at least works. */ if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1 && s->codec_id==AV_CODEC_ID_MPEG4 && s->vo_type==0) s->workaround_bugs|= FF_BUG_NO_PADDING; if(s->lavc_build<4609U) //FIXME not sure about the version num but a 4609 file seems ok s->workaround_bugs|= FF_BUG_NO_PADDING; #endif } if(s->workaround_bugs& FF_BUG_STD_QPEL){ SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c) } if(avctx->debug & FF_DEBUG_BUGS) av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build, s->divx_packed ? "p" : ""); #if HAVE_MMX if (s->codec_id == AV_CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) { avctx->idct_algo= FF_IDCT_XVIDMMX; ff_dct_common_init(s); goto retry; } #endif /* After H263 & mpeg4 header decode we have the height, width,*/ /* and other parameters. So then we could init the picture */ /* FIXME: By the way H263 decoder is evolving it should have */ /* an H263EncContext */ if (s->width != avctx->coded_width || s->height != avctx->coded_height || s->context_reinit) { /* H.263 could change picture size any time */ s->context_reinit = 0; avcodec_set_dimensions(avctx, s->width, s->height); if ((ret = ff_MPV_common_frame_size_change(s))) return ret; } if((s->codec_id==AV_CODEC_ID_H263 || s->codec_id==AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_H263I)) s->gob_index = ff_h263_get_gob_height(s); // for skipping the frame s->current_picture.f.pict_type = s->pict_type; s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; /* skip B-frames if we don't have reference frames */ if (s->last_picture_ptr == NULL && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) return get_consumed_bytes(s, buf_size); if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) return get_consumed_bytes(s, buf_size); if(s->next_p_frame_damaged){ if(s->pict_type==AV_PICTURE_TYPE_B) return get_consumed_bytes(s, buf_size); else s->next_p_frame_damaged=0; } if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ s->me.qpel_put= s->dsp.put_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; }else{ s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; } if ((ret = ff_MPV_frame_start(s, avctx)) < 0) return ret; if (!s->divx_packed && !avctx->hwaccel) ff_thread_finish_setup(avctx); if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) { ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer); goto frame_end; } if (avctx->hwaccel) { if ((ret = avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer)) < 0) return ret; } ff_mpeg_er_frame_start(s); //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type //which is not available before ff_MPV_frame_start() if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){ ret = ff_wmv2_decode_secondary_picture_header(s); if(ret<0) return ret; if(ret==1) goto frame_end; } /* decode each macroblock */ s->mb_x=0; s->mb_y=0; ret = decode_slice(s); while(s->mb_y<s->mb_height){ if(s->msmpeg4_version){ if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_left(&s->gb)<0) break; }else{ int prev_x=s->mb_x, prev_y=s->mb_y; if(ff_h263_resync(s)<0) break; if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x) s->er.error_occurred = 1; } if(s->msmpeg4_version<4 && s->h263_pred) ff_mpeg4_clean_buffers(s); if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA; } if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, buf_size) < 0){ s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR; } av_assert1(s->bitstream_buffer_size==0); frame_end: ff_er_frame_end(&s->er); if (avctx->hwaccel) { if ((ret = avctx->hwaccel->end_frame(avctx)) < 0) return ret; } ff_MPV_frame_end(s); /* divx 5.01+ bitstream reorder stuff */ /* Since this clobbers the input buffer and hwaccel codecs still need the * data during hwaccel->end_frame we should not do this any earlier */ if(s->codec_id==AV_CODEC_ID_MPEG4 && s->divx_packed){ int current_pos= s->gb.buffer == s->bitstream_buffer ? 0 : (get_bits_count(&s->gb)>>3); int startcode_found=0; if(buf_size - current_pos > 7){ int i; for(i=current_pos; i<buf_size-4; i++){ if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){ startcode_found=!(buf[i+4]&0x40); break; } } } if(startcode_found){ av_fast_malloc( &s->bitstream_buffer, &s->allocated_bitstream_buffer_size, buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE); if (!s->bitstream_buffer) return AVERROR(ENOMEM); memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos); s->bitstream_buffer_size= buf_size - current_pos; } } if (!s->divx_packed && avctx->hwaccel) ff_thread_finish_setup(avctx); av_assert1(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); av_assert1(s->current_picture.f.pict_type == s->pict_type); if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0) return ret; ff_print_debug_info(s, s->current_picture_ptr, pict); ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_QSCALE_TYPE_MPEG1); } else if (s->last_picture_ptr != NULL) { if ((ret = av_frame_ref(pict, &s->last_picture_ptr->f)) < 0) return ret; ff_print_debug_info(s, s->last_picture_ptr, pict); ff_mpv_export_qp_table(s, pict, s->last_picture_ptr, FF_QSCALE_TYPE_MPEG1); } if(s->last_picture_ptr || s->low_delay){ if ( pict->format == AV_PIX_FMT_YUV420P && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) { int x, y, p; av_frame_make_writable(pict); for (p=0; p<3; p++) { int w = FF_CEIL_RSHIFT(pict-> width, !!p); int h = FF_CEIL_RSHIFT(pict->height, !!p); int linesize = pict->linesize[p]; for (y=0; y<(h>>1); y++) for (x=0; x<w; x++) FFSWAP(int, pict->data[p][x + y*linesize], pict->data[p][x + (h-1-y)*linesize]); } } *got_frame = 1; } return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size); }
true
FFmpeg
d47e14b53a3908e5bad82e22129bbd175b49e89b
24,890
void avcodec_free_context(AVCodecContext **pavctx) { AVCodecContext *avctx = *pavctx; if (!avctx) return; avcodec_close(avctx); av_freep(&avctx->extradata); av_freep(&avctx->subtitle_header); av_freep(pavctx); }
true
FFmpeg
345cfd04d093d9fdec81ea3531e73b1f5c1b6a6c