comparison utils.c @ 172:9a0ab557b159 libavformat

fixed RTP/TCP client support
author bellard
date Tue, 15 Jul 2003 16:57:35 +0000
parents 808dabf5a88e
children b6fa8a3b78c6
comparison
equal deleted inserted replaced
171:fe5fc579b4de 172:9a0ab557b159
310 AVInputFormat *fmt, 310 AVInputFormat *fmt,
311 int buf_size, 311 int buf_size,
312 AVFormatParameters *ap) 312 AVFormatParameters *ap)
313 { 313 {
314 AVFormatContext *ic = NULL; 314 AVFormatContext *ic = NULL;
315 int err; 315 int err, must_open_file;
316 char buf[PROBE_BUF_SIZE]; 316 char buf[PROBE_BUF_SIZE];
317 AVProbeData probe_data, *pd = &probe_data; 317 AVProbeData probe_data, *pd = &probe_data;
318 318
319 ic = av_mallocz(sizeof(AVFormatContext)); 319 ic = av_mallocz(sizeof(AVFormatContext));
320 if (!ic) { 320 if (!ic) {
329 if (!fmt) { 329 if (!fmt) {
330 /* guess format if no file can be opened */ 330 /* guess format if no file can be opened */
331 fmt = av_probe_input_format(pd, 0); 331 fmt = av_probe_input_format(pd, 0);
332 } 332 }
333 333
334 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { 334 /* do not open file if the format does not need it. XXX: specific
335 hack needed to handle RTSP/TCP */
336 must_open_file = 1;
337 if ((fmt->flags & AVFMT_NOFILE) ||
338 (fmt == &rtp_demux && !strcmp(filename, "null"))) {
339 must_open_file = 0;
340 }
341
342 if (!fmt || must_open_file) {
335 /* if no file needed do not try to open one */ 343 /* if no file needed do not try to open one */
336 if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) { 344 if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {
337 err = AVERROR_IO; 345 err = AVERROR_IO;
338 goto fail; 346 goto fail;
339 } 347 }
395 if (err < 0) 403 if (err < 0)
396 goto fail1; 404 goto fail1;
397 *ic_ptr = ic; 405 *ic_ptr = ic;
398 return 0; 406 return 0;
399 fail1: 407 fail1:
400 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { 408 if (!fmt || must_open_file) {
401 url_fclose(&ic->pb); 409 url_fclose(&ic->pb);
402 } 410 }
403 fail: 411 fail:
404 if (ic) { 412 if (ic) {
405 av_freep(&ic->priv_data); 413 av_freep(&ic->priv_data);
662 * 670 *
663 * @param s media file handle 671 * @param s media file handle
664 */ 672 */
665 void av_close_input_file(AVFormatContext *s) 673 void av_close_input_file(AVFormatContext *s)
666 { 674 {
667 int i; 675 int i, must_open_file;
668 676
669 if (s->iformat->read_close) 677 if (s->iformat->read_close)
670 s->iformat->read_close(s); 678 s->iformat->read_close(s);
671 for(i=0;i<s->nb_streams;i++) { 679 for(i=0;i<s->nb_streams;i++) {
672 av_free(s->streams[i]); 680 av_free(s->streams[i]);
680 av_free(p); 688 av_free(p);
681 p = p1; 689 p = p1;
682 } 690 }
683 s->packet_buffer = NULL; 691 s->packet_buffer = NULL;
684 } 692 }
685 if (!(s->iformat->flags & AVFMT_NOFILE)) { 693 must_open_file = 1;
694 if ((s->iformat->flags & AVFMT_NOFILE) ||
695 (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))) {
696 must_open_file = 0;
697 }
698 if (must_open_file) {
686 url_fclose(&s->pb); 699 url_fclose(&s->pb);
687 } 700 }
688 av_freep(&s->priv_data); 701 av_freep(&s->priv_data);
689 av_free(s); 702 av_free(s);
690 } 703 }