]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/utils.c
Remove redundant fastmemcpy.h #include, it is indirectly #included by avutil.h.
[ffmpeg] / libavformat / utils.c
index b748b546cac8fcfbdefe9122b577c42a5e89f16d..ab7345ede2022cd5795e5ceb111b381049a3ae6a 100644 (file)
@@ -417,8 +417,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
 
     if (!fmt || must_open_file) {
         /* if no file needed do not try to open one */
-        if (url_fopen(pb, filename, URL_RDONLY) < 0) {
-            err = AVERROR_IO;
+        if ((err=url_fopen(pb, filename, URL_RDONLY)) < 0) {
             goto fail;
         }
         file_opened = 1;
@@ -452,7 +451,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
     }
 
     /* XXX: suppress this hack for redirectors */
-#ifdef CONFIG_NETWORK
+#ifdef CONFIG_REDIR_DEMUXER
     if (fmt == &redir_demuxer) {
         err = redir_open(ic_ptr, pb);
         url_fclose(pb);
@@ -484,6 +483,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
 
 int av_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    av_init_packet(pkt);
     return s->iformat->read_packet(s, pkt);
 }
 
@@ -702,6 +702,8 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
     AVStream *st;
     int len, ret, i;
 
+    av_init_packet(pkt);
+
     for(;;) {
         /* select current input stream component */
         st = s->cur_st;
@@ -726,6 +728,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 /* return packet if any */
                 if (pkt->size) {
                 got_packet:
+                    pkt->pos = s->cur_pkt.pos;              // Isn't quite accurate but close.
                     pkt->duration = 0;
                     pkt->stream_index = st->index;
                     pkt->pts = st->parser->pts;
@@ -782,8 +785,8 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 st->parser = av_parser_init(st->codec->codec_id);
                 if (!st->parser) {
                     /* no parser available : just output the raw packets */
-                    st->need_parsing = 0;
-                }else if(st->need_parsing == 2){
+                    st->need_parsing = AVSTREAM_PARSE_NONE;
+                }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){
                     st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
                 }
                 if(st->parser && (s->iformat->flags & AVFMT_GENERIC_INDEX)){
@@ -1214,6 +1217,10 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
 #ifdef DEBUG_SEEK
 av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, start_pos, no_change);
 #endif
+        if(ts == AV_NOPTS_VALUE){
+            av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n");
+            return -1;
+        }
         assert(ts != AV_NOPTS_VALUE);
         if (target_ts <= ts) {
             pos_limit = start_pos - 1;
@@ -1276,7 +1283,7 @@ static int av_seek_frame_generic(AVFormatContext *s,
 
     index = av_index_search_timestamp(st, timestamp, flags);
 
-    if(index < 0){
+    if(index < 0 || index==st->nb_index_entries-1){
         int i;
         AVPacket pkt;
 
@@ -1476,7 +1483,21 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offse
     int64_t end_time;
     int64_t filesize, offset, duration;
 
-    av_read_frame_flush(ic);
+    /* free previous packet */
+    if (ic->cur_st && ic->cur_st->parser)
+        av_free_packet(&ic->cur_pkt);
+    ic->cur_st = NULL;
+
+    /* flush packet queue */
+    flush_packet_queue(ic);
+
+    for(i=0;i<ic->nb_streams;i++) {
+        st = ic->streams[i];
+        if (st->parser) {
+            av_parser_close(st->parser);
+            st->parser= NULL;
+        }
+    }
 
     /* we read the first packets to get the first PTS (not fully
        accurate, but it is enough now) */
@@ -1663,7 +1684,7 @@ static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
         else if (strncmp(fmt->name, "ac3", 3) == 0)
             st->codec->codec_id = CODEC_ID_AC3;
     }
-    return fmt;
+    return !!fmt;
 }
 
 /* absolute maximum size we read until we abort */
@@ -1704,7 +1725,7 @@ int av_find_stream_info(AVFormatContext *ic)
         //only for the split stuff
         if (!st->parser) {
             st->parser = av_parser_init(st->codec->codec_id);
-            if(st->need_parsing == 2 && st->parser){
+            if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){
                 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
             }
         }
@@ -1907,7 +1928,7 @@ int av_find_stream_info(AVFormatContext *ic)
             if (st->codec->codec_id == CODEC_ID_NONE) {
                 codec_identified[st->index] = set_codec_from_probe_data(st, &(probe_data[st->index]), 0);
                 if (codec_identified[st->index]) {
-                    st->need_parsing = 1;
+                    st->need_parsing = AVSTREAM_PARSE_FULL;
                 }
             }
             if(!st->codec->bits_per_sample)
@@ -2177,12 +2198,11 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){
     }
 
     if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
-        av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64" st:%d\n", st->cur_dts, pkt->dts, st->index);
+        av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts);
         return -1;
     }
     if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){
-        av_log(NULL, AV_LOG_ERROR, "error, pts < dts (%"PRId64" < %"PRId64")\n",
-               pkt->pts, pkt->dts);
+        av_log(NULL, AV_LOG_ERROR, "error, pts < dts\n");
         return -1;
     }
 
@@ -2470,6 +2490,30 @@ static AbvEntry frame_abvs[] = {
     { "qcif",      176, 144,     0,    0 },
     { "cif",       352, 288,     0,    0 },
     { "4cif",      704, 576,     0,    0 },
+    { "qqvga",     160, 120,     0,    0 },
+    { "qvga",      320, 240,     0,    0 },
+    { "vga",       640, 480,     0,    0 },
+    { "svga",      800, 600,     0,    0 },
+    { "xga",      1024, 768,     0,    0 },
+    { "uxga",     1600,1200,     0,    0 },
+    { "qxga",     2048,1536,     0,    0 },
+    { "sxga",     1280,1024,     0,    0 },
+    { "qsxga",    2560,2048,     0,    0 },
+    { "hsxga",    5120,4096,     0,    0 },
+    { "wvga",      852, 480,     0,    0 },
+    { "wxga",     1366, 768,     0,    0 },
+    { "wsxga",    1600,1024,     0,    0 },
+    { "wuxga",    1920,1200,     0,    0 },
+    { "woxga",    2560,1600,     0,    0 },
+    { "wqsxga",   3200,2048,     0,    0 },
+    { "wquxga",   3840,2400,     0,    0 },
+    { "whsxga",   6400,4096,     0,    0 },
+    { "whuxga",   7680,4800,     0,    0 },
+    { "cga",       320, 200,     0,    0 },
+    { "ega",       640, 350,     0,    0 },
+    { "hd480",     852, 480,     0,    0 },
+    { "hd720",    1280, 720,     0,    0 },
+    { "hd1080",   1920,1080,     0,    0 },
 };
 
 int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
@@ -2537,7 +2581,6 @@ int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
         return 0;
 }
 
-#ifndef CONFIG_WINCE
 int64_t parse_date(const char *datestr, int duration)
 {
     const char *p;
@@ -2645,7 +2688,6 @@ int64_t parse_date(const char *datestr, int duration)
     }
     return negative ? -t : t;
 }
-#endif /* CONFIG_WINCE */
 
 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
 {