av_cold void ff_blockdsp_init_x86(BlockDSPContext *c, AVCodecContext *avctx) #else av_cold void ff_blockdsp_init_x86(BlockDSPContext *c) #endif /* FF_API_XVMC */ { #if HAVE_INLINE_ASM int cpu_flags = av_get_cpu_flags(); if (INLINE_MMX(cpu_flags)) { c->clear_block = clear_block_mmx; c->clear_blocks = clear_blocks_mmx; } #if FF_API_XVMC FF_DISABLE_DEPRECATION_WARNINGS /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */ if (CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1) return; FF_ENABLE_DEPRECATION_WARNINGS #endif /* FF_API_XVMC */ if (INLINE_SSE(cpu_flags)) { c->clear_block = clear_block_sse; c->clear_blocks = clear_blocks_sse; } #endif /* HAVE_INLINE_ASM */ }


static int read_bfraction(VC1Context *v, GetBitContext* gb) { v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; return 0; }


AVStream *add_video_stream(AVFormatContext *oc, int codec_id) { AVCodec *codec; AVCodecContext *c; AVStream *st; uint8_t *picture_buf; int size; st = av_new_stream(oc, 0); if (!st) { fprintf(stderr, "Could not alloc stream\n"); exit(1); } /* find the mpeg1 video encoder */ codec = avcodec_find_encoder(codec_id); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } c = &st->codec; c->codec_type = CODEC_TYPE_VIDEO; /* put sample parameters */ c->bit_rate = 400000; /* resolution must be a multiple of two */ c->width = 352; c->height = 288; /* frames per second */ c->frame_rate = 25; c->frame_rate_base= 1; c->gop_size = 12; /* emit one intra frame every twelve frames */ /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } /* alloc various buffers */ picture= avcodec_alloc_frame(); video_outbuf_size = 100000; video_outbuf = malloc(video_outbuf_size); size = c->width * c->height; picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */ picture->data[0] = picture_buf; picture->data[1] = picture->data[0] + size; picture->data[2] = picture->data[1] + size / 4; picture->linesize[0] = c->width; picture->linesize[1] = c->width / 2; picture->linesize[2] = c->width / 2; return st; }


const uint8_t *get_submv_prob(uint32_t left, uint32_t top) { if (left == top) return vp8_submv_prob[4 - !!left]; if (!top) return vp8_submv_prob[2]; return vp8_submv_prob[1 - !!left]; }


static inline void cpu_handle_interrupt(CPUState *cpu, TranslationBlock **last_tb) { CPUClass *cc = CPU_GET_CLASS(cpu); int interrupt_request = cpu->interrupt_request; if (unlikely(interrupt_request)) { if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) { /* Mask out external interrupts for this step. */ interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; } if (interrupt_request & CPU_INTERRUPT_DEBUG) { cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG; cpu->exception_index = EXCP_DEBUG; cpu_loop_exit(cpu); } if (replay_mode == REPLAY_MODE_PLAY && !replay_has_interrupt()) { /* Do nothing */ } else if (interrupt_request & CPU_INTERRUPT_HALT) { replay_interrupt(); cpu->interrupt_request &= ~CPU_INTERRUPT_HALT; cpu->halted = 1; cpu->exception_index = EXCP_HLT; cpu_loop_exit(cpu); } #if defined(TARGET_I386) else if (interrupt_request & CPU_INTERRUPT_INIT) { X86CPU *x86_cpu = X86_CPU(cpu); CPUArchState *env = &x86_cpu->env; replay_interrupt(); cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0); do_cpu_init(x86_cpu); cpu->exception_index = EXCP_HALTED; cpu_loop_exit(cpu); } #else else if (interrupt_request & CPU_INTERRUPT_RESET) { replay_interrupt(); cpu_reset(cpu); cpu_loop_exit(cpu); } #endif /* The target hook has 3 exit conditions: False when the interrupt isn't processed, True when it is, and we should restart on a new TB, and via longjmp via cpu_loop_exit. */ else { replay_interrupt(); if (cc->cpu_exec_interrupt(cpu, interrupt_request)) { *last_tb = NULL; } /* The target hook may have updated the 'cpu->interrupt_request'; * reload the 'interrupt_request' value */ interrupt_request = cpu->interrupt_request; } if (interrupt_request & CPU_INTERRUPT_EXITTB) { cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB; /* ensure that no TB jump will be modified as the program flow was changed */ *last_tb = NULL; } } if (unlikely(cpu->exit_request || replay_has_interrupt())) { cpu->exit_request = 0; cpu->exception_index = EXCP_INTERRUPT; cpu_loop_exit(cpu); } }


int qemu_get_byte(QEMUFile *f) { int result; result = qemu_peek_byte(f, 0); qemu_file_skip(f, 1); return result; }


bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) { TranslationBlock *tb; bool r = false; tb_lock(); tb = tb_find_pc(retaddr); if (tb) { cpu_restore_state_from_tb(cpu, tb, retaddr); if (tb->cflags & CF_NOCACHE) { /* one-shot translation, invalidate it immediately */ tb_phys_invalidate(tb, -1); tb_free(tb); r = true; tb_unlock();


pflash_t *pflash_cfi01_register(target_phys_addr_t base, DeviceState *qdev, const char *name, target_phys_addr_t size, BlockDriverState *bs, uint32_t sector_len, int nb_blocs, int width, uint16_t id0, uint16_t id1, uint16_t id2, uint16_t id3, int be) { pflash_t *pfl; target_phys_addr_t total_len; int ret; total_len = sector_len * nb_blocs; /* XXX: to be fixed */ #if 0 if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) && total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024)) return NULL; #endif pfl = g_malloc0(sizeof(pflash_t)); memory_region_init_rom_device( &pfl->mem, be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl, name, size); vmstate_register_ram(&pfl->mem, qdev); pfl->storage = memory_region_get_ram_ptr(&pfl->mem); memory_region_add_subregion(get_system_memory(), base, &pfl->mem); pfl->bs = bs; if (pfl->bs) { /* read the initial flash content */ ret = bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9); if (ret < 0) { memory_region_del_subregion(get_system_memory(), &pfl->mem); vmstate_unregister_ram(&pfl->mem, qdev); memory_region_destroy(&pfl->mem); g_free(pfl); return NULL; } bdrv_attach_dev_nofail(pfl->bs, pfl); } if (pfl->bs) { pfl->ro = bdrv_is_read_only(pfl->bs); } else { pfl->ro = 0; } pfl->timer = qemu_new_timer_ns(vm_clock, pflash_timer, pfl); pfl->base = base; pfl->sector_len = sector_len; pfl->total_len = total_len; pfl->width = width; pfl->wcycle = 0; pfl->cmd = 0; pfl->status = 0; pfl->ident[0] = id0; pfl->ident[1] = id1; pfl->ident[2] = id2; pfl->ident[3] = id3; /* Hardcoded CFI table */ pfl->cfi_len = 0x52; /* Standard "QRY" string */ pfl->cfi_table[0x10] = 'Q'; pfl->cfi_table[0x11] = 'R'; pfl->cfi_table[0x12] = 'Y'; /* Command set (Intel) */ pfl->cfi_table[0x13] = 0x01; pfl->cfi_table[0x14] = 0x00; /* Primary extended table address (none) */ pfl->cfi_table[0x15] = 0x31; pfl->cfi_table[0x16] = 0x00; /* Alternate command set (none) */ pfl->cfi_table[0x17] = 0x00; pfl->cfi_table[0x18] = 0x00; /* Alternate extended table (none) */ pfl->cfi_table[0x19] = 0x00; pfl->cfi_table[0x1A] = 0x00; /* Vcc min */ pfl->cfi_table[0x1B] = 0x45; /* Vcc max */ pfl->cfi_table[0x1C] = 0x55; /* Vpp min (no Vpp pin) */ pfl->cfi_table[0x1D] = 0x00; /* Vpp max (no Vpp pin) */ pfl->cfi_table[0x1E] = 0x00; /* Reserved */ pfl->cfi_table[0x1F] = 0x07; /* Timeout for min size buffer write */ pfl->cfi_table[0x20] = 0x07; /* Typical timeout for block erase */ pfl->cfi_table[0x21] = 0x0a; /* Typical timeout for full chip erase (4096 ms) */ pfl->cfi_table[0x22] = 0x00; /* Reserved */ pfl->cfi_table[0x23] = 0x04; /* Max timeout for buffer write */ pfl->cfi_table[0x24] = 0x04; /* Max timeout for block erase */ pfl->cfi_table[0x25] = 0x04; /* Max timeout for chip erase */ pfl->cfi_table[0x26] = 0x00; /* Device size */ pfl->cfi_table[0x27] = ctz32(total_len); // + 1; /* Flash device interface (8 & 16 bits) */ pfl->cfi_table[0x28] = 0x02; pfl->cfi_table[0x29] = 0x00; /* Max number of bytes in multi-bytes write */ if (width == 1) { pfl->cfi_table[0x2A] = 0x08; } else { pfl->cfi_table[0x2A] = 0x0B; } pfl->writeblock_size = 1 << pfl->cfi_table[0x2A]; pfl->cfi_table[0x2B] = 0x00; /* Number of erase block regions (uniform) */ pfl->cfi_table[0x2C] = 0x01; /* Erase block region 1 */ pfl->cfi_table[0x2D] = nb_blocs - 1; pfl->cfi_table[0x2E] = (nb_blocs - 1) >> 8; pfl->cfi_table[0x2F] = sector_len >> 8; pfl->cfi_table[0x30] = sector_len >> 16; /* Extended */ pfl->cfi_table[0x31] = 'P'; pfl->cfi_table[0x32] = 'R'; pfl->cfi_table[0x33] = 'I'; pfl->cfi_table[0x34] = '1'; pfl->cfi_table[0x35] = '1'; pfl->cfi_table[0x36] = 0x00; pfl->cfi_table[0x37] = 0x00; pfl->cfi_table[0x38] = 0x00; pfl->cfi_table[0x39] = 0x00; pfl->cfi_table[0x3a] = 0x00; pfl->cfi_table[0x3b] = 0x00; pfl->cfi_table[0x3c] = 0x00; return pfl; }


static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr, UHCI_TD *td, uint32_t td_addr, uint32_t *int_mask) { int len = 0, max_len; bool spd; bool queuing = (q != NULL); uint8_t pid = td->token & 0xff; UHCIAsync *async = uhci_async_find_td(s, td_addr); if (async) { if (uhci_queue_verify(async->queue, qh_addr, td, td_addr, queuing)) { assert(q == NULL || q == async->queue); q = async->queue; } else { uhci_queue_free(async->queue, "guest re-used pending td"); async = NULL; if (q == NULL) { q = uhci_queue_find(s, td); if (q && !uhci_queue_verify(q, qh_addr, td, td_addr, queuing)) { uhci_queue_free(q, "guest re-used qh"); q = NULL; if (q) { q->valid = 32; /* Is active ? */ if (!(td->ctrl & TD_CTRL_ACTIVE)) { if (async) { /* Guest marked a pending td non-active, cancel the queue */ uhci_queue_free(async->queue, "pending td non-active"); /* * ehci11d spec page 22: "Even if the Active bit in the TD is already * cleared when the TD is fetched ... an IOC interrupt is generated" */ if (td->ctrl & TD_CTRL_IOC) { *int_mask |= 0x01; return TD_RESULT_NEXT_QH; if (async) { if (queuing) { /* we are busy filling the queue, we are not prepared to consume completed packages then, just leave them in async state */ return TD_RESULT_ASYNC_CONT; if (!async->done) { UHCI_TD last_td; UHCIAsync *last = QTAILQ_LAST(&async->queue->asyncs, asyncs_head); /* * While we are waiting for the current td to complete, the guest * may have added more tds to the queue. Note we re-read the td * rather then caching it, as we want to see guest made changes! */ uhci_read_td(s, &last_td, last->td_addr); uhci_queue_fill(async->queue, &last_td); return TD_RESULT_ASYNC_CONT; uhci_async_unlink(async); goto done; /* Allocate new packet */ if (q == NULL) { USBDevice *dev = uhci_find_device(s, (td->token >> 8) & 0x7f); USBEndpoint *ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); q = uhci_queue_new(s, qh_addr, td, ep); async = uhci_async_alloc(q, td_addr); max_len = ((td->token >> 21) + 1) & 0x7ff; spd = (pid == USB_TOKEN_IN && (td->ctrl & TD_CTRL_SPD) != 0); usb_packet_setup(&async->packet, pid, q->ep, td_addr, spd, (td->ctrl & TD_CTRL_IOC) != 0); qemu_sglist_add(&async->sgl, td->buffer, max_len); usb_packet_map(&async->packet, &async->sgl); switch(pid) { case USB_TOKEN_OUT: case USB_TOKEN_SETUP: len = usb_handle_packet(q->ep->dev, &async->packet); if (len >= 0) len = max_len; break; case USB_TOKEN_IN: len = usb_handle_packet(q->ep->dev, &async->packet); break; default: /* invalid pid : frame interrupted */ usb_packet_unmap(&async->packet, &async->sgl); uhci_async_free(async); s->status |= UHCI_STS_HCPERR; uhci_update_irq(s); return TD_RESULT_STOP_FRAME; if (len == USB_RET_ASYNC) { uhci_async_link(async); if (!queuing) { uhci_queue_fill(q, td); return TD_RESULT_ASYNC_START; async->packet.result = len; done: len = uhci_complete_td(s, td, async, int_mask); usb_packet_unmap(&async->packet, &async->sgl); uhci_async_free(async); return len;


static int writev_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag = false, qflag = false; int flags = 0; int c, cnt; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int nr_iov; int pattern = 0xcd; QEMUIOVector qiov; while ((c = getopt(argc, argv, "CqP:")) != -1) { switch (c) { case 'C': Cflag = true; break; case 'f': flags |= BDRV_REQ_FUA; break; case 'q': qflag = true; 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); } offset = cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); return 0; } optind++; nr_iov = argc - optind; buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); if (buf == NULL) { return 0; } gettimeofday(&t1, NULL); cnt = do_aio_writev(blk, &qiov, offset, flags, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("writev 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, offset, qiov.size, total, cnt, Cflag); out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); return 0; }


libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample) { libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); enum dshowDeviceType devtype = pin->filter->type; void *priv_data; uint8_t *buf; int buf_size; int index; int64_t curtime; dshowdebug("libAVMemInputPin_Receive(%p)\n", this); if (!sample) return E_POINTER; if (devtype == VideoDevice) { /* PTS from video devices is unreliable. */ IReferenceClock *clock = pin->filter->clock; IReferenceClock_GetTime(clock, &curtime); } else { int64_t dummy; IMediaSample_GetTime(sample, &curtime, &dummy); curtime += pin->filter->start_time; } buf_size = IMediaSample_GetActualDataLength(sample); IMediaSample_GetPointer(sample, &buf); priv_data = pin->filter->priv_data; index = pin->filter->stream_index; pin->filter->callback(priv_data, index, buf, buf_size, curtime); return S_OK; }


static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const uint8_t *data, int size) { VP9Context *s = avctx->priv_data; int ret, tile_row, tile_col, i, ref = -1, row, col; ptrdiff_t yoff = 0, uvoff = 0; ret = decode_frame_header(avctx, data, size, &ref); if (ret < 0) { return ret; } else if (!ret) { if (!s->refs[ref]->buf[0]) { av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref); return AVERROR_INVALIDDATA; } ret = av_frame_ref(frame, s->refs[ref]); if (ret < 0) return ret; *got_frame = 1; return 0; } data += ret; size -= ret; s->cur_frame = frame; av_frame_unref(s->cur_frame); if ((ret = ff_get_buffer(avctx, s->cur_frame, s->refreshrefmask ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) return ret; s->cur_frame->key_frame = s->keyframe; s->cur_frame->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; // main tile decode loop memset(s->above_partition_ctx, 0, s->cols); memset(s->above_skip_ctx, 0, s->cols); if (s->keyframe || s->intraonly) memset(s->above_mode_ctx, DC_PRED, s->cols * 2); else memset(s->above_mode_ctx, NEARESTMV, s->cols); memset(s->above_y_nnz_ctx, 0, s->sb_cols * 16); memset(s->above_uv_nnz_ctx[0], 0, s->sb_cols * 8); memset(s->above_uv_nnz_ctx[1], 0, s->sb_cols * 8); memset(s->above_segpred_ctx, 0, s->cols); for (tile_row = 0; tile_row < s->tiling.tile_rows; tile_row++) { set_tile_offset(&s->tiling.tile_row_start, &s->tiling.tile_row_end, tile_row, s->tiling.log2_tile_rows, s->sb_rows); for (tile_col = 0; tile_col < s->tiling.tile_cols; tile_col++) { int64_t tile_size; if (tile_col == s->tiling.tile_cols - 1 && tile_row == s->tiling.tile_rows - 1) { tile_size = size; } else { tile_size = AV_RB32(data); data += 4; size -= 4; } if (tile_size > size) return AVERROR_INVALIDDATA; ff_vp56_init_range_decoder(&s->c_b[tile_col], data, tile_size); if (vp56_rac_get_prob_branchy(&s->c_b[tile_col], 128)) // marker bit return AVERROR_INVALIDDATA; data += tile_size; size -= tile_size; } for (row = s->tiling.tile_row_start; row < s->tiling.tile_row_end; row += 8, yoff += s->cur_frame->linesize[0] * 64, uvoff += s->cur_frame->linesize[1] * 32) { VP9Filter *lflvl = s->lflvl; ptrdiff_t yoff2 = yoff, uvoff2 = uvoff; for (tile_col = 0; tile_col < s->tiling.tile_cols; tile_col++) { set_tile_offset(&s->tiling.tile_col_start, &s->tiling.tile_col_end, tile_col, s->tiling.log2_tile_cols, s->sb_cols); memset(s->left_partition_ctx, 0, 8); memset(s->left_skip_ctx, 0, 8); if (s->keyframe || s->intraonly) memset(s->left_mode_ctx, DC_PRED, 16); else memset(s->left_mode_ctx, NEARESTMV, 8); memset(s->left_y_nnz_ctx, 0, 16); memset(s->left_uv_nnz_ctx, 0, 16); memset(s->left_segpred_ctx, 0, 8); memcpy(&s->c, &s->c_b[tile_col], sizeof(s->c)); for (col = s->tiling.tile_col_start; col < s->tiling.tile_col_end; col += 8, yoff2 += 64, uvoff2 += 32, lflvl++) { // FIXME integrate with lf code (i.e. zero after each // use, similar to invtxfm coefficients, or similar) memset(lflvl->mask, 0, sizeof(lflvl->mask)); if ((ret = decode_subblock(avctx, row, col, lflvl, yoff2, uvoff2, BL_64X64)) < 0) return ret; } memcpy(&s->c_b[tile_col], &s->c, sizeof(s->c)); } // backup pre-loopfilter reconstruction data for intra // prediction of next row of sb64s if (row + 8 < s->rows) { memcpy(s->intra_pred_data[0], s->cur_frame->data[0] + yoff + 63 * s->cur_frame->linesize[0], 8 * s->cols); memcpy(s->intra_pred_data[1], s->cur_frame->data[1] + uvoff + 31 * s->cur_frame->linesize[1], 4 * s->cols); memcpy(s->intra_pred_data[2], s->cur_frame->data[2] + uvoff + 31 * s->cur_frame->linesize[2], 4 * s->cols); } // loopfilter one row if (s->filter.level) { yoff2 = yoff; uvoff2 = uvoff; lflvl = s->lflvl; for (col = 0; col < s->cols; col += 8, yoff2 += 64, uvoff2 += 32, lflvl++) loopfilter_subblock(avctx, lflvl, row, col, yoff2, uvoff2); } } } // bw adaptivity (or in case of parallel decoding mode, fw adaptivity // probability maintenance between frames) if (s->refreshctx) { if (s->parallelmode) { memcpy(s->prob_ctx[s->framectxid].coef, s->prob.coef, sizeof(s->prob.coef)); s->prob_ctx[s->framectxid].p = s->prob.p; } else { ff_vp9_adapt_probs(s); } } FFSWAP(VP9MVRefPair *, s->mv[0], s->mv[1]); // ref frame setup for (i = 0; i < 8; i++) if (s->refreshrefmask & (1 << i)) { av_frame_unref(s->refs[i]); ret = av_frame_ref(s->refs[i], s->cur_frame); if (ret < 0) return ret; } if (s->invisible) av_frame_unref(s->cur_frame); else *got_frame = 1; return 0; }


static int parallels_open(BlockDriverState *bs, int flags) { BDRVParallelsState *s = bs->opaque; int i; struct parallels_header ph; bs->read_only = 1; // no write support yet if (bdrv_pread(bs->file, 0, &ph, sizeof(ph)) != sizeof(ph)) goto fail; if (memcmp(ph.magic, HEADER_MAGIC, 16) || (le32_to_cpu(ph.version) != HEADER_VERSION)) { goto fail; } bs->total_sectors = le32_to_cpu(ph.nb_sectors); s->tracks = le32_to_cpu(ph.tracks); s->catalog_size = le32_to_cpu(ph.catalog_entries); s->catalog_bitmap = g_malloc(s->catalog_size * 4); if (bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4) != s->catalog_size * 4) goto fail; for (i = 0; i < s->catalog_size; i++) le32_to_cpus(&s->catalog_bitmap[i]); qemu_co_mutex_init(&s->lock); return 0; fail: if (s->catalog_bitmap) g_free(s->catalog_bitmap); return -1; }


int inet_aton (const char * str, struct in_addr * add) { const char * pch = str; unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; add1 = atoi(pch); pch = strpbrk(pch,"."); if (pch == 0 || ++pch == 0) goto done; add2 = atoi(pch); pch = strpbrk(pch,"."); if (pch == 0 || ++pch == 0) goto done; add3 = atoi(pch); pch = strpbrk(pch,"."); if (pch == 0 || ++pch == 0) goto done; add4 = atoi(pch); done: add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; return 1; }


static void pci_indirect(void) { QVirtioPCIDevice *dev; QPCIBus *bus; QVirtQueuePCI *vqpci; QGuestAllocator *alloc; QVirtioBlkReq req; QVRingIndirectDesc *indirect; void *addr; uint64_t req_addr; uint64_t capacity; uint32_t features; uint32_t free_head; uint8_t status; char *data; bus = test_start(); dev = virtio_blk_init(bus); /* MSI-X is not enabled */ addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_NO_MSIX; capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features = qvirtio_get_features(&qvirtio_pci, &dev->vdev); g_assert_cmphex(features & QVIRTIO_F_RING_INDIRECT_DESC, !=, 0); features = features & ~(QVIRTIO_F_BAD_FEATURE | QVIRTIO_F_RING_EVENT_IDX | QVIRTIO_BLK_F_SCSI); qvirtio_set_features(&qvirtio_pci, &dev->vdev, features); alloc = pc_alloc_init(); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev, alloc, 0); qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev); /* Write request */ req.type = QVIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); strcpy(req.data, "TEST"); req_addr = virtio_blk_request(alloc, &req, 512); g_free(req.data); indirect = qvring_indirect_desc_setup(&dev->vdev, alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); g_assert(qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, QVIRTIO_BLK_TIMEOUT)); status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); g_free(indirect); guest_free(alloc, req_addr); /* Read request */ req.type = QVIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); strcpy(req.data, "TEST"); req_addr = virtio_blk_request(alloc, &req, 512); g_free(req.data); indirect = qvring_indirect_desc_setup(&dev->vdev, alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); g_assert(qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, QVIRTIO_BLK_TIMEOUT)); status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); data = g_malloc0(512); memread(req_addr + 16, data, 512); g_assert_cmpstr(data, ==, "TEST"); g_free(data); g_free(indirect); guest_free(alloc, req_addr); /* End test */ guest_free(alloc, vqpci->vq.desc); qvirtio_pci_device_disable(dev); g_free(dev); test_end(); }


static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) { int i; for (i = 0; i < vs->num_queues + 2; i++) { qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], vs->qs->alloc); } qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev)); g_free(vs->dev); qvirtio_scsi_stop(vs->qs); g_free(vs); }


static void *circular_buffer_task_tx( void *_URLContext) { URLContext *h = _URLContext; UDPContext *s = h->priv_data; int old_cancelstate; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate); for(;;) { int len; uint8_t tmp[4]; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelstate); av_usleep(s->packet_gap); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate); pthread_mutex_lock(&s->mutex); len=av_fifo_size(s->fifo); while (len<4) { if (pthread_cond_wait(&s->cond, &s->mutex) < 0) { goto end; } len=av_fifo_size(s->fifo); } av_fifo_generic_peek(s->fifo, tmp, 4, NULL); len=AV_RL32(tmp); if (len>0 && av_fifo_size(s->fifo)>=len+4) { av_fifo_drain(s->fifo, 4); /* skip packet length */ av_fifo_generic_read(s->fifo, h, len, do_udp_write); /* use function for write from fifo buffer */ if (s->circular_buffer_error == len) { /* all ok - reset error */ s->circular_buffer_error=0; } } pthread_mutex_unlock(&s->mutex); } end: pthread_mutex_unlock(&s->mutex); return NULL; }


int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int max_shift, int zero_shift) { double autoc[MAX_LPC_ORDER+1]; double ref[MAX_LPC_ORDER]; double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER]; int i, j, pass = 0; int opt_order; av_assert2(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && lpc_type > FF_LPC_TYPE_FIXED); /* reinit LPC context if parameters have changed */ if (blocksize != s->blocksize || max_order != s->max_order || lpc_type != s->lpc_type) { ff_lpc_end(s); ff_lpc_init(s, blocksize, max_order, lpc_type); } if(lpc_passes <= 0) lpc_passes = 2; if (lpc_type == FF_LPC_TYPE_LEVINSON || (lpc_type == FF_LPC_TYPE_CHOLESKY && lpc_passes > 1)) { s->lpc_apply_welch_window(samples, blocksize, s->windowed_samples); s->lpc_compute_autocorr(s->windowed_samples, blocksize, max_order, autoc); compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1); for(i=0; i<max_order; i++) ref[i] = fabs(lpc[i][i]); pass++; } if (lpc_type == FF_LPC_TYPE_CHOLESKY) { LLSModel m[2]; LOCAL_ALIGNED(32, double, var, [FFALIGN(MAX_LPC_ORDER+1,4)]); double av_uninit(weight); memset(var, 0, FFALIGN(MAX_LPC_ORDER+1,4)*sizeof(*var)); for(j=0; j<max_order; j++) m[0].coeff[max_order-1][j] = -lpc[max_order-1][j]; for(; pass<lpc_passes; pass++){ avpriv_init_lls(&m[pass&1], max_order); weight=0; for(i=max_order; i<blocksize; i++){ for(j=0; j<=max_order; j++) var[j]= samples[i-j]; if(pass){ double eval, inv, rinv; eval= m[(pass-1)&1].evaluate_lls(&m[(pass-1)&1], var+1, max_order-1); eval= (512>>pass) + fabs(eval - var[0]); inv = 1/eval; rinv = sqrt(inv); for(j=0; j<=max_order; j++) var[j] *= rinv; weight += inv; }else weight++; m[pass&1].update_lls(&m[pass&1], var); } avpriv_solve_lls(&m[pass&1], 0.001, 0); } for(i=0; i<max_order; i++){ for(j=0; j<max_order; j++) lpc[i][j]=-m[(pass-1)&1].coeff[i][j]; ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000; } for(i=max_order-1; i>0; i--) ref[i] = ref[i-1] - ref[i]; } opt_order = max_order; if(omethod == ORDER_METHOD_EST) { opt_order = estimate_best_order(ref, min_order, max_order); i = opt_order-1; quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift); } else { for(i=min_order-1; i<max_order; i++) { quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift); } } return opt_order; }


static void string_deserialize(void **native_out, void *datap, VisitorFunc visit, Error **errp) { StringSerializeData *d = datap; d->siv = string_input_visitor_new(string_output_get_string(d->sov)); visit(string_input_get_visitor(d->siv), native_out, errp); }


static int rtp_read_header(AVFormatContext *s) { uint8_t recvbuf[RTP_MAX_PACKET_LENGTH]; char host[500], sdp[500]; int ret, port; URLContext* in = NULL; int payload_type; AVCodecContext codec = { 0 }; struct sockaddr_storage addr; AVIOContext pb; socklen_t addrlen = sizeof(addr); RTSPState *rt = s->priv_data; if (!ff_network_init()) return AVERROR(EIO); if (!rt->protocols) { rt->protocols = ffurl_get_protocols(NULL, NULL); if (!rt->protocols) return AVERROR(ENOMEM); } ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ, &s->interrupt_callback, NULL, rt->protocols); if (ret) goto fail; while (1) { ret = ffurl_read(in, recvbuf, sizeof(recvbuf)); if (ret == AVERROR(EAGAIN)) continue; if (ret < 0) goto fail; if (ret < 12) { av_log(s, AV_LOG_WARNING, "Received too short packet\n"); continue; } if ((recvbuf[0] & 0xc0) != 0x80) { av_log(s, AV_LOG_WARNING, "Unsupported RTP version packet " "received\n"); continue; } if (RTP_PT_IS_RTCP(recvbuf[1])) continue; payload_type = recvbuf[1] & 0x7f; break; } getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen); ffurl_close(in); in = NULL; if (ff_rtp_get_codec_info(&codec, payload_type)) { av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d " "without an SDP file describing it\n", payload_type); goto fail; } if (codec.codec_type != AVMEDIA_TYPE_DATA) { av_log(s, AV_LOG_WARNING, "Guessing on RTP content - if not received " "properly you need an SDP file " "describing it\n"); } av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, s->filename); snprintf(sdp, sizeof(sdp), "v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n", addr.ss_family == AF_INET ? 4 : 6, host, codec.codec_type == AVMEDIA_TYPE_DATA ? "application" : codec.codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio", port, payload_type); av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp); ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL); s->pb = &pb; /* sdp_read_header initializes this again */ ff_network_close(); rt->media_type_mask = (1 << (AVMEDIA_TYPE_DATA+1)) - 1; ret = sdp_read_header(s); s->pb = NULL; return ret; fail: if (in) ffurl_close(in); ff_network_close(); return ret; }


static void qemu_aio_wait_all(void) { while (aio_poll(ctx, true)) { /* Do nothing */ } }


static int send_invoke_response(URLContext *s, RTMPPacket *pkt) { RTMPContext *rt = s->priv_data; double seqnum; char filename[64]; char command[64]; int stringlen; char *pchar; const uint8_t *p = pkt->data; uint8_t *pp = NULL; RTMPPacket spkt = { 0 }; GetByteContext gbc; int ret; bytestream2_init(&gbc, p, pkt->size); if (ff_amf_read_string(&gbc, command, sizeof(command), &stringlen)) { av_log(s, AV_LOG_ERROR, "Error in PT_INVOKE\n"); return AVERROR_INVALIDDATA; } ret = ff_amf_read_number(&gbc, &seqnum); if (ret) return ret; ret = ff_amf_read_null(&gbc); if (ret) return ret; if (!strcmp(command, "FCPublish") || !strcmp(command, "publish")) { ret = ff_amf_read_string(&gbc, filename, sizeof(filename), &stringlen); if (ret) { if (ret == AVERROR(EINVAL)) av_log(s, AV_LOG_ERROR, "Unable to parse stream name - name too long?\n"); else av_log(s, AV_LOG_ERROR, "Unable to parse stream name\n"); return ret; } // check with url if (s->filename) { pchar = strrchr(s->filename, '/'); if (!pchar) { av_log(s, AV_LOG_WARNING, "Unable to find / in url %s, bad format\n", s->filename); pchar = s->filename; } pchar++; if (strcmp(pchar, filename)) av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting" " %s\n", filename, pchar); } rt->state = STATE_RECEIVING; } if (!strcmp(command, "FCPublish")) { if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, RTMP_PKTDATA_DEFAULT_SIZE)) < 0) { av_log(s, AV_LOG_ERROR, "Unable to create response packet\n"); return ret; } pp = spkt.data; ff_amf_write_string(&pp, "onFCPublish"); } else if (!strcmp(command, "publish")) { ret = write_begin(s); if (ret < 0) return ret; // Send onStatus(NetStream.Publish.Start) return write_status(s, pkt, "NetStream.Publish.Start", filename); } else if (!strcmp(command, "play")) { ret = write_begin(s); if (ret < 0) return ret; rt->state = STATE_SENDING; return write_status(s, pkt, "NetStream.Play.Start", filename); } else { if ((ret = ff_rtmp_packet_create(&spkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, RTMP_PKTDATA_DEFAULT_SIZE)) < 0) { av_log(s, AV_LOG_ERROR, "Unable to create response packet\n"); return ret; } pp = spkt.data; ff_amf_write_string(&pp, "_result"); ff_amf_write_number(&pp, seqnum); ff_amf_write_null(&pp); if (!strcmp(command, "createStream")) { rt->nb_streamid++; if (rt->nb_streamid == 0 || rt->nb_streamid == 2) rt->nb_streamid++; /* Values 0 and 2 are reserved */ ff_amf_write_number(&pp, rt->nb_streamid); /* By now we don't control which streams are removed in * deleteStream. There is no stream creation control * if a client creates more than 2^32 - 2 streams. */ } } spkt.size = pp - spkt.data; ret = ff_rtmp_packet_write(rt->stream, &spkt, rt->out_chunk_size, &rt->prev_pkt[1], &rt->nb_prev_pkt[1]); ff_rtmp_packet_destroy(&spkt); return ret; }


static void coroutine_fn v9fs_open(void *opaque) { int flags; int32_t fid; int32_t mode; V9fsQID qid; int iounit = 0; ssize_t err = 0; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; if (s->proto_version == V9FS_PROTO_2000L) { err = pdu_unmarshal(pdu, offset, "dd", &fid, &mode); } else { uint8_t modebyte; err = pdu_unmarshal(pdu, offset, "db", &fid, &modebyte); mode = modebyte; } if (err < 0) { goto out_nofid; } trace_v9fs_open(pdu->tag, pdu->id, fid, mode); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } BUG_ON(fidp->fid_type != P9_FID_NONE); err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); if (S_ISDIR(stbuf.st_mode)) { err = v9fs_co_opendir(pdu, fidp); if (err < 0) { goto out; } fidp->fid_type = P9_FID_DIR; err = pdu_marshal(pdu, offset, "Qd", &qid, 0); if (err < 0) { goto out; } err += offset; } else { if (s->proto_version == V9FS_PROTO_2000L) { flags = get_dotl_openflags(s, mode); } else { flags = omode_to_uflags(mode); } if (is_ro_export(&s->ctx)) { if (mode & O_WRONLY || mode & O_RDWR || mode & O_APPEND || mode & O_TRUNC) { err = -EROFS; goto out; } } err = v9fs_co_open(pdu, fidp, flags); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = flags; if (flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } iounit = get_iounit(pdu, &fidp->path); err = pdu_marshal(pdu, offset, "Qd", &qid, iounit); if (err < 0) { goto out; } err += offset; } trace_v9fs_open_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, iounit); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }


static void init_blk_migration_it(void *opaque, BlockDriverState *bs) { BlkMigDevState *bmds; int64_t sectors; if (!bdrv_is_read_only(bs)) { sectors = bdrv_nb_sectors(bs); if (sectors <= 0) { return; } bmds = g_malloc0(sizeof(BlkMigDevState)); bmds->bs = bs; bmds->bulk_completed = 0; bmds->total_sectors = sectors; bmds->completed_sectors = 0; bmds->shared_base = block_mig_state.shared_base; alloc_aio_bitmap(bmds); error_setg(&bmds->blocker, "block device is in use by migration"); bdrv_op_block_all(bs, bmds->blocker); bdrv_ref(bs); block_mig_state.total_sector_sum += sectors; if (bmds->shared_base) { DPRINTF("Start migration for %s with shared base image\n", bs->device_name); } else { DPRINTF("Start full migration for %s\n", bs->device_name); } QSIMPLEQ_INSERT_TAIL(&block_mig_state.bmds_list, bmds, entry); } }


static void megasas_command_complete(SCSIRequest *req, uint32_t status, size_t resid) { MegasasCmd *cmd = req->hba_private; uint8_t cmd_status = MFI_STAT_OK; trace_megasas_command_complete(cmd->index, status, resid); if (req->io_canceled) { return; } if (cmd->req == NULL) { /* * Internal command complete */ cmd_status = megasas_finish_internal_dcmd(cmd, req, resid); if (cmd_status == MFI_STAT_INVALID_STATUS) { return; } } else { req->status = status; trace_megasas_scsi_complete(cmd->index, req->status, cmd->iov_size, req->cmd.xfer); if (req->status != GOOD) { cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR; } if (req->status == CHECK_CONDITION) { megasas_copy_sense(cmd); } cmd->frame->header.scsi_status = req->status; } cmd->frame->header.cmd_status = cmd_status; megasas_complete_command(cmd); }


static void GLZWDecodeInit(GifState * s, int csize) { /* read buffer */ s->eob_reached = 0; s->pbuf = s->buf; s->ebuf = s->buf; s->bbuf = 0; s->bbits = 0; /* decoder */ s->codesize = csize; s->cursize = s->codesize + 1; s->curmask = mask[s->cursize]; s->top_slot = 1 << s->cursize; s->clear_code = 1 << s->codesize; s->end_code = s->clear_code + 1; s->slot = s->newcodes = s->clear_code + 2; s->oc = s->fc = 0; s->sp = s->stack; }


SchroFrame *ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt) { AVFrame *p_pic; SchroFrame *p_frame; int y_width, uv_width; int y_height, uv_height; int i; y_width = avctx->width; y_height = avctx->height; uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt)); uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt)); p_pic = av_frame_alloc(); if (!p_pic) return NULL; if (ff_get_buffer(avctx, p_pic, AV_GET_BUFFER_FLAG_REF) < 0) { av_frame_free(&p_pic); return NULL; } p_frame = schro_frame_new(); p_frame->format = schro_frame_fmt; p_frame->width = y_width; p_frame->height = y_height; schro_frame_set_free_callback(p_frame, free_schro_frame, p_pic); for (i = 0; i < 3; ++i) { p_frame->components[i].width = i ? uv_width : y_width; p_frame->components[i].stride = p_pic->linesize[i]; p_frame->components[i].height = i ? uv_height : y_height; p_frame->components[i].length = p_frame->components[i].stride * p_frame->components[i].height; p_frame->components[i].data = p_pic->data[i]; if (i) { p_frame->components[i].v_shift = SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format); p_frame->components[i].h_shift = SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format); } } return p_frame; }


static int applehttp_open(URLContext *h, const char *uri, int flags) { AppleHTTPContext *s; int ret, i; const char *nested_url; if (flags & AVIO_FLAG_WRITE) return AVERROR(ENOSYS); s = av_mallocz(sizeof(AppleHTTPContext)); if (!s) return AVERROR(ENOMEM); h->priv_data = s; h->is_streamed = 1; if (av_strstart(uri, "applehttp+", &nested_url)) { av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl)); } else if (av_strstart(uri, "applehttp://", &nested_url)) { av_strlcpy(s->playlisturl, "http://", sizeof(s->playlisturl)); av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl)); } else { av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); ret = AVERROR(EINVAL); goto fail; } if ((ret = parse_playlist(h, s->playlisturl)) < 0) goto fail; if (s->n_segments == 0 && s->n_variants > 0) { int max_bandwidth = 0, maxvar = -1; for (i = 0; i < s->n_variants; i++) { if (s->variants[i]->bandwidth > max_bandwidth || i == 0) { max_bandwidth = s->variants[i]->bandwidth; maxvar = i; } } av_strlcpy(s->playlisturl, s->variants[maxvar]->url, sizeof(s->playlisturl)); if ((ret = parse_playlist(h, s->playlisturl)) < 0) goto fail; } if (s->n_segments == 0) { av_log(h, AV_LOG_WARNING, "Empty playlist\n"); ret = AVERROR(EIO); goto fail; } s->cur_seq_no = s->start_seq_no; if (!s->finished && s->n_segments >= 3) s->cur_seq_no = s->start_seq_no + s->n_segments - 3; return 0; fail: av_free(s); return ret; }


static int mpeg_decode_slice(AVCodecContext *avctx, AVPicture *pict, int start_code, UINT8 *buf, int buf_size) { Mpeg1Context *s1 = avctx->priv_data; MpegEncContext *s = &s1->mpeg_enc_ctx; int ret; start_code = (start_code - 1) & 0xff; if (start_code >= s->mb_height) return -1; s->last_dc[0] = 1 << (7 + s->intra_dc_precision); s->last_dc[1] = s->last_dc[0]; s->last_dc[2] = s->last_dc[0]; memset(s->last_mv, 0, sizeof(s->last_mv)); s->mb_x = -1; s->mb_y = start_code; s->mb_incr = 0; /* start frame decoding */ if (s->first_slice) { s->first_slice = 0; MPV_frame_start(s); } init_get_bits(&s->gb, buf, buf_size); s->qscale = get_qscale(s); /* extra slice info */ while (get_bits1(&s->gb) != 0) { skip_bits(&s->gb, 8); } for(;;) { clear_blocks(s->block[0]); emms_c(); ret = mpeg_decode_mb(s, s->block); dprintf("ret=%d\n", ret); if (ret < 0) return -1; if (ret == 1) break; MPV_decode_mb(s, s->block); } emms_c(); /* end of slice reached */ if (s->mb_x == (s->mb_width - 1) && s->mb_y == (s->mb_height - 1)) { /* end of image */ UINT8 **picture; MPV_frame_end(s); /* XXX: incorrect reported qscale for mpeg2 */ if (s->pict_type == B_TYPE) { picture = s->current_picture; avctx->quality = s->qscale; } else { /* latency of 1 frame for I and P frames */ /* XXX: use another variable than picture_number */ if (s->picture_number == 0) { picture = NULL; } else { picture = s->last_picture; avctx->quality = s->last_qscale; } s->last_qscale = s->qscale; s->picture_number++; } if (picture) { pict->data[0] = picture[0]; pict->data[1] = picture[1]; pict->data[2] = picture[2]; pict->linesize[0] = s->linesize; pict->linesize[1] = s->linesize / 2; pict->linesize[2] = s->linesize / 2; return 1; } else { return 0; } } else { return 0; } }


static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket * pkt, uint32_t * timestamp, const uint8_t * buf, int len, int flags) { uint8_t nal = buf[0]; uint8_t type = (nal & 0x1f); int result= 0; uint8_t start_sequence[]= {0, 0, 1}; #ifdef DEBUG assert(data); assert(data->cookie == MAGIC_COOKIE); #endif assert(buf); if (type >= 1 && type <= 23) type = 1; // simplify the case. (these are all the nal types used internally by the h264 codec) switch (type) { case 0: // undefined; result= -1; break; case 1: av_new_packet(pkt, len+sizeof(start_sequence)); memcpy(pkt->data, start_sequence, sizeof(start_sequence)); memcpy(pkt->data+sizeof(start_sequence), buf, len); #ifdef DEBUG data->packet_types_received[nal & 0x1f]++; #endif break; case 24: // STAP-A (one packet, multiple nals) // consume the STAP-A NAL buf++; len--; // first we are going to figure out the total size.... { int pass= 0; int total_length= 0; uint8_t *dst= NULL; for(pass= 0; pass<2; pass++) { const uint8_t *src= buf; int src_len= len; do { uint16_t nal_size = AV_RB16(src); // this going to be a problem if unaligned (can it be?) // consume the length of the aggregate... src += 2; src_len -= 2; if (nal_size <= src_len) { if(pass==0) { // counting... total_length+= sizeof(start_sequence)+nal_size; } else { // copying assert(dst); memcpy(dst, start_sequence, sizeof(start_sequence)); dst+= sizeof(start_sequence); memcpy(dst, src, nal_size); #ifdef DEBUG data->packet_types_received[*src & 0x1f]++; #endif dst+= nal_size; } } else { av_log(ctx, AV_LOG_ERROR, "nal size exceeds length: %d %d\n", nal_size, src_len); } // eat what we handled... src += nal_size; src_len -= nal_size; if (src_len < 0) av_log(ctx, AV_LOG_ERROR, "Consumed more bytes than we got! (%d)\n", src_len); } while (src_len > 2); // because there could be rtp padding.. if(pass==0) { // now we know the total size of the packet (with the start sequences added) av_new_packet(pkt, total_length); dst= pkt->data; } else { assert(dst-pkt->data==total_length); } } } break; case 25: // STAP-B case 26: // MTAP-16 case 27: // MTAP-24 case 29: // FU-B av_log(ctx, AV_LOG_ERROR, "Unhandled type (%d) (See RFC for implementation details\n", type); result= -1; break; case 28: // FU-A (fragmented nal) buf++; len--; // skip the fu_indicator { // these are the same as above, we just redo them here for clarity... uint8_t fu_indicator = nal; uint8_t fu_header = *buf; // read the fu_header. uint8_t start_bit = fu_header >> 7; // uint8_t end_bit = (fu_header & 0x40) >> 6; uint8_t nal_type = (fu_header & 0x1f); uint8_t reconstructed_nal; // reconstruct this packet's true nal; only the data follows.. reconstructed_nal = fu_indicator & (0xe0); // the original nal forbidden bit and NRI are stored in this packet's nal; reconstructed_nal |= nal_type; // skip the fu_header... buf++; len--; #ifdef DEBUG if (start_bit) data->packet_types_received[nal_type]++; #endif if(start_bit) { // copy in the start sequence, and the reconstructed nal.... av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len); memcpy(pkt->data, start_sequence, sizeof(start_sequence)); pkt->data[sizeof(start_sequence)]= reconstructed_nal; memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len); } else { av_new_packet(pkt, len); memcpy(pkt->data, buf, len); } } break; case 30: // undefined case 31: // undefined default: av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type); result= -1; break; } return result; }


static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) { int i; #if COMPILE_TEMPLATE_MMX if(!(c->flags & SWS_BITEXACT)) { long p= 4; const uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW}; uint8_t *dst[4]= {aDest, dest, uDest, vDest}; x86_reg counter[4]= {dstW, dstW, chrDstW, chrDstW}; if (c->flags & SWS_ACCURATE_RND) { while(p--) { if (dst[p]) { __asm__ volatile( YSCALEYUV2YV121_ACCURATE :: "r" (src[p]), "r" (dst[p] + counter[p]), "g" (-counter[p]) : "%"REG_a ); } } } else { while(p--) { if (dst[p]) { __asm__ volatile( YSCALEYUV2YV121 :: "r" (src[p]), "r" (dst[p] + counter[p]), "g" (-counter[p]) : "%"REG_a ); } } } return; } #endif for (i=0; i<dstW; i++) { int val= (lumSrc[i]+64)>>7; if (val&256) { if (val<0) val=0; else val=255; } dest[i]= val; } if (uDest) for (i=0; i<chrDstW; i++) { int u=(chrSrc[i ]+64)>>7; int v=(chrSrc[i + VOFW]+64)>>7; if ((u|v)&256) { if (u<0) u=0; else if (u>255) u=255; if (v<0) v=0; else if (v>255) v=255; } uDest[i]= u; vDest[i]= v; } if (CONFIG_SWSCALE_ALPHA && aDest) for (i=0; i<dstW; i++) { int val= (alpSrc[i]+64)>>7; aDest[i]= av_clip_uint8(val); } }


static int interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy) { int work[10]; int b = NBLOCKS - a; int i; // Interpolate block coefficients from the this frame's forth block and // last frame's forth block. for (i=0; i<30; i++) out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2; if (eval_refl(work, out, ractx)) { // The interpolated coefficients are unstable, copy either new or old // coefficients. int_to_int16(out, ractx->lpc_coef[copyold]); return rescale_rms(ractx->lpc_refl_rms[copyold], energy); } else { return rescale_rms(rms(work), energy); } }


static int dv_extract_audio(uint8_t *frame, uint8_t *ppcm[4], const DVprofile *sys) { int size, chan, i, j, d, of, smpls, freq, quant, half_ch; uint16_t lc, rc; const uint8_t *as_pack; uint8_t *pcm, ipcm; as_pack = dv_extract_pack(frame, dv_audio_source); if (!as_pack) /* No audio ? */ return 0; smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ freq = as_pack[4] >> 3 & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */ quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ if (quant > 1) return -1; /* unsupported quantization */ if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency)) return AVERROR_INVALIDDATA; size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ half_ch = sys->difseg_size / 2; /* We work with 720p frames split in half, thus even frames have * channels 0,1 and odd 2,3. */ ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0; /* for each DIF channel */ for (chan = 0; chan < sys->n_difchan; chan++) { /* next stereo channel (50Mbps and 100Mbps only) */ pcm = ppcm[ipcm++]; if (!pcm) break; /* for each DIF segment */ for (i = 0; i < sys->difseg_size; i++) { frame += 6 * 80; /* skip DIF segment header */ if (quant == 1 && i == half_ch) { /* next stereo channel (12bit mode only) */ pcm = ppcm[ipcm++]; if (!pcm) break; } /* for each AV sequence */ for (j = 0; j < 9; j++) { for (d = 8; d < 80; d += 2) { if (quant == 0) { /* 16bit quantization */ of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride; if (of * 2 >= size) continue; /* FIXME: maybe we have to admit that DV is a * big-endian PCM */ pcm[of * 2] = frame[d + 1]; pcm[of * 2 + 1] = frame[d]; if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00) pcm[of * 2 + 1] = 0; } else { /* 12bit quantization */ lc = ((uint16_t)frame[d] << 4) | ((uint16_t)frame[d + 2] >> 4); rc = ((uint16_t)frame[d + 1] << 4) | ((uint16_t)frame[d + 2] & 0x0f); lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); of = sys->audio_shuffle[i % half_ch][j] + (d - 8) / 3 * sys->audio_stride; if (of * 2 >= size) continue; /* FIXME: maybe we have to admit that DV is a * big-endian PCM */ pcm[of * 2] = lc & 0xff; pcm[of * 2 + 1] = lc >> 8; of = sys->audio_shuffle[i % half_ch + half_ch][j] + (d - 8) / 3 * sys->audio_stride; /* FIXME: maybe we have to admit that DV is a * big-endian PCM */ pcm[of * 2] = rc & 0xff; pcm[of * 2 + 1] = rc >> 8; ++d; } } frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ } } } return size; }


void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) { if (min_size < *size) return ptr; min_size = FFMAX(17 * min_size / 16 + 32, min_size); ptr = av_realloc(ptr, min_size); /* we could set this to the unmodified min_size but this is safer * if the user lost the ptr and uses NULL now */ if (!ptr) min_size = 0; *size = min_size; return ptr; }


static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block, int index, const int type) { static const uint8_t *const scan_patterns[4] = { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan }; int run, level, sign, vlc, limit; const int intra = 3 * type >> 2; const uint8_t *const scan = scan_patterns[type]; for (limit = (16 >> intra); index < 16; index = limit, limit += 8) { for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) { if (vlc == INVALID_VLC) return -1; sign = (vlc & 0x1) - 1; vlc = vlc + 1 >> 1; if (type == 3) { if (vlc < 3) { run = 0; level = vlc; } else if (vlc < 4) { run = 1; level = 1; } else { run = vlc & 0x3; level = (vlc + 9 >> 2) - run; } } else { if (vlc < 16) { run = svq3_dct_tables[intra][vlc].run; level = svq3_dct_tables[intra][vlc].level; } else if (intra) { run = vlc & 0x7; level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1))); } else { run = vlc & 0xF; level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0))); } } if ((index += run) >= limit) return -1; block[scan[index]] = (level ^ sign) - sign; } if (type != 2) { break; } } return 0; }


static int flac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { FLACContext *s = avctx->priv_data; int metadata_last, metadata_type, metadata_size; int tmp = 0, i, j = 0, input_buf_size; int16_t *samples = data, *left, *right; *data_size = 0; s->avctx = avctx; if(s->max_framesize == 0){ s->max_framesize= 8192; // should hopefully be enough for the first header s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); } if(1 && s->max_framesize){//FIXME truncated buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); input_buf_size= buf_size; if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ // printf("memmove\n"); memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); s->bitstream_index=0; } memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); buf= &s->bitstream[s->bitstream_index]; buf_size += s->bitstream_size; s->bitstream_size= buf_size; if(buf_size < s->max_framesize){ // printf("wanna more data ...\n"); return input_buf_size; } } init_get_bits(&s->gb, buf, buf_size*8); /* fLaC signature (be) */ if (show_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("fLaC"))) { skip_bits(&s->gb, 32); av_log(s->avctx, AV_LOG_DEBUG, "STREAM HEADER\n"); do { metadata_last = get_bits(&s->gb, 1); metadata_type = get_bits(&s->gb, 7); metadata_size = get_bits_long(&s->gb, 24); av_log(s->avctx, AV_LOG_DEBUG, " metadata block: flag = %d, type = %d, size = %d\n", metadata_last, metadata_type, metadata_size); if(metadata_size){ switch(metadata_type) { case METADATA_TYPE_STREAMINFO: if(metadata_size == 0) av_log(s->avctx, AV_LOG_DEBUG, "size= 0 WTF!?\n"); metadata_streaminfo(s); dump_headers(s); break; default: for(i=0; i<metadata_size; i++) skip_bits(&s->gb, 8); } } } while(!metadata_last); } else { tmp = show_bits(&s->gb, 16); if(tmp != 0xFFF8){ av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); while(get_bits_count(&s->gb)/8+2 < buf_size && show_bits(&s->gb, 16) != 0xFFF8) skip_bits(&s->gb, 8); goto end; // we may not have enough bits left to decode a frame, so try next time } skip_bits(&s->gb, 16); if (decode_frame(s) < 0) return -1; } #if 0 /* fix the channel order here */ if (s->order == MID_SIDE) { short *left = samples; short *right = samples + s->blocksize; for (i = 0; i < s->blocksize; i += 2) { uint32_t x = s->decoded[0][i]; uint32_t y = s->decoded[0][i+1]; right[i] = x - (y / 2); left[i] = right[i] + y; } *data_size = 2 * s->blocksize; } else { for (i = 0; i < s->channels; i++) { switch(s->order) { case INDEPENDENT: for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[i][j]; break; case LEFT_SIDE: case RIGHT_SIDE: if (i == 0) for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[0][j]; else for (j = 0; j < s->blocksize; j++) samples[(s->blocksize*i)+j] = s->decoded[0][j] - s->decoded[i][j]; break; // case MID_SIDE: // av_log(s->avctx, AV_LOG_DEBUG, "mid-side unsupported\n"); } *data_size += s->blocksize; } } #else switch(s->order) { case INDEPENDENT: for (j = 0; j < s->blocksize; j++) { for (i = 0; i < s->channels; i++) *(samples++) = s->decoded[i][j]; } break; case LEFT_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { *(samples++) = s->decoded[0][i]; *(samples++) = s->decoded[0][i] - s->decoded[1][i]; } break; case RIGHT_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { *(samples++) = s->decoded[0][i] + s->decoded[1][i]; *(samples++) = s->decoded[1][i]; } break; case MID_SIDE: assert(s->channels == 2); for (i = 0; i < s->blocksize; i++) { int mid, side; mid = s->decoded[0][i]; side = s->decoded[1][i]; mid <<= 1; if (side & 1) mid++; *(samples++) = (mid + side) >> 1; *(samples++) = (mid - side) >> 1; } break; } #endif *data_size = (int8_t *)samples - (int8_t *)data; av_log(s->avctx, AV_LOG_DEBUG, "data size: %d\n", *data_size); // s->last_blocksize = s->blocksize; end: i= (get_bits_count(&s->gb)+7)/8;; if(i > buf_size){ av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); return -1; } if(s->bitstream_size){ s->bitstream_index += i; s->bitstream_size -= i; return input_buf_size; }else return i; }


int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name) { switch(nb_channels) { case 1: return AV_CH_LAYOUT_MONO; case 2: return AV_CH_LAYOUT_STEREO; case 3: return AV_CH_LAYOUT_SURROUND; case 4: return AV_CH_LAYOUT_QUAD; case 5: return AV_CH_LAYOUT_5POINT0; case 6: return AV_CH_LAYOUT_5POINT1; case 8: return AV_CH_LAYOUT_7POINT1; default: return 0; } }


static inline void downmix_2f_1r_to_dolby(float *samples) { int i; for (i = 0; i < 256; i++) { samples[i] -= samples[i + 512]; samples[i + 256] += samples[i + 512]; samples[i + 512] = 0; } }


static int vc1_init_common(VC1Context *v) { static int done = 0; int i = 0; static VLC_TYPE vlc_table[32372][2]; v->hrd_rate = v->hrd_buffer = NULL; /* VLC tables */ if (!done) { INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, ff_vc1_bfraction_bits, 1, 1, ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS); INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, ff_vc1_norm2_bits, 1, 1, ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS); INIT_VLC_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64, ff_vc1_norm6_bits, 1, 1, ff_vc1_norm6_codes, 2, 2, 556); INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, ff_vc1_imode_bits, 1, 1, ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS); for (i = 0; i < 3; i++) { ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 0]]; ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i * 3 + 1] - vlc_offs[i * 3 + 0]; init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, ff_vc1_ttmb_bits[i], 1, 1, ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]]; ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1]; init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, ff_vc1_ttblk_bits[i], 1, 1, ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]]; ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2]; init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, ff_vc1_subblkpat_bits[i], 1, 1, ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); } for (i = 0; i < 4; i++) { ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 9]]; ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i * 3 + 10] - vlc_offs[i * 3 + 9]; init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, ff_vc1_4mv_block_pattern_bits[i], 1, 1, ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 10]]; ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i * 3 + 11] - vlc_offs[i * 3 + 10]; init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, ff_vc1_cbpcy_p_bits[i], 1, 1, ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 11]]; ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i * 3 + 12] - vlc_offs[i * 3 + 11]; init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, ff_vc1_mv_diff_bits[i], 1, 1, ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); } for (i = 0; i < 8; i++) { ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i * 2 + 21]]; ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i * 2 + 22] - vlc_offs[i * 2 + 21]; init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i], &vc1_ac_tables[i][0][1], 8, 4, &vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC); /* initialize interlaced MVDATA tables (2-Ref) */ ff_vc1_2ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 2 + 22]]; ff_vc1_2ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 2 + 23] - vlc_offs[i * 2 + 22]; init_vlc(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126, ff_vc1_2ref_mvdata_bits[i], 1, 1, ff_vc1_2ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC); } for (i = 0; i < 4; i++) { /* initialize 4MV MBMODE VLC tables for interlaced frame P picture */ ff_vc1_intfr_4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 37]]; ff_vc1_intfr_4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 38] - vlc_offs[i * 3 + 37]; init_vlc(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15, ff_vc1_intfr_4mv_mbmode_bits[i], 1, 1, ff_vc1_intfr_4mv_mbmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); /* initialize NON-4MV MBMODE VLC tables for the same */ ff_vc1_intfr_non4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 38]]; ff_vc1_intfr_non4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 39] - vlc_offs[i * 3 + 38]; init_vlc(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9, ff_vc1_intfr_non4mv_mbmode_bits[i], 1, 1, ff_vc1_intfr_non4mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); /* initialize interlaced MVDATA tables (1-Ref) */ ff_vc1_1ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 39]]; ff_vc1_1ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 3 + 40] - vlc_offs[i * 3 + 39]; init_vlc(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72, ff_vc1_1ref_mvdata_bits[i], 1, 1, ff_vc1_1ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC); } for (i = 0; i < 4; i++) { /* Initialize 2MV Block pattern VLC tables */ ff_vc1_2mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i + 49]]; ff_vc1_2mv_block_pattern_vlc[i].table_allocated = vlc_offs[i + 50] - vlc_offs[i + 49]; init_vlc(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4, ff_vc1_2mv_block_pattern_bits[i], 1, 1, ff_vc1_2mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); } for (i = 0; i < 8; i++) { /* Initialize interlaced CBPCY VLC tables (Table 124 - Table 131) */ ff_vc1_icbpcy_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 53]]; ff_vc1_icbpcy_vlc[i].table_allocated = vlc_offs[i * 3 + 54] - vlc_offs[i * 3 + 53]; init_vlc(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63, ff_vc1_icbpcy_p_bits[i], 1, 1, ff_vc1_icbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); /* Initialize interlaced field picture MBMODE VLC tables */ ff_vc1_if_mmv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 54]]; ff_vc1_if_mmv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 55] - vlc_offs[i * 3 + 54]; init_vlc(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8, ff_vc1_if_mmv_mbmode_bits[i], 1, 1, ff_vc1_if_mmv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ff_vc1_if_1mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 55]]; ff_vc1_if_1mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 56] - vlc_offs[i * 3 + 55]; init_vlc(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6, ff_vc1_if_1mv_mbmode_bits[i], 1, 1, ff_vc1_if_1mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); } done = 1; } /* Other defaults */ v->pq = -1; v->mvrange = 0; /* 7.1.1.18, p80 */ return 0; }


static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size, int *golden_frame) { VP56RangeCoder *c = &s->c; int parse_filter_info = 0; int coeff_offset = 0; int vrt_shift = 0; int sub_version; int rows, cols; int res = 1; int separated_coeff = buf[0] & 1; s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80); ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F); if (s->framep[VP56_FRAME_CURRENT]->key_frame) { sub_version = buf[1] >> 3; if (sub_version > 8) return 0; s->filter_header = buf[1] & 0x06; if (buf[1] & 1) { av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n"); return 0; } if (separated_coeff || !s->filter_header) { coeff_offset = AV_RB16(buf+2) - 2; buf += 2; buf_size -= 2; } rows = buf[2]; /* number of stored macroblock rows */ cols = buf[3]; /* number of stored macroblock cols */ /* buf[4] is number of displayed macroblock rows */ /* buf[5] is number of displayed macroblock cols */ if (!s->macroblocks || /* first frame */ 16*cols != s->avctx->coded_width || 16*rows != s->avctx->coded_height) { avcodec_set_dimensions(s->avctx, 16*cols, 16*rows); if (s->avctx->extradata_size == 1) { s->avctx->width -= s->avctx->extradata[0] >> 4; s->avctx->height -= s->avctx->extradata[0] & 0x0F; } res = 2; } ff_vp56_init_range_decoder(c, buf+6, buf_size-6); vp56_rac_gets(c, 2); parse_filter_info = s->filter_header; if (sub_version < 8) vrt_shift = 5; s->sub_version = sub_version; } else { if (!s->sub_version) return 0; if (separated_coeff || !s->filter_header) { coeff_offset = AV_RB16(buf+1) - 2; buf += 2; buf_size -= 2; } ff_vp56_init_range_decoder(c, buf+1, buf_size-1); *golden_frame = vp56_rac_get(c); if (s->filter_header) { s->deblock_filtering = vp56_rac_get(c); if (s->deblock_filtering) vp56_rac_get(c); if (s->sub_version > 7) parse_filter_info = vp56_rac_get(c); } } if (parse_filter_info) { if (vp56_rac_get(c)) { s->filter_mode = 2; s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift; s->max_vector_length = 2 << vp56_rac_gets(c, 3); } else if (vp56_rac_get(c)) { s->filter_mode = 1; } else { s->filter_mode = 0; } if (s->sub_version > 7) s->filter_selection = vp56_rac_gets(c, 4); else s->filter_selection = 16; } s->use_huffman = vp56_rac_get(c); s->parse_coeff = vp6_parse_coeff; if (coeff_offset) { buf += coeff_offset; buf_size -= coeff_offset; if (buf_size < 0) return 0; if (s->use_huffman) { s->parse_coeff = vp6_parse_coeff_huffman; init_get_bits(&s->gb, buf, buf_size<<3); } else { ff_vp56_init_range_decoder(&s->cc, buf, buf_size); s->ccp = &s->cc; } } else { s->ccp = &s->c; } return res; }


int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb) { int ret; int64_t wait_start = 0; while (1) { ret = ff_network_wait_fd(fd, write); if (ret != AVERROR(EAGAIN)) return ret; if (ff_check_interrupt(int_cb)) return AVERROR_EXIT; if (timeout > 0) { if (!wait_start) wait_start = av_gettime(); else if (av_gettime() - wait_start > timeout) return AVERROR(ETIMEDOUT); } } }


GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) { GuestNetworkInterfaceList *head = NULL, *cur_item = NULL; struct ifaddrs *ifap, *ifa; if (getifaddrs(&ifap) < 0) { error_setg_errno(errp, errno, "getifaddrs failed"); goto error; } for (ifa = ifap; ifa; ifa = ifa->ifa_next) { GuestNetworkInterfaceList *info; GuestIpAddressList **address_list = NULL, *address_item = NULL; char addr4[INET_ADDRSTRLEN]; char addr6[INET6_ADDRSTRLEN]; int sock; struct ifreq ifr; unsigned char *mac_addr; void *p; g_debug("Processing %s interface", ifa->ifa_name); info = guest_find_interface(head, ifa->ifa_name); if (!info) { info = g_malloc0(sizeof(*info)); info->value = g_malloc0(sizeof(*info->value)); info->value->name = g_strdup(ifa->ifa_name); if (!cur_item) { head = cur_item = info; } else { cur_item->next = info; cur_item = info; } } if (!info->value->has_hardware_address && ifa->ifa_flags & SIOCGIFHWADDR) { /* we haven't obtained HW address yet */ sock = socket(PF_INET, SOCK_STREAM, 0); if (sock == -1) { error_setg_errno(errp, errno, "failed to create socket"); goto error; } memset(&ifr, 0, sizeof(ifr)); pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->value->name); if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { error_setg_errno(errp, errno, "failed to get MAC address of %s", ifa->ifa_name); goto error; } mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; info->value->hardware_address = g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x", (int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[4], (int) mac_addr[5]); info->value->has_hardware_address = true; close(sock); } if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { /* interface with IPv4 address */ address_item = g_malloc0(sizeof(*address_item)); address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) { error_setg_errno(errp, errno, "inet_ntop failed"); goto error; } address_item->value->ip_address = g_strdup(addr4); address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4; if (ifa->ifa_netmask) { /* Count the number of set bits in netmask. * This is safe as '1' and '0' cannot be shuffled in netmask. */ p = &((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr; address_item->value->prefix = ctpop32(((uint32_t *) p)[0]); } } else if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) { /* interface with IPv6 address */ address_item = g_malloc0(sizeof(*address_item)); address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) { error_setg_errno(errp, errno, "inet_ntop failed"); goto error; } address_item->value->ip_address = g_strdup(addr6); address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6; if (ifa->ifa_netmask) { /* Count the number of set bits in netmask. * This is safe as '1' and '0' cannot be shuffled in netmask. */ p = &((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr; address_item->value->prefix = ctpop32(((uint32_t *) p)[0]) + ctpop32(((uint32_t *) p)[1]) + ctpop32(((uint32_t *) p)[2]) + ctpop32(((uint32_t *) p)[3]); } } if (!address_item) { continue; } address_list = &info->value->ip_addresses; while (*address_list && (*address_list)->next) { address_list = &(*address_list)->next; } if (!*address_list) { *address_list = address_item; } else { (*address_list)->next = address_item; } info->value->has_ip_addresses = true; } freeifaddrs(ifap); return head; error: freeifaddrs(ifap); qapi_free_GuestNetworkInterfaceList(head); return NULL; }


PPC_OP(mulli) { T0 = (Ts0 * SPARAM(1)); RETURN(); }


static int print_uint64(DeviceState *dev, Property *prop, char *dest, size_t len) { uint64_t *ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "%" PRIu64, *ptr); }


static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr, int is_vp7) { VP8Context *s = avctx->priv_data; VP8ThreadData *prev_td, *next_td, *td = &s->thread_data[threadnr]; int mb_y = td->thread_mb_pos >> 16; int mb_x, mb_xy = mb_y * s->mb_width; int num_jobs = s->num_jobs; VP8Frame *curframe = s->curframe, *prev_frame = s->prev_frame; VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 1)]; VP8Macroblock *mb; uint8_t *dst[3] = { curframe->tf.f->data[0] + 16 * mb_y * s->linesize, curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize, curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize }; if (mb_y == 0) prev_td = td; else prev_td = &s->thread_data[(jobnr + num_jobs - 1) % num_jobs]; if (mb_y == s->mb_height - 1) next_td = td; else next_td = &s->thread_data[(jobnr + 1) % num_jobs]; if (s->mb_layout == 1) mb = s->macroblocks_base + ((s->mb_width + 1) * (mb_y + 1) + 1); else { // Make sure the previous frame has read its segmentation map, // if we re-use the same map. if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map) ff_thread_await_progress(&prev_frame->tf, mb_y, 0); mb = s->macroblocks + (s->mb_height - mb_y - 1) * 2; memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101); } if (!is_vp7 || mb_y == 0) memset(td->left_nnz, 0, sizeof(td->left_nnz)); s->mv_min.x = -MARGIN; s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN; for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) { // Wait for previous thread to read mb_x+2, and reach mb_y-1. if (prev_td != td) { if (threadnr != 0) { check_thread_pos(td, prev_td, mb_x + (is_vp7 ? 2 : 1), mb_y - (is_vp7 ? 2 : 1)); } else { check_thread_pos(td, prev_td, mb_x + (is_vp7 ? 2 : 1) + s->mb_width + 3, mb_y - (is_vp7 ? 2 : 1)); } } s->vdsp.prefetch(dst[0] + (mb_x & 3) * 4 * s->linesize + 64, s->linesize, 4); s->vdsp.prefetch(dst[1] + (mb_x & 7) * s->uvlinesize + 64, dst[2] - dst[1], 2); if (!s->mb_layout) decode_mb_mode(s, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy, prev_frame && prev_frame->seg_map ? prev_frame->seg_map->data + mb_xy : NULL, 0, is_vp7); prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS); if (!mb->skip) decode_mb_coeffs(s, td, c, mb, s->top_nnz[mb_x], td->left_nnz, is_vp7); if (mb->mode <= MODE_I4x4) intra_predict(s, td, dst, mb, mb_x, mb_y, is_vp7); else inter_predict(s, td, dst, mb, mb_x, mb_y); prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN); if (!mb->skip) { idct_mb(s, td, dst, mb); } else { AV_ZERO64(td->left_nnz); AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned /* Reset DC block predictors if they would exist * if the mb had coefficients */ if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) { td->left_nnz[8] = 0; s->top_nnz[mb_x][8] = 0; } } if (s->deblock_filter) filter_level_for_mb(s, mb, &td->filter_strength[mb_x], is_vp7); if (s->deblock_filter && num_jobs != 1 && threadnr == num_jobs - 1) { if (s->filter.simple) backup_mb_border(s->top_border[mb_x + 1], dst[0], NULL, NULL, s->linesize, 0, 1); else backup_mb_border(s->top_border[mb_x + 1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0); } prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN2); dst[0] += 16; dst[1] += 8; dst[2] += 8; s->mv_min.x -= 64; s->mv_max.x -= 64; if (mb_x == s->mb_width + 1) { update_pos(td, mb_y, s->mb_width + 3); } else { update_pos(td, mb_y, mb_x); } } }


static void yop_next_macroblock(YopDecContext *s) { // If we are advancing to the next row of macroblocks if (s->row_pos == s->frame.linesize[0] - 2) { s->dstptr += s->frame.linesize[0]; s->row_pos = 0; }else { s->row_pos += 2; } s->dstptr += 2; }


static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist) { AHCICmdHdr *cmd = ad->cur_cmd; uint32_t opts = le32_to_cpu(cmd->opts); uint64_t prdt_addr = le64_to_cpu(cmd->tbl_addr) + 0x80; int sglist_alloc_hint = opts >> AHCI_CMD_HDR_PRDT_LEN; dma_addr_t prdt_len = (sglist_alloc_hint * sizeof(AHCI_SG)); dma_addr_t real_prdt_len = prdt_len; uint8_t *prdt; int i; int r = 0; if (!sglist_alloc_hint) { DPRINTF(ad->port_no, "no sg list given by guest: 0x%08x\n", opts); return -1; } /* map PRDT */ if (!(prdt = dma_memory_map(ad->hba->dma, prdt_addr, &prdt_len, DMA_DIRECTION_TO_DEVICE))){ DPRINTF(ad->port_no, "map failed\n"); return -1; } if (prdt_len < real_prdt_len) { DPRINTF(ad->port_no, "mapped less than expected\n"); r = -1; goto out; } /* Get entries in the PRDT, init a qemu sglist accordingly */ if (sglist_alloc_hint > 0) { AHCI_SG *tbl = (AHCI_SG *)prdt; qemu_sglist_init(sglist, sglist_alloc_hint, ad->hba->dma); for (i = 0; i < sglist_alloc_hint; i++) { /* flags_size is zero-based */ qemu_sglist_add(sglist, le64_to_cpu(tbl[i].addr), le32_to_cpu(tbl[i].flags_size) + 1); } } out: dma_memory_unmap(ad->hba->dma, prdt, prdt_len, DMA_DIRECTION_TO_DEVICE, prdt_len); return r; }


static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) { MpegEncContext *s = &ctx->m; int width, height, vo_ver_id; /* vol header */ skip_bits(gb, 1); /* random access */ s->vo_type = get_bits(gb, 8); if (get_bits1(gb) != 0) { /* is_ol_id */ vo_ver_id = get_bits(gb, 4); /* vo_ver_id */ skip_bits(gb, 3); /* vo_priority */ } else { vo_ver_id = 1; s->aspect_ratio_info = get_bits(gb, 4); if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) { s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height } else { s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[s->aspect_ratio_info]; if ((s->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */ int chroma_format = get_bits(gb, 2); if (chroma_format != CHROMA_420) av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); s->low_delay = get_bits1(gb); if (get_bits1(gb)) { /* vbv parameters */ get_bits(gb, 15); /* first_half_bitrate */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* latter_half_bitrate */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* first_half_vbv_buffer_size */ skip_bits1(gb); /* marker */ get_bits(gb, 3); /* latter_half_vbv_buffer_size */ get_bits(gb, 11); /* first_half_vbv_occupancy */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* latter_half_vbv_occupancy */ skip_bits1(gb); /* marker */ } else { /* is setting low delay flag only once the smartest thing to do? * low delay detection won't be overriden. */ if (s->picture_number == 0) s->low_delay = 0; ctx->shape = get_bits(gb, 2); /* vol shape */ if (ctx->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) { av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); skip_bits(gb, 4); /* video_object_layer_shape_extension */ check_marker(gb, "before time_increment_resolution"); s->avctx->time_base.den = get_bits(gb, 16); if (!s->avctx->time_base.den) { av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n"); s->avctx->time_base.num = 0; return -1; ctx->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; if (ctx->time_increment_bits < 1) ctx->time_increment_bits = 1; check_marker(gb, "before fixed_vop_rate"); if (get_bits1(gb) != 0) /* fixed_vop_rate */ s->avctx->time_base.num = get_bits(gb, ctx->time_increment_bits); else s->avctx->time_base.num = 1; ctx->t_frame = 0; if (ctx->shape != BIN_ONLY_SHAPE) { if (ctx->shape == RECT_SHAPE) { check_marker(gb, "before width"); width = get_bits(gb, 13); check_marker(gb, "before height"); height = get_bits(gb, 13); check_marker(gb, "after height"); if (width && height && /* they should be non zero but who knows */ !(s->width && s->codec_tag == AV_RL32("MP4S"))) { if (s->width && s->height && (s->width != width || s->height != height)) s->context_reinit = 1; s->width = width; s->height = height; s->progressive_sequence = s->progressive_frame = get_bits1(gb) ^ 1; s->interlaced_dct = 0; if (!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) av_log(s->avctx, AV_LOG_INFO, /* OBMC Disable */ "MPEG4 OBMC not supported (very likely buggy encoder)\n"); if (vo_ver_id == 1) ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ else ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ if (ctx->vol_sprite_usage == STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); if (ctx->vol_sprite_usage == STATIC_SPRITE || ctx->vol_sprite_usage == GMC_SPRITE) { if (ctx->vol_sprite_usage == STATIC_SPRITE) { skip_bits(gb, 13); // sprite_width skip_bits1(gb); /* marker */ skip_bits(gb, 13); // sprite_height skip_bits1(gb); /* marker */ skip_bits(gb, 13); // sprite_left skip_bits1(gb); /* marker */ skip_bits(gb, 13); // sprite_top skip_bits1(gb); /* marker */ ctx->num_sprite_warping_points = get_bits(gb, 6); if (ctx->num_sprite_warping_points > 3) { av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", ctx->num_sprite_warping_points); ctx->num_sprite_warping_points = 0; return -1; s->sprite_warping_accuracy = get_bits(gb, 2); ctx->sprite_brightness_change = get_bits1(gb); if (ctx->vol_sprite_usage == STATIC_SPRITE) skip_bits1(gb); // low_latency_sprite // FIXME sadct disable bit if verid!=1 && shape not rect if (get_bits1(gb) == 1) { /* not_8_bit */ s->quant_precision = get_bits(gb, 4); /* quant_precision */ if (get_bits(gb, 4) != 8) /* bits_per_pixel */ av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); if (s->quant_precision != 5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision); if (s->quant_precision<3 || s->quant_precision>9) { s->quant_precision = 5; } else { s->quant_precision = 5; // FIXME a bunch of grayscale shape things if ((s->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */ int i, v; /* load default matrixes */ for (i = 0; i < 64; i++) { int j = s->dsp.idct_permutation[i]; v = ff_mpeg4_default_intra_matrix[i]; s->intra_matrix[j] = v; s->chroma_intra_matrix[j] = v; v = ff_mpeg4_default_non_intra_matrix[i]; s->inter_matrix[j] = v; s->chroma_inter_matrix[j] = v; /* load custom intra matrix */ if (get_bits1(gb)) { int last = 0; for (i = 0; i < 64; i++) { int j; v = get_bits(gb, 8); if (v == 0) break; last = v; j = s->dsp.idct_permutation[ff_zigzag_direct[i]]; s->intra_matrix[j] = last; s->chroma_intra_matrix[j] = last; /* replicate last value */ for (; i < 64; i++) { int j = s->dsp.idct_permutation[ff_zigzag_direct[i]]; s->intra_matrix[j] = last; s->chroma_intra_matrix[j] = last; /* load custom non intra matrix */ if (get_bits1(gb)) { int last = 0; for (i = 0; i < 64; i++) { int j; v = get_bits(gb, 8); if (v == 0) break; last = v; j = s->dsp.idct_permutation[ff_zigzag_direct[i]]; s->inter_matrix[j] = v; s->chroma_inter_matrix[j] = v; /* replicate last value */ for (; i < 64; i++) { int j = s->dsp.idct_permutation[ff_zigzag_direct[i]]; s->inter_matrix[j] = last; s->chroma_inter_matrix[j] = last; // FIXME a bunch of grayscale shape things if (vo_ver_id != 1) s->quarter_sample = get_bits1(gb); else s->quarter_sample = 0; if (!get_bits1(gb)) { int pos = get_bits_count(gb); int estimation_method = get_bits(gb, 2); if (estimation_method < 2) { if (!get_bits1(gb)) { ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* opaque */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* transparent */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* intra_cae */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* inter_cae */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* no_update */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* upampling */ if (!get_bits1(gb)) { ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* intra_blocks */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter_blocks */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */ if (!check_marker(gb, "in complexity estimation part 1")) { skip_bits_long(gb, pos - get_bits_count(gb)); goto no_cplx_est; if (!get_bits1(gb)) { ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* dct_coeffs */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* dct_lines */ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* vlc_syms */ ctx->cplx_estimation_trash_i += 4 * get_bits1(gb); /* vlc_bits */ if (!get_bits1(gb)) { ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* apm */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* npm */ ctx->cplx_estimation_trash_b += 8 * get_bits1(gb); /* interpolate_mc_q */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* forwback_mc_q */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */ if (!check_marker(gb, "in complexity estimation part 2")) { skip_bits_long(gb, pos - get_bits_count(gb)); goto no_cplx_est; if (estimation_method == 1) { ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* sadct */ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */ } else av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method); } else { no_cplx_est: ctx->cplx_estimation_trash_i = ctx->cplx_estimation_trash_p = ctx->cplx_estimation_trash_b = 0; ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */ s->data_partitioning = get_bits1(gb); if (s->data_partitioning) ctx->rvlc = get_bits1(gb); if (vo_ver_id != 1) { ctx->new_pred = get_bits1(gb); if (ctx->new_pred) { av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); skip_bits(gb, 2); /* requested upstream message type */ skip_bits1(gb); /* newpred segment type */ if (get_bits1(gb)) // reduced_res_vop av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n"); } else { ctx->new_pred = 0; ctx->scalability = get_bits1(gb); if (ctx->scalability) { GetBitContext bak = *gb; int h_sampling_factor_n; int h_sampling_factor_m; int v_sampling_factor_n; int v_sampling_factor_m; skip_bits1(gb); // hierarchy_type skip_bits(gb, 4); /* ref_layer_id */ skip_bits1(gb); /* ref_layer_sampling_dir */ h_sampling_factor_n = get_bits(gb, 5); h_sampling_factor_m = get_bits(gb, 5); v_sampling_factor_n = get_bits(gb, 5); v_sampling_factor_m = get_bits(gb, 5); ctx->enhancement_type = get_bits1(gb); if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 || v_sampling_factor_n == 0 || v_sampling_factor_m == 0) { /* illegal scalability header (VERY broken encoder), * trying to workaround */ ctx->scalability = 0; *gb = bak; } else av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); // bin shape stuff FIXME if (s->avctx->debug&FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, %s%s%s%s\n", s->avctx->time_base.num, s->avctx->time_base.den, ctx->time_increment_bits, s->quant_precision, s->progressive_sequence, ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "", s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : "" ); return 0;


static int ac3_probe(AVProbeData *p) { int max_frames, first_frames, frames; uint8_t *buf, *buf2, *end; AC3HeaderInfo hdr; if(p->buf_size < 7) return 0; max_frames = 0; buf = p->buf; end = buf + FFMIN(4096, p->buf_size - 7); for(; buf < end; buf++) { buf2 = buf; for(frames = 0; buf2 < end; frames++) { if(ff_ac3_parse_header(buf2, &hdr) < 0) break; buf2 += hdr.frame_size; } max_frames = FFMAX(max_frames, frames); if(buf == p->buf) first_frames = frames; } if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4; else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2; else if(max_frames>=1) return 1; else return 0; }


static void virtio_ccw_device_plugged(DeviceState *d) { VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); SubchDev *sch = dev->sch; sch->id.cu_model = virtio_bus_get_vdev_id(&dev->bus); css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, d->hotplugged, 1); }


static void digic_uart_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { DigicUartState *s = opaque; unsigned char ch = value; addr >>= 2; switch (addr) { case R_TX: if (s->chr) { qemu_chr_fe_write_all(s->chr, &ch, 1); } break; case R_ST: /* * Ignore write to R_ST. * * The point is that this register is actively used * during receiving and transmitting symbols, * but we don't know the function of most of bits. * * Ignoring writes to R_ST is only a simplification * of the model. It has no perceptible side effects * for existing guests. */ break; default: qemu_log_mask(LOG_UNIMP, "digic-uart: write access to unknown register 0x" TARGET_FMT_plx, addr << 2); } }


static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen, int vr_type) { GetBitContext *gb = &vc->gb; uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions; uint_fast16_t ptns_to_read = vr->ptns_to_read; uint_fast8_t *classifs = vr->classifs; uint_fast8_t pass; uint_fast8_t ch_used; uint_fast8_t i,j,l; uint_fast16_t k; if (vr_type == 2) { for (j = 1; j < ch; ++j) do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input if (do_not_decode[0]) return 0; ch_used = 1; } else { ch_used = ch; } AV_DEBUG(" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c); for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE? uint_fast16_t voffset; uint_fast16_t partition_count; uint_fast16_t j_times_ptns_to_read; voffset = vr->begin; for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error if (!pass) { uint_fast32_t inverse_class = ff_inverse[vr->classifications]; for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { if (!do_not_decode[j]) { uint_fast32_t temp = get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, vc->codebooks[vr->classbook].nb_bits, 3); AV_DEBUG("Classword: %d \n", temp); assert(vr->classifications > 1 && temp <= 65536); //needed for inverse[] for (i = 0; i < c_p_c; ++i) { uint_fast32_t temp2; temp2 = (((uint_fast64_t)temp) * inverse_class) >> 32; if (partition_count + c_p_c - 1 - i < ptns_to_read) classifs[j_times_ptns_to_read + partition_count + c_p_c - 1 - i] = temp - temp2 * vr->classifications; temp = temp2; } } j_times_ptns_to_read += ptns_to_read; } } for (i = 0; (i < c_p_c) && (partition_count < ptns_to_read); ++i) { for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { uint_fast16_t voffs; if (!do_not_decode[j]) { uint_fast8_t vqclass = classifs[j_times_ptns_to_read+partition_count]; int_fast16_t vqbook = vr->books[vqclass][pass]; if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) { uint_fast16_t coffs; unsigned dim = vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 uint_fast16_t step = dim == 1 ? vr->partition_size : FASTDIV(vr->partition_size, dim); vorbis_codebook codebook = vc->codebooks[vqbook]; if (vr_type == 0) { voffs = voffset+j*vlen; for (k = 0; k < step; ++k) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; for (l = 0; l < dim; ++l) vec[voffs + k + l * step] += codebook.codevectors[coffs + l]; // FPMATH } } else if (vr_type == 1) { voffs = voffset + j * vlen; for (k = 0; k < step; ++k) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; for (l = 0; l < dim; ++l, ++voffs) { vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs); } } } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized voffs = voffset >> 1; if (dim == 2) { for (k = 0; k < step; ++k) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2; vec[voffs + k ] += codebook.codevectors[coffs ]; // FPMATH vec[voffs + k + vlen] += codebook.codevectors[coffs + 1]; // FPMATH } } else if (dim == 4) { for (k = 0; k < step; ++k, voffs += 2) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 4; vec[voffs ] += codebook.codevectors[coffs ]; // FPMATH vec[voffs + 1 ] += codebook.codevectors[coffs + 2]; // FPMATH vec[voffs + vlen ] += codebook.codevectors[coffs + 1]; // FPMATH vec[voffs + vlen + 1] += codebook.codevectors[coffs + 3]; // FPMATH } } else for (k = 0; k < step; ++k) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; for (l = 0; l < dim; l += 2, voffs++) { vec[voffs ] += codebook.codevectors[coffs + l ]; // FPMATH vec[voffs + vlen] += codebook.codevectors[coffs + l + 1]; // FPMATH AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset / ch + (voffs % ch) * vlen, vec[voffset / ch + (voffs % ch) * vlen], codebook.codevectors[coffs + l], coffs, l); } } } else if (vr_type == 2) { voffs = voffset; for (k = 0; k < step; ++k) { coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; for (l = 0; l < dim; ++l, ++voffs) { vec[voffs / ch + (voffs % ch) * vlen] += codebook.codevectors[coffs + l]; // FPMATH FIXME use if and counter instead of / and % AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset / ch + (voffs % ch) * vlen, vec[voffset / ch + (voffs % ch) * vlen], codebook.codevectors[coffs + l], coffs, l); } } } } } j_times_ptns_to_read += ptns_to_read; } ++partition_count; voffset += vr->partition_size; } } } return 0; }


static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path, const char *name, V9fsPath *target) { if (dir_path) { v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); } else { v9fs_path_sprintf(target, "%s", name); } return 0; }


static inline void RENAME(bgr24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) { int i; for (i=0; i<width; i++) { int b= src1[6*i + 0] + src1[6*i + 3]; int g= src1[6*i + 1] + src1[6*i + 4]; int r= src1[6*i + 2] + src1[6*i + 5]; dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1); dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1); } assert(src1 == src2); }


static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next) { char *fact, *value; av_dlog(NULL, "%s\n", mlsd); while(fact = av_strtok(mlsd, ";", &mlsd)) { if (fact[0] == ' ') { next->name = av_strdup(&fact[1]); continue; } fact = av_strtok(fact, "=", &value); if (!av_strcasecmp(fact, "type")) { if (!av_strcasecmp(value, "cdir") || !av_strcasecmp(value, "pdir")) return 1; if (!av_strcasecmp(value, "dir")) next->type = AVIO_ENTRY_DIRECTORY; else if (!av_strcasecmp(value, "file")) next->type = AVIO_ENTRY_FILE; else if (!av_strcasecmp(value, "OS.unix=slink:")) next->type = AVIO_ENTRY_SYMBOLIC_LINK; } else if (!av_strcasecmp(fact, "modify")) { next->modification_timestamp = ftp_parse_date(value); } else if (!av_strcasecmp(fact, "UNIX.mode")) { next->filemode = strtoumax(value, NULL, 8); } else if (!av_strcasecmp(fact, "UNIX.uid") || !av_strcasecmp(fact, "UNIX.owner")) next->user_id = strtoumax(value, NULL, 10); else if (!av_strcasecmp(fact, "UNIX.gid") || !av_strcasecmp(fact, "UNIX.group")) next->group_id = strtoumax(value, NULL, 10); else if (!av_strcasecmp(fact, "size") || !av_strcasecmp(fact, "sizd")) next->size = strtoll(value, NULL, 10); } return 0; }


static int get_scale_idx(GetBitContext *gb, int ref) { int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; if (t == 8) return get_bits(gb, 6); return ref + t; }