id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
func_clean
stringlengths
26
131k
vul_lines
dict
normalized_func
stringlengths
24
132k
lines
sequencelengths
1
2.8k
label
sequencelengths
1
2.8k
line_no
sequencelengths
1
2.8k
0
static av_cold int vdadec_init(AVCodecContext *avctx) { VDADecoderContext *ctx = avctx->priv_data; struct vda_context *vda_ctx = &ctx->vda_ctx; OSStatus status; int ret; ctx->h264_initialized = 0; /* init pix_fmts of codec */ if (!ff_h264_vda_decoder.pix_fmts) { if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7) ff_h264_vda_decoder.pix_fmts = vda_pixfmts_prior_10_7; else ff_h264_vda_decoder.pix_fmts = vda_pixfmts; } /* init vda */ memset(vda_ctx, 0, sizeof(struct vda_context)); vda_ctx->width = avctx->width; vda_ctx->height = avctx->height; vda_ctx->format = 'avc1'; vda_ctx->use_sync_decoding = 1; vda_ctx->use_ref_buffer = 1; ctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); switch (ctx->pix_fmt) { case AV_PIX_FMT_UYVY422: vda_ctx->cv_pix_fmt_type = '2vuy'; break; case AV_PIX_FMT_YUYV422: vda_ctx->cv_pix_fmt_type = 'yuvs'; break; case AV_PIX_FMT_NV12: vda_ctx->cv_pix_fmt_type = '420v'; break; case AV_PIX_FMT_YUV420P: vda_ctx->cv_pix_fmt_type = 'y420'; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n", avctx->pix_fmt); goto failed; } status = ff_vda_create_decoder(vda_ctx, avctx->extradata, avctx->extradata_size); if (status != kVDADecoderNoErr) { av_log(avctx, AV_LOG_ERROR, "Failed to init VDA decoder: %d.\n", status); goto failed; } avctx->hwaccel_context = vda_ctx; /* changes callback functions */ avctx->get_format = get_format; avctx->get_buffer2 = get_buffer2; #if FF_API_GET_BUFFER // force the old get_buffer to be empty avctx->get_buffer = NULL; #endif /* init H.264 decoder */ ret = ff_h264_decoder.init(avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to open H.264 decoder.\n"); goto failed; } ctx->h264_initialized = 1; return 0; failed: vdadec_close(avctx); return -1; }
false
FFmpeg
973b1a6b9070e2bf17d17568cbaf4043ce931f51
static av_cold int vdadec_init(AVCodecContext *avctx) { VDADecoderContext *ctx = avctx->priv_data; struct vda_context *vda_ctx = &ctx->vda_ctx; OSStatus status; int ret; ctx->h264_initialized = 0; if (!ff_h264_vda_decoder.pix_fmts) { if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7) ff_h264_vda_decoder.pix_fmts = vda_pixfmts_prior_10_7; else ff_h264_vda_decoder.pix_fmts = vda_pixfmts; } memset(vda_ctx, 0, sizeof(struct vda_context)); vda_ctx->width = avctx->width; vda_ctx->height = avctx->height; vda_ctx->format = 'avc1'; vda_ctx->use_sync_decoding = 1; vda_ctx->use_ref_buffer = 1; ctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); switch (ctx->pix_fmt) { case AV_PIX_FMT_UYVY422: vda_ctx->cv_pix_fmt_type = '2vuy'; break; case AV_PIX_FMT_YUYV422: vda_ctx->cv_pix_fmt_type = 'yuvs'; break; case AV_PIX_FMT_NV12: vda_ctx->cv_pix_fmt_type = '420v'; break; case AV_PIX_FMT_YUV420P: vda_ctx->cv_pix_fmt_type = 'y420'; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n", avctx->pix_fmt); goto failed; } status = ff_vda_create_decoder(vda_ctx, avctx->extradata, avctx->extradata_size); if (status != kVDADecoderNoErr) { av_log(avctx, AV_LOG_ERROR, "Failed to init VDA decoder: %d.\n", status); goto failed; } avctx->hwaccel_context = vda_ctx; avctx->get_format = get_format; avctx->get_buffer2 = get_buffer2; #if FF_API_GET_BUFFER avctx->get_buffer = NULL; #endif ret = ff_h264_decoder.init(avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to open H.264 decoder.\n"); goto failed; } ctx->h264_initialized = 1; return 0; failed: vdadec_close(avctx); return -1; }
{ "code": [], "line_no": [] }
static av_cold int FUNC_0(AVCodecContext *avctx) { VDADecoderContext *ctx = avctx->priv_data; struct vda_context *VAR_0 = &ctx->VAR_0; OSStatus status; int VAR_1; ctx->h264_initialized = 0; if (!ff_h264_vda_decoder.pix_fmts) { if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7) ff_h264_vda_decoder.pix_fmts = vda_pixfmts_prior_10_7; else ff_h264_vda_decoder.pix_fmts = vda_pixfmts; } memset(VAR_0, 0, sizeof(struct vda_context)); VAR_0->width = avctx->width; VAR_0->height = avctx->height; VAR_0->format = 'avc1'; VAR_0->use_sync_decoding = 1; VAR_0->use_ref_buffer = 1; ctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); switch (ctx->pix_fmt) { case AV_PIX_FMT_UYVY422: VAR_0->cv_pix_fmt_type = '2vuy'; break; case AV_PIX_FMT_YUYV422: VAR_0->cv_pix_fmt_type = 'yuvs'; break; case AV_PIX_FMT_NV12: VAR_0->cv_pix_fmt_type = '420v'; break; case AV_PIX_FMT_YUV420P: VAR_0->cv_pix_fmt_type = 'y420'; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n", avctx->pix_fmt); goto failed; } status = ff_vda_create_decoder(VAR_0, avctx->extradata, avctx->extradata_size); if (status != kVDADecoderNoErr) { av_log(avctx, AV_LOG_ERROR, "Failed to init VDA decoder: %d.\n", status); goto failed; } avctx->hwaccel_context = VAR_0; avctx->get_format = get_format; avctx->get_buffer2 = get_buffer2; #if FF_API_GET_BUFFER avctx->get_buffer = NULL; #endif VAR_1 = ff_h264_decoder.init(avctx); if (VAR_1 < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to open H.264 decoder.\n"); goto failed; } ctx->h264_initialized = 1; return 0; failed: vdadec_close(avctx); return -1; }
[ "static av_cold int FUNC_0(AVCodecContext *avctx)\n{", "VDADecoderContext *ctx = avctx->priv_data;", "struct vda_context *VAR_0 = &ctx->VAR_0;", "OSStatus status;", "int VAR_1;", "ctx->h264_initialized = 0;", "if (!ff_h264_vda_decoder.pix_fmts) {", "if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7)\nff_h264_vda_decoder.pix_fmts = vda_pixfmts_prior_10_7;", "else\nff_h264_vda_decoder.pix_fmts = vda_pixfmts;", "}", "memset(VAR_0, 0, sizeof(struct vda_context));", "VAR_0->width = avctx->width;", "VAR_0->height = avctx->height;", "VAR_0->format = 'avc1';", "VAR_0->use_sync_decoding = 1;", "VAR_0->use_ref_buffer = 1;", "ctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts);", "switch (ctx->pix_fmt) {", "case AV_PIX_FMT_UYVY422:\nVAR_0->cv_pix_fmt_type = '2vuy';", "break;", "case AV_PIX_FMT_YUYV422:\nVAR_0->cv_pix_fmt_type = 'yuvs';", "break;", "case AV_PIX_FMT_NV12:\nVAR_0->cv_pix_fmt_type = '420v';", "break;", "case AV_PIX_FMT_YUV420P:\nVAR_0->cv_pix_fmt_type = 'y420';", "break;", "default:\nav_log(avctx, AV_LOG_ERROR, \"Unsupported pixel format: %d\\n\", avctx->pix_fmt);", "goto failed;", "}", "status = ff_vda_create_decoder(VAR_0,\navctx->extradata, avctx->extradata_size);", "if (status != kVDADecoderNoErr) {", "av_log(avctx, AV_LOG_ERROR,\n\"Failed to init VDA decoder: %d.\\n\", status);", "goto failed;", "}", "avctx->hwaccel_context = VAR_0;", "avctx->get_format = get_format;", "avctx->get_buffer2 = get_buffer2;", "#if FF_API_GET_BUFFER\navctx->get_buffer = NULL;", "#endif\nVAR_1 = ff_h264_decoder.init(avctx);", "if (VAR_1 < 0) {", "av_log(avctx, AV_LOG_ERROR, \"Failed to open H.264 decoder.\\n\");", "goto failed;", "}", "ctx->h264_initialized = 1;", "return 0;", "failed:\nvdadec_close(avctx);", "return -1;", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7 ], [ 9 ], [ 11 ], [ 15 ], [ 21 ], [ 23, 25 ], [ 27, 29 ], [ 31 ], [ 37 ], [ 39 ], [ 41 ], [ 43 ], [ 45 ], [ 47 ], [ 49 ], [ 51 ], [ 53, 55 ], [ 57 ], [ 59, 61 ], [ 63 ], [ 65, 67 ], [ 69 ], [ 71, 73 ], [ 75 ], [ 77, 79 ], [ 81 ], [ 83 ], [ 85, 87 ], [ 89 ], [ 91, 93 ], [ 95 ], [ 97 ], [ 99 ], [ 105 ], [ 107 ], [ 109, 113 ], [ 115, 121 ], [ 123 ], [ 125 ], [ 127 ], [ 129 ], [ 131 ], [ 135 ], [ 139, 141 ], [ 143 ], [ 145 ] ]
1
static int transcode(AVFormatContext **output_files, int nb_output_files, InputFile *input_files, int nb_input_files, StreamMap *stream_maps, int nb_stream_maps) { int ret = 0, i, j, k, n, nb_ostreams = 0, step; AVFormatContext *is, *os; AVCodecContext *codec, *icodec; OutputStream *ost, **ost_table = NULL; InputStream *ist; char error[1024]; int key; int want_sdp = 1; uint8_t no_packet[MAX_FILES]={0}; int no_packet_count=0; int nb_frame_threshold[AVMEDIA_TYPE_NB]={0}; int nb_streams[AVMEDIA_TYPE_NB]={0}; if (rate_emu) for (i = 0; i < nb_input_streams; i++) input_streams[i].start = av_gettime(); /* output stream init */ nb_ostreams = 0; for(i=0;i<nb_output_files;i++) { os = output_files[i]; if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Output file #%d does not contain any stream\n", i); ret = AVERROR(EINVAL); goto fail; } nb_ostreams += os->nb_streams; } if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { fprintf(stderr, "Number of stream maps must match number of output streams\n"); ret = AVERROR(EINVAL); goto fail; } /* Sanity check the mapping args -- do the input files & streams exist? */ for(i=0;i<nb_stream_maps;i++) { int fi = stream_maps[i].file_index; int si = stream_maps[i].stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; } fi = stream_maps[i].sync_file_index; si = stream_maps[i].sync_stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; } } ost_table = av_mallocz(sizeof(OutputStream *) * nb_ostreams); if (!ost_table) goto fail; for(k=0;k<nb_output_files;k++) { os = output_files[k]; for(i=0;i<os->nb_streams;i++,n++) { nb_streams[os->streams[i]->codec->codec_type]++; } } for(step=1<<30; step; step>>=1){ int found_streams[AVMEDIA_TYPE_NB]={0}; for(j=0; j<AVMEDIA_TYPE_NB; j++) nb_frame_threshold[j] += step; for(j=0; j<nb_input_streams; j++) { int skip=0; ist = &input_streams[j]; if(opt_programid){ int pi,si; AVFormatContext *f= input_files[ ist->file_index ].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(si=0; si<p->nb_stream_indexes; si++){ if(f->streams[ p->stream_index[si] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){ found_streams[ist->st->codec->codec_type]++; } } for(j=0; j<AVMEDIA_TYPE_NB; j++) if(found_streams[j] < nb_streams[j]) nb_frame_threshold[j] -= step; } n = 0; for(k=0;k<nb_output_files;k++) { os = output_files[k]; for(i=0;i<os->nb_streams;i++,n++) { int found; ost = ost_table[n] = output_streams_for_file[k][i]; if (nb_stream_maps > 0) { ost->source_index = input_files[stream_maps[n].file_index].ist_index + stream_maps[n].stream_index; /* Sanity check that the stream types match */ if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) { int i= ost->file_index; av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", stream_maps[n].file_index, stream_maps[n].stream_index, ost->file_index, ost->index); ffmpeg_exit(1); } } else { /* get corresponding input stream index : we select the first one with the right type */ found = 0; for (j = 0; j < nb_input_streams; j++) { int skip=0; ist = &input_streams[j]; if(opt_programid){ int pi,si; AVFormatContext *f = input_files[ist->file_index].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(si=0; si<p->nb_stream_indexes; si++){ if(f->streams[ p->stream_index[si] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && ist->st->codec->codec_type == ost->st->codec->codec_type && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) { ost->source_index = j; found = 1; break; } } if (!found) { if(! opt_programid) { /* try again and reuse existing stream */ for (j = 0; j < nb_input_streams; j++) { ist = &input_streams[j]; if ( ist->st->codec->codec_type == ost->st->codec->codec_type && ist->st->discard != AVDISCARD_ALL) { ost->source_index = j; found = 1; } } } if (!found) { int i= ost->file_index; av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", ost->file_index, ost->index); ffmpeg_exit(1); } } } ist = &input_streams[ost->source_index]; ist->discard = 0; ost->sync_ist = (nb_stream_maps > 0) ? &input_streams[input_files[stream_maps[n].sync_file_index].ist_index + stream_maps[n].sync_stream_index] : ist; } } /* for each output stream, we compute the right encoding parameters */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; os = output_files[ost->file_index]; ist = &input_streams[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; if (metadata_streams_autocopy) av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); ost->st->disposition = ist->st->disposition; codec->bits_per_raw_sample= icodec->bits_per_raw_sample; codec->chroma_sample_location = icodec->chroma_sample_location; if (ost->st->stream_copy) { uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; if (extra_size > INT_MAX) goto fail; /* if stream_copy is selected, no need to decode or encode */ codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; if(!codec->codec_tag){ if( !os->oformat->codec_tag || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) codec->codec_tag = icodec->codec_tag; } codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; codec->extradata= av_mallocz(extra_size); if (!codec->extradata) goto fail; memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); codec->extradata_size= icodec->extradata_size; if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){ codec->time_base = icodec->time_base; codec->time_base.num *= icodec->ticks_per_frame; av_reduce(&codec->time_base.num, &codec->time_base.den, codec->time_base.num, codec->time_base.den, INT_MAX); }else codec->time_base = ist->st->time_base; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(audio_volume != 256) { fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); ffmpeg_exit(1); } codec->channel_layout = icodec->channel_layout; codec->sample_rate = icodec->sample_rate; codec->channels = icodec->channels; codec->frame_size = icodec->frame_size; codec->audio_service_type = icodec->audio_service_type; codec->block_align= icodec->block_align; if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) codec->block_align= 0; if(codec->codec_id == CODEC_ID_AC3) codec->block_align= 0; break; case AVMEDIA_TYPE_VIDEO: codec->pix_fmt = icodec->pix_fmt; codec->width = icodec->width; codec->height = icodec->height; codec->has_b_frames = icodec->has_b_frames; if (!codec->sample_aspect_ratio.num) { codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : ist->st->codec->sample_aspect_ratio.num ? ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; } break; case AVMEDIA_TYPE_SUBTITLE: codec->width = icodec->width; codec->height = icodec->height; break; case AVMEDIA_TYPE_DATA: break; default: abort(); } } else { if (!ost->enc) ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: ost->fifo= av_fifo_alloc(1024); if(!ost->fifo) goto fail; ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); if (!codec->sample_rate) { codec->sample_rate = icodec->sample_rate; if (icodec->lowres) codec->sample_rate >>= icodec->lowres; } choose_sample_rate(ost->st, ost->enc); codec->time_base = (AVRational){1, codec->sample_rate}; if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) codec->sample_fmt = icodec->sample_fmt; choose_sample_fmt(ost->st, ost->enc); if (!codec->channels) { codec->channels = icodec->channels; codec->channel_layout = icodec->channel_layout; } if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) codec->channel_layout = 0; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; ost->encoding_needed = 1; ost->resample_sample_fmt = icodec->sample_fmt; ost->resample_sample_rate = icodec->sample_rate; ost->resample_channels = icodec->channels; break; case AVMEDIA_TYPE_VIDEO: if (codec->pix_fmt == PIX_FMT_NONE) codec->pix_fmt = icodec->pix_fmt; choose_pixel_fmt(ost->st, ost->enc); if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); ffmpeg_exit(1); } ost->video_resample = codec->width != icodec->width || codec->height != icodec->height || codec->pix_fmt != icodec->pix_fmt; if (ost->video_resample) { codec->bits_per_raw_sample= frame_bits_per_raw_sample; } if (!codec->width || !codec->height) { codec->width = icodec->width; codec->height = icodec->height; } ost->resample_height = icodec->height; ost->resample_width = icodec->width; ost->resample_pix_fmt= icodec->pix_fmt; ost->encoding_needed = 1; ist->decoding_needed = 1; if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; if (ost->enc && ost->enc->supported_framerates && !force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; if( av_q2d(codec->time_base) < 0.001 && video_sync_method && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n" "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n"); } #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { fprintf(stderr, "Error opening filters!\n"); exit(1); } #endif break; case AVMEDIA_TYPE_SUBTITLE: ost->encoding_needed = 1; ist->decoding_needed = 1; break; default: abort(); break; } /* two pass mode */ if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 && (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { char logfilename[1024]; FILE *f; snprintf(logfilename, sizeof(logfilename), "%s-%d.log", pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, i); if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(logfilename, "wb"); if (!f) { fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); ffmpeg_exit(1); } ost->logfile = f; } else { char *logbuffer; size_t logbuffer_size; if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); ffmpeg_exit(1); } codec->stats_in = logbuffer; } } } if(codec->codec_type == AVMEDIA_TYPE_VIDEO){ /* maximum video buffer size is 6-bytes per pixel, plus DPX header size */ int size= codec->width * codec->height; bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 1664); } } if (!bit_buffer) bit_buffer = av_malloc(bit_buffer_size); if (!bit_buffer) { fprintf(stderr, "Cannot allocate %d bytes output buffer\n", bit_buffer_size); ret = AVERROR(ENOMEM); goto fail; } /* open each encoder */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { AVCodec *codec = ost->enc; AVCodecContext *dec = input_streams[ost->source_index].st->codec; if (!codec) { snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d", ost->st->codec->codec_id, ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } if (dec->subtitle_header) { ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); if (!ost->st->codec->subtitle_header) { ret = AVERROR(ENOMEM); goto dump_format; } memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); ost->st->codec->subtitle_header_size = dec->subtitle_header_size; } if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) { snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ost->st->codec, 1); assert_avoptions(ost->opts); if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\n"); extra_size += ost->st->codec->extradata_size; } } /* open each decoder */ for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { AVCodec *codec = ist->dec; if (!codec) codec = avcodec_find_decoder(ist->st->codec->codec_id); if (!codec) { snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d", ist->st->codec->codec_id, ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d", ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ist->st->codec, 0); assert_avoptions(ost->opts); //if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; } } /* init pts */ for (i = 0; i < nb_input_streams; i++) { AVStream *st; ist = &input_streams[i]; st= ist->st; ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; ist->next_pts = AV_NOPTS_VALUE; ist->is_start = 1; } /* set meta data information from input file if required */ for (i=0;i<nb_meta_data_maps;i++) { AVFormatContext *files[2]; AVDictionary **meta[2]; int j; #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\ (desc), (index));\ ret = AVERROR(EINVAL);\ goto dump_format;\ } int out_file_index = meta_data_maps[i][0].file; int in_file_index = meta_data_maps[i][1].file; if (in_file_index < 0 || out_file_index < 0) continue; METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file") METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file") files[0] = output_files[out_file_index]; files[1] = input_files[in_file_index].ctx; for (j = 0; j < 2; j++) { MetadataMap *map = &meta_data_maps[i][j]; switch (map->type) { case 'g': meta[j] = &files[j]->metadata; break; case 's': METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream") meta[j] = &files[j]->streams[map->index]->metadata; break; case 'c': METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter") meta[j] = &files[j]->chapters[map->index]->metadata; break; case 'p': METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program") meta[j] = &files[j]->programs[map->index]->metadata; break; } } av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE); } /* copy global metadata by default */ if (metadata_global_autocopy) { for (i = 0; i < nb_output_files; i++) av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata, AV_DICT_DONT_OVERWRITE); } /* copy chapters according to chapter maps */ for (i = 0; i < nb_chapter_maps; i++) { int infile = chapter_maps[i].in_file; int outfile = chapter_maps[i].out_file; if (infile < 0 || outfile < 0) continue; if (infile >= nb_input_files) { snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile); ret = AVERROR(EINVAL); goto dump_format; } if (outfile >= nb_output_files) { snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile); ret = AVERROR(EINVAL); goto dump_format; } copy_chapters(infile, outfile); } /* copy chapters from the first input file that has them*/ if (!nb_chapter_maps) for (i = 0; i < nb_input_files; i++) { if (!input_files[i].ctx->nb_chapters) continue; for (j = 0; j < nb_output_files; j++) if ((ret = copy_chapters(i, j)) < 0) goto dump_format; break; } /* open files and write file headers */ for(i=0;i<nb_output_files;i++) { os = output_files[i]; if (avformat_write_header(os, &output_opts[i]) < 0) { snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); ret = AVERROR(EINVAL); goto dump_format; } assert_avoptions(output_opts[i]); if (strcmp(output_files[i]->oformat->name, "rtp")) { want_sdp = 0; } } dump_format: /* dump the file output parameters - cannot be done before in case of stream copy */ for(i=0;i<nb_output_files;i++) { av_dump_format(output_files[i], i, output_files[i]->filename, 1); } /* dump the stream mapping */ if (verbose >= 0) { fprintf(stderr, "Stream mapping:\n"); for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; fprintf(stderr, " Stream #%d.%d -> #%d.%d", input_streams[ost->source_index].file_index, input_streams[ost->source_index].st->index, ost->file_index, ost->index); if (ost->sync_ist != &input_streams[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); fprintf(stderr, "\n"); } } if (ret) { fprintf(stderr, "%s\n", error); goto fail; } if (want_sdp) { print_sdp(output_files, nb_output_files); } if (!using_stdin) { if(verbose >= 0) fprintf(stderr, "Press [q] to stop, [?] for help\n"); avio_set_interrupt_cb(decode_interrupt_cb); } term_init(); timer_start = av_gettime(); for(; received_sigterm == 0;) { int file_index, ist_index; AVPacket pkt; double ipts_min; double opts_min; redo: ipts_min= 1e100; opts_min= 1e100; /* if 'q' pressed, exits */ if (!using_stdin) { if (q_pressed) break; /* read_key() returns 0 on EOF */ key = read_key(); if (key == 'q') break; if (key == '+') verbose++; if (key == '-') verbose--; if (key == 's') qp_hist ^= 1; if (key == 'h'){ if (do_hex_dump){ do_hex_dump = do_pkt_dump = 0; } else if(do_pkt_dump){ do_hex_dump = 1; } else do_pkt_dump = 1; av_log_set_level(AV_LOG_DEBUG); } if (key == 'd' || key == 'D'){ int debug=0; if(key == 'D') { debug = input_streams[0].st->codec->debug<<1; if(!debug) debug = 1; while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) //unsupported, would just crash debug += debug; }else scanf("%d", &debug); for(i=0;i<nb_input_streams;i++) { input_streams[i].st->codec->debug = debug; } for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; ost->st->codec->debug = debug; } if(debug) av_log_set_level(AV_LOG_DEBUG); fprintf(stderr,"debug=%d\n", debug); } if (key == '?'){ fprintf(stderr, "key function\n" "? show this help\n" "+ increase verbosity\n" "- decrease verbosity\n" "D cycle through available debug modes\n" "h dump packets/hex press to cycle through the 3 states\n" "q quit\n" "s Show QP histogram\n" ); } } /* select the stream that we must read now by looking at the smallest output pts */ file_index = -1; for(i=0;i<nb_ostreams;i++) { double ipts, opts; ost = ost_table[i]; os = output_files[ost->file_index]; ist = &input_streams[ost->source_index]; if(ist->is_past_recording_time || no_packet[ist->file_index]) continue; opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = (double)ist->pts; if (!input_files[ist->file_index].eof_reached){ if(ipts < ipts_min) { ipts_min = ipts; if(input_sync ) file_index = ist->file_index; } if(opts < opts_min) { opts_min = opts; if(!input_sync) file_index = ist->file_index; } } if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){ file_index= -1; break; } } /* if none, if is finished */ if (file_index < 0) { if(no_packet_count){ no_packet_count=0; memset(no_packet, 0, sizeof(no_packet)); usleep(10000); continue; } break; } /* finish if limit size exhausted */ if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb)) break; /* read a frame from it and output it in the fifo */ is = input_files[file_index].ctx; ret= av_read_frame(is, &pkt); if(ret == AVERROR(EAGAIN)){ no_packet[file_index]=1; no_packet_count++; continue; } if (ret < 0) { input_files[file_index].eof_reached = 1; if (opt_shortest) break; else continue; } no_packet_count=0; memset(no_packet, 0, sizeof(no_packet)); if (do_pkt_dump) { av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, is->streams[pkt.stream_index]); } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ if (pkt.stream_index >= input_files[file_index].ctx->nb_streams) goto discard_packet; ist_index = input_files[file_index].ist_index + pkt.stream_index; ist = &input_streams[ist_index]; if (ist->discard) goto discard_packet; if (pkt.dts != AV_NOPTS_VALUE) pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (ist->ts_scale) { if(pkt.pts != AV_NOPTS_VALUE) pkt.pts *= ist->ts_scale; if(pkt.dts != AV_NOPTS_VALUE) pkt.dts *= ist->ts_scale; } // fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type); if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE && (is->iformat->flags & AVFMT_TS_DISCONT)) { int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); int64_t delta= pkt_dts - ist->next_pts; if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){ input_files[ist->file_index].ts_offset -= delta; if (verbose > 2) fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files[ist->file_index].ts_offset); pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if(pkt.pts != AV_NOPTS_VALUE) pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } /* finish if recording time exhausted */ if (recording_time != INT64_MAX && (pkt.pts != AV_NOPTS_VALUE ? av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) : av_compare_ts(ist->pts, AV_TIME_BASE_Q, recording_time + start_time, (AVRational){1, 1000000}) )>= 0) { ist->is_past_recording_time = 1; goto discard_packet; } //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size); if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { if (verbose >= 0) fprintf(stderr, "Error while decoding stream #%d.%d\n", ist->file_index, ist->st->index); if (exit_on_error) ffmpeg_exit(1); av_free_packet(&pkt); goto redo; } discard_packet: av_free_packet(&pkt); /* dump report by using the output first video and audio streams */ print_report(output_files, ost_table, nb_ostreams, 0); } /* at the end of stream, we must flush the decoder buffers */ for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { output_packet(ist, i, ost_table, nb_ostreams, NULL); } } term_exit(); /* write the trailer if needed and close file */ for(i=0;i<nb_output_files;i++) { os = output_files[i]; av_write_trailer(os); } /* dump report by using the first video and audio streams */ print_report(output_files, ost_table, nb_ostreams, 1); /* close each encoder */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { av_freep(&ost->st->codec->stats_in); avcodec_close(ost->st->codec); } #if CONFIG_AVFILTER avfilter_graph_free(&ost->graph); #endif } /* close each decoder */ for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { avcodec_close(ist->st->codec); } } /* finished ! */ ret = 0; fail: av_freep(&bit_buffer); if (ost_table) { for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost) { if (ost->st->stream_copy) av_freep(&ost->st->codec->extradata); if (ost->logfile) { fclose(ost->logfile); ost->logfile = NULL; } av_fifo_free(ost->fifo); /* works even if fifo is not initialized but set to zero */ av_freep(&ost->st->codec->subtitle_header); av_free(ost->resample_frame.data[0]); av_free(ost->forced_kf_pts); if (ost->video_resample) sws_freeContext(ost->img_resample_ctx); if (ost->resample) audio_resample_close(ost->resample); if (ost->reformat_ctx) av_audio_convert_free(ost->reformat_ctx); av_dict_free(&ost->opts); av_free(ost); } } av_free(ost_table); } return ret; }
false
FFmpeg
321b2a9ded0468670b7678b7c098886930ae16b2
static int transcode(AVFormatContext **output_files, int nb_output_files, InputFile *input_files, int nb_input_files, StreamMap *stream_maps, int nb_stream_maps) { int ret = 0, i, j, k, n, nb_ostreams = 0, step; AVFormatContext *is, *os; AVCodecContext *codec, *icodec; OutputStream *ost, **ost_table = NULL; InputStream *ist; char error[1024]; int key; int want_sdp = 1; uint8_t no_packet[MAX_FILES]={0}; int no_packet_count=0; int nb_frame_threshold[AVMEDIA_TYPE_NB]={0}; int nb_streams[AVMEDIA_TYPE_NB]={0}; if (rate_emu) for (i = 0; i < nb_input_streams; i++) input_streams[i].start = av_gettime(); nb_ostreams = 0; for(i=0;i<nb_output_files;i++) { os = output_files[i]; if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Output file #%d does not contain any stream\n", i); ret = AVERROR(EINVAL); goto fail; } nb_ostreams += os->nb_streams; } if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { fprintf(stderr, "Number of stream maps must match number of output streams\n"); ret = AVERROR(EINVAL); goto fail; } for(i=0;i<nb_stream_maps;i++) { int fi = stream_maps[i].file_index; int si = stream_maps[i].stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; } fi = stream_maps[i].sync_file_index; si = stream_maps[i].sync_stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; } } ost_table = av_mallocz(sizeof(OutputStream *) * nb_ostreams); if (!ost_table) goto fail; for(k=0;k<nb_output_files;k++) { os = output_files[k]; for(i=0;i<os->nb_streams;i++,n++) { nb_streams[os->streams[i]->codec->codec_type]++; } } for(step=1<<30; step; step>>=1){ int found_streams[AVMEDIA_TYPE_NB]={0}; for(j=0; j<AVMEDIA_TYPE_NB; j++) nb_frame_threshold[j] += step; for(j=0; j<nb_input_streams; j++) { int skip=0; ist = &input_streams[j]; if(opt_programid){ int pi,si; AVFormatContext *f= input_files[ ist->file_index ].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(si=0; si<p->nb_stream_indexes; si++){ if(f->streams[ p->stream_index[si] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){ found_streams[ist->st->codec->codec_type]++; } } for(j=0; j<AVMEDIA_TYPE_NB; j++) if(found_streams[j] < nb_streams[j]) nb_frame_threshold[j] -= step; } n = 0; for(k=0;k<nb_output_files;k++) { os = output_files[k]; for(i=0;i<os->nb_streams;i++,n++) { int found; ost = ost_table[n] = output_streams_for_file[k][i]; if (nb_stream_maps > 0) { ost->source_index = input_files[stream_maps[n].file_index].ist_index + stream_maps[n].stream_index; if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) { int i= ost->file_index; av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", stream_maps[n].file_index, stream_maps[n].stream_index, ost->file_index, ost->index); ffmpeg_exit(1); } } else { found = 0; for (j = 0; j < nb_input_streams; j++) { int skip=0; ist = &input_streams[j]; if(opt_programid){ int pi,si; AVFormatContext *f = input_files[ist->file_index].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(si=0; si<p->nb_stream_indexes; si++){ if(f->streams[ p->stream_index[si] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && ist->st->codec->codec_type == ost->st->codec->codec_type && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) { ost->source_index = j; found = 1; break; } } if (!found) { if(! opt_programid) { for (j = 0; j < nb_input_streams; j++) { ist = &input_streams[j]; if ( ist->st->codec->codec_type == ost->st->codec->codec_type && ist->st->discard != AVDISCARD_ALL) { ost->source_index = j; found = 1; } } } if (!found) { int i= ost->file_index; av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", ost->file_index, ost->index); ffmpeg_exit(1); } } } ist = &input_streams[ost->source_index]; ist->discard = 0; ost->sync_ist = (nb_stream_maps > 0) ? &input_streams[input_files[stream_maps[n].sync_file_index].ist_index + stream_maps[n].sync_stream_index] : ist; } } for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; os = output_files[ost->file_index]; ist = &input_streams[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; if (metadata_streams_autocopy) av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); ost->st->disposition = ist->st->disposition; codec->bits_per_raw_sample= icodec->bits_per_raw_sample; codec->chroma_sample_location = icodec->chroma_sample_location; if (ost->st->stream_copy) { uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; if (extra_size > INT_MAX) goto fail; codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; if(!codec->codec_tag){ if( !os->oformat->codec_tag || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) codec->codec_tag = icodec->codec_tag; } codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; codec->extradata= av_mallocz(extra_size); if (!codec->extradata) goto fail; memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); codec->extradata_size= icodec->extradata_size; if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){ codec->time_base = icodec->time_base; codec->time_base.num *= icodec->ticks_per_frame; av_reduce(&codec->time_base.num, &codec->time_base.den, codec->time_base.num, codec->time_base.den, INT_MAX); }else codec->time_base = ist->st->time_base; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(audio_volume != 256) { fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); ffmpeg_exit(1); } codec->channel_layout = icodec->channel_layout; codec->sample_rate = icodec->sample_rate; codec->channels = icodec->channels; codec->frame_size = icodec->frame_size; codec->audio_service_type = icodec->audio_service_type; codec->block_align= icodec->block_align; if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) codec->block_align= 0; if(codec->codec_id == CODEC_ID_AC3) codec->block_align= 0; break; case AVMEDIA_TYPE_VIDEO: codec->pix_fmt = icodec->pix_fmt; codec->width = icodec->width; codec->height = icodec->height; codec->has_b_frames = icodec->has_b_frames; if (!codec->sample_aspect_ratio.num) { codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : ist->st->codec->sample_aspect_ratio.num ? ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; } break; case AVMEDIA_TYPE_SUBTITLE: codec->width = icodec->width; codec->height = icodec->height; break; case AVMEDIA_TYPE_DATA: break; default: abort(); } } else { if (!ost->enc) ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: ost->fifo= av_fifo_alloc(1024); if(!ost->fifo) goto fail; ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); if (!codec->sample_rate) { codec->sample_rate = icodec->sample_rate; if (icodec->lowres) codec->sample_rate >>= icodec->lowres; } choose_sample_rate(ost->st, ost->enc); codec->time_base = (AVRational){1, codec->sample_rate}; if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) codec->sample_fmt = icodec->sample_fmt; choose_sample_fmt(ost->st, ost->enc); if (!codec->channels) { codec->channels = icodec->channels; codec->channel_layout = icodec->channel_layout; } if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) codec->channel_layout = 0; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; ost->encoding_needed = 1; ost->resample_sample_fmt = icodec->sample_fmt; ost->resample_sample_rate = icodec->sample_rate; ost->resample_channels = icodec->channels; break; case AVMEDIA_TYPE_VIDEO: if (codec->pix_fmt == PIX_FMT_NONE) codec->pix_fmt = icodec->pix_fmt; choose_pixel_fmt(ost->st, ost->enc); if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); ffmpeg_exit(1); } ost->video_resample = codec->width != icodec->width || codec->height != icodec->height || codec->pix_fmt != icodec->pix_fmt; if (ost->video_resample) { codec->bits_per_raw_sample= frame_bits_per_raw_sample; } if (!codec->width || !codec->height) { codec->width = icodec->width; codec->height = icodec->height; } ost->resample_height = icodec->height; ost->resample_width = icodec->width; ost->resample_pix_fmt= icodec->pix_fmt; ost->encoding_needed = 1; ist->decoding_needed = 1; if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; if (ost->enc && ost->enc->supported_framerates && !force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; if( av_q2d(codec->time_base) < 0.001 && video_sync_method && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n" "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n"); } #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { fprintf(stderr, "Error opening filters!\n"); exit(1); } #endif break; case AVMEDIA_TYPE_SUBTITLE: ost->encoding_needed = 1; ist->decoding_needed = 1; break; default: abort(); break; } if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 && (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { char logfilename[1024]; FILE *f; snprintf(logfilename, sizeof(logfilename), "%s-%d.log", pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, i); if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(logfilename, "wb"); if (!f) { fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); ffmpeg_exit(1); } ost->logfile = f; } else { char *logbuffer; size_t logbuffer_size; if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); ffmpeg_exit(1); } codec->stats_in = logbuffer; } } } if(codec->codec_type == AVMEDIA_TYPE_VIDEO){ int size= codec->width * codec->height; bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 1664); } } if (!bit_buffer) bit_buffer = av_malloc(bit_buffer_size); if (!bit_buffer) { fprintf(stderr, "Cannot allocate %d bytes output buffer\n", bit_buffer_size); ret = AVERROR(ENOMEM); goto fail; } for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { AVCodec *codec = ost->enc; AVCodecContext *dec = input_streams[ost->source_index].st->codec; if (!codec) { snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d", ost->st->codec->codec_id, ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } if (dec->subtitle_header) { ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); if (!ost->st->codec->subtitle_header) { ret = AVERROR(ENOMEM); goto dump_format; } memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); ost->st->codec->subtitle_header_size = dec->subtitle_header_size; } if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) { snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ost->file_index, ost->index); ret = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ost->st->codec, 1); assert_avoptions(ost->opts); if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\n"); extra_size += ost->st->codec->extradata_size; } } for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { AVCodec *codec = ist->dec; if (!codec) codec = avcodec_find_decoder(ist->st->codec->codec_id); if (!codec) { snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d", ist->st->codec->codec_id, ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d", ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ist->st->codec, 0); assert_avoptions(ost->opts); } } for (i = 0; i < nb_input_streams; i++) { AVStream *st; ist = &input_streams[i]; st= ist->st; ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; ist->next_pts = AV_NOPTS_VALUE; ist->is_start = 1; } for (i=0;i<nb_meta_data_maps;i++) { AVFormatContext *files[2]; AVDictionary **meta[2]; int j; #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\ (desc), (index));\ ret = AVERROR(EINVAL);\ goto dump_format;\ } int out_file_index = meta_data_maps[i][0].file; int in_file_index = meta_data_maps[i][1].file; if (in_file_index < 0 || out_file_index < 0) continue; METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file") METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file") files[0] = output_files[out_file_index]; files[1] = input_files[in_file_index].ctx; for (j = 0; j < 2; j++) { MetadataMap *map = &meta_data_maps[i][j]; switch (map->type) { case 'g': meta[j] = &files[j]->metadata; break; case 's': METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream") meta[j] = &files[j]->streams[map->index]->metadata; break; case 'c': METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter") meta[j] = &files[j]->chapters[map->index]->metadata; break; case 'p': METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program") meta[j] = &files[j]->programs[map->index]->metadata; break; } } av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE); } if (metadata_global_autocopy) { for (i = 0; i < nb_output_files; i++) av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata, AV_DICT_DONT_OVERWRITE); } for (i = 0; i < nb_chapter_maps; i++) { int infile = chapter_maps[i].in_file; int outfile = chapter_maps[i].out_file; if (infile < 0 || outfile < 0) continue; if (infile >= nb_input_files) { snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile); ret = AVERROR(EINVAL); goto dump_format; } if (outfile >= nb_output_files) { snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile); ret = AVERROR(EINVAL); goto dump_format; } copy_chapters(infile, outfile); } if (!nb_chapter_maps) for (i = 0; i < nb_input_files; i++) { if (!input_files[i].ctx->nb_chapters) continue; for (j = 0; j < nb_output_files; j++) if ((ret = copy_chapters(i, j)) < 0) goto dump_format; break; } for(i=0;i<nb_output_files;i++) { os = output_files[i]; if (avformat_write_header(os, &output_opts[i]) < 0) { snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); ret = AVERROR(EINVAL); goto dump_format; } assert_avoptions(output_opts[i]); if (strcmp(output_files[i]->oformat->name, "rtp")) { want_sdp = 0; } } dump_format: for(i=0;i<nb_output_files;i++) { av_dump_format(output_files[i], i, output_files[i]->filename, 1); } if (verbose >= 0) { fprintf(stderr, "Stream mapping:\n"); for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; fprintf(stderr, " Stream #%d.%d -> #%d.%d", input_streams[ost->source_index].file_index, input_streams[ost->source_index].st->index, ost->file_index, ost->index); if (ost->sync_ist != &input_streams[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); fprintf(stderr, "\n"); } } if (ret) { fprintf(stderr, "%s\n", error); goto fail; } if (want_sdp) { print_sdp(output_files, nb_output_files); } if (!using_stdin) { if(verbose >= 0) fprintf(stderr, "Press [q] to stop, [?] for help\n"); avio_set_interrupt_cb(decode_interrupt_cb); } term_init(); timer_start = av_gettime(); for(; received_sigterm == 0;) { int file_index, ist_index; AVPacket pkt; double ipts_min; double opts_min; redo: ipts_min= 1e100; opts_min= 1e100; if (!using_stdin) { if (q_pressed) break; key = read_key(); if (key == 'q') break; if (key == '+') verbose++; if (key == '-') verbose--; if (key == 's') qp_hist ^= 1; if (key == 'h'){ if (do_hex_dump){ do_hex_dump = do_pkt_dump = 0; } else if(do_pkt_dump){ do_hex_dump = 1; } else do_pkt_dump = 1; av_log_set_level(AV_LOG_DEBUG); } if (key == 'd' || key == 'D'){ int debug=0; if(key == 'D') { debug = input_streams[0].st->codec->debug<<1; if(!debug) debug = 1; while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) debug += debug; }else scanf("%d", &debug); for(i=0;i<nb_input_streams;i++) { input_streams[i].st->codec->debug = debug; } for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; ost->st->codec->debug = debug; } if(debug) av_log_set_level(AV_LOG_DEBUG); fprintf(stderr,"debug=%d\n", debug); } if (key == '?'){ fprintf(stderr, "key function\n" "? show this help\n" "+ increase verbosity\n" "- decrease verbosity\n" "D cycle through available debug modes\n" "h dump packets/hex press to cycle through the 3 states\n" "q quit\n" "s Show QP histogram\n" ); } } file_index = -1; for(i=0;i<nb_ostreams;i++) { double ipts, opts; ost = ost_table[i]; os = output_files[ost->file_index]; ist = &input_streams[ost->source_index]; if(ist->is_past_recording_time || no_packet[ist->file_index]) continue; opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = (double)ist->pts; if (!input_files[ist->file_index].eof_reached){ if(ipts < ipts_min) { ipts_min = ipts; if(input_sync ) file_index = ist->file_index; } if(opts < opts_min) { opts_min = opts; if(!input_sync) file_index = ist->file_index; } } if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){ file_index= -1; break; } } if (file_index < 0) { if(no_packet_count){ no_packet_count=0; memset(no_packet, 0, sizeof(no_packet)); usleep(10000); continue; } break; } if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb)) break; is = input_files[file_index].ctx; ret= av_read_frame(is, &pkt); if(ret == AVERROR(EAGAIN)){ no_packet[file_index]=1; no_packet_count++; continue; } if (ret < 0) { input_files[file_index].eof_reached = 1; if (opt_shortest) break; else continue; } no_packet_count=0; memset(no_packet, 0, sizeof(no_packet)); if (do_pkt_dump) { av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, is->streams[pkt.stream_index]); } if (pkt.stream_index >= input_files[file_index].ctx->nb_streams) goto discard_packet; ist_index = input_files[file_index].ist_index + pkt.stream_index; ist = &input_streams[ist_index]; if (ist->discard) goto discard_packet; if (pkt.dts != AV_NOPTS_VALUE) pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (ist->ts_scale) { if(pkt.pts != AV_NOPTS_VALUE) pkt.pts *= ist->ts_scale; if(pkt.dts != AV_NOPTS_VALUE) pkt.dts *= ist->ts_scale; } if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE && (is->iformat->flags & AVFMT_TS_DISCONT)) { int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); int64_t delta= pkt_dts - ist->next_pts; if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){ input_files[ist->file_index].ts_offset -= delta; if (verbose > 2) fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files[ist->file_index].ts_offset); pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if(pkt.pts != AV_NOPTS_VALUE) pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } if (recording_time != INT64_MAX && (pkt.pts != AV_NOPTS_VALUE ? av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) : av_compare_ts(ist->pts, AV_TIME_BASE_Q, recording_time + start_time, (AVRational){1, 1000000}) )>= 0) { ist->is_past_recording_time = 1; goto discard_packet; } if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { if (verbose >= 0) fprintf(stderr, "Error while decoding stream #%d.%d\n", ist->file_index, ist->st->index); if (exit_on_error) ffmpeg_exit(1); av_free_packet(&pkt); goto redo; } discard_packet: av_free_packet(&pkt); print_report(output_files, ost_table, nb_ostreams, 0); } for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { output_packet(ist, i, ost_table, nb_ostreams, NULL); } } term_exit(); for(i=0;i<nb_output_files;i++) { os = output_files[i]; av_write_trailer(os); } print_report(output_files, ost_table, nb_ostreams, 1); for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { av_freep(&ost->st->codec->stats_in); avcodec_close(ost->st->codec); } #if CONFIG_AVFILTER avfilter_graph_free(&ost->graph); #endif } for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; if (ist->decoding_needed) { avcodec_close(ist->st->codec); } } ret = 0; fail: av_freep(&bit_buffer); if (ost_table) { for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost) { if (ost->st->stream_copy) av_freep(&ost->st->codec->extradata); if (ost->logfile) { fclose(ost->logfile); ost->logfile = NULL; } av_fifo_free(ost->fifo); av_freep(&ost->st->codec->subtitle_header); av_free(ost->resample_frame.data[0]); av_free(ost->forced_kf_pts); if (ost->video_resample) sws_freeContext(ost->img_resample_ctx); if (ost->resample) audio_resample_close(ost->resample); if (ost->reformat_ctx) av_audio_convert_free(ost->reformat_ctx); av_dict_free(&ost->opts); av_free(ost); } } av_free(ost_table); } return ret; }
{ "code": [], "line_no": [] }
static int FUNC_0(AVFormatContext **VAR_0, int VAR_1, InputFile *VAR_2, int VAR_3, StreamMap *VAR_4, int VAR_5) { int VAR_6 = 0, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11 = 0, VAR_12; AVFormatContext *is, *os; AVCodecContext *codec, *icodec; OutputStream *ost, **ost_table = NULL; InputStream *ist; char VAR_13[1024]; int VAR_14; int VAR_15 = 1; uint8_t no_packet[MAX_FILES]={0}; int VAR_16=0; int VAR_17[AVMEDIA_TYPE_NB]={0}; int VAR_18[AVMEDIA_TYPE_NB]={0}; if (rate_emu) for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) input_streams[VAR_7].start = av_gettime(); VAR_11 = 0; for(VAR_7=0;VAR_7<VAR_1;VAR_7++) { os = VAR_0[VAR_7]; if (!os->VAR_18 && !(os->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1); fprintf(stderr, "Output file #%d does not contain any stream\VAR_10", VAR_7); VAR_6 = AVERROR(EINVAL); goto fail; } VAR_11 += os->VAR_18; } if (VAR_5 > 0 && VAR_5 != VAR_11) { fprintf(stderr, "Number of stream maps must match number of output streams\VAR_10"); VAR_6 = AVERROR(EINVAL); goto fail; } for(VAR_7=0;VAR_7<VAR_5;VAR_7++) { int VAR_19 = VAR_4[VAR_7].file_index; int VAR_20 = VAR_4[VAR_7].stream_index; if (VAR_19 < 0 || VAR_19 > VAR_3 - 1 || VAR_20 < 0 || VAR_20 > VAR_2[VAR_19].ctx->VAR_18 - 1) { fprintf(stderr,"Could not find input stream #%d.%d\VAR_10", VAR_19, VAR_20); VAR_6 = AVERROR(EINVAL); goto fail; } VAR_19 = VAR_4[VAR_7].sync_file_index; VAR_20 = VAR_4[VAR_7].sync_stream_index; if (VAR_19 < 0 || VAR_19 > VAR_3 - 1 || VAR_20 < 0 || VAR_20 > VAR_2[VAR_19].ctx->VAR_18 - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\VAR_10", VAR_19, VAR_20); VAR_6 = AVERROR(EINVAL); goto fail; } } ost_table = av_mallocz(sizeof(OutputStream *) * VAR_11); if (!ost_table) goto fail; for(VAR_9=0;VAR_9<VAR_1;VAR_9++) { os = VAR_0[VAR_9]; for(VAR_7=0;VAR_7<os->VAR_18;VAR_7++,VAR_10++) { VAR_18[os->streams[VAR_7]->codec->codec_type]++; } } for(VAR_12=1<<30; VAR_12; VAR_12>>=1){ int VAR_21[AVMEDIA_TYPE_NB]={0}; for(VAR_8=0; VAR_8<AVMEDIA_TYPE_NB; VAR_8++) VAR_17[VAR_8] += VAR_12; for(VAR_8=0; VAR_8<nb_input_streams; VAR_8++) { int skip=0; ist = &input_streams[VAR_8]; if(opt_programid){ int pi,VAR_20; AVFormatContext *f= VAR_2[ ist->file_index ].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(VAR_20=0; VAR_20<p->nb_stream_indexes; VAR_20++){ if(f->streams[ p->stream_index[VAR_20] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && VAR_17[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){ VAR_21[ist->st->codec->codec_type]++; } } for(VAR_8=0; VAR_8<AVMEDIA_TYPE_NB; VAR_8++) if(VAR_21[VAR_8] < VAR_18[VAR_8]) VAR_17[VAR_8] -= VAR_12; } VAR_10 = 0; for(VAR_9=0;VAR_9<VAR_1;VAR_9++) { os = VAR_0[VAR_9]; for(VAR_7=0;VAR_7<os->VAR_18;VAR_7++,VAR_10++) { int found; ost = ost_table[VAR_10] = output_streams_for_file[VAR_9][VAR_7]; if (VAR_5 > 0) { ost->source_index = VAR_2[VAR_4[VAR_10].file_index].ist_index + VAR_4[VAR_10].stream_index; if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) { int VAR_7= ost->file_index; av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1); fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\VAR_10", VAR_4[VAR_10].file_index, VAR_4[VAR_10].stream_index, ost->file_index, ost->index); ffmpeg_exit(1); } } else { found = 0; for (VAR_8 = 0; VAR_8 < nb_input_streams; VAR_8++) { int skip=0; ist = &input_streams[VAR_8]; if(opt_programid){ int pi,VAR_20; AVFormatContext *f = VAR_2[ist->file_index].ctx; skip=1; for(pi=0; pi<f->nb_programs; pi++){ AVProgram *p= f->programs[pi]; if(p->id == opt_programid) for(VAR_20=0; VAR_20<p->nb_stream_indexes; VAR_20++){ if(f->streams[ p->stream_index[VAR_20] ] == ist->st) skip=0; } } } if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && ist->st->codec->codec_type == ost->st->codec->codec_type && VAR_17[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) { ost->source_index = VAR_8; found = 1; break; } } if (!found) { if(! opt_programid) { for (VAR_8 = 0; VAR_8 < nb_input_streams; VAR_8++) { ist = &input_streams[VAR_8]; if ( ist->st->codec->codec_type == ost->st->codec->codec_type && ist->st->discard != AVDISCARD_ALL) { ost->source_index = VAR_8; found = 1; } } } if (!found) { int VAR_7= ost->file_index; av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1); fprintf(stderr, "Could not find input stream matching output stream #%d.%d\VAR_10", ost->file_index, ost->index); ffmpeg_exit(1); } } } ist = &input_streams[ost->source_index]; ist->discard = 0; ost->sync_ist = (VAR_5 > 0) ? &input_streams[VAR_2[VAR_4[VAR_10].sync_file_index].ist_index + VAR_4[VAR_10].sync_stream_index] : ist; } } for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; os = VAR_0[ost->file_index]; ist = &input_streams[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; if (metadata_streams_autocopy) av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); ost->st->disposition = ist->st->disposition; codec->bits_per_raw_sample= icodec->bits_per_raw_sample; codec->chroma_sample_location = icodec->chroma_sample_location; if (ost->st->stream_copy) { uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; if (extra_size > INT_MAX) goto fail; codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; if(!codec->codec_tag){ if( !os->oformat->codec_tag || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) codec->codec_tag = icodec->codec_tag; } codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; codec->extradata= av_mallocz(extra_size); if (!codec->extradata) goto fail; memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); codec->extradata_size= icodec->extradata_size; if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){ codec->time_base = icodec->time_base; codec->time_base.num *= icodec->ticks_per_frame; av_reduce(&codec->time_base.num, &codec->time_base.den, codec->time_base.num, codec->time_base.den, INT_MAX); }else codec->time_base = ist->st->time_base; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(audio_volume != 256) { fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\VAR_10"); ffmpeg_exit(1); } codec->channel_layout = icodec->channel_layout; codec->sample_rate = icodec->sample_rate; codec->channels = icodec->channels; codec->frame_size = icodec->frame_size; codec->audio_service_type = icodec->audio_service_type; codec->block_align= icodec->block_align; if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) codec->block_align= 0; if(codec->codec_id == CODEC_ID_AC3) codec->block_align= 0; break; case AVMEDIA_TYPE_VIDEO: codec->pix_fmt = icodec->pix_fmt; codec->width = icodec->width; codec->height = icodec->height; codec->has_b_frames = icodec->has_b_frames; if (!codec->sample_aspect_ratio.num) { codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : ist->st->codec->sample_aspect_ratio.num ? ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; } break; case AVMEDIA_TYPE_SUBTITLE: codec->width = icodec->width; codec->height = icodec->height; break; case AVMEDIA_TYPE_DATA: break; default: abort(); } } else { if (!ost->enc) ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: ost->fifo= av_fifo_alloc(1024); if(!ost->fifo) goto fail; ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); if (!codec->sample_rate) { codec->sample_rate = icodec->sample_rate; if (icodec->lowres) codec->sample_rate >>= icodec->lowres; } choose_sample_rate(ost->st, ost->enc); codec->time_base = (AVRational){1, codec->sample_rate}; if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) codec->sample_fmt = icodec->sample_fmt; choose_sample_fmt(ost->st, ost->enc); if (!codec->channels) { codec->channels = icodec->channels; codec->channel_layout = icodec->channel_layout; } if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) codec->channel_layout = 0; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; ost->encoding_needed = 1; ost->resample_sample_fmt = icodec->sample_fmt; ost->resample_sample_rate = icodec->sample_rate; ost->resample_channels = icodec->channels; break; case AVMEDIA_TYPE_VIDEO: if (codec->pix_fmt == PIX_FMT_NONE) codec->pix_fmt = icodec->pix_fmt; choose_pixel_fmt(ost->st, ost->enc); if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\VAR_10"); ffmpeg_exit(1); } ost->video_resample = codec->width != icodec->width || codec->height != icodec->height || codec->pix_fmt != icodec->pix_fmt; if (ost->video_resample) { codec->bits_per_raw_sample= frame_bits_per_raw_sample; } if (!codec->width || !codec->height) { codec->width = icodec->width; codec->height = icodec->height; } ost->resample_height = icodec->height; ost->resample_width = icodec->width; ost->resample_pix_fmt= icodec->pix_fmt; ost->encoding_needed = 1; ist->decoding_needed = 1; if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; if (ost->enc && ost->enc->supported_framerates && !force_fps) { int VAR_22 = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[VAR_22]; } codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; if( av_q2d(codec->time_base) < 0.001 && video_sync_method && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\VAR_10" "Please consider specifiying a lower framerate, a different muxer or -vsync 2\VAR_10"); } #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { fprintf(stderr, "Error opening filters!\VAR_10"); exit(1); } #endif break; case AVMEDIA_TYPE_SUBTITLE: ost->encoding_needed = 1; ist->decoding_needed = 1; break; default: abort(); break; } if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 && (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { char VAR_23[1024]; FILE *f; snprintf(VAR_23, sizeof(VAR_23), "%s-%d.log", pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, VAR_7); if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(VAR_23, "wb"); if (!f) { fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\VAR_10", VAR_23, strerror(errno)); ffmpeg_exit(1); } ost->logfile = f; } else { char *VAR_24; size_t logbuffer_size; if (read_file(VAR_23, &VAR_24, &logbuffer_size) < 0) { fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\VAR_10", VAR_23); ffmpeg_exit(1); } codec->stats_in = VAR_24; } } } if(codec->codec_type == AVMEDIA_TYPE_VIDEO){ int VAR_25= codec->width * codec->height; bit_buffer_size= FFMAX(bit_buffer_size, 6*VAR_25 + 1664); } } if (!bit_buffer) bit_buffer = av_malloc(bit_buffer_size); if (!bit_buffer) { fprintf(stderr, "Cannot allocate %d bytes output buffer\VAR_10", bit_buffer_size); VAR_6 = AVERROR(ENOMEM); goto fail; } for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; if (ost->encoding_needed) { AVCodec *codec = ost->enc; AVCodecContext *dec = input_streams[ost->source_index].st->codec; if (!codec) { snprintf(VAR_13, sizeof(VAR_13), "Encoder (codec id %d) not found for output stream #%d.%d", ost->st->codec->codec_id, ost->file_index, ost->index); VAR_6 = AVERROR(EINVAL); goto dump_format; } if (dec->subtitle_header) { ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); if (!ost->st->codec->subtitle_header) { VAR_6 = AVERROR(ENOMEM); goto dump_format; } memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); ost->st->codec->subtitle_header_size = dec->subtitle_header_size; } if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) { snprintf(VAR_13, sizeof(VAR_13), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ost->file_index, ost->index); VAR_6 = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ost->st->codec, 1); assert_avoptions(ost->opts); if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\VAR_10"); extra_size += ost->st->codec->extradata_size; } } for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) { ist = &input_streams[VAR_7]; if (ist->decoding_needed) { AVCodec *codec = ist->dec; if (!codec) codec = avcodec_find_decoder(ist->st->codec->codec_id); if (!codec) { snprintf(VAR_13, sizeof(VAR_13), "Decoder (codec id %d) not found for input stream #%d.%d", ist->st->codec->codec_id, ist->file_index, ist->st->index); VAR_6 = AVERROR(EINVAL); goto dump_format; } if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { snprintf(VAR_13, sizeof(VAR_13), "Error while opening decoder for input stream #%d.%d", ist->file_index, ist->st->index); VAR_6 = AVERROR(EINVAL); goto dump_format; } assert_codec_experimental(ist->st->codec, 0); assert_avoptions(ost->opts); } } for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) { AVStream *st; ist = &input_streams[VAR_7]; st= ist->st; ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; ist->next_pts = AV_NOPTS_VALUE; ist->is_start = 1; } for (VAR_7=0;VAR_7<nb_meta_data_maps;VAR_7++) { AVFormatContext *files[2]; AVDictionary **meta[2]; int VAR_8; #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ snprintf(VAR_13, sizeof(VAR_13), "Invalid %s index %d while processing metadata maps\VAR_10",\ (desc), (index));\ VAR_6 = AVERROR(EINVAL);\ goto dump_format;\ } int out_file_index = meta_data_maps[VAR_7][0].file; int in_file_index = meta_data_maps[VAR_7][1].file; if (in_file_index < 0 || out_file_index < 0) continue; METADATA_CHECK_INDEX(out_file_index, VAR_1, "output file") METADATA_CHECK_INDEX(in_file_index, VAR_3, "input file") files[0] = VAR_0[out_file_index]; files[1] = VAR_2[in_file_index].ctx; for (VAR_8 = 0; VAR_8 < 2; VAR_8++) { MetadataMap *map = &meta_data_maps[VAR_7][VAR_8]; switch (map->type) { case 'g': meta[VAR_8] = &files[VAR_8]->metadata; break; case 's': METADATA_CHECK_INDEX(map->index, files[VAR_8]->VAR_18, "stream") meta[VAR_8] = &files[VAR_8]->streams[map->index]->metadata; break; case 'c': METADATA_CHECK_INDEX(map->index, files[VAR_8]->nb_chapters, "chapter") meta[VAR_8] = &files[VAR_8]->chapters[map->index]->metadata; break; case 'p': METADATA_CHECK_INDEX(map->index, files[VAR_8]->nb_programs, "program") meta[VAR_8] = &files[VAR_8]->programs[map->index]->metadata; break; } } av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE); } if (metadata_global_autocopy) { for (VAR_7 = 0; VAR_7 < VAR_1; VAR_7++) av_dict_copy(&VAR_0[VAR_7]->metadata, VAR_2[0].ctx->metadata, AV_DICT_DONT_OVERWRITE); } for (VAR_7 = 0; VAR_7 < nb_chapter_maps; VAR_7++) { int infile = chapter_maps[VAR_7].in_file; int outfile = chapter_maps[VAR_7].out_file; if (infile < 0 || outfile < 0) continue; if (infile >= VAR_3) { snprintf(VAR_13, sizeof(VAR_13), "Invalid input file index %d in chapter mapping.\VAR_10", infile); VAR_6 = AVERROR(EINVAL); goto dump_format; } if (outfile >= VAR_1) { snprintf(VAR_13, sizeof(VAR_13), "Invalid output file index %d in chapter mapping.\VAR_10",outfile); VAR_6 = AVERROR(EINVAL); goto dump_format; } copy_chapters(infile, outfile); } if (!nb_chapter_maps) for (VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) { if (!VAR_2[VAR_7].ctx->nb_chapters) continue; for (VAR_8 = 0; VAR_8 < VAR_1; VAR_8++) if ((VAR_6 = copy_chapters(VAR_7, VAR_8)) < 0) goto dump_format; break; } for(VAR_7=0;VAR_7<VAR_1;VAR_7++) { os = VAR_0[VAR_7]; if (avformat_write_header(os, &output_opts[VAR_7]) < 0) { snprintf(VAR_13, sizeof(VAR_13), "Could not write header for output file #%d (incorrect codec parameters ?)", VAR_7); VAR_6 = AVERROR(EINVAL); goto dump_format; } assert_avoptions(output_opts[VAR_7]); if (strcmp(VAR_0[VAR_7]->oformat->name, "rtp")) { VAR_15 = 0; } } dump_format: for(VAR_7=0;VAR_7<VAR_1;VAR_7++) { av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1); } if (verbose >= 0) { fprintf(stderr, "Stream mapping:\VAR_10"); for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; fprintf(stderr, " Stream #%d.%d -> #%d.%d", input_streams[ost->source_index].file_index, input_streams[ost->source_index].st->index, ost->file_index, ost->index); if (ost->sync_ist != &input_streams[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); fprintf(stderr, "\VAR_10"); } } if (VAR_6) { fprintf(stderr, "%s\VAR_10", VAR_13); goto fail; } if (VAR_15) { print_sdp(VAR_0, VAR_1); } if (!using_stdin) { if(verbose >= 0) fprintf(stderr, "Press [q] to stop, [?] for help\VAR_10"); avio_set_interrupt_cb(decode_interrupt_cb); } term_init(); timer_start = av_gettime(); for(; received_sigterm == 0;) { int file_index, ist_index; AVPacket pkt; double ipts_min; double opts_min; redo: ipts_min= 1e100; opts_min= 1e100; if (!using_stdin) { if (q_pressed) break; VAR_14 = read_key(); if (VAR_14 == 'q') break; if (VAR_14 == '+') verbose++; if (VAR_14 == '-') verbose--; if (VAR_14 == 's') qp_hist ^= 1; if (VAR_14 == 'h'){ if (do_hex_dump){ do_hex_dump = do_pkt_dump = 0; } else if(do_pkt_dump){ do_hex_dump = 1; } else do_pkt_dump = 1; av_log_set_level(AV_LOG_DEBUG); } if (VAR_14 == 'd' || VAR_14 == 'D'){ int debug=0; if(VAR_14 == 'D') { debug = input_streams[0].st->codec->debug<<1; if(!debug) debug = 1; while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) debug += debug; }else scanf("%d", &debug); for(VAR_7=0;VAR_7<nb_input_streams;VAR_7++) { input_streams[VAR_7].st->codec->debug = debug; } for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; ost->st->codec->debug = debug; } if(debug) av_log_set_level(AV_LOG_DEBUG); fprintf(stderr,"debug=%d\VAR_10", debug); } if (VAR_14 == '?'){ fprintf(stderr, "VAR_14 function\VAR_10" "? show this help\VAR_10" "+ increase verbosity\VAR_10" "- decrease verbosity\VAR_10" "D cycle through available debug modes\VAR_10" "h dump packets/hex press to cycle through the 3 states\VAR_10" "q quit\VAR_10" "s Show QP histogram\VAR_10" ); } } file_index = -1; for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { double ipts, opts; ost = ost_table[VAR_7]; os = VAR_0[ost->file_index]; ist = &input_streams[ost->source_index]; if(ist->is_past_recording_time || no_packet[ist->file_index]) continue; opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = (double)ist->pts; if (!VAR_2[ist->file_index].eof_reached){ if(ipts < ipts_min) { ipts_min = ipts; if(input_sync ) file_index = ist->file_index; } if(opts < opts_min) { opts_min = opts; if(!input_sync) file_index = ist->file_index; } } if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){ file_index= -1; break; } } if (file_index < 0) { if(VAR_16){ VAR_16=0; memset(no_packet, 0, sizeof(no_packet)); usleep(10000); continue; } break; } if (limit_filesize != 0 && limit_filesize <= avio_tell(VAR_0[0]->pb)) break; is = VAR_2[file_index].ctx; VAR_6= av_read_frame(is, &pkt); if(VAR_6 == AVERROR(EAGAIN)){ no_packet[file_index]=1; VAR_16++; continue; } if (VAR_6 < 0) { VAR_2[file_index].eof_reached = 1; if (opt_shortest) break; else continue; } VAR_16=0; memset(no_packet, 0, sizeof(no_packet)); if (do_pkt_dump) { av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, is->streams[pkt.stream_index]); } if (pkt.stream_index >= VAR_2[file_index].ctx->VAR_18) goto discard_packet; ist_index = VAR_2[file_index].ist_index + pkt.stream_index; ist = &input_streams[ist_index]; if (ist->discard) goto discard_packet; if (pkt.dts != AV_NOPTS_VALUE) pkt.dts += av_rescale_q(VAR_2[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts += av_rescale_q(VAR_2[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (ist->ts_scale) { if(pkt.pts != AV_NOPTS_VALUE) pkt.pts *= ist->ts_scale; if(pkt.dts != AV_NOPTS_VALUE) pkt.dts *= ist->ts_scale; } if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE && (is->iformat->flags & AVFMT_TS_DISCONT)) { int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); int64_t delta= pkt_dts - ist->next_pts; if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){ VAR_2[ist->file_index].ts_offset -= delta; if (verbose > 2) fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\VAR_10", delta, VAR_2[ist->file_index].ts_offset); pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if(pkt.pts != AV_NOPTS_VALUE) pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } if (recording_time != INT64_MAX && (pkt.pts != AV_NOPTS_VALUE ? av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) : av_compare_ts(ist->pts, AV_TIME_BASE_Q, recording_time + start_time, (AVRational){1, 1000000}) )>= 0) { ist->is_past_recording_time = 1; goto discard_packet; } if (output_packet(ist, ist_index, ost_table, VAR_11, &pkt) < 0) { if (verbose >= 0) fprintf(stderr, "Error while decoding stream #%d.%d\VAR_10", ist->file_index, ist->st->index); if (exit_on_error) ffmpeg_exit(1); av_free_packet(&pkt); goto redo; } discard_packet: av_free_packet(&pkt); print_report(VAR_0, ost_table, VAR_11, 0); } for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) { ist = &input_streams[VAR_7]; if (ist->decoding_needed) { output_packet(ist, VAR_7, ost_table, VAR_11, NULL); } } term_exit(); for(VAR_7=0;VAR_7<VAR_1;VAR_7++) { os = VAR_0[VAR_7]; av_write_trailer(os); } print_report(VAR_0, ost_table, VAR_11, 1); for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; if (ost->encoding_needed) { av_freep(&ost->st->codec->stats_in); avcodec_close(ost->st->codec); } #if CONFIG_AVFILTER avfilter_graph_free(&ost->graph); #endif } for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) { ist = &input_streams[VAR_7]; if (ist->decoding_needed) { avcodec_close(ist->st->codec); } } VAR_6 = 0; fail: av_freep(&bit_buffer); if (ost_table) { for(VAR_7=0;VAR_7<VAR_11;VAR_7++) { ost = ost_table[VAR_7]; if (ost) { if (ost->st->stream_copy) av_freep(&ost->st->codec->extradata); if (ost->logfile) { fclose(ost->logfile); ost->logfile = NULL; } av_fifo_free(ost->fifo); av_freep(&ost->st->codec->subtitle_header); av_free(ost->resample_frame.data[0]); av_free(ost->forced_kf_pts); if (ost->video_resample) sws_freeContext(ost->img_resample_ctx); if (ost->resample) audio_resample_close(ost->resample); if (ost->reformat_ctx) av_audio_convert_free(ost->reformat_ctx); av_dict_free(&ost->opts); av_free(ost); } } av_free(ost_table); } return VAR_6; }
[ "static int FUNC_0(AVFormatContext **VAR_0,\nint VAR_1,\nInputFile *VAR_2,\nint VAR_3,\nStreamMap *VAR_4, int VAR_5)\n{", "int VAR_6 = 0, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11 = 0, VAR_12;", "AVFormatContext *is, *os;", "AVCodecContext *codec, *icodec;", "OutputStream *ost, **ost_table = NULL;", "InputStream *ist;", "char VAR_13[1024];", "int VAR_14;", "int VAR_15 = 1;", "uint8_t no_packet[MAX_FILES]={0};", "int VAR_16=0;", "int VAR_17[AVMEDIA_TYPE_NB]={0};", "int VAR_18[AVMEDIA_TYPE_NB]={0};", "if (rate_emu)\nfor (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++)", "input_streams[VAR_7].start = av_gettime();", "VAR_11 = 0;", "for(VAR_7=0;VAR_7<VAR_1;VAR_7++) {", "os = VAR_0[VAR_7];", "if (!os->VAR_18 && !(os->oformat->flags & AVFMT_NOSTREAMS)) {", "av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1);", "fprintf(stderr, \"Output file #%d does not contain any stream\\VAR_10\", VAR_7);", "VAR_6 = AVERROR(EINVAL);", "goto fail;", "}", "VAR_11 += os->VAR_18;", "}", "if (VAR_5 > 0 && VAR_5 != VAR_11) {", "fprintf(stderr, \"Number of stream maps must match number of output streams\\VAR_10\");", "VAR_6 = AVERROR(EINVAL);", "goto fail;", "}", "for(VAR_7=0;VAR_7<VAR_5;VAR_7++) {", "int VAR_19 = VAR_4[VAR_7].file_index;", "int VAR_20 = VAR_4[VAR_7].stream_index;", "if (VAR_19 < 0 || VAR_19 > VAR_3 - 1 ||\nVAR_20 < 0 || VAR_20 > VAR_2[VAR_19].ctx->VAR_18 - 1) {", "fprintf(stderr,\"Could not find input stream #%d.%d\\VAR_10\", VAR_19, VAR_20);", "VAR_6 = AVERROR(EINVAL);", "goto fail;", "}", "VAR_19 = VAR_4[VAR_7].sync_file_index;", "VAR_20 = VAR_4[VAR_7].sync_stream_index;", "if (VAR_19 < 0 || VAR_19 > VAR_3 - 1 ||\nVAR_20 < 0 || VAR_20 > VAR_2[VAR_19].ctx->VAR_18 - 1) {", "fprintf(stderr,\"Could not find sync stream #%d.%d\\VAR_10\", VAR_19, VAR_20);", "VAR_6 = AVERROR(EINVAL);", "goto fail;", "}", "}", "ost_table = av_mallocz(sizeof(OutputStream *) * VAR_11);", "if (!ost_table)\ngoto fail;", "for(VAR_9=0;VAR_9<VAR_1;VAR_9++) {", "os = VAR_0[VAR_9];", "for(VAR_7=0;VAR_7<os->VAR_18;VAR_7++,VAR_10++) {", "VAR_18[os->streams[VAR_7]->codec->codec_type]++;", "}", "}", "for(VAR_12=1<<30; VAR_12; VAR_12>>=1){", "int VAR_21[AVMEDIA_TYPE_NB]={0};", "for(VAR_8=0; VAR_8<AVMEDIA_TYPE_NB; VAR_8++)", "VAR_17[VAR_8] += VAR_12;", "for(VAR_8=0; VAR_8<nb_input_streams; VAR_8++) {", "int skip=0;", "ist = &input_streams[VAR_8];", "if(opt_programid){", "int pi,VAR_20;", "AVFormatContext *f= VAR_2[ ist->file_index ].ctx;", "skip=1;", "for(pi=0; pi<f->nb_programs; pi++){", "AVProgram *p= f->programs[pi];", "if(p->id == opt_programid)\nfor(VAR_20=0; VAR_20<p->nb_stream_indexes; VAR_20++){", "if(f->streams[ p->stream_index[VAR_20] ] == ist->st)\nskip=0;", "}", "}", "}", "if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip\n&& VAR_17[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){", "VAR_21[ist->st->codec->codec_type]++;", "}", "}", "for(VAR_8=0; VAR_8<AVMEDIA_TYPE_NB; VAR_8++)", "if(VAR_21[VAR_8] < VAR_18[VAR_8])\nVAR_17[VAR_8] -= VAR_12;", "}", "VAR_10 = 0;", "for(VAR_9=0;VAR_9<VAR_1;VAR_9++) {", "os = VAR_0[VAR_9];", "for(VAR_7=0;VAR_7<os->VAR_18;VAR_7++,VAR_10++) {", "int found;", "ost = ost_table[VAR_10] = output_streams_for_file[VAR_9][VAR_7];", "if (VAR_5 > 0) {", "ost->source_index = VAR_2[VAR_4[VAR_10].file_index].ist_index +\nVAR_4[VAR_10].stream_index;", "if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) {", "int VAR_7= ost->file_index;", "av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1);", "fprintf(stderr, \"Codec type mismatch for mapping #%d.%d -> #%d.%d\\VAR_10\",\nVAR_4[VAR_10].file_index, VAR_4[VAR_10].stream_index,\nost->file_index, ost->index);", "ffmpeg_exit(1);", "}", "} else {", "found = 0;", "for (VAR_8 = 0; VAR_8 < nb_input_streams; VAR_8++) {", "int skip=0;", "ist = &input_streams[VAR_8];", "if(opt_programid){", "int pi,VAR_20;", "AVFormatContext *f = VAR_2[ist->file_index].ctx;", "skip=1;", "for(pi=0; pi<f->nb_programs; pi++){", "AVProgram *p= f->programs[pi];", "if(p->id == opt_programid)\nfor(VAR_20=0; VAR_20<p->nb_stream_indexes; VAR_20++){", "if(f->streams[ p->stream_index[VAR_20] ] == ist->st)\nskip=0;", "}", "}", "}", "if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&\nist->st->codec->codec_type == ost->st->codec->codec_type &&\nVAR_17[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) {", "ost->source_index = VAR_8;", "found = 1;", "break;", "}", "}", "if (!found) {", "if(! opt_programid) {", "for (VAR_8 = 0; VAR_8 < nb_input_streams; VAR_8++) {", "ist = &input_streams[VAR_8];", "if ( ist->st->codec->codec_type == ost->st->codec->codec_type\n&& ist->st->discard != AVDISCARD_ALL) {", "ost->source_index = VAR_8;", "found = 1;", "}", "}", "}", "if (!found) {", "int VAR_7= ost->file_index;", "av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1);", "fprintf(stderr, \"Could not find input stream matching output stream #%d.%d\\VAR_10\",\nost->file_index, ost->index);", "ffmpeg_exit(1);", "}", "}", "}", "ist = &input_streams[ost->source_index];", "ist->discard = 0;", "ost->sync_ist = (VAR_5 > 0) ?\n&input_streams[VAR_2[VAR_4[VAR_10].sync_file_index].ist_index +\nVAR_4[VAR_10].sync_stream_index] : ist;", "}", "}", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "os = VAR_0[ost->file_index];", "ist = &input_streams[ost->source_index];", "codec = ost->st->codec;", "icodec = ist->st->codec;", "if (metadata_streams_autocopy)\nav_dict_copy(&ost->st->metadata, ist->st->metadata,\nAV_DICT_DONT_OVERWRITE);", "ost->st->disposition = ist->st->disposition;", "codec->bits_per_raw_sample= icodec->bits_per_raw_sample;", "codec->chroma_sample_location = icodec->chroma_sample_location;", "if (ost->st->stream_copy) {", "uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;", "if (extra_size > INT_MAX)\ngoto fail;", "codec->codec_id = icodec->codec_id;", "codec->codec_type = icodec->codec_type;", "if(!codec->codec_tag){", "if( !os->oformat->codec_tag\n|| av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id\n|| av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0)\ncodec->codec_tag = icodec->codec_tag;", "}", "codec->bit_rate = icodec->bit_rate;", "codec->rc_max_rate = icodec->rc_max_rate;", "codec->rc_buffer_size = icodec->rc_buffer_size;", "codec->extradata= av_mallocz(extra_size);", "if (!codec->extradata)\ngoto fail;", "memcpy(codec->extradata, icodec->extradata, icodec->extradata_size);", "codec->extradata_size= icodec->extradata_size;", "if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){", "codec->time_base = icodec->time_base;", "codec->time_base.num *= icodec->ticks_per_frame;", "av_reduce(&codec->time_base.num, &codec->time_base.den,\ncodec->time_base.num, codec->time_base.den, INT_MAX);", "}else", "codec->time_base = ist->st->time_base;", "switch(codec->codec_type) {", "case AVMEDIA_TYPE_AUDIO:\nif(audio_volume != 256) {", "fprintf(stderr,\"-acodec copy and -vol are incompatible (frames are not decoded)\\VAR_10\");", "ffmpeg_exit(1);", "}", "codec->channel_layout = icodec->channel_layout;", "codec->sample_rate = icodec->sample_rate;", "codec->channels = icodec->channels;", "codec->frame_size = icodec->frame_size;", "codec->audio_service_type = icodec->audio_service_type;", "codec->block_align= icodec->block_align;", "if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)\ncodec->block_align= 0;", "if(codec->codec_id == CODEC_ID_AC3)\ncodec->block_align= 0;", "break;", "case AVMEDIA_TYPE_VIDEO:\ncodec->pix_fmt = icodec->pix_fmt;", "codec->width = icodec->width;", "codec->height = icodec->height;", "codec->has_b_frames = icodec->has_b_frames;", "if (!codec->sample_aspect_ratio.num) {", "codec->sample_aspect_ratio =\nost->st->sample_aspect_ratio =\nist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :\nist->st->codec->sample_aspect_ratio.num ?\nist->st->codec->sample_aspect_ratio : (AVRational){0, 1};", "}", "break;", "case AVMEDIA_TYPE_SUBTITLE:\ncodec->width = icodec->width;", "codec->height = icodec->height;", "break;", "case AVMEDIA_TYPE_DATA:\nbreak;", "default:\nabort();", "}", "} else {", "if (!ost->enc)\nost->enc = avcodec_find_encoder(ost->st->codec->codec_id);", "switch(codec->codec_type) {", "case AVMEDIA_TYPE_AUDIO:\nost->fifo= av_fifo_alloc(1024);", "if(!ost->fifo)\ngoto fail;", "ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);", "if (!codec->sample_rate) {", "codec->sample_rate = icodec->sample_rate;", "if (icodec->lowres)\ncodec->sample_rate >>= icodec->lowres;", "}", "choose_sample_rate(ost->st, ost->enc);", "codec->time_base = (AVRational){1, codec->sample_rate};", "if (codec->sample_fmt == AV_SAMPLE_FMT_NONE)\ncodec->sample_fmt = icodec->sample_fmt;", "choose_sample_fmt(ost->st, ost->enc);", "if (!codec->channels) {", "codec->channels = icodec->channels;", "codec->channel_layout = icodec->channel_layout;", "}", "if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)\ncodec->channel_layout = 0;", "ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;", "icodec->request_channels = codec->channels;", "ist->decoding_needed = 1;", "ost->encoding_needed = 1;", "ost->resample_sample_fmt = icodec->sample_fmt;", "ost->resample_sample_rate = icodec->sample_rate;", "ost->resample_channels = icodec->channels;", "break;", "case AVMEDIA_TYPE_VIDEO:\nif (codec->pix_fmt == PIX_FMT_NONE)\ncodec->pix_fmt = icodec->pix_fmt;", "choose_pixel_fmt(ost->st, ost->enc);", "if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {", "fprintf(stderr, \"Video pixel format is unknown, stream cannot be encoded\\VAR_10\");", "ffmpeg_exit(1);", "}", "ost->video_resample = codec->width != icodec->width ||\ncodec->height != icodec->height ||\ncodec->pix_fmt != icodec->pix_fmt;", "if (ost->video_resample) {", "codec->bits_per_raw_sample= frame_bits_per_raw_sample;", "}", "if (!codec->width || !codec->height) {", "codec->width = icodec->width;", "codec->height = icodec->height;", "}", "ost->resample_height = icodec->height;", "ost->resample_width = icodec->width;", "ost->resample_pix_fmt= icodec->pix_fmt;", "ost->encoding_needed = 1;", "ist->decoding_needed = 1;", "if (!ost->frame_rate.num)\nost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};", "if (ost->enc && ost->enc->supported_framerates && !force_fps) {", "int VAR_22 = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);", "ost->frame_rate = ost->enc->supported_framerates[VAR_22];", "}", "codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};", "if( av_q2d(codec->time_base) < 0.001 && video_sync_method\n&& (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){", "av_log(os, AV_LOG_WARNING, \"Frame rate very high for a muxer not effciciently supporting it.\\VAR_10\"\n\"Please consider specifiying a lower framerate, a different muxer or -vsync 2\\VAR_10\");", "}", "#if CONFIG_AVFILTER\nif (configure_video_filters(ist, ost)) {", "fprintf(stderr, \"Error opening filters!\\VAR_10\");", "exit(1);", "}", "#endif\nbreak;", "case AVMEDIA_TYPE_SUBTITLE:\nost->encoding_needed = 1;", "ist->decoding_needed = 1;", "break;", "default:\nabort();", "break;", "}", "if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 &&\n(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {", "char VAR_23[1024];", "FILE *f;", "snprintf(VAR_23, sizeof(VAR_23), \"%s-%d.log\",\npass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,\nVAR_7);", "if (codec->flags & CODEC_FLAG_PASS1) {", "f = fopen(VAR_23, \"wb\");", "if (!f) {", "fprintf(stderr, \"Cannot write log file '%s' for pass-1 encoding: %s\\VAR_10\", VAR_23, strerror(errno));", "ffmpeg_exit(1);", "}", "ost->logfile = f;", "} else {", "char *VAR_24;", "size_t logbuffer_size;", "if (read_file(VAR_23, &VAR_24, &logbuffer_size) < 0) {", "fprintf(stderr, \"Error reading log file '%s' for pass-2 encoding\\VAR_10\", VAR_23);", "ffmpeg_exit(1);", "}", "codec->stats_in = VAR_24;", "}", "}", "}", "if(codec->codec_type == AVMEDIA_TYPE_VIDEO){", "int VAR_25= codec->width * codec->height;", "bit_buffer_size= FFMAX(bit_buffer_size, 6*VAR_25 + 1664);", "}", "}", "if (!bit_buffer)\nbit_buffer = av_malloc(bit_buffer_size);", "if (!bit_buffer) {", "fprintf(stderr, \"Cannot allocate %d bytes output buffer\\VAR_10\",\nbit_buffer_size);", "VAR_6 = AVERROR(ENOMEM);", "goto fail;", "}", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "if (ost->encoding_needed) {", "AVCodec *codec = ost->enc;", "AVCodecContext *dec = input_streams[ost->source_index].st->codec;", "if (!codec) {", "snprintf(VAR_13, sizeof(VAR_13), \"Encoder (codec id %d) not found for output stream #%d.%d\",\nost->st->codec->codec_id, ost->file_index, ost->index);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "if (dec->subtitle_header) {", "ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size);", "if (!ost->st->codec->subtitle_header) {", "VAR_6 = AVERROR(ENOMEM);", "goto dump_format;", "}", "memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);", "ost->st->codec->subtitle_header_size = dec->subtitle_header_size;", "}", "if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) {", "snprintf(VAR_13, sizeof(VAR_13), \"Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\",\nost->file_index, ost->index);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "assert_codec_experimental(ost->st->codec, 1);", "assert_avoptions(ost->opts);", "if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000)\nav_log(NULL, AV_LOG_WARNING, \"The bitrate parameter is set too low.\"\n\"It takes bits/s as argument, not kbits/s\\VAR_10\");", "extra_size += ost->st->codec->extradata_size;", "}", "}", "for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) {", "ist = &input_streams[VAR_7];", "if (ist->decoding_needed) {", "AVCodec *codec = ist->dec;", "if (!codec)\ncodec = avcodec_find_decoder(ist->st->codec->codec_id);", "if (!codec) {", "snprintf(VAR_13, sizeof(VAR_13), \"Decoder (codec id %d) not found for input stream #%d.%d\",\nist->st->codec->codec_id, ist->file_index, ist->st->index);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) {", "snprintf(VAR_13, sizeof(VAR_13), \"Error while opening decoder for input stream #%d.%d\",\nist->file_index, ist->st->index);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "assert_codec_experimental(ist->st->codec, 0);", "assert_avoptions(ost->opts);", "}", "}", "for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) {", "AVStream *st;", "ist = &input_streams[VAR_7];", "st= ist->st;", "ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0;", "ist->next_pts = AV_NOPTS_VALUE;", "ist->is_start = 1;", "}", "for (VAR_7=0;VAR_7<nb_meta_data_maps;VAR_7++) {", "AVFormatContext *files[2];", "AVDictionary **meta[2];", "int VAR_8;", "#define METADATA_CHECK_INDEX(index, nb_elems, desc)\\\nif ((index) < 0 || (index) >= (nb_elems)) {\\", "snprintf(VAR_13, sizeof(VAR_13), \"Invalid %s index %d while processing metadata maps\\VAR_10\",\\\n(desc), (index));\\", "VAR_6 = AVERROR(EINVAL);\\", "goto dump_format;\\", "}", "int out_file_index = meta_data_maps[VAR_7][0].file;", "int in_file_index = meta_data_maps[VAR_7][1].file;", "if (in_file_index < 0 || out_file_index < 0)\ncontinue;", "METADATA_CHECK_INDEX(out_file_index, VAR_1, \"output file\")\nMETADATA_CHECK_INDEX(in_file_index, VAR_3, \"input file\")\nfiles[0] = VAR_0[out_file_index];", "files[1] = VAR_2[in_file_index].ctx;", "for (VAR_8 = 0; VAR_8 < 2; VAR_8++) {", "MetadataMap *map = &meta_data_maps[VAR_7][VAR_8];", "switch (map->type) {", "case 'g':\nmeta[VAR_8] = &files[VAR_8]->metadata;", "break;", "case 's':\nMETADATA_CHECK_INDEX(map->index, files[VAR_8]->VAR_18, \"stream\")\nmeta[VAR_8] = &files[VAR_8]->streams[map->index]->metadata;", "break;", "case 'c':\nMETADATA_CHECK_INDEX(map->index, files[VAR_8]->nb_chapters, \"chapter\")\nmeta[VAR_8] = &files[VAR_8]->chapters[map->index]->metadata;", "break;", "case 'p':\nMETADATA_CHECK_INDEX(map->index, files[VAR_8]->nb_programs, \"program\")\nmeta[VAR_8] = &files[VAR_8]->programs[map->index]->metadata;", "break;", "}", "}", "av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);", "}", "if (metadata_global_autocopy) {", "for (VAR_7 = 0; VAR_7 < VAR_1; VAR_7++)", "av_dict_copy(&VAR_0[VAR_7]->metadata, VAR_2[0].ctx->metadata,\nAV_DICT_DONT_OVERWRITE);", "}", "for (VAR_7 = 0; VAR_7 < nb_chapter_maps; VAR_7++) {", "int infile = chapter_maps[VAR_7].in_file;", "int outfile = chapter_maps[VAR_7].out_file;", "if (infile < 0 || outfile < 0)\ncontinue;", "if (infile >= VAR_3) {", "snprintf(VAR_13, sizeof(VAR_13), \"Invalid input file index %d in chapter mapping.\\VAR_10\", infile);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "if (outfile >= VAR_1) {", "snprintf(VAR_13, sizeof(VAR_13), \"Invalid output file index %d in chapter mapping.\\VAR_10\",outfile);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "copy_chapters(infile, outfile);", "}", "if (!nb_chapter_maps)\nfor (VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) {", "if (!VAR_2[VAR_7].ctx->nb_chapters)\ncontinue;", "for (VAR_8 = 0; VAR_8 < VAR_1; VAR_8++)", "if ((VAR_6 = copy_chapters(VAR_7, VAR_8)) < 0)\ngoto dump_format;", "break;", "}", "for(VAR_7=0;VAR_7<VAR_1;VAR_7++) {", "os = VAR_0[VAR_7];", "if (avformat_write_header(os, &output_opts[VAR_7]) < 0) {", "snprintf(VAR_13, sizeof(VAR_13), \"Could not write header for output file #%d (incorrect codec parameters ?)\", VAR_7);", "VAR_6 = AVERROR(EINVAL);", "goto dump_format;", "}", "assert_avoptions(output_opts[VAR_7]);", "if (strcmp(VAR_0[VAR_7]->oformat->name, \"rtp\")) {", "VAR_15 = 0;", "}", "}", "dump_format:\nfor(VAR_7=0;VAR_7<VAR_1;VAR_7++) {", "av_dump_format(VAR_0[VAR_7], VAR_7, VAR_0[VAR_7]->filename, 1);", "}", "if (verbose >= 0) {", "fprintf(stderr, \"Stream mapping:\\VAR_10\");", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "fprintf(stderr, \" Stream #%d.%d -> #%d.%d\",\ninput_streams[ost->source_index].file_index,\ninput_streams[ost->source_index].st->index,\nost->file_index,\nost->index);", "if (ost->sync_ist != &input_streams[ost->source_index])\nfprintf(stderr, \" [sync #%d.%d]\",\nost->sync_ist->file_index,\nost->sync_ist->st->index);", "fprintf(stderr, \"\\VAR_10\");", "}", "}", "if (VAR_6) {", "fprintf(stderr, \"%s\\VAR_10\", VAR_13);", "goto fail;", "}", "if (VAR_15) {", "print_sdp(VAR_0, VAR_1);", "}", "if (!using_stdin) {", "if(verbose >= 0)\nfprintf(stderr, \"Press [q] to stop, [?] for help\\VAR_10\");", "avio_set_interrupt_cb(decode_interrupt_cb);", "}", "term_init();", "timer_start = av_gettime();", "for(; received_sigterm == 0;) {", "int file_index, ist_index;", "AVPacket pkt;", "double ipts_min;", "double opts_min;", "redo:\nipts_min= 1e100;", "opts_min= 1e100;", "if (!using_stdin) {", "if (q_pressed)\nbreak;", "VAR_14 = read_key();", "if (VAR_14 == 'q')\nbreak;", "if (VAR_14 == '+') verbose++;", "if (VAR_14 == '-') verbose--;", "if (VAR_14 == 's') qp_hist ^= 1;", "if (VAR_14 == 'h'){", "if (do_hex_dump){", "do_hex_dump = do_pkt_dump = 0;", "} else if(do_pkt_dump){", "do_hex_dump = 1;", "} else", "do_pkt_dump = 1;", "av_log_set_level(AV_LOG_DEBUG);", "}", "if (VAR_14 == 'd' || VAR_14 == 'D'){", "int debug=0;", "if(VAR_14 == 'D') {", "debug = input_streams[0].st->codec->debug<<1;", "if(!debug) debug = 1;", "while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE))\ndebug += debug;", "}else", "scanf(\"%d\", &debug);", "for(VAR_7=0;VAR_7<nb_input_streams;VAR_7++) {", "input_streams[VAR_7].st->codec->debug = debug;", "}", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "ost->st->codec->debug = debug;", "}", "if(debug) av_log_set_level(AV_LOG_DEBUG);", "fprintf(stderr,\"debug=%d\\VAR_10\", debug);", "}", "if (VAR_14 == '?'){", "fprintf(stderr, \"VAR_14 function\\VAR_10\"\n\"? show this help\\VAR_10\"\n\"+ increase verbosity\\VAR_10\"\n\"- decrease verbosity\\VAR_10\"\n\"D cycle through available debug modes\\VAR_10\"\n\"h dump packets/hex press to cycle through the 3 states\\VAR_10\"\n\"q quit\\VAR_10\"\n\"s Show QP histogram\\VAR_10\"\n);", "}", "}", "file_index = -1;", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "double ipts, opts;", "ost = ost_table[VAR_7];", "os = VAR_0[ost->file_index];", "ist = &input_streams[ost->source_index];", "if(ist->is_past_recording_time || no_packet[ist->file_index])\ncontinue;", "opts = ost->st->pts.val * av_q2d(ost->st->time_base);", "ipts = (double)ist->pts;", "if (!VAR_2[ist->file_index].eof_reached){", "if(ipts < ipts_min) {", "ipts_min = ipts;", "if(input_sync ) file_index = ist->file_index;", "}", "if(opts < opts_min) {", "opts_min = opts;", "if(!input_sync) file_index = ist->file_index;", "}", "}", "if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){", "file_index= -1;", "break;", "}", "}", "if (file_index < 0) {", "if(VAR_16){", "VAR_16=0;", "memset(no_packet, 0, sizeof(no_packet));", "usleep(10000);", "continue;", "}", "break;", "}", "if (limit_filesize != 0 && limit_filesize <= avio_tell(VAR_0[0]->pb))\nbreak;", "is = VAR_2[file_index].ctx;", "VAR_6= av_read_frame(is, &pkt);", "if(VAR_6 == AVERROR(EAGAIN)){", "no_packet[file_index]=1;", "VAR_16++;", "continue;", "}", "if (VAR_6 < 0) {", "VAR_2[file_index].eof_reached = 1;", "if (opt_shortest)\nbreak;", "else\ncontinue;", "}", "VAR_16=0;", "memset(no_packet, 0, sizeof(no_packet));", "if (do_pkt_dump) {", "av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,\nis->streams[pkt.stream_index]);", "}", "if (pkt.stream_index >= VAR_2[file_index].ctx->VAR_18)\ngoto discard_packet;", "ist_index = VAR_2[file_index].ist_index + pkt.stream_index;", "ist = &input_streams[ist_index];", "if (ist->discard)\ngoto discard_packet;", "if (pkt.dts != AV_NOPTS_VALUE)\npkt.dts += av_rescale_q(VAR_2[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);", "if (pkt.pts != AV_NOPTS_VALUE)\npkt.pts += av_rescale_q(VAR_2[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);", "if (ist->ts_scale) {", "if(pkt.pts != AV_NOPTS_VALUE)\npkt.pts *= ist->ts_scale;", "if(pkt.dts != AV_NOPTS_VALUE)\npkt.dts *= ist->ts_scale;", "}", "if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE\n&& (is->iformat->flags & AVFMT_TS_DISCONT)) {", "int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);", "int64_t delta= pkt_dts - ist->next_pts;", "if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){", "VAR_2[ist->file_index].ts_offset -= delta;", "if (verbose > 2)\nfprintf(stderr, \"timestamp discontinuity %\"PRId64\", new offset= %\"PRId64\"\\VAR_10\",\ndelta, VAR_2[ist->file_index].ts_offset);", "pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);", "if(pkt.pts != AV_NOPTS_VALUE)\npkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);", "}", "}", "if (recording_time != INT64_MAX &&\n(pkt.pts != AV_NOPTS_VALUE ?\nav_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000})", ":\nav_compare_ts(ist->pts, AV_TIME_BASE_Q, recording_time + start_time, (AVRational){1, 1000000})", ")>= 0) {", "ist->is_past_recording_time = 1;", "goto discard_packet;", "}", "if (output_packet(ist, ist_index, ost_table, VAR_11, &pkt) < 0) {", "if (verbose >= 0)\nfprintf(stderr, \"Error while decoding stream #%d.%d\\VAR_10\",\nist->file_index, ist->st->index);", "if (exit_on_error)\nffmpeg_exit(1);", "av_free_packet(&pkt);", "goto redo;", "}", "discard_packet:\nav_free_packet(&pkt);", "print_report(VAR_0, ost_table, VAR_11, 0);", "}", "for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) {", "ist = &input_streams[VAR_7];", "if (ist->decoding_needed) {", "output_packet(ist, VAR_7, ost_table, VAR_11, NULL);", "}", "}", "term_exit();", "for(VAR_7=0;VAR_7<VAR_1;VAR_7++) {", "os = VAR_0[VAR_7];", "av_write_trailer(os);", "}", "print_report(VAR_0, ost_table, VAR_11, 1);", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "if (ost->encoding_needed) {", "av_freep(&ost->st->codec->stats_in);", "avcodec_close(ost->st->codec);", "}", "#if CONFIG_AVFILTER\navfilter_graph_free(&ost->graph);", "#endif\n}", "for (VAR_7 = 0; VAR_7 < nb_input_streams; VAR_7++) {", "ist = &input_streams[VAR_7];", "if (ist->decoding_needed) {", "avcodec_close(ist->st->codec);", "}", "}", "VAR_6 = 0;", "fail:\nav_freep(&bit_buffer);", "if (ost_table) {", "for(VAR_7=0;VAR_7<VAR_11;VAR_7++) {", "ost = ost_table[VAR_7];", "if (ost) {", "if (ost->st->stream_copy)\nav_freep(&ost->st->codec->extradata);", "if (ost->logfile) {", "fclose(ost->logfile);", "ost->logfile = NULL;", "}", "av_fifo_free(ost->fifo);", "av_freep(&ost->st->codec->subtitle_header);", "av_free(ost->resample_frame.data[0]);", "av_free(ost->forced_kf_pts);", "if (ost->video_resample)\nsws_freeContext(ost->img_resample_ctx);", "if (ost->resample)\naudio_resample_close(ost->resample);", "if (ost->reformat_ctx)\nav_audio_convert_free(ost->reformat_ctx);", "av_dict_free(&ost->opts);", "av_free(ost);", "}", "}", "av_free(ost_table);", "}", "return VAR_6;", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ [ 1, 3, 5, 7, 9, 11 ], [ 13 ], [ 17 ], [ 19 ], [ 21 ], [ 23 ], [ 25 ], [ 27 ], [ 29 ], [ 31 ], [ 33 ], [ 35 ], [ 37 ], [ 41, 43 ], [ 45 ], [ 51 ], [ 53 ], [ 55 ], [ 57 ], [ 59 ], [ 61 ], [ 63 ], [ 65 ], [ 67 ], [ 69 ], [ 71 ], [ 73 ], [ 75 ], [ 77 ], [ 79 ], [ 81 ], [ 87 ], [ 89 ], [ 91 ], [ 95, 97 ], [ 99 ], [ 101 ], [ 103 ], [ 105 ], [ 107 ], [ 109 ], [ 111, 113 ], [ 115 ], [ 117 ], [ 119 ], [ 121 ], [ 123 ], [ 127 ], [ 129, 131 ], [ 135 ], [ 137 ], [ 139 ], [ 141 ], [ 143 ], [ 145 ], [ 147 ], [ 149 ], [ 151 ], [ 153 ], [ 157 ], [ 159 ], [ 161 ], [ 163 ], [ 165 ], [ 167 ], [ 169 ], [ 171 ], [ 173 ], [ 175, 177 ], [ 179, 181 ], [ 183 ], [ 185 ], [ 187 ], [ 189, 191 ], [ 193 ], [ 195 ], [ 197 ], [ 199 ], [ 201, 203 ], [ 205 ], [ 207 ], [ 209 ], [ 211 ], [ 213 ], [ 215 ], [ 217 ], [ 219 ], [ 221, 223 ], [ 229 ], [ 231 ], [ 233 ], [ 235, 237, 239 ], [ 241 ], [ 243 ], [ 247 ], [ 251 ], [ 253 ], [ 255 ], [ 257 ], [ 259 ], [ 261 ], [ 263 ], [ 265 ], [ 267 ], [ 269 ], [ 271, 273 ], [ 275, 277 ], [ 279 ], [ 281 ], [ 283 ], [ 285, 287, 289 ], [ 291 ], [ 293 ], [ 295 ], [ 297 ], [ 299 ], [ 303 ], [ 305 ], [ 309 ], [ 311 ], [ 313, 315 ], [ 317 ], [ 319 ], [ 321 ], [ 323 ], [ 325 ], [ 327 ], [ 329 ], [ 331 ], [ 333, 335 ], [ 337 ], [ 339 ], [ 341 ], [ 343 ], [ 345 ], [ 347 ], [ 349, 351, 353 ], [ 355 ], [ 357 ], [ 363 ], [ 365 ], [ 367 ], [ 369 ], [ 373 ], [ 375 ], [ 379, 381, 383 ], [ 387 ], [ 389 ], [ 391 ], [ 395 ], [ 397 ], [ 401, 403 ], [ 409 ], [ 411 ], [ 415 ], [ 417, 419, 421, 423 ], [ 425 ], [ 429 ], [ 431 ], [ 433 ], [ 435 ], [ 437, 439 ], [ 441 ], [ 443 ], [ 445 ], [ 447 ], [ 449 ], [ 451, 453 ], [ 455 ], [ 457 ], [ 459 ], [ 461, 463 ], [ 465 ], [ 467 ], [ 469 ], [ 471 ], [ 473 ], [ 475 ], [ 477 ], [ 479 ], [ 481 ], [ 483, 485 ], [ 487, 489 ], [ 491 ], [ 493, 495 ], [ 497 ], [ 499 ], [ 501 ], [ 503 ], [ 505, 507, 509, 511, 513 ], [ 515 ], [ 517 ], [ 519, 521 ], [ 523 ], [ 525 ], [ 527, 529 ], [ 531, 533 ], [ 535 ], [ 537 ], [ 539, 541 ], [ 543 ], [ 545, 547 ], [ 549, 551 ], [ 553 ], [ 555 ], [ 557 ], [ 559, 561 ], [ 563 ], [ 565 ], [ 567 ], [ 569, 571 ], [ 573 ], [ 575 ], [ 577 ], [ 579 ], [ 581 ], [ 583, 585 ], [ 587 ], [ 589 ], [ 591 ], [ 593 ], [ 595 ], [ 597 ], [ 599 ], [ 601 ], [ 603, 605, 607 ], [ 609 ], [ 613 ], [ 615 ], [ 617 ], [ 619 ], [ 621, 623, 625 ], [ 627 ], [ 629 ], [ 631 ], [ 633 ], [ 635 ], [ 637 ], [ 639 ], [ 641 ], [ 643 ], [ 645 ], [ 647 ], [ 649 ], [ 653, 655 ], [ 657 ], [ 659 ], [ 661 ], [ 663 ], [ 665 ], [ 667, 669 ], [ 671, 673 ], [ 675 ], [ 679, 681 ], [ 683 ], [ 685 ], [ 687 ], [ 689, 691 ], [ 693, 695 ], [ 697 ], [ 699 ], [ 701, 703 ], [ 705 ], [ 707 ], [ 711, 713 ], [ 715 ], [ 717 ], [ 721, 723, 725 ], [ 727 ], [ 729 ], [ 731 ], [ 733 ], [ 735 ], [ 737 ], [ 739 ], [ 741 ], [ 743 ], [ 745 ], [ 747 ], [ 749 ], [ 751 ], [ 753 ], [ 755 ], [ 757 ], [ 759 ], [ 761 ], [ 763 ], [ 767 ], [ 769 ], [ 771 ], [ 773 ], [ 777, 779 ], [ 781 ], [ 783, 785 ], [ 787 ], [ 789 ], [ 791 ], [ 797 ], [ 799 ], [ 801 ], [ 803 ], [ 805 ], [ 807 ], [ 809, 811 ], [ 813 ], [ 815 ], [ 817 ], [ 819 ], [ 821 ], [ 823 ], [ 825 ], [ 827 ], [ 829 ], [ 831 ], [ 833 ], [ 835 ], [ 837 ], [ 839, 841 ], [ 843 ], [ 845 ], [ 847 ], [ 849 ], [ 851 ], [ 853, 855, 857 ], [ 859 ], [ 861 ], [ 863 ], [ 869 ], [ 871 ], [ 873 ], [ 875 ], [ 877, 879 ], [ 881 ], [ 883, 885 ], [ 887 ], [ 889 ], [ 891 ], [ 893 ], [ 895, 897 ], [ 899 ], [ 901 ], [ 903 ], [ 905 ], [ 907 ], [ 913 ], [ 915 ], [ 921 ], [ 923 ], [ 925 ], [ 927 ], [ 929 ], [ 931 ], [ 933 ], [ 935 ], [ 941 ], [ 943 ], [ 945 ], [ 947 ], [ 951, 953 ], [ 955, 957 ], [ 959 ], [ 961 ], [ 963 ], [ 967 ], [ 969 ], [ 971, 973 ], [ 975, 977, 981 ], [ 983 ], [ 987 ], [ 989 ], [ 993 ], [ 995, 997 ], [ 999 ], [ 1001, 1003, 1005 ], [ 1007 ], [ 1009, 1011, 1013 ], [ 1015 ], [ 1017, 1019, 1021 ], [ 1023 ], [ 1025 ], [ 1027 ], [ 1031 ], [ 1033 ], [ 1039 ], [ 1043 ], [ 1045, 1047 ], [ 1049 ], [ 1055 ], [ 1057 ], [ 1059 ], [ 1063, 1065 ], [ 1067 ], [ 1069 ], [ 1071 ], [ 1073 ], [ 1075 ], [ 1077 ], [ 1079 ], [ 1081 ], [ 1083 ], [ 1085 ], [ 1087 ], [ 1089 ], [ 1095, 1097 ], [ 1099, 1101 ], [ 1105 ], [ 1107, 1109 ], [ 1111 ], [ 1113 ], [ 1119 ], [ 1121 ], [ 1123 ], [ 1125 ], [ 1127 ], [ 1129 ], [ 1131 ], [ 1133 ], [ 1135 ], [ 1137 ], [ 1139 ], [ 1141 ], [ 1145, 1151 ], [ 1153 ], [ 1155 ], [ 1161 ], [ 1163 ], [ 1165 ], [ 1167 ], [ 1169, 1171, 1173, 1175, 1177 ], [ 1179, 1181, 1183, 1185 ], [ 1187 ], [ 1189 ], [ 1191 ], [ 1195 ], [ 1197 ], [ 1199 ], [ 1201 ], [ 1205 ], [ 1207 ], [ 1209 ], [ 1213 ], [ 1215, 1217 ], [ 1219 ], [ 1221 ], [ 1223 ], [ 1227 ], [ 1231 ], [ 1233 ], [ 1235 ], [ 1237 ], [ 1239 ], [ 1243, 1245 ], [ 1247 ], [ 1251 ], [ 1253, 1255 ], [ 1259 ], [ 1261, 1263 ], [ 1265 ], [ 1267 ], [ 1269 ], [ 1271 ], [ 1273 ], [ 1275 ], [ 1277 ], [ 1279 ], [ 1281 ], [ 1283 ], [ 1285 ], [ 1287 ], [ 1289 ], [ 1291 ], [ 1293 ], [ 1295 ], [ 1297 ], [ 1299, 1301 ], [ 1303 ], [ 1305 ], [ 1307 ], [ 1309 ], [ 1311 ], [ 1313 ], [ 1315 ], [ 1317 ], [ 1319 ], [ 1321 ], [ 1323 ], [ 1325 ], [ 1327 ], [ 1329, 1331, 1333, 1335, 1337, 1339, 1341, 1343, 1345 ], [ 1347 ], [ 1349 ], [ 1357 ], [ 1359 ], [ 1361 ], [ 1363 ], [ 1365 ], [ 1367 ], [ 1369, 1371 ], [ 1373 ], [ 1375 ], [ 1377 ], [ 1379 ], [ 1381 ], [ 1383 ], [ 1385 ], [ 1387 ], [ 1389 ], [ 1391 ], [ 1393 ], [ 1395 ], [ 1397 ], [ 1399 ], [ 1401 ], [ 1403 ], [ 1405 ], [ 1409 ], [ 1411 ], [ 1413 ], [ 1415 ], [ 1417 ], [ 1419 ], [ 1421 ], [ 1423 ], [ 1425 ], [ 1431, 1433 ], [ 1439 ], [ 1441 ], [ 1443 ], [ 1445 ], [ 1447 ], [ 1449 ], [ 1451 ], [ 1453 ], [ 1455 ], [ 1457, 1459 ], [ 1461, 1463 ], [ 1465 ], [ 1469 ], [ 1471 ], [ 1475 ], [ 1477, 1479 ], [ 1481 ], [ 1487, 1489 ], [ 1491 ], [ 1493 ], [ 1495, 1497 ], [ 1501, 1503 ], [ 1505, 1507 ], [ 1511 ], [ 1513, 1515 ], [ 1517, 1519 ], [ 1521 ], [ 1527, 1529 ], [ 1531 ], [ 1533 ], [ 1535 ], [ 1537 ], [ 1539, 1541, 1543 ], [ 1545 ], [ 1547, 1549 ], [ 1551 ], [ 1553 ], [ 1559, 1561, 1563 ], [ 1565, 1567 ], [ 1569 ], [ 1571 ], [ 1573 ], [ 1575 ], [ 1581 ], [ 1585, 1587, 1589 ], [ 1591, 1593 ], [ 1595 ], [ 1597 ], [ 1599 ], [ 1603, 1605 ], [ 1611 ], [ 1613 ], [ 1619 ], [ 1621 ], [ 1623 ], [ 1625 ], [ 1627 ], [ 1629 ], [ 1633 ], [ 1639 ], [ 1641 ], [ 1643 ], [ 1645 ], [ 1651 ], [ 1657 ], [ 1659 ], [ 1661 ], [ 1663 ], [ 1665 ], [ 1667 ], [ 1669, 1671 ], [ 1673, 1675 ], [ 1681 ], [ 1683 ], [ 1685 ], [ 1687 ], [ 1689 ], [ 1691 ], [ 1697 ], [ 1701, 1703 ], [ 1707 ], [ 1709 ], [ 1711 ], [ 1713 ], [ 1715, 1717 ], [ 1719 ], [ 1721 ], [ 1723 ], [ 1725 ], [ 1727 ], [ 1731 ], [ 1733 ], [ 1735 ], [ 1737, 1739 ], [ 1741, 1743 ], [ 1745, 1747 ], [ 1749 ], [ 1751 ], [ 1753 ], [ 1755 ], [ 1757 ], [ 1759 ], [ 1761 ], [ 1763 ] ]
2
static void v4l2_free_buffer(void *opaque, uint8_t *unused) { V4L2Buffer* avbuf = opaque; V4L2m2mContext *s = buf_to_m2mctx(avbuf); if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) { atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel); if (s->reinit) { if (!atomic_load(&s->refcount)) sem_post(&s->refsync); } else if (avbuf->context->streamon) ff_v4l2_buffer_enqueue(avbuf); av_buffer_unref(&avbuf->context_ref); } }
false
FFmpeg
5d5de3eba4c7890c2e8077f5b4ae569671d11cf8
static void v4l2_free_buffer(void *opaque, uint8_t *unused) { V4L2Buffer* avbuf = opaque; V4L2m2mContext *s = buf_to_m2mctx(avbuf); if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) { atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel); if (s->reinit) { if (!atomic_load(&s->refcount)) sem_post(&s->refsync); } else if (avbuf->context->streamon) ff_v4l2_buffer_enqueue(avbuf); av_buffer_unref(&avbuf->context_ref); } }
{ "code": [], "line_no": [] }
static void FUNC_0(void *VAR_0, uint8_t *VAR_1) { V4L2Buffer* avbuf = VAR_0; V4L2m2mContext *s = buf_to_m2mctx(avbuf); if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) { atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel); if (s->reinit) { if (!atomic_load(&s->refcount)) sem_post(&s->refsync); } else if (avbuf->context->streamon) ff_v4l2_buffer_enqueue(avbuf); av_buffer_unref(&avbuf->context_ref); } }
[ "static void FUNC_0(void *VAR_0, uint8_t *VAR_1)\n{", "V4L2Buffer* avbuf = VAR_0;", "V4L2m2mContext *s = buf_to_m2mctx(avbuf);", "if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) {", "atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel);", "if (s->reinit) {", "if (!atomic_load(&s->refcount))\nsem_post(&s->refsync);", "} else if (avbuf->context->streamon)", "ff_v4l2_buffer_enqueue(avbuf);", "av_buffer_unref(&avbuf->context_ref);", "}", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7 ], [ 11 ], [ 13 ], [ 17 ], [ 19, 21 ], [ 23 ], [ 25 ], [ 29 ], [ 31 ], [ 33 ] ]
4
int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size) { cl_int status; void *mapped = clEnqueueMapBuffer(gpu_env.command_queue, dst_cl_buf, CL_TRUE,CL_MAP_WRITE, 0, sizeof(uint8_t) * buf_size, 0, NULL, NULL, &status); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } memcpy(mapped, src_buf, buf_size); status = clEnqueueUnmapMemObject(gpu_env.command_queue, dst_cl_buf, mapped, 0, NULL, NULL); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } return 0; }
false
FFmpeg
57d77b3963ce1023eaf5ada8cba58b9379405cc8
int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size) { cl_int status; void *mapped = clEnqueueMapBuffer(gpu_env.command_queue, dst_cl_buf, CL_TRUE,CL_MAP_WRITE, 0, sizeof(uint8_t) * buf_size, 0, NULL, NULL, &status); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } memcpy(mapped, src_buf, buf_size); status = clEnqueueUnmapMemObject(gpu_env.command_queue, dst_cl_buf, mapped, 0, NULL, NULL); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } return 0; }
{ "code": [], "line_no": [] }
int FUNC_0(cl_mem VAR_0, uint8_t *VAR_1, size_t VAR_2) { cl_int status; void *VAR_3 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_0, CL_TRUE,CL_MAP_WRITE, 0, sizeof(uint8_t) * VAR_2, 0, NULL, NULL, &status); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } memcpy(VAR_3, VAR_1, VAR_2); status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_0, VAR_3, 0, NULL, NULL); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } return 0; }
[ "int FUNC_0(cl_mem VAR_0, uint8_t *VAR_1, size_t VAR_2)\n{", "cl_int status;", "void *VAR_3 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_0,\nCL_TRUE,CL_MAP_WRITE, 0, sizeof(uint8_t) * VAR_2,\n0, NULL, NULL, &status);", "if (status != CL_SUCCESS) {", "av_log(&openclutils, AV_LOG_ERROR, \"Could not map OpenCL buffer: %s\\n\", opencl_errstr(status));", "return AVERROR_EXTERNAL;", "}", "memcpy(VAR_3, VAR_1, VAR_2);", "status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_0, VAR_3, 0, NULL, NULL);", "if (status != CL_SUCCESS) {", "av_log(&openclutils, AV_LOG_ERROR, \"Could not unmap OpenCL buffer: %s\\n\", opencl_errstr(status));", "return AVERROR_EXTERNAL;", "}", "return 0;", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7, 9, 11 ], [ 15 ], [ 17 ], [ 19 ], [ 21 ], [ 23 ], [ 27 ], [ 29 ], [ 31 ], [ 33 ], [ 35 ], [ 37 ], [ 39 ] ]
5
static int r3d_read_rdvo(AVFormatContext *s, Atom *atom) { R3DContext *r3d = s->priv_data; AVStream *st = s->streams[0]; int i; r3d->video_offsets_count = (atom->size - 8) / 4; r3d->video_offsets = av_malloc(atom->size); if (!r3d->video_offsets) return AVERROR(ENOMEM); for (i = 0; i < r3d->video_offsets_count; i++) { r3d->video_offsets[i] = avio_rb32(s->pb); if (!r3d->video_offsets[i]) { r3d->video_offsets_count = i; break; } av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]); } if (st->r_frame_rate.num) st->duration = av_rescale_q(r3d->video_offsets_count, (AVRational){st->r_frame_rate.den, st->r_frame_rate.num}, st->time_base); av_dlog(s, "duration %"PRId64"\n", st->duration); return 0; }
true
FFmpeg
aba232cfa9b193604ed98f3fa505378d006b1b3b
static int r3d_read_rdvo(AVFormatContext *s, Atom *atom) { R3DContext *r3d = s->priv_data; AVStream *st = s->streams[0]; int i; r3d->video_offsets_count = (atom->size - 8) / 4; r3d->video_offsets = av_malloc(atom->size); if (!r3d->video_offsets) return AVERROR(ENOMEM); for (i = 0; i < r3d->video_offsets_count; i++) { r3d->video_offsets[i] = avio_rb32(s->pb); if (!r3d->video_offsets[i]) { r3d->video_offsets_count = i; break; } av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]); } if (st->r_frame_rate.num) st->duration = av_rescale_q(r3d->video_offsets_count, (AVRational){st->r_frame_rate.den, st->r_frame_rate.num}, st->time_base); av_dlog(s, "duration %"PRId64"\n", st->duration); return 0; }
{ "code": [ " if (st->r_frame_rate.num)", " (AVRational){st->r_frame_rate.den,", " st->r_frame_rate.num},", " if (st->r_frame_rate.num)" ], "line_no": [ 41, 45, 47, 41 ] }
static int FUNC_0(AVFormatContext *VAR_0, Atom *VAR_1) { R3DContext *r3d = VAR_0->priv_data; AVStream *st = VAR_0->streams[0]; int VAR_2; r3d->video_offsets_count = (VAR_1->size - 8) / 4; r3d->video_offsets = av_malloc(VAR_1->size); if (!r3d->video_offsets) return AVERROR(ENOMEM); for (VAR_2 = 0; VAR_2 < r3d->video_offsets_count; VAR_2++) { r3d->video_offsets[VAR_2] = avio_rb32(VAR_0->pb); if (!r3d->video_offsets[VAR_2]) { r3d->video_offsets_count = VAR_2; break; } av_dlog(VAR_0, "video offset %d: %#x\n", VAR_2, r3d->video_offsets[VAR_2]); } if (st->r_frame_rate.num) st->duration = av_rescale_q(r3d->video_offsets_count, (AVRational){st->r_frame_rate.den, st->r_frame_rate.num}, st->time_base); av_dlog(VAR_0, "duration %"PRId64"\n", st->duration); return 0; }
[ "static int FUNC_0(AVFormatContext *VAR_0, Atom *VAR_1)\n{", "R3DContext *r3d = VAR_0->priv_data;", "AVStream *st = VAR_0->streams[0];", "int VAR_2;", "r3d->video_offsets_count = (VAR_1->size - 8) / 4;", "r3d->video_offsets = av_malloc(VAR_1->size);", "if (!r3d->video_offsets)\nreturn AVERROR(ENOMEM);", "for (VAR_2 = 0; VAR_2 < r3d->video_offsets_count; VAR_2++) {", "r3d->video_offsets[VAR_2] = avio_rb32(VAR_0->pb);", "if (!r3d->video_offsets[VAR_2]) {", "r3d->video_offsets_count = VAR_2;", "break;", "}", "av_dlog(VAR_0, \"video offset %d: %#x\\n\", VAR_2, r3d->video_offsets[VAR_2]);", "}", "if (st->r_frame_rate.num)\nst->duration = av_rescale_q(r3d->video_offsets_count,\n(AVRational){st->r_frame_rate.den,", "st->r_frame_rate.num},", "st->time_base);", "av_dlog(VAR_0, \"duration %\"PRId64\"\\n\", st->duration);", "return 0;", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7 ], [ 9 ], [ 13 ], [ 15 ], [ 17, 19 ], [ 23 ], [ 25 ], [ 27 ], [ 29 ], [ 31 ], [ 33 ], [ 35 ], [ 37 ], [ 41, 43, 45 ], [ 47 ], [ 49 ], [ 51 ], [ 55 ], [ 57 ] ]
6
static int dds_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { DDSContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; AVFrame *frame = data; int mipmap; int ret; ff_texturedsp_init(&ctx->texdsp); bytestream2_init(gbc, avpkt->data, avpkt->size); if (bytestream2_get_bytes_left(gbc) < 128) { av_log(avctx, AV_LOG_ERROR, "Frame is too small (%d).\n", bytestream2_get_bytes_left(gbc)); return AVERROR_INVALIDDATA; } if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') || bytestream2_get_le32(gbc) != 124) { // header size av_log(avctx, AV_LOG_ERROR, "Invalid DDS header.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(gbc, 4); // flags avctx->height = bytestream2_get_le32(gbc); avctx->width = bytestream2_get_le32(gbc); ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid image size %dx%d.\n", avctx->width, avctx->height); return ret; } /* Since codec is based on 4x4 blocks, size is aligned to 4. */ avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W); avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H); bytestream2_skip(gbc, 4); // pitch bytestream2_skip(gbc, 4); // depth mipmap = bytestream2_get_le32(gbc); if (mipmap != 0) av_log(avctx, AV_LOG_VERBOSE, "Found %d mipmaps (ignored).\n", mipmap); /* Extract pixel format information, considering additional elements * in reserved1 and reserved2. */ ret = parse_pixel_format(avctx); if (ret < 0) return ret; ret = ff_get_buffer(avctx, frame, 0); if (ret < 0) return ret; if (ctx->compressed) { int size = (avctx->coded_height / TEXTURE_BLOCK_H) * (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio; ctx->slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); if (bytestream2_get_bytes_left(gbc) < size) { av_log(avctx, AV_LOG_ERROR, "Compressed Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), size); return AVERROR_INVALIDDATA; } /* Use the decompress function on the texture, one block per thread. */ ctx->tex_data = gbc->buffer; avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count); } else if (!ctx->paletted && ctx->bpp == 4 && avctx->pix_fmt == AV_PIX_FMT_PAL8) { uint8_t *dst = frame->data[0]; int x, y, i; /* Use the first 64 bytes as palette, then copy the rest. */ bytestream2_get_buffer(gbc, frame->data[1], 16 * 4); for (i = 0; i < 16; i++) { AV_WN32(frame->data[1] + i*4, (frame->data[1][2+i*4]<<0)+ (frame->data[1][1+i*4]<<8)+ (frame->data[1][0+i*4]<<16)+ (frame->data[1][3+i*4]<<24) ); } frame->palette_has_changed = 1; if (bytestream2_get_bytes_left(gbc) < frame->height * frame->width / 2) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * frame->width / 2); return AVERROR_INVALIDDATA; } for (y = 0; y < frame->height; y++) { for (x = 0; x < frame->width; x += 2) { uint8_t val = bytestream2_get_byte(gbc); dst[x ] = val & 0xF; dst[x + 1] = val >> 4; } dst += frame->linesize[0]; } } else { int linesize = av_image_get_linesize(avctx->pix_fmt, frame->width, 0); if (ctx->paletted) { int i; /* Use the first 1024 bytes as palette, then copy the rest. */ bytestream2_get_buffer(gbc, frame->data[1], 256 * 4); for (i = 0; i < 256; i++) AV_WN32(frame->data[1] + i*4, (frame->data[1][2+i*4]<<0)+ (frame->data[1][1+i*4]<<8)+ (frame->data[1][0+i*4]<<16)+ (frame->data[1][3+i*4]<<24) ); frame->palette_has_changed = 1; } if (bytestream2_get_bytes_left(gbc) < frame->height * linesize) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * linesize); return AVERROR_INVALIDDATA; } av_image_copy_plane(frame->data[0], frame->linesize[0], gbc->buffer, linesize, linesize, frame->height); } /* Run any post processing here if needed. */ if (ctx->postproc != DDS_NONE) run_postproc(avctx, frame); /* Frame is ready to be output. */ frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; *got_frame = 1; return avpkt->size; }
true
FFmpeg
afb4632cc30e83287338690c785ebac180436a59
static int dds_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { DDSContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; AVFrame *frame = data; int mipmap; int ret; ff_texturedsp_init(&ctx->texdsp); bytestream2_init(gbc, avpkt->data, avpkt->size); if (bytestream2_get_bytes_left(gbc) < 128) { av_log(avctx, AV_LOG_ERROR, "Frame is too small (%d).\n", bytestream2_get_bytes_left(gbc)); return AVERROR_INVALIDDATA; } if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') || bytestream2_get_le32(gbc) != 124) { av_log(avctx, AV_LOG_ERROR, "Invalid DDS header.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(gbc, 4); avctx->height = bytestream2_get_le32(gbc); avctx->width = bytestream2_get_le32(gbc); ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid image size %dx%d.\n", avctx->width, avctx->height); return ret; } avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W); avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H); bytestream2_skip(gbc, 4); bytestream2_skip(gbc, 4); mipmap = bytestream2_get_le32(gbc); if (mipmap != 0) av_log(avctx, AV_LOG_VERBOSE, "Found %d mipmaps (ignored).\n", mipmap); ret = parse_pixel_format(avctx); if (ret < 0) return ret; ret = ff_get_buffer(avctx, frame, 0); if (ret < 0) return ret; if (ctx->compressed) { int size = (avctx->coded_height / TEXTURE_BLOCK_H) * (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio; ctx->slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); if (bytestream2_get_bytes_left(gbc) < size) { av_log(avctx, AV_LOG_ERROR, "Compressed Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), size); return AVERROR_INVALIDDATA; } ctx->tex_data = gbc->buffer; avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count); } else if (!ctx->paletted && ctx->bpp == 4 && avctx->pix_fmt == AV_PIX_FMT_PAL8) { uint8_t *dst = frame->data[0]; int x, y, i; bytestream2_get_buffer(gbc, frame->data[1], 16 * 4); for (i = 0; i < 16; i++) { AV_WN32(frame->data[1] + i*4, (frame->data[1][2+i*4]<<0)+ (frame->data[1][1+i*4]<<8)+ (frame->data[1][0+i*4]<<16)+ (frame->data[1][3+i*4]<<24) ); } frame->palette_has_changed = 1; if (bytestream2_get_bytes_left(gbc) < frame->height * frame->width / 2) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * frame->width / 2); return AVERROR_INVALIDDATA; } for (y = 0; y < frame->height; y++) { for (x = 0; x < frame->width; x += 2) { uint8_t val = bytestream2_get_byte(gbc); dst[x ] = val & 0xF; dst[x + 1] = val >> 4; } dst += frame->linesize[0]; } } else { int linesize = av_image_get_linesize(avctx->pix_fmt, frame->width, 0); if (ctx->paletted) { int i; bytestream2_get_buffer(gbc, frame->data[1], 256 * 4); for (i = 0; i < 256; i++) AV_WN32(frame->data[1] + i*4, (frame->data[1][2+i*4]<<0)+ (frame->data[1][1+i*4]<<8)+ (frame->data[1][0+i*4]<<16)+ (frame->data[1][3+i*4]<<24) ); frame->palette_has_changed = 1; } if (bytestream2_get_bytes_left(gbc) < frame->height * linesize) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * linesize); return AVERROR_INVALIDDATA; } av_image_copy_plane(frame->data[0], frame->linesize[0], gbc->buffer, linesize, linesize, frame->height); } if (ctx->postproc != DDS_NONE) run_postproc(avctx, frame); frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; *got_frame = 1; return avpkt->size; }
{ "code": [ " (frame->data[1][3+i*4]<<24)" ], "line_no": [ 227 ] }
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1, int *VAR_2, AVPacket *VAR_3) { DDSContext *ctx = VAR_0->priv_data; GetByteContext *gbc = &ctx->gbc; AVFrame *frame = VAR_1; int VAR_4; int VAR_5; ff_texturedsp_init(&ctx->texdsp); bytestream2_init(gbc, VAR_3->VAR_1, VAR_3->VAR_6); if (bytestream2_get_bytes_left(gbc) < 128) { av_log(VAR_0, AV_LOG_ERROR, "Frame is too small (%d).\n", bytestream2_get_bytes_left(gbc)); return AVERROR_INVALIDDATA; } if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') || bytestream2_get_le32(gbc) != 124) { av_log(VAR_0, AV_LOG_ERROR, "Invalid DDS header.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(gbc, 4); VAR_0->height = bytestream2_get_le32(gbc); VAR_0->width = bytestream2_get_le32(gbc); VAR_5 = av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0); if (VAR_5 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Invalid image VAR_6 %dx%d.\n", VAR_0->width, VAR_0->height); return VAR_5; } VAR_0->coded_width = FFALIGN(VAR_0->width, TEXTURE_BLOCK_W); VAR_0->coded_height = FFALIGN(VAR_0->height, TEXTURE_BLOCK_H); bytestream2_skip(gbc, 4); bytestream2_skip(gbc, 4); VAR_4 = bytestream2_get_le32(gbc); if (VAR_4 != 0) av_log(VAR_0, AV_LOG_VERBOSE, "Found %d mipmaps (ignored).\n", VAR_4); VAR_5 = parse_pixel_format(VAR_0); if (VAR_5 < 0) return VAR_5; VAR_5 = ff_get_buffer(VAR_0, frame, 0); if (VAR_5 < 0) return VAR_5; if (ctx->compressed) { int VAR_6 = (VAR_0->coded_height / TEXTURE_BLOCK_H) * (VAR_0->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio; ctx->slice_count = av_clip(VAR_0->thread_count, 1, VAR_0->coded_height / TEXTURE_BLOCK_H); if (bytestream2_get_bytes_left(gbc) < VAR_6) { av_log(VAR_0, AV_LOG_ERROR, "Compressed Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), VAR_6); return AVERROR_INVALIDDATA; } ctx->tex_data = gbc->buffer; VAR_0->execute2(VAR_0, decompress_texture_thread, frame, NULL, ctx->slice_count); } else if (!ctx->paletted && ctx->bpp == 4 && VAR_0->pix_fmt == AV_PIX_FMT_PAL8) { uint8_t *dst = frame->VAR_1[0]; int VAR_7, VAR_8, VAR_11; bytestream2_get_buffer(gbc, frame->VAR_1[1], 16 * 4); for (VAR_11 = 0; VAR_11 < 16; VAR_11++) { AV_WN32(frame->VAR_1[1] + VAR_11*4, (frame->VAR_1[1][2+VAR_11*4]<<0)+ (frame->VAR_1[1][1+VAR_11*4]<<8)+ (frame->VAR_1[1][0+VAR_11*4]<<16)+ (frame->VAR_1[1][3+VAR_11*4]<<24) ); } frame->palette_has_changed = 1; if (bytestream2_get_bytes_left(gbc) < frame->height * frame->width / 2) { av_log(VAR_0, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * frame->width / 2); return AVERROR_INVALIDDATA; } for (VAR_8 = 0; VAR_8 < frame->height; VAR_8++) { for (VAR_7 = 0; VAR_7 < frame->width; VAR_7 += 2) { uint8_t val = bytestream2_get_byte(gbc); dst[VAR_7 ] = val & 0xF; dst[VAR_7 + 1] = val >> 4; } dst += frame->VAR_10[0]; } } else { int VAR_10 = av_image_get_linesize(VAR_0->pix_fmt, frame->width, 0); if (ctx->paletted) { int VAR_11; bytestream2_get_buffer(gbc, frame->VAR_1[1], 256 * 4); for (VAR_11 = 0; VAR_11 < 256; VAR_11++) AV_WN32(frame->VAR_1[1] + VAR_11*4, (frame->VAR_1[1][2+VAR_11*4]<<0)+ (frame->VAR_1[1][1+VAR_11*4]<<8)+ (frame->VAR_1[1][0+VAR_11*4]<<16)+ (frame->VAR_1[1][3+VAR_11*4]<<24) ); frame->palette_has_changed = 1; } if (bytestream2_get_bytes_left(gbc) < frame->height * VAR_10) { av_log(VAR_0, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * VAR_10); return AVERROR_INVALIDDATA; } av_image_copy_plane(frame->VAR_1[0], frame->VAR_10[0], gbc->buffer, VAR_10, VAR_10, frame->height); } if (ctx->postproc != DDS_NONE) run_postproc(VAR_0, frame); frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; *VAR_2 = 1; return VAR_3->VAR_6; }
[ "static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,\nint *VAR_2, AVPacket *VAR_3)\n{", "DDSContext *ctx = VAR_0->priv_data;", "GetByteContext *gbc = &ctx->gbc;", "AVFrame *frame = VAR_1;", "int VAR_4;", "int VAR_5;", "ff_texturedsp_init(&ctx->texdsp);", "bytestream2_init(gbc, VAR_3->VAR_1, VAR_3->VAR_6);", "if (bytestream2_get_bytes_left(gbc) < 128) {", "av_log(VAR_0, AV_LOG_ERROR, \"Frame is too small (%d).\\n\",\nbytestream2_get_bytes_left(gbc));", "return AVERROR_INVALIDDATA;", "}", "if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') ||\nbytestream2_get_le32(gbc) != 124) {", "av_log(VAR_0, AV_LOG_ERROR, \"Invalid DDS header.\\n\");", "return AVERROR_INVALIDDATA;", "}", "bytestream2_skip(gbc, 4);", "VAR_0->height = bytestream2_get_le32(gbc);", "VAR_0->width = bytestream2_get_le32(gbc);", "VAR_5 = av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0);", "if (VAR_5 < 0) {", "av_log(VAR_0, AV_LOG_ERROR, \"Invalid image VAR_6 %dx%d.\\n\",\nVAR_0->width, VAR_0->height);", "return VAR_5;", "}", "VAR_0->coded_width = FFALIGN(VAR_0->width, TEXTURE_BLOCK_W);", "VAR_0->coded_height = FFALIGN(VAR_0->height, TEXTURE_BLOCK_H);", "bytestream2_skip(gbc, 4);", "bytestream2_skip(gbc, 4);", "VAR_4 = bytestream2_get_le32(gbc);", "if (VAR_4 != 0)\nav_log(VAR_0, AV_LOG_VERBOSE, \"Found %d mipmaps (ignored).\\n\", VAR_4);", "VAR_5 = parse_pixel_format(VAR_0);", "if (VAR_5 < 0)\nreturn VAR_5;", "VAR_5 = ff_get_buffer(VAR_0, frame, 0);", "if (VAR_5 < 0)\nreturn VAR_5;", "if (ctx->compressed) {", "int VAR_6 = (VAR_0->coded_height / TEXTURE_BLOCK_H) *\n(VAR_0->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio;", "ctx->slice_count = av_clip(VAR_0->thread_count, 1,\nVAR_0->coded_height / TEXTURE_BLOCK_H);", "if (bytestream2_get_bytes_left(gbc) < VAR_6) {", "av_log(VAR_0, AV_LOG_ERROR,\n\"Compressed Buffer is too small (%d < %d).\\n\",\nbytestream2_get_bytes_left(gbc), VAR_6);", "return AVERROR_INVALIDDATA;", "}", "ctx->tex_data = gbc->buffer;", "VAR_0->execute2(VAR_0, decompress_texture_thread, frame, NULL, ctx->slice_count);", "} else if (!ctx->paletted && ctx->bpp == 4 && VAR_0->pix_fmt == AV_PIX_FMT_PAL8) {", "uint8_t *dst = frame->VAR_1[0];", "int VAR_7, VAR_8, VAR_11;", "bytestream2_get_buffer(gbc, frame->VAR_1[1], 16 * 4);", "for (VAR_11 = 0; VAR_11 < 16; VAR_11++) {", "AV_WN32(frame->VAR_1[1] + VAR_11*4,\n(frame->VAR_1[1][2+VAR_11*4]<<0)+\n(frame->VAR_1[1][1+VAR_11*4]<<8)+\n(frame->VAR_1[1][0+VAR_11*4]<<16)+\n(frame->VAR_1[1][3+VAR_11*4]<<24)\n);", "}", "frame->palette_has_changed = 1;", "if (bytestream2_get_bytes_left(gbc) < frame->height * frame->width / 2) {", "av_log(VAR_0, AV_LOG_ERROR, \"Buffer is too small (%d < %d).\\n\",\nbytestream2_get_bytes_left(gbc), frame->height * frame->width / 2);", "return AVERROR_INVALIDDATA;", "}", "for (VAR_8 = 0; VAR_8 < frame->height; VAR_8++) {", "for (VAR_7 = 0; VAR_7 < frame->width; VAR_7 += 2) {", "uint8_t val = bytestream2_get_byte(gbc);", "dst[VAR_7 ] = val & 0xF;", "dst[VAR_7 + 1] = val >> 4;", "}", "dst += frame->VAR_10[0];", "}", "} else {", "int VAR_10 = av_image_get_linesize(VAR_0->pix_fmt, frame->width, 0);", "if (ctx->paletted) {", "int VAR_11;", "bytestream2_get_buffer(gbc, frame->VAR_1[1], 256 * 4);", "for (VAR_11 = 0; VAR_11 < 256; VAR_11++)", "AV_WN32(frame->VAR_1[1] + VAR_11*4,\n(frame->VAR_1[1][2+VAR_11*4]<<0)+\n(frame->VAR_1[1][1+VAR_11*4]<<8)+\n(frame->VAR_1[1][0+VAR_11*4]<<16)+\n(frame->VAR_1[1][3+VAR_11*4]<<24)\n);", "frame->palette_has_changed = 1;", "}", "if (bytestream2_get_bytes_left(gbc) < frame->height * VAR_10) {", "av_log(VAR_0, AV_LOG_ERROR, \"Buffer is too small (%d < %d).\\n\",\nbytestream2_get_bytes_left(gbc), frame->height * VAR_10);", "return AVERROR_INVALIDDATA;", "}", "av_image_copy_plane(frame->VAR_1[0], frame->VAR_10[0],\ngbc->buffer, VAR_10,\nVAR_10, frame->height);", "}", "if (ctx->postproc != DDS_NONE)\nrun_postproc(VAR_0, frame);", "frame->pict_type = AV_PICTURE_TYPE_I;", "frame->key_frame = 1;", "*VAR_2 = 1;", "return VAR_3->VAR_6;", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[ [ 1, 3, 5 ], [ 7 ], [ 9 ], [ 11 ], [ 13 ], [ 15 ], [ 19 ], [ 21 ], [ 25 ], [ 27, 29 ], [ 31 ], [ 33 ], [ 37, 39 ], [ 41 ], [ 43 ], [ 45 ], [ 49 ], [ 53 ], [ 55 ], [ 57 ], [ 59 ], [ 61, 63 ], [ 65 ], [ 67 ], [ 73 ], [ 75 ], [ 79 ], [ 81 ], [ 83 ], [ 85, 87 ], [ 95 ], [ 97, 99 ], [ 103 ], [ 105, 107 ], [ 111 ], [ 113, 115 ], [ 117, 119 ], [ 123 ], [ 125, 127, 129 ], [ 131 ], [ 133 ], [ 139 ], [ 141 ], [ 143 ], [ 145 ], [ 147 ], [ 153 ], [ 155 ], [ 157, 159, 161, 163, 165, 167 ], [ 169 ], [ 171 ], [ 175 ], [ 177, 179 ], [ 181 ], [ 183 ], [ 187 ], [ 189 ], [ 191 ], [ 193 ], [ 195 ], [ 197 ], [ 199 ], [ 201 ], [ 203 ], [ 205 ], [ 209 ], [ 211 ], [ 215 ], [ 217 ], [ 219, 221, 223, 225, 227, 229 ], [ 233 ], [ 235 ], [ 239 ], [ 241, 243 ], [ 245 ], [ 247 ], [ 251, 253, 255 ], [ 257 ], [ 263, 265 ], [ 271 ], [ 273 ], [ 275 ], [ 279 ], [ 281 ] ]
7
static void check_lowpass_line(int depth){ LOCAL_ALIGNED_32(uint8_t, src, [SRC_SIZE]); LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]); int w = WIDTH; int mref = WIDTH_PADDED * -1; int pref = WIDTH_PADDED; int i, depth_byte; InterlaceContext s; declare_func(void, uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); s.lowpass = 1; s.lowpass = VLPF_LIN; depth_byte = depth >> 3; w /= depth_byte; memset(src, 0, SRC_SIZE); memset(dst_ref, 0, WIDTH_PADDED); memset(dst_new, 0, WIDTH_PADDED); randomize_buffers(src, SRC_SIZE); ff_interlace_init(&s, depth); if (check_func(s.lowpass_line, "lowpass_line_%d", depth)) { for (i = 0; i < 32; i++) { /* simulate crop */ call_ref(dst_ref, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0); call_new(dst_new, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0); if (memcmp(dst_ref, dst_new, WIDTH - i)) fail(); } bench_new(dst_new, w, src + WIDTH_PADDED, mref, pref, 0); } }
true
FFmpeg
da032427786d9db4ab21014998cb1245083d6c85
static void check_lowpass_line(int depth){ LOCAL_ALIGNED_32(uint8_t, src, [SRC_SIZE]); LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]); int w = WIDTH; int mref = WIDTH_PADDED * -1; int pref = WIDTH_PADDED; int i, depth_byte; InterlaceContext s; declare_func(void, uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); s.lowpass = 1; s.lowpass = VLPF_LIN; depth_byte = depth >> 3; w /= depth_byte; memset(src, 0, SRC_SIZE); memset(dst_ref, 0, WIDTH_PADDED); memset(dst_new, 0, WIDTH_PADDED); randomize_buffers(src, SRC_SIZE); ff_interlace_init(&s, depth); if (check_func(s.lowpass_line, "lowpass_line_%d", depth)) { for (i = 0; i < 32; i++) { call_ref(dst_ref, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0); call_new(dst_new, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0); if (memcmp(dst_ref, dst_new, WIDTH - i)) fail(); } bench_new(dst_new, w, src + WIDTH_PADDED, mref, pref, 0); } }
{ "code": [ "static void check_lowpass_line(int depth){", " LOCAL_ALIGNED_32(uint8_t, src, [SRC_SIZE]);", " LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]);", " LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]);", " int w = WIDTH;", " int mref = WIDTH_PADDED * -1;", " int pref = WIDTH_PADDED;", " int i, depth_byte;", " InterlaceContext s;", " declare_func(void, uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp,", " ptrdiff_t mref, ptrdiff_t pref, int clip_max);", " s.lowpass = 1;", " s.lowpass = VLPF_LIN;", " depth_byte = depth >> 3;", " w /= depth_byte;", " memset(src, 0, SRC_SIZE);", " memset(dst_ref, 0, WIDTH_PADDED);", " memset(dst_new, 0, WIDTH_PADDED);", " randomize_buffers(src, SRC_SIZE);", " ff_interlace_init(&s, depth);", " if (check_func(s.lowpass_line, \"lowpass_line_%d\", depth)) {", " call_ref(dst_ref, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0);", " call_new(dst_new, w, src + WIDTH_PADDED, mref - i*depth_byte, pref, 0);", " if (memcmp(dst_ref, dst_new, WIDTH - i))", " fail();", " bench_new(dst_new, w, src + WIDTH_PADDED, mref, pref, 0);" ], "line_no": [ 1, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 27, 29, 31, 33, 37, 39, 41, 43, 47, 51, 55, 57, 59, 61, 65 ] }
static void FUNC_0(int VAR_0){ LOCAL_ALIGNED_32(uint8_t, src, [SRC_SIZE]); LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]); int VAR_1 = WIDTH; int VAR_2 = WIDTH_PADDED * -1; int VAR_3 = WIDTH_PADDED; int VAR_4, VAR_5; InterlaceContext s; declare_func(void, uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t VAR_2, ptrdiff_t VAR_3, int clip_max); s.lowpass = 1; s.lowpass = VLPF_LIN; VAR_5 = VAR_0 >> 3; VAR_1 /= VAR_5; memset(src, 0, SRC_SIZE); memset(dst_ref, 0, WIDTH_PADDED); memset(dst_new, 0, WIDTH_PADDED); randomize_buffers(src, SRC_SIZE); ff_interlace_init(&s, VAR_0); if (check_func(s.lowpass_line, "lowpass_line_%d", VAR_0)) { for (VAR_4 = 0; VAR_4 < 32; VAR_4++) { call_ref(dst_ref, VAR_1, src + WIDTH_PADDED, VAR_2 - VAR_4*VAR_5, VAR_3, 0); call_new(dst_new, VAR_1, src + WIDTH_PADDED, VAR_2 - VAR_4*VAR_5, VAR_3, 0); if (memcmp(dst_ref, dst_new, WIDTH - VAR_4)) fail(); } bench_new(dst_new, VAR_1, src + WIDTH_PADDED, VAR_2, VAR_3, 0); } }
[ "static void FUNC_0(int VAR_0){", "LOCAL_ALIGNED_32(uint8_t, src, [SRC_SIZE]);", "LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]);", "LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]);", "int VAR_1 = WIDTH;", "int VAR_2 = WIDTH_PADDED * -1;", "int VAR_3 = WIDTH_PADDED;", "int VAR_4, VAR_5;", "InterlaceContext s;", "declare_func(void, uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp,\nptrdiff_t VAR_2, ptrdiff_t VAR_3, int clip_max);", "s.lowpass = 1;", "s.lowpass = VLPF_LIN;", "VAR_5 = VAR_0 >> 3;", "VAR_1 /= VAR_5;", "memset(src, 0, SRC_SIZE);", "memset(dst_ref, 0, WIDTH_PADDED);", "memset(dst_new, 0, WIDTH_PADDED);", "randomize_buffers(src, SRC_SIZE);", "ff_interlace_init(&s, VAR_0);", "if (check_func(s.lowpass_line, \"lowpass_line_%d\", VAR_0)) {", "for (VAR_4 = 0; VAR_4 < 32; VAR_4++) {", "call_ref(dst_ref, VAR_1, src + WIDTH_PADDED, VAR_2 - VAR_4*VAR_5, VAR_3, 0);", "call_new(dst_new, VAR_1, src + WIDTH_PADDED, VAR_2 - VAR_4*VAR_5, VAR_3, 0);", "if (memcmp(dst_ref, dst_new, WIDTH - VAR_4))\nfail();", "}", "bench_new(dst_new, VAR_1, src + WIDTH_PADDED, VAR_2, VAR_3, 0);", "}", "}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0 ]
[ [ 1 ], [ 3 ], [ 5 ], [ 7 ], [ 9 ], [ 11 ], [ 13 ], [ 15 ], [ 17 ], [ 21, 23 ], [ 27 ], [ 29 ], [ 31 ], [ 33 ], [ 37 ], [ 39 ], [ 41 ], [ 43 ], [ 47 ], [ 51 ], [ 53 ], [ 55 ], [ 57 ], [ 59, 61 ], [ 63 ], [ 65 ], [ 67 ], [ 69 ] ]
9
static void test_init(TestData *d) { QPCIBus *bus; QTestState *qs; char *s; s = g_strdup_printf("-machine q35 %s %s", d->noreboot ? "" : "-global ICH9-LPC.noreboot=false", !d->args ? "" : d->args); qs = qtest_start(s); qtest_irq_intercept_in(qs, "ioapic"); g_free(s); bus = qpci_init_pc(NULL); d->dev = qpci_device_find(bus, QPCI_DEVFN(0x1f, 0x00)); g_assert(d->dev != NULL); qpci_device_enable(d->dev); /* set ACPI PM I/O space base address */ qpci_config_writel(d->dev, ICH9_LPC_PMBASE, PM_IO_BASE_ADDR | 0x1); /* enable ACPI I/O */ qpci_config_writeb(d->dev, ICH9_LPC_ACPI_CTRL, 0x80); /* set Root Complex BAR */ qpci_config_writel(d->dev, ICH9_LPC_RCBA, RCBA_BASE_ADDR | 0x1); d->tco_io_base = qpci_legacy_iomap(d->dev, PM_IO_BASE_ADDR + 0x60); }
true
qemu
b4ba67d9a702507793c2724e56f98e9b0f7be02b
static void test_init(TestData *d) { QPCIBus *bus; QTestState *qs; char *s; s = g_strdup_printf("-machine q35 %s %s", d->noreboot ? "" : "-global ICH9-LPC.noreboot=false", !d->args ? "" : d->args); qs = qtest_start(s); qtest_irq_intercept_in(qs, "ioapic"); g_free(s); bus = qpci_init_pc(NULL); d->dev = qpci_device_find(bus, QPCI_DEVFN(0x1f, 0x00)); g_assert(d->dev != NULL); qpci_device_enable(d->dev); qpci_config_writel(d->dev, ICH9_LPC_PMBASE, PM_IO_BASE_ADDR | 0x1); qpci_config_writeb(d->dev, ICH9_LPC_ACPI_CTRL, 0x80); qpci_config_writel(d->dev, ICH9_LPC_RCBA, RCBA_BASE_ADDR | 0x1); d->tco_io_base = qpci_legacy_iomap(d->dev, PM_IO_BASE_ADDR + 0x60); }
{ "code": [ " d->tco_io_base = qpci_legacy_iomap(d->dev, PM_IO_BASE_ADDR + 0x60);" ], "line_no": [ 53 ] }
static void FUNC_0(TestData *VAR_0) { QPCIBus *bus; QTestState *qs; char *VAR_1; VAR_1 = g_strdup_printf("-machine q35 %VAR_1 %VAR_1", VAR_0->noreboot ? "" : "-global ICH9-LPC.noreboot=false", !VAR_0->args ? "" : VAR_0->args); qs = qtest_start(VAR_1); qtest_irq_intercept_in(qs, "ioapic"); g_free(VAR_1); bus = qpci_init_pc(NULL); VAR_0->dev = qpci_device_find(bus, QPCI_DEVFN(0x1f, 0x00)); g_assert(VAR_0->dev != NULL); qpci_device_enable(VAR_0->dev); qpci_config_writel(VAR_0->dev, ICH9_LPC_PMBASE, PM_IO_BASE_ADDR | 0x1); qpci_config_writeb(VAR_0->dev, ICH9_LPC_ACPI_CTRL, 0x80); qpci_config_writel(VAR_0->dev, ICH9_LPC_RCBA, RCBA_BASE_ADDR | 0x1); VAR_0->tco_io_base = qpci_legacy_iomap(VAR_0->dev, PM_IO_BASE_ADDR + 0x60); }
[ "static void FUNC_0(TestData *VAR_0)\n{", "QPCIBus *bus;", "QTestState *qs;", "char *VAR_1;", "VAR_1 = g_strdup_printf(\"-machine q35 %VAR_1 %VAR_1\",\nVAR_0->noreboot ? \"\" : \"-global ICH9-LPC.noreboot=false\",\n!VAR_0->args ? \"\" : VAR_0->args);", "qs = qtest_start(VAR_1);", "qtest_irq_intercept_in(qs, \"ioapic\");", "g_free(VAR_1);", "bus = qpci_init_pc(NULL);", "VAR_0->dev = qpci_device_find(bus, QPCI_DEVFN(0x1f, 0x00));", "g_assert(VAR_0->dev != NULL);", "qpci_device_enable(VAR_0->dev);", "qpci_config_writel(VAR_0->dev, ICH9_LPC_PMBASE, PM_IO_BASE_ADDR | 0x1);", "qpci_config_writeb(VAR_0->dev, ICH9_LPC_ACPI_CTRL, 0x80);", "qpci_config_writel(VAR_0->dev, ICH9_LPC_RCBA, RCBA_BASE_ADDR | 0x1);", "VAR_0->tco_io_base = qpci_legacy_iomap(VAR_0->dev, PM_IO_BASE_ADDR + 0x60);", "}" ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7 ], [ 9 ], [ 13, 15, 17 ], [ 19 ], [ 21 ], [ 23 ], [ 27 ], [ 29 ], [ 31 ], [ 35 ], [ 41 ], [ 45 ], [ 49 ], [ 53 ], [ 55 ] ]
11
void assert_avoptions(AVDictionary *m) { AVDictionaryEntry *t; if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); exit(1); } }
true
FFmpeg
636ced8e1dc8248a1353b416240b93d70ad03edb
void assert_avoptions(AVDictionary *m) { AVDictionaryEntry *t; if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); exit(1); } }
{ "code": [ " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);", " exit(1);" ], "line_no": [ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11 ] }
void FUNC_0(AVDictionary *VAR_0) { AVDictionaryEntry *t; if ((t = av_dict_get(VAR_0, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); exit(1); } }
[ "void FUNC_0(AVDictionary *VAR_0)\n{", "AVDictionaryEntry *t;", "if ((t = av_dict_get(VAR_0, \"\", NULL, AV_DICT_IGNORE_SUFFIX))) {", "av_log(NULL, AV_LOG_FATAL, \"Option %s not found.\\n\", t->key);", "exit(1);", "}", "}" ]
[ 0, 0, 0, 0, 1, 0, 0 ]
[ [ 1, 3 ], [ 5 ], [ 7 ], [ 9 ], [ 11 ], [ 13 ], [ 15 ] ]
13
"static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)\n\n{\n\n BDRVNBDState *s (...TRUNCATED)
true
qemu
a1d4e38a8b01a6699355c31867d524f8d4cd480e
"static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)\n\n{\n\n BDRVNBDState *s (...TRUNCATED)
{ "code": [], "line_no": [] }
"static void FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1)\n\n{\n\n BDRVNBDState *s = VAR_0->opaq(...TRUNCATED)
["static void FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1)\n{","BDRVNBDState *s = VAR_0->opaque;","(...TRUNCATED)
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
[[1,3],[5],[7],[9],[11],[13],[17],[19],[21],[23],[25],[27],[29],[31],[33],[37],[41],[43,45,47],[49,5(...TRUNCATED)

Dataset Card for "devign_with_norm_vul_lines"

More Information needed

Original Paper: https://www.sciencedirect.com/science/article/abs/pii/S0167739X24004680

bibtex

@article{TRAN2024107504,
title = {DetectVul: A statement-level code vulnerability detection for Python},
journal = {Future Generation Computer Systems},
pages = {107504},
year = {2024},
issn = {0167-739X},
doi = {https://doi.org/10.1016/j.future.2024.107504},
url = {https://www.sciencedirect.com/science/article/pii/S0167739X24004680},
author = {Hoai-Chau Tran and Anh-Duy Tran and Kim-Hung Le},
keywords = {Source code vulnerability detection, Deep learning, Natural language processing},
abstract = {Detecting vulnerabilities in source code using graph neural networks (GNN) has gained significant attention in recent years. However, the detection performance of these approaches relies highly on the graph structure, and constructing meaningful graphs is expensive. Moreover, they often operate at a coarse level of granularity (such as function-level), which limits their applicability to other scripting languages like Python and their effectiveness in identifying vulnerabilities. To address these limitations, we propose DetectVul, a new approach that accurately detects vulnerable patterns in Python source code at the statement level. DetectVul applies self-attention to directly learn patterns and interactions between statements in a raw Python function; thus, it eliminates the complicated graph extraction process without sacrificing model performance. In addition, the information about each type of statement is also leveraged to enhance the model’s detection accuracy. In our experiments, we used two datasets, CVEFixes and Vudenc, with 211,317 Python statements in 21,571 functions from real-world projects on GitHub, covering seven vulnerability types. Our experiments show that DetectVul outperforms GNN-based models using control flow graphs, achieving the best F1 score of 74.47%, which is 25.45% and 18.05% higher than the best GCN and GAT models, respectively.}
}
Downloads last month
76