Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: source/patched-ffmpeg-mt/libavformat/utils.c

Issue 3384002: ffmpeg source update for sep 09 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * various utility functions for use within FFmpeg 2 * various utility functions for use within FFmpeg
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 if (ic->iformat->read_header) { 451 if (ic->iformat->read_header) {
452 err = ic->iformat->read_header(ic, ap); 452 err = ic->iformat->read_header(ic, ap);
453 if (err < 0) 453 if (err < 0)
454 goto fail; 454 goto fail;
455 } 455 }
456 456
457 if (pb && !ic->data_offset) 457 if (pb && !ic->data_offset)
458 ic->data_offset = url_ftell(ic->pb); 458 ic->data_offset = url_ftell(ic->pb);
459 459
460 #if LIBAVFORMAT_VERSION_MAJOR < 53 460 #if FF_API_OLD_METADATA
461 ff_metadata_demux_compat(ic); 461 ff_metadata_demux_compat(ic);
462 #endif 462 #endif
463 463
464 ic->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; 464 ic->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
465 465
466 *ic_ptr = ic; 466 *ic_ptr = ic;
467 return 0; 467 return 0;
468 fail: 468 fail:
469 if (ic) { 469 if (ic) {
470 int i; 470 int i;
471 av_freep(&ic->priv_data); 471 av_freep(&ic->priv_data);
472 for(i=0;i<ic->nb_streams;i++) { 472 for(i=0;i<ic->nb_streams;i++) {
473 AVStream *st = ic->streams[i]; 473 AVStream *st = ic->streams[i];
474 if (st) { 474 if (st) {
475 av_free(st->priv_data); 475 av_free(st->priv_data);
476 av_free(st->codec->extradata); 476 av_free(st->codec->extradata);
477 av_free(st->codec);
477 } 478 }
478 av_free(st); 479 av_free(st);
479 } 480 }
480 } 481 }
481 av_free(ic); 482 av_free(ic);
482 *ic_ptr = NULL; 483 *ic_ptr = NULL;
483 return err; 484 return err;
484 } 485 }
485 486
486 /** size of probe buffer, for guessing file type from file contents */ 487 /** size of probe buffer, for guessing file type from file contents */
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 ) 2159 )
2159 return 1; 2160 return 1;
2160 return 0; 2161 return 0;
2161 } 2162 }
2162 2163
2163 int av_find_stream_info(AVFormatContext *ic) 2164 int av_find_stream_info(AVFormatContext *ic)
2164 { 2165 {
2165 int i, count, ret, read_size, j; 2166 int i, count, ret, read_size, j;
2166 AVStream *st; 2167 AVStream *st;
2167 AVPacket pkt1, *pkt; 2168 AVPacket pkt1, *pkt;
2168 int64_t last_dts[MAX_STREAMS];
2169 int64_t duration_gcd[MAX_STREAMS]={0};
2170 int duration_count[MAX_STREAMS]={0};
2171 double (*duration_error)[MAX_STD_TIMEBASES];
2172 int64_t old_offset = url_ftell(ic->pb); 2169 int64_t old_offset = url_ftell(ic->pb);
2173 int64_t codec_info_duration[MAX_STREAMS]={0}; 2170 struct {
2174 2171 int64_t last_dts;
2175 duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); 2172 int64_t duration_gcd;
2176 if (!duration_error) return AVERROR(ENOMEM); 2173 int duration_count;
2174 double duration_error[MAX_STD_TIMEBASES];
2175 int64_t codec_info_duration;
2176 } info[MAX_STREAMS] = {{0}};
2177 2177
2178 for(i=0;i<ic->nb_streams;i++) { 2178 for(i=0;i<ic->nb_streams;i++) {
2179 st = ic->streams[i]; 2179 st = ic->streams[i];
2180 if (st->codec->codec_id == CODEC_ID_AAC) { 2180 if (st->codec->codec_id == CODEC_ID_AAC) {
2181 st->codec->sample_rate = 0; 2181 st->codec->sample_rate = 0;
2182 st->codec->frame_size = 0; 2182 st->codec->frame_size = 0;
2183 st->codec->channels = 0; 2183 st->codec->channels = 0;
2184 } 2184 }
2185 if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ 2185 if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
2186 /* if(!st->time_base.num) 2186 /* if(!st->time_base.num)
(...skipping 11 matching lines...) Expand all
2198 assert(!st->codec->codec); 2198 assert(!st->codec->codec);
2199 //try to just open decoders, in case this is enough to get parameters 2199 //try to just open decoders, in case this is enough to get parameters
2200 if(!has_codec_parameters(st->codec)){ 2200 if(!has_codec_parameters(st->codec)){
2201 AVCodec *codec = avcodec_find_decoder(st->codec->codec_id); 2201 AVCodec *codec = avcodec_find_decoder(st->codec->codec_id);
2202 if (codec) 2202 if (codec)
2203 avcodec_open(st->codec, codec); 2203 avcodec_open(st->codec, codec);
2204 } 2204 }
2205 } 2205 }
2206 2206
2207 for(i=0;i<MAX_STREAMS;i++){ 2207 for(i=0;i<MAX_STREAMS;i++){
2208 last_dts[i]= AV_NOPTS_VALUE; 2208 info[i].last_dts= AV_NOPTS_VALUE;
2209 } 2209 }
2210 2210
2211 count = 0; 2211 count = 0;
2212 read_size = 0; 2212 read_size = 0;
2213 for(;;) { 2213 for(;;) {
2214 if(url_interrupt_cb()){ 2214 if(url_interrupt_cb()){
2215 ret= AVERROR(EINTR); 2215 ret= AVERROR(EINTR);
2216 av_log(ic, AV_LOG_DEBUG, "interrupted\n"); 2216 av_log(ic, AV_LOG_DEBUG, "interrupted\n");
2217 break; 2217 break;
2218 } 2218 }
2219 2219
2220 /* check if one codec still needs to be handled */ 2220 /* check if one codec still needs to be handled */
2221 for(i=0;i<ic->nb_streams;i++) { 2221 for(i=0;i<ic->nb_streams;i++) {
2222 st = ic->streams[i]; 2222 st = ic->streams[i];
2223 if (!has_codec_parameters(st->codec)) 2223 if (!has_codec_parameters(st->codec))
2224 break; 2224 break;
2225 /* variable fps and no guess at the real fps */ 2225 /* variable fps and no guess at the real fps */
2226 if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_ frame_rate.num) 2226 if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_ frame_rate.num)
2227 && duration_count[i]<20 && st->codec->codec_type == AVMEDIA_TYPE_ VIDEO) 2227 && info[i].duration_count<20 && st->codec->codec_type == AVMEDIA_ TYPE_VIDEO)
2228 break; 2228 break;
2229 if(st->parser && st->parser->parser->split && !st->codec->extradata) 2229 if(st->parser && st->parser->parser->split && !st->codec->extradata)
2230 break; 2230 break;
2231 if(st->first_dts == AV_NOPTS_VALUE) 2231 if(st->first_dts == AV_NOPTS_VALUE)
2232 break; 2232 break;
2233 } 2233 }
2234 if (i == ic->nb_streams) { 2234 if (i == ic->nb_streams) {
2235 /* NOTE: if the format has no header, then we need to read 2235 /* NOTE: if the format has no header, then we need to read
2236 some packets to get most of the streams, so we cannot 2236 some packets to get most of the streams, so we cannot
2237 stop here */ 2237 stop here */
(...skipping 27 matching lines...) Expand all
2265 av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf); 2265 av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf);
2266 } else { 2266 } else {
2267 ret = 0; 2267 ret = 0;
2268 } 2268 }
2269 } 2269 }
2270 break; 2270 break;
2271 } 2271 }
2272 2272
2273 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end); 2273 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end);
2274 if(av_dup_packet(pkt) < 0) { 2274 if(av_dup_packet(pkt) < 0) {
2275 av_free(duration_error);
2276 return AVERROR(ENOMEM); 2275 return AVERROR(ENOMEM);
2277 } 2276 }
2278 2277
2279 read_size += pkt->size; 2278 read_size += pkt->size;
2280 2279
2281 st = ic->streams[pkt->stream_index]; 2280 st = ic->streams[pkt->stream_index];
2282 if(st->codec_info_nb_frames>1) { 2281 if(st->codec_info_nb_frames>1) {
2283 if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->in dex], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration){ 2282 if (st->time_base.den > 0 && av_rescale_q(info[st->index].codec_info _duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration){
2284 av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n"); 2283 av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n");
2285 break; 2284 break;
2286 } 2285 }
2287 codec_info_duration[st->index] += pkt->duration; 2286 info[st->index].codec_info_duration += pkt->duration;
2288 } 2287 }
2289 { 2288 {
2290 int index= pkt->stream_index; 2289 int index= pkt->stream_index;
2291 int64_t last= last_dts[index]; 2290 int64_t last= info[index].last_dts;
2292 int64_t duration= pkt->dts - last; 2291 int64_t duration= pkt->dts - last;
2293 2292
2294 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration> 0){ 2293 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration> 0){
2295 double dur= duration * av_q2d(st->time_base); 2294 double dur= duration * av_q2d(st->time_base);
2296 2295
2297 // if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) 2296 // if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
2298 // av_log(NULL, AV_LOG_ERROR, "%f\n", dur); 2297 // av_log(NULL, AV_LOG_ERROR, "%f\n", dur);
2299 if(duration_count[index] < 2) 2298 if(info[index].duration_count < 2)
2300 memset(duration_error[index], 0, sizeof(*duration_error)); 2299 memset(info[index].duration_error, 0, sizeof(info[index].dur ation_error));
2301 for(i=1; i<MAX_STD_TIMEBASES; i++){ 2300 for(i=1; i<MAX_STD_TIMEBASES; i++){
2302 int framerate= get_std_framerate(i); 2301 int framerate= get_std_framerate(i);
2303 int ticks= lrintf(dur*framerate/(1001*12)); 2302 int ticks= lrintf(dur*framerate/(1001*12));
2304 double error= dur - ticks*1001*12/(double)framerate; 2303 double error= dur - ticks*1001*12/(double)framerate;
2305 duration_error[index][i] += error*error; 2304 info[index].duration_error[i] += error*error;
2306 } 2305 }
2307 duration_count[index]++; 2306 info[index].duration_count++;
2308 // ignore the first 4 values, they might have some random jitter 2307 // ignore the first 4 values, they might have some random jitter
2309 if (duration_count[index] > 3) 2308 if (info[index].duration_count > 3)
2310 duration_gcd[index] = av_gcd(duration_gcd[index], duration); 2309 info[index].duration_gcd = av_gcd(info[index].duration_gcd, duration);
2311 } 2310 }
2312 if(last == AV_NOPTS_VALUE || duration_count[index]<=1) 2311 if(last == AV_NOPTS_VALUE || info[index].duration_count <= 1)
2313 last_dts[pkt->stream_index]= pkt->dts; 2312 info[pkt->stream_index].last_dts = pkt->dts;
2314 } 2313 }
2315 if(st->parser && st->parser->parser->split && !st->codec->extradata){ 2314 if(st->parser && st->parser->parser->split && !st->codec->extradata){
2316 int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); 2315 int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
2317 if(i){ 2316 if(i){
2318 st->codec->extradata_size= i; 2317 st->codec->extradata_size= i;
2319 st->codec->extradata= av_malloc(st->codec->extradata_size + FF_I NPUT_BUFFER_PADDING_SIZE); 2318 st->codec->extradata= av_malloc(st->codec->extradata_size + FF_I NPUT_BUFFER_PADDING_SIZE);
2320 memcpy(st->codec->extradata, pkt->data, st->codec->extradata_siz e); 2319 memcpy(st->codec->extradata, pkt->data, st->codec->extradata_siz e);
2321 memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE ); 2320 memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE );
2322 } 2321 }
2323 } 2322 }
(...skipping 10 matching lines...) Expand all
2334 } 2333 }
2335 2334
2336 // close codecs which were opened in try_decode_frame() 2335 // close codecs which were opened in try_decode_frame()
2337 for(i=0;i<ic->nb_streams;i++) { 2336 for(i=0;i<ic->nb_streams;i++) {
2338 st = ic->streams[i]; 2337 st = ic->streams[i];
2339 if(st->codec->codec) 2338 if(st->codec->codec)
2340 avcodec_close(st->codec); 2339 avcodec_close(st->codec);
2341 } 2340 }
2342 for(i=0;i<ic->nb_streams;i++) { 2341 for(i=0;i<ic->nb_streams;i++) {
2343 st = ic->streams[i]; 2342 st = ic->streams[i];
2344 if(st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && codec_info_d uration[i]) 2343 if(st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && info[i].code c_info_duration)
2345 av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, 2344 av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
2346 (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den, 2345 (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den,
2347 codec_info_duration[i] *(int64_t)st->time_base.num, 600 00); 2346 info[i].codec_info_duration*(int64_t)st->time_base.num, 60 000);
2348 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { 2347 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
2349 if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample) 2348 if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample)
2350 st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pi x_fmt); 2349 st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pi x_fmt);
2351 2350
2352 // the check for tb_unreliable() is not completely correct, since th is is not about handling 2351 // the check for tb_unreliable() is not completely correct, since th is is not about handling
2353 // a unreliable/inexact time base, but a time base that is finer tha n necessary, as e.g. 2352 // a unreliable/inexact time base, but a time base that is finer tha n necessary, as e.g.
2354 // ipmovie.c produces. 2353 // ipmovie.c produces.
2355 if (tb_unreliable(st->codec) && duration_count[i] > 15 && duration_g cd[i] > 1 && !st->r_frame_rate.num) 2354 if (tb_unreliable(st->codec) && info[i].duration_count > 15 && info[ i].duration_gcd > 1 && !st->r_frame_rate.num)
2356 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time _base.den, st->time_base.num * duration_gcd[i], INT_MAX); 2355 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time _base.den, st->time_base.num * info[i].duration_gcd, INT_MAX);
2357 if(duration_count[i] && !st->r_frame_rate.num 2356 if(info[i].duration_count && !st->r_frame_rate.num
2358 && tb_unreliable(st->codec) /*&& 2357 && tb_unreliable(st->codec) /*&&
2359 //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ... 2358 //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ...
2360 st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->t ime_base.den*/){ 2359 st->time_base.num*duration_sum[i]/info[i].duration_count*101LL > st->time_base.den*/){
2361 int num = 0; 2360 int num = 0;
2362 double best_error= 2*av_q2d(st->time_base); 2361 double best_error= 2*av_q2d(st->time_base);
2363 best_error= best_error*best_error*duration_count[i]*1000*12*30; 2362 best_error= best_error*best_error*info[i].duration_count*1000*12 *30;
2364 2363
2365 for(j=1; j<MAX_STD_TIMEBASES; j++){ 2364 for(j=1; j<MAX_STD_TIMEBASES; j++){
2366 double error= duration_error[i][j] * get_std_framerate(j); 2365 double error= info[i].duration_error[j] * get_std_framerate( j);
2367 // if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) 2366 // if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
2368 // av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerat e(j) / 12.0/1001, error); 2367 // av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerat e(j) / 12.0/1001, error);
2369 if(error < best_error){ 2368 if(error < best_error){
2370 best_error= error; 2369 best_error= error;
2371 num = get_std_framerate(j); 2370 num = get_std_framerate(j);
2372 } 2371 }
2373 } 2372 }
2374 // do not increase frame rate by more than 1 % in order to match a standard rate. 2373 // do not increase frame rate by more than 1 % in order to match a standard rate.
2375 if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.0 1 * av_q2d(st->r_frame_rate))) 2374 if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.0 1 * av_q2d(st->r_frame_rate)))
2376 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); 2375 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 ppkt1= ppkt1->next; 2413 ppkt1= ppkt1->next;
2415 } 2414 }
2416 if(ppkt1) 2415 if(ppkt1)
2417 continue; 2416 continue;
2418 st->cur_dts -= delta; 2417 st->cur_dts -= delta;
2419 } 2418 }
2420 } 2419 }
2421 } 2420 }
2422 #endif 2421 #endif
2423 2422
2424 av_free(duration_error);
2425
2426 return ret; 2423 return ret;
2427 } 2424 }
2428 2425
2429 /*******************************************************/ 2426 /*******************************************************/
2430 2427
2431 int av_read_play(AVFormatContext *s) 2428 int av_read_play(AVFormatContext *s)
2432 { 2429 {
2433 if (s->iformat->read_play) 2430 if (s->iformat->read_play)
2434 return s->iformat->read_play(s); 2431 return s->iformat->read_play(s);
2435 if (s->pb) 2432 if (s->pb)
(...skipping 21 matching lines...) Expand all
2457 /* free all data in a stream component */ 2454 /* free all data in a stream component */
2458 st = s->streams[i]; 2455 st = s->streams[i];
2459 if (st->parser) { 2456 if (st->parser) {
2460 av_parser_close(st->parser); 2457 av_parser_close(st->parser);
2461 av_free_packet(&st->cur_pkt); 2458 av_free_packet(&st->cur_pkt);
2462 } 2459 }
2463 av_metadata_free(&st->metadata); 2460 av_metadata_free(&st->metadata);
2464 av_free(st->index_entries); 2461 av_free(st->index_entries);
2465 av_free(st->codec->extradata); 2462 av_free(st->codec->extradata);
2466 av_free(st->codec); 2463 av_free(st->codec);
2467 #if LIBAVFORMAT_VERSION_INT < (53<<16) 2464 #if FF_API_OLD_METADATA
2468 av_free(st->filename); 2465 av_free(st->filename);
2469 #endif 2466 #endif
2470 av_free(st->priv_data); 2467 av_free(st->priv_data);
2471 av_free(st); 2468 av_free(st);
2472 } 2469 }
2473 for(i=s->nb_programs-1; i>=0; i--) { 2470 for(i=s->nb_programs-1; i>=0; i--) {
2474 #if LIBAVFORMAT_VERSION_INT < (53<<16) 2471 #if FF_API_OLD_METADATA
2475 av_freep(&s->programs[i]->provider_name); 2472 av_freep(&s->programs[i]->provider_name);
2476 av_freep(&s->programs[i]->name); 2473 av_freep(&s->programs[i]->name);
2477 #endif 2474 #endif
2478 av_metadata_free(&s->programs[i]->metadata); 2475 av_metadata_free(&s->programs[i]->metadata);
2479 av_freep(&s->programs[i]->stream_index); 2476 av_freep(&s->programs[i]->stream_index);
2480 av_freep(&s->programs[i]); 2477 av_freep(&s->programs[i]);
2481 } 2478 }
2482 av_freep(&s->programs); 2479 av_freep(&s->programs);
2483 flush_packet_queue(s); 2480 flush_packet_queue(s);
2484 av_freep(&s->priv_data); 2481 av_freep(&s->priv_data);
2485 while(s->nb_chapters--) { 2482 while(s->nb_chapters--) {
2486 #if LIBAVFORMAT_VERSION_INT < (53<<16) 2483 #if FF_API_OLD_METADATA
2487 av_free(s->chapters[s->nb_chapters]->title); 2484 av_free(s->chapters[s->nb_chapters]->title);
2488 #endif 2485 #endif
2489 av_metadata_free(&s->chapters[s->nb_chapters]->metadata); 2486 av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
2490 av_free(s->chapters[s->nb_chapters]); 2487 av_free(s->chapters[s->nb_chapters]);
2491 } 2488 }
2492 av_freep(&s->chapters); 2489 av_freep(&s->chapters);
2493 av_metadata_free(&s->metadata); 2490 av_metadata_free(&s->metadata);
2491 av_freep(&s->key);
2494 av_free(s); 2492 av_free(s);
2495 } 2493 }
2496 2494
2497 void av_close_input_file(AVFormatContext *s) 2495 void av_close_input_file(AVFormatContext *s)
2498 { 2496 {
2499 ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb; 2497 ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;
2500 av_close_input_stream(s); 2498 av_close_input_stream(s);
2501 if (pb) 2499 if (pb)
2502 url_fclose(pb); 2500 url_fclose(pb);
2503 } 2501 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 for(i=0; i<s->nb_chapters; i++) 2577 for(i=0; i<s->nb_chapters; i++)
2580 if(s->chapters[i]->id == id) 2578 if(s->chapters[i]->id == id)
2581 chapter = s->chapters[i]; 2579 chapter = s->chapters[i];
2582 2580
2583 if(!chapter){ 2581 if(!chapter){
2584 chapter= av_mallocz(sizeof(AVChapter)); 2582 chapter= av_mallocz(sizeof(AVChapter));
2585 if(!chapter) 2583 if(!chapter)
2586 return NULL; 2584 return NULL;
2587 dynarray_add(&s->chapters, &s->nb_chapters, chapter); 2585 dynarray_add(&s->chapters, &s->nb_chapters, chapter);
2588 } 2586 }
2589 #if LIBAVFORMAT_VERSION_INT < (53<<16) 2587 #if FF_API_OLD_METADATA
2590 av_free(chapter->title); 2588 av_free(chapter->title);
2591 #endif 2589 #endif
2592 av_metadata_set2(&chapter->metadata, "title", title, 0); 2590 av_metadata_set2(&chapter->metadata, "title", title, 0);
2593 chapter->id = id; 2591 chapter->id = id;
2594 chapter->time_base= time_base; 2592 chapter->time_base= time_base;
2595 chapter->start = start; 2593 chapter->start = start;
2596 chapter->end = end; 2594 chapter->end = end;
2597 2595
2598 return chapter; 2596 return chapter;
2599 } 2597 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 if(s->oformat->codec_tag){ 2694 if(s->oformat->codec_tag){
2697 if(st->codec->codec_tag && st->codec->codec_id == CODEC_ID_RAWVIDEO && av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id) == 0 && !validat e_codec_tag(s, st)){ 2695 if(st->codec->codec_tag && st->codec->codec_id == CODEC_ID_RAWVIDEO && av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id) == 0 && !validat e_codec_tag(s, st)){
2698 //the current rawvideo encoding system ends up setting the wrong codec_tag for avi, we override it here 2696 //the current rawvideo encoding system ends up setting the wrong codec_tag for avi, we override it here
2699 st->codec->codec_tag= 0; 2697 st->codec->codec_tag= 0;
2700 } 2698 }
2701 if(st->codec->codec_tag){ 2699 if(st->codec->codec_tag){
2702 if (!validate_codec_tag(s, st)) { 2700 if (!validate_codec_tag(s, st)) {
2703 char tagbuf[32]; 2701 char tagbuf[32];
2704 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), st->codec->c odec_tag); 2702 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), st->codec->c odec_tag);
2705 av_log(s, AV_LOG_ERROR, 2703 av_log(s, AV_LOG_ERROR,
2706 "Tag %s/0x%08x incompatible with output codec '%s'\n" , 2704 "Tag %s/0x%08x incompatible with output codec id '%d' \n",
2707 tagbuf, st->codec->codec_tag, st->codec->codec->name) ; 2705 tagbuf, st->codec->codec_tag, st->codec->codec_id);
2708 return AVERROR_INVALIDDATA; 2706 return AVERROR_INVALIDDATA;
2709 } 2707 }
2710 }else 2708 }else
2711 st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st ->codec->codec_id); 2709 st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st ->codec->codec_id);
2712 } 2710 }
2713 2711
2714 if(s->oformat->flags & AVFMT_GLOBALHEADER && 2712 if(s->oformat->flags & AVFMT_GLOBALHEADER &&
2715 !(st->codec->flags & CODEC_FLAG_GLOBAL_HEADER)) 2713 !(st->codec->flags & CODEC_FLAG_GLOBAL_HEADER))
2716 av_log(s, AV_LOG_WARNING, "Codec for stream %d does not use global hea ders but container format requires global headers\n", i); 2714 av_log(s, AV_LOG_WARNING, "Codec for stream %d does not use global hea ders but container format requires global headers\n", i);
2717 } 2715 }
2718 2716
2719 if (!s->priv_data && s->oformat->priv_data_size > 0) { 2717 if (!s->priv_data && s->oformat->priv_data_size > 0) {
2720 s->priv_data = av_mallocz(s->oformat->priv_data_size); 2718 s->priv_data = av_mallocz(s->oformat->priv_data_size);
2721 if (!s->priv_data) 2719 if (!s->priv_data)
2722 return AVERROR(ENOMEM); 2720 return AVERROR(ENOMEM);
2723 } 2721 }
2724 2722
2725 #if LIBAVFORMAT_VERSION_MAJOR < 53 2723 #if FF_API_OLD_METADATA
2726 ff_metadata_mux_compat(s); 2724 ff_metadata_mux_compat(s);
2727 #endif 2725 #endif
2728 2726
2729 /* set muxer identification string */ 2727 /* set muxer identification string */
2730 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { 2728 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
2731 AVMetadata *m; 2729 AVMetadata *m;
2732 AVMetadataTag *t; 2730 AVMetadataTag *t;
2733 2731
2734 if (!(m = av_mallocz(sizeof(AVMetadata)))) 2732 if (!(m = av_mallocz(sizeof(AVMetadata))))
2735 return AVERROR(ENOMEM); 2733 return AVERROR(ENOMEM);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 mins %= 60; 3133 mins %= 60;
3136 av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs, 3134 av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
3137 (100 * us) / AV_TIME_BASE); 3135 (100 * us) / AV_TIME_BASE);
3138 } else { 3136 } else {
3139 av_log(NULL, AV_LOG_INFO, "N/A"); 3137 av_log(NULL, AV_LOG_INFO, "N/A");
3140 } 3138 }
3141 if (ic->start_time != AV_NOPTS_VALUE) { 3139 if (ic->start_time != AV_NOPTS_VALUE) {
3142 int secs, us; 3140 int secs, us;
3143 av_log(NULL, AV_LOG_INFO, ", start: "); 3141 av_log(NULL, AV_LOG_INFO, ", start: ");
3144 secs = ic->start_time / AV_TIME_BASE; 3142 secs = ic->start_time / AV_TIME_BASE;
3145 us = ic->start_time % AV_TIME_BASE; 3143 us = abs(ic->start_time % AV_TIME_BASE);
3146 av_log(NULL, AV_LOG_INFO, "%d.%06d", 3144 av_log(NULL, AV_LOG_INFO, "%d.%06d",
3147 secs, (int)av_rescale(us, 1000000, AV_TIME_BASE)); 3145 secs, (int)av_rescale(us, 1000000, AV_TIME_BASE));
3148 } 3146 }
3149 av_log(NULL, AV_LOG_INFO, ", bitrate: "); 3147 av_log(NULL, AV_LOG_INFO, ", bitrate: ");
3150 if (ic->bit_rate) { 3148 if (ic->bit_rate) {
3151 av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000); 3149 av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000);
3152 } else { 3150 } else {
3153 av_log(NULL, AV_LOG_INFO, "N/A"); 3151 av_log(NULL, AV_LOG_INFO, "N/A");
3154 } 3152 }
3155 av_log(NULL, AV_LOG_INFO, "\n"); 3153 av_log(NULL, AV_LOG_INFO, "\n");
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
3598 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc; 3596 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
3599 3597
3600 for(i = 0; i < s; i++) { 3598 for(i = 0; i < s; i++) {
3601 buff[i * 2] = hex_table[src[i] >> 4]; 3599 buff[i * 2] = hex_table[src[i] >> 4];
3602 buff[i * 2 + 1] = hex_table[src[i] & 0xF]; 3600 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
3603 } 3601 }
3604 3602
3605 return buff; 3603 return buff;
3606 } 3604 }
3607 3605
3606 int ff_hex_to_data(uint8_t *data, const char *p)
3607 {
3608 int c, len, v;
3609
3610 len = 0;
3611 v = 1;
3612 for (;;) {
3613 p += strspn(p, SPACE_CHARS);
3614 if (*p == '\0')
3615 break;
3616 c = toupper((unsigned char) *p++);
3617 if (c >= '0' && c <= '9')
3618 c = c - '0';
3619 else if (c >= 'A' && c <= 'F')
3620 c = c - 'A' + 10;
3621 else
3622 break;
3623 v = (v << 4) | c;
3624 if (v & 0x100) {
3625 if (data)
3626 data[len] = v;
3627 len++;
3628 v = 1;
3629 }
3630 }
3631 return len;
3632 }
3633
3608 void av_set_pts_info(AVStream *s, int pts_wrap_bits, 3634 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
3609 unsigned int pts_num, unsigned int pts_den) 3635 unsigned int pts_num, unsigned int pts_den)
3610 { 3636 {
3611 s->pts_wrap_bits = pts_wrap_bits; 3637 s->pts_wrap_bits = pts_wrap_bits;
3612 3638
3613 if(av_reduce(&s->time_base.num, &s->time_base.den, pts_num, pts_den, INT_MAX )){ 3639 if(av_reduce(&s->time_base.num, &s->time_base.den, pts_num, pts_den, INT_MAX )){
3614 if(s->time_base.num != pts_num) 3640 if(s->time_base.num != pts_num)
3615 av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from tim ebase\n", s->index, pts_num/s->time_base.num); 3641 av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from tim ebase\n", s->index, pts_num/s->time_base.num);
3616 }else 3642 }else
3617 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n", s->index); 3643 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n", s->index);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3676 local_pkt.pts = av_rescale_q(pkt->pts, 3702 local_pkt.pts = av_rescale_q(pkt->pts,
3677 src->streams[pkt->stream_index]->time_base, 3703 src->streams[pkt->stream_index]->time_base,
3678 dst->streams[dst_stream]->time_base); 3704 dst->streams[dst_stream]->time_base);
3679 if (pkt->dts != AV_NOPTS_VALUE) 3705 if (pkt->dts != AV_NOPTS_VALUE)
3680 local_pkt.dts = av_rescale_q(pkt->dts, 3706 local_pkt.dts = av_rescale_q(pkt->dts,
3681 src->streams[pkt->stream_index]->time_base, 3707 src->streams[pkt->stream_index]->time_base,
3682 dst->streams[dst_stream]->time_base); 3708 dst->streams[dst_stream]->time_base);
3683 return av_write_frame(dst, &local_pkt); 3709 return av_write_frame(dst, &local_pkt);
3684 } 3710 }
3685 3711
3712 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
3713 void *context)
3714 {
3715 const char *ptr = str;
3716
3717 /* Parse key=value pairs. */
3718 for (;;) {
3719 const char *key;
3720 char *dest = NULL, *dest_end;
3721 int key_len, dest_len = 0;
3722
3723 /* Skip whitespace and potential commas. */
3724 while (*ptr && (isspace(*ptr) || *ptr == ','))
3725 ptr++;
3726 if (!*ptr)
3727 break;
3728
3729 key = ptr;
3730
3731 if (!(ptr = strchr(key, '=')))
3732 break;
3733 ptr++;
3734 key_len = ptr - key;
3735
3736 callback_get_buf(context, key, key_len, &dest, &dest_len);
3737 dest_end = dest + dest_len - 1;
3738
3739 if (*ptr == '\"') {
3740 ptr++;
3741 while (*ptr && *ptr != '\"') {
3742 if (*ptr == '\\') {
3743 if (!ptr[1])
3744 break;
3745 if (dest && dest < dest_end)
3746 *dest++ = ptr[1];
3747 ptr += 2;
3748 } else {
3749 if (dest && dest < dest_end)
3750 *dest++ = *ptr;
3751 ptr++;
3752 }
3753 }
3754 if (*ptr == '\"')
3755 ptr++;
3756 } else {
3757 for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
3758 if (dest && dest < dest_end)
3759 *dest++ = *ptr;
3760 }
3761 if (dest)
3762 *dest = 0;
3763 }
3764 }
3765
OLDNEW
« no previous file with comments | « source/patched-ffmpeg-mt/libavformat/tcp.c ('k') | source/patched-ffmpeg-mt/libavformat/vorbiscomment.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698