static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, int width) { #ifdef HAVE_MMX asm volatile( "mov %2, %%"REG_a" \n\t" "movq "MANGLE(bgr2YCoeff)", %%mm6 \n\t" "movq "MANGLE(w1111)", %%mm5 \n\t" "pxor %%mm7, %%mm7 \n\t" "lea (%%"REG_a", %%"REG_a", 2), %%"REG_b"\n\t" ".balign 16 \n\t" "1: \n\t" PREFETCH" 64(%0, %%"REG_b") \n\t" "movd (%0, %%"REG_b"), %%mm0 \n\t" "movd 3(%0, %%"REG_b"), %%mm1 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "movd 6(%0, %%"REG_b"), %%mm2 \n\t" "movd 9(%0, %%"REG_b"), %%mm3 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "punpcklbw %%mm7, %%mm3 \n\t" "pmaddwd %%mm6, %%mm0 \n\t" "pmaddwd %%mm6, %%mm1 \n\t" "pmaddwd %%mm6, %%mm2 \n\t" "pmaddwd %%mm6, %%mm3 \n\t" #ifndef FAST_BGR2YV12 "psrad $8, %%mm0 \n\t" "psrad $8, %%mm1 \n\t" "psrad $8, %%mm2 \n\t" "psrad $8, %%mm3 \n\t" #endif "packssdw %%mm1, %%mm0 \n\t" "packssdw %%mm3, %%mm2 \n\t" "pmaddwd %%mm5, %%mm0 \n\t" "pmaddwd %%mm5, %%mm2 \n\t" "packssdw %%mm2, %%mm0 \n\t" "psraw $7, %%mm0 \n\t" "movd 12(%0, %%"REG_b"), %%mm4 \n\t" "movd 15(%0, %%"REG_b"), %%mm1 \n\t" "punpcklbw %%mm7, %%mm4 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "movd 18(%0, %%"REG_b"), %%mm2 \n\t" "movd 21(%0, %%"REG_b"), %%mm3 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "punpcklbw %%mm7, %%mm3 \n\t" "pmaddwd %%mm6, %%mm4 \n\t" "pmaddwd %%mm6, %%mm1 \n\t" "pmaddwd %%mm6, %%mm2 \n\t" "pmaddwd %%mm6, %%mm3 \n\t" #ifndef FAST_BGR2YV12 "psrad $8, %%mm4 \n\t" "psrad $8, %%mm1 \n\t" "psrad $8, %%mm2 \n\t" "psrad $8, %%mm3 \n\t" #endif "packssdw %%mm1, %%mm4 \n\t" "packssdw %%mm3, %%mm2 \n\t" "pmaddwd %%mm5, %%mm4 \n\t" "pmaddwd %%mm5, %%mm2 \n\t" "add $24, %%"REG_b" \n\t" "packssdw %%mm2, %%mm4 \n\t" "psraw $7, %%mm4 \n\t" "packuswb %%mm4, %%mm0 \n\t" "paddusb "MANGLE(bgr2YOffset)", %%mm0 \n\t" "movq %%mm0, (%1, %%"REG_a") \n\t" "add $8, %%"REG_a" \n\t" " js 1b \n\t" : : "r" (src+width*3), "r" (dst+width), "g" ((long)-width) : "%"REG_a, "%"REG_b ); #else int i; for(i=0; i<width; i++) { int b= src[i*3+0]; int g= src[i*3+1]; int r= src[i*3+2]; dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT); } #endif }


void dsputil_init_armv4l(void) { // ff_idct = j_rev_dct_ARM; }


static void RENAME(resample_one)(DELEM *dst, const DELEM *src, int dst_size, int64_t index2, int64_t incr) { int dst_index; for (dst_index = 0; dst_index < dst_size; dst_index++) { dst[dst_index] = src[index2 >> 32]; index2 += incr; } }


static int qemu_gluster_create(const char *filename, QEMUOptionParameter *options, Error **errp) { struct glfs *glfs; struct glfs_fd *fd; int ret = 0; int prealloc = 0; int64_t total_size = 0; GlusterConf *gconf = g_malloc0(sizeof(GlusterConf)); glfs = qemu_gluster_init(gconf, filename, errp); if (!glfs) { ret = -EINVAL; goto out; } while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { total_size = options->value.n / BDRV_SECTOR_SIZE; } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) { if (!options->value.s || !strcmp(options->value.s, "off")) { prealloc = 0; } else if (!strcmp(options->value.s, "full") && gluster_supports_zerofill()) { prealloc = 1; } else { error_setg(errp, "Invalid preallocation mode: '%s'" " or GlusterFS doesn't support zerofill API", options->value.s); ret = -EINVAL; goto out; } } options++; } fd = glfs_creat(glfs, gconf->image, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR); if (!fd) { ret = -errno; } else { if (!glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE)) { if (prealloc && qemu_gluster_zerofill(fd, 0, total_size * BDRV_SECTOR_SIZE)) { ret = -errno; } } else { ret = -errno; } if (glfs_close(fd) != 0) { ret = -errno; } } out: qemu_gluster_gconf_free(gconf); if (glfs) { glfs_fini(glfs); } return ret; }


void OPPROTO op_subfme (void) { T0 = ~T0 + xer_ca - 1; if (likely((uint32_t)T0 != (uint32_t)-1)) xer_ca = 1; RETURN(); }


int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags) { ssize_t ret; NBDClientSession *client = nbd_get_client_session(bs); NBDRequest request = { .type = NBD_CMD_WRITE_ZEROES, .from = offset, .len = count, }; NBDReply reply; if (!(client->nbdflags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; } if (flags & BDRV_REQ_FUA) { assert(client->nbdflags & NBD_FLAG_SEND_FUA); request.flags |= NBD_CMD_FLAG_FUA; } if (!(flags & BDRV_REQ_MAY_UNMAP)) { request.flags |= NBD_CMD_FLAG_NO_HOLE; } nbd_coroutine_start(client, &request); ret = nbd_co_send_request(bs, &request, NULL); if (ret < 0) { reply.error = -ret; } else { nbd_co_receive_reply(client, &request, &reply, NULL); } nbd_coroutine_end(bs, &request); return -reply.error; }


static void usbredir_control_packet(void *priv, uint32_t id, struct usb_redir_control_packet_header *control_packet, uint8_t *data, int data_len) { USBRedirDevice *dev = priv; int len = control_packet->length; AsyncURB *aurb; DPRINTF("ctrl-in status %d len %d id %u\n", control_packet->status, len, id); aurb = async_find(dev, id); if (!aurb) { free(data); return; } aurb->control_packet.status = control_packet->status; aurb->control_packet.length = control_packet->length; if (memcmp(&aurb->control_packet, control_packet, sizeof(*control_packet))) { ERROR("return control packet mismatch, please report this!\n"); len = USB_RET_NAK; } if (aurb->packet) { len = usbredir_handle_status(dev, control_packet->status, len); if (len > 0) { usbredir_log_data(dev, "ctrl data in:", data, data_len); if (data_len <= sizeof(dev->dev.data_buf)) { memcpy(dev->dev.data_buf, data, data_len); } else { ERROR("ctrl buffer too small (%d > %zu)\n", data_len, sizeof(dev->dev.data_buf)); len = USB_RET_STALL; } } aurb->packet->len = len; usb_generic_async_ctrl_complete(&dev->dev, aurb->packet); } async_free(dev, aurb); free(data); }


int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame) { if (avctx->internal->pkt) { frame->pkt_pts = avctx->internal->pkt->pts; av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos); av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration); av_frame_set_pkt_size (frame, avctx->internal->pkt->size); } else { frame->pkt_pts = AV_NOPTS_VALUE; av_frame_set_pkt_pos (frame, -1); av_frame_set_pkt_duration(frame, 0); av_frame_set_pkt_size (frame, -1); } frame->reordered_opaque = avctx->reordered_opaque; switch (avctx->codec->type) { case AVMEDIA_TYPE_VIDEO: if (frame->format < 0) frame->format = avctx->pix_fmt; if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; if (av_frame_get_colorspace(frame) == AVCOL_SPC_UNSPECIFIED) av_frame_set_colorspace(frame, avctx->colorspace); if (av_frame_get_color_range(frame) == AVCOL_RANGE_UNSPECIFIED) av_frame_set_color_range(frame, avctx->color_range); break; case AVMEDIA_TYPE_AUDIO: if (!frame->sample_rate) frame->sample_rate = avctx->sample_rate; if (frame->format < 0) frame->format = avctx->sample_fmt; if (!frame->channel_layout) { if (avctx->channel_layout) { if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) { av_log(avctx, AV_LOG_ERROR, "Inconsistent channel " "configuration.\n"); return AVERROR(EINVAL); } frame->channel_layout = avctx->channel_layout; } else { if (avctx->channels > FF_SANE_NB_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n", avctx->channels); return AVERROR(ENOSYS); } } } av_frame_set_channels(frame, avctx->channels); break; } return 0; }


AVFilterContext *avfilter_open(AVFilter *filter, char *inst_name) { AVFilterContext *ret = av_malloc(sizeof(AVFilterContext)); ret->av_class = av_mallocz(sizeof(AVClass)); ret->av_class->item_name = filter_name; ret->filter = filter; ret->name = inst_name ? av_strdup(inst_name) : NULL; ret->priv = av_mallocz(filter->priv_size); ret->input_count = pad_count(filter->inputs); ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count); ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); ret->output_count = pad_count(filter->outputs); ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count); ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); return ret; }


static int vnc_zlib_stop(VncState *vs) { z_streamp zstream = &vs->zlib.stream; int previous_out; // switch back to normal output/zlib buffers vs->zlib.zlib = vs->output; vs->output = vs->zlib.tmp; // compress the zlib buffer // initialize the stream // XXX need one stream per session if (zstream->opaque != vs) { int err; VNC_DEBUG("VNC: initializing zlib stream\n"); VNC_DEBUG("VNC: opaque = %p | vs = %p\n", zstream->opaque, vs); zstream->zalloc = vnc_zlib_zalloc; zstream->zfree = vnc_zlib_zfree; err = deflateInit2(zstream, vs->tight.compression, Z_DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (err != Z_OK) { fprintf(stderr, "VNC: error initializing zlib\n"); return -1; } vs->zlib.level = vs->tight.compression; zstream->opaque = vs; } if (vs->tight.compression != vs->zlib.level) { if (deflateParams(zstream, vs->tight.compression, Z_DEFAULT_STRATEGY) != Z_OK) { return -1; } vs->zlib.level = vs->tight.compression; } // reserve memory in output buffer buffer_reserve(&vs->output, vs->zlib.zlib.offset + 64); // set pointers zstream->next_in = vs->zlib.zlib.buffer; zstream->avail_in = vs->zlib.zlib.offset; zstream->next_out = vs->output.buffer + vs->output.offset; zstream->avail_out = vs->output.capacity - vs->output.offset; zstream->data_type = Z_BINARY; previous_out = zstream->total_out; // start encoding if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) { fprintf(stderr, "VNC: error during zlib compression\n"); return -1; } vs->output.offset = vs->output.capacity - zstream->avail_out; return zstream->total_out - previous_out; }


void OPPROTO op_divw_AX_T0(void) { unsigned int num, den, q, r; num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); den = (T0 & 0xffff); if (den == 0) { raise_exception(EXCP00_DIVZ); } q = (num / den) & 0xffff; r = (num % den) & 0xffff; EAX = (EAX & ~0xffff) | q; EDX = (EDX & ~0xffff) | r; }


static void fic_draw_cursor(AVCodecContext *avctx, int cur_x, int cur_y) { FICContext *ctx = avctx->priv_data; uint8_t *ptr = ctx->cursor_buf; uint8_t *dstptr[3]; uint8_t planes[4][1024]; uint8_t chroma[3][256]; int i, j, p; /* Convert to YUVA444. */ for (i = 0; i < 1024; i++) { planes[0][i] = av_clip_uint8((( 25 * ptr[0] + 129 * ptr[1] + 66 * ptr[2]) / 255) + 16); planes[1][i] = av_clip_uint8(((-38 * ptr[0] + 112 * ptr[1] + -74 * ptr[2]) / 255) + 128); planes[2][i] = av_clip_uint8(((-18 * ptr[0] + 112 * ptr[1] + -94 * ptr[2]) / 255) + 128); planes[3][i] = ptr[3]; ptr += 4; } /* Subsample chroma. */ for (i = 0; i < 32; i += 2) for (j = 0; j < 32; j += 2) for (p = 0; p < 3; p++) chroma[p][16 * (i / 2) + j / 2] = (planes[p + 1][32 * i + j ] + planes[p + 1][32 * i + j + 1] + planes[p + 1][32 * (i + 1) + j ] + planes[p + 1][32 * (i + 1) + j + 1]) / 4; /* Seek to x/y pos of cursor. */ for (i = 0; i < 3; i++) dstptr[i] = ctx->final_frame->data[i] + (ctx->final_frame->linesize[i] * (cur_y >> !!i)) + (cur_x >> !!i) + !!i; /* Copy. */ for (i = 0; i < FFMIN(32, avctx->height - cur_y) - 1; i += 2) { int lsize = FFMIN(32, avctx->width - cur_x); int csize = lsize / 2; fic_alpha_blend(dstptr[0], planes[0] + i * 32, lsize, planes[3] + i * 32); fic_alpha_blend(dstptr[0] + ctx->final_frame->linesize[0], planes[0] + (i + 1) * 32, lsize, planes[3] + (i + 1) * 32); fic_alpha_blend(dstptr[1], chroma[0] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16); fic_alpha_blend(dstptr[2], chroma[1] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16); dstptr[0] += ctx->final_frame->linesize[0] * 2; dstptr[1] += ctx->final_frame->linesize[1]; dstptr[2] += ctx->final_frame->linesize[2]; } }


static int decode_ref_pic_list_reordering(H264Context *h){ MpegEncContext * const s = &h->s; int list, index; print_short_term(h); print_long_term(h); if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func for(list=0; list<2; list++){ memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); if(get_bits1(&s->gb)){ int pred= h->curr_pic_num; for(index=0; ; index++){ int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb); int pic_id; int i; Picture *ref = NULL; if(reordering_of_pic_nums_idc==3) break; if(index >= h->ref_count[list]){ av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); return -1; } if(reordering_of_pic_nums_idc<3){ if(reordering_of_pic_nums_idc<2){ const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; if(abs_diff_pic_num >= h->max_pic_num){ av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); return -1; } if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; else pred+= abs_diff_pic_num; pred &= h->max_pic_num - 1; for(i= h->short_ref_count-1; i>=0; i--){ ref = h->short_ref[i]; assert(ref->reference == 3); assert(!ref->long_ref); if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer break; } if(i>=0) ref->pic_id= ref->frame_num; }else{ pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx ref = h->long_ref[pic_id]; if(ref){ ref->pic_id= pic_id; assert(ref->reference == 3); assert(ref->long_ref); i=0; }else{ i=-1; } } if (i < 0) { av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME } else { for(i=index; i+1<h->ref_count[list]; i++){ if(ref->long_ref == h->ref_list[list][i].long_ref && ref->pic_id == h->ref_list[list][i].pic_id) break; } for(; i > index; i--){ h->ref_list[list][i]= h->ref_list[list][i-1]; } h->ref_list[list][index]= *ref; } }else{ av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); return -1; } } } if(h->slice_type!=B_TYPE) break; } for(list=0; list<2; list++){ for(index= 0; index < h->ref_count[list]; index++){ if(!h->ref_list[list][index].data[0]) h->ref_list[list][index]= s->current_picture; } if(h->slice_type!=B_TYPE) break; } if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) direct_dist_scale_factor(h); direct_ref_list_init(h); return 0; }


TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *old_op, TCGOpcode opc, int nargs) { int oi = s->gen_next_op_idx; int prev = old_op->prev; int next = old_op - s->gen_op_buf; TCGOp *new_op; tcg_debug_assert(oi < OPC_BUF_SIZE); s->gen_next_op_idx = oi + 1; new_op = &s->gen_op_buf[oi]; *new_op = (TCGOp){ .opc = opc, .prev = prev, .next = next }; s->gen_op_buf[prev].next = oi; old_op->prev = oi; return new_op; }


void FUNCC(ff_h264_idct8_dc_add)(uint8_t *_dst, DCTELEM *block, int stride){ int i, j; int dc = (((dctcoef*)block)[0] + 32) >> 6; INIT_CLIP pixel *dst = (pixel*)_dst; stride /= sizeof(pixel); for( j = 0; j < 8; j++ ) { for( i = 0; i < 8; i++ ) dst[i] = CLIP( dst[i] + dc ); dst += stride; } }


static int svq3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; SVQ3Context *svq3 = avctx->priv_data; H264Context *h = &svq3->h; MpegEncContext *s = &h->s; int buf_size = avpkt->size; int m, mb_type; /* special case for last picture */ if (buf_size == 0) { if (s->next_picture_ptr && !s->low_delay) { *(AVFrame *) data = s->next_picture.f; s->next_picture_ptr = NULL; *got_frame = 1; } return 0; } init_get_bits(&s->gb, buf, 8 * buf_size); s->mb_x = s->mb_y = h->mb_xy = 0; if (svq3_decode_slice_header(avctx)) return -1; s->pict_type = h->slice_type; s->picture_number = h->slice_num; if (avctx->debug & FF_DEBUG_PICT_INFO) av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n", av_get_picture_type_char(s->pict_type), svq3->halfpel_flag, svq3->thirdpel_flag, s->adaptive_quant, s->qscale, h->slice_num); /* for skipping the frame */ s->current_picture.f.pict_type = s->pict_type; s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I); /* Skip B-frames if we do not have reference frames. */ if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B) return 0; if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B || avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I || avctx->skip_frame >= AVDISCARD_ALL) return 0; if (s->next_p_frame_damaged) { if (s->pict_type == AV_PICTURE_TYPE_B) return 0; else s->next_p_frame_damaged = 0; } if (ff_h264_frame_start(h) < 0) return -1; if (s->pict_type == AV_PICTURE_TYPE_B) { h->frame_num_offset = h->slice_num - h->prev_frame_num; if (h->frame_num_offset < 0) h->frame_num_offset += 256; if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) { av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n"); return -1; } } else { h->prev_frame_num = h->frame_num; h->frame_num = h->slice_num; h->prev_frame_num_offset = h->frame_num - h->prev_frame_num; if (h->prev_frame_num_offset < 0) h->prev_frame_num_offset += 256; } for (m = 0; m < 2; m++) { int i; for (i = 0; i < 4; i++) { int j; for (j = -1; j < 4; j++) h->ref_cache[m][scan8[0] + 8 * i + j] = 1; if (i < 3) h->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE; } } for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) { h->mb_xy = s->mb_x + s->mb_y * s->mb_stride; if ((get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits && ((get_bits_count(&s->gb) & 7) == 0 || show_bits(&s->gb, -get_bits_count(&s->gb) & 7) == 0)) { skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb)); s->gb.size_in_bits = 8 * buf_size; if (svq3_decode_slice_header(avctx)) return -1; /* TODO: support s->mb_skip_run */ } mb_type = svq3_get_ue_golomb(&s->gb); if (s->pict_type == AV_PICTURE_TYPE_I) mb_type += 8; else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4) mb_type += 4; if ((unsigned)mb_type > 33 || svq3_decode_mb(svq3, mb_type)) { av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); return -1; } if (mb_type != 0) ff_h264_hl_decode_mb(h); if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay) s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1; } ff_draw_horiz_band(s, 16 * s->mb_y, 16); } ff_MPV_frame_end(s); if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) *(AVFrame *)data = s->current_picture.f; else *(AVFrame *)data = s->last_picture.f; /* Do not output the last pic after seeking. */ if (s->last_picture_ptr || s->low_delay) *got_frame = 1; return buf_size; }


static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) { int i; int a= 2<<s->sprite_warping_accuracy; int rho= 3-s->sprite_warping_accuracy; int r=16/a; const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; int sprite_ref[4][2]; int virtual_ref[2][2]; int w2, h2, w3, h3; int alpha=0, beta=0; int w= s->width; int h= s->height; int min_ab; for(i=0; i<s->num_sprite_warping_points; i++){ int length; int x=0, y=0; length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); if(length){ x= get_xbits(gb, length); } if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */ length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); if(length){ y=get_xbits(gb, length); } skip_bits1(gb); /* marker bit */ s->sprite_traj[i][0]= d[i][0]= x; s->sprite_traj[i][1]= d[i][1]= y; } for(; i<4; i++) s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0; while((1<<alpha)<w) alpha++; while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' w2= 1<<alpha; h2= 1<<beta; // Note, the 4th point isn't used for GMC if(s->divx_version==500 && s->divx_build==413){ sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; } else { sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); } /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) // perhaps it should be reordered to be more readable ... // the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides // so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); virtual_ref[0][1]= 16*vop_ref[0][1] + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); virtual_ref[1][0]= 16*vop_ref[0][0] + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); switch(s->num_sprite_warping_points) { case 0: s->sprite_offset[0][0]= 0; s->sprite_offset[0][1]= 0; s->sprite_offset[1][0]= 0; s->sprite_offset[1][1]= 0; s->sprite_delta[0][0]= a; s->sprite_delta[0][1]= 0; s->sprite_delta[1][0]= 0; s->sprite_delta[1][1]= a; s->sprite_shift[0]= 0; s->sprite_shift[1]= 0; break; case 1: //GMC only s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); s->sprite_delta[0][0]= a; s->sprite_delta[0][1]= 0; s->sprite_delta[1][0]= 0; s->sprite_delta[1][1]= a; s->sprite_shift[0]= 0; s->sprite_shift[1]= 0; break; case 2: s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1]) + (1<<(alpha+rho-1)); s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1]) + (1<<(alpha+rho-1)); s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) +2*w2*r*sprite_ref[0][0] - 16*w2 + (1<<(alpha+rho+1))); s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) +2*w2*r*sprite_ref[0][1] - 16*w2 + (1<<(alpha+rho+1))); s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]); s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); s->sprite_shift[0]= alpha+rho; s->sprite_shift[1]= alpha+rho+2; break; case 3: min_ab= FFMIN(alpha, beta); w3= w2>>min_ab; h3= h2>>min_ab; s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab)) + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0]) + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1]) + (1<<(alpha+beta+rho-min_ab-1)); s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab)) + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0]) + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1]) + (1<<(alpha+beta+rho-min_ab-1)); s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1) + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1) + 2*w2*h3*r*sprite_ref[0][0] - 16*w2*h3 + (1<<(alpha+beta+rho-min_ab+1)); s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1) + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1) + 2*w2*h3*r*sprite_ref[0][1] - 16*w2*h3 + (1<<(alpha+beta+rho-min_ab+1)); s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3; s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3; s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3; s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3; s->sprite_shift[0]= alpha + beta + rho - min_ab; s->sprite_shift[1]= alpha + beta + rho - min_ab + 2; break; } /* try to simplify the situation */ if( s->sprite_delta[0][0] == a<<s->sprite_shift[0] && s->sprite_delta[0][1] == 0 && s->sprite_delta[1][0] == 0 && s->sprite_delta[1][1] == a<<s->sprite_shift[0]) { s->sprite_offset[0][0]>>=s->sprite_shift[0]; s->sprite_offset[0][1]>>=s->sprite_shift[0]; s->sprite_offset[1][0]>>=s->sprite_shift[1]; s->sprite_offset[1][1]>>=s->sprite_shift[1]; s->sprite_delta[0][0]= a; s->sprite_delta[0][1]= 0; s->sprite_delta[1][0]= 0; s->sprite_delta[1][1]= a; s->sprite_shift[0]= 0; s->sprite_shift[1]= 0; s->real_sprite_warping_points=1; } else{ int shift_y= 16 - s->sprite_shift[0]; int shift_c= 16 - s->sprite_shift[1]; for(i=0; i<2; i++){ s->sprite_offset[0][i]<<= shift_y; s->sprite_offset[1][i]<<= shift_c; s->sprite_delta[0][i]<<= shift_y; s->sprite_delta[1][i]<<= shift_y; s->sprite_shift[i]= 16; } s->real_sprite_warping_points= s->num_sprite_warping_points; } }


static int parse(AVCodecParserContext *ctx, AVCodecContext *avctx, const uint8_t **out_data, int *out_size, const uint8_t *data, int size) { VP9ParseContext *s = ctx->priv_data; int full_size = size; int marker; if (size <= 0) { *out_size = 0; *out_data = data; return 0; } if (s->n_frames > 0) { *out_data = data; *out_size = s->size[--s->n_frames]; parse_frame(ctx, *out_data, *out_size); return s->n_frames > 0 ? *out_size : size /* i.e. include idx tail */; } marker = data[size - 1]; if ((marker & 0xe0) == 0xc0) { int nbytes = 1 + ((marker >> 3) & 0x3); int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes; if (size >= idx_sz && data[size - idx_sz] == marker) { const uint8_t *idx = data + size + 1 - idx_sz; int first = 1; switch (nbytes) { #define case_n(a, rd) \ case a: \ while (n_frames--) { \ unsigned sz = rd; \ idx += a; \ if (sz > size) { \ s->n_frames = 0; \ *out_size = size; \ *out_data = data; \ av_log(avctx, AV_LOG_ERROR, \ "Superframe packet size too big: %u > %d\n", \ sz, size); \ return full_size; \ } \ if (first) { \ first = 0; \ *out_data = data; \ *out_size = sz; \ s->n_frames = n_frames; \ } else { \ s->size[n_frames] = sz; \ } \ data += sz; \ size -= sz; \ } \ parse_frame(ctx, *out_data, *out_size); \ return *out_size case_n(1, *idx); case_n(2, AV_RL16(idx)); case_n(3, AV_RL24(idx)); case_n(4, AV_RL32(idx)); } } } *out_data = data; *out_size = size; parse_frame(ctx, data, size); return size; }


void axisdev88_init(MachineState *machine) { ram_addr_t ram_size = machine->ram_size; const char *cpu_model = machine->cpu_model; const char *kernel_filename = machine->kernel_filename; const char *kernel_cmdline = machine->kernel_cmdline; CRISCPU *cpu; CPUCRISState *env; DeviceState *dev; SysBusDevice *s; DriveInfo *nand; qemu_irq irq[30], nmi[2]; void *etraxfs_dmac; struct etraxfs_dma_client *dma_eth; int i; MemoryRegion *address_space_mem = get_system_memory(); MemoryRegion *phys_ram = g_new(MemoryRegion, 1); MemoryRegion *phys_intmem = g_new(MemoryRegion, 1); /* init CPUs */ if (cpu_model == NULL) { cpu_model = "crisv32"; } cpu = cpu_cris_init(cpu_model); env = &cpu->env; /* allocate RAM */ memory_region_allocate_system_memory(phys_ram, NULL, "axisdev88.ram", ram_size); memory_region_add_subregion(address_space_mem, 0x40000000, phys_ram); /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the internal memory. */ memory_region_init_ram(phys_intmem, NULL, "axisdev88.chipram", INTMEM_SIZE, &error_abort); vmstate_register_ram_global(phys_intmem); memory_region_add_subregion(address_space_mem, 0x38000000, phys_intmem); /* Attach a NAND flash to CS1. */ nand = drive_get(IF_MTD, 0, 0); nand_state.nand = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL, NAND_MFR_STMICRO, 0x39); memory_region_init_io(&nand_state.iomem, NULL, &nand_ops, &nand_state, "nand", 0x05000000); memory_region_add_subregion(address_space_mem, 0x10000000, &nand_state.iomem); gpio_state.nand = &nand_state; memory_region_init_io(&gpio_state.iomem, NULL, &gpio_ops, &gpio_state, "gpio", 0x5c); memory_region_add_subregion(address_space_mem, 0x3001a000, &gpio_state.iomem); dev = qdev_create(NULL, "etraxfs,pic"); /* FIXME: Is there a proper way to signal vectors to the CPU core? */ qdev_prop_set_ptr(dev, "interrupt_vector", &env->interrupt_vector); qdev_init_nofail(dev); s = SYS_BUS_DEVICE(dev); sysbus_mmio_map(s, 0, 0x3001c000); sysbus_connect_irq(s, 0, qdev_get_gpio_in(DEVICE(cpu), CRIS_CPU_IRQ)); sysbus_connect_irq(s, 1, qdev_get_gpio_in(DEVICE(cpu), CRIS_CPU_NMI)); for (i = 0; i < 30; i++) { irq[i] = qdev_get_gpio_in(dev, i); } nmi[0] = qdev_get_gpio_in(dev, 30); nmi[1] = qdev_get_gpio_in(dev, 31); etraxfs_dmac = etraxfs_dmac_init(0x30000000, 10); for (i = 0; i < 10; i++) { /* On ETRAX, odd numbered channels are inputs. */ etraxfs_dmac_connect(etraxfs_dmac, i, irq + 7 + i, i & 1); } /* Add the two ethernet blocks. */ dma_eth = g_malloc0(sizeof dma_eth[0] * 4); /* Allocate 4 channels. */ etraxfs_eth_init(&nd_table[0], 0x30034000, 1, &dma_eth[0], &dma_eth[1]); if (nb_nics > 1) { etraxfs_eth_init(&nd_table[1], 0x30036000, 2, &dma_eth[2], &dma_eth[3]); } /* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client(etraxfs_dmac, 0, &dma_eth[0]); etraxfs_dmac_connect_client(etraxfs_dmac, 1, &dma_eth[1]); if (nb_nics > 1) { etraxfs_dmac_connect_client(etraxfs_dmac, 6, &dma_eth[2]); etraxfs_dmac_connect_client(etraxfs_dmac, 7, &dma_eth[3]); } /* 2 timers. */ sysbus_create_varargs("etraxfs,timer", 0x3001e000, irq[0x1b], nmi[1], NULL); sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL); for (i = 0; i < 4; i++) { sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000, irq[0x14 + i]); } if (kernel_filename) { li.image_filename = kernel_filename; li.cmdline = kernel_cmdline; cris_load_image(cpu, &li); } else if (!qtest_enabled()) { fprintf(stderr, "Kernel image must be specified\n"); exit(1); } }


static int mjpeg_decode_app(MJpegDecodeContext *s) { int len, id, i; len = get_bits(&s->gb, 16); if (len < 6) return AVERROR_INVALIDDATA; if (8 * len > get_bits_left(&s->gb)) return AVERROR_INVALIDDATA; id = get_bits_long(&s->gb, 32); len -= 6; if (s->avctx->debug & FF_DEBUG_STARTCODE) { char id_str[32]; av_get_codec_tag_string(id_str, sizeof(id_str), av_bswap32(id)); av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n", id_str, id, len); } /* Buggy AVID, it puts EOI only at every 10th frame. */ /* Also, this fourcc is used by non-avid files too, it holds some information, but it's always present in AVID-created files. */ if (id == AV_RB32("AVI1")) { /* structure: 4bytes AVI1 1bytes polarity 1bytes always zero 4bytes field_size 4bytes field_size_less_padding */ s->buggy_avid = 1; i = get_bits(&s->gb, 8); len--; av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i); #if 0 skip_bits(&s->gb, 8); skip_bits(&s->gb, 32); skip_bits(&s->gb, 32); len -= 10; #endif } // len -= 2; if (id == AV_RB32("JFIF")) { int t_w, t_h, v1, v2; skip_bits(&s->gb, 8); /* the trailing zero-byte */ v1 = get_bits(&s->gb, 8); v2 = get_bits(&s->gb, 8); skip_bits(&s->gb, 8); s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16); s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16); if ( s->avctx->sample_aspect_ratio.num <= 0 || s->avctx->sample_aspect_ratio.den <= 0) { s->avctx->sample_aspect_ratio.num = 0; s->avctx->sample_aspect_ratio.den = 1; } if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n", v1, v2, s->avctx->sample_aspect_ratio.num, s->avctx->sample_aspect_ratio.den); len -= 8; if (len >= 2) { t_w = get_bits(&s->gb, 8); t_h = get_bits(&s->gb, 8); if (t_w && t_h) { /* skip thumbnail */ if (len -10 - (t_w * t_h * 3) > 0) len -= t_w * t_h * 3; } len -= 2; } } if ( id == AV_RB32("Adob") && len >= 7 && show_bits(&s->gb, 8) == 'e' && show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) { skip_bits(&s->gb, 8); /* 'e' */ skip_bits(&s->gb, 16); /* version */ skip_bits(&s->gb, 16); /* flags0 */ skip_bits(&s->gb, 16); /* flags1 */ s->adobe_transform = get_bits(&s->gb, 8); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform); len -= 7; } if (id == AV_RB32("LJIF")) { int rgb = s->rgb; int pegasus_rct = s->pegasus_rct; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n"); skip_bits(&s->gb, 16); /* version ? */ skip_bits(&s->gb, 16); /* unknown always 0? */ skip_bits(&s->gb, 16); /* unknown always 0? */ skip_bits(&s->gb, 16); /* unknown always 0? */ switch (i=get_bits(&s->gb, 8)) { case 1: rgb = 1; pegasus_rct = 0; break; case 2: rgb = 1; pegasus_rct = 1; break; default: av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace %d\n", i); } len -= 9; if (s->got_picture) if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) { av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n"); } s->rgb = rgb; s->pegasus_rct = pegasus_rct; } if (id == AV_RL32("colr") && len > 0) { s->colr = get_bits(&s->gb, 8); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "COLR %d\n", s->colr); len --; } if (id == AV_RL32("xfrm") && len > 0) { s->xfrm = get_bits(&s->gb, 8); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "XFRM %d\n", s->xfrm); len --; } /* JPS extension by VRex */ if (s->start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) { int flags, layout, type; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n"); skip_bits(&s->gb, 32); len -= 4; /* JPS_ */ skip_bits(&s->gb, 16); len -= 2; /* block length */ skip_bits(&s->gb, 8); /* reserved */ flags = get_bits(&s->gb, 8); layout = get_bits(&s->gb, 8); type = get_bits(&s->gb, 8); len -= 4; s->stereo3d = av_stereo3d_alloc(); if (!s->stereo3d) { } if (type == 0) { s->stereo3d->type = AV_STEREO3D_2D; } else if (type == 1) { switch (layout) { case 0x01: s->stereo3d->type = AV_STEREO3D_LINES; break; case 0x02: s->stereo3d->type = AV_STEREO3D_SIDEBYSIDE; break; case 0x03: s->stereo3d->type = AV_STEREO3D_TOPBOTTOM; break; } if (!(flags & 0x04)) { s->stereo3d->flags = AV_STEREO3D_FLAG_INVERT; } } } /* EXIF metadata */ if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) { GetByteContext gbytes; int ret, le, ifd_offset, bytes_read; const uint8_t *aligned; skip_bits(&s->gb, 16); // skip padding len -= 2; // init byte wise reading aligned = align_get_bits(&s->gb); bytestream2_init(&gbytes, aligned, len); // read TIFF header ret = ff_tdecode_header(&gbytes, &le, &ifd_offset); if (ret) { av_log(s->avctx, AV_LOG_ERROR, "mjpeg: invalid TIFF header in EXIF data\n"); } else { bytestream2_seek(&gbytes, ifd_offset, SEEK_SET); // read 0th IFD and store the metadata // (return values > 0 indicate the presence of subimage metadata) ret = avpriv_exif_decode_ifd(s->avctx, &gbytes, le, 0, &s->exif_metadata); if (ret < 0) { av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error decoding EXIF data\n"); } } bytes_read = bytestream2_tell(&gbytes); skip_bits(&s->gb, bytes_read << 3); len -= bytes_read; } /* Apple MJPEG-A */ if ((s->start_code == APP1) && (len > (0x28 - 8))) { id = get_bits_long(&s->gb, 32); len -= 4; /* Apple MJPEG-A */ if (id == AV_RB32("mjpg")) { #if 0 skip_bits(&s->gb, 32); /* field size */ skip_bits(&s->gb, 32); /* pad field size */ skip_bits(&s->gb, 32); /* next off */ skip_bits(&s->gb, 32); /* quant off */ skip_bits(&s->gb, 32); /* huff off */ skip_bits(&s->gb, 32); /* image off */ skip_bits(&s->gb, 32); /* scan off */ skip_bits(&s->gb, 32); /* data off */ #endif if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n"); } } out: /* slow but needed for extreme adobe jpegs */ if (len < 0) av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n"); while (--len > 0) skip_bits(&s->gb, 8); return 0; }


static int do_decode(AVCodecContext *avctx, AVPacket *pkt) { int got_frame; int ret; av_assert0(!avctx->internal->buffer_frame->buf[0]); if (!pkt) pkt = avctx->internal->buffer_pkt; // This is the lesser evil. The field is for compatibility with legacy users // of the legacy API, and users using the new API should not be forced to // even know about this field. avctx->refcounted_frames = 1; // Some codecs (at least wma lossless) will crash when feeding drain packets // after EOF was signaled. if (avctx->internal->draining_done) return AVERROR_EOF; if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame, &got_frame, pkt); if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)) ret = pkt->size; } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame, &got_frame, pkt); } else { ret = AVERROR(EINVAL); } if (ret == AVERROR(EAGAIN)) ret = pkt->size; if (avctx->internal->draining && !got_frame) avctx->internal->draining_done = 1; if (ret < 0) return ret; if (ret >= pkt->size) { av_packet_unref(avctx->internal->buffer_pkt); } else { int consumed = ret; if (pkt != avctx->internal->buffer_pkt) { av_packet_unref(avctx->internal->buffer_pkt); if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0) return ret; } avctx->internal->buffer_pkt->data += consumed; avctx->internal->buffer_pkt->size -= consumed; avctx->internal->buffer_pkt->pts = AV_NOPTS_VALUE; avctx->internal->buffer_pkt->dts = AV_NOPTS_VALUE; } if (got_frame) av_assert0(avctx->internal->buffer_frame->buf[0]); return 0; }


void ff_h264_free_tables(H264Context *h, int free_rbsp) { int i; av_freep(&h->intra4x4_pred_mode); av_freep(&h->chroma_pred_mode_table); av_freep(&h->cbp_table); av_freep(&h->mvd_table[0]); av_freep(&h->mvd_table[1]); av_freep(&h->direct_table); av_freep(&h->non_zero_count); av_freep(&h->slice_table_base); h->slice_table = NULL; av_freep(&h->list_counts); av_freep(&h->mb2b_xy); av_freep(&h->mb2br_xy); av_buffer_pool_uninit(&h->qscale_table_pool); av_buffer_pool_uninit(&h->mb_type_pool); av_buffer_pool_uninit(&h->motion_val_pool); av_buffer_pool_uninit(&h->ref_index_pool); if (free_rbsp && h->DPB) { for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) ff_h264_unref_picture(h, &h->DPB[i]); av_freep(&h->DPB); } h->cur_pic_ptr = NULL; for (i = 0; i < h->nb_slice_ctx; i++) { H264SliceContext *sl = &h->slice_ctx[i]; av_freep(&sl->dc_val_base); av_freep(&sl->er.mb_index2xy); av_freep(&sl->er.error_status_table); av_freep(&sl->er.er_temp_buffer); av_freep(&sl->bipred_scratchpad); av_freep(&sl->edge_emu_buffer); av_freep(&sl->top_borders[0]); av_freep(&sl->top_borders[1]); sl->bipred_scratchpad_allocated = 0; sl->edge_emu_buffer_allocated = 0; sl->top_borders_allocated[0] = 0; sl->top_borders_allocated[1] = 0; if (free_rbsp) { av_freep(&sl->rbsp_buffer); sl->rbsp_buffer_size = 0; } } }


static bool s390_gen_initial_iplb(S390IPLState *ipl) { DeviceState *dev_st; dev_st = get_boot_device(0); if (dev_st) { VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *) object_dynamic_cast(OBJECT(qdev_get_parent_bus(dev_st)->parent), TYPE_VIRTIO_CCW_DEVICE); SCSIDevice *sd = (SCSIDevice *) object_dynamic_cast(OBJECT(dev_st), TYPE_SCSI_DEVICE); if (virtio_ccw_dev) { CcwDevice *ccw_dev = CCW_DEVICE(virtio_ccw_dev); ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN); ipl->iplb.blk0_len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN); ipl->iplb.pbt = S390_IPL_TYPE_CCW; ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno); ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3; return true; } else if (sd) { SCSIBus *bus = scsi_bus_from_device(sd); VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus); VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw, vdev); CcwDevice *ccw_dev = CCW_DEVICE(scsi_ccw); ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN); ipl->iplb.blk0_len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN); ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI; ipl->iplb.scsi.lun = cpu_to_be32(sd->lun); ipl->iplb.scsi.target = cpu_to_be16(sd->id); ipl->iplb.scsi.channel = cpu_to_be16(sd->channel); ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno); ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3; return true; return false;


static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch) { int bin, blk, gs; int end_bap, gaq_mode; GetBitContext *gbc = &s->gbc; int gaq_gain[AC3_MAX_COEFS]; gaq_mode = get_bits(gbc, 2); end_bap = (gaq_mode < 2) ? 12 : 17; /* if GAQ gain is used, decode gain codes for bins with hebap between 8 and end_bap */ gs = 0; if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) { /* read 1-bit GAQ gain codes */ for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap) gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1); } } else if (gaq_mode == EAC3_GAQ_124) { /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */ int gc = 2; for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) { if (gc++ == 2) { int group_code = get_bits(gbc, 5); if (group_code > 26) { av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n"); group_code = 26; } gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0]; gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1]; gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2]; gc = 0; } } } } gs=0; for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { int hebap = s->bap[ch][bin]; int bits = ff_eac3_bits_vs_hebap[hebap]; if (!hebap) { /* zero-mantissa dithering */ for (blk = 0; blk < 6; blk++) { s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; } } else if (hebap < 8) { /* Vector Quantization */ int v = get_bits(gbc, bits); for (blk = 0; blk < 6; blk++) { s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8; } } else { /* Gain Adaptive Quantization */ int gbits, log_gain; if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) { log_gain = gaq_gain[gs++]; } else { log_gain = 0; } gbits = bits - log_gain; for (blk = 0; blk < 6; blk++) { int mant = get_sbits(gbc, gbits); if (log_gain && mant == -(1 << (gbits-1))) { /* large mantissa */ int b; int mbits = bits - (2 - log_gain); mant = get_sbits(gbc, mbits); mant <<= (23 - (mbits - 1)); /* remap mantissa value to correct for asymmetric quantization */ if (mant >= 0) b = 1 << (23 - log_gain); else b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8; mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b; } else { /* small mantissa, no GAQ, or Gk=1 */ mant <<= 24 - bits; if (!log_gain) { /* remap mantissa value for no GAQ or Gk=1 */ mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15; } } s->pre_mantissa[ch][bin][blk] = mant; } } idct6(s->pre_mantissa[ch][bin]); } }


int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count) { Coroutine *co; DiscardCo rwco = { .bs = bs, .offset = offset, .count = count, .ret = NOT_DONE, }; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_pdiscard_co_entry(&rwco); } else { co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco); qemu_coroutine_enter(co); BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE); } return rwco.ret; }


static void alpha_cpu_initfn(Object *obj) { CPUState *cs = CPU(obj); AlphaCPU *cpu = ALPHA_CPU(obj); CPUAlphaState *env = &cpu->env; cs->env_ptr = env; cpu_exec_init(cs, &error_abort); tlb_flush(cs, 1); alpha_translate_init(); #if defined(CONFIG_USER_ONLY) env->ps = PS_USER_MODE; cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD | FPCR_UNFD | FPCR_INED | FPCR_DNOD | FPCR_DYN_NORMAL)); #endif env->lock_addr = -1; env->fen = 1; }


static void render_line(int x0, int y0, int x1, int y1, float *buf) { int dy = y1 - y0; int adx = x1 - x0; int ady = FFABS(dy); int sy = dy < 0 ? -1 : 1; buf[x0] = ff_vorbis_floor1_inverse_db_table[y0]; if (ady*2 <= adx) { // optimized common case render_line_unrolled(x0, y0, x1, sy, ady, adx, buf); } else { int base = dy / adx; int x = x0; int y = y0; int err = -adx; ady -= FFABS(base) * adx; while (++x < x1) { y += base; err += ady; if (err >= 0) { err -= adx; y += sy; } buf[x] = ff_vorbis_floor1_inverse_db_table[y]; } } }


void ram_control_after_iterate(QEMUFile *f, uint64_t flags) { int ret = 0; if (f->ops->after_ram_iterate) { ret = f->ops->after_ram_iterate(f, f->opaque, flags); if (ret < 0) { qemu_file_set_error(f, ret); } } }


void ff_rtsp_close_streams(AVFormatContext *s) { RTSPState *rt = s->priv_data; int i; RTSPStream *rtsp_st; ff_rtsp_undo_setup(s); for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; if (rtsp_st) { if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) rtsp_st->dynamic_handler->close( rtsp_st->dynamic_protocol_context); } } av_free(rt->rtsp_streams); if (rt->asf_ctx) { av_close_input_stream (rt->asf_ctx); rt->asf_ctx = NULL; } av_free(rt->p); av_free(rt->recvbuf); }


static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc = container_of(dcbase, DisasContext, base); dc->insn_start_idx = tcg_op_buf_count(); tcg_gen_insn_start(dc->pc, 0, 0); }


int ff_xvid_rate_control_init(MpegEncContext *s){ char *tmp_name; int fd, i; xvid_plg_create_t xvid_plg_create = { 0 }; xvid_plugin_2pass2_t xvid_2pass2 = { 0 }; fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx); if (fd == -1) { av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n"); return -1; } for(i=0; i<s->rc_context.num_entries; i++){ static const char frame_types[] = " ipbs"; char tmp[256]; RateControlEntry *rce; rce= &s->rc_context.entry[i]; snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n", frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8); if (write(fd, tmp, strlen(tmp)) < 0) { av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno)); return AVERROR(errno); } } xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0); xvid_2pass2.filename= tmp_name; xvid_2pass2.bitrate= s->avctx->bit_rate; xvid_2pass2.vbv_size= s->avctx->rc_buffer_size; xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate; xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy; xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0); xvid_plg_create.fbase= s->avctx->time_base.den; xvid_plg_create.fincr= s->avctx->time_base.num; xvid_plg_create.param= &xvid_2pass2; if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){ av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n"); return -1; } return 0; }


void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, size_t len) { int i, index; void *ptr = NULL; assert(s->files); index = be32_to_cpu(s->files->count); assert(index < fw_cfg_file_slots(s)); for (i = 0; i < index; i++) { if (strcmp(filename, s->files->f[i].name) == 0) { ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i, data, len); s->files->f[i].size = cpu_to_be32(len); return ptr; } } /* add new one */ fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true); return NULL; }


int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); BlockDriverState *bs; bs = bdrv_find(id); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, id); return -1; } if (bdrv_in_use(bs)) { qerror_report(QERR_DEVICE_IN_USE, id); return -1; } /* quiesce block driver; prevent further io */ qemu_aio_flush(); bdrv_flush(bs); bdrv_close(bs); /* if we have a device attached to this BlockDriverState * then we need to make the drive anonymous until the device * can be removed. If this is a drive with no device backing * then we can just get rid of the block driver state right here. */ if (bdrv_get_attached_dev(bs)) { bdrv_make_anon(bs); } else { drive_uninit(drive_get_by_blockdev(bs)); } return 0; }


static void init_proc_970FX (CPUPPCState *env) { gen_spr_ne_601(env); gen_spr_7xx(env); /* Time base */ gen_tbl(env); /* Hardware implementation registers */ /* XXX : not implemented */ spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_clear, 0x60000000); /* XXX : not implemented */ spr_register(env, SPR_HID1, "HID1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_970_HID5, "HID5", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, POWERPC970_HID5_INIT); /* Memory management */ /* XXX: not correct */ gen_low_BATs(env); spr_register(env, SPR_HIOR, "SPR_HIOR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_hior, &spr_write_hior, 0x00000000); spr_register(env, SPR_CTRL, "SPR_CTRL", SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, &spr_write_generic, 0x00000000); spr_register(env, SPR_UCTRL, "SPR_UCTRL", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, SPR_NOACCESS, 0x00000000); spr_register(env, SPR_VRSAVE, "SPR_VRSAVE", &spr_read_generic, &spr_write_generic, &spr_read_generic, &spr_write_generic, 0x00000000); #if !defined(CONFIG_USER_ONLY) env->slb_nr = 64; #endif init_excp_970(env); env->dcache_line_size = 128; env->icache_line_size = 128; /* Allocate hardware IRQ controller */ ppc970_irq_init(env); /* Can't find information on what this should be on reset. This * value is the one used by 74xx processors. */ vscr_init(env, 0x00010000); }


static QPCIBus *pci_test_start(int socket) { char *cmdline; cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device " "virtio-net-pci,netdev=hs0", socket); qtest_start(cmdline); g_free(cmdline); return qpci_init_pc(NULL); }


static void ppc_prep_init(QEMUMachineInitArgs *args) { ram_addr_t ram_size = args->ram_size; const char *cpu_model = args->cpu_model; const char *kernel_filename = args->kernel_filename; const char *kernel_cmdline = args->kernel_cmdline; const char *initrd_filename = args->initrd_filename; const char *boot_device = args->boot_device; MemoryRegion *sysmem = get_system_memory(); PowerPCCPU *cpu = NULL; CPUPPCState *env = NULL; char *filename; nvram_t nvram; M48t59State *m48t59; MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1); PortioList *port_list = g_new(PortioList, 1); #if 0 MemoryRegion *xcsr = g_new(MemoryRegion, 1); #endif int linux_boot, i, nb_nics1, bios_size; MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *bios = g_new(MemoryRegion, 1); uint32_t kernel_base, initrd_base; long kernel_size, initrd_size; DeviceState *dev; PCIHostState *pcihost; PCIBus *pci_bus; PCIDevice *pci; ISABus *isa_bus; ISADevice *isa; qemu_irq *cpu_exit_irq; int ppc_boot_device; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; sysctrl = g_malloc0(sizeof(sysctrl_t)); linux_boot = (kernel_filename != NULL); /* init CPUs */ if (cpu_model == NULL) cpu_model = "602"; for (i = 0; i < smp_cpus; i++) { cpu = cpu_ppc_init(cpu_model); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } env = &cpu->env; if (env->flags & POWERPC_FLAG_RTC_CLK) { /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */ cpu_ppc_tb_init(env, 7812500UL); } else { /* Set time-base frequency to 100 Mhz */ cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); } qemu_register_reset(ppc_prep_reset, cpu); } /* allocate RAM */ memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size); vmstate_register_ram_global(ram); memory_region_add_subregion(sysmem, 0, ram); /* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE); memory_region_set_readonly(bios, true); memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios); vmstate_register_ram_global(bios); if (bios_name == NULL) bios_name = BIOS_FILENAME; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); if (filename) { bios_size = load_elf(filename, NULL, NULL, NULL, NULL, NULL, 1, ELF_MACHINE, 0); if (bios_size < 0) { bios_size = get_image_size(filename); if (bios_size > 0 && bios_size <= BIOS_SIZE) { hwaddr bios_addr; bios_size = (bios_size + 0xfff) & ~0xfff; bios_addr = (uint32_t)(-bios_size); bios_size = load_image_targphys(filename, bios_addr, bios_size); } if (bios_size > BIOS_SIZE) { fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n", bios_name, bios_size); exit(1); } } } else { bios_size = -1; } if (bios_size < 0 && !qtest_enabled()) { fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n", bios_name); exit(1); } if (filename) { g_free(filename); } if (linux_boot) { kernel_base = KERNEL_LOAD_ADDR; /* now we can load the kernel */ kernel_size = load_image_targphys(kernel_filename, kernel_base, ram_size - kernel_base); if (kernel_size < 0) { hw_error("qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } /* load initrd */ if (initrd_filename) { initrd_base = INITRD_LOAD_ADDR; initrd_size = load_image_targphys(initrd_filename, initrd_base, ram_size - initrd_base); if (initrd_size < 0) { hw_error("qemu: could not load initial ram disk '%s'\n", initrd_filename); } } else { initrd_base = 0; initrd_size = 0; } ppc_boot_device = 'm'; } else { kernel_base = 0; kernel_size = 0; initrd_base = 0; initrd_size = 0; ppc_boot_device = '\0'; /* For now, OHW cannot boot from the network. */ for (i = 0; boot_device[i] != '\0'; i++) { if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { ppc_boot_device = boot_device[i]; break; } } if (ppc_boot_device == '\0') { fprintf(stderr, "No valid boot device for Mac99 machine\n"); exit(1); } } if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { hw_error("Only 6xx bus is supported on PREP machine\n"); } dev = qdev_create(NULL, "raven-pcihost"); pcihost = PCI_HOST_BRIDGE(dev); object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL); qdev_init_nofail(dev); pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0"); if (pci_bus == NULL) { fprintf(stderr, "Couldn't create PCI host controller.\n"); exit(1); } /* PCI -> ISA bridge */ pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378"); cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); cpu = POWERPC_CPU(first_cpu); qdev_connect_gpio_out(&pci->qdev, 0, cpu->env.irq_inputs[PPC6xx_INPUT_INT]); qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq); sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9)); sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11)); sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9)); sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11)); isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0")); /* Super I/O (parallel + serial ports) */ isa = isa_create(isa_bus, TYPE_PC87312); dev = DEVICE(isa); qdev_prop_set_uint8(dev, "config", 13); /* fdc, ser0, ser1, par0 */ qdev_init_nofail(dev); /* Register 8 MB of ISA IO space (needed for non-contiguous map) */ memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl, "ppc-io", 0x00800000); memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory); /* init basic PC hardware */ pci_vga_init(pci_bus); nb_nics1 = nb_nics; if (nb_nics1 > NE2000_NB_MAX) nb_nics1 = NE2000_NB_MAX; for(i = 0; i < nb_nics1; i++) { if (nd_table[i].model == NULL) { nd_table[i].model = g_strdup("ne2k_isa"); } if (strcmp(nd_table[i].model, "ne2k_isa") == 0) { isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i], &nd_table[i]); } else { pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); } } ide_drive_get(hd, MAX_IDE_BUS); for(i = 0; i < MAX_IDE_BUS; i++) { isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[2 * i], hd[2 * i + 1]); } isa_create_simple(isa_bus, "i8042"); cpu = POWERPC_CPU(first_cpu); sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET]; portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep"); portio_list_add(port_list, get_system_io(), 0x0); /* PowerPC control and status register group */ #if 0 memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000); memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr); #endif if (usb_enabled(false)) { pci_create_simple(pci_bus, -1, "pci-ohci"); } m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59); if (m48t59 == NULL) return; sysctrl->nvram = m48t59; /* Initialise NVRAM */ nvram.opaque = m48t59; nvram.read_fn = &m48t59_read; nvram.write_fn = &m48t59_write; PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device, kernel_base, kernel_size, kernel_cmdline, initrd_base, initrd_size, /* XXX: need an option to load a NVRAM image */ 0, graphic_width, graphic_height, graphic_depth); }


static void smc91c111_cleanup(NetClientState *nc) { smc91c111_state *s = qemu_get_nic_opaque(nc); s->nic = NULL; }


e1000e_setup_tx_offloads(E1000ECore *core, struct e1000e_tx *tx) { if (tx->props.tse && tx->props.cptse) { net_tx_pkt_build_vheader(tx->tx_pkt, true, true, tx->props.mss); net_tx_pkt_update_ip_checksums(tx->tx_pkt); e1000x_inc_reg_if_not_full(core->mac, TSCTC); return; } if (tx->props.sum_needed & E1000_TXD_POPTS_TXSM) { net_tx_pkt_build_vheader(tx->tx_pkt, false, true, 0); } if (tx->props.sum_needed & E1000_TXD_POPTS_IXSM) { net_tx_pkt_update_ip_hdr_checksum(tx->tx_pkt); } }


static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs, const struct iovec *iov, int iovcnt, off_t offset) { ssize_t ret; #ifdef CONFIG_PREADV ret = pwritev(fs->fd, iov, iovcnt, offset); #else ret = lseek(fs->fd, offset, SEEK_SET); if (ret >= 0) { ret = writev(fs->fd, iov, iovcnt); } #endif #ifdef CONFIG_SYNC_FILE_RANGE if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { /* * Initiate a writeback. This is not a data integrity sync. * We want to ensure that we don't leave dirty pages in the cache * after write when writeout=immediate is sepcified. */ sync_file_range(fs->fd, offset, ret, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); } #endif return ret; }


static int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr, int rw, int access_type) { ppc6xx_tlb_t *tlb; int nr, best, way; int ret; best = -1; ret = -1; /* No TLB found */ for (way = 0; way < env->nb_ways; way++) { nr = ppc6xx_tlb_getnum(env, eaddr, way, access_type == ACCESS_CODE ? 1 : 0); tlb = &env->tlb[nr].tlb6; /* This test "emulates" the PTE index match for hardware TLBs */ if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) { #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "TLB %d/%d %s [" ADDRX " " ADDRX "] <> " ADDRX "\n", nr, env->nb_tlb, pte_is_valid(tlb->pte0) ? "valid" : "inval", tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr); } #endif continue; } #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "TLB %d/%d %s " ADDRX " <> " ADDRX " " ADDRX " %c %c\n", nr, env->nb_tlb, pte_is_valid(tlb->pte0) ? "valid" : "inval", tlb->EPN, eaddr, tlb->pte1, rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D'); } #endif switch (pte32_check(ctx, tlb->pte0, tlb->pte1, 0, rw)) { case -3: /* TLB inconsistency */ return -1; case -2: /* Access violation */ ret = -2; best = nr; break; case -1: default: /* No match */ break; case 0: /* access granted */ /* XXX: we should go on looping to check all TLBs consistency * but we can speed-up the whole thing as the * result would be undefined if TLBs are not consistent. */ ret = 0; best = nr; goto done; } } if (best != -1) { done: #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n", ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret); } #endif /* Update page flags */ pte_update_flags(ctx, &env->tlb[best].tlb6.pte1, ret, rw); } return ret; }


static inline bool media_is_dvd(SCSIDiskState *s) { uint64_t nb_sectors; if (s->qdev.type != TYPE_ROM) { return false; } if (!bdrv_is_inserted(s->qdev.conf.bs)) { return false; } bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); return nb_sectors > CD_MAX_SECTORS; }


int avpriv_exif_decode_ifd(AVCodecContext *avctx, GetByteContext *gbytes, int le, int depth, AVDictionary **metadata) { int i, ret; int entries; entries = ff_tget_short(gbytes, le); if (bytestream2_get_bytes_left(gbytes) < entries * 12) { return AVERROR_INVALIDDATA; } for (i = 0; i < entries; i++) { if ((ret = exif_decode_tag(avctx, gbytes, le, depth, metadata)) < 0) { return ret; } } // return next IDF offset or 0x000000000 or a value < 0 for failure return ff_tget_long(gbytes, le); }


DeviceState *qdev_create(BusState *bus, const char *name) { DeviceType *t; DeviceState *dev; for (t = device_type_list; t; t = t->next) { if (strcmp(t->info->name, name) == 0) { break; } } if (!t) { hw_error("Unknown device '%s'\n", name); } dev = qemu_mallocz(t->info->size); dev->type = t; if (!bus) { /* ???: This assumes system busses have no additional state. */ if (!main_system_bus) { main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState), NULL, "main-system-bus"); } bus = main_system_bus; } if (t->info->bus_type != bus->type) { /* TODO: Print bus type names. */ hw_error("Device '%s' on wrong bus type (%d/%d)", name, t->info->bus_type, bus->type); } dev->parent_bus = bus; LIST_INSERT_HEAD(&bus->children, dev, sibling); return dev; }


static CPAccessResult ats_access(CPUARMState *env, const ARMCPRegInfo *ri) { if (ri->opc2 & 4) { /* Other states are only available with TrustZone; in * a non-TZ implementation these registers don't exist * at all, which is an Uncategorized trap. This underdecoding * is safe because the reginfo is NO_MIGRATE. */ return CP_ACCESS_TRAP_UNCATEGORIZED; } return CP_ACCESS_OK; }


on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming) { uint32_t *capabilities = (incoming->capabilities); int num_capabilities = 1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t)); int i; QemuThread thread_id; incoming->version = ntohl(incoming->version); if (incoming->version != VSCARD_VERSION) { if (verbose > 0) { printf("warning: host has version %d, we have %d\n", verbose, VSCARD_VERSION); } } if (incoming->magic != VSCARD_MAGIC) { printf("unexpected magic: got %d, expected %d\n", incoming->magic, VSCARD_MAGIC); return -1; } for (i = 0 ; i < num_capabilities; ++i) { capabilities[i] = ntohl(capabilities[i]); } /* Future: check capabilities */ /* remove whatever reader might be left in qemu, * in case of an unclean previous exit. */ send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0); /* launch the event_thread. This will trigger reader adds for all the * existing readers */ qemu_thread_create(&thread_id, "vsc/event", event_thread, NULL, 0); return 0; }


static GenericList *qmp_input_next_list(Visitor *v, GenericList *tail, size_t size) { QmpInputVisitor *qiv = to_qiv(v); StackObject *so = &qiv->stack[qiv->nb_stack - 1]; if (!so->entry) { return NULL; } tail->next = g_malloc0(size); return tail->next; }


static size_t handle_aiocb_ioctl(struct qemu_paiocb *aiocb) { int ret; ret = ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioctl_buf); if (ret == -1) return -errno; /* * This looks weird, but the aio code only consideres a request * successfull if it has written the number full number of bytes. * * Now we overload aio_nbytes as aio_ioctl_cmd for the ioctl command, * so in fact we return the ioctl command here to make posix_aio_read() * happy.. */ return aiocb->aio_nbytes; }


static always_inline void gen_load_mem (DisasContext *ctx, void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1, int flags), int ra, int rb, int32_t disp16, int fp, int clear) { TCGv addr; if (unlikely(ra == 31)) return; addr = tcg_temp_new(TCG_TYPE_I64); if (rb != 31) { tcg_gen_addi_i64(addr, cpu_ir[rb], disp16); if (clear) tcg_gen_andi_i64(addr, addr, ~0x7); } else { if (clear) disp16 &= ~0x7; tcg_gen_movi_i64(addr, disp16); } if (fp) tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx); else tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx); tcg_temp_free(addr); }


int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len, int flags) { target_ulong len_mask = ~(len - 1); CPUWatchpoint *wp; TAILQ_FOREACH(wp, &env->watchpoints, entry) { if (addr == wp->vaddr && len_mask == wp->len_mask && flags == (wp->flags & ~BP_WATCHPOINT_HIT)) { cpu_watchpoint_remove_by_ref(env, wp); return 0; } } return -ENOENT; }


static int segment_start(AVFormatContext *s, int write_header) { SegmentContext *c = s->priv_data; AVFormatContext *oc = c->avf; int err = 0; if (write_header) { avformat_free_context(oc); c->avf = NULL; if ((err = segment_mux_init(s)) < 0) return err; oc = c->avf; } if (c->wrap) c->number %= c->wrap; if (av_get_frame_filename(oc->filename, sizeof(oc->filename), s->filename, c->number++) < 0) return AVERROR(EINVAL); if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL)) < 0) return err; if (oc->oformat->priv_class && oc->priv_data) av_opt_set(oc->priv_data, "resend_headers", "1", 0); /* mpegts specific */ if (write_header) { if ((err = avformat_write_header(oc, NULL)) < 0) return err; } return 0; }


static void s390x_cpu_set_id(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { S390CPU *cpu = S390_CPU(obj); DeviceState *dev = DEVICE(obj); const int64_t min = 0; const int64_t max = UINT32_MAX; Error *err = NULL; int64_t value; if (dev->realized) { error_setg(errp, "Attempt to set property '%s' on '%s' after " "it was realized", name, object_get_typename(obj)); return; } visit_type_int(v, name, &value, &err); if (err) { error_propagate(errp, err); return; } if (value < min || value > max) { error_setg(errp, "Property %s.%s doesn't take value %" PRId64 " (minimum: %" PRId64 ", maximum: %" PRId64 ")" , object_get_typename(obj), name, value, min, max); return; } cpu->id = value; }


static void sunmouse_event(void *opaque, int dx, int dy, int dz, int buttons_state) { ChannelState *s = opaque; int ch; MS_DPRINTF("dx=%d dy=%d buttons=%01x\n", dx, dy, buttons_state); ch = 0x80 | 0x7; /* protocol start byte, no buttons pressed */ if (buttons_state & MOUSE_EVENT_LBUTTON) ch ^= 0x4; if (buttons_state & MOUSE_EVENT_MBUTTON) ch ^= 0x2; if (buttons_state & MOUSE_EVENT_RBUTTON) ch ^= 0x1; put_queue(s, ch); ch = dx; if (ch > 127) ch=127; else if (ch < -127) ch=-127; put_queue(s, ch & 0xff); ch = -dy; if (ch > 127) ch=127; else if (ch < -127) ch=-127; put_queue(s, ch & 0xff); // MSC protocol specify two extra motion bytes put_queue(s, 0); put_queue(s, 0); }


void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, uint8_t *buf, uint64_t start, uint64_t count) { hbitmap_serialize_part(bitmap->bitmap, buf, start, count); }


int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp) { unsigned long sectors = info->size / BDRV_SECTOR_SIZE; if (info->size / BDRV_SECTOR_SIZE != sectors) { error_setg(errp, "Export size %" PRIu64 " too large for 32-bit kernel", info->size); return -E2BIG; } trace_nbd_init_set_socket(); if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) { int serrno = errno; error_setg(errp, "Failed to set NBD socket"); return -serrno; } trace_nbd_init_set_block_size(BDRV_SECTOR_SIZE); if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) { int serrno = errno; error_setg(errp, "Failed setting NBD block size"); return -serrno; } trace_nbd_init_set_size(sectors); if (info->size % BDRV_SECTOR_SIZE) { trace_nbd_init_trailing_bytes(info->size % BDRV_SECTOR_SIZE); } if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) { int serrno = errno; error_setg(errp, "Failed setting size (in blocks)"); return -serrno; } if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) info->flags) < 0) { if (errno == ENOTTY) { int read_only = (info->flags & NBD_FLAG_READ_ONLY) != 0; trace_nbd_init_set_readonly(); if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { int serrno = errno; error_setg(errp, "Failed setting read-only attribute"); return -serrno; } } else { int serrno = errno; error_setg(errp, "Failed setting flags"); return -serrno; } } trace_nbd_init_finish(); return 0; }


void helper_dcbz(CPUPPCState *env, target_ulong addr, uint32_t is_dcbzl) { int dcbz_size = env->dcache_line_size; #if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64) if (!is_dcbzl && (env->excp_model == POWERPC_EXCP_970) && ((env->spr[SPR_970_HID5] >> 7) & 0x3) == 1) { dcbz_size = 32; } #endif /* XXX add e500mc support */ do_dcbz(env, addr, dcbz_size); }


static void nvme_rw_cb(void *opaque, int ret) { NvmeRequest *req = opaque; NvmeSQueue *sq = req->sq; NvmeCtrl *n = sq->ctrl; NvmeCQueue *cq = n->cq[sq->cqid]; block_acct_done(bdrv_get_stats(n->conf.bs), &req->acct); if (!ret) { req->status = NVME_SUCCESS; } else { req->status = NVME_INTERNAL_DEV_ERROR; } qemu_sglist_destroy(&req->qsg); nvme_enqueue_req_completion(cq, req); }


static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) { PowerPCCPU *cpu = POWERPC_CPU(dev); CPUPPCState *env = &cpu->env; int i; for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) { if (env->opcodes[i] != &invalid_handler) { g_free(env->opcodes[i]); } } }


static void xen_exit_notifier(Notifier *n, void *data) { XenIOState *state = container_of(n, XenIOState, exit); xc_evtchn_close(state->xce_handle); xs_daemon_close(state->xenstore); }


static void avc_loopfilter_cb_or_cr_inter_edge_ver_msa(uint8_t *data, uint8_t bs0, uint8_t bs1, uint8_t bs2, uint8_t bs3, uint8_t tc0, uint8_t tc1, uint8_t tc2, uint8_t tc3, uint8_t alpha_in, uint8_t beta_in, uint32_t img_width) { uint8_t *src; uint16_t out0, out1, out2, out3; v16u8 alpha, beta; v16u8 p0_asub_q0, p1_asub_p0, q1_asub_q0; v16u8 is_less_than, is_less_than_beta, is_less_than_alpha; v16u8 p0, q0; v8i16 p0_r = { 0 }; v8i16 q0_r = { 0 }; v16u8 p1_org, p0_org, q0_org, q1_org; v8i16 p1_org_r, p0_org_r, q0_org_r, q1_org_r; v16u8 is_bs_greater_than0; v8i16 tc_r, negate_tc_r; v16i8 negate_tc, sign_negate_tc; v16i8 zero = { 0 }; v16u8 row0, row1, row2, row3, row4, row5, row6, row7; v8i16 tmp1, tmp_vec, bs = { 0 }; v8i16 tc = { 0 }; tmp_vec = (v8i16) __msa_fill_b(bs0); bs = __msa_insve_h(bs, 0, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(bs1); bs = __msa_insve_h(bs, 1, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(bs2); bs = __msa_insve_h(bs, 2, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(bs3); bs = __msa_insve_h(bs, 3, tmp_vec); if (!__msa_test_bz_v((v16u8) bs)) { tmp_vec = (v8i16) __msa_fill_b(tc0); tc = __msa_insve_h(tc, 0, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(tc1); tc = __msa_insve_h(tc, 1, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(tc2); tc = __msa_insve_h(tc, 2, tmp_vec); tmp_vec = (v8i16) __msa_fill_b(tc3); tc = __msa_insve_h(tc, 3, tmp_vec); is_bs_greater_than0 = (v16u8) (zero < (v16i8) bs); LOAD_8VECS_UB((data - 2), img_width, row0, row1, row2, row3, row4, row5, row6, row7); TRANSPOSE8x4_B_UB(row0, row1, row2, row3, row4, row5, row6, row7, p1_org, p0_org, q0_org, q1_org); p0_asub_q0 = __msa_asub_u_b(p0_org, q0_org); p1_asub_p0 = __msa_asub_u_b(p1_org, p0_org); q1_asub_q0 = __msa_asub_u_b(q1_org, q0_org); alpha = (v16u8) __msa_fill_b(alpha_in); beta = (v16u8) __msa_fill_b(beta_in); is_less_than_alpha = (p0_asub_q0 < alpha); is_less_than_beta = (p1_asub_p0 < beta); is_less_than = is_less_than_beta & is_less_than_alpha; is_less_than_beta = (q1_asub_q0 < beta); is_less_than = is_less_than_beta & is_less_than; is_less_than = is_bs_greater_than0 & is_less_than; is_less_than = (v16u8) __msa_ilvr_d((v2i64) zero, (v2i64) is_less_than); if (!__msa_test_bz_v(is_less_than)) { p1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p1_org); p0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p0_org); q0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q0_org); q1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q1_org); negate_tc = zero - (v16i8) tc; sign_negate_tc = __msa_clti_s_b(negate_tc, 0); negate_tc_r = (v8i16) __msa_ilvr_b(sign_negate_tc, negate_tc); tc_r = (v8i16) __msa_ilvr_b(zero, (v16i8) tc); AVC_LOOP_FILTER_P0Q0(q0_org_r, p0_org_r, p1_org_r, q1_org_r, negate_tc_r, tc_r, p0_r, q0_r); p0 = (v16u8) __msa_pckev_b(zero, (v16i8) p0_r); q0 = (v16u8) __msa_pckev_b(zero, (v16i8) q0_r); p0_org = __msa_bmnz_v(p0_org, p0, is_less_than); q0_org = __msa_bmnz_v(q0_org, q0, is_less_than); tmp1 = (v8i16) __msa_ilvr_b((v16i8) q0_org, (v16i8) p0_org); src = data - 1; out0 = __msa_copy_u_h(tmp1, 0); out1 = __msa_copy_u_h(tmp1, 1); out2 = __msa_copy_u_h(tmp1, 2); out3 = __msa_copy_u_h(tmp1, 3); STORE_HWORD(src, out0); src += img_width; STORE_HWORD(src, out1); src += img_width; STORE_HWORD(src, out2); src += img_width; STORE_HWORD(src, out3); out0 = __msa_copy_u_h(tmp1, 4); out1 = __msa_copy_u_h(tmp1, 5); out2 = __msa_copy_u_h(tmp1, 6); out3 = __msa_copy_u_h(tmp1, 7); src += img_width; STORE_HWORD(src, out0); src += img_width; STORE_HWORD(src, out1); src += img_width; STORE_HWORD(src, out2); src += img_width; STORE_HWORD(src, out3); } } }


static int mov_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; MOVMuxContext *mov = s->priv_data; AVDictionaryEntry *t, *global_tcr = av_dict_get(s->metadata, "timecode", NULL, 0); int i, ret, hint_track = 0, tmcd_track = 0; mov->fc = s; /* Default mode == MP4 */ mov->mode = MODE_MP4; if (s->oformat) { if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP; else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3GP|MODE_3G2; else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; else if (!strcmp("ismv",s->oformat->name)) mov->mode = MODE_ISM; else if (!strcmp("f4v", s->oformat->name)) mov->mode = MODE_F4V; } if (s->flags & AVFMT_FLAG_BITEXACT) mov->exact = 1; if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) mov->flags |= FF_MOV_FLAG_EMPTY_MOOV; /* Set the FRAGMENT flag if any of the fragmentation methods are * enabled. */ if (mov->max_fragment_duration || mov->max_fragment_size || mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_FRAG_KEYFRAME | FF_MOV_FLAG_FRAG_CUSTOM)) mov->flags |= FF_MOV_FLAG_FRAGMENT; /* Set other implicit flags immediately */ if (mov->mode == MODE_ISM) mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF | FF_MOV_FLAG_FRAGMENT; if (mov->flags & FF_MOV_FLAG_DASH) mov->flags |= FF_MOV_FLAG_FRAGMENT | FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_DEFAULT_BASE_MOOF; if (mov->flags & FF_MOV_FLAG_FASTSTART) { mov->reserved_moov_size = -1; } if (mov->use_editlist < 0) { mov->use_editlist = 1; if (mov->flags & FF_MOV_FLAG_FRAGMENT && !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) { // If we can avoid needing an edit list by shifting the // tracks, prefer that over (trying to) write edit lists // in fragmented output. if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) mov->use_editlist = 0; } } if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV && !(mov->flags & FF_MOV_FLAG_DELAY_MOOV) && mov->use_editlist) av_log(s, AV_LOG_WARNING, "No meaningful edit list will be written when using empty_moov without delay_moov\n"); if (!mov->use_editlist && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO) s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_ZERO; /* Clear the omit_tfhd_offset flag if default_base_moof is set; * if the latter is set that's enough and omit_tfhd_offset doesn't * add anything extra on top of that. */ if (mov->flags & FF_MOV_FLAG_OMIT_TFHD_OFFSET && mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF) mov->flags &= ~FF_MOV_FLAG_OMIT_TFHD_OFFSET; if (mov->frag_interleave && mov->flags & (FF_MOV_FLAG_OMIT_TFHD_OFFSET | FF_MOV_FLAG_SEPARATE_MOOF)) { av_log(s, AV_LOG_ERROR, "Sample interleaving in fragments is mutually exclusive with " "omit_tfhd_offset and separate_moof\n"); return AVERROR(EINVAL); } /* Non-seekable output is ok if using fragmentation. If ism_lookahead * is enabled, we don't support non-seekable output at all. */ if (!s->pb->seekable && (!(mov->flags & FF_MOV_FLAG_FRAGMENT) || mov->ism_lookahead)) { av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); return AVERROR(EINVAL); } if (!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) { if ((ret = mov_write_identification(pb, s)) < 0) return ret; } mov->nb_streams = s->nb_streams; if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters) mov->chapter_track = mov->nb_streams++; if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Add hint tracks for each audio and video stream */ hint_track = mov->nb_streams; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { mov->nb_streams++; } } } if (mov->mode == MODE_MOV) { tmcd_track = mov->nb_streams; /* +1 tmcd track for each video stream with a timecode */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (global_tcr || av_dict_get(st->metadata, "timecode", NULL, 0))) mov->nb_meta_tmcd++; } /* check if there is already a tmcd track to remux */ if (mov->nb_meta_tmcd) { for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codec->codec_tag == MKTAG('t','m','c','d')) { av_log(s, AV_LOG_WARNING, "You requested a copy of the original timecode track " "so timecode metadata are now ignored\n"); mov->nb_meta_tmcd = 0; } } } mov->nb_streams += mov->nb_meta_tmcd; } // Reserve an extra stream for chapters for the case where chapters // are written in the trailer mov->tracks = av_mallocz_array((mov->nb_streams + 1), sizeof(*mov->tracks)); if (!mov->tracks) return AVERROR(ENOMEM); for (i = 0; i < s->nb_streams; i++) { AVStream *st= s->streams[i]; MOVTrack *track= &mov->tracks[i]; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); track->st = st; track->enc = st->codec; track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); if (track->language < 0) track->language = 0; track->mode = mov->mode; track->tag = mov_find_codec_tag(s, track); if (!track->tag) { av_log(s, AV_LOG_ERROR, "Could not find tag for codec %s in stream #%d, " "codec not currently supported in container\n", avcodec_get_name(st->codec->codec_id), i); ret = AVERROR(EINVAL); goto error; } /* If hinting of this track is enabled by a later hint track, * this is updated. */ track->hint_track = -1; track->start_dts = AV_NOPTS_VALUE; track->start_cts = AV_NOPTS_VALUE; track->end_pts = AV_NOPTS_VALUE; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) { if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) { av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n"); ret = AVERROR(EINVAL); goto error; } track->height = track->tag >> 24 == 'n' ? 486 : 576; } if (mov->video_track_timescale) { track->timescale = mov->video_track_timescale; } else { track->timescale = st->time_base.den; while(track->timescale < 10000) track->timescale *= 2; } if (st->codec->width > 65535 || st->codec->height > 65535) { av_log(s, AV_LOG_ERROR, "Resolution %dx%d too large for mov/mp4\n", st->codec->width, st->codec->height); ret = AVERROR(EINVAL); goto error; } if (track->mode == MODE_MOV && track->timescale > 100000) av_log(s, AV_LOG_WARNING, "WARNING codec timebase is very high. If duration is too long,\n" "file may not be playable by quicktime. Specify a shorter timebase\n" "or choose different container.\n"); } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { track->timescale = st->codec->sample_rate; if (!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { av_log(s, AV_LOG_WARNING, "track %d: codec frame size is not set\n", i); track->audio_vbr = 1; }else if (st->codec->codec_id == AV_CODEC_ID_ADPCM_MS || st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || st->codec->codec_id == AV_CODEC_ID_ILBC){ if (!st->codec->block_align) { av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i); ret = AVERROR(EINVAL); goto error; } track->sample_size = st->codec->block_align; }else if (st->codec->frame_size > 1){ /* assume compressed audio */ track->audio_vbr = 1; }else{ track->sample_size = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; } if (st->codec->codec_id == AV_CODEC_ID_ILBC || st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_QT) { track->audio_vbr = 1; } if (track->mode != MODE_MOV && track->enc->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) { if (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not standard, to mux anyway set strict to -1\n", i, track->enc->sample_rate); ret = AVERROR(EINVAL); goto error; } else { av_log(s, AV_LOG_WARNING, "track %d: muxing mp3 at %dhz is not standard in MP4\n", i, track->enc->sample_rate); } } } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { track->timescale = st->time_base.den; } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { track->timescale = st->time_base.den; } else { track->timescale = MOV_TIMESCALE; } if (!track->height) track->height = st->codec->height; /* The ism specific timescale isn't mandatory, but is assumed by * some tools, such as mp4split. */ if (mov->mode == MODE_ISM) track->timescale = 10000000; avpriv_set_pts_info(st, 64, 1, track->timescale); /* copy extradata if it exists */ if (st->codec->extradata_size) { if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) mov_create_dvd_sub_decoder_specific_info(track, st); else if (!TAG_IS_AVCI(track->tag) && st->codec->codec_id != AV_CODEC_ID_DNXHD) { track->vos_len = st->codec->extradata_size; track->vos_data = av_malloc(track->vos_len); if (!track->vos_data) { ret = AVERROR(ENOMEM); goto error; } memcpy(track->vos_data, st->codec->extradata, track->vos_len); } } } for (i = 0; i < s->nb_streams; i++) { int j; AVStream *st= s->streams[i]; MOVTrack *track= &mov->tracks[i]; if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || track->enc->channel_layout != AV_CH_LAYOUT_MONO) continue; for (j = 0; j < s->nb_streams; j++) { AVStream *stj= s->streams[j]; MOVTrack *trackj= &mov->tracks[j]; if (j == i) continue; if (stj->codec->codec_type != AVMEDIA_TYPE_AUDIO || trackj->enc->channel_layout != AV_CH_LAYOUT_MONO || trackj->language != track->language || trackj->tag != track->tag ) continue; track->multichannel_as_mono++; } } enable_tracks(s); if (mov->reserved_moov_size){ mov->reserved_moov_pos= avio_tell(pb); if (mov->reserved_moov_size > 0) avio_skip(pb, mov->reserved_moov_size); } if (mov->flags & FF_MOV_FLAG_FRAGMENT) { /* If no fragmentation options have been set, set a default. */ if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME | FF_MOV_FLAG_FRAG_CUSTOM)) && !mov->max_fragment_duration && !mov->max_fragment_size) mov->flags |= FF_MOV_FLAG_FRAG_KEYFRAME; } else { if (mov->flags & FF_MOV_FLAG_FASTSTART) mov->reserved_moov_pos = avio_tell(pb); mov_write_mdat_tag(pb, mov); } if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) mov->time = ff_iso8601_to_unix_time(t->value); if (mov->time) mov->time += 0x7C25B080; // 1970 based -> 1904 based if (mov->chapter_track) if ((ret = mov_create_chapter_track(s, mov->chapter_track)) < 0) goto error; if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Initialize the hint tracks for each audio and video stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if ((ret = ff_mov_init_hinting(s, hint_track, i)) < 0) goto error; hint_track++; } } } if (mov->nb_meta_tmcd) { /* Initialize the tmcd tracks */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; t = global_tcr; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (!t) t = av_dict_get(st->metadata, "timecode", NULL, 0); if (!t) continue; if ((ret = mov_create_timecode_track(s, tmcd_track, i, t->value)) < 0) goto error; tmcd_track++; } } } avio_flush(pb); if (mov->flags & FF_MOV_FLAG_ISML) mov_write_isml_manifest(pb, mov); if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV && !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) { if ((ret = mov_write_moov_tag(pb, mov, s)) < 0) return ret; mov->moov_written = 1; if (mov->flags & FF_MOV_FLAG_FASTSTART) mov->reserved_moov_pos = avio_tell(pb); } return 0; error: mov_free(s); return ret; }


static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) { ALSSpecificConfig *sconf = &ctx->sconf; AVCodecContext *avctx = ctx->avctx; GetBitContext *gb = &ctx->gb; unsigned int div_blocks[32]; ///< block sizes. unsigned int c; unsigned int js_blocks[2]; uint32_t bs_info = 0; int ret; // skip the size of the ra unit if present in the frame if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame) skip_bits_long(gb, 32); if (sconf->mc_coding && sconf->joint_stereo) { ctx->js_switch = get_bits1(gb); align_get_bits(gb); if (!sconf->mc_coding || ctx->js_switch) { int independent_bs = !sconf->joint_stereo; for (c = 0; c < avctx->channels; c++) { js_blocks[0] = 0; js_blocks[1] = 0; get_block_sizes(ctx, div_blocks, &bs_info); // if joint_stereo and block_switching is set, independent decoding // is signaled via the first bit of bs_info if (sconf->joint_stereo && sconf->block_switching) if (bs_info >> 31) independent_bs = 2; // if this is the last channel, it has to be decoded independently if (c == avctx->channels - 1) independent_bs = 1; if (independent_bs) { ret = decode_blocks_ind(ctx, ra_frame, c, div_blocks, js_blocks); if (ret < 0) return ret; independent_bs--; } else { ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks); if (ret < 0) return ret; c++; // store carryover raw samples memmove(ctx->raw_samples[c] - sconf->max_order, ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, sizeof(*ctx->raw_samples[c]) * sconf->max_order); } else { // multi-channel coding ALSBlockData bd = { 0 }; int b, ret; int *reverted_channels = ctx->reverted_channels; unsigned int offset = 0; for (c = 0; c < avctx->channels; c++) if (ctx->chan_data[c] < ctx->chan_data_buffer) { av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n"); memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels); bd.ra_block = ra_frame; bd.prev_raw_samples = ctx->prev_raw_samples; get_block_sizes(ctx, div_blocks, &bs_info); for (b = 0; b < ctx->num_blocks; b++) { bd.block_length = div_blocks[b]; if (bd.block_length <= 0) { av_log(ctx->avctx, AV_LOG_WARNING, "Invalid block length %u in channel data!\n", bd.block_length); continue; for (c = 0; c < avctx->channels; c++) { bd.const_block = ctx->const_block + c; bd.shift_lsbs = ctx->shift_lsbs + c; bd.opt_order = ctx->opt_order + c; bd.store_prev_samples = ctx->store_prev_samples + c; bd.use_ltp = ctx->use_ltp + c; bd.ltp_lag = ctx->ltp_lag + c; bd.ltp_gain = ctx->ltp_gain[c]; bd.lpc_cof = ctx->lpc_cof[c]; bd.quant_cof = ctx->quant_cof[c]; bd.raw_samples = ctx->raw_samples[c] + offset; bd.raw_other = NULL; if ((ret = read_block(ctx, &bd)) < 0) return ret; if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0) return ret; for (c = 0; c < avctx->channels; c++) { ret = revert_channel_correlation(ctx, &bd, ctx->chan_data, reverted_channels, offset, c); if (ret < 0) return ret; for (c = 0; c < avctx->channels; c++) { bd.const_block = ctx->const_block + c; bd.shift_lsbs = ctx->shift_lsbs + c; bd.opt_order = ctx->opt_order + c; bd.store_prev_samples = ctx->store_prev_samples + c; bd.use_ltp = ctx->use_ltp + c; bd.ltp_lag = ctx->ltp_lag + c; bd.ltp_gain = ctx->ltp_gain[c]; bd.lpc_cof = ctx->lpc_cof[c]; bd.quant_cof = ctx->quant_cof[c]; bd.raw_samples = ctx->raw_samples[c] + offset; if ((ret = decode_block(ctx, &bd)) < 0) return ret; memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); offset += div_blocks[b]; bd.ra_block = 0; // store carryover raw samples for (c = 0; c < avctx->channels; c++) memmove(ctx->raw_samples[c] - sconf->max_order, ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, sizeof(*ctx->raw_samples[c]) * sconf->max_order); // TODO: read_diff_float_data return 0;


int swr_resample(AVResampleContext *c, short *dst, const short *src, int *consumed, int src_size, int dst_size, int update_ctx){ int dst_index, i; int index= c->index; int frac= c->frac; int dst_incr_frac= c->dst_incr % c->src_incr; int dst_incr= c->dst_incr / c->src_incr; int compensation_distance= c->compensation_distance; if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){ int64_t index2= ((int64_t)index)<<32; int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr); for(dst_index=0; dst_index < dst_size; dst_index++){ dst[dst_index] = src[index2>>32]; index2 += incr; } frac += dst_index * dst_incr_frac; index += dst_index * dst_incr; index += frac / c->src_incr; frac %= c->src_incr; }else{ for(dst_index=0; dst_index < dst_size; dst_index++){ FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); int sample_index= index >> c->phase_shift; FELEM2 val=0; if(sample_index < 0){ for(i=0; i<c->filter_length; i++) val += src[FFABS(sample_index + i) % src_size] * filter[i]; }else if(sample_index + c->filter_length > src_size){ break; }else if(c->linear){ FELEM2 v2=0; for(i=0; i<c->filter_length; i++){ val += src[sample_index + i] * (FELEM2)filter[i]; v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length]; } val+=(v2-val)*(FELEML)frac / c->src_incr; }else{ for(i=0; i<c->filter_length; i++){ val += src[sample_index + i] * (FELEM2)filter[i]; } } #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE dst[dst_index] = av_clip_int16(lrintf(val)); #else val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val; #endif frac += dst_incr_frac; index += dst_incr; if(frac >= c->src_incr){ frac -= c->src_incr; index++; } if(dst_index + 1 == compensation_distance){ compensation_distance= 0; dst_incr_frac= c->ideal_dst_incr % c->src_incr; dst_incr= c->ideal_dst_incr / c->src_incr; } } } *consumed= FFMAX(index, 0) >> c->phase_shift; if(index>=0) index &= c->phase_mask; if(compensation_distance){ compensation_distance -= dst_index; assert(compensation_distance > 0); } if(update_ctx){ c->frac= frac; c->index= index; c->dst_incr= dst_incr_frac + c->src_incr*dst_incr; c->compensation_distance= compensation_distance; } #if 0 if(update_ctx && !c->compensation_distance){ #undef rand av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2); av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance); } #endif return dst_index; }


static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) { STM32F205State *s = STM32F205_SOC(dev_soc); DeviceState *syscfgdev, *usartdev, *timerdev; SysBusDevice *syscfgbusdev, *usartbusdev, *timerbusdev; qemu_irq *pic; Error *err = NULL; int i; MemoryRegion *system_memory = get_system_memory(); MemoryRegion *sram = g_new(MemoryRegion, 1); MemoryRegion *flash = g_new(MemoryRegion, 1); MemoryRegion *flash_alias = g_new(MemoryRegion, 1); memory_region_init_ram(flash, NULL, "STM32F205.flash", FLASH_SIZE, &error_abort); memory_region_init_alias(flash_alias, NULL, "STM32F205.flash.alias", flash, 0, FLASH_SIZE); vmstate_register_ram_global(flash); memory_region_set_readonly(flash, true); memory_region_set_readonly(flash_alias, true); memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash); memory_region_add_subregion(system_memory, 0, flash_alias); memory_region_init_ram(sram, NULL, "STM32F205.sram", SRAM_SIZE, &error_abort); vmstate_register_ram_global(sram); memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram); pic = armv7m_init(get_system_memory(), FLASH_SIZE, 96, s->kernel_filename, s->cpu_model); /* System configuration controller */ syscfgdev = DEVICE(&s->syscfg); object_property_set_bool(OBJECT(&s->syscfg), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } syscfgbusdev = SYS_BUS_DEVICE(syscfgdev); sysbus_mmio_map(syscfgbusdev, 0, 0x40013800); sysbus_connect_irq(syscfgbusdev, 0, pic[71]); /* Attach UART (uses USART registers) and USART controllers */ for (i = 0; i < STM_NUM_USARTS; i++) { usartdev = DEVICE(&(s->usart[i])); object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } usartbusdev = SYS_BUS_DEVICE(usartdev); sysbus_mmio_map(usartbusdev, 0, usart_addr[i]); sysbus_connect_irq(usartbusdev, 0, pic[usart_irq[i]]); } /* Timer 2 to 5 */ for (i = 0; i < STM_NUM_TIMERS; i++) { timerdev = DEVICE(&(s->timer[i])); qdev_prop_set_uint64(timerdev, "clock-frequency", 1000000000); object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; } timerbusdev = SYS_BUS_DEVICE(timerdev); sysbus_mmio_map(timerbusdev, 0, timer_addr[i]); sysbus_connect_irq(timerbusdev, 0, pic[timer_irq[i]]); } }


static int cmp_int(const void *p1, const void *p2) { int left = *(const int *)p1; int right = *(const int *)p2; return ((left > right) - (left < right)); }


static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) { const CodecMime *mime = ff_id3v2_mime_tags; enum CodecID id = CODEC_ID_NONE; uint8_t mimetype[64], *desc = NULL, *data = NULL; AVIOContext *pb = NULL; AVStream *st; int type, width, height; int len, ret = 0; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL); if (!pb) return AVERROR(ENOMEM); /* read the picture type */ type = avio_rb32(pb); if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type); ret = AVERROR_INVALIDDATA; goto fail; } /* picture mimetype */ len = avio_rb32(pb); if (len <= 0 || avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) { av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached " "picture.\n"); ret = AVERROR_INVALIDDATA; goto fail; } mimetype[len] = 0; while (mime->id != CODEC_ID_NONE) { if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { id = mime->id; break; } mime++; } if (id == CODEC_ID_NONE) { av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", mimetype); ret = AVERROR_INVALIDDATA; goto fail; } /* picture description */ len = avio_rb32(pb); if (len > 0) { if (!(desc = av_malloc(len + 1))) { ret = AVERROR(ENOMEM); goto fail; } if (avio_read(pb, desc, len) != len) { ret = AVERROR(EIO); goto fail; } desc[len] = 0; } /* picture metadata */ width = avio_rb32(pb); height = avio_rb32(pb); avio_skip(pb, 8); /* picture data */ len = avio_rb32(pb); if (len <= 0) { ret = AVERROR_INVALIDDATA; goto fail; } if (!(data = av_malloc(len))) { ret = AVERROR(ENOMEM); goto fail; } if (avio_read(pb, data, len) != len) { ret = AVERROR(EIO); goto fail; } av_init_packet(&st->attached_pic); st->attached_pic.data = data; st->attached_pic.size = len; st->attached_pic.destruct = av_destruct_packet; st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; st->disposition |= AV_DISPOSITION_ATTACHED_PIC; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = id; st->codec->width = width; st->codec->height = height; av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0); if (desc) av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); av_freep(&pb); return 0; fail: av_freep(&desc); av_freep(&data); av_freep(&pb); return ret; }


void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, Error **errp) { error_setg(errp, "AioContext polling is not implemented on Windows"); }


static void host_memory_backend_set_prealloc(Object *obj, bool value, Error **errp) { Error *local_err = NULL; HostMemoryBackend *backend = MEMORY_BACKEND(obj); if (backend->force_prealloc) { if (value) { error_setg(errp, "remove -mem-prealloc to use the prealloc property"); return; } } if (!memory_region_size(&backend->mr)) { backend->prealloc = value; return; } if (value && !backend->prealloc) { int fd = memory_region_get_fd(&backend->mr); void *ptr = memory_region_get_ram_ptr(&backend->mr); uint64_t sz = memory_region_size(&backend->mr); os_mem_prealloc(fd, ptr, sz, &local_err); if (local_err) { error_propagate(errp, local_err); return; } backend->prealloc = true; } }


void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)) { AVPacketList **next_point, *this_pktl; this_pktl = av_mallocz(sizeof(AVPacketList)); this_pktl->pkt= *pkt; pkt->destruct= NULL; // do not free original but only the copy av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory if(s->streams[pkt->stream_index]->last_in_packet_buffer){ next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next); }else next_point = &s->packet_buffer; if(*next_point){ if(compare(s, &s->packet_buffer_end->pkt, pkt)){ while(!compare(s, &(*next_point)->pkt, pkt)){ next_point= &(*next_point)->next; } goto next_non_null; }else{ next_point = &(s->packet_buffer_end->next); } } assert(!*next_point); s->packet_buffer_end= this_pktl; next_non_null: this_pktl->next= *next_point; s->streams[pkt->stream_index]->last_in_packet_buffer= *next_point= this_pktl; }


static void read_partition(uint8_t *p, struct partition_record *r) { r->bootable = p[0]; r->start_head = p[1]; r->start_cylinder = p[3] | ((p[2] << 2) & 0x0300); r->start_sector = p[2] & 0x3f; r->system = p[4]; r->end_head = p[5]; r->end_cylinder = p[7] | ((p[6] << 2) & 0x300); r->end_sector = p[6] & 0x3f; r->start_sector_abs = p[8] | p[9] << 8 | p[10] << 16 | p[11] << 24; r->nb_sectors_abs = p[12] | p[13] << 8 | p[14] << 16 | p[15] << 24; }