void ff_slice_thread_free(AVCodecContext *avctx) { SliceThreadContext *c = avctx->internal->thread_ctx; int i; pthread_mutex_lock(&c->current_job_lock); c->done = 1; pthread_cond_broadcast(&c->current_job_cond); for (i = 0; i < c->thread_count; i++) pthread_cond_broadcast(&c->progress_cond[i]); pthread_mutex_unlock(&c->current_job_lock); for (i=0; i<avctx->thread_count; i++) pthread_join(c->workers[i], NULL); for (i = 0; i < c->thread_count; i++) { pthread_mutex_destroy(&c->progress_mutex[i]); pthread_cond_destroy(&c->progress_cond[i]); } pthread_mutex_destroy(&c->current_job_lock); pthread_cond_destroy(&c->current_job_cond); pthread_cond_destroy(&c->last_job_cond); av_freep(&c->entries); av_freep(&c->progress_mutex); av_freep(&c->progress_cond); av_freep(&c->workers); av_freep(&avctx->internal->thread_ctx); }


RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, RTPPayloadData *rtp_payload_data) { RTPDemuxContext *s; s = av_mallocz(sizeof(RTPDemuxContext)); if (!s) return NULL; s->payload_type = payload_type; s->last_rtcp_ntp_time = AV_NOPTS_VALUE; s->first_rtcp_ntp_time = AV_NOPTS_VALUE; s->ic = s1; s->st = st; s->rtp_payload_data = rtp_payload_data; rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp? if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) { s->ts = ff_mpegts_parse_open(s->ic); if (s->ts == NULL) { av_free(s); return NULL; } } else { av_set_pts_info(st, 32, 1, 90000); switch(st->codec->codec_id) { case CODEC_ID_MPEG1VIDEO: case CODEC_ID_MPEG2VIDEO: case CODEC_ID_MP2: case CODEC_ID_MP3: case CODEC_ID_MPEG4: case CODEC_ID_H263: case CODEC_ID_H264: st->need_parsing = AVSTREAM_PARSE_FULL; break; default: if (st->codec->codec_type == CODEC_TYPE_AUDIO) { av_set_pts_info(st, 32, 1, st->codec->sample_rate); } break; } } // needed to send back RTCP RR in RTSP sessions s->rtp_ctx = rtpc; gethostname(s->hostname, sizeof(s->hostname)); return s; }


static int http_send_data(HTTPContext *c, long cur_time) { int len, ret; while (c->buffer_ptr >= c->buffer_end) { ret = http_prepare_data(c, cur_time); if (ret < 0) return -1; else if (ret == 0) { continue; } else { /* state change requested */ return 0; } } if (c->buffer_end > c->buffer_ptr) { len = write(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr); if (len < 0) { if (errno != EAGAIN && errno != EINTR) { /* error : close connection */ return -1; } } else { c->buffer_ptr += len; c->data_count += len; if (c->stream) c->stream->bytes_served += len; } } return 0; }


static void virgl_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_resource_unref unref; VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); virgl_renderer_resource_unref(unref.resource_id);


static void perf_yield(void) { unsigned int i, maxcycles; double duration; maxcycles = 100000000; i = maxcycles; Coroutine *coroutine = qemu_coroutine_create(yield_loop); g_test_timer_start(); while (i > 0) { qemu_coroutine_enter(coroutine, &i); } duration = g_test_timer_elapsed(); g_test_message("Yield %u iterations: %f s\n", maxcycles, duration); }


static void fill_picture_parameters(AVCodecContext *avctx, struct dxva_context *ctx, const struct MpegEncContext *s, DXVA_PictureParameters *pp) { const Picture *current_picture = s->current_picture_ptr; int is_field = s->picture_structure != PICT_FRAME; memset(pp, 0, sizeof(*pp)); pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(ctx, &current_picture->f); pp->wDeblockedPictureIndex = 0; if (s->pict_type != AV_PICTURE_TYPE_I) pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture.f); else pp->wForwardRefPictureIndex = 0xffff; if (s->pict_type == AV_PICTURE_TYPE_B) pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture.f); else pp->wBackwardRefPictureIndex = 0xffff; pp->wPicWidthInMBminus1 = s->mb_width - 1; pp->wPicHeightInMBminus1 = (s->mb_height >> is_field) - 1; pp->bMacroblockWidthMinus1 = 15; pp->bMacroblockHeightMinus1 = 15; pp->bBlockWidthMinus1 = 7; pp->bBlockHeightMinus1 = 7; pp->bBPPminus1 = 7; pp->bPicStructure = s->picture_structure; pp->bSecondField = is_field && !s->first_field; pp->bPicIntra = s->pict_type == AV_PICTURE_TYPE_I; pp->bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B; pp->bBidirectionalAveragingMode = 0; pp->bMVprecisionAndChromaRelation= 0; /* FIXME */ pp->bChromaFormat = s->chroma_format; pp->bPicScanFixed = 1; pp->bPicScanMethod = s->alternate_scan ? 1 : 0; pp->bPicReadbackRequests = 0; pp->bRcontrol = 0; pp->bPicSpatialResid8 = 0; pp->bPicOverflowBlocks = 0; pp->bPicExtrapolation = 0; pp->bPicDeblocked = 0; pp->bPicDeblockConfined = 0; pp->bPic4MVallowed = 0; pp->bPicOBMC = 0; pp->bPicBinPB = 0; pp->bMV_RPS = 0; pp->bReservedBits = 0; pp->wBitstreamFcodes = (s->mpeg_f_code[0][0] << 12) | (s->mpeg_f_code[0][1] << 8) | (s->mpeg_f_code[1][0] << 4) | (s->mpeg_f_code[1][1] ); pp->wBitstreamPCEelements = (s->intra_dc_precision << 14) | (s->picture_structure << 12) | (s->top_field_first << 11) | (s->frame_pred_frame_dct << 10) | (s->concealment_motion_vectors << 9) | (s->q_scale_type << 8) | (s->intra_vlc_format << 7) | (s->alternate_scan << 6) | (s->repeat_first_field << 5) | (s->chroma_420_type << 4) | (s->progressive_frame << 3); pp->bBitstreamConcealmentNeed = 0; pp->bBitstreamConcealmentMethod = 0; }


static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id) { VirtIOBalloon *s = opaque; if (version_id != 1) return -EINVAL; virtio_load(&s->vdev, f); s->num_pages = qemu_get_be32(f); s->actual = qemu_get_be32(f); qemu_get_buffer(f, (uint8_t *)&s->stats_vq_elem, sizeof(VirtQueueElement)); qemu_get_buffer(f, (uint8_t *)&s->stats_vq_offset, sizeof(size_t)); qemu_get_buffer(f, (uint8_t *)&s->stats_callback, sizeof(MonitorCompletion)); qemu_get_buffer(f, (uint8_t *)&s->stats_opaque_callback_data, sizeof(void)); return 0; }


static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop) { _regs->gpr[1] = infop->start_stack; #if defined(TARGET_PPC64) && !defined(TARGET_ABI32) if (get_ppc64_abi(infop) < 2) { _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias; infop->entry = ldq_raw(infop->entry) + infop->load_bias; } else { _regs->gpr[12] = infop->entry; /* r12 set to global entry address */ } #endif _regs->nip = infop->entry; }


static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int size) { int64_t end = avio_tell(pb) + size; uint8_t *key = NULL, *val = NULL; int i; AVStream *st; MOVStreamContext *sc; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; sc = st->priv_data; for (i = 0; i < 2; i++) { uint8_t **p; uint32_t len, tag; if (end - avio_tell(pb) <= 12) break; len = avio_rb32(pb); tag = avio_rl32(pb); avio_skip(pb, 4); // flags if (len < 12 || len - 12 > end - avio_tell(pb)) break; len -= 12; if (tag == MKTAG('n', 'a', 'm', 'e')) p = &key; else if (tag == MKTAG('d', 'a', 't', 'a') && len > 4) { avio_skip(pb, 4); len -= 4; p = &val; } else break; *p = av_malloc(len + 1); if (!*p) break; avio_read(pb, *p, len); (*p)[len] = 0; } if (key && val) { if (strcmp(key, "iTunSMPB") == 0) { int priming, remainder, samples; if(sscanf(val, "%*X %X %X %X", &priming, &remainder, &samples) == 3){ if(priming>0 && priming<16384) sc->start_pad = priming; } } if (strcmp(key, "cdec") != 0) { av_dict_set(&c->fc->metadata, key, val, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); key = val = NULL; } } avio_seek(pb, end, SEEK_SET); av_freep(&key); av_freep(&val); return 0; }


static void softusb_usbdev_datain(void *opaque) { MilkymistSoftUsbState *s = opaque; USBPacket p; p.pid = USB_TOKEN_IN; p.devep = 1; p.data = s->kbd_usb_buffer; p.len = sizeof(s->kbd_usb_buffer); s->usbdev->info->handle_data(s->usbdev, &p); softusb_kbd_changed(s); }


static int a52_decode_init(AVCodecContext *avctx) { AC3DecodeState *s = avctx->priv_data; #ifdef CONFIG_LIBA52BIN s->handle = dlopen(liba52name, RTLD_LAZY); if (!s->handle) { av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror()); return -1; } s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init"); s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples"); s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo"); s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame"); s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block"); s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free"); if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo || !s->a52_frame || !s->a52_block || !s->a52_free) { dlclose(s->handle); return -1; } #else s->handle = 0; s->a52_init = a52_init; s->a52_samples = a52_samples; s->a52_syncinfo = a52_syncinfo; s->a52_frame = a52_frame; s->a52_block = a52_block; s->a52_free = a52_free; #endif s->state = s->a52_init(0); /* later use CPU flags */ s->samples = s->a52_samples(s->state); s->inbuf_ptr = s->inbuf; s->frame_size = 0; /* allow downmixing to stereo or mono */ if (avctx->channels > 0 && avctx->request_channels > 0 && avctx->request_channels < avctx->channels && avctx->request_channels <= 2) { avctx->channels = avctx->request_channels; } return 0; }


static void release_drive(Object *obj, const char *name, void *opaque) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; BlockBackend **ptr = qdev_get_prop_ptr(dev, prop); if (*ptr) { blk_detach_dev(*ptr, dev); blockdev_auto_del(*ptr); } }


static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ MpegEncContext * const s = &h->s; unsigned int pps_id= get_ue_golomb(&s->gb); PPS *pps; if(pps_id>=MAX_PPS_COUNT){ av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } pps = &h->pps_buffer[pps_id]; pps->sps_id= get_ue_golomb(&s->gb); pps->cabac= get_bits1(&s->gb); pps->pic_order_present= get_bits1(&s->gb); pps->slice_group_count= get_ue_golomb(&s->gb) + 1; if(pps->slice_group_count > 1 ){ pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); switch(pps->mb_slice_group_map_type){ case 0: #if 0 | for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | | run_length[ i ] |1 |ue(v) | #endif break; case 2: #if 0 | for( i = 0; i < num_slice_groups_minus1; i++ ) | | | |{ | | | | top_left_mb[ i ] |1 |ue(v) | | bottom_right_mb[ i ] |1 |ue(v) | | } | | | #endif break; case 3: case 4: case 5: #if 0 | slice_group_change_direction_flag |1 |u(1) | | slice_group_change_rate_minus1 |1 |ue(v) | #endif break; case 6: #if 0 | slice_group_id_cnt_minus1 |1 |ue(v) | | for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | |) | | | | slice_group_id[ i ] |1 |u(v) | #endif break; } } pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; if(pps->ref_count[0] > 32 || pps->ref_count[1] > 32){ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); return -1; } pps->weighted_pred= get_bits1(&s->gb); pps->weighted_bipred_idc= get_bits(&s->gb, 2); pps->init_qp= get_se_golomb(&s->gb) + 26; pps->init_qs= get_se_golomb(&s->gb) + 26; pps->chroma_qp_index_offset= get_se_golomb(&s->gb); pps->deblocking_filter_parameters_present= get_bits1(&s->gb); pps->constrained_intra_pred= get_bits1(&s->gb); pps->redundant_pic_cnt_present = get_bits1(&s->gb); pps->transform_8x8_mode= 0; h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit memset(pps->scaling_matrix4, 16, 6*16*sizeof(uint8_t)); memset(pps->scaling_matrix8, 16, 2*64*sizeof(uint8_t)); if(get_bits_count(&s->gb) < bit_length){ pps->transform_8x8_mode= get_bits1(&s->gb); decode_scaling_matrices(h, &h->sps_buffer[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); get_se_golomb(&s->gb); //second_chroma_qp_index_offset } if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s %s\n", pps_id, pps->sps_id, pps->cabac ? "CABAC" : "CAVLC", pps->slice_group_count, pps->ref_count[0], pps->ref_count[1], pps->weighted_pred ? "weighted" : "", pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, pps->deblocking_filter_parameters_present ? "LPAR" : "", pps->constrained_intra_pred ? "CONSTR" : "", pps->redundant_pic_cnt_present ? "REDU" : "", pps->transform_8x8_mode ? "8x8DCT" : "" ); } return 0; }


static uint64_t watch_mem_read(void *opaque, hwaddr addr, unsigned size) { check_watchpoint(addr & ~TARGET_PAGE_MASK, size, BP_MEM_READ); switch (size) { case 1: return ldub_phys(&address_space_memory, addr); case 2: return lduw_phys(&address_space_memory, addr); case 4: return ldl_phys(&address_space_memory, addr); default: abort(); } }


static int tcp_open(URLContext *h, const char *uri, int flags) { struct sockaddr_in dest_addr; char hostname[1024], *q; int port, fd = -1; TCPContext *s; const char *p; fd_set wfds; int fd_max, ret; struct timeval tv; socklen_t optlen; s = av_malloc(sizeof(TCPContext)); if (!s) return -ENOMEM; h->priv_data = s; p = uri; if (!strstart(p, "tcp://", &p)) goto fail; q = hostname; while (*p != ':' && *p != '/' && *p != '\0') { if ((q - hostname) < sizeof(hostname) - 1) *q++ = *p; p++; } *q = '\0'; if (*p != ':') goto fail; p++; port = strtoul(p, (char **)&p, 10); if (port <= 0 || port >= 65536) goto fail; dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(port); if (resolve_host(&dest_addr.sin_addr, hostname) < 0) goto fail; fd = socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) goto fail; fcntl(fd, F_SETFL, O_NONBLOCK); redo: ret = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); if (ret < 0) { if (errno == EINTR) goto redo; if (errno != EINPROGRESS) goto fail; /* wait until we are connected or until abort */ for(;;) { if (url_interrupt_cb()) { ret = -EINTR; goto fail1; } fd_max = fd; FD_ZERO(&wfds); FD_SET(fd, &wfds); tv.tv_sec = 0; tv.tv_usec = 100 * 1000; ret = select(fd_max + 1, NULL, &wfds, NULL, &tv); if (ret > 0 && FD_ISSET(fd, &wfds)) break; } /* test error */ optlen = sizeof(ret); getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); if (ret != 0) goto fail; } s->fd = fd; return 0; fail: ret = AVERROR_IO; fail1: if (fd >= 0) close(fd); av_free(s); return ret; }


static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov) { int max_track_id = 1, i; int64_t max_track_len_temp, max_track_len = 0; int version; for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].entry > 0) { max_track_len_temp = av_rescale_rnd(mov->tracks[i].track_duration, MOV_TIMESCALE, mov->tracks[i].timescale, AV_ROUND_UP); if (max_track_len < max_track_len_temp) max_track_len = max_track_len_temp; if (max_track_id < mov->tracks[i].track_id) max_track_id = mov->tracks[i].track_id; } } version = max_track_len < UINT32_MAX ? 0 : 1; (version == 1) ? avio_wb32(pb, 120) : avio_wb32(pb, 108); /* size */ ffio_wfourcc(pb, "mvhd"); avio_w8(pb, version); avio_wb24(pb, 0); /* flags */ if (version == 1) { avio_wb64(pb, mov->time); avio_wb64(pb, mov->time); } else { avio_wb32(pb, mov->time); /* creation time */ avio_wb32(pb, mov->time); /* modification time */ } avio_wb32(pb, MOV_TIMESCALE); (version == 1) ? avio_wb64(pb, max_track_len) : avio_wb32(pb, max_track_len); /* duration of longest track */ avio_wb32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */ avio_wb16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */ avio_wb16(pb, 0); /* reserved */ avio_wb32(pb, 0); /* reserved */ avio_wb32(pb, 0); /* reserved */ /* Matrix structure */ avio_wb32(pb, 0x00010000); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x00010000); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x0); /* reserved */ avio_wb32(pb, 0x40000000); /* reserved */ avio_wb32(pb, 0); /* reserved (preview time) */ avio_wb32(pb, 0); /* reserved (preview duration) */ avio_wb32(pb, 0); /* reserved (poster time) */ avio_wb32(pb, 0); /* reserved (selection time) */ avio_wb32(pb, 0); /* reserved (selection duration) */ avio_wb32(pb, 0); /* reserved (current time) */ avio_wb32(pb, max_track_id + 1); /* Next track id */ return 0x6c; }


static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; a0 = col[8*0]; a1 = col[8*2]; a2 = col[8*4]; a3 = col[8*6]; c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = cm[(c0 + c1) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 + c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 - c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c0 - c1) >> C_SHIFT]; }


static void print_final_stats(int64_t total_size) { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; float percent = -1.0; int i, j; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; switch (ost->st->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->data_size; break; default: other_size += ost->data_size; break; } extra_size += ost->st->codec->extradata_size; data_size += ost->data_size; } if (data_size && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; av_log(NULL, AV_LOG_INFO, "\n"); av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", video_size / 1024.0, audio_size / 1024.0, subtitle_size / 1024.0, other_size / 1024.0, extra_size / 1024.0); if (percent >= 0.0) av_log(NULL, AV_LOG_INFO, "%f%%", percent); else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { InputFile *f = input_files[i]; uint64_t total_packets = 0, total_size = 0; av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n", i, f->ctx->filename); for (j = 0; j < f->nb_streams; j++) { InputStream *ist = input_streams[f->ist_index + j]; enum AVMediaType type = ist->st->codec->codec_type; total_size += ist->data_size; total_packets += ist->nb_packets; av_log(NULL, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ", i, j, media_type_string(type)); av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ", ist->nb_packets, ist->data_size); if (ist->decoding_needed) { av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded", ist->frames_decoded); if (type == AVMEDIA_TYPE_AUDIO) av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded); av_log(NULL, AV_LOG_VERBOSE, "; "); } av_log(NULL, AV_LOG_VERBOSE, "\n"); } av_log(NULL, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n", total_packets, total_size); } for (i = 0; i < nb_output_files; i++) { OutputFile *of = output_files[i]; uint64_t total_packets = 0, total_size = 0; av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n", i, of->ctx->filename); for (j = 0; j < of->ctx->nb_streams; j++) { OutputStream *ost = output_streams[of->ost_index + j]; enum AVMediaType type = ost->st->codec->codec_type; total_size += ost->data_size; total_packets += ost->packets_written; av_log(NULL, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ", i, j, media_type_string(type)); if (ost->encoding_needed) { av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded", ost->frames_encoded); if (type == AVMEDIA_TYPE_AUDIO) av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded); av_log(NULL, AV_LOG_VERBOSE, "; "); } av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ", ost->packets_written, ost->data_size); av_log(NULL, AV_LOG_VERBOSE, "\n"); } av_log(NULL, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n", total_packets, total_size); } if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){ av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)\n"); } }


static void read_sbr_channel_pair_element(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb) { if (get_bits1(gb)) // bs_data_extra skip_bits(gb, 8); // bs_reserved if ((sbr->bs_coupling = get_bits1(gb))) { read_sbr_grid(ac, sbr, gb, &sbr->data[0]); copy_sbr_grid(&sbr->data[1], &sbr->data[0]); read_sbr_dtdf(sbr, gb, &sbr->data[0]); read_sbr_dtdf(sbr, gb, &sbr->data[1]); read_sbr_invf(sbr, gb, &sbr->data[0]); memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); read_sbr_envelope(sbr, gb, &sbr->data[0], 0); read_sbr_noise(sbr, gb, &sbr->data[0], 0); read_sbr_envelope(sbr, gb, &sbr->data[1], 1); read_sbr_noise(sbr, gb, &sbr->data[1], 1); } else { read_sbr_grid(ac, sbr, gb, &sbr->data[0]); read_sbr_grid(ac, sbr, gb, &sbr->data[1]); read_sbr_dtdf(sbr, gb, &sbr->data[0]); read_sbr_dtdf(sbr, gb, &sbr->data[1]); read_sbr_invf(sbr, gb, &sbr->data[0]); read_sbr_invf(sbr, gb, &sbr->data[1]); read_sbr_envelope(sbr, gb, &sbr->data[0], 0); read_sbr_envelope(sbr, gb, &sbr->data[1], 1); read_sbr_noise(sbr, gb, &sbr->data[0], 0); read_sbr_noise(sbr, gb, &sbr->data[1], 1); } if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb))) get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]); }


static void qtrle_decode_16bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change) { int rle_code; int pixel_ptr; int row_inc = s->frame.linesize[0]; unsigned short rgb16; unsigned char *rgb = s->frame.data[0]; int pixel_limit = s->frame.linesize[0] * s->avctx->height; while (lines_to_change--) { CHECK_STREAM_PTR(2); pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2; while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { if (rle_code == 0) { /* there's another skip code in the stream */ CHECK_STREAM_PTR(1); pixel_ptr += (s->buf[stream_ptr++] - 1) * 2; CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ } else if (rle_code < 0) { /* decode the run length code */ rle_code = -rle_code; CHECK_STREAM_PTR(2); rgb16 = AV_RB16(&s->buf[stream_ptr]); stream_ptr += 2; CHECK_PIXEL_PTR(rle_code * 2); while (rle_code--) { *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; pixel_ptr += 2; } } else { CHECK_STREAM_PTR(rle_code * 2); CHECK_PIXEL_PTR(rle_code * 2); /* copy pixels directly to output */ while (rle_code--) { rgb16 = AV_RB16(&s->buf[stream_ptr]); stream_ptr += 2; *(unsigned short *)(&rgb[pixel_ptr]) = rgb16; pixel_ptr += 2; } } } row_ptr += row_inc; } }


static void v9fs_mknod(void *opaque) { int mode; gid_t gid; int32_t fid; V9fsQID qid; int err = 0; int major, minor; size_t offset = 7; V9fsString name; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; pdu_unmarshal(pdu, offset, "dsdddd", &fid, &name, &mode, &major, &minor, &gid); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, gid, makedev(major, minor), mode, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); err = offset; err += pdu_marshal(pdu, offset, "Q", &qid); out: put_fid(pdu, fidp); out_nofid: trace_v9fs_mknod_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); complete_pdu(s, pdu, err); v9fs_string_free(&name); }


void HELPER(cpsr_write_eret)(CPUARMState *env, uint32_t val) { cpsr_write(env, val, CPSR_ERET_MASK, CPSRWriteExceptionReturn); arm_call_el_change_hook(arm_env_get_cpu(env)); }


static void vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr) { decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1); }


static void test_parse_path_subprocess(void) { /* All these should work without issue */ qemu_set_log_filename("/tmp/qemu.log"); qemu_set_log_filename("/tmp/qemu-%d.log"); qemu_set_log_filename("/tmp/qemu.log.%d"); }


static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, int16_t *filter, int16_t *filterPos, long filterSize) { #ifdef HAVE_MMX assert(filterSize % 4 == 0 && filterSize>0); if(filterSize==4) // allways true for upscaling, sometimes for down too { long counter= -2*dstW; filter-= counter*2; filterPos-= counter/2; dst-= counter/2; asm volatile( "pxor %%mm7, %%mm7 \n\t" "movq "MANGLE(w02)", %%mm6 \n\t" "push %%"REG_BP" \n\t" // we use 7 regs here ... "mov %%"REG_a", %%"REG_BP" \n\t" ASMALIGN16 "1: \n\t" "movzwl (%2, %%"REG_BP"), %%eax \n\t" "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t" "movq (%1, %%"REG_BP", 4), %%mm1\n\t" "movq 8(%1, %%"REG_BP", 4), %%mm3\n\t" "movd (%3, %%"REG_a"), %%mm0 \n\t" "movd (%3, %%"REG_b"), %%mm2 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "pmaddwd %%mm1, %%mm0 \n\t" "pmaddwd %%mm2, %%mm3 \n\t" "psrad $8, %%mm0 \n\t" "psrad $8, %%mm3 \n\t" "packssdw %%mm3, %%mm0 \n\t" "pmaddwd %%mm6, %%mm0 \n\t" "packssdw %%mm0, %%mm0 \n\t" "movd %%mm0, (%4, %%"REG_BP") \n\t" "add $4, %%"REG_BP" \n\t" " jnc 1b \n\t" "pop %%"REG_BP" \n\t" : "+a" (counter) : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) : "%"REG_b ); } else if(filterSize==8) { long counter= -2*dstW; filter-= counter*4; filterPos-= counter/2; dst-= counter/2; asm volatile( "pxor %%mm7, %%mm7 \n\t" "movq "MANGLE(w02)", %%mm6 \n\t" "push %%"REG_BP" \n\t" // we use 7 regs here ... "mov %%"REG_a", %%"REG_BP" \n\t" ASMALIGN16 "1: \n\t" "movzwl (%2, %%"REG_BP"), %%eax \n\t" "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t" "movq (%1, %%"REG_BP", 8), %%mm1\n\t" "movq 16(%1, %%"REG_BP", 8), %%mm3\n\t" "movd (%3, %%"REG_a"), %%mm0 \n\t" "movd (%3, %%"REG_b"), %%mm2 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "pmaddwd %%mm1, %%mm0 \n\t" "pmaddwd %%mm2, %%mm3 \n\t" "movq 8(%1, %%"REG_BP", 8), %%mm1\n\t" "movq 24(%1, %%"REG_BP", 8), %%mm5\n\t" "movd 4(%3, %%"REG_a"), %%mm4 \n\t" "movd 4(%3, %%"REG_b"), %%mm2 \n\t" "punpcklbw %%mm7, %%mm4 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "pmaddwd %%mm1, %%mm4 \n\t" "pmaddwd %%mm2, %%mm5 \n\t" "paddd %%mm4, %%mm0 \n\t" "paddd %%mm5, %%mm3 \n\t" "psrad $8, %%mm0 \n\t" "psrad $8, %%mm3 \n\t" "packssdw %%mm3, %%mm0 \n\t" "pmaddwd %%mm6, %%mm0 \n\t" "packssdw %%mm0, %%mm0 \n\t" "movd %%mm0, (%4, %%"REG_BP") \n\t" "add $4, %%"REG_BP" \n\t" " jnc 1b \n\t" "pop %%"REG_BP" \n\t" : "+a" (counter) : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) : "%"REG_b ); } else { uint8_t *offset = src+filterSize; long counter= -2*dstW; // filter-= counter*filterSize/2; filterPos-= counter/2; dst-= counter/2; asm volatile( "pxor %%mm7, %%mm7 \n\t" "movq "MANGLE(w02)", %%mm6 \n\t" ASMALIGN16 "1: \n\t" "mov %2, %%"REG_c" \n\t" "movzwl (%%"REG_c", %0), %%eax \n\t" "movzwl 2(%%"REG_c", %0), %%ebx \n\t" "mov %5, %%"REG_c" \n\t" "pxor %%mm4, %%mm4 \n\t" "pxor %%mm5, %%mm5 \n\t" "2: \n\t" "movq (%1), %%mm1 \n\t" "movq (%1, %6), %%mm3 \n\t" "movd (%%"REG_c", %%"REG_a"), %%mm0\n\t" "movd (%%"REG_c", %%"REG_b"), %%mm2\n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm2 \n\t" "pmaddwd %%mm1, %%mm0 \n\t" "pmaddwd %%mm2, %%mm3 \n\t" "paddd %%mm3, %%mm5 \n\t" "paddd %%mm0, %%mm4 \n\t" "add $8, %1 \n\t" "add $4, %%"REG_c" \n\t" "cmp %4, %%"REG_c" \n\t" " jb 2b \n\t" "add %6, %1 \n\t" "psrad $8, %%mm4 \n\t" "psrad $8, %%mm5 \n\t" "packssdw %%mm5, %%mm4 \n\t" "pmaddwd %%mm6, %%mm4 \n\t" "packssdw %%mm4, %%mm4 \n\t" "mov %3, %%"REG_a" \n\t" "movd %%mm4, (%%"REG_a", %0) \n\t" "add $4, %0 \n\t" " jnc 1b \n\t" : "+r" (counter), "+r" (filter) : "m" (filterPos), "m" (dst), "m"(offset), "m" (src), "r" (filterSize*2) : "%"REG_b, "%"REG_a, "%"REG_c ); } #else #ifdef HAVE_ALTIVEC hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize); #else int i; for(i=0; i<dstW; i++) { int j; int srcPos= filterPos[i]; int val=0; // printf("filterPos: %d\n", filterPos[i]); for(j=0; j<filterSize; j++) { // printf("filter: %d, src: %d\n", filter[i], src[srcPos + j]); val += ((int)src[srcPos + j])*filter[filterSize*i + j]; } // filter += hFilterSize; dst[i] = FFMIN(FFMAX(0, val>>7), (1<<15)-1); // the cubic equation does overflow ... // dst[i] = val>>7; } #endif #endif }


int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples) { int i, nb_samples1; short *bufin[2]; short *bufout[2]; short *buftmp2[2], *buftmp3[2]; int lenout; if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) { /* nothing to do */ memcpy(output, input, nb_samples * s->input_channels * sizeof(short)); return nb_samples; } /* XXX: move those malloc to resample init code */ for(i=0; i<s->filter_channels; i++){ bufin[i]= (short*) av_malloc( (nb_samples + s->temp_len) * sizeof(short) ); memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short)); buftmp2[i] = bufin[i] + s->temp_len; } /* make some zoom to avoid round pb */ lenout= (int)(4*nb_samples * s->ratio) + 16; bufout[0]= (short*) av_malloc( lenout * sizeof(short) ); bufout[1]= (short*) av_malloc( lenout * sizeof(short) ); if (s->input_channels == 2 && s->output_channels == 1) { buftmp3[0] = output; stereo_to_mono(buftmp2[0], input, nb_samples); } else if (s->output_channels >= 2 && s->input_channels == 1) { buftmp3[0] = bufout[0]; memcpy(buftmp2[0], input, nb_samples*sizeof(short)); } else if (s->output_channels >= 2) { buftmp3[0] = bufout[0]; buftmp3[1] = bufout[1]; stereo_split(buftmp2[0], buftmp2[1], input, nb_samples); } else { buftmp3[0] = output; memcpy(buftmp2[0], input, nb_samples*sizeof(short)); } nb_samples += s->temp_len; /* resample each channel */ nb_samples1 = 0; /* avoid warning */ for(i=0;i<s->filter_channels;i++) { int consumed; int is_last= i+1 == s->filter_channels; nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last); s->temp_len= nb_samples - consumed; s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short)); memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short)); } if (s->output_channels == 2 && s->input_channels == 1) { mono_to_stereo(output, buftmp3[0], nb_samples1); } else if (s->output_channels == 2) { stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); } else if (s->output_channels == 6) { ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1); } for(i=0; i<s->filter_channels; i++) av_free(bufin[i]); av_free(bufout[0]); av_free(bufout[1]); return nb_samples1; }


static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { TransContext *s = ctx->priv; ThreadData *td = arg; AVFrame *out = td->out; AVFrame *in = td->in; int plane; for (plane = 0; out->data[plane]; plane++) { int hsub = plane == 1 || plane == 2 ? s->hsub : 0; int vsub = plane == 1 || plane == 2 ? s->vsub : 0; int pixstep = s->pixsteps[plane]; int inh = AV_CEIL_RSHIFT(in->height, vsub); int outw = AV_CEIL_RSHIFT(out->width, hsub); int outh = AV_CEIL_RSHIFT(out->height, vsub); int start = (outh * jobnr ) / nb_jobs; int end = (outh * (jobnr+1)) / nb_jobs; uint8_t *dst, *src; int dstlinesize, srclinesize; int x, y; dstlinesize = out->linesize[plane]; dst = out->data[plane] + start * dstlinesize; src = in->data[plane]; srclinesize = in->linesize[plane]; if (s->dir & 1) { src += in->linesize[plane] * (inh - 1); srclinesize *= -1; } if (s->dir & 2) { dst = out->data[plane] + dstlinesize * (outh - start - 1); dstlinesize *= -1; } for (y = start; y < end - 7; y += 8) { for (x = 0; x < outw - 7; x += 8) { s->transpose_8x8(src + x * srclinesize + y * pixstep, srclinesize, dst + (y - start) * dstlinesize + x * pixstep, dstlinesize); } if (outw - x > 0 && end - y > 0) s->transpose_block(src + x * srclinesize + y * pixstep, srclinesize, dst + (y - start) * dstlinesize + x * pixstep, dstlinesize, outw - x, end - y); } if (end - y > 0) s->transpose_block(src + 0 * srclinesize + y * pixstep, srclinesize, dst + (y - start) * dstlinesize + 0 * pixstep, dstlinesize, outw, end - y); } return 0; }


static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, unsigned char *out_buf, uint8_t* out_end, int pixelstride) { unsigned char pixel, count; unsigned char *orig = out_buf; while (1) { if(in_buf + 1 > in_end) return -1; pixel = bytestream_get_byte(&in_buf); if (!(count = (pixel & 0x7f))) { return (out_buf - orig) / pixelstride; } /* Check for buffer overflow. */ if(out_buf + pixelstride * count >= out_end) return -1; if (pixel & 0x80) { while (count--) { *out_buf = bytestream_get_byte(&in_buf); out_buf += pixelstride; } } else { pixel = bytestream_get_byte(&in_buf); while (count--) { *out_buf = pixel; out_buf += pixelstride; } } } }


static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy, uint8_t *num_exp_groups) { int group_size, nb_groups, i, j, k, exp_min; group_size = exp_strategy + (exp_strategy == EXP_D45); *num_exp_groups = (nb_exps + (group_size * 3) - 4) / (3 * group_size); nb_groups = *num_exp_groups * 3; /* for each group, compute the minimum exponent */ if (exp_strategy > EXP_D15) { k = 1; for (i = 1; i <= nb_groups; i++) { exp_min = exp[k]; assert(exp_min >= 0 && exp_min <= 24); for (j = 1; j < group_size; j++) { if (exp[k+j] < exp_min) exp_min = exp[k+j]; } exp[i] = exp_min; k += group_size; } } /* constraint for DC exponent */ if (exp[0] > 15) exp[0] = 15; /* decrease the delta between each groups to within 2 so that they can be differentially encoded */ for (i = 1; i <= nb_groups; i++) exp[i] = FFMIN(exp[i], exp[i-1] + 2); for (i = nb_groups-1; i >= 0; i--) exp[i] = FFMIN(exp[i], exp[i+1] + 2); /* now we have the exponent values the decoder will see */ if (exp_strategy > EXP_D15) { k = nb_groups * group_size; for (i = nb_groups; i > 0; i--) { for (j = 0; j < group_size; j++) exp[k-j] = exp[i]; k -= group_size; } } }


static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap, int len) { while (len-- >= 0) mant_cnt[bap[len]]++; }


static av_cold int adpcm_decode_init(AVCodecContext * avctx) { ADPCMDecodeContext *c = avctx->priv_data; unsigned int min_channels = 1; unsigned int max_channels = 2; switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_DTK: case AV_CODEC_ID_ADPCM_EA: min_channels = 2; break; case AV_CODEC_ID_ADPCM_AFC: case AV_CODEC_ID_ADPCM_EA_R1: case AV_CODEC_ID_ADPCM_EA_R2: case AV_CODEC_ID_ADPCM_EA_R3: case AV_CODEC_ID_ADPCM_EA_XAS: max_channels = 6; break; case AV_CODEC_ID_ADPCM_THP: case AV_CODEC_ID_ADPCM_THP_LE: max_channels = 10; break; } if (avctx->channels < min_channels || avctx->channels > max_channels) { av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); return AVERROR(EINVAL); } switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_CT: c->status[0].step = c->status[1].step = 511; break; case AV_CODEC_ID_ADPCM_IMA_WAV: if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5) return AVERROR_INVALIDDATA; break; case AV_CODEC_ID_ADPCM_IMA_APC: if (avctx->extradata && avctx->extradata_size >= 8) { c->status[0].predictor = AV_RL32(avctx->extradata); c->status[1].predictor = AV_RL32(avctx->extradata + 4); } break; case AV_CODEC_ID_ADPCM_IMA_WS: if (avctx->extradata && avctx->extradata_size >= 2) c->vqa_version = AV_RL16(avctx->extradata); break; default: break; } switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_IMA_QT: case AV_CODEC_ID_ADPCM_IMA_WAV: case AV_CODEC_ID_ADPCM_4XM: case AV_CODEC_ID_ADPCM_XA: case AV_CODEC_ID_ADPCM_EA_R1: case AV_CODEC_ID_ADPCM_EA_R2: case AV_CODEC_ID_ADPCM_EA_R3: case AV_CODEC_ID_ADPCM_EA_XAS: case AV_CODEC_ID_ADPCM_THP: case AV_CODEC_ID_ADPCM_THP_LE: case AV_CODEC_ID_ADPCM_AFC: case AV_CODEC_ID_ADPCM_DTK: avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break; case AV_CODEC_ID_ADPCM_IMA_WS: avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P : AV_SAMPLE_FMT_S16; break; default: avctx->sample_fmt = AV_SAMPLE_FMT_S16; } return 0; }


static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame) { TestSourceContext *s = ctx->priv; FFDrawColor color; unsigned alpha = (uint32_t)s->alpha << 24; /* colored background */ { unsigned i, x = 0, x2; x = 0; for (i = 1; i < 7; i++) { x2 = av_rescale(i, s->w, 6); x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2); set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) | ((i & 2) ? 0x00FF00 : 0) | ((i & 4) ? 0x0000FF : 0) | alpha); ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x, 0, x2 - x, frame->height); x = x2; } } /* oblique gradient */ /* note: too slow if using blending */ if (s->h >= 64) { unsigned x, dx, y0, y, g0, g; dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1); y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16)); g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128)); for (x = 0; x < s->w; x += dx) { g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256); set_color(s, &color, color_gradient(g) | alpha); y = y0 + av_rescale(x, s->h / 2, s->w); y %= 2 * (s->h - 16); if (y > s->h - 16) y = 2 * (s->h - 16) - y; y = ff_draw_round_to_sub(&s->draw, 1, 0, y); ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x, y, dx, 16); } } /* top right: draw clock hands */ if (s->w >= 64 && s->h >= 64) { int l = (FFMIN(s->w, s->h) - 32) >> 1; int steps = FFMAX(4, l >> 5); int xc = (s->w >> 2) + (s->w >> 1); int yc = (s->h >> 2); int cycle = l << 2; int pos, xh, yh; int c, i; for (c = 0; c < 3; c++) { set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha); pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle; xh = pos < 1 * l ? pos : pos < 2 * l ? l : pos < 3 * l ? 3 * l - pos : 0; yh = pos < 1 * l ? 0 : pos < 2 * l ? pos - l : pos < 3 * l ? l : cycle - pos; xh -= l >> 1; yh -= l >> 1; for (i = 1; i <= steps; i++) { int x = av_rescale(xh, i, steps) + xc; int y = av_rescale(yh, i, steps) + yc; x = ff_draw_round_to_sub(&s->draw, 0, -1, x); y = ff_draw_round_to_sub(&s->draw, 1, -1, y); ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x, y, 8, 8); } } } /* bottom left: beating rectangles */ if (s->w >= 64 && s->h >= 64) { int l = (FFMIN(s->w, s->h) - 16) >> 2; int cycle = l << 3; int xc = (s->w >> 2); int yc = (s->h >> 2) + (s->h >> 1); int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8); int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8); int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8); int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8); int size, step, x1, x2, y1, y2; size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle)); step = size / l; size %= l; if (step & 1) size = l - size; step = (step >> 1) & 3; set_color(s, &color, 0xFF808080); x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size); x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size); y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size); y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size); if (step == 0 || step == 2) ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x1, ym1, x2 - x1, ym2 - ym1); if (step == 1 || step == 2) ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, xm1, y1, xm2 - xm1, y2 - y1); if (step == 3) ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x1, y1, x2 - x1, y2 - y1); } /* bottom right: checker with random noise */ { unsigned xmin = av_rescale(5, s->w, 8); unsigned xmax = av_rescale(7, s->w, 8); unsigned ymin = av_rescale(5, s->h, 8); unsigned ymax = av_rescale(7, s->h, 8); unsigned x, y, i, r; uint8_t alpha[256]; r = s->pts; for (y = ymin; y < ymax - 15; y += 16) { for (x = xmin; x < xmax - 15; x += 16) { if ((x ^ y) & 16) continue; for (i = 0; i < 256; i++) { r = r * 1664525 + 1013904223; alpha[i] = r >> 24; } set_color(s, &color, 0xFF00FF80); ff_blend_mask(&s->draw, &color, frame->data, frame->linesize, frame->width, frame->height, alpha, 16, 16, 16, 3, 0, x, y); } } } /* bouncing square */ if (s->w >= 16 && s->h >= 16) { unsigned w = s->w - 8; unsigned h = s->h - 8; unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1); unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1); if (x > w) x = (w << 1) - x; if (y > h) y = (h << 1) - y; x = ff_draw_round_to_sub(&s->draw, 0, -1, x); y = ff_draw_round_to_sub(&s->draw, 1, -1, y); set_color(s, &color, 0xFF8000FF); ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x, y, 8, 8); } /* top right: draw frame time and frame number */ { char buf[256]; unsigned time; time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000; set_color(s, &color, 0xC0000000); ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize, frame->width, frame->height, 2, 2, 100, 36); set_color(s, &color, 0xFFFF8000); snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64, time / 3600000, (time / 60000) % 60, (time / 1000) % 60, time % 1000, s->pts); draw_text(s, frame, &color, 4, 4, buf); } }


static int iv_decode_frame(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { Indeo3DecodeContext *s = avctx->priv_data; unsigned int image_width, image_height, chroma_width, chroma_height; unsigned long flags, cb_offset, data_size, y_offset, v_offset, u_offset, mc_vector_count; const uint8_t *hdr_pos, *buf_pos; buf_pos = buf; buf_pos += 18; /* skip OS header (16 bytes) and version number */ flags = bytestream_get_le16(&buf_pos); data_size = bytestream_get_le32(&buf_pos); cb_offset = *buf_pos++; buf_pos += 3; /* skip reserved byte and checksum */ image_height = bytestream_get_le16(&buf_pos); image_width = bytestream_get_le16(&buf_pos); if(avcodec_check_dimensions(avctx, image_width, image_height)) return -1; chroma_height = ((image_height >> 2) + 3) & 0x7ffc; chroma_width = ((image_width >> 2) + 3) & 0x7ffc; y_offset = bytestream_get_le32(&buf_pos); v_offset = bytestream_get_le32(&buf_pos); u_offset = bytestream_get_le32(&buf_pos); buf_pos += 4; /* reserved */ hdr_pos = buf_pos; if(data_size == 0x80) return 4; if(FFMAX3(y_offset, v_offset, u_offset) >= buf_size-16) { av_log(s->avctx, AV_LOG_ERROR, "y/u/v offset outside buffer\n"); return -1; if(flags & 0x200) { s->cur_frame = s->iv_frame + 1; s->ref_frame = s->iv_frame; } else { s->cur_frame = s->iv_frame; s->ref_frame = s->iv_frame + 1; buf_pos = buf + 16 + y_offset; mc_vector_count = bytestream_get_le32(&buf_pos); if(2LL*mc_vector_count >= buf_size-16-y_offset) { av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); return -1; iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, image_width, image_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, FFMIN(image_width, 160)); if (!(s->avctx->flags & CODEC_FLAG_GRAY)) { buf_pos = buf + 16 + v_offset; mc_vector_count = bytestream_get_le32(&buf_pos); if(2LL*mc_vector_count >= buf_size-16-v_offset) { av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); return -1; iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width, chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, FFMIN(chroma_width, 40)); buf_pos = buf + 16 + u_offset; mc_vector_count = bytestream_get_le32(&buf_pos); if(2LL*mc_vector_count >= buf_size-16-u_offset) { av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); return -1; iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width, chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, FFMIN(chroma_width, 40)); return 8;


static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) { int ret = 0; /* apply the output bitstream filters, if any */ if (ost->nb_bitstream_filters) { int idx; ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt); if (ret < 0) goto finish; idx = 1; while (idx) { /* get a packet from the previous filter up the chain */ ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt); /* HACK! - aac_adtstoasc updates extradata after filtering the first frame when * the api states this shouldn't happen after init(). Propagate it here to the * muxer and to the next filters in the chain to workaround this. * TODO/FIXME - Make aac_adtstoasc use new packet side data instead of changing * par_out->extradata and adapt muxers accordingly to get rid of this. */ if (!(ost->bsf_extradata_updated[idx - 1] & 1)) { ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out); if (ret < 0) goto finish; ost->bsf_extradata_updated[idx - 1] |= 1; } if (ret == AVERROR(EAGAIN)) { ret = 0; idx--; continue; } else if (ret < 0) goto finish; /* send it to the next filter down the chain or to the muxer */ if (idx < ost->nb_bitstream_filters) { /* HACK/FIXME! - See above */ if (!(ost->bsf_extradata_updated[idx] & 2)) { ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out); if (ret < 0) goto finish; ost->bsf_extradata_updated[idx] |= 2; } ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt); if (ret < 0) goto finish; idx++; } else write_packet(of, pkt, ost); } } else write_packet(of, pkt, ost); finish: if (ret < 0 && ret != AVERROR_EOF) { av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output " "packet for stream #%d:%d.\n", ost->file_index, ost->index); if(exit_on_error) exit_program(1); } }


static void audio_pp_nb_voices (const char *typ, int nb) { switch (nb) { case 0: printf ("Does not support %s\n", typ); break; case 1: printf ("One %s voice\n", typ); break; case INT_MAX: printf ("Theoretically supports many %s voices\n", typ); break; default: printf ("Theoretically supports upto %d %s voices\n", nb, typ); break; } }


int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) { RTSPState *rt = s->priv_data; int ret, len; RTSPStream *rtsp_st, *first_queue_st = NULL; int64_t wait_end = 0; if (rt->nb_byes == rt->nb_rtsp_streams) return AVERROR_EOF; /* get next frames from the same RTP packet */ if (rt->cur_transport_priv) { if (rt->transport == RTSP_TRANSPORT_RDT) { ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); } else if (rt->transport == RTSP_TRANSPORT_RTP) { ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); } else if (rt->ts && CONFIG_RTPDEC) { ret = ff_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf + rt->recvbuf_pos, rt->recvbuf_len - rt->recvbuf_pos); if (ret >= 0) { rt->recvbuf_pos += ret; ret = rt->recvbuf_pos < rt->recvbuf_len; } } else ret = -1; if (ret == 0) { rt->cur_transport_priv = NULL; return 0; } else if (ret == 1) { return 0; } else rt->cur_transport_priv = NULL; } redo: if (rt->transport == RTSP_TRANSPORT_RTP) { int i; int64_t first_queue_time = 0; for (i = 0; i < rt->nb_rtsp_streams; i++) { RTPDemuxContext *rtpctx = rt->rtsp_streams[i]->transport_priv; int64_t queue_time; if (!rtpctx) continue; queue_time = ff_rtp_queued_packet_time(rtpctx); if (queue_time && (queue_time - first_queue_time < 0 || !first_queue_time)) { first_queue_time = queue_time; first_queue_st = rt->rtsp_streams[i]; } } if (first_queue_time) { wait_end = first_queue_time + s->max_delay; } else { wait_end = 0; first_queue_st = NULL; } } /* read next RTP packet */ if (!rt->recvbuf) { rt->recvbuf = av_malloc(RECVBUF_SIZE); if (!rt->recvbuf) return AVERROR(ENOMEM); } switch(rt->lower_transport) { default: #if CONFIG_RTSP_DEMUXER case RTSP_LOWER_TRANSPORT_TCP: len = ff_rtsp_tcp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE); break; #endif case RTSP_LOWER_TRANSPORT_UDP: case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end); if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, rtsp_st->rtp_handle, NULL, len); break; case RTSP_LOWER_TRANSPORT_CUSTOM: if (first_queue_st && rt->transport == RTSP_TRANSPORT_RTP && wait_end && wait_end < av_gettime_relative()) len = AVERROR(EAGAIN); else len = ffio_read_partial(s->pb, rt->recvbuf, RECVBUF_SIZE); len = pick_stream(s, &rtsp_st, rt->recvbuf, len); if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, NULL, s->pb, len); break; } if (len == AVERROR(EAGAIN) && first_queue_st && rt->transport == RTSP_TRANSPORT_RTP) { rtsp_st = first_queue_st; ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0); goto end; } if (len < 0) return len; if (len == 0) return AVERROR_EOF; if (rt->transport == RTSP_TRANSPORT_RDT) { ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); } else if (rt->transport == RTSP_TRANSPORT_RTP) { ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); if (rtsp_st->feedback) { AVIOContext *pb = NULL; if (rt->lower_transport == RTSP_LOWER_TRANSPORT_CUSTOM) pb = s->pb; ff_rtp_send_rtcp_feedback(rtsp_st->transport_priv, rtsp_st->rtp_handle, pb); } if (ret < 0) { /* Either bad packet, or a RTCP packet. Check if the * first_rtcp_ntp_time field was initialized. */ RTPDemuxContext *rtpctx = rtsp_st->transport_priv; if (rtpctx->first_rtcp_ntp_time != AV_NOPTS_VALUE) { /* first_rtcp_ntp_time has been initialized for this stream, * copy the same value to all other uninitialized streams, * in order to map their timestamp origin to the same ntp time * as this one. */ int i; AVStream *st = NULL; if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; for (i = 0; i < rt->nb_rtsp_streams; i++) { RTPDemuxContext *rtpctx2 = rt->rtsp_streams[i]->transport_priv; AVStream *st2 = NULL; if (rt->rtsp_streams[i]->stream_index >= 0) st2 = s->streams[rt->rtsp_streams[i]->stream_index]; if (rtpctx2 && st && st2 && rtpctx2->first_rtcp_ntp_time == AV_NOPTS_VALUE) { rtpctx2->first_rtcp_ntp_time = rtpctx->first_rtcp_ntp_time; rtpctx2->rtcp_ts_offset = av_rescale_q( rtpctx->rtcp_ts_offset, st->time_base, st2->time_base); } } } if (ret == -RTCP_BYE) { rt->nb_byes++; av_log(s, AV_LOG_DEBUG, "Received BYE for stream %d (%d/%d)\n", rtsp_st->stream_index, rt->nb_byes, rt->nb_rtsp_streams); if (rt->nb_byes == rt->nb_rtsp_streams) return AVERROR_EOF; } } } else if (rt->ts && CONFIG_RTPDEC) { ret = ff_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf, len); if (ret >= 0) { if (ret < len) { rt->recvbuf_len = len; rt->recvbuf_pos = ret; rt->cur_transport_priv = rt->ts; return 1; } else { ret = 0; } } } else { return AVERROR_INVALIDDATA; } end: if (ret < 0) goto redo; if (ret == 1) /* more packets may follow, so we save the RTP context */ rt->cur_transport_priv = rtsp_st->transport_priv; return ret; }


static void assign_failed_examine(AssignedDevice *dev) { char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns; uint16_t vendor_id, device_id; int r; snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/", dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function); snprintf(name, sizeof(name), "%sdriver", dir); r = readlink(name, driver, sizeof(driver)); if ((r <= 0) || r >= sizeof(driver)) { goto fail; } ns = strrchr(driver, '/'); if (!ns) { goto fail; } ns++; if (get_real_vendor_id(dir, &vendor_id) || get_real_device_id(dir, &device_id)) { goto fail; } error_printf("*** The driver '%s' is occupying your device " "%04x:%02x:%02x.%x.\n" "***\n" "*** You can try the following commands to free it:\n" "***\n" "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/new_id\n" "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/%s/unbind\n" "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/" "pci-stub/bind\n" "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/remove_id\n" "***", ns, dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function, vendor_id, device_id, dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function, ns, dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function, vendor_id, device_id); return; fail: error_report("Couldn't find out why."); }


av_cold void ff_h264_free_context(H264Context *h) { int i; free_tables(h); //FIXME cleanup init stuff perhaps for(i = 0; i < MAX_SPS_COUNT; i++) av_freep(h->sps_buffers + i); for(i = 0; i < MAX_PPS_COUNT; i++) av_freep(h->pps_buffers + i); }


static int nbd_co_receive_request(NBDRequest *req, struct nbd_request *request) { NBDClient *client = req->client; int csock = client->sock; int rc; client->recv_coroutine = qemu_coroutine_self(); if (nbd_receive_request(csock, request) == -1) { rc = -EIO; goto out; } if (request->len > NBD_BUFFER_SIZE) { LOG("len (%u) is larger than max len (%u)", request->len, NBD_BUFFER_SIZE); rc = -EINVAL; goto out; } if ((request->from + request->len) < request->from) { LOG("integer overflow detected! " "you're probably being attacked"); rc = -EINVAL; goto out; } TRACE("Decoding type"); if ((request->type & NBD_CMD_MASK_COMMAND) == NBD_CMD_WRITE) { TRACE("Reading %u byte(s)", request->len); if (qemu_co_recv(csock, req->data, request->len) != request->len) { LOG("reading from socket failed"); rc = -EIO; goto out; } } rc = 0; out: client->recv_coroutine = NULL; return rc; }


static inline int hpel_motion(MpegEncContext *s, uint8_t *dest, uint8_t *src, int src_x, int src_y, op_pixels_func *pix_op, int motion_x, int motion_y) { int dxy = 0; int emu = 0; src_x += motion_x >> 1; src_y += motion_y >> 1; /* WARNING: do no forget half pels */ src_x = av_clip(src_x, -16, s->width); // FIXME unneeded for emu? if (src_x != s->width) dxy |= motion_x & 1; src_y = av_clip(src_y, -16, s->height); if (src_y != s->height) dxy |= (motion_y & 1) << 1; src += src_y * s->linesize + src_x; if (s->unrestricted_mv) { if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) { s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src, s->linesize, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); src = s->sc.edge_emu_buffer; emu = 1; } } pix_op[dxy](dest, src, s->linesize, 8); return emu; }


static void inline xan_wc3_copy_pixel_run(XanContext *s, int x, int y, int pixel_count, int motion_x, int motion_y) { int stride; int line_inc; int curframe_index, prevframe_index; int curframe_x, prevframe_x; int width = s->avctx->width; unsigned char *palette_plane, *prev_palette_plane; unsigned char *y_plane, *u_plane, *v_plane; unsigned char *prev_y_plane, *prev_u_plane, *prev_v_plane; unsigned char *rgb_plane, *prev_rgb_plane; unsigned short *rgb16_plane, *prev_rgb16_plane; unsigned int *rgb32_plane, *prev_rgb32_plane; switch (s->avctx->pix_fmt) { case PIX_FMT_PAL8: palette_plane = s->current_frame.data[0]; prev_palette_plane = s->last_frame.data[0]; stride = s->current_frame.linesize[0]; line_inc = stride - width; curframe_index = y * stride + x; curframe_x = x; prevframe_index = (y + motion_y) * stride + x + motion_x; prevframe_x = x + motion_x; while(pixel_count--) { palette_plane[curframe_index++] = prev_palette_plane[prevframe_index++]; ADVANCE_CURFRAME_X(); ADVANCE_PREVFRAME_X(); } break; case PIX_FMT_RGB555: case PIX_FMT_RGB565: rgb16_plane = (unsigned short *)s->current_frame.data[0]; prev_rgb16_plane = (unsigned short *)s->last_frame.data[0]; stride = s->current_frame.linesize[0] / 2; line_inc = stride - width; curframe_index = y * stride + x; curframe_x = x; prevframe_index = (y + motion_y) * stride + x + motion_x; prevframe_x = x + motion_x; while(pixel_count--) { rgb16_plane[curframe_index++] = prev_rgb16_plane[prevframe_index++]; ADVANCE_CURFRAME_X(); ADVANCE_PREVFRAME_X(); } break; case PIX_FMT_RGB24: case PIX_FMT_BGR24: rgb_plane = s->current_frame.data[0]; prev_rgb_plane = s->last_frame.data[0]; stride = s->current_frame.linesize[0]; line_inc = stride - width * 3; curframe_index = y * stride + x * 3; curframe_x = x; prevframe_index = (y + motion_y) * stride + (3 * (x + motion_x)); prevframe_x = x + motion_x; while(pixel_count--) { rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++]; rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++]; rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++]; ADVANCE_CURFRAME_X(); ADVANCE_PREVFRAME_X(); } break; case PIX_FMT_RGBA32: rgb32_plane = (unsigned int *)s->current_frame.data[0]; prev_rgb32_plane = (unsigned int *)s->last_frame.data[0]; stride = s->current_frame.linesize[0] / 4; line_inc = stride - width; curframe_index = y * stride + x; curframe_x = x; prevframe_index = (y + motion_y) * stride + x + motion_x; prevframe_x = x + motion_x; while(pixel_count--) { rgb32_plane[curframe_index++] = prev_rgb32_plane[prevframe_index++]; ADVANCE_CURFRAME_X(); ADVANCE_PREVFRAME_X(); } break; case PIX_FMT_YUV444P: y_plane = s->current_frame.data[0]; u_plane = s->current_frame.data[1]; v_plane = s->current_frame.data[2]; prev_y_plane = s->last_frame.data[0]; prev_u_plane = s->last_frame.data[1]; prev_v_plane = s->last_frame.data[2]; stride = s->current_frame.linesize[0]; line_inc = stride - width; curframe_index = y * stride + x; curframe_x = x; prevframe_index = (y + motion_y) * stride + x + motion_x; prevframe_x = x + motion_x; while(pixel_count--) { y_plane[curframe_index] = prev_y_plane[prevframe_index]; u_plane[curframe_index] = prev_u_plane[prevframe_index]; v_plane[curframe_index] = prev_v_plane[prevframe_index]; curframe_index++; ADVANCE_CURFRAME_X(); prevframe_index++; ADVANCE_PREVFRAME_X(); } break; default: av_log(s->avctx, AV_LOG_ERROR, " Xan WC3: Unhandled colorspace\n"); break; } }


static int set_format(void *obj, const char *name, int fmt, int search_flags, enum AVOptionType type, const char *desc, int nb_fmts) { void *target_obj; const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); int min, max; const AVClass *class = *(AVClass **)obj; if (!o || !target_obj) return AVERROR_OPTION_NOT_FOUND; if (o->type != type) { av_log(obj, AV_LOG_ERROR, "The value set by option '%s' is not a %s format", name, desc); return AVERROR(EINVAL); } #if LIBAVUTIL_VERSION_MAJOR < 54 if (class->version && class->version < AV_VERSION_INT(52, 11, 100)) { min = -1; max = nb_fmts-1; } else #endif { min = FFMIN(o->min, -1); max = FFMAX(o->max, nb_fmts-1); } if (fmt < min || fmt > max) { av_log(obj, AV_LOG_ERROR, "Value %d for parameter '%s' out of %s format range [%d - %d]\n", fmt, name, desc, min, max); return AVERROR(ERANGE); } *(int *)(((uint8_t *)target_obj) + o->offset) = fmt; return 0; }


void ff_put_h264_qpel4_mc01_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_vt_qrt_4w_msa(src - (stride * 2), stride, dst, stride, 4, 0); }


static void dump_cook_context(COOKContext *q, COOKextradata *e) { //int i=0; #define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b); av_log(NULL,AV_LOG_ERROR,"COOKextradata\n"); av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",e->cookversion); if (e->cookversion > MONO_COOK2) { PRINT("js_subband_start",e->js_subband_start); PRINT("js_vlc_bits",e->js_vlc_bits); } av_log(NULL,AV_LOG_ERROR,"COOKContext\n"); PRINT("nb_channels",q->nb_channels); PRINT("bit_rate",q->bit_rate); PRINT("sample_rate",q->sample_rate); PRINT("samples_per_channel",q->samples_per_channel); PRINT("samples_per_frame",q->samples_per_frame); PRINT("subbands",q->subbands); PRINT("random_state",q->random_state); PRINT("mlt_size",q->mlt_size); PRINT("js_subband_start",q->js_subband_start); PRINT("numvector_bits",q->numvector_bits); PRINT("numvector_size",q->numvector_size); PRINT("total_subbands",q->total_subbands); PRINT("frame_reorder_counter",q->frame_reorder_counter); PRINT("frame_reorder_index_size",q->frame_reorder_index_size); }


static void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size) { FFMContext *ffm = s->priv_data; ffm->write_index = pos; ffm->file_size = file_size; }


static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data) { USBDeviceClass *uc = USB_DEVICE_CLASS(klass); uc->realize = usb_msd_realize_bot; uc->attached_settable = true; }


uint64_t HELPER(get_cp_reg64)(CPUARMState *env, void *rip) { const ARMCPRegInfo *ri = rip; return ri->readfn(env, ri); }


static USBDevice *usb_try_create_simple(USBBus *bus, const char *name, Error **errp) { Error *err = NULL; USBDevice *dev; dev = USB_DEVICE(qdev_try_create(&bus->qbus, name)); if (!dev) { error_setg(errp, "Failed to create USB device '%s'", name); return NULL; } object_property_set_bool(OBJECT(dev), true, "realized", &err); if (err) { error_propagate(errp, err); error_prepend(errp, "Failed to initialize USB device '%s': ", name); object_unparent(OBJECT(dev)); return NULL; } return dev; }


static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int *got_output, const uint8_t *buf, int buf_size) { Mpeg1Context *s = avctx->priv_data; MpegEncContext *s2 = &s->mpeg_enc_ctx; const uint8_t *buf_ptr = buf; const uint8_t *buf_end = buf + buf_size; int ret, input_size; int last_code = 0; for (;;) { /* find next start code */ uint32_t start_code = -1; buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &start_code); if (start_code > 0x1ff) { if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) { if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) { int i; avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*)); for (i = 0; i < s->slice_count; i++) s2->error_count += s2->thread_context[i]->error_count; } if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count); if (slice_end(avctx, picture)) { if (s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice *got_output = 1; } } s2->pict_type = 0; return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); } input_size = buf_end - buf_ptr; if (avctx->debug & FF_DEBUG_STARTCODE) { av_log(avctx, AV_LOG_DEBUG, "%3X at %td left %d\n", start_code, buf_ptr-buf, input_size); } /* prepare data for next start code */ switch (start_code) { case SEQ_START_CODE: if (last_code == 0) { mpeg1_decode_sequence(avctx, buf_ptr, input_size); s->sync=1; } else { av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } break; case PICTURE_START_CODE: if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && s->slice_count) { int i; avctx->execute(avctx, slice_decode_thread, s2->thread_context, NULL, s->slice_count, sizeof(void*)); for (i = 0; i < s->slice_count; i++) s2->error_count += s2->thread_context[i]->error_count; s->slice_count = 0; } if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { ret = mpeg_decode_postinit(avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n"); return ret; } /* we have a complete image: we try to decompress it */ if (mpeg1_decode_picture(avctx, buf_ptr, input_size) < 0) s2->pict_type = 0; s2->first_slice = 1; last_code = PICTURE_START_CODE; } else { av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } break; case EXT_START_CODE: init_get_bits(&s2->gb, buf_ptr, input_size*8); switch (get_bits(&s2->gb, 4)) { case 0x1: if (last_code == 0) { mpeg_decode_sequence_extension(s); } else { av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } break; case 0x2: mpeg_decode_sequence_display_extension(s); break; case 0x3: mpeg_decode_quant_matrix_extension(s2); break; case 0x7: mpeg_decode_picture_display_extension(s); break; case 0x8: if (last_code == PICTURE_START_CODE) { mpeg_decode_picture_coding_extension(s); } else { av_log(avctx, AV_LOG_ERROR, "ignoring pic cod ext after %X\n", last_code); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } break; } break; case USER_START_CODE: mpeg_decode_user_data(avctx, buf_ptr, input_size); break; case GOP_START_CODE: if (last_code == 0) { s2->first_field=0; mpeg_decode_gop(avctx, buf_ptr, input_size); s->sync=1; } else { av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } break; default: if (start_code >= SLICE_MIN_START_CODE && start_code <= SLICE_MAX_START_CODE && last_code != 0) { const int field_pic = s2->picture_structure != PICT_FRAME; int mb_y = (start_code - SLICE_MIN_START_CODE) << field_pic; last_code = SLICE_MIN_START_CODE; if (s2->picture_structure == PICT_BOTTOM_FIELD) mb_y++; if (mb_y >= s2->mb_height) { av_log(s2->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s2->mb_height); return -1; } if (s2->last_picture_ptr == NULL) { /* Skip B-frames if we do not have reference frames and gop is not closed */ if (s2->pict_type == AV_PICTURE_TYPE_B) { if (!s->closed_gop) break; } } if (s2->pict_type == AV_PICTURE_TYPE_I) s->sync=1; if (s2->next_picture_ptr == NULL) { /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) break; } if ((avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type == AV_PICTURE_TYPE_B) || (avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type != AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) break; if (!s->mpeg_enc_ctx_allocated) break; if (s2->codec_id == AV_CODEC_ID_MPEG2VIDEO) { if (mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom) break; } if (!s2->pict_type) { av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n"); if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; break; } if (s2->first_slice) { s2->first_slice = 0; if (mpeg_field_start(s2, buf, buf_size) < 0) return -1; } if (!s2->current_picture_ptr) { av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n"); return AVERROR_INVALIDDATA; } if (avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) { s->slice_count++; break; } if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) { int threshold = (s2->mb_height * s->slice_count + s2->slice_context_count / 2) / s2->slice_context_count; if (threshold <= mb_y) { MpegEncContext *thread_context = s2->thread_context[s->slice_count]; thread_context->start_mb_y = mb_y; thread_context->end_mb_y = s2->mb_height; if (s->slice_count) { s2->thread_context[s->slice_count-1]->end_mb_y = mb_y; ff_update_duplicate_context(thread_context, s2); } init_get_bits(&thread_context->gb, buf_ptr, input_size*8); s->slice_count++; } buf_ptr += 2; // FIXME add minimum number of bytes per slice } else { ret = mpeg_decode_slice(s2, mb_y, &buf_ptr, input_size); emms_c(); if (ret < 0) { if (avctx->err_recognition & AV_EF_EXPLODE) return ret; if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0) ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); } else { ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); } } } break; } } }


static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n) { int level, diff, i, j, run; int component; RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable = a->scantable.permutated; const uint16_t *quant_matrix = ff_mpeg1_default_intra_matrix; const int qscale = a->qscale; /* DC coefficient */ if (a->version == 2) { block[0] = 2 * get_sbits(&a->gb, 10) + 1024; } else { component = (n <= 3 ? 0 : n - 4 + 1); diff = decode_dc(&a->gb, component); if (diff >= 0xffff) return AVERROR_INVALIDDATA; a->last_dc[component] += diff; block[0] = a->last_dc[component] << 3; } i = 0; { OPEN_READER(re, &a->gb); /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &a->gb); GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); if (level == 127) { break; } else if (level != 0) { i += run; if (i > 63) { av_log(a->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", a->mb_x, a->mb_y); return AVERROR_INVALIDDATA; } j = scantable[i]; level = (level * qscale * quant_matrix[j]) >> 3; level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1); LAST_SKIP_BITS(re, &a->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6); UPDATE_CACHE(re, &a->gb); level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10); i += run; if (i > 63) { av_log(a->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", a->mb_x, a->mb_y); return AVERROR_INVALIDDATA; } j = scantable[i]; if (level < 0) { level = -level; level = (level * qscale * quant_matrix[j]) >> 3; level = (level - 1) | 1; level = -level; } else { level = (level * qscale * quant_matrix[j]) >> 3; level = (level - 1) | 1; } } block[j] = level; } CLOSE_READER(re, &a->gb); } a->block_last_index[n] = i; return 0; }


static int raw_open_common(BlockDriverState *bs, QDict *options, int bdrv_flags, int open_flags, Error **errp) { BDRVRawState *s = bs->opaque; QemuOpts *opts; Error *local_err = NULL; const char *filename = NULL; const char *str; BlockdevAioOptions aio, aio_default; int fd, ret; struct stat st; OnOffAuto locking; opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); filename = qemu_opt_get(opts, "filename"); ret = raw_normalize_devicepath(&filename); if (ret != 0) { error_setg_errno(errp, -ret, "Could not normalize device path"); aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE : BLOCKDEV_AIO_OPTIONS_THREADS; aio = qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), aio_default, &local_err); s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE); locking = qapi_enum_parse(&OnOffAuto_lookup, qemu_opt_get(opts, "locking"), ON_OFF_AUTO_AUTO, &local_err); switch (locking) { case ON_OFF_AUTO_ON: s->use_lock = true; if (!qemu_has_ofd_lock()) { fprintf(stderr, "File lock requested but OFD locking syscall is " "unavailable, falling back to POSIX file locks.\n" "Due to the implementation, locks can be lost " "unexpectedly.\n"); break; case ON_OFF_AUTO_OFF: s->use_lock = false; break; case ON_OFF_AUTO_AUTO: s->use_lock = qemu_has_ofd_lock(); break; default: abort(); s->open_flags = open_flags; raw_parse_flags(bdrv_flags, &s->open_flags); s->fd = -1; fd = qemu_open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not open '%s'", filename); if (ret == -EROFS) { ret = -EACCES; s->fd = fd; s->lock_fd = -1; if (s->use_lock) { fd = qemu_open(filename, s->open_flags); if (fd < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not open '%s' for locking", filename); qemu_close(s->fd); s->lock_fd = fd; s->perm = 0; s->shared_perm = BLK_PERM_ALL; #ifdef CONFIG_LINUX_AIO /* Currently Linux does AIO only for files opened with O_DIRECT */ if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) { error_setg(errp, "aio=native was specified, but it requires " "cache.direct=on, which was not specified."); #else if (s->use_linux_aio) { error_setg(errp, "aio=native was specified, but is not supported " "in this build."); #endif /* !defined(CONFIG_LINUX_AIO) */ s->has_discard = true; s->has_write_zeroes = true; bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP; if ((bs->open_flags & BDRV_O_NOCACHE) != 0) { s->needs_alignment = true; if (fstat(s->fd, &st) < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not stat file"); if (S_ISREG(st.st_mode)) { s->discard_zeroes = true; s->has_fallocate = true; if (S_ISBLK(st.st_mode)) { #ifdef BLKDISCARDZEROES unsigned int arg; if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) { s->discard_zeroes = true; #endif #ifdef __linux__ /* On Linux 3.10, BLKDISCARD leaves stale data in the page cache. Do * not rely on the contents of discarded blocks unless using O_DIRECT. * Same for BLKZEROOUT. */ if (!(bs->open_flags & BDRV_O_NOCACHE)) { s->discard_zeroes = false; s->has_write_zeroes = false; #endif #ifdef __FreeBSD__ if (S_ISCHR(st.st_mode)) { /* * The file is a char device (disk), which on FreeBSD isn't behind * a pager, so force all requests to be aligned. This is needed * so QEMU makes sure all IO operations on the device are aligned * to sector size, or else FreeBSD will reject them with EINVAL. */ s->needs_alignment = true; #endif #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) { s->is_xfs = true; #endif ret = 0; fail: if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) { unlink(filename); qemu_opts_del(opts); return ret;


av_cold int ff_vp8_decode_init(AVCodecContext *avctx) { VP8Context *s = avctx->priv_data; int ret; s->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_YUV420P; avctx->internal->allocate_progress = 1; ff_videodsp_init(&s->vdsp, 8); ff_h264_pred_init(&s->hpc, AV_CODEC_ID_VP8, 8, 1); ff_vp8dsp_init(&s->vp8dsp); if ((ret = vp8_init_frames(s)) < 0) { ff_vp8_decode_free(avctx); return ret; } return 0; }


static inline void json_print_item_str(WriterContext *wctx, const char *key, const char *value, const char *indent) { char *key_esc = json_escape_str(key); char *value_esc = json_escape_str(value); printf("%s\"%s\": \"%s\"", indent, key_esc ? key_esc : "", value_esc ? value_esc : ""); av_free(key_esc); av_free(value_esc); }


static void handle_keydown(SDL_Event *ev) { int mod_state, win; struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); if (alt_grab) { mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) == (gui_grab_code | KMOD_LSHIFT); } else if (ctrl_grab) { mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL; } else { mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code; gui_key_modifier_pressed = mod_state; if (gui_key_modifier_pressed) { switch (ev->key.keysym.scancode) { case SDL_SCANCODE_2: case SDL_SCANCODE_3: case SDL_SCANCODE_4: case SDL_SCANCODE_5: case SDL_SCANCODE_6: case SDL_SCANCODE_7: case SDL_SCANCODE_8: case SDL_SCANCODE_9: win = ev->key.keysym.scancode - SDL_SCANCODE_1; if (win < sdl2_num_outputs) { sdl2_console[win].hidden = !sdl2_console[win].hidden; if (sdl2_console[win].real_window) { if (sdl2_console[win].hidden) { SDL_HideWindow(sdl2_console[win].real_window); } else { SDL_ShowWindow(sdl2_console[win].real_window); gui_keysym = 1; break; case SDL_SCANCODE_F: toggle_full_screen(scon); gui_keysym = 1; break; case SDL_SCANCODE_U: sdl2_window_destroy(scon); sdl2_window_create(scon); if (!scon->opengl) { /* re-create scon->texture */ sdl2_2d_switch(&scon->dcl, scon->surface); gui_keysym = 1; break; #if 0 case SDL_SCANCODE_KP_PLUS: case SDL_SCANCODE_KP_MINUS: if (!gui_fullscreen) { int scr_w, scr_h; int width, height; SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); width = MAX(scr_w + (ev->key.keysym.scancode == SDL_SCANCODE_KP_PLUS ? 50 : -50), 160); height = (surface_height(scon->surface) * width) / surface_width(scon->surface); fprintf(stderr, "%s: scale to %dx%d\n", __func__, width, height); sdl_scale(scon, width, height); sdl2_redraw(scon); gui_keysym = 1; #endif default: break; if (!gui_keysym) { sdl2_process_key(scon, &ev->key);


AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission) { AVRational q; int j; if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { q = (AVRational){1, st->codec->sample_rate}; } else { q = st->codec->time_base; } for (j=2; j<2000; j+= 1+(j>2)) while (q.den / q.num < min_precission && q.num % j == 0) q.num /= j; while (q.den / q.num < min_precission && q.den < (1<<24)) q.den <<= 1; return q; }


static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { PCMDecode *s = avctx->priv_data; int c, n; short *samples; uint8_t *src, *src2[MAX_CHANNELS]; samples = data; src = buf; n= av_get_bits_per_sample(avctx->codec_id)/8; if((n && buf_size % n) || avctx->channels > MAX_CHANNELS){ av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n"); return -1; } buf_size= FFMIN(buf_size, *data_size/2); *data_size=0; n = buf_size/avctx->channels; for(c=0;c<avctx->channels;c++) src2[c] = &src[c*n]; switch(avctx->codec->id) { case CODEC_ID_PCM_S32LE: decode_to16(4, 1, 0, &src, &samples, buf_size); break; case CODEC_ID_PCM_S32BE: decode_to16(4, 0, 0, &src, &samples, buf_size); break; case CODEC_ID_PCM_U32LE: decode_to16(4, 1, 1, &src, &samples, buf_size); break; case CODEC_ID_PCM_U32BE: decode_to16(4, 0, 1, &src, &samples, buf_size); break; case CODEC_ID_PCM_S24LE: decode_to16(3, 1, 0, &src, &samples, buf_size); break; case CODEC_ID_PCM_S24BE: decode_to16(3, 0, 0, &src, &samples, buf_size); break; case CODEC_ID_PCM_U24LE: decode_to16(3, 1, 1, &src, &samples, buf_size); break; case CODEC_ID_PCM_U24BE: decode_to16(3, 0, 1, &src, &samples, buf_size); break; case CODEC_ID_PCM_S24DAUD: n = buf_size / 3; for(;n>0;n--) { uint32_t v = bytestream_get_be24(&src); v >>= 4; // sync flags are here *samples++ = ff_reverse[(v >> 8) & 0xff] + (ff_reverse[v & 0xff] << 8); } break; case CODEC_ID_PCM_S16LE: n = buf_size >> 1; for(;n>0;n--) { *samples++ = bytestream_get_le16(&src); } break; case CODEC_ID_PCM_S16LE_PLANAR: for(n>>=1;n>0;n--) for(c=0;c<avctx->channels;c++) *samples++ = bytestream_get_le16(&src2[c]); src = src2[avctx->channels-1]; break; case CODEC_ID_PCM_S16BE: n = buf_size >> 1; for(;n>0;n--) { *samples++ = bytestream_get_be16(&src); } break; case CODEC_ID_PCM_U16LE: n = buf_size >> 1; for(;n>0;n--) { *samples++ = bytestream_get_le16(&src) - 0x8000; } break; case CODEC_ID_PCM_U16BE: n = buf_size >> 1; for(;n>0;n--) { *samples++ = bytestream_get_be16(&src) - 0x8000; } break; case CODEC_ID_PCM_S8: n = buf_size; for(;n>0;n--) { *samples++ = *src++ << 8; } break; case CODEC_ID_PCM_U8: n = buf_size; for(;n>0;n--) { *samples++ = ((int)*src++ - 128) << 8; } break; case CODEC_ID_PCM_ZORK: n = buf_size; for(;n>0;n--) { int x= *src++; if(x&128) x-= 128; else x = -x; *samples++ = x << 8; } break; case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: n = buf_size; for(;n>0;n--) { *samples++ = s->table[*src++]; } break; default: return -1; } *data_size = (uint8_t *)samples - (uint8_t *)data; return src - buf; }


static int h264_slice_init(H264Context *h, H264SliceContext *sl, const H2645NAL *nal) { int i, j, ret = 0; if (h->picture_idr && nal->type != H264_NAL_IDR_SLICE) { av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of IDR and non-IDR slices\n"); return AVERROR_INVALIDDATA; } av_assert1(h->mb_num == h->mb_width * h->mb_height); if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || sl->first_mb_addr >= h->mb_num) { av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return AVERROR_INVALIDDATA; } sl->resync_mb_x = sl->mb_x = sl->first_mb_addr % h->mb_width; sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) << FIELD_OR_MBAFF_PICTURE(h); if (h->picture_structure == PICT_BOTTOM_FIELD) sl->resync_mb_y = sl->mb_y = sl->mb_y + 1; av_assert1(sl->mb_y < h->mb_height); ret = ff_h264_build_ref_list(h, sl); if (ret < 0) return ret; if (h->ps.pps->weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, -1); if (FRAME_MBAFF(h)) { implicit_weight_table(h, sl, 0); implicit_weight_table(h, sl, 1); } } if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) ff_h264_direct_dist_scale_factor(h, sl); ff_h264_direct_ref_list_init(h, sl); if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->nal_unit_type != H264_NAL_IDR_SLICE) || (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && nal->ref_idc == 0)) sl->deblocking_filter = 0; if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) { if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) { /* Cheat slightly for speed: * Do not bother to deblock across slices. */ sl->deblocking_filter = 2; } else { h->postpone_filter = 1; } } sl->qp_thresh = 15 - FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) - FFMAX3(0, h->ps.pps->chroma_qp_index_offset[0], h->ps.pps->chroma_qp_index_offset[1]) + 6 * (h->ps.sps->bit_depth_luma - 8); sl->slice_num = ++h->current_slice; if (sl->slice_num) h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y; if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y && sl->slice_num >= MAX_SLICES) { //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES); } for (j = 0; j < 2; j++) { int id_list[16]; int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; for (i = 0; i < 16; i++) { id_list[i] = 60; if (j < sl->list_count && i < sl->ref_count[j] && sl->ref_list[j][i].parent->f->buf[0]) { int k; AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer; for (k = 0; k < h->short_ref_count; k++) if (h->short_ref[k]->f->buf[0]->buffer == buf) { id_list[i] = k; break; } for (k = 0; k < h->long_ref_count; k++) if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) { id_list[i] = h->short_ref_count + k; break; } } } ref2frm[0] = ref2frm[1] = -1; for (i = 0; i < 16; i++) ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); ref2frm[18 + 0] = ref2frm[18 + 1] = -1; for (i = 16; i < 48; i++) ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + (sl->ref_list[j][i].reference & 3); } if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", sl->slice_num, (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"), sl->mb_y * h->mb_width + sl->mb_x, av_get_picture_type_char(sl->slice_type), sl->slice_type_fixed ? " fix" : "", nal->type == H264_NAL_IDR_SLICE ? " IDR" : "", h->poc.frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], sl->ref_count[0], sl->ref_count[1], sl->qscale, sl->deblocking_filter, sl->slice_alpha_c0_offset, sl->slice_beta_offset, sl->pwt.use_weight, sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "", sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); } return 0; }


RockerSwitch *qmp_query_rocker(const char *name, Error **errp) { RockerSwitch *rocker = g_malloc0(sizeof(*rocker)); Rocker *r; r = rocker_find(name); if (!r) { error_set(errp, ERROR_CLASS_GENERIC_ERROR, "rocker %s not found", name); return NULL; } rocker->name = g_strdup(r->name); rocker->id = r->switch_id; rocker->ports = r->fp_ports; return rocker; }


static int init_dimensions(H264Context *h) { int width = h->width - (h->sps.crop_right + h->sps.crop_left); int height = h->height - (h->sps.crop_top + h->sps.crop_bottom); /* handle container cropping */ if (FFALIGN(h->avctx->width, 16) == FFALIGN(width, 16) && FFALIGN(h->avctx->height, 16) == FFALIGN(height, 16)) { width = h->avctx->width; height = h->avctx->height; } if (width <= 0 || height <= 0) { av_log(h->avctx, AV_LOG_ERROR, "Invalid cropped dimensions: %dx%d.\n", width, height); if (h->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; av_log(h->avctx, AV_LOG_WARNING, "Ignoring cropping information.\n"); h->sps.crop_bottom = h->sps.crop_top = h->sps.crop_right = h->sps.crop_left = h->sps.crop = 0; width = h->width; height = h->height; } h->avctx->coded_width = h->width; h->avctx->coded_height = h->height; h->avctx->width = width; h->avctx->height = height; return 0; }


static inline CopyRet copy_frame(AVCodecContext *avctx, BC_DTS_PROC_OUT *output, void *data, int *data_size, uint8_t second_field) { BC_STATUS ret; BC_DTS_STATUS decoder_status; uint8_t is_paff; uint8_t next_frame_same; uint8_t interlaced; CHDContext *priv = avctx->priv_data; int64_t pkt_pts = AV_NOPTS_VALUE; uint8_t pic_type = 0; uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) == VDEC_FLAG_BOTTOMFIELD; uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST); int width = output->PicInfo.width; int height = output->PicInfo.height; int bwidth; uint8_t *src = output->Ybuff; int sStride; uint8_t *dst; int dStride; if (output->PicInfo.timeStamp != 0) { OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp); if (node) { pkt_pts = node->reordered_opaque; pic_type = node->pic_type; av_free(node); } else { /* * We will encounter a situation where a timestamp cannot be * popped if a second field is being returned. In this case, * each field has the same timestamp and the first one will * cause it to be popped. To keep subsequent calculations * simple, pic_type should be set a FIELD value - doesn't * matter which, but I chose BOTTOM. */ pic_type = PICT_BOTTOM_FIELD; } av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n", output->PicInfo.timeStamp); av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n", pic_type); } ret = DtsGetDriverStatus(priv->dev, &decoder_status); if (ret != BC_STS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed: %u\n", ret); return RET_ERROR; } is_paff = ASSUME_PAFF_OVER_MBAFF || !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC); next_frame_same = output->PicInfo.picture_number == (decoder_status.picNumFlags & ~0x40000000); interlaced = ((output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && is_paff) || next_frame_same || bottom_field || second_field; av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: next_frame_same: %u | %u | %u\n", next_frame_same, output->PicInfo.picture_number, decoder_status.picNumFlags & ~0x40000000); if (priv->pic.data[0] && !priv->need_second_field) avctx->release_buffer(avctx, &priv->pic); priv->need_second_field = interlaced && !priv->need_second_field; priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (!priv->pic.data[0]) { if (avctx->get_buffer(avctx, &priv->pic) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return RET_ERROR; } } bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0); if (priv->is_70012) { int pStride; if (width <= 720) pStride = 720; else if (width <= 1280) pStride = 1280; else if (width <= 1080) pStride = 1080; sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0); } else { sStride = bwidth; } dStride = priv->pic.linesize[0]; dst = priv->pic.data[0]; av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n"); if (interlaced) { int dY = 0; int sY = 0; height /= 2; if (bottom_field) { av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n"); dY = 1; } else { av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n"); dY = 0; } for (sY = 0; sY < height; dY++, sY++) { memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth); dY++; } } else { av_image_copy_plane(dst, dStride, src, sStride, bwidth, height); } priv->pic.interlaced_frame = interlaced; if (interlaced) priv->pic.top_field_first = !bottom_first; priv->pic.pkt_pts = pkt_pts; if (!priv->need_second_field) { *data_size = sizeof(AVFrame); *(AVFrame *)data = priv->pic; } if (ASSUME_TWO_INPUTS_ONE_OUTPUT && output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) { av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); return RET_SKIP_NEXT_COPY; } /* * Testing has shown that in all cases where we don't want to return the * full frame immediately, VDEC_FLAG_UNKNOWN_SRC is set. */ return priv->need_second_field && !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ? RET_COPY_NEXT_FIELD : RET_OK; }


static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) { X11GrabContext *s = s1->priv_data; Display *dpy = s->dpy; XImage *image = s->image; int x_off = s->x_off; int y_off = s->y_off; int follow_mouse = s->follow_mouse; int screen; Window root; int64_t curtime, delay; struct timespec ts; /* Calculate the time of the next frame */ s->time_frame += INT64_C(1000000); /* wait based on the frame rate */ for (;;) { curtime = av_gettime(); delay = s->time_frame * av_q2d(s->time_base) - curtime; if (delay <= 0) { if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) s->time_frame += INT64_C(1000000); break; } ts.tv_sec = delay / 1000000; ts.tv_nsec = (delay % 1000000) * 1000; nanosleep(&ts, NULL); } av_init_packet(pkt); pkt->data = image->data; pkt->size = s->frame_size; pkt->pts = curtime; screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); if (follow_mouse) { int screen_w, screen_h; int pointer_x, pointer_y, _; Window w; screen_w = DisplayWidth(dpy, screen); screen_h = DisplayHeight(dpy, screen); XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_); if (follow_mouse == -1) { // follow the mouse, put it at center of grabbing region x_off += pointer_x - s->width / 2 - x_off; y_off += pointer_y - s->height / 2 - y_off; } else { // follow the mouse, but only move the grabbing region when mouse // reaches within certain pixels to the edge. if (pointer_x > x_off + s->width - follow_mouse) x_off += pointer_x - (x_off + s->width - follow_mouse); else if (pointer_x < x_off + follow_mouse) x_off -= (x_off + follow_mouse) - pointer_x; if (pointer_y > y_off + s->height - follow_mouse) y_off += pointer_y - (y_off + s->height - follow_mouse); else if (pointer_y < y_off + follow_mouse) y_off -= (y_off + follow_mouse) - pointer_y; } // adjust grabbing region position if it goes out of screen. s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width); s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height); if (s->show_region && s->region_win) XMoveWindow(dpy, s->region_win, s->x_off - REGION_WIN_BORDER, s->y_off - REGION_WIN_BORDER); } if (s->show_region) { if (s->region_win) { XEvent evt = { .type = NoEventMask }; // Clean up the events, and do the initial draw or redraw. while (XCheckMaskEvent(dpy, ExposureMask | StructureNotifyMask, &evt)) ; if (evt.type) x11grab_draw_region_win(s); } else { x11grab_region_win_init(s); } } if (s->use_shm) { if (!XShmGetImage(dpy, root, image, x_off, y_off, AllPlanes)) av_log(s1, AV_LOG_INFO, "XShmGetImage() failed\n"); } else { if (!xget_zpixmap(dpy, root, image, x_off, y_off)) av_log(s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); } if (s->draw_mouse) paint_mouse_pointer(image, s); return s->frame_size; }


void usb_ep_combine_input_packets(USBEndpoint *ep) { USBPacket *p, *u, *next, *prev = NULL, *first = NULL; USBPort *port = ep->dev->port; int ret; assert(ep->pipeline); assert(ep->pid == USB_TOKEN_IN); QTAILQ_FOREACH_SAFE(p, &ep->queue, queue, next) { /* Empty the queue on a halt */ if (ep->halted) { p->result = USB_RET_REMOVE_FROM_QUEUE; port->ops->complete(port, p); continue; } /* Skip packets already submitted to the device */ if (p->state == USB_PACKET_ASYNC) { prev = p; continue; } usb_packet_check_state(p, USB_PACKET_QUEUED); /* * If the previous (combined) packet has the short_not_ok flag set * stop, as we must not submit packets to the device after a transfer * ending with short_not_ok packet. */ if (prev && prev->short_not_ok) { break; } if (first) { if (first->combined == NULL) { USBCombinedPacket *combined = g_new0(USBCombinedPacket, 1); combined->first = first; QTAILQ_INIT(&combined->packets); qemu_iovec_init(&combined->iov, 2); usb_combined_packet_add(combined, first); } usb_combined_packet_add(first->combined, p); } else { first = p; } /* Is this packet the last one of a (combined) transfer? */ if ((p->iov.size % ep->max_packet_size) != 0 || !p->short_not_ok || next == NULL) { ret = usb_device_handle_data(ep->dev, first); assert(ret == USB_RET_ASYNC); if (first->combined) { QTAILQ_FOREACH(u, &first->combined->packets, combined_entry) { usb_packet_set_state(u, USB_PACKET_ASYNC); } } else { usb_packet_set_state(first, USB_PACKET_ASYNC); } first = NULL; prev = p; } } }


static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d, hwaddr addr, bool resolve_subpage) { MemoryRegionSection *section = atomic_read(&d->mru_section); subpage_t *subpage; bool update; if (section && section != &d->map.sections[PHYS_SECTION_UNASSIGNED] && section_covers_addr(section, addr)) { update = false; } else { section = phys_page_find(d, addr); update = true; } if (resolve_subpage && section->mr->subpage) { subpage = container_of(section->mr, subpage_t, iomem); section = &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr)]]; } if (update) { atomic_set(&d->mru_section, section); } return section; }


static int asf_read_generic_value(AVFormatContext *s, uint8_t *name, uint16_t name_len, int type, AVDictionary **met) { AVIOContext *pb = s->pb; uint64_t value; char buf[32]; switch (type) { case ASF_BOOL: value = avio_rl32(pb); break; case ASF_DWORD: value = avio_rl32(pb); break; case ASF_QWORD: value = avio_rl64(pb); break; case ASF_WORD: value = avio_rl16(pb); break; default: av_freep(&name); return AVERROR_INVALIDDATA; } snprintf(buf, sizeof(buf), "%"PRIu64, value); if (av_dict_set(met, name, buf, 0) < 0) av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); return 0; }


int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { QemuOpts *opts; int res; opts = qemu_opts_from_qdict(&qemu_netdev_opts, qdict); if (!opts) { return -1; res = net_client_init(mon, opts, 1); return res;


static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, uint8_t *p) { int pages = -1; if (is_zero_range(p, TARGET_PAGE_SIZE)) { rs->zero_pages++; rs->bytes_transferred += save_page_header(rs, block, offset | RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(rs->f, 0); rs->bytes_transferred += 1; pages = 1; } return pages; }


static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) { MovieContext *movie = ctx->priv; AVPacket *pkt = &movie->pkt; enum AVMediaType frame_type; MovieStream *st; int ret, got_frame = 0, pkt_out_id; AVFilterLink *outlink; AVFrame *frame; if (!pkt->size) { if (movie->eof) { if (movie->st[out_id].done) { if (movie->loop_count != 1) { ret = rewind_file(ctx); if (ret < 0) return ret; movie->loop_count -= movie->loop_count > 1; av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n"); return 0; /* retry */ } return AVERROR_EOF; } pkt->stream_index = movie->st[out_id].st->index; /* packet is already ready for flushing */ } else { ret = av_read_frame(movie->format_ctx, &movie->pkt0); if (ret < 0) { av_init_packet(&movie->pkt0); /* ready for flushing */ *pkt = movie->pkt0; if (ret == AVERROR_EOF) { movie->eof = 1; return 0; /* start flushing */ } return ret; } *pkt = movie->pkt0; } } pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 : movie->out_index[pkt->stream_index]; if (pkt_out_id < 0) { av_free_packet(&movie->pkt0); pkt->size = 0; /* ready for next run */ pkt->data = NULL; return 0; } st = &movie->st[pkt_out_id]; outlink = ctx->outputs[pkt_out_id]; frame = av_frame_alloc(); if (!frame) return AVERROR(ENOMEM); frame_type = st->st->codec->codec_type; switch (frame_type) { case AVMEDIA_TYPE_VIDEO: ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt); break; case AVMEDIA_TYPE_AUDIO: ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt); break; default: ret = AVERROR(ENOSYS); break; } if (ret < 0) { av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret)); av_frame_free(&frame); av_free_packet(&movie->pkt0); movie->pkt.size = 0; movie->pkt.data = NULL; return 0; } if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) ret = pkt->size; pkt->data += ret; pkt->size -= ret; if (pkt->size <= 0) { av_free_packet(&movie->pkt0); pkt->size = 0; /* ready for next run */ pkt->data = NULL; } if (!got_frame) { if (!ret) st->done = 1; av_frame_free(&frame); return 0; } frame->pts = av_frame_get_best_effort_timestamp(frame); av_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name, describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink)); if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (frame->format != outlink->format) { av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n", av_get_pix_fmt_name(outlink->format), av_get_pix_fmt_name(frame->format) ); av_frame_free(&frame); return 0; } } ret = ff_filter_frame(outlink, frame); if (ret < 0) return ret; return pkt_out_id == out_id; }


static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; const uint8_t *mm_end; uint16_t *d = (uint16_t *)dst; end = s + src_size; __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm__ volatile( "movq %0, %%mm7 \n\t" "movq %1, %%mm6 \n\t" ::"m"(red_15mask),"m"(green_15mask)); mm_end = end - 15; while (s < mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movd %1, %%mm0 \n\t" "movd 3%1, %%mm3 \n\t" "punpckldq 6%1, %%mm0 \n\t" "punpckldq 9%1, %%mm3 \n\t" "movq %%mm0, %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "movq %%mm3, %%mm4 \n\t" "movq %%mm3, %%mm5 \n\t" "psllq $7, %%mm0 \n\t" "psllq $7, %%mm3 \n\t" "pand %%mm7, %%mm0 \n\t" "pand %%mm7, %%mm3 \n\t" "psrlq $6, %%mm1 \n\t" "psrlq $6, %%mm4 \n\t" "pand %%mm6, %%mm1 \n\t" "pand %%mm6, %%mm4 \n\t" "psrlq $19, %%mm2 \n\t" "psrlq $19, %%mm5 \n\t" "pand %2, %%mm2 \n\t" "pand %2, %%mm5 \n\t" "por %%mm1, %%mm0 \n\t" "por %%mm4, %%mm3 \n\t" "por %%mm2, %%mm0 \n\t" "por %%mm5, %%mm3 \n\t" "psllq $16, %%mm3 \n\t" "por %%mm3, %%mm0 \n\t" MOVNTQ" %%mm0, %0 \n\t" :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); d += 4; s += 12; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); while (s < end) { const int r = *s++; const int g = *s++; const int b = *s++; *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); } }


static int decode_picture_timing(H264Context *h) { if (h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag) { h->sei_cpb_removal_delay = get_bits(&h->gb, h->sps.cpb_removal_delay_length); h->sei_dpb_output_delay = get_bits(&h->gb, h->sps.dpb_output_delay_length); } if (h->sps.pic_struct_present_flag) { unsigned int i, num_clock_ts; h->sei_pic_struct = get_bits(&h->gb, 4); h->sei_ct_type = 0; if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) return AVERROR_INVALIDDATA; num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; for (i = 0; i < num_clock_ts; i++) { if (get_bits(&h->gb, 1)) { /* clock_timestamp_flag */ unsigned int full_timestamp_flag; h->sei_ct_type |= 1 << get_bits(&h->gb, 2); skip_bits(&h->gb, 1); /* nuit_field_based_flag */ skip_bits(&h->gb, 5); /* counting_type */ full_timestamp_flag = get_bits(&h->gb, 1); skip_bits(&h->gb, 1); /* discontinuity_flag */ skip_bits(&h->gb, 1); /* cnt_dropped_flag */ skip_bits(&h->gb, 8); /* n_frames */ if (full_timestamp_flag) { skip_bits(&h->gb, 6); /* seconds_value 0..59 */ skip_bits(&h->gb, 6); /* minutes_value 0..59 */ skip_bits(&h->gb, 5); /* hours_value 0..23 */ } else { if (get_bits(&h->gb, 1)) { /* seconds_flag */ skip_bits(&h->gb, 6); /* seconds_value range 0..59 */ if (get_bits(&h->gb, 1)) { /* minutes_flag */ skip_bits(&h->gb, 6); /* minutes_value 0..59 */ if (get_bits(&h->gb, 1)) /* hours_flag */ skip_bits(&h->gb, 5); /* hours_value 0..23 */ } } } if (h->sps.time_offset_length > 0) skip_bits(&h->gb, h->sps.time_offset_length); /* time_offset */ } } if (h->avctx->debug & FF_DEBUG_PICT_INFO) av_log(h->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); } return 0; }


static int ftp_close(URLContext *h) { FTPContext *s = h->priv_data; av_dlog(h, "ftp protocol close\n"); ftp_close_both_connections(s); av_freep(&s->user); av_freep(&s->password); av_freep(&s->hostname); av_freep(&s->path); av_freep(&s->features); return 0; }