static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data, int jobnr, int threadnr) { VP56Context *s0 = avctx->priv_data; int is_alpha = (jobnr == 1); VP56Context *s = is_alpha ? s0->alpha_context : s0; AVFrame *const p = s->frames[VP56_FRAME_CURRENT]; int mb_row, mb_col, mb_row_flip, mb_offset = 0; int block, y, uv; ptrdiff_t stride_y, stride_uv; int res; int damaged = 0; if (p->key_frame) { p->pict_type = AV_PICTURE_TYPE_I; s->default_models_init(s); for (block=0; block<s->mb_height*s->mb_width; block++) s->macroblocks[block].type = VP56_MB_INTRA; } else { p->pict_type = AV_PICTURE_TYPE_P; vp56_parse_mb_type_models(s); s->parse_vector_models(s); s->mb_type = VP56_MB_INTER_NOVEC_PF; } if (s->parse_coeff_models(s)) goto next; memset(s->prev_dc, 0, sizeof(s->prev_dc)); s->prev_dc[1][VP56_FRAME_CURRENT] = 128; s->prev_dc[2][VP56_FRAME_CURRENT] = 128; for (block=0; block < 4*s->mb_width+6; block++) { s->above_blocks[block].ref_frame = VP56_FRAME_NONE; s->above_blocks[block].dc_coeff = 0; s->above_blocks[block].not_null_dc = 0; } s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT; s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT; stride_y = p->linesize[0]; stride_uv = p->linesize[1]; if (s->flip < 0) mb_offset = 7; /* main macroblocks loop */ for (mb_row=0; mb_row<s->mb_height; mb_row++) { if (s->flip < 0) mb_row_flip = s->mb_height - mb_row - 1; else mb_row_flip = mb_row; for (block=0; block<4; block++) { s->left_block[block].ref_frame = VP56_FRAME_NONE; s->left_block[block].dc_coeff = 0; s->left_block[block].not_null_dc = 0; } memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx)); memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last)); s->above_block_idx[0] = 1; s->above_block_idx[1] = 2; s->above_block_idx[2] = 1; s->above_block_idx[3] = 2; s->above_block_idx[4] = 2*s->mb_width + 2 + 1; s->above_block_idx[5] = 3*s->mb_width + 4 + 1; s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y; s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y; s->block_offset[1] = s->block_offset[0] + 8; s->block_offset[3] = s->block_offset[2] + 8; s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv; s->block_offset[5] = s->block_offset[4]; for (mb_col=0; mb_col<s->mb_width; mb_col++) { if (!damaged) { int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha); if (ret < 0) damaged = 1; } if (damaged) vp56_conceal_mb(s, mb_row, mb_col, is_alpha); for (y=0; y<4; y++) { s->above_block_idx[y] += 2; s->block_offset[y] += 16; } for (uv=4; uv<6; uv++) { s->above_block_idx[uv] += 1; s->block_offset[uv] += 8; } } } next: if (p->key_frame || s->golden_frame) { av_frame_unref(s->frames[VP56_FRAME_GOLDEN]); if ((res = av_frame_ref(s->frames[VP56_FRAME_GOLDEN], p)) < 0) return res; } av_frame_unref(s->frames[VP56_FRAME_PREVIOUS]); FFSWAP(AVFrame *, s->frames[VP56_FRAME_CURRENT], s->frames[VP56_FRAME_PREVIOUS]); return 0; }


static void pci_config(void) { QVirtioPCIDevice *dev; QOSState *qs; int n_size = TEST_IMAGE_SIZE / 2; uint64_t capacity; qs = pci_test_start(); dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); capacity = qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); qvirtio_set_driver_ok(&dev->vdev); qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US); capacity = qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, ==, n_size / 512); qvirtio_pci_device_disable(dev); g_free(dev); qtest_shutdown(qs); }


static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir) { AlphaExtractContext *extract = inlink->dst->priv; AVFilterBufferRef *cur_buf = inlink->cur_buf; AVFilterBufferRef *out_buf = inlink->dst->outputs[0]->out_buf; if (extract->is_packed_rgb) { int x, y; uint8_t *pin, *pout; for (y = y0; y < (y0 + h); y++) { pin = cur_buf->data[0] + y * cur_buf->linesize[0] + extract->rgba_map[A]; pout = out_buf->data[0] + y * out_buf->linesize[0]; for (x = 0; x < out_buf->video->w; x++) { *pout = *pin; pout += 1; pin += 4; } } } else if (cur_buf->linesize[A] == out_buf->linesize[Y]) { const int linesize = cur_buf->linesize[A]; memcpy(out_buf->data[Y] + y0 * linesize, cur_buf->data[A] + y0 * linesize, linesize * h); } else { const int linesize = FFMIN(out_buf->linesize[Y], cur_buf->linesize[A]); int y; for (y = y0; y < (y0 + h); y++) { memcpy(out_buf->data[Y] + y * out_buf->linesize[Y], cur_buf->data[A] + y * cur_buf->linesize[A], linesize); } } return ff_draw_slice(inlink->dst->outputs[0], y0, h, slice_dir); }


static int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sad; vector signed int sumdiffs; sad = (vector unsigned int)vec_splat_u32(0); for (i = 0; i < h; i++) { /* Read potentially unaligned pixels into t1 and t2 */ perm1 = vec_lvsl(0, pix1); pix1v = (vector unsigned char *) pix1; perm2 = vec_lvsl(0, pix2); pix2v = (vector unsigned char *) pix2; t1 = vec_perm(pix1v[0], pix1v[1], perm1); t2 = vec_perm(pix2v[0], pix2v[1], perm2); /* Calculate a sum of abs differences vector */ t3 = vec_max(t1, t2); t4 = vec_min(t1, t2); t5 = vec_sub(t3, t4); /* Add each 4 pixel group together and put 4 results into sad */ sad = vec_sum4s(t5, sad); pix1 += line_size; pix2 += line_size; } /* Sum up the four partial sums, and put the result into s */ sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); sumdiffs = vec_splat(sumdiffs, 3); vec_ste(sumdiffs, 0, &s); return s; }


void rgb8tobgr8(const uint8_t *src, uint8_t *dst, unsigned int src_size) { unsigned i; unsigned num_pixels = src_size; for(i=0; i<num_pixels; i++) { unsigned b,g,r; register uint8_t rgb; rgb = src[i]; r = (rgb&0x07); g = (rgb&0x38)>>3; b = (rgb&0xC0)>>6; dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); } }


static int net_vde_init(VLANState *vlan, const char *model, const char *name, const char *sock, int port, const char *group, int mode) { VDEState *s; char *init_group = strlen(group) ? (char *)group : NULL; char *init_sock = strlen(sock) ? (char *)sock : NULL; struct vde_open_args args = { .port = port, .group = init_group, .mode = mode, }; s = qemu_mallocz(sizeof(VDEState)); s->vde = vde_open(init_sock, "QEMU", &args); if (!s->vde){ free(s); return -1; } s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s); qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", sock, vde_datafd(s->vde)); return 0; }


static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){ GetBitContext *gb=&vc->gb; uint_fast8_t i, j, k; vc->residue_count=get_bits(gb, 6)+1; vc->residues=av_mallocz(vc->residue_count * sizeof(vorbis_residue)); AV_DEBUG(" There are %d residues. \n", vc->residue_count); for(i=0;i<vc->residue_count;++i) { vorbis_residue *res_setup=&vc->residues[i]; uint_fast8_t cascade[64]; uint_fast8_t high_bits; uint_fast8_t low_bits; res_setup->type=get_bits(gb, 16); AV_DEBUG(" %d. residue type %d \n", i, res_setup->type); res_setup->begin=get_bits(gb, 24); res_setup->end=get_bits(gb, 24); res_setup->partition_size=get_bits(gb, 24)+1; res_setup->classifications=get_bits(gb, 6)+1; res_setup->classbook=get_bits(gb, 8); if (res_setup->classbook>=vc->codebook_count) { av_log(vc->avccontext, AV_LOG_ERROR, "classbook value %d out of range. \n", res_setup->classbook); AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, res_setup->classifications, res_setup->classbook); for(j=0;j<res_setup->classifications;++j) { high_bits=0; low_bits=get_bits(gb, 3); if (get_bits1(gb)) { high_bits=get_bits(gb, 5); cascade[j]=(high_bits<<3)+low_bits; AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j])); res_setup->maxpass=0; for(j=0;j<res_setup->classifications;++j) { for(k=0;k<8;++k) { if (cascade[j]&(1<<k)) { int bits=get_bits(gb, 8); if (bits>=vc->codebook_count) { av_log(vc->avccontext, AV_LOG_ERROR, "book value %d out of range. \n", bits); res_setup->books[j][k]=bits; AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]); if (k>res_setup->maxpass) { res_setup->maxpass=k; } else { res_setup->books[j][k]=-1; return 0;


static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt, GetBitContext *gb, int block_size, int width, int height, int x_pos, int y_pos, int blk_idx) { struct FlashSVContext *s = avctx->priv_data; uint8_t *line = s->tmpblock; int k; int ret = inflateReset(&s->zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_UNKNOWN; } if (s->zlibprime_curr || s->zlibprime_prev) { ret = flashsv2_prime(s, s->blocks[blk_idx].pos, s->blocks[blk_idx].size); if (ret < 0) return ret; } s->zstream.next_in = avpkt->data + get_bits_count(gb) / 8; s->zstream.avail_in = block_size; s->zstream.next_out = s->tmpblock; s->zstream.avail_out = s->block_size * 3; ret = inflate(&s->zstream, Z_FINISH); if (ret == Z_DATA_ERROR) { av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n"); inflateSync(&s->zstream); ret = inflate(&s->zstream, Z_FINISH); } if (ret != Z_OK && ret != Z_STREAM_END) { //return -1; } if (s->is_keyframe) { s->blocks[blk_idx].pos = s->keyframedata + (get_bits_count(gb) / 8); s->blocks[blk_idx].size = block_size; } y_pos += s->diff_start; if (!s->color_depth) { /* Flash Screen Video stores the image upside down, so copy * lines to destination in reverse order. */ for (k = 1; k <= s->diff_height; k++) { memcpy(s->frame->data[0] + x_pos * 3 + (s->image_height - y_pos - k) * s->frame->linesize[0], line, width * 3); /* advance source pointer to next line */ line += width * 3; } } else { /* hybrid 15-bit/palette mode */ decode_hybrid(s->tmpblock, s->frame->data[0], s->image_height - (y_pos + 1 + s->diff_height), x_pos, s->diff_height, width, s->frame->linesize[0], s->pal); } skip_bits_long(gb, 8 * block_size); /* skip the consumed bits */ return 0; }


void breakpoint_handler(CPUX86State *env) { CPUBreakpoint *bp; if (env->watchpoint_hit) { if (env->watchpoint_hit->flags & BP_CPU) { env->watchpoint_hit = NULL; if (check_hw_breakpoints(env, 0)) raise_exception(env, EXCP01_DB); else cpu_resume_from_signal(env, NULL); } } else { QTAILQ_FOREACH(bp, &env->breakpoints, entry) if (bp->pc == env->eip) { if (bp->flags & BP_CPU) { check_hw_breakpoints(env, 1); raise_exception(env, EXCP01_DB); } break; } } }


static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset) { m5206_mbar_state *s = (m5206_mbar_state *)opaque; int width; offset &= 0x3ff; if (offset > 0x200) { hw_error("Bad MBAR read offset 0x%x", (int)offset); } width = m5206_mbar_width[offset >> 2]; if (width < 4) { uint32_t val; val = m5206_mbar_readw(opaque, offset) << 16; val |= m5206_mbar_readw(opaque, offset + 2); return val; } return m5206_mbar_read(s, offset, 4); }


static void test_qemu_strtoul_empty(void) { const char *str = ""; char f = 'X'; const char *endptr = &f; unsigned long res = 999; int err; err = qemu_strtoul(str, &endptr, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, 0); g_assert(endptr == str); }


static void lm32_cpu_class_init(ObjectClass *oc, void *data) { LM32CPUClass *lcc = LM32_CPU_CLASS(oc); CPUClass *cc = CPU_CLASS(oc); DeviceClass *dc = DEVICE_CLASS(oc); lcc->parent_realize = dc->realize; dc->realize = lm32_cpu_realizefn; lcc->parent_reset = cc->reset; cc->reset = lm32_cpu_reset; cc->class_by_name = lm32_cpu_class_by_name; cc->has_work = lm32_cpu_has_work; cc->do_interrupt = lm32_cpu_do_interrupt; cc->cpu_exec_interrupt = lm32_cpu_exec_interrupt; cc->dump_state = lm32_cpu_dump_state; cc->set_pc = lm32_cpu_set_pc; cc->gdb_read_register = lm32_cpu_gdb_read_register; cc->gdb_write_register = lm32_cpu_gdb_write_register; #ifdef CONFIG_USER_ONLY cc->handle_mmu_fault = lm32_cpu_handle_mmu_fault; #else cc->get_phys_page_debug = lm32_cpu_get_phys_page_debug; cc->vmsd = &vmstate_lm32_cpu; #endif cc->gdb_num_core_regs = 32 + 7; cc->gdb_stop_before_watchpoint = true; cc->debug_excp_handler = lm32_debug_excp_handler; }


static void vnc_copy(VncState *vs, int src_x, int src_y, int dst_x, int dst_y, int w, int h) { /* send bitblit op to the vnc client */ vnc_lock_output(vs); vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE); vnc_write_u8(vs, 0); vnc_write_u16(vs, 1); /* number of rects */ vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT); vnc_write_u16(vs, src_x); vnc_write_u16(vs, src_y); vnc_unlock_output(vs); vnc_flush(vs); }


static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int chroma, int chroma444, int dir) { MpegEncContext * const s = &h->s; int edge; int chroma_qp_avg[2]; const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; const int mbm_type = dir == 0 ? h->left_type[LTOP] : h->top_type; // how often to recheck mv-based bS when iterating between edges static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, {0,3,1,1,3,3,3,3}}; const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7]; const int edges = mask_edge== 3 && !(h->cbp&15) ? 1 : 4; // how often to recheck mv-based bS when iterating along each edge const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)); if(mbm_type && !first_vertical_edge_done){ if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) && IS_INTERLACED(mbm_type&~mb_type) ) { // This is a special case in the norm where the filtering must // be done twice (one each of the field) even if we are in a // frame macroblock. // unsigned int tmp_linesize = 2 * linesize; unsigned int tmp_uvlinesize = 2 * uvlinesize; int mbn_xy = mb_xy - 2 * s->mb_stride; int j; for(j=0; j<2; j++, mbn_xy += s->mb_stride){ DECLARE_ALIGNED(8, int16_t, bS)[4]; int qp; if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) { AV_WN64A(bS, 0x0003000300030003ULL); } else { if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) { bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]); bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]); bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]); bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+3]); }else{ const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4; int i; for( i = 0; i < 4; i++ ) { bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); } } } // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1; tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, h ); chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; if (chroma) { if (chroma444) { filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], h); } else { filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], h); } } } }else{ DECLARE_ALIGNED(8, int16_t, bS)[4]; int qp; if( IS_INTRA(mb_type|mbm_type)) { AV_WN64A(bS, 0x0003000300030003ULL); if ( (!IS_INTERLACED(mb_type|mbm_type)) || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) ) AV_WN64A(bS, 0x0004000400040004ULL); } else { int i; int mv_done; if( dir && FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbm_type)) { AV_WN64A(bS, 0x0001000100010001ULL); mv_done = 1; } else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) { int b_idx= 8 + 4; int bn_idx= b_idx - (dir ? 8:1); bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, 8 + 4, bn_idx, mvy_limit); mv_done = 1; } else mv_done = 0; for( i = 0; i < 4; i++ ) { int x = dir == 0 ? 0 : i; int y = dir == 0 ? i : 0; int b_idx= 8 + 4 + x + 8*y; int bn_idx= b_idx - (dir ? 8:1); if( h->non_zero_count_cache[b_idx] | h->non_zero_count_cache[bn_idx] ) { bS[i] = 2; } else if(!mv_done) { bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit); } } } /* Filter edge */ // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. if(bS[0]+bS[1]+bS[2]+bS[3]){ qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1; //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; if( dir == 0 ) { filter_mb_edgev( &img_y[0], linesize, bS, qp, h ); if (chroma) { if (chroma444) { filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h); } else { filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h); } } } else { filter_mb_edgeh( &img_y[0], linesize, bS, qp, h ); if (chroma) { if (chroma444) { filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h); } else { filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h); filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h); } } } } } } /* Calculate bS */ for( edge = 1; edge < edges; edge++ ) { DECLARE_ALIGNED(8, int16_t, bS)[4]; int qp; if( IS_8x8DCT(mb_type & (edge<<24)) ) // (edge&1) && IS_8x8DCT(mb_type) continue; if( IS_INTRA(mb_type)) { AV_WN64A(bS, 0x0003000300030003ULL); } else { int i; int mv_done; if( edge & mask_edge ) { AV_ZERO64(bS); mv_done = 1; } else if( mask_par0 ) { int b_idx= 8 + 4 + edge * (dir ? 8:1); int bn_idx= b_idx - (dir ? 8:1); bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, b_idx, bn_idx, mvy_limit); mv_done = 1; } else mv_done = 0; for( i = 0; i < 4; i++ ) { int x = dir == 0 ? edge : i; int y = dir == 0 ? i : edge; int b_idx= 8 + 4 + x + 8*y; int bn_idx= b_idx - (dir ? 8:1); if( h->non_zero_count_cache[b_idx] | h->non_zero_count_cache[bn_idx] ) { bS[i] = 2; } else if(!mv_done) { bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit); } } if(bS[0]+bS[1]+bS[2]+bS[3] == 0) continue; } /* Filter edge */ // Do not use s->qscale as luma quantizer because it has not the same // value in IPCM macroblocks. qp = s->current_picture.f.qscale_table[mb_xy]; //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } if( dir == 0 ) { filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, h ); if (chroma) { if (chroma444) { filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h); filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h); } else if( (edge&1) == 0 ) { filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h); filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h); } } } else { filter_mb_edgeh( &img_y[4*edge*linesize], linesize, bS, qp, h ); if (chroma) { if (chroma444) { filter_mb_edgeh ( &img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], h); filter_mb_edgeh ( &img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], h); } else if( (edge&1) == 0 ) { filter_mb_edgech( &img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], h); filter_mb_edgech( &img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], h); } } } } }


static int mov_read_close(AVFormatContext *s) { MOVContext *mov = s->priv_data; int i, j; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; av_freep(&sc->ctts_data); for (j = 0; j < sc->drefs_count; j++) { av_freep(&sc->drefs[j].path); av_freep(&sc->drefs[j].dir); } av_freep(&sc->drefs); if (sc->pb && sc->pb != s->pb) avio_close(sc->pb); av_freep(&sc->chunk_offsets); av_freep(&sc->stsc_data); av_freep(&sc->sample_sizes); av_freep(&sc->keyframes); av_freep(&sc->stts_data); av_freep(&sc->stps_data); av_freep(&sc->rap_group); av_freep(&sc->display_matrix); } if (mov->dv_demux) { avformat_free_context(mov->dv_fctx); mov->dv_fctx = NULL; } av_freep(&mov->trex_data); return 0; }


static int color_request_frame(AVFilterLink *link) { ColorContext *color = link->src->priv; AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); int ret; picref->video->pixel_aspect = (AVRational) {1, 1}; picref->pts = color->pts++; picref->pos = -1; ret = ff_start_frame(link, avfilter_ref_buffer(picref, ~0)); if (ret < 0) goto fail; ff_draw_rectangle(picref->data, picref->linesize, color->line, color->line_step, color->hsub, color->vsub, 0, 0, color->w, color->h); ret = ff_draw_slice(link, 0, color->h, 1); if (ret < 0) goto fail; ret = ff_end_frame(link); fail: avfilter_unref_buffer(picref); return ret; }


static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; MOVStreamContext *sc = st->priv_data; int j, entries, pseudo_stream_id; get_byte(pb); /* version */ get_be24(pb); /* flags */ entries = get_be32(pb); for(pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) { //Parsing Sample description table enum CodecID id; int dref_id; MOV_atom_t a = { 0, 0, 0 }; offset_t start_pos = url_ftell(pb); int size = get_be32(pb); /* size */ uint32_t format = get_le32(pb); /* data format */ get_be32(pb); /* reserved */ get_be16(pb); /* reserved */ dref_id = get_be16(pb); if (st->codec->codec_tag && st->codec->codec_tag != format && (c->fc->video_codec_id ? codec_get_id(codec_movvideo_tags, format) != c->fc->video_codec_id : st->codec->codec_tag != MKTAG('j','p','e','g')) ){ /* Multiple fourcc, we skip JPEG. This is not correct, we should * export it as a separate AVStream but this needs a few changes * in the MOV demuxer, patch welcome. */ av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n"); url_fskip(pb, size - (url_ftell(pb) - start_pos)); continue; } sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id; sc->dref_id= dref_id; st->codec->codec_tag = format; id = codec_get_id(codec_movaudio_tags, format); if (id<=0 && (format&0xFFFF) == 'm'+('s'<<8)) id = codec_get_id(codec_wav_tags, bswap_32(format)&0xFFFF); if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) { st->codec->codec_type = CODEC_TYPE_AUDIO; } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */ format && format != MKTAG('m','p','4','s')) { /* skip old asf mpeg4 tag */ id = codec_get_id(codec_movvideo_tags, format); if (id <= 0) id = codec_get_id(codec_bmp_tags, format); if (id > 0) st->codec->codec_type = CODEC_TYPE_VIDEO; else if(st->codec->codec_type == CODEC_TYPE_DATA){ id = codec_get_id(ff_codec_movsubtitle_tags, format); if(id > 0) st->codec->codec_type = CODEC_TYPE_SUBTITLE; } } dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size, (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, st->codec->codec_type); if(st->codec->codec_type==CODEC_TYPE_VIDEO) { uint8_t codec_name[32]; unsigned int color_depth; int color_greyscale; st->codec->codec_id = id; get_be16(pb); /* version */ get_be16(pb); /* revision level */ get_be32(pb); /* vendor */ get_be32(pb); /* temporal quality */ get_be32(pb); /* spatial quality */ st->codec->width = get_be16(pb); /* width */ st->codec->height = get_be16(pb); /* height */ get_be32(pb); /* horiz resolution */ get_be32(pb); /* vert resolution */ get_be32(pb); /* data size, always 0 */ get_be16(pb); /* frames per samples */ get_buffer(pb, codec_name, 32); /* codec name, pascal string */ if (codec_name[0] <= 31) { memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]); st->codec->codec_name[codec_name[0]] = 0; } st->codec->bits_per_coded_sample = get_be16(pb); /* depth */ st->codec->color_table_id = get_be16(pb); /* colortable id */ dprintf(c->fc, "depth %d, ctab id %d\n", st->codec->bits_per_coded_sample, st->codec->color_table_id); /* figure out the palette situation */ color_depth = st->codec->bits_per_coded_sample & 0x1F; color_greyscale = st->codec->bits_per_coded_sample & 0x20; /* if the depth is 2, 4, or 8 bpp, file is palettized */ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) { /* for palette traversal */ unsigned int color_start, color_count, color_end; unsigned char r, g, b; if (color_greyscale) { int color_index, color_dec; /* compute the greyscale palette */ st->codec->bits_per_coded_sample = color_depth; color_count = 1 << color_depth; color_index = 255; color_dec = 256 / (color_count - 1); for (j = 0; j < color_count; j++) { r = g = b = color_index; c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); color_index -= color_dec; if (color_index < 0) color_index = 0; } } else if (st->codec->color_table_id) { const uint8_t *color_table; /* if flag bit 3 is set, use the default palette */ color_count = 1 << color_depth; if (color_depth == 2) color_table = ff_qt_default_palette_4; else if (color_depth == 4) color_table = ff_qt_default_palette_16; else color_table = ff_qt_default_palette_256; for (j = 0; j < color_count; j++) { r = color_table[j * 4 + 0]; g = color_table[j * 4 + 1]; b = color_table[j * 4 + 2]; c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); } } else { /* load the palette from the file */ color_start = get_be32(pb); color_count = get_be16(pb); color_end = get_be16(pb); if ((color_start <= 255) && (color_end <= 255)) { for (j = color_start; j <= color_end; j++) { /* each R, G, or B component is 16 bits; * only use the top 8 bits; skip alpha bytes * up front */ get_byte(pb); get_byte(pb); r = get_byte(pb); get_byte(pb); g = get_byte(pb); get_byte(pb); b = get_byte(pb); get_byte(pb); c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); } } } st->codec->palctrl = &c->palette_control; st->codec->palctrl->palette_changed = 1; } else st->codec->palctrl = NULL; } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) { int bits_per_sample, flags; uint16_t version = get_be16(pb); st->codec->codec_id = id; get_be16(pb); /* revision level */ get_be32(pb); /* vendor */ st->codec->channels = get_be16(pb); /* channel count */ dprintf(c->fc, "audio channels %d\n", st->codec->channels); st->codec->bits_per_coded_sample = get_be16(pb); /* sample size */ sc->audio_cid = get_be16(pb); get_be16(pb); /* packet size = 0 */ st->codec->sample_rate = ((get_be32(pb) >> 16)); //Read QT version 1 fields. In version 0 these do not exist. dprintf(c->fc, "version =%d, isom =%d\n",version,c->isom); if(!c->isom) { if(version==1) { sc->samples_per_frame = get_be32(pb); get_be32(pb); /* bytes per packet */ sc->bytes_per_frame = get_be32(pb); get_be32(pb); /* bytes per sample */ } else if(version==2) { get_be32(pb); /* sizeof struct only */ st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */ st->codec->channels = get_be32(pb); get_be32(pb); /* always 0x7F000000 */ st->codec->bits_per_coded_sample = get_be32(pb); /* bits per channel if sound is uncompressed */ flags = get_be32(pb); /* lcpm format specific flag */ sc->bytes_per_frame = get_be32(pb); /* bytes per audio packet if constant */ sc->samples_per_frame = get_be32(pb); /* lpcm frames per audio packet if constant */ if (format == MKTAG('l','p','c','m')) st->codec->codec_id = mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); } } switch (st->codec->codec_id) { case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: if (st->codec->bits_per_coded_sample == 16) st->codec->codec_id = CODEC_ID_PCM_S16BE; break; case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: if (st->codec->bits_per_coded_sample == 8) st->codec->codec_id = CODEC_ID_PCM_S8; else if (st->codec->bits_per_coded_sample == 24) st->codec->codec_id = st->codec->codec_id == CODEC_ID_PCM_S16BE ? CODEC_ID_PCM_S24BE : CODEC_ID_PCM_S24LE; break; /* set values for old format before stsd version 1 appeared */ case CODEC_ID_MACE3: sc->samples_per_frame = 6; sc->bytes_per_frame = 2*st->codec->channels; break; case CODEC_ID_MACE6: sc->samples_per_frame = 6; sc->bytes_per_frame = 1*st->codec->channels; break; case CODEC_ID_ADPCM_IMA_QT: sc->samples_per_frame = 64; sc->bytes_per_frame = 34*st->codec->channels; break; case CODEC_ID_GSM: sc->samples_per_frame = 160; sc->bytes_per_frame = 33; break; default: break; } bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); if (bits_per_sample) { st->codec->bits_per_coded_sample = bits_per_sample; sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; } } else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){ st->codec->codec_id= id; } else { /* other codec type, just skip (rtp, mp4s, tmcd ...) */ url_fskip(pb, size - (url_ftell(pb) - start_pos)); } /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ a.size = size - (url_ftell(pb) - start_pos); if (a.size > 8) { if (mov_read_default(c, pb, a) < 0) return -1; } else if (a.size > 0) url_fskip(pb, a.size); } if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) st->codec->sample_rate= sc->time_scale; /* special codec parameters handling */ switch (st->codec->codec_id) { #ifdef CONFIG_DV_DEMUXER case CODEC_ID_DVAUDIO: c->dv_fctx = av_alloc_format_context(); c->dv_demux = dv_init_demux(c->dv_fctx); if (!c->dv_demux) { av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); return -1; } sc->dv_audio_container = 1; st->codec->codec_id = CODEC_ID_PCM_S16LE; break; #endif /* no ifdef since parameters are always those */ case CODEC_ID_AMR_WB: st->codec->sample_rate= 16000; st->codec->channels= 1; /* really needed */ break; case CODEC_ID_QCELP: case CODEC_ID_AMR_NB: st->codec->frame_size= sc->samples_per_frame; st->codec->sample_rate= 8000; st->codec->channels= 1; /* really needed */ break; case CODEC_ID_MP2: case CODEC_ID_MP3: st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ st->need_parsing = AVSTREAM_PARSE_FULL; break; case CODEC_ID_GSM: case CODEC_ID_ADPCM_MS: case CODEC_ID_ADPCM_IMA_WAV: st->codec->block_align = sc->bytes_per_frame; break; case CODEC_ID_ALAC: if (st->codec->extradata_size == 36) st->codec->frame_size = AV_RB32((st->codec->extradata+12)); break; default: break; } return 0; }


void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size) { HEVCLocalContext *lc = &s->HEVClc; MvField *tab_mvf = s->ref->tab_mvf; int log2_min_pu_size = s->sps->log2_min_pu_size; int log2_min_tu_size = s->sps->log2_min_tb_size; int min_pu_width = s->sps->min_pu_width; int min_tu_width = s->sps->min_tb_width; int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width + (x0 >> log2_min_pu_size)].is_intra; int i, j, bs; if (y0 > 0 && (y0 & 7) == 0) { int yp_pu = (y0 - 1) >> log2_min_pu_size; int yq_pu = y0 >> log2_min_pu_size; int yp_tu = (y0 - 1) >> log2_min_tu_size; int yq_tu = y0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 - 1); bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 1); if (!s->sh.slice_loop_filter_across_slices_enabled_flag && lc->boundary_flags & BOUNDARY_UPPER_SLICE && (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; else if (!s->pps->loop_filter_across_tiles_enabled_flag && lc->boundary_flags & BOUNDARY_UPPER_TILE && (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (bs) s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs; } } // bs for TU internal horizontal PU boundaries if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra) for (j = 8; j < (1 << log2_trafo_size); j += 8) { int yp_pu = (y0 + j - 1) >> log2_min_pu_size; int yq_pu = (y0 + j) >> log2_min_pu_size; int yp_tu = (y0 + j - 1) >> log2_min_tu_size; int yq_tu = (y0 + j) >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 + j - 1); bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 0); if (bs) s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs; } } // bs for vertical TU boundaries if (x0 > 0 && (x0 & 7) == 0) { int xp_pu = (x0 - 1) >> log2_min_pu_size; int xq_pu = x0 >> log2_min_pu_size; int xp_tu = (x0 - 1) >> log2_min_tu_size; int xq_tu = x0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int y_pu = (y0 + i) >> log2_min_pu_size; int y_tu = (y0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 - 1, y0 + i); bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 1); if (!s->sh.slice_loop_filter_across_slices_enabled_flag && lc->boundary_flags & BOUNDARY_LEFT_SLICE && (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; else if (!s->pps->loop_filter_across_tiles_enabled_flag && lc->boundary_flags & BOUNDARY_LEFT_TILE && (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (bs) s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs; } } // bs for TU internal vertical PU boundaries if (log2_trafo_size > log2_min_pu_size && !is_intra) for (j = 0; j < (1 << log2_trafo_size); j += 4) { int y_pu = (y0 + j) >> log2_min_pu_size; int y_tu = (y0 + j) >> log2_min_tu_size; for (i = 8; i < (1 << log2_trafo_size); i += 8) { int xp_pu = (x0 + i - 1) >> log2_min_pu_size; int xq_pu = (x0 + i) >> log2_min_pu_size; int xp_tu = (x0 + i - 1) >> log2_min_tu_size; int xq_tu = (x0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i - 1, y0 + j); bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 0); if (bs) s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs; } } }


int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs) { int j; fs->plane_count = f->plane_count; fs->transparency = f->transparency; for (j = 0; j < f->plane_count; j++) { PlaneContext *const p = &fs->plane[j]; if (fs->ac) { if (!p->state) p->state = av_malloc(CONTEXT_SIZE * p->context_count * sizeof(uint8_t)); if (!p->state) return AVERROR(ENOMEM); } else { if (!p->vlc_state) p->vlc_state = av_malloc(p->context_count * sizeof(VlcState)); if (!p->vlc_state) return AVERROR(ENOMEM); } } if (fs->ac > 1) { //FIXME only redo if state_transition changed for (j = 1; j < 256; j++) { fs->c.one_state[j] = f->state_transition[j]; fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j]; } } return 0; }


static int vdpau_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { VC1Context * const v = avctx->priv_data; MpegEncContext * const s = &v->s; Picture *pic = s->current_picture_ptr; struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; VdpPictureInfoVC1 *info = &pic_ctx->info.vc1; VdpVideoSurface ref; /* fill LvPictureInfoVC1 struct */ info->forward_reference = VDP_INVALID_HANDLE; info->backward_reference = VDP_INVALID_HANDLE; switch (s->pict_type) { case AV_PICTURE_TYPE_B: ref = ff_vdpau_get_surface_id(&s->next_picture.f); assert(ref != VDP_INVALID_HANDLE); info->backward_reference = ref; /* fall-through */ case AV_PICTURE_TYPE_P: ref = ff_vdpau_get_surface_id(&s->last_picture.f); assert(ref != VDP_INVALID_HANDLE); info->forward_reference = ref; } info->slice_count = 0; if (v->bi_type) info->picture_type = 4; else info->picture_type = s->pict_type - 1 + s->pict_type / 3; info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0; info->postprocflag = v->postprocflag; info->pulldown = v->broadcast; info->interlace = v->interlace; info->tfcntrflag = v->tfcntrflag; info->finterpflag = v->finterpflag; info->psf = v->psf; info->dquant = v->dquant; info->panscan_flag = v->panscanflag; info->refdist_flag = v->refdist_flag; info->quantizer = v->quantizer_mode; info->extended_mv = v->extended_mv; info->extended_dmv = v->extended_dmv; info->overlap = v->overlap; info->vstransform = v->vstransform; info->loopfilter = v->s.loop_filter; info->fastuvmc = v->fastuvmc; info->range_mapy_flag = v->range_mapy_flag; info->range_mapy = v->range_mapy; info->range_mapuv_flag = v->range_mapuv_flag; info->range_mapuv = v->range_mapuv; /* Specific to simple/main profile only */ info->multires = v->multires; info->syncmarker = v->resync_marker; info->rangered = v->rangered | (v->rangeredfrm << 1); info->maxbframes = v->s.max_b_frames; info->deblockEnable = v->postprocflag & 1; info->pquant = v->pq; return ff_vdpau_common_start_frame(pic_ctx, buffer, size); }


static int cinvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; CinVideoContext *cin = avctx->priv_data; int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size; cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (avctx->reget_buffer(avctx, &cin->frame)) { av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n"); return -1; } palette_type = buf[0]; palette_colors_count = AV_RL16(buf+1); bitmap_frame_type = buf[3]; buf += 4; bitmap_frame_size = buf_size - 4; /* handle palette */ if (palette_type == 0) { for (i = 0; i < palette_colors_count; ++i) { cin->palette[i] = bytestream_get_le24(&buf); bitmap_frame_size -= 3; } } else { for (i = 0; i < palette_colors_count; ++i) { cin->palette[buf[0]] = AV_RL24(buf+1); buf += 4; bitmap_frame_size -= 4; } } memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette)); cin->frame.palette_has_changed = 1; /* note: the decoding routines below assumes that surface.width = surface.pitch */ switch (bitmap_frame_type) { case 9: cin_decode_rle(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 34: cin_decode_rle(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 35: cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 36: bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 37: cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 38: cin_decode_lzss(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 39: cin_decode_lzss(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; } for (y = 0; y < cin->avctx->height; ++y) memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0], cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width, cin->avctx->width); FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]); *data_size = sizeof(AVFrame); *(AVFrame *)data = cin->frame; return buf_size; }


static void RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3]) { int x, y, p; TYPE *sample[4][2]; int lbd = s->avctx->bits_per_raw_sample <= 8; int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; int offset = 1 << bits; for (x = 0; x < 4; x++) { sample[x][0] = RENAME(s->sample_buffer) + x * 2 * (w + 6) + 3; sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; } s->run_index = 0; memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer))); for (y = 0; y < h; y++) { for (p = 0; p < 3 + s->transparency; p++) { TYPE *temp = sample[p][0]; // FIXME: try a normal buffer sample[p][0] = sample[p][1]; sample[p][1] = temp; sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && s->slice_coding_mode == 0) RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9); else RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); } for (x = 0; x < w; x++) { int g = sample[0][1][x]; int b = sample[1][1][x]; int r = sample[2][1][x]; int a = sample[3][1][x]; if (s->slice_coding_mode != 1) { b -= offset; r -= offset; g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2; b += g; r += g; } if (lbd) *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + (g<<8) + (r<<16) + (a<<24); else if (sizeof(TYPE) == 4) { *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g; *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b; *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; } else { *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b; *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g; *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; } } } }


QPEL_H264(put_, PUT_OP, mmxext) QPEL_H264(avg_, AVG_MMXEXT_OP, mmxext) QPEL_H264_V_XMM(put_, PUT_OP, sse2) QPEL_H264_V_XMM(avg_,AVG_MMXEXT_OP, sse2) QPEL_H264_HV_XMM(put_, PUT_OP, sse2) QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, sse2) QPEL_H264_H_XMM(put_, PUT_OP, ssse3) QPEL_H264_H_XMM(avg_,AVG_MMXEXT_OP, ssse3) QPEL_H264_HV_XMM(put_, PUT_OP, ssse3) QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, ssse3) #undef PAVGB H264_MC_4816(mmxext) H264_MC_816(H264_MC_V, sse2) H264_MC_816(H264_MC_HV, sse2) H264_MC_816(H264_MC_H, ssse3) H264_MC_816(H264_MC_HV, ssse3) //10bit #define LUMA_MC_OP(OP, NUM, DEPTH, TYPE, OPT) \ void ff_ ## OP ## _h264_qpel ## NUM ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT \ (uint8_t *dst, uint8_t *src, int stride); #define LUMA_MC_ALL(DEPTH, TYPE, OPT) \ LUMA_MC_OP(put, 4, DEPTH, TYPE, OPT) \ LUMA_MC_OP(avg, 4, DEPTH, TYPE, OPT) \ LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \ LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \ LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \ LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT) #define LUMA_MC_816(DEPTH, TYPE, OPT) \ LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \ LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \ LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \ LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT) LUMA_MC_ALL(10, mc00, mmxext) LUMA_MC_ALL(10, mc10, mmxext) LUMA_MC_ALL(10, mc20, mmxext) LUMA_MC_ALL(10, mc30, mmxext) LUMA_MC_ALL(10, mc01, mmxext) LUMA_MC_ALL(10, mc11, mmxext) LUMA_MC_ALL(10, mc21, mmxext) LUMA_MC_ALL(10, mc31, mmxext) LUMA_MC_ALL(10, mc02, mmxext) LUMA_MC_ALL(10, mc12, mmxext) LUMA_MC_ALL(10, mc22, mmxext) LUMA_MC_ALL(10, mc32, mmxext) LUMA_MC_ALL(10, mc03, mmxext) LUMA_MC_ALL(10, mc13, mmxext) LUMA_MC_ALL(10, mc23, mmxext) LUMA_MC_ALL(10, mc33, mmxext) LUMA_MC_816(10, mc00, sse2) LUMA_MC_816(10, mc10, sse2) LUMA_MC_816(10, mc10, sse2_cache64) LUMA_MC_816(10, mc10, ssse3_cache64) LUMA_MC_816(10, mc20, sse2) LUMA_MC_816(10, mc20, sse2_cache64) LUMA_MC_816(10, mc20, ssse3_cache64) LUMA_MC_816(10, mc30, sse2) LUMA_MC_816(10, mc30, sse2_cache64) LUMA_MC_816(10, mc30, ssse3_cache64) LUMA_MC_816(10, mc01, sse2) LUMA_MC_816(10, mc11, sse2) LUMA_MC_816(10, mc21, sse2) LUMA_MC_816(10, mc31, sse2) LUMA_MC_816(10, mc02, sse2) LUMA_MC_816(10, mc12, sse2) LUMA_MC_816(10, mc22, sse2) LUMA_MC_816(10, mc32, sse2) LUMA_MC_816(10, mc03, sse2) LUMA_MC_816(10, mc13, sse2) LUMA_MC_816(10, mc23, sse2) LUMA_MC_816(10, mc33, sse2) #define QPEL16_OPMC(OP, MC, MMX)\ void ff_ ## OP ## _h264_qpel16_ ## MC ## _10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\ src += 8*stride;\ dst += 8*stride;\ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\ } #define QPEL16_OP(MC, MMX)\ QPEL16_OPMC(put, MC, MMX)\ QPEL16_OPMC(avg, MC, MMX) #define QPEL16(MMX)\ QPEL16_OP(mc00, MMX)\ QPEL16_OP(mc01, MMX)\ QPEL16_OP(mc02, MMX)\ QPEL16_OP(mc03, MMX)\ QPEL16_OP(mc10, MMX)\ QPEL16_OP(mc11, MMX)\ QPEL16_OP(mc12, MMX)\ QPEL16_OP(mc13, MMX)\ QPEL16_OP(mc20, MMX)\ QPEL16_OP(mc21, MMX)\ QPEL16_OP(mc22, MMX)\ QPEL16_OP(mc23, MMX)\ QPEL16_OP(mc30, MMX)\ QPEL16_OP(mc31, MMX)\ QPEL16_OP(mc32, MMX)\ QPEL16_OP(mc33, MMX) #if ARCH_X86_32 && HAVE_YASM && CONFIG_H264QPEL // ARCH_X86_64 implies SSE2+ QPEL16(mmxext) #endif #endif /* HAVE_YASM */ #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \ do { \ c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \ c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \ c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \ c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \ c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \ c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \ c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \ } while (0) #define H264_QPEL_FUNCS(x, y, CPU) \ do { \ c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \ c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc ## x ## y ## _ ## CPU; \ c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \ c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc ## x ## y ## _ ## CPU; \ } while (0) #define H264_QPEL_FUNCS_10(x, y, CPU) \ do { \ c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \ c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \ c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \ c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \ } while (0) void ff_h264qpel_init_x86(H264QpelContext *c, int bit_depth) { int high_bit_depth = bit_depth > 8; int mm_flags = av_get_cpu_flags(); #if HAVE_MMXEXT_EXTERNAL if (!high_bit_depth) { SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, ); SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmxext, ); SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmxext, ); SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, ); SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmxext, ); SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmxext, ); } else if (bit_depth == 10) { #if !ARCH_X86_64 SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_); SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_); SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_); SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_); #endif SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_); SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_); } #endif #if HAVE_SSE2_EXTERNAL if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW) && !high_bit_depth) { // these functions are slower than mmx on AMD, but faster on Intel H264_QPEL_FUNCS(0, 0, sse2); } if (!high_bit_depth) { H264_QPEL_FUNCS(0, 1, sse2); H264_QPEL_FUNCS(0, 2, sse2); H264_QPEL_FUNCS(0, 3, sse2); H264_QPEL_FUNCS(1, 1, sse2); H264_QPEL_FUNCS(1, 2, sse2); H264_QPEL_FUNCS(1, 3, sse2); H264_QPEL_FUNCS(2, 1, sse2); H264_QPEL_FUNCS(2, 2, sse2); H264_QPEL_FUNCS(2, 3, sse2); H264_QPEL_FUNCS(3, 1, sse2); H264_QPEL_FUNCS(3, 2, sse2); H264_QPEL_FUNCS(3, 3, sse2); } if (bit_depth == 10) { SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_); SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_); SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_); SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_); H264_QPEL_FUNCS_10(1, 0, sse2_cache64); H264_QPEL_FUNCS_10(2, 0, sse2_cache64); H264_QPEL_FUNCS_10(3, 0, sse2_cache64); } #endif #if HAVE_SSSE3_EXTERNAL if (!high_bit_depth) { H264_QPEL_FUNCS(1, 0, ssse3); H264_QPEL_FUNCS(1, 1, ssse3); H264_QPEL_FUNCS(1, 2, ssse3); H264_QPEL_FUNCS(1, 3, ssse3); H264_QPEL_FUNCS(2, 0, ssse3); H264_QPEL_FUNCS(2, 1, ssse3); H264_QPEL_FUNCS(2, 2, ssse3); H264_QPEL_FUNCS(2, 3, ssse3); H264_QPEL_FUNCS(3, 0, ssse3); H264_QPEL_FUNCS(3, 1, ssse3); H264_QPEL_FUNCS(3, 2, ssse3); H264_QPEL_FUNCS(3, 3, ssse3); } if (bit_depth == 10) { H264_QPEL_FUNCS_10(1, 0, ssse3_cache64); H264_QPEL_FUNCS_10(2, 0, ssse3_cache64); H264_QPEL_FUNCS_10(3, 0, ssse3_cache64); } #endif #if HAVE_AVX_EXTERNAL if (bit_depth == 10) { H264_QPEL_FUNCS_10(1, 0, sse2); H264_QPEL_FUNCS_10(2, 0, sse2); H264_QPEL_FUNCS_10(3, 0, sse2); } #endif }


static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags) { int ret; BDRVQcow2State *s = bs->opaque; uint32_t head = offset % s->cluster_size; uint32_t tail = (offset + count) % s->cluster_size; trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count); if (head || tail) { int64_t cl_start = (offset - head) >> BDRV_SECTOR_BITS; uint64_t off; unsigned int nr; assert(head + count <= s->cluster_size); /* check whether remainder of cluster already reads as zero */ if (!(is_zero_sectors(bs, cl_start, DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) && is_zero_sectors(bs, (offset + count) >> BDRV_SECTOR_BITS, DIV_ROUND_UP(-tail & (s->cluster_size - 1), BDRV_SECTOR_SIZE)))) { return -ENOTSUP; qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ offset = cl_start << BDRV_SECTOR_BITS; count = s->cluster_size; nr = s->cluster_size; ret = qcow2_get_cluster_offset(bs, offset, &nr, &off); if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO_PLAIN && ret != QCOW2_CLUSTER_ZERO_ALLOC) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } else { qemu_co_mutex_lock(&s->lock); trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count); /* Whatever is left can use real zero clusters */ ret = qcow2_zero_clusters(bs, offset, count >> BDRV_SECTOR_BITS, flags); qemu_co_mutex_unlock(&s->lock); return ret;


static void virtio_blk_complete_request(VirtIOBlockReq *req, unsigned char status) { VirtIOBlock *s = req->dev; VirtIODevice *vdev = VIRTIO_DEVICE(s); trace_virtio_blk_req_complete(req, status); stb_p(&req->in->status, status); virtqueue_push(s->vq, req->elem, req->qiov.size + sizeof(*req->in)); virtio_notify(vdev, s->vq); }


static void vfio_enable_msi(VFIODevice *vdev) { int ret, i; vfio_disable_interrupts(vdev); vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev); retry: vdev->msi_vectors = g_malloc0(vdev->nr_vectors * sizeof(VFIOMSIVector)); for (i = 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector = &vdev->msi_vectors[i]; vector->vdev = vdev; vector->use = true; if (event_notifier_init(&vector->interrupt, 0)) { error_report("vfio: Error: event_notifier_init failed"); } vector->msg = msi_get_message(&vdev->pdev, i); /* * Attempt to enable route through KVM irqchip, * default to userspace handling if unavailable. */ vector->virq = kvm_irqchip_add_msi_route(kvm_state, vector->msg); if (vector->virq < 0 || kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt, NULL, vector->virq) < 0) { qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), vfio_msi_interrupt, NULL, vector); } } ret = vfio_enable_vectors(vdev, false); if (ret) { if (ret < 0) { error_report("vfio: Error: Failed to setup MSI fds: %m"); } else if (ret != vdev->nr_vectors) { error_report("vfio: Error: Failed to enable %d " "MSI vectors, retry with %d", vdev->nr_vectors, ret); } for (i = 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector = &vdev->msi_vectors[i]; if (vector->virq >= 0) { kvm_irqchip_remove_irqfd_notifier(kvm_state, &vector->interrupt, vector->virq); kvm_irqchip_release_virq(kvm_state, vector->virq); vector->virq = -1; } else { qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), NULL, NULL, NULL); } event_notifier_cleanup(&vector->interrupt); } g_free(vdev->msi_vectors); if (ret > 0 && ret != vdev->nr_vectors) { vdev->nr_vectors = ret; goto retry; } vdev->nr_vectors = 0; return; } vdev->interrupt = VFIO_INT_MSI; DPRINTF("%s(%04x:%02x:%02x.%x) Enabled %d MSI vectors\n", __func__, vdev->host.domain, vdev->host.bus, vdev->host.slot, vdev->host.function, vdev->nr_vectors); }


static int decode_lowdelay(DiracContext *s) { AVCodecContext *avctx = s->avctx; int slice_x, slice_y, bufsize; int64_t coef_buf_size, bytes = 0; const uint8_t *buf; DiracSlice *slices; SliceCoeffs tmp[MAX_DWT_LEVELS]; int slice_num = 0; if (s->slice_params_num_buf != (s->num_x * s->num_y)) { s->slice_params_buf = av_realloc_f(s->slice_params_buf, s->num_x * s->num_y, sizeof(DiracSlice)); if (!s->slice_params_buf) { av_log(s->avctx, AV_LOG_ERROR, "slice params buffer allocation failure\n"); return AVERROR(ENOMEM); } s->slice_params_num_buf = s->num_x * s->num_y; } slices = s->slice_params_buf; /* 8 becacuse that's how much the golomb reader could overread junk data * from another plane/slice at most, and 512 because SIMD */ coef_buf_size = subband_coeffs(s, s->num_x - 1, s->num_y - 1, 0, tmp) + 8; coef_buf_size = (coef_buf_size << (1 + s->pshift)) + 512; if (s->threads_num_buf != avctx->thread_count || s->thread_buf_size != coef_buf_size) { s->threads_num_buf = avctx->thread_count; s->thread_buf_size = coef_buf_size; s->thread_buf = av_realloc_f(s->thread_buf, avctx->thread_count, s->thread_buf_size); if (!s->thread_buf) { av_log(s->avctx, AV_LOG_ERROR, "thread buffer allocation failure\n"); return AVERROR(ENOMEM); } } align_get_bits(&s->gb); /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */ buf = s->gb.buffer + get_bits_count(&s->gb)/8; bufsize = get_bits_left(&s->gb); if (s->hq_picture) { int i; for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) { for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) { bytes = s->highquality.prefix_bytes + 1; for (i = 0; i < 3; i++) { if (bytes <= bufsize/8) bytes += buf[bytes] * s->highquality.size_scaler + 1; } if (bytes >= INT_MAX || bytes*8 > bufsize) { av_log(s->avctx, AV_LOG_ERROR, "too many bytes\n"); return AVERROR_INVALIDDATA; } slices[slice_num].bytes = bytes; slices[slice_num].slice_x = slice_x; slices[slice_num].slice_y = slice_y; init_get_bits(&slices[slice_num].gb, buf, bufsize); slice_num++; buf += bytes; if (bufsize/8 >= bytes) bufsize -= bytes*8; else bufsize = 0; } } if (s->num_x*s->num_y != slice_num) { av_log(s->avctx, AV_LOG_ERROR, "too few slices\n"); return AVERROR_INVALIDDATA; } avctx->execute2(avctx, decode_hq_slice_row, slices, NULL, s->num_y); } else { for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) { for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) { bytes = (slice_num+1) * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den - slice_num * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den; slices[slice_num].bytes = bytes; slices[slice_num].slice_x = slice_x; slices[slice_num].slice_y = slice_y; init_get_bits(&slices[slice_num].gb, buf, bufsize); slice_num++; buf += bytes; if (bufsize/8 >= bytes) bufsize -= bytes*8; else bufsize = 0; } } avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num, sizeof(DiracSlice)); /* [DIRAC_STD] 13.5.2 Slices */ } if (s->dc_prediction) { if (s->pshift) { intra_dc_prediction_10(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction_10(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction_10(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ } else { intra_dc_prediction_8(&s->plane[0].band[0][0]); intra_dc_prediction_8(&s->plane[1].band[0][0]); intra_dc_prediction_8(&s->plane[2].band[0][0]); } } return 0; }


static int xface_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { XFaceContext *xface = avctx->priv_data; ProbRangesQueue pq = {{ 0 }, 0}; uint8_t bitmap_copy[XFACE_PIXELS]; BigInt b = {0}; int i, j, k, ret = 0; const uint8_t *buf; uint8_t *p; char intbuf[XFACE_MAX_DIGITS]; if (avctx->width || avctx->height) { if (avctx->width != XFACE_WIDTH || avctx->height != XFACE_HEIGHT) { av_log(avctx, AV_LOG_ERROR, "Size value %dx%d not supported, only accepts a size of %dx%d\n", avctx->width, avctx->height, XFACE_WIDTH, XFACE_HEIGHT); return AVERROR(EINVAL); } } avctx->width = XFACE_WIDTH; avctx->height = XFACE_HEIGHT; /* convert image from MONOWHITE to 1=black 0=white bitmap */ buf = frame->data[0]; i = j = 0; do { for (k = 0; k < 8; k++) xface->bitmap[i++] = (buf[j]>>(7-k))&1; if (++j == XFACE_WIDTH/8) { buf += frame->linesize[0]; j = 0; } } while (i < XFACE_PIXELS); /* create a copy of bitmap */ memcpy(bitmap_copy, xface->bitmap, XFACE_PIXELS); ff_xface_generate_face(xface->bitmap, bitmap_copy); encode_block(xface->bitmap, 16, 16, 0, &pq); encode_block(xface->bitmap + 16, 16, 16, 0, &pq); encode_block(xface->bitmap + 32, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16 + 16, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 16 + 32, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32 + 16, 16, 16, 0, &pq); encode_block(xface->bitmap + XFACE_WIDTH * 32 + 32, 16, 16, 0, &pq); while (pq.prob_ranges_idx > 0) push_integer(&b, pq.prob_ranges[--pq.prob_ranges_idx]); /* write the inverted big integer in b to intbuf */ i = 0; while (b.nb_words) { uint8_t r; ff_big_div(&b, XFACE_PRINTS, &r); intbuf[i++] = r + XFACE_FIRST_PRINT; } if ((ret = ff_alloc_packet2(avctx, pkt, i+2)) < 0) return ret; /* revert the number, and close the buffer */ p = pkt->data; while (--i >= 0) *(p++) = intbuf[i]; *(p++) = '\n'; *(p++) = 0; pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; return 0; }


static int mov_text_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt) { AVSubtitle *sub = data; int ret, ts_start, ts_end; AVBPrint buf; char *ptr = avpkt->data; char *end; //char *ptr_temp; int text_length, tsmb_type, style_entries, tsmb_size; int **style_start = {0,}; int **style_end = {0,}; int **style_flags = {0,}; const uint8_t *tsmb; int index, i; int *flag; int *style_pos; if (!ptr || avpkt->size < 2) return AVERROR_INVALIDDATA; /* * A packet of size two with value zero is an empty subtitle * used to mark the end of the previous non-empty subtitle. * We can just drop them here as we have duration information * already. If the value is non-zero, then it's technically a * bad packet. */ if (avpkt->size == 2) return AV_RB16(ptr) == 0 ? 0 : AVERROR_INVALIDDATA; /* * The first two bytes of the packet are the length of the text string * In complex cases, there are style descriptors appended to the string * so we can't just assume the packet size is the string size. */ text_length = AV_RB16(ptr); end = ptr + FFMIN(2 + text_length, avpkt->size); ptr += 2; ts_start = av_rescale_q(avpkt->pts, avctx->time_base, (AVRational){1,100}); ts_end = av_rescale_q(avpkt->pts + avpkt->duration, avctx->time_base, (AVRational){1,100}); tsmb_size = 0; // Note that the spec recommends lines be no longer than 2048 characters. av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); if (text_length + 2 != avpkt->size) { while (text_length + 2 + tsmb_size < avpkt->size) { tsmb = ptr + text_length + tsmb_size; tsmb_size = AV_RB32(tsmb); tsmb += 4; tsmb_type = AV_RB32(tsmb); tsmb += 4; if (tsmb_type == MKBETAG('s','t','y','l')) { style_entries = AV_RB16(tsmb); tsmb += 2; for(i = 0; i < style_entries; i++) { style_pos = av_malloc(4); *style_pos = AV_RB16(tsmb); index = i; av_dynarray_add(&style_start, &index, style_pos); tsmb += 2; style_pos = av_malloc(4); *style_pos = AV_RB16(tsmb); index = i; av_dynarray_add(&style_end, &index, style_pos); tsmb += 2; // fontID = AV_RB16(tsmb); tsmb += 2; flag = av_malloc(4); *flag = AV_RB8(tsmb); index = i; av_dynarray_add(&style_flags, &index, flag); //fontsize=AV_RB8(tsmb); tsmb += 2; // text-color-rgba tsmb += 4; } text_to_ass(&buf, ptr, end, style_start, style_end, style_flags, style_entries); av_freep(&style_start); av_freep(&style_end); av_freep(&style_flags); } } } else text_to_ass(&buf, ptr, end, NULL, NULL, 0, 0); ret = ff_ass_add_rect_bprint(sub, &buf, ts_start, ts_end - ts_start); av_bprint_finalize(&buf, NULL); if (ret < 0) return ret; *got_sub_ptr = sub->num_rects > 0; return avpkt->size; }


av_cold void ff_snow_common_end(SnowContext *s) { int plane_index, level, orientation, i; av_freep(&s->spatial_dwt_buffer); av_freep(&s->temp_dwt_buffer); av_freep(&s->spatial_idwt_buffer); av_freep(&s->temp_idwt_buffer); av_freep(&s->run_buffer); s->m.me.temp= NULL; av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); av_freep(&s->m.me.score_map); av_freep(&s->m.obmc_scratchpad); av_freep(&s->block); av_freep(&s->scratchbuf); av_freep(&s->emu_edge_buffer); for(i=0; i<MAX_REF_FRAMES; i++){ av_freep(&s->ref_mvs[i]); av_freep(&s->ref_scores[i]); if(s->last_picture[i]->data[0]) { av_assert0(s->last_picture[i]->data[0] != s->current_picture->data[0]); } av_frame_free(&s->last_picture[i]); } for(plane_index=0; plane_index < s->nb_planes; plane_index++){ for(level=s->spatial_decomposition_count-1; level>=0; level--){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ SubBand *b= &s->plane[plane_index].band[level][orientation]; av_freep(&b->x_coeff); } } } av_frame_free(&s->mconly_picture); av_frame_free(&s->current_picture); }


HELPER_LD_ATOMIC(ll, lw) #ifdef TARGET_MIPS64 HELPER_LD_ATOMIC(lld, ld) #endif #undef HELPER_LD_ATOMIC #define HELPER_ST_ATOMIC(name, ld_insn, st_insn, almask) \ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \ target_ulong arg2, int mem_idx) \ { \ target_long tmp; \ \ if (arg2 & almask) { \ env->CP0_BadVAddr = arg2; \ helper_raise_exception(env, EXCP_AdES); \ } \ if (do_translate_address(env, arg2, 1) == env->lladdr) { \ tmp = do_##ld_insn(env, arg2, mem_idx); \ if (tmp == env->llval) { \ do_##st_insn(env, arg2, arg1, mem_idx); \ return 1; \ } \ } \ return 0; \ } HELPER_ST_ATOMIC(sc, lw, sw, 0x3) #ifdef TARGET_MIPS64 HELPER_ST_ATOMIC(scd, ld, sd, 0x7) #endif #undef HELPER_ST_ATOMIC #endif #ifdef TARGET_WORDS_BIGENDIAN #define GET_LMASK(v) ((v) & 3) #define GET_OFFSET(addr, offset) (addr + (offset)) #else #define GET_LMASK(v) (((v) & 3) ^ 3) #define GET_OFFSET(addr, offset) (addr - (offset)) #endif target_ulong helper_lwl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, int mem_idx) { target_ulong tmp; tmp = do_lbu(env, arg2, mem_idx); arg1 = (arg1 & 0x00FFFFFF) | (tmp << 24); if (GET_LMASK(arg2) <= 2) { tmp = do_lbu(env, GET_OFFSET(arg2, 1), mem_idx); arg1 = (arg1 & 0xFF00FFFF) | (tmp << 16); } if (GET_LMASK(arg2) <= 1) { tmp = do_lbu(env, GET_OFFSET(arg2, 2), mem_idx); arg1 = (arg1 & 0xFFFF00FF) | (tmp << 8); } if (GET_LMASK(arg2) == 0) { tmp = do_lbu(env, GET_OFFSET(arg2, 3), mem_idx); arg1 = (arg1 & 0xFFFFFF00) | tmp; } return (int32_t)arg1; }


static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, UINT8 * buf, int buf_size) { MPADecodeContext *s = avctx->priv_data; UINT32 header; UINT8 *buf_ptr; int len, out_size; short *out_samples = data; *data_size = 0; buf_ptr = buf; while (buf_size > 0) { len = s->inbuf_ptr - s->inbuf; if (s->frame_size == 0) { /* special case for next header for first frame in free format case (XXX: find a simpler method) */ if (s->free_format_next_header != 0) { s->inbuf[0] = s->free_format_next_header >> 24; s->inbuf[1] = s->free_format_next_header >> 16; s->inbuf[2] = s->free_format_next_header >> 8; s->inbuf[3] = s->free_format_next_header; s->inbuf_ptr = s->inbuf + 4; s->free_format_next_header = 0; goto got_header; } /* no header seen : find one. We need at least HEADER_SIZE bytes to parse it */ len = HEADER_SIZE - len; if (len > buf_size) len = buf_size; if (len > 0) { memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; buf_size -= len; s->inbuf_ptr += len; } if ((s->inbuf_ptr - s->inbuf) >= HEADER_SIZE) { got_header: header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; if (check_header(header) < 0) { /* no sync found : move by one byte (inefficient, but simple!) */ memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; dprintf("skip %x\n", header); /* reset free format frame size to give a chance to get a new bitrate */ s->free_format_frame_size = 0; } else { if (decode_header(s, header) == 1) { /* free format: compute frame size */ s->frame_size = -1; memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; } else { /* update codec info */ avctx->sample_rate = s->sample_rate; avctx->channels = s->nb_channels; avctx->bit_rate = s->bit_rate; avctx->frame_size = s->frame_size; } } } } else if (s->frame_size == -1) { /* free format : find next sync to compute frame size */ len = MPA_MAX_CODED_FRAME_SIZE - len; if (len > buf_size) len = buf_size; if (len == 0) { /* frame too long: resync */ s->frame_size = 0; } else { UINT8 *p, *pend; UINT32 header1; int padding; memcpy(s->inbuf_ptr, buf_ptr, len); /* check for header */ p = s->inbuf_ptr - 3; pend = s->inbuf_ptr + len - 4; while (p <= pend) { header = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; /* check with high probability that we have a valid header */ if ((header & SAME_HEADER_MASK) == (header1 & SAME_HEADER_MASK)) { /* header found: update pointers */ len = (p + 4) - s->inbuf_ptr; buf_ptr += len; buf_size -= len; s->inbuf_ptr = p; /* compute frame size */ s->free_format_next_header = header; s->free_format_frame_size = s->inbuf_ptr - s->inbuf; padding = (header1 >> 9) & 1; if (s->layer == 1) s->free_format_frame_size -= padding * 4; else s->free_format_frame_size -= padding; dprintf("free frame size=%d padding=%d\n", s->free_format_frame_size, padding); decode_header(s, header1); goto next_data; } p++; } /* not found: simply increase pointers */ buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } } else if (len < s->frame_size) { if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) s->frame_size = MPA_MAX_CODED_FRAME_SIZE; len = s->frame_size - len; if (len > buf_size) len = buf_size; else if (len < 4) len = buf_size > 4 ? 4 : buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } else { out_size = mp_decode_frame(s, out_samples); s->inbuf_ptr = s->inbuf; s->frame_size = 0; *data_size = out_size; break; } next_data: } return buf_ptr - buf; }


static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) { AVStream *video_st = s->streams[0]; AVCodecParameters *video_par = s->streams[0]->codecpar; AVCodecParameters *audio_par = s->streams[1]->codecpar; int audio_rate = audio_par->sample_rate; int64_t frame_rate = (video_st->avg_frame_rate.num * 0x10000LL) / video_st->avg_frame_rate.den; int audio_kbitrate = audio_par->bit_rate / 1000; int video_kbitrate = FFMIN(video_par->bit_rate / 1000, 800 - audio_kbitrate); avio_wb32(pb, 0x94); /* size */ ffio_wfourcc(pb, "uuid"); ffio_wfourcc(pb, "PROF"); avio_wb32(pb, 0x21d24fce); /* 96 bit UUID */ avio_wb32(pb, 0xbb88695c); avio_wb32(pb, 0xfac9c740); avio_wb32(pb, 0x0); /* ? */ avio_wb32(pb, 0x3); /* 3 sections ? */ avio_wb32(pb, 0x14); /* size */ ffio_wfourcc(pb, "FPRF"); avio_wb32(pb, 0x0); /* ? */ avio_wb32(pb, 0x0); /* ? */ avio_wb32(pb, 0x0); /* ? */ avio_wb32(pb, 0x2c); /* size */ ffio_wfourcc(pb, "APRF"); /* audio */ avio_wb32(pb, 0x0); avio_wb32(pb, 0x2); /* TrackID */ ffio_wfourcc(pb, "mp4a"); avio_wb32(pb, 0x20f); avio_wb32(pb, 0x0); avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_rate); avio_wb32(pb, audio_par->channels); avio_wb32(pb, 0x34); /* size */ ffio_wfourcc(pb, "VPRF"); /* video */ avio_wb32(pb, 0x0); avio_wb32(pb, 0x1); /* TrackID */ if (video_par->codec_id == AV_CODEC_ID_H264) { ffio_wfourcc(pb, "avc1"); avio_wb16(pb, 0x014D); avio_wb16(pb, 0x0015); } else { ffio_wfourcc(pb, "mp4v"); avio_wb16(pb, 0x0000); avio_wb16(pb, 0x0103); } avio_wb32(pb, 0x0); avio_wb32(pb, video_kbitrate); avio_wb32(pb, video_kbitrate); avio_wb32(pb, frame_rate); avio_wb32(pb, frame_rate); avio_wb16(pb, video_par->width); avio_wb16(pb, video_par->height); avio_wb32(pb, 0x010001); /* ? */ }


void rgb32tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size) { unsigned i; unsigned num_pixels = src_size >> 2; for(i=0; i<num_pixels; i++) { dst[3*i + 0] = src[4*i + 2]; dst[3*i + 1] = src[4*i + 1]; dst[3*i + 2] = src[4*i + 0]; } }


static long do_sigreturn_v2(CPUARMState *env) { abi_ulong frame_addr; struct sigframe_v2 *frame; /* * Since we stacked the signal on a 64-bit boundary, * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ if (env->regs[13] & 7) goto badframe; frame_addr = env->regs[13]; if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; if (do_sigframe_return_v2(env, frame_addr, &frame->uc)) goto badframe; unlock_user_struct(frame, frame_addr, 0); return env->regs[0]; badframe: unlock_user_struct(frame, frame_addr, 0); force_sig(TARGET_SIGSEGV /* , current */); return 0; }


static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { int devfn = (config_addr >> 8) & 0xFF; sPAPRPHBState *phb; QLIST_FOREACH(phb, &spapr->phbs, list) { BusChild *kid; if (phb->buid != buid) { continue; } QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { PCIDevice *dev = (PCIDevice *)kid->child; if (dev->devfn == devfn) { return dev; } } } return NULL; }


int xics_alloc(XICSState *icp, int src, int irq_hint, bool lsi) { ICSState *ics = &icp->ics[src]; int irq; if (irq_hint) { assert(src == xics_find_source(icp, irq_hint)); if (!ICS_IRQ_FREE(ics, irq_hint - ics->offset)) { trace_xics_alloc_failed_hint(src, irq_hint); return -1; } irq = irq_hint; } else { irq = ics_find_free_block(ics, 1, 1); if (irq < 0) { trace_xics_alloc_failed_no_left(src); return -1; } irq += ics->offset; } ics_set_irq_type(ics, irq - ics->offset, lsi); trace_xics_alloc(src, irq); return irq; }


static int ftp_store(FTPContext *s) { char command[CONTROL_BUFFER_SIZE]; const int stor_codes[] = {150, 0}; snprintf(command, sizeof(command), "STOR %s\r\n", s->path); if (!ftp_send_command(s, command, stor_codes, NULL)) return AVERROR(EIO); s->state = UPLOADING; return 0; }


enum AVPixelFormat avpriv_fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id) { int i; for (i = 0; avpriv_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { if (avpriv_fmt_conversion_table[i].v4l2_fmt == v4l2_fmt && avpriv_fmt_conversion_table[i].codec_id == codec_id) { return avpriv_fmt_conversion_table[i].ff_fmt; } } return AV_PIX_FMT_NONE; }


void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) { RTPDemuxContext *s = s1->priv_data; int len, h, max_packet_size; uint8_t *q; int begin_of_slice, end_of_slice, frame_type, temporal_reference; max_packet_size = s->max_payload_size; begin_of_slice = 1; end_of_slice = 0; frame_type = 0; temporal_reference = 0; while (size > 0) { int begin_of_sequence; begin_of_sequence = 0; len = max_packet_size - 4; if (len >= size) { len = size; end_of_slice = 1; } else { const uint8_t *r, *r1; int start_code; r1 = buf1; while (1) { start_code = -1; r = ff_find_start_code(r1, buf1 + size, &start_code); if((start_code & 0xFFFFFF00) == 0x100) { /* New start code found */ if (start_code == 0x100) { frame_type = (r[1] & 0x38) >> 3; temporal_reference = (int)r[0] << 2 | r[1] >> 6; } if (start_code == 0x1B8) { begin_of_sequence = 1; } if (r - buf1 < len) { /* The current slice fits in the packet */ if (begin_of_slice == 0) { /* no slice at the beginning of the packet... */ end_of_slice = 1; len = r - buf1 - 4; break; } r1 = r; } else { if (r - r1 < max_packet_size) { len = r1 - buf1 - 4; end_of_slice = 1; } break; } } else { break; } } } h = 0; h |= temporal_reference << 16; h |= begin_of_sequence << 13; h |= begin_of_slice << 12; h |= end_of_slice << 11; h |= frame_type << 8; q = s->buf; *q++ = h >> 24; *q++ = h >> 16; *q++ = h >> 8; *q++ = h; memcpy(q, buf1, len); q += len; /* 90 KHz time stamp */ s->timestamp = s->cur_timestamp; ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size)); buf1 += len; size -= len; begin_of_slice = end_of_slice; end_of_slice = 0; } }


static int archipelago_submit_request(BDRVArchipelagoState *s, uint64_t bufidx, size_t count, off_t offset, ArchipelagoAIOCB *aio_cb, ArchipelagoSegmentedRequest *segreq, int op) { int ret, targetlen; char *target; void *data = NULL; struct xseg_request *req; AIORequestData *reqdata = g_malloc(sizeof(AIORequestData)); targetlen = strlen(s->volname); req = xseg_get_request(s->xseg, s->srcport, s->vportno, X_ALLOC); if (!req) { archipelagolog("Cannot get XSEG request\n"); goto err_exit2; } ret = xseg_prep_request(s->xseg, req, targetlen, count); if (ret < 0) { archipelagolog("Cannot prepare XSEG request\n"); goto err_exit; } target = xseg_get_target(s->xseg, req); if (!target) { archipelagolog("Cannot get XSEG target\n"); goto err_exit; } memcpy(target, s->volname, targetlen); req->size = count; req->offset = offset; switch (op) { case ARCHIP_OP_READ: req->op = X_READ; break; case ARCHIP_OP_WRITE: req->op = X_WRITE; break; case ARCHIP_OP_FLUSH: req->op = X_FLUSH; break; } reqdata->volname = s->volname; reqdata->offset = offset; reqdata->size = count; reqdata->bufidx = bufidx; reqdata->aio_cb = aio_cb; reqdata->segreq = segreq; reqdata->op = op; xseg_set_req_data(s->xseg, req, reqdata); if (op == ARCHIP_OP_WRITE) { data = xseg_get_data(s->xseg, req); if (!data) { archipelagolog("Cannot get XSEG data\n"); goto err_exit; } qemu_iovec_to_buf(aio_cb->qiov, bufidx, data, count); } xport p = xseg_submit(s->xseg, req, s->srcport, X_ALLOC); if (p == NoPort) { archipelagolog("Could not submit XSEG request\n"); goto err_exit; } xseg_signal(s->xseg, p); return 0; err_exit: g_free(reqdata); xseg_put_request(s->xseg, req, s->srcport); return -EIO; err_exit2: g_free(reqdata); return -EIO; }


int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) { BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); int i, r; if (!k->set_host_notifier) { fprintf(stderr, "binding does not support host notifiers\n"); r = -ENOSYS; goto fail; } for (i = 0; i < hdev->nvqs; ++i) { r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true); if (r < 0) { fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r); goto fail_vq; } } return 0; fail_vq: while (--i >= 0) { r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false); if (r < 0) { fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r); fflush(stderr); } assert (r >= 0); } fail: return r; }


static int multiwrite_f(BlockDriverState *bs, int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, cnt; char **buf; int64_t offset, first_offset = 0; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int nr_iov; int nr_reqs; int pattern = 0xcd; QEMUIOVector *qiovs; int i; BlockRequest *reqs; while ((c = getopt(argc, argv, "CqP:")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'P': pattern = parse_pattern(optarg); if (pattern < 0) { return 0; } break; default: return qemuio_command_usage(&writev_cmd); } } if (optind > argc - 2) { return qemuio_command_usage(&writev_cmd); } nr_reqs = 1; for (i = optind; i < argc; i++) { if (!strcmp(argv[i], ";")) { nr_reqs++; } } reqs = g_malloc0(nr_reqs * sizeof(*reqs)); buf = g_malloc0(nr_reqs * sizeof(*buf)); qiovs = g_malloc(nr_reqs * sizeof(*qiovs)); for (i = 0; i < nr_reqs && optind < argc; i++) { int j; /* Read the offset of the request */ offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric offset argument -- %s\n", argv[optind]); goto out; } optind++; if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n", (long long)offset); goto out; } if (i == 0) { first_offset = offset; } /* Read lengths for qiov entries */ for (j = optind; j < argc; j++) { if (!strcmp(argv[j], ";")) { break; } } nr_iov = j - optind; /* Build request */ buf[i] = create_iovec(bs, &qiovs[i], &argv[optind], nr_iov, pattern); if (buf[i] == NULL) { goto out; } reqs[i].qiov = &qiovs[i]; reqs[i].sector = offset >> 9; reqs[i].nb_sectors = reqs[i].qiov->size >> 9; optind = j + 1; pattern++; } /* If there were empty requests at the end, ignore them */ nr_reqs = i; gettimeofday(&t1, NULL); cnt = do_aio_multiwrite(bs, reqs, nr_reqs, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("aio_multiwrite failed: %s\n", strerror(-cnt)); goto out; } if (qflag) { goto out; } /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("wrote", &t2, first_offset, total, total, cnt, Cflag); out: for (i = 0; i < nr_reqs; i++) { qemu_io_free(buf[i]); if (reqs[i].qiov != NULL) { qemu_iovec_destroy(&qiovs[i]); } } g_free(buf); g_free(reqs); g_free(qiovs); return 0; }


static void check_consistency(FFFrameQueue *fq) { #if ASSERT_LEVEL >= 2 uint64_t nb_samples = 0; size_t i; av_assert0(fq->queued == fq->total_frames_head - fq->total_frames_tail); for (i = 0; i < fq->queued; i++) nb_samples += bucket(fq, i)->frame->nb_samples; av_assert0(nb_samples == fq->total_samples_head - fq->total_samples_tail); #endif }


void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size, int slice_or_tiles_up_boundary, int slice_or_tiles_left_boundary) { MvField *tab_mvf = s->ref->tab_mvf; int log2_min_pu_size = s->sps->log2_min_pu_size; int log2_min_tu_size = s->sps->log2_min_tb_size; int min_pu_width = s->sps->min_pu_width; int min_tu_width = s->sps->min_tb_width; int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width + (x0 >> log2_min_pu_size)].is_intra; int i, j, bs; if (y0 > 0 && (y0 & 7) == 0) { int yp_pu = (y0 - 1) >> log2_min_pu_size; int yq_pu = y0 >> log2_min_pu_size; int yp_tu = (y0 - 1) >> log2_min_tu_size; int yq_tu = y0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 - 1); bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 1); if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_up_boundary & 1) && (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_up_boundary & 2) && (y0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (y0 == 0 || s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs; } } // bs for TU internal horizontal PU boundaries if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra) for (j = 8; j < (1 << log2_trafo_size); j += 8) { int yp_pu = (y0 + j - 1) >> log2_min_pu_size; int yq_pu = (y0 + j) >> log2_min_pu_size; int yp_tu = (y0 + j - 1) >> log2_min_tu_size; int yq_tu = (y0 + j) >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 + j - 1); bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 0); if (s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs; } } // bs for vertical TU boundaries if (x0 > 0 && (x0 & 7) == 0) { int xp_pu = (x0 - 1) >> log2_min_pu_size; int xq_pu = x0 >> log2_min_pu_size; int xp_tu = (x0 - 1) >> log2_min_tu_size; int xq_tu = x0 >> log2_min_tu_size; for (i = 0; i < (1 << log2_trafo_size); i += 4) { int y_pu = (y0 + i) >> log2_min_pu_size; int y_tu = (y0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 - 1, y0 + i); bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 1); if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_left_boundary & 1) && (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_left_boundary & 2) && (x0 % (1 << s->sps->log2_ctb_size)) == 0) bs = 0; if (x0 == 0 || s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs; } } // bs for TU internal vertical PU boundaries if (log2_trafo_size > log2_min_pu_size && !is_intra) for (j = 0; j < (1 << log2_trafo_size); j += 4) { int y_pu = (y0 + j) >> log2_min_pu_size; int y_tu = (y0 + j) >> log2_min_tu_size; for (i = 8; i < (1 << log2_trafo_size); i += 8) { int xp_pu = (x0 + i - 1) >> log2_min_pu_size; int xq_pu = (x0 + i) >> log2_min_pu_size; int xp_tu = (x0 + i - 1) >> log2_min_tu_size; int xq_tu = (x0 + i) >> log2_min_tu_size; MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i - 1, y0 + j); bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 0); if (s->sh.disable_deblocking_filter_flag == 1) bs = 0; if (bs) s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs; } } }


static void mips_cps_realize(DeviceState *dev, Error **errp) { MIPSCPSState *s = MIPS_CPS(dev); CPUMIPSState *env; MIPSCPU *cpu; int i; Error *err = NULL; target_ulong gcr_base; bool itu_present = false; for (i = 0; i < s->num_vp; i++) { cpu = cpu_mips_init(s->cpu_model); if (cpu == NULL) { error_setg(errp, "%s: CPU initialization failed", __func__); return; } /* Init internal devices */ cpu_mips_irq_init_cpu(cpu); cpu_mips_clock_init(cpu); env = &cpu->env; if (cpu_mips_itu_supported(env)) { itu_present = true; /* Attach ITC Tag to the VP */ env->itc_tag = mips_itu_get_tag_region(&s->itu); } qemu_register_reset(main_cpu_reset, cpu); } cpu = MIPS_CPU(first_cpu); env = &cpu->env; /* Inter-Thread Communication Unit */ if (itu_present) { object_initialize(&s->itu, sizeof(s->itu), TYPE_MIPS_ITU); qdev_set_parent_bus(DEVICE(&s->itu), sysbus_get_default()); object_property_set_int(OBJECT(&s->itu), 16, "num-fifo", &err); object_property_set_int(OBJECT(&s->itu), 16, "num-semaphores", &err); object_property_set_bool(OBJECT(&s->itu), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } memory_region_add_subregion(&s->container, 0, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0)); } /* Cluster Power Controller */ object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC); qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default()); object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err); object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err); object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } memory_region_add_subregion(&s->container, 0, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0)); /* Global Interrupt Controller */ object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC); qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default()); object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err); object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err); object_property_set_bool(OBJECT(&s->gic), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } memory_region_add_subregion(&s->container, 0, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0)); /* Global Configuration Registers */ gcr_base = env->CP0_CMGCRBase << 4; object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR); qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default()); object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err); object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err); object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err); object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err); object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err); object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } memory_region_add_subregion(&s->container, gcr_base, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0)); }


static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) { int i, shnum, nsyms, sym_idx = 0, str_idx = 0; struct elf_shdr *shdr; char *strings = NULL; struct syminfo *s = NULL; struct elf_sym *new_syms, *syms = NULL; shnum = hdr->e_shnum; i = shnum * sizeof(struct elf_shdr); shdr = (struct elf_shdr *)alloca(i); if (pread(fd, shdr, i, hdr->e_shoff) != i) { return; } bswap_shdr(shdr, shnum); for (i = 0; i < shnum; ++i) { if (shdr[i].sh_type == SHT_SYMTAB) { sym_idx = i; str_idx = shdr[i].sh_link; goto found; } } /* There will be no symbol table if the file was stripped. */ return; found: /* Now know where the strtab and symtab are. Snarf them. */ s = g_try_new(struct syminfo, 1); if (!s) { goto give_up; } i = shdr[str_idx].sh_size; s->disas_strtab = strings = g_try_malloc(i); if (!strings || pread(fd, strings, i, shdr[str_idx].sh_offset) != i) { goto give_up; } i = shdr[sym_idx].sh_size; syms = g_try_malloc(i); if (!syms || pread(fd, syms, i, shdr[sym_idx].sh_offset) != i) { goto give_up; } nsyms = i / sizeof(struct elf_sym); for (i = 0; i < nsyms; ) { bswap_sym(syms + i); /* Throw away entries which we do not need. */ if (syms[i].st_shndx == SHN_UNDEF || syms[i].st_shndx >= SHN_LORESERVE || ELF_ST_TYPE(syms[i].st_info) != STT_FUNC) { if (i < --nsyms) { syms[i] = syms[nsyms]; } } else { #if defined(TARGET_ARM) || defined (TARGET_MIPS) /* The bottom address bit marks a Thumb or MIPS16 symbol. */ syms[i].st_value &= ~(target_ulong)1; #endif syms[i].st_value += load_bias; i++; } } /* No "useful" symbol. */ if (nsyms == 0) { goto give_up; } /* Attempt to free the storage associated with the local symbols that we threw away. Whether or not this has any effect on the memory allocation depends on the malloc implementation and how many symbols we managed to discard. */ new_syms = g_try_renew(struct elf_sym, syms, nsyms); if (new_syms == NULL) { goto give_up; } syms = new_syms; qsort(syms, nsyms, sizeof(*syms), symcmp); s->disas_num_syms = nsyms; #if ELF_CLASS == ELFCLASS32 s->disas_symtab.elf32 = syms; #else s->disas_symtab.elf64 = syms; #endif s->lookup_symbol = lookup_symbolxx; s->next = syminfos; syminfos = s; return; give_up: g_free(s); g_free(strings); g_free(syms); }


static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; qpci_io_writel(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_PFN, pfn); }


static int swf_write_audio(AVFormatContext *s, const uint8_t *buf, int size) { ByteIOContext *pb = &s->pb; put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); put_buffer(pb, buf, size); put_swf_end_tag(s); put_flush_packet(&s->pb); return 0; }


static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard) { AviSynthContext *avs = s->priv_data; AVRational fps, samplerate; int samples; const char* error; if (avs->curr_sample >= avs->vi->num_audio_samples) return AVERROR_EOF; fps.num = avs->vi->fps_numerator; fps.den = avs->vi->fps_denominator; samplerate.num = avs->vi->audio_samples_per_second; samplerate.den = 1; if (avs_has_video(avs->vi)) { if (avs->curr_frame < avs->vi->num_frames) samples = av_rescale_q(avs->curr_frame, samplerate, fps) - avs->curr_sample; else samples = av_rescale_q(1, samplerate, fps); } else { samples = 1000; } // After seeking, audio may catch up with video. if (samples <= 0) { pkt->size = 0; pkt->data = NULL; return 0; } if (avs->curr_sample + samples > avs->vi->num_audio_samples) samples = avs->vi->num_audio_samples - avs->curr_sample; // This must happen even if the stream is discarded to prevent desync. avs->curr_sample += samples; if (discard) return 0; pkt->pts = avs->curr_sample; pkt->dts = avs->curr_sample; pkt->duration = samples; pkt->size = avs_bytes_per_channel_sample(avs->vi) * samples * avs->vi->nchannels; if (!pkt->size) return AVERROR_UNKNOWN; pkt->data = av_malloc(pkt->size); if (!pkt->data) return AVERROR_UNKNOWN; avs_library->avs_get_audio(avs->clip, pkt->data, avs->curr_sample, samples); error = avs_library->avs_clip_get_error(avs->clip); if (error) { av_log(s, AV_LOG_ERROR, "%s\n", error); avs->error = 1; av_freep(&pkt->data); return AVERROR_UNKNOWN; } return 0; }