]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/utils.c
align
[ffmpeg] / libavformat / utils.c
index b9247cf8037aa5e11b8a0f4c922d63dce50cdfc6..a593f42d6c79709e7fda0414d81934f7f96e64f8 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "avformat.h"
-#include <ctype.h>
-#ifdef CONFIG_WIN32
-#define strcasecmp _stricmp
-#include <sys/types.h>
-#include <sys/timeb.h>
-#elif defined(CONFIG_OS2)
-#include <string.h>
-#define strcasecmp stricmp
-#include <sys/time.h>
-#else
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#endif
-#include <time.h>
-
-#ifndef HAVE_STRPTIME
-#include "strptime.h"
-#endif
 
 AVInputFormat *first_iformat;
 AVOutputFormat *first_oformat;
@@ -336,8 +317,11 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
     /* do not open file if the format does not need it. XXX: specific
        hack needed to handle RTSP/TCP */
     must_open_file = 1;
-    if ((fmt && (fmt->flags & AVFMT_NOFILE)) ||
-        (fmt == &rtp_demux && !strcmp(filename, "null"))) {
+    if ((fmt && (fmt->flags & AVFMT_NOFILE)) 
+#ifdef CONFIG_NETWORK
+        || (fmt == &rtp_demux && !strcmp(filename, "null"))
+#endif
+        ) {
         must_open_file = 0;
     }
 
@@ -552,6 +536,7 @@ static void flush_packet_queue(AVFormatContext *s)
         if (!pktl) 
             break;
         s->packet_buffer = pktl->next;
+        av_free_packet(&pktl->pkt);
         av_free(pktl);
     }
 }
@@ -591,9 +576,9 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic)
         if (pkt->pts != AV_NOPTS_VALUE) {
             if (st->start_time == AV_NOPTS_VALUE)
                 st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
-         }
-         av_free_packet(pkt);
-     }
+        }
+        av_free_packet(pkt);
+    }
 
     /* we compute the minimum start_time and use it as default */
     start_time = MAXINT64;
@@ -603,7 +588,6 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic)
             st->start_time < start_time)
             start_time = st->start_time;
     }
-    printf("start=%lld\n", start_time);
     if (start_time != MAXINT64)
         ic->start_time = start_time;
     
@@ -984,8 +968,11 @@ void av_close_input_file(AVFormatContext *s)
         s->packet_buffer = NULL;
     }
     must_open_file = 1;
-    if ((s->iformat->flags & AVFMT_NOFILE) ||
-        (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))) {
+    if ((s->iformat->flags & AVFMT_NOFILE)
+#ifdef CONFIG_NETWORK
+        || (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))
+#endif
+        ) {
         must_open_file = 0;
     }
     if (must_open_file) {
@@ -1015,7 +1002,10 @@ AVStream *av_new_stream(AVFormatContext *s, int id)
     if (!st)
         return NULL;
     avcodec_get_context_defaults(&st->codec);
-
+    if (s->iformat) {
+        /* no default bitrate if decoding */
+        st->codec.bit_rate = 0;
+    }
     st->index = s->nb_streams;
     st->id = id;
     st->start_time = AV_NOPTS_VALUE;
@@ -1170,7 +1160,7 @@ void dump_format(AVFormatContext *ic,
             is_output ? ic->oformat->name : ic->iformat->name, 
             is_output ? "to" : "from", url);
     if (!is_output) {
-        printf("  Duration: ");
+        fprintf(stderr, "  Duration: ");
         if (ic->duration != AV_NOPTS_VALUE) {
             int hours, mins, secs, us;
             secs = ic->duration / AV_TIME_BASE;
@@ -1179,18 +1169,18 @@ void dump_format(AVFormatContext *ic,
             secs %= 60;
             hours = mins / 60;
             mins %= 60;
-            printf("%02d:%02d:%02d.%01d", hours, mins, secs, 
+            fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs, 
                    (10 * us) / AV_TIME_BASE);
         } else {
-            printf("N/A");
+            fprintf(stderr, "N/A");
         }
-        printf(", bitrate: ");
+        fprintf(stderr, ", bitrate: ");
         if (ic->bit_rate) {
-            printf("%d kb/s", ic->bit_rate / 1000);
+            fprintf(stderr,"%d kb/s", ic->bit_rate / 1000);
         } else {
-            printf("N/A");
+            fprintf(stderr, "N/A");
         }
-        printf("\n");
+        fprintf(stderr, "\n");
     }
     for(i=0;i<ic->nb_streams;i++) {
         AVStream *st = ic->streams[i];
@@ -1216,8 +1206,12 @@ typedef struct {
 } AbvEntry;
 
 static AbvEntry frame_abvs[] = {
-    { "ntsc",      352, 240, 30000, 1001 },
-    { "pal",       352, 288,    25,    1 },
+    { "ntsc",      720, 480, 30000, 1001 },
+    { "pal",       720, 576,    25,    1 },
+    { "qntsc",     352, 240, 30000, 1001 }, /* VCD compliant ntsc */
+    { "qpal",      352, 288,    25,    1 }, /* VCD compliant pal */
+    { "sntsc",     640, 480, 30000, 1001 }, /* square pixel ntsc */
+    { "spal",      768, 576,    25,    1 }, /* square pixel pal */
     { "film",      352, 240,    24,    1 },
     { "ntsc-film", 352, 240, 24000, 1001 },
     { "sqcif",     128,  96,     0,    0 },
@@ -1288,38 +1282,6 @@ int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
         return 0;
 }
 
-int64_t av_gettime(void)
-{
-#ifdef CONFIG_WIN32
-    struct _timeb tb;
-    _ftime(&tb);
-    return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000);
-#else
-    struct timeval tv;
-    gettimeofday(&tv,NULL);
-    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-#endif
-}
-
-static time_t mktimegm(struct tm *tm)
-{
-    time_t t;
-
-    int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
-
-    if (m < 3) {
-        m += 12;
-        y--;
-    }
-
-    t = 86400 * 
-        (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
-
-    t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
-
-    return t;
-}
-
 /* Syntax:
  * - If not a duration:
  *  [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
@@ -1361,7 +1323,7 @@ int64_t parse_date(const char *datestr, int duration)
     q = NULL;
     if (!duration) {
         for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
-            q = strptime(p, date_fmt[i], &dt);
+            q = small_strptime(p, date_fmt[i], &dt);
             if (q) {
                 break;
             }
@@ -1382,13 +1344,13 @@ int64_t parse_date(const char *datestr, int duration)
             p++;
 
         for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
-            q = strptime(p, time_fmt[i], &dt);
+            q = small_strptime(p, time_fmt[i], &dt);
             if (q) {
                 break;
             }
         }
     } else {
-        q = strptime(p, time_fmt[0], &dt);
+        q = small_strptime(p, time_fmt[0], &dt);
         if (!q) {
             dt.tm_sec = strtol(p, (char **)&q, 10);
             dt.tm_min = 0;
@@ -1495,12 +1457,6 @@ int get_frame_filename(char *buf, int buf_size,
                     nd = nd * 10 + *p++ - '0';
                 }
                 c = *p++;
-                if (c == '*' && nd > 0) {
-                    // The nd field is actually the modulus
-                    number = number % nd;
-                    c = *p++;
-                    nd = 0;
-                }
             } while (isdigit(c));
 
             switch(c) {