static void monitor_qapi_event_handler(void *opaque) { MonitorQAPIEventState *evstate = opaque; MonitorQAPIEventConf *evconf = &monitor_qapi_event_conf[evstate->event]; trace_monitor_protocol_event_handler(evstate->event, evstate->qdict); qemu_mutex_lock(&monitor_lock); if (evstate->qdict) { int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); monitor_qapi_event_emit(evstate->event, evstate->qdict); QDECREF(evstate->qdict); evstate->qdict = NULL; timer_mod_ns(evstate->timer, now + evconf->rate); } else { g_hash_table_remove(monitor_qapi_event_state, evstate); QDECREF(evstate->data); timer_free(evstate->timer); g_free(evstate); } qemu_mutex_unlock(&monitor_lock); }


static void body(uint32_t ABCD[4], uint32_t X[16]) { int i av_unused; uint32_t t; uint32_t a = ABCD[3]; uint32_t b = ABCD[2]; uint32_t c = ABCD[1]; uint32_t d = ABCD[0]; #if HAVE_BIGENDIAN for (i = 0; i < 16; i++) X[i] = av_bswap32(X[i]); #endif #if CONFIG_SMALL for (i = 0; i < 64; i++) { CORE(i, a, b, c, d); t = d; d = c; c = b; b = a; a = t; } #else #define CORE2(i) \ CORE( i, a,b,c,d); CORE((i+1),d,a,b,c); \ CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a) #define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12)) CORE4(0); CORE4(16); CORE4(32); CORE4(48); #endif ABCD[0] += d; ABCD[1] += c; ABCD[2] += b; ABCD[3] += a; }


static int v210_read_header(AVFormatContext *ctx) { V210DemuxerContext *s = ctx->priv_data; AVStream *st; st = avformat_new_stream(ctx, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = ctx->iformat->raw_codec_id; avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); st->codec->width = s->width; st->codec->height = s->height; st->codec->pix_fmt = ctx->iformat->raw_codec_id == AV_CODEC_ID_V210 ? AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV422P16; st->codec->bit_rate = av_rescale_q(GET_PACKET_SIZE(s->width, s->height), (AVRational){8,1}, st->time_base); return 0; }


int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64]) { int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; int16_t *mot_val; const int xy= s->mb_x + s->mb_y * s->mb_stride; int cbpb = 0, pb_mv_count = 0; assert(!s->h263_pred); if (s->pict_type == AV_PICTURE_TYPE_P) { do{ if (get_bits1(&s->gb)) { /* skip mb */ s->mb_intra = 0; for(i=0;i<6;i++) s->block_last_index[i] = -1; s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->mb_skipped = !(s->obmc | s->loop_filter); goto end; } cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 20); s->dsp.clear_blocks(s->block[0]); dquant = cbpc & 8; s->mb_intra = ((cbpc & 4) != 0); if (s->mb_intra) goto intra; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } s->mv_dir = MV_DIR_FORWARD; if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ s->mv_type = MV_TYPE_16X16; ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][0][0] = mx; s->mv[0][0][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ } else { s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; s->mv_type = MV_TYPE_8X8; for(i=0;i<4;i++) { mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else mx = ff_h263_decode_motion(s, pred_x, 1); if (mx >= 0xffff) return -1; if (s->umvplus) my = h263p_decode_umotion(s, pred_y); else my = ff_h263_decode_motion(s, pred_y, 1); if (my >= 0xffff) return -1; s->mv[0][i][0] = mx; s->mv[0][i][1] = my; if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ mot_val[0] = mx; mot_val[1] = my; } } } else if(s->pict_type==AV_PICTURE_TYPE_B) { int mb_type; const int stride= s->b8_stride; int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; //FIXME ugly mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; do{ mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); if (mb_type < 0){ av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } mb_type= h263_mb_type_b_map[ mb_type ]; }while(!mb_type); s->mb_intra = IS_INTRA(mb_type); if(HAS_CBP(mb_type)){ s->dsp.clear_blocks(s->block[0]); cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); if(s->mb_intra){ dquant = IS_QUANT(mb_type); goto intra; } cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if (cbpy < 0){ av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) cbpy ^= 0xF; cbp = (cbpc & 3) | (cbpy << 2); }else cbp=0; assert(!s->mb_intra); if(IS_QUANT(mb_type)){ h263_decode_dquant(s); } if(IS_DIRECT(mb_type)){ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); }else{ s->mv_dir = 0; s->mv_type= MV_TYPE_16X16; //FIXME UMV if(USES_LIST(mb_type, 0)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my); s->mv_dir = MV_DIR_FORWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[0][0][0] = mx; s->mv[0][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } if(USES_LIST(mb_type, 1)){ int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my); s->mv_dir |= MV_DIR_BACKWARD; mx = ff_h263_decode_motion(s, mx, 1); my = ff_h263_decode_motion(s, my, 1); s->mv[1][0][0] = mx; s->mv[1][0][1] = my; mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; } } s->current_picture.mb_type[xy] = mb_type; } else { /* I-Frame */ do{ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); if (cbpc < 0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } }while(cbpc == 8); s->dsp.clear_blocks(s->block[0]); dquant = cbpc & 4; s->mb_intra = 1; intra: s->current_picture.mb_type[xy] = MB_TYPE_INTRA; if (s->h263_aic) { s->ac_pred = get_bits1(&s->gb); if(s->ac_pred){ s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; s->h263_aic_dir = get_bits1(&s->gb); } }else s->ac_pred = 0; if(s->pb_frame && get_bits1(&s->gb)) pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { h263_decode_dquant(s); } pb_mv_count += !!s->pb_frame; } while(pb_mv_count--){ ff_h263_decode_motion(s, 0, 1); ff_h263_decode_motion(s, 0, 1); } /* decode each block */ for (i = 0; i < 6; i++) { if (h263_decode_block(s, block[i], i, cbp&32) < 0) return -1; cbp+=cbp; } if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) return -1; if(s->obmc && !s->mb_intra){ if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1) preview_obmc(s); } end: /* per-MB end of slice check */ { int v= show_bits(&s->gb, 16); if (get_bits_left(&s->gb) < 16) { v >>= 16 - get_bits_left(&s->gb); } if(v==0) return SLICE_END; } return SLICE_OK; }


const QEMUSizedBuffer *qemu_buf_get(QEMUFile *f) { QEMUBuffer *p; qemu_fflush(f); p = f->opaque; return p->qsb; }


static int vncws_start_tls_handshake(struct VncState *vs) { int ret = gnutls_handshake(vs->tls.session); if (ret < 0) { if (!gnutls_error_is_fatal(ret)) { VNC_DEBUG("Handshake interrupted (blocking)\n"); if (!gnutls_record_get_direction(vs->tls.session)) { qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs); qemu_set_fd_handler(vs->csock, NULL, vncws_tls_handshake_io, vs); return 0; VNC_DEBUG("Handshake failed %s\n", gnutls_strerror(ret)); VNC_DEBUG("Handshake done, switching to TLS data mode\n"); qemu_set_fd_handler2(vs->csock, NULL, vncws_handshake_read, NULL, vs); return 0;


static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){ int frequency[512]; uint8_t flag[512]; int up[512]; uint8_t len_tab[257]; int bits_tab[257]; int start, end; uint8_t *ptr= buf; int j; memset(frequency, 0, sizeof(frequency)); memset(up, -1, sizeof(up)); start= *ptr++; end= *ptr++; for(;;){ int i; for(i=start; i<=end; i++){ frequency[i]= *ptr++; // printf("%d %d %d\n", start, end, frequency[i]); } start= *ptr++; if(start==0) break; end= *ptr++; } frequency[256]=1; while((ptr - buf)&3) ptr++; // 4byte align // for(j=0; j<16; j++) // printf("%2X", ptr[j]); for(j=257; j<512; j++){ int min_freq[2]= {256*256, 256*256}; int smallest[2]= {0, 0}; int i; for(i=0; i<j; i++){ if(frequency[i] == 0) continue; if(frequency[i] < min_freq[1]){ if(frequency[i] < min_freq[0]){ min_freq[1]= min_freq[0]; smallest[1]= smallest[0]; min_freq[0]= frequency[i];smallest[0]= i; }else{ min_freq[1]= frequency[i];smallest[1]= i; } } } if(min_freq[1] == 256*256) break; frequency[j]= min_freq[0] + min_freq[1]; flag[ smallest[0] ]= 0; flag[ smallest[1] ]= 1; up[ smallest[0] ]= up[ smallest[1] ]= j; frequency[ smallest[0] ]= frequency[ smallest[1] ]= 0; } for(j=0; j<257; j++){ int node; int len=0; int bits=0; for(node= j; up[node] != -1; node= up[node]){ bits += flag[node]<<len; len++; if(len > 31) av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); //can this happen at all ? } bits_tab[j]= bits; len_tab[j]= len; } init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab , 1, 1, bits_tab, 4, 4); return ptr; }


static bool ohci_eof_timer_needed(void *opaque) { OHCIState *ohci = opaque; return ohci->eof_timer != NULL; }


static int decode_frame_apng(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { PNGDecContext *const s = avctx->priv_data; int ret; AVFrame *p; ff_thread_release_buffer(avctx, &s->last_picture); FFSWAP(ThreadFrame, s->picture, s->last_picture); p = s->picture.f; if (!(s->state & PNG_IHDR)) { int side_data_size = 0; uint8_t *side_data = NULL; if (avpkt) side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size); if (side_data_size) { av_freep(&s->extra_data); s->extra_data = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!s->extra_data) return AVERROR(ENOMEM); s->extra_data_size = side_data_size; memcpy(s->extra_data, side_data, s->extra_data_size); } if (!s->extra_data_size) return AVERROR_INVALIDDATA; /* only init fields, there is no zlib use in extradata */ s->zstream.zalloc = ff_png_zalloc; s->zstream.zfree = ff_png_zfree; bytestream2_init(&s->gb, s->extra_data, s->extra_data_size); if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) goto end; } /* reset state for a new frame */ if ((ret = inflateInit(&s->zstream)) != Z_OK) { av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret); ret = AVERROR_EXTERNAL; goto end; } s->y = 0; s->state &= ~(PNG_IDAT | PNG_ALLIMAGE); bytestream2_init(&s->gb, avpkt->data, avpkt->size); if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) goto end; if (!(s->state & PNG_ALLIMAGE)) av_log(avctx, AV_LOG_WARNING, "Frame did not contain a complete image\n"); if (!(s->state & (PNG_ALLIMAGE|PNG_IDAT))) { ret = AVERROR_INVALIDDATA; goto end; } if ((ret = av_frame_ref(data, s->picture.f)) < 0) goto end; *got_frame = 1; ret = bytestream2_tell(&s->gb); end: inflateEnd(&s->zstream); return ret; }


static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size) { abi_ulong addr; abi_ulong end_addr; int prot; int looped = 0; if (size > reserved_va) { return (abi_ulong)-1; } size = HOST_PAGE_ALIGN(size); end_addr = start + size; if (end_addr > reserved_va) { end_addr = reserved_va; } addr = end_addr - qemu_host_page_size; while (1) { if (addr > end_addr) { if (looped) { return (abi_ulong)-1; } end_addr = reserved_va; addr = end_addr - qemu_host_page_size; looped = 1; continue; } prot = page_get_flags(addr); if (prot) { end_addr = addr; } if (addr + size == end_addr) { break; } addr -= qemu_host_page_size; } if (start == mmap_next_start) { mmap_next_start = addr; } return addr; }


static av_always_inline int process_frame(WriterContext *w, InputFile *ifile, AVFrame *frame, AVPacket *pkt) { AVFormatContext *fmt_ctx = ifile->fmt_ctx; AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx; AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar; AVSubtitle sub; int ret = 0, got_frame = 0; if (dec_ctx->codec) { switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, pkt); break; case AVMEDIA_TYPE_AUDIO: ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt); break; case AVMEDIA_TYPE_SUBTITLE: ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt); break; } } if (ret < 0) return ret; ret = FFMIN(ret, pkt->size); /* guard against bogus return values */ pkt->data += ret; pkt->size -= ret; if (got_frame) { int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE); nb_streams_frames[pkt->stream_index]++; if (do_show_frames) if (is_sub) show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx); else show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx); if (is_sub) avsubtitle_free(&sub); } return got_frame; }


static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; MOVStreamContext *sc; int ret; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams - 1]; sc = st->priv_data; avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ sc->stsd_count = avio_rb32(pb); /* entries */ /* Prepare space for hosting multiple extradata. */ sc->extradata = av_mallocz_array(sc->stsd_count, sizeof(*sc->extradata)); if (!sc->extradata) return AVERROR(ENOMEM); sc->extradata_size = av_mallocz_array(sc->stsd_count, sizeof(*sc->extradata_size)); if (!sc->extradata_size) return AVERROR(ENOMEM); ret = ff_mov_read_stsd_entries(c, pb, sc->stsd_count); if (ret < 0) return ret; /* Restore back the primary extradata. */ av_freep(&st->codecpar->extradata); st->codecpar->extradata_size = sc->extradata_size[0]; if (sc->extradata_size[0]) { st->codecpar->extradata = av_mallocz(sc->extradata_size[0] + AV_INPUT_BUFFER_PADDING_SIZE); if (!st->codecpar->extradata) return AVERROR(ENOMEM); memcpy(st->codecpar->extradata, sc->extradata[0], sc->extradata_size[0]); } return 0; }


static void implicit_weight_table(H264Context *h){ MpegEncContext * const s = &h->s; int ref0, ref1, i; int cur_poc = s->current_picture_ptr->poc; if( h->ref_count[0] == 1 && h->ref_count[1] == 1 && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ h->use_weight= 0; h->use_weight_chroma= 0; return; } h->use_weight= 2; h->use_weight_chroma= 2; h->luma_log2_weight_denom= 5; h->chroma_log2_weight_denom= 5; for (i = 0; i < 2; i++) { h->luma_weight_flag[i] = 0; h->chroma_weight_flag[i] = 0; } for(ref0=0; ref0 < h->ref_count[0]; ref0++){ int poc0 = h->ref_list[0][ref0].poc; for(ref1=0; ref1 < h->ref_count[1]; ref1++){ int poc1 = h->ref_list[1][ref1].poc; int td = av_clip(poc1 - poc0, -128, 127); if(td){ int tb = av_clip(cur_poc - poc0, -128, 127); int tx = (16384 + (FFABS(td) >> 1)) / td; int dist_scale_factor = av_clip((tb*tx + 32) >> 6, -1024, 1023) >> 2; if(dist_scale_factor < -64 || dist_scale_factor > 128) h->implicit_weight[ref0][ref1] = 32; else h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor; }else h->implicit_weight[ref0][ref1] = 32; } } }


static av_cold int ra144_encode_init(AVCodecContext * avctx) { RA144Context *ractx; int ret; if (avctx->channels != 1) { av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", avctx->channels); return -1; } avctx->frame_size = NBLOCKS * BLOCKSIZE; avctx->delay = avctx->frame_size; avctx->bit_rate = 8000; ractx = avctx->priv_data; ractx->lpc_coef[0] = ractx->lpc_tables[0]; ractx->lpc_coef[1] = ractx->lpc_tables[1]; ractx->avctx = avctx; ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER, FF_LPC_TYPE_LEVINSON); if (ret < 0) goto error; ff_af_queue_init(avctx, &ractx->afq); return 0; error: ra144_encode_close(avctx); return ret; }


static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) { MXFDescriptor *descriptor = arg; descriptor->pix_fmt = AV_PIX_FMT_NONE; switch(tag) { case 0x3F01: descriptor->sub_descriptors_count = avio_rb32(pb); if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID)) return AVERROR_INVALIDDATA; descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID)); if (!descriptor->sub_descriptors_refs) return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID)); break; case 0x3004: avio_read(pb, descriptor->essence_container_ul, 16); break; case 0x3006: descriptor->linked_track_id = avio_rb32(pb); break; case 0x3201: /* PictureEssenceCoding */ avio_read(pb, descriptor->essence_codec_ul, 16); break; case 0x3203: descriptor->width = avio_rb32(pb); break; case 0x3202: descriptor->height = avio_rb32(pb); break; case 0x320C: descriptor->frame_layout = avio_r8(pb); break; case 0x320E: descriptor->aspect_ratio.num = avio_rb32(pb); descriptor->aspect_ratio.den = avio_rb32(pb); break; case 0x3301: descriptor->component_depth = avio_rb32(pb); break; case 0x3302: descriptor->horiz_subsampling = avio_rb32(pb); break; case 0x3308: descriptor->vert_subsampling = avio_rb32(pb); break; case 0x3D03: descriptor->sample_rate.num = avio_rb32(pb); descriptor->sample_rate.den = avio_rb32(pb); break; case 0x3D06: /* SoundEssenceCompression */ avio_read(pb, descriptor->essence_codec_ul, 16); break; case 0x3D07: descriptor->channels = avio_rb32(pb); break; case 0x3D01: descriptor->bits_per_sample = avio_rb32(pb); break; case 0x3401: mxf_read_pixel_layout(pb, descriptor); break; default: /* Private uid used by SONY C0023S01.mxf */ if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) { descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); if (!descriptor->extradata) return AVERROR(ENOMEM); descriptor->extradata_size = size; avio_read(pb, descriptor->extradata, size); } break; } return 0; }


int pt_removexattr(FsContext *ctx, const char *path, const char *name) { char *buffer; int ret; buffer = rpath(ctx, path); ret = lremovexattr(path, name); g_free(buffer); return ret; }


int64_t ff_ape_parse_tag(AVFormatContext *s) { AVIOContext *pb = s->pb; int file_size = avio_size(pb); uint32_t val, fields, tag_bytes; uint8_t buf[8]; int64_t tag_start; int i; if (file_size < APE_TAG_FOOTER_BYTES) return 0; avio_seek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); avio_read(pb, buf, 8); /* APETAGEX */ if (strncmp(buf, "APETAGEX", 8)) { return 0; } val = avio_rl32(pb); /* APE tag version */ if (val > APE_TAG_VERSION) { av_log(s, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION); return 0; } tag_bytes = avio_rl32(pb); /* tag size */ if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) { av_log(s, AV_LOG_ERROR, "Tag size is way too big\n"); return 0; } tag_start = file_size - tag_bytes - APE_TAG_FOOTER_BYTES; if (tag_start < 0) { av_log(s, AV_LOG_ERROR, "Invalid tag size %u.\n", tag_bytes); return 0; } fields = avio_rl32(pb); /* number of fields */ if (fields > 65536) { av_log(s, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields); return 0; } val = avio_rl32(pb); /* flags */ if (val & APE_TAG_FLAG_IS_HEADER) { av_log(s, AV_LOG_ERROR, "APE Tag is a header\n"); return 0; } avio_seek(pb, file_size - tag_bytes, SEEK_SET); for (i=0; i<fields; i++) if (ape_tag_read_field(s) < 0) break; return tag_start; }


static void* attribute_align_arg worker(void *v) { ThreadContext *c = v; int our_job = c->nb_jobs; int nb_threads = c->nb_threads; unsigned int last_execute = 0; int self_id; pthread_mutex_lock(&c->current_job_lock); self_id = c->current_job++; for (;;) { while (our_job >= c->nb_jobs) { if (c->current_job == nb_threads + c->nb_jobs) pthread_cond_signal(&c->last_job_cond); while (last_execute == c->current_execute && !c->done) pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); last_execute = c->current_execute; our_job = self_id; if (c->done) { pthread_mutex_unlock(&c->current_job_lock); return NULL; } } pthread_mutex_unlock(&c->current_job_lock); c->rets[our_job % c->nb_rets] = c->func(c->ctx, c->arg, our_job, c->nb_jobs); pthread_mutex_lock(&c->current_job_lock); our_job = c->current_job++; } }


static void pc87312_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->realize = pc87312_realize; dc->reset = pc87312_reset; dc->vmsd = &vmstate_pc87312; dc->props = pc87312_properties; }


static int mkv_field_order(MatroskaDemuxContext *matroska, int64_t field_order) { int major, minor, micro, bttb = 0; /* workaround a bug in our Matroska muxer, introduced in version 57.36 alongside * this function, and fixed in 57.52 */ if (sscanf(matroska->muxingapp, "Lavf%d.%d.%d", &major, &minor, &micro) == 3) bttb = (major == 57 && minor >= 36 && minor <= 51 && micro >= 100); switch (field_order) { case MATROSKA_VIDEO_FIELDORDER_PROGRESSIVE: return AV_FIELD_PROGRESSIVE; case MATROSKA_VIDEO_FIELDORDER_UNDETERMINED: return AV_FIELD_UNKNOWN; case MATROSKA_VIDEO_FIELDORDER_TT: return AV_FIELD_TT; case MATROSKA_VIDEO_FIELDORDER_BB: return AV_FIELD_BB; case MATROSKA_VIDEO_FIELDORDER_BT: return bttb ? AV_FIELD_TB : AV_FIELD_BT; case MATROSKA_VIDEO_FIELDORDER_TB: return bttb ? AV_FIELD_BT : AV_FIELD_TB; default: return AV_FIELD_UNKNOWN; } }


av_cold void ff_fft_init_arm(FFTContext *s) { int cpu_flags = av_get_cpu_flags(); if (have_vfp(cpu_flags) && !have_vfpv3(cpu_flags)) { s->fft_calc = ff_fft_calc_vfp; #if CONFIG_MDCT s->imdct_half = ff_imdct_half_vfp; #endif } if (have_neon(cpu_flags)) { s->fft_permute = ff_fft_permute_neon; s->fft_calc = ff_fft_calc_neon; #if CONFIG_MDCT s->imdct_calc = ff_imdct_calc_neon; s->imdct_half = ff_imdct_half_neon; s->mdct_calc = ff_mdct_calc_neon; s->mdct_permutation = FF_MDCT_PERM_INTERLEAVE; #endif } }


unsigned long find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { const unsigned long *p = addr + BITOP_WORD(offset); unsigned long result = offset & ~(BITS_PER_LONG-1); unsigned long tmp; if (offset >= size) { return size; } size -= result; offset %= BITS_PER_LONG; if (offset) { tmp = *(p++); tmp &= (~0UL << offset); if (size < BITS_PER_LONG) { goto found_first; } if (tmp) { goto found_middle; } size -= BITS_PER_LONG; result += BITS_PER_LONG; } while (size & ~(BITS_PER_LONG-1)) { if ((tmp = *(p++))) { goto found_middle; } result += BITS_PER_LONG; size -= BITS_PER_LONG; } if (!size) { return result; } tmp = *p; found_first: tmp &= (~0UL >> (BITS_PER_LONG - size)); if (tmp == 0UL) { /* Are any bits set? */ return result + size; /* Nope. */ } found_middle: return result + bitops_ffsl(tmp); }


void migration_set_outgoing_channel(MigrationState *s, QIOChannel *ioc) { QEMUFile *f = qemu_fopen_channel_output(ioc); s->to_dst_file = f; migrate_fd_connect(s); }


static void qemu_wait_io_event_common(CPUState *cpu) { if (cpu->stop) { cpu->stop = false; cpu->stopped = true; qemu_cond_broadcast(&qemu_pause_cond); } process_queued_cpu_work(cpu); cpu->thread_kicked = false; }


static void ahci_test_identify(AHCIQState *ahci) { uint16_t buff[256]; unsigned px; int rc; uint16_t sect_size; const size_t buffsize = 512; g_assert(ahci != NULL); /** * This serves as a bit of a tutorial on AHCI device programming: * * (1) Create a data buffer for the IDENTIFY response to be sent to * (2) Create a Command Table buffer, where we will store the * command and PRDT (Physical Region Descriptor Table) * (3) Construct an FIS host-to-device command structure, and write it to * the top of the Command Table buffer. * (4) Create one or more Physical Region Descriptors (PRDs) that describe * a location in memory where data may be stored/retrieved. * (5) Write these PRDTs to the bottom (offset 0x80) of the Command Table. * (6) Each AHCI port has up to 32 command slots. Each slot contains a * header that points to a Command Table buffer. Pick an unused slot * and update it to point to the Command Table we have built. * (7) Now: Command #n points to our Command Table, and our Command Table * contains the FIS (that describes our command) and the PRDTL, which * describes our buffer. * (8) We inform the HBA via PxCI (Command Issue) that the command in slot * #n is ready for processing. */ /* Pick the first implemented and running port */ px = ahci_port_select(ahci); g_test_message("Selected port %u for test", px); /* Clear out the FIS Receive area and any pending interrupts. */ ahci_port_clear(ahci, px); /* "Read" 512 bytes using CMD_IDENTIFY into the host buffer. */ ahci_io(ahci, px, CMD_IDENTIFY, &buff, buffsize); /* Check serial number/version in the buffer */ /* NB: IDENTIFY strings are packed in 16bit little endian chunks. * Since we copy byte-for-byte in ahci-test, on both LE and BE, we need to * unchunk this data. By contrast, ide-test copies 2 bytes at a time, and * as a consequence, only needs to unchunk the data on LE machines. */ string_bswap16(&buff[10], 20); rc = memcmp(&buff[10], "testdisk ", 20); g_assert_cmphex(rc, ==, 0); string_bswap16(&buff[23], 8); rc = memcmp(&buff[23], "version ", 8); g_assert_cmphex(rc, ==, 0); }


static void rc4030_realize(DeviceState *dev, Error **errp) { rc4030State *s = RC4030(dev); Object *o = OBJECT(dev); int i; s->periodic_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rc4030_periodic_timer, s); memory_region_init_io(&s->iomem_chipset, NULL, &rc4030_ops, s, "rc4030.chipset", 0x300); memory_region_init_io(&s->iomem_jazzio, NULL, &jazzio_ops, s, "rc4030.jazzio", 0x00001000); memory_region_init_rom_device(&s->dma_tt, o, &rc4030_dma_tt_ops, s, "dma-table", MAX_TL_ENTRIES * sizeof(dma_pagetable_entry), NULL); memory_region_init(&s->dma_tt_alias, o, "dma-table-alias", 0); memory_region_init(&s->dma_mr, o, "dma", INT32_MAX); for (i = 0; i < MAX_TL_ENTRIES; ++i) { memory_region_init_alias(&s->dma_mrs[i], o, "dma-alias", get_system_memory(), 0, DMA_PAGESIZE); memory_region_set_enabled(&s->dma_mrs[i], false); memory_region_add_subregion(&s->dma_mr, i * DMA_PAGESIZE, &s->dma_mrs[i]); } address_space_init(&s->dma_as, &s->dma_mr, "rc4030-dma"); }


static int fourxm_probe(AVProbeData *p) { if ((AV_RL32(&p->buf[0]) != RIFF_TAG) || (AV_RL32(&p->buf[8]) != _4XMV_TAG)) return 0; return AVPROBE_SCORE_MAX; }


void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical) { CPUClass *cc = CPU_GET_CLASS(cpu); int count, i; CPUDebug s; INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf); s.cpu = cpu; monitor_disas_is_physical = is_physical; s.info.read_memory_func = monitor_read_memory; s.info.print_address_func = generic_print_address; s.info.buffer_vma = pc; s.info.cap_arch = -1; s.info.cap_mode = 0; #ifdef TARGET_WORDS_BIGENDIAN s.info.endian = BFD_ENDIAN_BIG; #else s.info.endian = BFD_ENDIAN_LITTLE; #endif if (cc->disas_set_info) { cc->disas_set_info(cpu, &s.info); } if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) { return; } if (!s.info.print_insn) { monitor_printf(mon, "0x" TARGET_FMT_lx ": Asm output not supported on this arch\n", pc); return; } for(i = 0; i < nb_insn; i++) { monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); count = s.info.print_insn(pc, &s.info); monitor_printf(mon, "\n"); if (count < 0) break; pc += count; } }


static struct omap_pwl_s *omap_pwl_init(MemoryRegion *system_memory, hwaddr base, omap_clk clk) { struct omap_pwl_s *s = g_malloc0(sizeof(*s)); omap_pwl_reset(s); memory_region_init_io(&s->iomem, NULL, &omap_pwl_ops, s, "omap-pwl", 0x800); memory_region_add_subregion(system_memory, base, &s->iomem); omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]); return s; }


static int amr_nb_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf, int buf_size) { AMRContext *s = avctx->priv_data; uint8_t*amrData=buf; int offset=0; UWord8 toc, q, ft; Word16 serial[SERIAL_FRAMESIZE]; /* coded bits */ Word16 *synth; UWord8 *packed_bits; static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0}; int i; //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount); synth=data; // while(offset<buf_size) { toc=amrData[offset]; /* read rest of the frame based on ToC byte */ q = (toc >> 2) & 0x01; ft = (toc >> 3) & 0x0F; //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]); offset++; packed_bits=amrData+offset; offset+=packed_size[ft]; //Unsort and unpack bits s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]); //We have a new frame s->frameCount++; if (s->rx_type == RX_NO_DATA) { s->mode = s->speech_decoder_state->prev_mode; } else { s->speech_decoder_state->prev_mode = s->mode; } /* if homed: check if this frame is another homing frame */ if (s->reset_flag_old == 1) { /* only check until end of first subframe */ s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode); } /* produce encoder homing frame if homed & input=decoder homing frame */ if ((s->reset_flag != 0) && (s->reset_flag_old != 0)) { for (i = 0; i < L_FRAME; i++) { synth[i] = EHF_MASK; } } else { /* decode frame */ Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth); } //Each AMR-frame results in 160 16-bit samples *data_size+=160*2; synth+=160; /* if not homed: check whether current frame is a homing frame */ if (s->reset_flag_old == 0) { /* check whole frame */ s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode); } /* reset decoder if current frame is a homing frame */ if (s->reset_flag != 0) { Speech_Decode_Frame_reset(s->speech_decoder_state); } s->reset_flag_old = s->reset_flag; } return offset; }


static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); int ret; avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "stbl"); mov_write_stsd_tag(s, pb, mov, track); mov_write_stts_tag(pb, track); if ((track->par->codec_type == AVMEDIA_TYPE_VIDEO || track->par->codec_tag == MKTAG('r','t','p',' ')) && track->has_keyframes && track->has_keyframes < track->entry) mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE); if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE); if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->flags & MOV_TRACK_CTTS && track->entry) { if ((ret = mov_write_ctts_tag(pb, track)) < 0) return ret; } mov_write_stsc_tag(pb, track); mov_write_stsz_tag(pb, track); mov_write_stco_tag(pb, track); if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) { ff_mov_cenc_write_stbl_atoms(&track->cenc, pb); } if (track->par->codec_id == AV_CODEC_ID_OPUS) { mov_preroll_write_stbl_atoms(pb, track); } return update_size(pb, pos); }


static av_cold void h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) { if (bit_depth == 8) { c->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_neon; c->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_neon; c->h264_v_loop_filter_chroma = ff_h264_v_loop_filter_chroma_neon; c->h264_h_loop_filter_chroma = ff_h264_h_loop_filter_chroma_neon; c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16_neon; c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_8_neon; c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_4_neon; c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16_neon; c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_8_neon; c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_4_neon; c->h264_idct_add = ff_h264_idct_add_neon; c->h264_idct_dc_add = ff_h264_idct_dc_add_neon; c->h264_idct_add16 = ff_h264_idct_add16_neon; c->h264_idct_add16intra = ff_h264_idct_add16intra_neon; if (chroma_format_idc == 1) c->h264_idct_add8 = ff_h264_idct_add8_neon; c->h264_idct8_add = ff_h264_idct8_add_neon; c->h264_idct8_dc_add = ff_h264_idct8_dc_add_neon; c->h264_idct8_add4 = ff_h264_idct8_add4_neon; } }


ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov, int iovcnt) { VLANState *vlan = vc1->vlan; VLANClientState *vc; ssize_t max_len = 0; if (vc1->link_down) return calc_iov_length(iov, iovcnt); for (vc = vlan->first_client; vc != NULL; vc = vc->next) { ssize_t len = 0; if (vc == vc1) continue; if (vc->link_down) len = calc_iov_length(iov, iovcnt); else if (vc->fd_readv) len = vc->fd_readv(vc->opaque, iov, iovcnt); else if (vc->fd_read) len = vc_sendv_compat(vc, iov, iovcnt); max_len = MAX(max_len, len); } return max_len; }


static bool blit_region_is_unsafe(struct CirrusVGAState *s, int32_t pitch, int32_t addr) { if (pitch < 0) { int64_t min = addr + ((int64_t)s->cirrus_blt_height-1) * pitch; int32_t max = addr + s->cirrus_blt_width; if (min < 0 || max >= s->vga.vram_size) { return true; } } else { int64_t max = addr + ((int64_t)s->cirrus_blt_height-1) * pitch + s->cirrus_blt_width; if (max >= s->vga.vram_size) { return true; } } return false; }


static int rv10_decode_picture_header(MpegEncContext *s) { int mb_count, pb_frame, marker, h, full_frame; /* skip packet header */ h = get_bits(&s->gb, 8); if ((h & 0xc0) == 0xc0) { int len, pos; full_frame = 1; len = get_num(&s->gb); pos = get_num(&s->gb); } else { int seq, frame_size, pos; full_frame = 0; seq = get_bits(&s->gb, 8); frame_size = get_num(&s->gb); pos = get_num(&s->gb); } /* picture number */ get_bits(&s->gb, 8); marker = get_bits(&s->gb, 1); if (get_bits(&s->gb, 1)) s->pict_type = P_TYPE; else s->pict_type = I_TYPE; pb_frame = get_bits(&s->gb, 1); #ifdef DEBUG printf("pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame); #endif if (pb_frame) return -1; s->qscale = get_bits(&s->gb, 5); if (s->pict_type == I_TYPE) { if (s->rv10_version == 3) { /* specific MPEG like DC coding not used */ s->last_dc[0] = get_bits(&s->gb, 8); s->last_dc[1] = get_bits(&s->gb, 8); s->last_dc[2] = get_bits(&s->gb, 8); #ifdef DEBUG printf("DC:%d %d %d\n", s->last_dc[0], s->last_dc[1], s->last_dc[2]); #endif } } /* if multiple packets per frame are sent, the position at which to display the macro blocks is coded here */ if (!full_frame) { s->mb_x = get_bits(&s->gb, 6); /* mb_x */ s->mb_y = get_bits(&s->gb, 6); /* mb_y */ mb_count = get_bits(&s->gb, 12); } else { s->mb_x = 0; s->mb_y = 0; mb_count = s->mb_width * s->mb_height; } get_bits(&s->gb, 3); /* ignored */ s->f_code = 1; s->unrestricted_mv = 1; #if 0 s->h263_long_vectors = 1; #endif return mb_count; }


host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { HostMemoryBackend *backend = MEMORY_BACKEND(obj); uint16List *host_nodes = NULL; uint16List **node = &host_nodes; unsigned long value; value = find_first_bit(backend->host_nodes, MAX_NODES); node = host_memory_append_node(node, value); if (value == MAX_NODES) { goto out; } do { value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1); if (value == MAX_NODES) { break; } node = host_memory_append_node(node, value); } while (true); out: visit_type_uint16List(v, name, &host_nodes, errp); }


static int v4l2_read_header(AVFormatContext *s1) { struct video_data *s = s1->priv_data; AVStream *st; int res = 0; uint32_t desired_format; enum AVCodecID codec_id = AV_CODEC_ID_NONE; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; struct v4l2_input input = { 0 }; st = avformat_new_stream(s1, NULL); if (!st) return AVERROR(ENOMEM); #if CONFIG_LIBV4L2 /* silence libv4l2 logging. if fopen() fails v4l2_log_file will be NULL and errors will get sent to stderr */ v4l2_log_file = fopen("/dev/null", "w"); #endif s->fd = device_open(s1); if (s->fd < 0) return s->fd; if (s->channel != -1) { /* set video input */ av_log(s1, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel); if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) { res = AVERROR(errno); av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res)); return res; } } else { /* get current video input */ if (v4l2_ioctl(s->fd, VIDIOC_G_INPUT, &s->channel) < 0) { res = AVERROR(errno); av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_INPUT): %s\n", av_err2str(res)); return res; } } /* enum input */ input.index = s->channel; if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) { res = AVERROR(errno); av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMINPUT): %s\n", av_err2str(res)); return res; } s->std_id = input.std; av_log(s1, AV_LOG_DEBUG, "Current input_channel: %d, input_name: %s\n", s->channel, input.name); if (s->list_format) { list_formats(s1, s->fd, s->list_format); return AVERROR_EXIT; } if (s->list_standard) { list_standards(s1); return AVERROR_EXIT; } avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ if (s->pixel_format) { AVCodec *codec = avcodec_find_decoder_by_name(s->pixel_format); if (codec) s1->video_codec_id = codec->id; pix_fmt = av_get_pix_fmt(s->pixel_format); if (pix_fmt == AV_PIX_FMT_NONE && !codec) { av_log(s1, AV_LOG_ERROR, "No such input format: %s.\n", s->pixel_format); return AVERROR(EINVAL); } } if (!s->width && !s->height) { struct v4l2_format fmt; av_log(s1, AV_LOG_VERBOSE, "Querying the device for the current frame size\n"); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (v4l2_ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { res = AVERROR(errno); av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_err2str(res)); return res; } s->width = fmt.fmt.pix.width; s->height = fmt.fmt.pix.height; av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, s->height); } res = device_try_init(s1, pix_fmt, &s->width, &s->height, &desired_format, &codec_id); if (res < 0) { v4l2_close(s->fd); return res; } /* If no pixel_format was specified, the codec_id was not known up * until now. Set video_codec_id in the context, as codec_id will * not be available outside this function */ if (codec_id != AV_CODEC_ID_NONE && s1->video_codec_id == AV_CODEC_ID_NONE) s1->video_codec_id = codec_id; if ((res = av_image_check_size(s->width, s->height, 0, s1)) < 0) return res; s->frame_format = desired_format; if ((res = v4l2_set_parameters(s1)) < 0) return res; st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id); s->frame_size = avpicture_get_size(st->codec->pix_fmt, s->width, s->height); if ((res = mmap_init(s1)) || (res = mmap_start(s1)) < 0) { v4l2_close(s->fd); return res; } s->top_field_first = first_field(s->fd); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = codec_id; if (codec_id == AV_CODEC_ID_RAWVIDEO) st->codec->codec_tag = avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); if (desired_format == V4L2_PIX_FMT_YVU420) st->codec->codec_tag = MKTAG('Y', 'V', '1', '2'); else if (desired_format == V4L2_PIX_FMT_YVU410) st->codec->codec_tag = MKTAG('Y', 'V', 'U', '9'); st->codec->width = s->width; st->codec->height = s->height; st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8; return 0; }


avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, int w, int h, enum PixelFormat format) { AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer)); AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef)); if (!pic || !picref) goto fail; picref->buf = pic; picref->buf->free = ff_avfilter_default_free_buffer; if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps)))) goto fail; picref->video->w = w; picref->video->h = h; /* make sure the buffer gets read permission or it's useless for output */ picref->perms = perms | AV_PERM_READ; pic->refcount = 1; picref->type = AVMEDIA_TYPE_VIDEO; picref->format = format; memcpy(pic->data, data, sizeof(pic->data)); memcpy(pic->linesize, linesize, sizeof(pic->linesize)); memcpy(picref->data, pic->data, sizeof(picref->data)); memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); return picref; fail: if (picref && picref->video) av_free(picref->video); av_free(picref); av_free(pic); return NULL; }


static int dca_decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int i; int16_t *samples = data; DCAContext *s = avctx->priv_data; int channels; s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE); if (s->dca_buffer_size == -1) { av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); } init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); if (dca_parse_frame_header(s) < 0) { //seems like the frame is corrupt, try with the next one *data_size=0; return buf_size; } //set AVCodec values with parsed data avctx->sample_rate = s->sample_rate; avctx->bit_rate = s->bit_rate; channels = s->prim_channels + !!s->lfe; if (s->amode<16) { avctx->channel_layout = dca_core_channel_layout[s->amode]; if (s->lfe) { avctx->channel_layout |= CH_LOW_FREQUENCY; s->channel_order_tab = dca_channel_reorder_lfe[s->amode]; } else s->channel_order_tab = dca_channel_reorder_nolfe[s->amode]; if(avctx->request_channels == 2 && s->prim_channels > 2) { channels = 2; s->output = DCA_STEREO; avctx->channel_layout = CH_LAYOUT_STEREO; } } else { av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); } /* There is nothing that prevents a dts frame to change channel configuration but FFmpeg doesn't support that so only set the channels if it is previously unset. Ideally during the first probe for channels the crc should be checked and only set avctx->channels when the crc is ok. Right now the decoder could set the channels based on a broken first frame.*/ if (!avctx->channels) avctx->channels = channels; if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; for (i = 0; i < (s->sample_blocks / 8); i++) { dca_decode_block(s); s->dsp.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels); samples += 256 * channels; } return buf_size; }


static void dmg_close(BlockDriverState *bs) { BDRVDMGState *s = bs->opaque; g_free(s->types); g_free(s->offsets); g_free(s->lengths); g_free(s->sectors); g_free(s->sectorcounts); g_free(s->compressed_chunk); g_free(s->uncompressed_chunk); inflateEnd(&s->zstream); }


int gdbserver_start(const char *device) { GDBState *s; char gdbstub_device_name[128]; CharDriverState *chr = NULL; CharDriverState *mon_chr; if (!device) return -1; if (strcmp(device, "none") != 0) { if (strstart(device, "tcp:", NULL)) { /* enforce required TCP attributes */ snprintf(gdbstub_device_name, sizeof(gdbstub_device_name), "%s,nowait,nodelay,server", device); device = gdbstub_device_name; } #ifndef _WIN32 else if (strcmp(device, "stdio") == 0) { struct sigaction act; memset(&act, 0, sizeof(act)); act.sa_handler = gdb_sigterm_handler; sigaction(SIGINT, &act, NULL); } #endif chr = qemu_chr_new("gdb", device, NULL); if (!chr) return -1; qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event, NULL); } s = gdbserver_state; if (!s) { s = g_malloc0(sizeof(GDBState)); gdbserver_state = s; qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); /* Initialize a monitor terminal for gdb */ mon_chr = g_malloc0(sizeof(*mon_chr)); mon_chr->chr_write = gdb_monitor_write; monitor_init(mon_chr, 0); } else { if (s->chr) qemu_chr_delete(s->chr); mon_chr = s->mon_chr; memset(s, 0, sizeof(GDBState)); } s->c_cpu = first_cpu; s->g_cpu = first_cpu; s->chr = chr; s->state = chr ? RS_IDLE : RS_INACTIVE; s->mon_chr = mon_chr; s->current_syscall_cb = NULL; return 0; }


static int opus_packet(AVFormatContext *avf, int idx) { struct ogg *ogg = avf->priv_data; struct ogg_stream *os = &ogg->streams[idx]; AVStream *st = avf->streams[idx]; struct oggopus_private *priv = os->private; uint8_t *packet = os->buf + os->pstart; int ret; if (!os->psize) return AVERROR_INVALIDDATA; if (os->granule > INT64_MAX - UINT32_MAX) { av_log(avf, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", os->granule); return AVERROR_INVALIDDATA; } if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) { int seg, d; int duration; uint8_t *last_pkt = os->buf + os->pstart; uint8_t *next_pkt = last_pkt; duration = 0; seg = os->segp; d = opus_duration(last_pkt, os->psize); if (d < 0) { os->pflags |= AV_PKT_FLAG_CORRUPT; return 0; } duration += d; last_pkt = next_pkt = next_pkt + os->psize; for (; seg < os->nsegs; seg++) { next_pkt += os->segments[seg]; if (os->segments[seg] < 255 && next_pkt != last_pkt) { int d = opus_duration(last_pkt, next_pkt - last_pkt); if (d > 0) duration += d; last_pkt = next_pkt; } } os->lastpts = os->lastdts = os->granule - duration; } if ((ret = opus_duration(packet, os->psize)) < 0) return ret; os->pduration = ret; if (os->lastpts != AV_NOPTS_VALUE) { if (st->start_time == AV_NOPTS_VALUE) st->start_time = os->lastpts; priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip; } priv->cur_dts += os->pduration; if ((os->flags & OGG_FLAG_EOS)) { int64_t skip = priv->cur_dts - os->granule + priv->pre_skip; skip = FFMIN(skip, os->pduration); if (skip > 0) { os->pduration = skip < os->pduration ? os->pduration - skip : 1; os->end_trimming = skip; av_log(avf, AV_LOG_DEBUG, "Last packet was truncated to %d due to end trimming.\n", os->pduration); } } return 0; }


static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) { unsigned char *destptr_bak = destptr; unsigned char *destptr_end = destptr + destsize; unsigned char mask = 0; unsigned char maskbit = 0; unsigned int ofs, cnt; while (srclen > 0 && destptr < destptr_end) { if (maskbit == 0) { mask = *srcptr++; maskbit = 8; srclen--; continue; } if ((mask & (1 << (--maskbit))) == 0) { if (destptr + 4 > destptr_end) break; memcpy(destptr, srcptr, 4); srclen -= 4; destptr += 4; srcptr += 4; } else { ofs = *srcptr++; cnt = *srcptr++; ofs += cnt * 256; cnt = ((cnt >> 3) & 0x1f) + 1; ofs &= 0x7ff; srclen -= 2; cnt *= 4; if (destptr + cnt > destptr_end) { cnt = destptr_end - destptr; } for (; cnt > 0; cnt--) { *destptr = *(destptr - ofs); destptr++; } } } return destptr - destptr_bak; }


static int decode_codestream(Jpeg2000DecoderContext *s) { Jpeg2000CodingStyle *codsty = s->codsty; Jpeg2000QuantStyle *qntsty = s->qntsty; uint8_t *properties = s->properties; for (;;){ int oldpos, marker, len, ret = 0; if (bytestream2_get_bytes_left(&s->g) < 2) { av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n"); break; } marker = bytestream2_get_be16u(&s->g); av_dlog(s->avctx, "marker 0x%.4X at pos 0x%x\n", marker, bytestream2_tell(&s->g) - 4); oldpos = bytestream2_tell(&s->g); if (marker == JPEG2000_SOD){ Jpeg2000Tile *tile = s->tile + s->curtileno; if (ret = init_tile(s, s->curtileno)) { av_log(s->avctx, AV_LOG_ERROR, "tile initialization failed\n"); return ret; } if (ret = jpeg2000_decode_packets(s, tile)) { av_log(s->avctx, AV_LOG_ERROR, "packets decoding failed\n"); return ret; } continue; } if (marker == JPEG2000_EOC) break; if (bytestream2_get_bytes_left(&s->g) < 2) return AVERROR(EINVAL); len = bytestream2_get_be16u(&s->g); switch (marker){ case JPEG2000_SIZ: ret = get_siz(s); break; case JPEG2000_COC: ret = get_coc(s, codsty, properties); break; case JPEG2000_COD: ret = get_cod(s, codsty, properties); break; case JPEG2000_QCC: ret = get_qcc(s, len, qntsty, properties); break; case JPEG2000_QCD: ret = get_qcd(s, len, qntsty, properties); break; case JPEG2000_SOT: if (!(ret = get_sot(s))){ codsty = s->tile[s->curtileno].codsty; qntsty = s->tile[s->curtileno].qntsty; properties = s->tile[s->curtileno].properties; } break; case JPEG2000_COM: // the comment is ignored bytestream2_skip(&s->g, len - 2); break; default: av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%x\n", marker, bytestream2_tell(&s->g) - 4); bytestream2_skip(&s->g, len - 2); break; } if (bytestream2_tell(&s->g) - oldpos != len || ret){ av_log(s->avctx, AV_LOG_ERROR, "error during processing marker segment %.4x\n", marker); return ret ? ret : -1; } } return 0; }


void do_mulldo (void) { int64_t th; uint64_t tl; muls64(&tl, &th, T0, T1); if (likely(th == 0)) { xer_ov = 0; } else { xer_ov = 1; xer_so = 1; } T0 = (int64_t)tl; }


static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigned *rval) { GetByteContext *gb = &s->gb; RangeCoder *rc = &s->rc; unsigned totfr = pixel->total_freq; unsigned value, x = 0, cumfr = 0, cnt_x = 0; int i, j, ret, c, cnt_c; if ((ret = s->get_freq(rc, totfr, &value)) < 0) return ret; while (x < 16) { cnt_x = pixel->lookup[x]; if (value >= cumfr + cnt_x) cumfr += cnt_x; else break; x++; } c = x * 16; cnt_c = 0; while (c < 256) { cnt_c = pixel->freq[c]; if (value >= cumfr + cnt_c) cumfr += cnt_c; else break; c++; } s->decode(gb, rc, cumfr, cnt_c, totfr); pixel->freq[c] = cnt_c + step; pixel->lookup[x] = cnt_x + step; totfr += step; if (totfr > BOT) { totfr = 0; for (i = 0; i < 256; i++) { unsigned nc = (pixel->freq[i] >> 1) + 1; pixel->freq[i] = nc; totfr += nc; } for (i = 0; i < 16; i++) { unsigned sum = 0; unsigned i16_17 = i << 4; for (j = 0; j < 16; j++) sum += pixel->freq[i16_17 + j]; pixel->lookup[i] = sum; } } pixel->total_freq = totfr; *rval = c & s->cbits; return 0; }


static void sbr_env_estimate(float (*e_curr)[48], float X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data) { int e, i, m; if (sbr->bs_interpol_freq) { for (e = 0; e < ch_data->bs_num_env; e++) { const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]); int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; for (m = 0; m < sbr->m[1]; m++) { float sum = 0.0f; for (i = ilb; i < iub; i++) { sum += X_high[m + sbr->kx[1]][i][0] * X_high[m + sbr->kx[1]][i][0] + X_high[m + sbr->kx[1]][i][1] * X_high[m + sbr->kx[1]][i][1]; } e_curr[e][m] = sum * recip_env_size; } } } else { int k, p; for (e = 0; e < ch_data->bs_num_env; e++) { const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]); int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) { float sum = 0.0f; const int den = env_size * (table[p + 1] - table[p]); for (k = table[p]; k < table[p + 1]; k++) { for (i = ilb; i < iub; i++) { sum += X_high[k][i][0] * X_high[k][i][0] + X_high[k][i][1] * X_high[k][i][1]; } } sum /= den; for (k = table[p]; k < table[p + 1]; k++) { e_curr[e][k - sbr->kx[1]] = sum; } } } } }


static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, const float *v1, const float *v2) { float cprod, oprod; int ret; cprod = cdsp->scalarproduct_float(v1, v2, LEN); oprod = fdsp->scalarproduct_float(v1, v2, LEN); if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST)) av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n"); return ret; }


static int mov_read_pasp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { const int num = get_be32(pb); const int den = get_be32(pb); AVStream * const st = c->fc->streams[c->fc->nb_streams-1]; if (den != 0) { if ((st->sample_aspect_ratio.den != 1 || st->sample_aspect_ratio.num) && // default (den != st->sample_aspect_ratio.den || num != st->sample_aspect_ratio.num)) av_log(c->fc, AV_LOG_WARNING, "sample aspect ratio already set to %d:%d, overriding by 'pasp' atom\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); st->sample_aspect_ratio.num = num; st->sample_aspect_ratio.den = den; } return 0; }


static void MPV_encode_defaults(MpegEncContext *s){ static int done=0; MPV_common_defaults(s); if(!done){ int i; done=1; for(i=-16; i<16; i++){ default_fcode_tab[i + MAX_MV]= 1; } } s->me.mv_penalty= default_mv_penalty; s->fcode_tab= default_fcode_tab; }


int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, int has_alpha) { const PixFmtInfo *pf, *ps; int loss; ps = &pix_fmt_info[src_pix_fmt]; pf = &pix_fmt_info[dst_pix_fmt]; /* compute loss */ loss = 0; pf = &pix_fmt_info[dst_pix_fmt]; if (pf->depth < ps->depth) loss |= FF_LOSS_DEPTH; if (pf->x_chroma_shift >= ps->x_chroma_shift || pf->y_chroma_shift >= ps->y_chroma_shift) loss |= FF_LOSS_RESOLUTION; switch(pf->color_type) { case FF_COLOR_RGB: if (ps->color_type != FF_COLOR_RGB && ps->color_type != FF_COLOR_GRAY) loss |= FF_LOSS_COLORSPACE; break; case FF_COLOR_GRAY: if (ps->color_type != FF_COLOR_GRAY) loss |= FF_LOSS_COLORSPACE; break; case FF_COLOR_YUV: if (ps->color_type != FF_COLOR_YUV) loss |= FF_LOSS_COLORSPACE; break; case FF_COLOR_YUV_JPEG: if (ps->color_type != FF_COLOR_YUV_JPEG && ps->color_type != FF_COLOR_YUV) loss |= FF_LOSS_COLORSPACE; break; default: /* fail safe test */ if (ps->color_type != pf->color_type) loss |= FF_LOSS_COLORSPACE; break; } if (pf->color_type == FF_COLOR_GRAY && ps->color_type != FF_COLOR_GRAY) loss |= FF_LOSS_CHROMA; if (!pf->is_alpha && (ps->is_alpha && has_alpha)) loss |= FF_LOSS_ALPHA; if (pf->is_paletted && (!ps->is_paletted && ps->color_type != FF_COLOR_GRAY)) loss |= FF_LOSS_COLORQUANT; return loss; }


static int ftp_get_file_handle(URLContext *h) { FTPContext *s = h->priv_data; av_dlog(h, "ftp protocol get_file_handle\n"); if (s->conn_data) return ffurl_get_file_handle(s->conn_data); return AVERROR(EIO); }


static void sdp_write_header(char *buff, int size, struct sdp_session_level *s) { av_strlcatf(buff, size, "v=%d\r\n" "o=- %d %d IN IPV4 %s\r\n" "t=%d %d\r\n" "s=%s\r\n" "a=tool:libavformat " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\r\n", s->sdp_version, s->id, s->version, s->src_addr, s->start_time, s->end_time, s->name[0] ? s->name : "No Name"); dest_write(buff, size, s->dst_addr, s->ttl); }


static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts) { int ret, i; AVFormatContext *dev = NULL; AVDeviceInfoList *device_list = NULL; AVDictionary *tmp_opts = NULL; if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) return AVERROR(EINVAL); printf("Audo-detected sources for %s:\n", fmt->name); if (!fmt->get_device_list) { ret = AVERROR(ENOSYS); printf("Cannot list sources. Not implemented.\n"); goto fail; } /* TODO: avformat_open_input calls read_header callback which is not necessary. Function like avformat_alloc_output_context2 for input could be helpful here. */ av_dict_copy(&tmp_opts, opts, 0); if ((ret = avformat_open_input(&dev, NULL, fmt, &tmp_opts)) < 0) { printf("Cannot open device: %s.\n", fmt->name); goto fail; } if ((ret = avdevice_list_devices(dev, &device_list)) < 0) { printf("Cannot list sources.\n"); goto fail; } for (i = 0; i < device_list->nb_devices; i++) { printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ", device_list->devices[i]->device_name, device_list->devices[i]->device_description); } fail: av_dict_free(&tmp_opts); avdevice_free_list_devices(&device_list); avformat_close_input(&dev); return ret; }


static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, uint8_t *dest, int dstW, int dstY) { int dummy=0; switch(c->dstFormat) { #ifdef HAVE_MMX case IMGFMT_BGR32: { asm volatile( YSCALEYUV2RGBX WRITEBGR32(%4, %5, %%REGa) :: "r" (&c->redDither), "m" (dummy), "m" (dummy), "m" (dummy), "r" (dest), "m" (dstW) : "%"REG_a, "%"REG_d, "%"REG_S ); } break; case IMGFMT_BGR24: { asm volatile( YSCALEYUV2RGBX "lea (%%"REG_a", %%"REG_a", 2), %%"REG_b"\n\t" //FIXME optimize "add %4, %%"REG_b" \n\t" WRITEBGR24(%%REGb, %5, %%REGa) :: "r" (&c->redDither), "m" (dummy), "m" (dummy), "m" (dummy), "r" (dest), "m" (dstW) : "%"REG_a, "%"REG_b, "%"REG_d, "%"REG_S //FIXME ebx ); } break; case IMGFMT_BGR15: { asm volatile( YSCALEYUV2RGBX /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g5Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR15(%4, %5, %%REGa) :: "r" (&c->redDither), "m" (dummy), "m" (dummy), "m" (dummy), "r" (dest), "m" (dstW) : "%"REG_a, "%"REG_d, "%"REG_S ); } break; case IMGFMT_BGR16: { asm volatile( YSCALEYUV2RGBX /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g6Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR16(%4, %5, %%REGa) :: "r" (&c->redDither), "m" (dummy), "m" (dummy), "m" (dummy), "r" (dest), "m" (dstW) : "%"REG_a, "%"REG_d, "%"REG_S ); } break; case IMGFMT_YUY2: { asm volatile( YSCALEYUV2PACKEDX /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ "psraw $3, %%mm3 \n\t" "psraw $3, %%mm4 \n\t" "psraw $3, %%mm1 \n\t" "psraw $3, %%mm7 \n\t" WRITEYUY2(%4, %5, %%REGa) :: "r" (&c->redDither), "m" (dummy), "m" (dummy), "m" (dummy), "r" (dest), "m" (dstW) : "%"REG_a, "%"REG_d, "%"REG_S ); } break; #endif default: #ifdef HAVE_ALTIVEC /* The following list of supported dstFormat values should match what's found in the body of altivec_yuv2packedX() */ if(c->dstFormat==IMGFMT_ABGR || c->dstFormat==IMGFMT_BGRA || c->dstFormat==IMGFMT_BGR24 || c->dstFormat==IMGFMT_RGB24 || c->dstFormat==IMGFMT_RGBA || c->dstFormat==IMGFMT_ARGB) altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize, chrFilter, chrSrc, chrFilterSize, dest, dstW, dstY); else #endif yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize, chrFilter, chrSrc, chrFilterSize, dest, dstW, dstY); break; } }


static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){ int i, ret= -1; int av_unused mm_flags = av_get_cpu_flags(); int need_emms= 0; if (c->compensation_distance) dst_size = FFMIN(dst_size, c->compensation_distance); for(i=0; i<dst->ch_count; i++){ #if HAVE_MMXEXT_INLINE #if HAVE_SSE2_INLINE if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_SSE2)) ret= swri_resample_int16_sse2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); else #endif if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_MMX2 )){ ret= swri_resample_int16_mmx2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); need_emms= 1; } else #endif if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); else if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); #if HAVE_AVX_INLINE else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_AVX)) ret= swri_resample_float_avx (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); #endif #if HAVE_SSE_INLINE else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_SSE)) ret= swri_resample_float_sse (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); #endif else if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); #if HAVE_SSE2_INLINE else if(c->format == AV_SAMPLE_FMT_DBLP && (mm_flags&AV_CPU_FLAG_SSE2)) ret= swri_resample_double_sse2(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); #endif else if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); if(need_emms) emms_c(); return ret;


static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts, int key, int stream_id) { MpegTSWriteStream *ts_st = st->priv_data; MpegTSWrite *ts = s->priv_data; uint8_t buf[TS_PACKET_SIZE]; uint8_t *q; int val, is_start, len, header_len, write_pcr, is_dvb_subtitle, is_dvb_teletext, flags; int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO); if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { force_pat = 1; is_start = 1; while (payload_size > 0) { retransmit_si_info(s, force_pat, dts); force_pat = 0; write_pcr = 0; if (ts_st->pid == ts_st->service->pcr_pid) { if (ts->mux_rate > 1 || is_start) // VBR pcr period is based on frames ts_st->service->pcr_packet_count++; if (ts_st->service->pcr_packet_count >= ts_st->service->pcr_packet_period) { ts_st->service->pcr_packet_count = 0; write_pcr = 1; if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE && (dts - get_pcr(ts, s->pb) / 300) > delay) { /* pcr insert gets priority over null packet insert */ if (write_pcr) mpegts_insert_pcr_only(s, st); else mpegts_insert_null_packet(s); /* recalculate write_pcr and possibly retransmit si_info */ continue; /* prepare packet header */ q = buf; *q++ = 0x47; val = ts_st->pid >> 8; if (is_start) val |= 0x40; *q++ = val; *q++ = ts_st->pid; ts_st->cc = ts_st->cc + 1 & 0xf; *q++ = 0x10 | ts_st->cc; // payload indicator + CC if (key && is_start && pts != AV_NOPTS_VALUE) { // set Random Access for key frames if (ts_st->pid == ts_st->service->pcr_pid) write_pcr = 1; set_af_flag(buf, 0x40); if (write_pcr) { set_af_flag(buf, 0x10); // add 11, pcr references the last byte of program clock reference base if (ts->mux_rate > 1) pcr = get_pcr(ts, s->pb); else pcr = (dts - delay) * 300; if (dts != AV_NOPTS_VALUE && dts < pcr / 300) av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n"); extend_af(buf, write_pcr_bits(q, pcr)); if (is_start) { int pes_extension = 0; int pes_header_stuffing_bytes = 0; /* write PES header */ *q++ = 0x00; *q++ = 0x00; *q++ = 0x01; is_dvb_subtitle = 0; is_dvb_teletext = 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) *q++ = 0xfd; else *q++ = 0xe0; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && (st->codecpar->codec_id == AV_CODEC_ID_MP2 || st->codecpar->codec_id == AV_CODEC_ID_MP3 || st->codecpar->codec_id == AV_CODEC_ID_AAC)) { *q++ = 0xc0; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AC3 && ts->m2ts_mode) { *q++ = 0xfd; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA && st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) { *q++ = 0xbd; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { *q++ = stream_id != -1 ? stream_id : 0xfc; if (stream_id == 0xbd) /* asynchronous KLV */ pts = dts = AV_NOPTS_VALUE; } else { *q++ = 0xbd; if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { is_dvb_subtitle = 1; } else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { is_dvb_teletext = 1; header_len = 0; flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; flags |= 0x80; if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { header_len += 5; flags |= 0x40; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; /* One byte for PES2 extension flag + * one byte for extension length + * one byte for extension id */ header_len += 3; /* for Blu-ray AC3 Audio the PES Extension flag should be as follow * otherwise it will not play sound on blu-ray */ if (ts->m2ts_mode && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AC3) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; header_len += 3; if (is_dvb_teletext) { pes_header_stuffing_bytes = 0x24 - header_len; header_len = 0x24; len = payload_size + header_len + 3; /* 3 extra bytes should be added to DVB subtitle payload: 0x20 0x00 at the beginning and trailing 0xff */ if (is_dvb_subtitle) { len += 3; payload_size++; if (len > 0xffff) len = 0; if (ts->omit_video_pes_length && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { len = 0; *q++ = len >> 8; *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle and data streams */ if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA) val |= 0x04; *q++ = val; *q++ = flags; *q++ = header_len; if (pts != AV_NOPTS_VALUE) { write_pts(q, flags >> 6, pts); q += 5; if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { write_pts(q, 1, dts); q += 5; if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ /* Set the stream ID extension flag bit to 0 and * write the extended stream ID. */ *q++ = 0x00 | 0x60; /* For Blu-ray AC3 Audio Setting extended flags */ if (ts->m2ts_mode && pes_extension && st->codecpar->codec_id == AV_CODEC_ID_AC3) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ *q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on blue-rays) */ if (is_dvb_subtitle) { /* First two fields of DVB subtitles PES data: * data_identifier: for DVB subtitle streams shall be coded with the value 0x20 * subtitle_stream_id: for DVB subtitle stream shall be identified by the value 0x00 */ *q++ = 0x20; *q++ = 0x00; if (is_dvb_teletext) { memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; is_start = 0; /* header size */ header_len = q - buf; /* data len */ len = TS_PACKET_SIZE - header_len; if (len > payload_size) len = payload_size; stuffing_len = TS_PACKET_SIZE - header_len - len; if (stuffing_len > 0) { /* add stuffing with AFC */ if (buf[3] & 0x20) { /* stuffing already present: increase its size */ afc_len = buf[4] + 1; memmove(buf + 4 + afc_len + stuffing_len, buf + 4 + afc_len, header_len - (4 + afc_len)); buf[4] += stuffing_len; memset(buf + 4 + afc_len, 0xff, stuffing_len); } else { /* add stuffing */ memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4); buf[3] |= 0x20; buf[4] = stuffing_len - 1; if (stuffing_len >= 2) { buf[5] = 0x00; memset(buf + 6, 0xff, stuffing_len - 2); if (is_dvb_subtitle && payload_size == len) { memcpy(buf + TS_PACKET_SIZE - len, payload, len - 1); buf[TS_PACKET_SIZE - 1] = 0xff; /* end_of_PES_data_field_marker: an 8-bit field with fixed contents 0xff for DVB subtitle */ } else { memcpy(buf + TS_PACKET_SIZE - len, payload, len); payload += len; payload_size -= len; mpegts_prefix_m2ts_header(s); avio_write(s->pb, buf, TS_PACKET_SIZE); ts_st->prev_payload_key = key;


void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap) { int i, j, end1, v, address; /* special case, if snr offset is -960, set all bap's to zero */ if (snr_offset == -960) { memset(bap, 0, 256); return; } i = start; j = bin_to_band_tab[start]; do { v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor; end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end); for (; i < end1; i++) { address = av_clip((psd[i] - v) >> 5, 0, 63); bap[i] = bap_tab[address]; } } while (end > band_start_tab[j++]); }


static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, uint16_t **refcount_table, int64_t *refcount_table_size, int64_t l2_offset, int flags) { BDRVQcowState *s = bs->opaque; uint64_t *l2_table, l2_entry; uint64_t next_contiguous_offset = 0; int i, l2_size, nb_csectors, ret; /* Read L2 table from disk */ l2_size = s->l2_size * sizeof(uint64_t); l2_table = g_malloc(l2_size); ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size); if (ret < 0) { fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); res->check_errors++; goto fail; } /* Do the actual checks */ for(i = 0; i < s->l2_size; i++) { l2_entry = be64_to_cpu(l2_table[i]); switch (qcow2_get_cluster_type(l2_entry)) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters don't have QCOW_OFLAG_COPIED */ if (l2_entry & QCOW_OFLAG_COPIED) { fprintf(stderr, "ERROR: cluster %" PRId64 ": " "copied flag must never be set for compressed " "clusters\n", l2_entry >> s->cluster_bits); l2_entry &= ~QCOW_OFLAG_COPIED; res->corruptions++; } /* Mark cluster as used */ nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; l2_entry &= s->cluster_offset_mask; ret = inc_refcounts(bs, res, refcount_table, refcount_table_size, l2_entry & ~511, nb_csectors * 512); if (ret < 0) { goto fail; } if (flags & CHECK_FRAG_INFO) { res->bfi.allocated_clusters++; res->bfi.compressed_clusters++; /* Compressed clusters are fragmented by nature. Since they * take up sub-sector space but we only have sector granularity * I/O we need to re-read the same sectors even for adjacent * compressed clusters. */ res->bfi.fragmented_clusters++; } break; case QCOW2_CLUSTER_ZERO: if ((l2_entry & L2E_OFFSET_MASK) == 0) { break; } /* fall through */ case QCOW2_CLUSTER_NORMAL: { uint64_t offset = l2_entry & L2E_OFFSET_MASK; if (flags & CHECK_FRAG_INFO) { res->bfi.allocated_clusters++; if (next_contiguous_offset && offset != next_contiguous_offset) { res->bfi.fragmented_clusters++; } next_contiguous_offset = offset + s->cluster_size; } /* Mark cluster as used */ ret = inc_refcounts(bs, res, refcount_table, refcount_table_size, offset, s->cluster_size); if (ret < 0) { goto fail; } /* Correct offsets are cluster aligned */ if (offset_into_cluster(s, offset)) { fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not " "properly aligned; L2 entry corrupted.\n", offset); res->corruptions++; } break; } case QCOW2_CLUSTER_UNALLOCATED: break; default: abort(); } } g_free(l2_table); return 0; fail: g_free(l2_table); return ret; }


static inline void mix_3f_to_mono(AC3DecodeContext *ctx) { int i; float (*output)[256] = ctx->audio_block.block_output; for (i = 0; i < 256; i++) output[1][i] += (output[2][i] + output[3][i]); memset(output[2], 0, sizeof(output[2])); memset(output[3], 0, sizeof(output[3])); }


int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) { int pqindex, lowquant; int status; int mbmodetab, imvtab, icbptab, twomvbptab, fourmvbptab; /* useful only for debugging */ int scale, shift, i; /* for initializing LUT for intensity compensation */ v->numref=0; v->p_frame_skipped = 0; if (v->second_field) { if(v->fcm!=2 || v->field_mode!=1) return -1; v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; if (v->fptype & 4) v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; v->s.current_picture_ptr->f.pict_type = v->s.pict_type; if (!v->pic_header_flag) goto parse_common_info; } v->field_mode = 0; if (v->interlace) { v->fcm = decode012(gb); if (v->fcm) { if (v->fcm == ILACE_FIELD) v->field_mode = 1; if (!v->warn_interlaced++) av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is incomplete\n"); } } else { v->fcm = PROGRESSIVE; } if (v->field_mode) { v->fptype = get_bits(gb, 3); v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; if (v->fptype & 4) // B-picture v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; } else { switch (get_unary(gb, 0, 4)) { case 0: v->s.pict_type = AV_PICTURE_TYPE_P; break; case 1: v->s.pict_type = AV_PICTURE_TYPE_B; break; case 2: v->s.pict_type = AV_PICTURE_TYPE_I; break; case 3: v->s.pict_type = AV_PICTURE_TYPE_BI; break; case 4: v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic v->p_frame_skipped = 1; break; } } if (v->tfcntrflag) skip_bits(gb, 8); if (v->broadcast) { if (!v->interlace || v->psf) { v->rptfrm = get_bits(gb, 2); } else { v->tff = get_bits1(gb); v->rff = get_bits1(gb); } } if (v->panscanflag) { av_log_missing_feature(v->s.avctx, "Pan-scan", 0); //... } if (v->p_frame_skipped) { return 0; } v->rnd = get_bits1(gb); if (v->interlace) v->uvsamp = get_bits1(gb); if(!ff_vc1_bfraction_vlc.table) return 0; //parsing only, vlc tables havnt been allocated if (v->field_mode) { if (!v->refdist_flag) v->refdist = 0; else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) { v->refdist = get_bits(gb, 2); if (v->refdist == 3) v->refdist += get_unary(gb, 0, 16); } if ((v->s.pict_type == AV_PICTURE_TYPE_B) || (v->s.pict_type == AV_PICTURE_TYPE_BI)) { 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]; v->frfd = (v->bfraction * v->refdist) >> 8; v->brfd = v->refdist - v->frfd - 1; if (v->brfd < 0) v->brfd = 0; } goto parse_common_info; } if (v->fcm == PROGRESSIVE) { if (v->finterpflag) v->interpfrm = get_bits1(gb); if (v->s.pict_type == AV_PICTURE_TYPE_B) { 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]; if (v->bfraction == 0) { v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */ } } } parse_common_info: if (v->field_mode) v->cur_field_type = !(v->tff ^ v->second_field); pqindex = get_bits(gb, 5); if (!pqindex) return -1; v->pqindex = pqindex; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) v->pq = ff_vc1_pquant_table[0][pqindex]; else v->pq = ff_vc1_pquant_table[1][pqindex]; v->pquantizer = 1; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) v->pquantizer = pqindex < 9; if (v->quantizer_mode == QUANT_NON_UNIFORM) v->pquantizer = 0; v->pqindex = pqindex; if (pqindex < 9) v->halfpq = get_bits1(gb); else v->halfpq = 0; if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) v->pquantizer = get_bits1(gb); if (v->postprocflag) v->postproc = get_bits(gb, 2); if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) v->use_ic = 0; if (v->parse_only) return 0; switch (v->s.pict_type) { case AV_PICTURE_TYPE_I: case AV_PICTURE_TYPE_BI: if (v->fcm == ILACE_FRAME) { //interlace frame picture status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); } status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); v->condover = CONDOVER_NONE; if (v->overlap && v->pq <= 8) { v->condover = decode012(gb); if (v->condover == CONDOVER_SELECT) { status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); } } break; case AV_PICTURE_TYPE_P: if (v->field_mode) { v->numref = get_bits1(gb); if (!v->numref) { v->reffield = get_bits1(gb); v->ref_field_type[0] = v->reffield ^ !v->cur_field_type; } } if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); else v->mvrange = 0; if (v->interlace) { if (v->extended_dmv) v->dmvrange = get_unary(gb, 0, 3); else v->dmvrange = 0; if (v->fcm == ILACE_FRAME) { // interlaced frame picture v->fourmvswitch = get_bits1(gb); v->intcomp = get_bits1(gb); if (v->intcomp) { v->lumscale = get_bits(gb, 6); v->lumshift = get_bits(gb, 6); INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv); } status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); mbmodetab = get_bits(gb, 2); if (v->fourmvswitch) v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[mbmodetab]; else v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab]; imvtab = get_bits(gb, 2); v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab]; // interlaced p-picture cbpcy range is [1, 63] icbptab = get_bits(gb, 3); v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; twomvbptab = get_bits(gb, 2); v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab]; if (v->fourmvswitch) { fourmvbptab = get_bits(gb, 2); v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; } } } v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 v->range_x = 1 << (v->k_x - 1); v->range_y = 1 << (v->k_y - 1); if (v->pq < 5) v->tt_index = 0; else if (v->pq < 13) v->tt_index = 1; else v->tt_index = 2; if (v->fcm != ILACE_FRAME) { int mvmode; mvmode = get_unary(gb, 1, 4); lowquant = (v->pq > 12) ? 0 : 1; v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode]; if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { int mvmode2; mvmode2 = get_unary(gb, 1, 3); v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2]; if (v->field_mode) v->intcompfield = decode210(gb); v->lumscale = get_bits(gb, 6); v->lumshift = get_bits(gb, 6); INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv); if ((v->field_mode) && !v->intcompfield) { v->lumscale2 = get_bits(gb, 6); v->lumshift2 = get_bits(gb, 6); INIT_LUT(v->lumscale2, v->lumshift2, v->luty2, v->lutuv2); } v->use_ic = 1; } v->qs_last = v->s.quarter_sample; if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) v->s.quarter_sample = 0; else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) v->s.quarter_sample = 0; else v->s.quarter_sample = 1; } else v->s.quarter_sample = 1; v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); } if (v->fcm == PROGRESSIVE) { // progressive if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) { status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); } else { v->mv_type_is_raw = 0; memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height); } status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); /* Hopefully this is correct for P frames */ v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; } else if (v->fcm == ILACE_FRAME) { // frame interlaced v->qs_last = v->s.quarter_sample; v->s.quarter_sample = 1; v->s.mspel = 1; } else { // field interlaced mbmodetab = get_bits(gb, 3); imvtab = get_bits(gb, 2 + v->numref); if (!v->numref) v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab]; else v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab]; icbptab = get_bits(gb, 3); v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) { fourmvbptab = get_bits(gb, 2); v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab]; } else { v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab]; } } if (v->dquant) { av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(v); } v->ttfrm = 0; //FIXME Is that so ? if (v->vstransform) { v->ttmbf = get_bits1(gb); if (v->ttmbf) { v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; v->ttfrm = TT_8X8; } break; case AV_PICTURE_TYPE_B: if (v->fcm == ILACE_FRAME) { 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]; if (v->bfraction == 0) { return -1; } } if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); else v->mvrange = 0; v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 v->range_x = 1 << (v->k_x - 1); v->range_y = 1 << (v->k_y - 1); if (v->pq < 5) v->tt_index = 0; else if (v->pq < 13) v->tt_index = 1; else v->tt_index = 2; if (v->field_mode) { int mvmode; av_log(v->s.avctx, AV_LOG_DEBUG, "B Fields\n"); if (v->extended_dmv) v->dmvrange = get_unary(gb, 0, 3); mvmode = get_unary(gb, 1, 3); lowquant = (v->pq > 12) ? 0 : 1; v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode]; v->qs_last = v->s.quarter_sample; v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV); v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || v->mv_mode == MV_PMODE_1MV_HPEL); status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); mbmodetab = get_bits(gb, 3); if (v->mv_mode == MV_PMODE_MIXED_MV) v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab]; else v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab]; imvtab = get_bits(gb, 3); v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab]; icbptab = get_bits(gb, 3); v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; if (v->mv_mode == MV_PMODE_MIXED_MV) { fourmvbptab = get_bits(gb, 2); v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; } v->numref = 1; // interlaced field B pictures are always 2-ref } else if (v->fcm == ILACE_FRAME) { if (v->extended_dmv) v->dmvrange = get_unary(gb, 0, 3); get_bits1(gb); /* intcomp - present but shall always be 0 */ v->intcomp = 0; v->mv_mode = MV_PMODE_1MV; v->fourmvswitch = 0; v->qs_last = v->s.quarter_sample; v->s.quarter_sample = 1; v->s.mspel = 1; status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); mbmodetab = get_bits(gb, 2); v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab]; imvtab = get_bits(gb, 2); v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab]; // interlaced p/b-picture cbpcy range is [1, 63] icbptab = get_bits(gb, 3); v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; twomvbptab = get_bits(gb, 2); v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab]; fourmvbptab = get_bits(gb, 2); v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; } else { v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; v->qs_last = v->s.quarter_sample; v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV); v->s.mspel = v->s.quarter_sample; status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); v->s.mv_table_index = get_bits(gb, 2); v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; } if (v->dquant) { av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(v); } v->ttfrm = 0; if (v->vstransform) { v->ttmbf = get_bits1(gb); if (v->ttmbf) { v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; v->ttfrm = TT_8X8; } break; } if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) { v->range_x <<= 1; v->range_y <<= 1; } /* AC Syntax */ v->c_ac_table_index = decode012(gb); if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) { v->y_ac_table_index = decode012(gb); } /* DC Syntax */ v->s.dc_table_index = get_bits1(gb); if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) && v->dquant) { av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(v); } v->bi_type = 0; if (v->s.pict_type == AV_PICTURE_TYPE_BI) { v->s.pict_type = AV_PICTURE_TYPE_B; v->bi_type = 1; } return 0; }


static int vivo_probe(AVProbeData *p) { const unsigned char *buf = p->buf; unsigned c, length = 0; // stream must start with packet of type 0 and sequence number 0 if (*buf++ != 0) return 0; // read at most 2 bytes of coded length c = *buf++; length = c & 0x7F; if (c & 0x80) { c = *buf++; length = (length << 7) | (c & 0x7F); } if (c & 0x80 || length > 1024 || length < 21) return 0; if (memcmp(buf, "\r\nVersion:Vivo/", 15)) return 0; buf += 15; if (*buf < '0' && *buf > '2') return 0; return AVPROBE_SCORE_MAX; }


static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time) { char buf[1024]; AVBPrint buf_script; OutputStream *ost; AVFormatContext *oc; int64_t total_size; AVCodecContext *enc; int frame_number, vid, i; double bitrate; int64_t pts = INT64_MIN; static int64_t last_time = -1; static int qp_histogram[52]; int hours, mins, secs, us; if (!print_stats && !is_last_report && !progress_avio) return; if (!is_last_report) { if (last_time == -1) { last_time = cur_time; return; } if ((cur_time - last_time) < 500000) return; last_time = cur_time; } oc = output_files[0]->ctx; total_size = avio_size(oc->pb); if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too total_size = avio_tell(oc->pb); buf[0] = '\0'; vid = 0; av_bprint_init(&buf_script, 0, 1); for (i = 0; i < nb_output_streams; i++) { float q = -1; ost = output_streams[i]; enc = ost->enc_ctx; if (!ost->stream_copy && enc->coded_frame) q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps, t = (cur_time-timer_start) / 1000000.0; frame_number = ost->frame_number; fps = t > 1 ? frame_number / t : 0; snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3.*f q=%3.1f ", frame_number, fps < 9.95, fps, q); av_bprintf(&buf_script, "frame=%d\n", frame_number); av_bprintf(&buf_script, "fps=%.1f\n", fps); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); if (is_last_report) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L"); if (qp_hist) { int j; int qp = lrintf(q); if (qp >= 0 && qp < FF_ARRAY_ELEMS(qp_histogram)) qp_histogram[qp]++; for (j = 0; j < 32; j++) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log2(qp_histogram[j] + 1))); } if ((enc->flags&CODEC_FLAG_PSNR) && (enc->coded_frame || is_last_report)) { int j; double error, error_sum = 0; double scale, scale_sum = 0; double p; char type[3] = { 'Y','U','V' }; snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR="); for (j = 0; j < 3; j++) { if (is_last_report) { error = enc->error[j]; scale = enc->width * enc->height * 255.0 * 255.0 * frame_number; } else { error = enc->coded_frame->error[j]; scale = enc->width * enc->height * 255.0 * 255.0; } if (j) scale /= 4; error_sum += error; scale_sum += scale; p = psnr(error / scale); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], p); av_bprintf(&buf_script, "stream_%d_%d_psnr_%c=%2.2f\n", ost->file_index, ost->index, type[j] | 32, p); } p = psnr(error_sum / scale_sum); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum / scale_sum)); av_bprintf(&buf_script, "stream_%d_%d_psnr_all=%2.2f\n", ost->file_index, ost->index, p); } vid = 1; } /* compute min output value */ if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_droped; } secs = pts / AV_TIME_BASE; us = pts % AV_TIME_BASE; mins = secs / 60; secs %= 60; hours = mins / 60; mins %= 60; bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1; if (total_size < 0) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "size=N/A time="); else snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "size=%8.0fkB time=", total_size / 1024.0); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02d:%02d:%02d.%02d ", hours, mins, secs, (100 * us) / AV_TIME_BASE); if (bitrate < 0) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),"bitrate=N/A"); av_bprintf(&buf_script, "bitrate=N/A\n"); }else{ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),"bitrate=%6.1fkbits/s", bitrate); av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate); } if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n"); else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size); av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts); av_bprintf(&buf_script, "out_time=%02d:%02d:%02d.%06d\n", hours, mins, secs, us); if (nb_frames_dup || nb_frames_drop) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup); av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop); if (print_stats || is_last_report) { const char end = is_last_report ? '\n' : '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf, end); } else av_log(NULL, AV_LOG_INFO, "%s %c", buf, end); fflush(stderr); } if (progress_avio) { av_bprintf(&buf_script, "progress=%s\n", is_last_report ? "end" : "continue"); avio_write(progress_avio, buf_script.str, FFMIN(buf_script.len, buf_script.size - 1)); avio_flush(progress_avio); av_bprint_finalize(&buf_script, NULL); if (is_last_report) { avio_closep(&progress_avio); } } if (is_last_report) print_final_stats(total_size); }


static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size) { put_flush_packet(bc); nut->last_packet_start= nut->packet_start; nut->packet_start+= nut->written_packet_size; nut->packet_size_pos = url_ftell(bc); nut->written_packet_size = max_size; /* packet header */ put_v(bc, nut->written_packet_size); /* forward ptr */ put_v(bc, nut->packet_start - nut->last_packet_start); /* backward ptr */ return 0; }