changeset 1291:185190bdc185 libavformat

Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be % Original thread: Date: Aug 30, 2006 4:54 PM Subject: [Ffmpeg-devel] [PATCH] Clarified API for numbered sequences
author gpoirier
date Mon, 04 Sep 2006 09:57:47 +0000
parents 423559fc3de3
children 6042770198c6
files avformat.h img.c img2.c utils.c
diffstat 4 files changed, 41 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/avformat.h	Mon Sep 04 04:25:47 2006 +0000
+++ b/avformat.h	Mon Sep 04 09:57:47 2006 +0000
@@ -515,9 +515,9 @@
 
 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
 
-int get_frame_filename(char *buf, int buf_size,
-                       const char *path, int number);
-int filename_number_test(const char *filename);
+int av_get_frame_filename(char *buf, int buf_size,
+                          const char *path, int number);
+int av_filename_number_test(const char *filename);
 
 /* grab specific */
 int video_grab_init(void);
--- a/img.c	Mon Sep 04 04:25:47 2006 +0000
+++ b/img.c	Mon Sep 04 09:57:47 2006 +0000
@@ -44,7 +44,7 @@
 
     /* find the first image */
     for(first_index = 0; first_index < 5; first_index++) {
-        if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0)
+        if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0)
             goto fail;
         if (url_exist(buf))
             break;
@@ -61,8 +61,8 @@
                 range1 = 1;
             else
                 range1 = 2 * range;
-            if (get_frame_filename(buf, sizeof(buf), path,
-                                   last_index + range1) < 0)
+            if (av_get_frame_filename(buf, sizeof(buf), path,
+                                      last_index + range1) < 0)
                 goto fail;
             if (!url_exist(buf))
                 break;
@@ -86,7 +86,7 @@
 
 static int image_probe(AVProbeData *p)
 {
-    if (filename_number_test(p->filename) >= 0 && guess_image_format(p->filename))
+    if (av_filename_number_test(p->filename) && guess_image_format(p->filename))
         return AVPROBE_SCORE_MAX-1;
     else
         return 0;
@@ -144,7 +144,7 @@
         /* compute duration */
         st->start_time = 0;
         st->duration = last_index - first_index + 1;
-        if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
+        if (av_get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
             goto fail;
         if (url_fopen(f, buf, URL_RDONLY) < 0)
             goto fail;
@@ -200,8 +200,8 @@
         if (s1->loop_input && s->img_number > s->img_last) {
             s->img_number = s->img_first;
         }
-        if (get_frame_filename(filename, sizeof(filename),
-                               s->path, s->img_number) < 0)
+        if (av_get_frame_filename(filename, sizeof(filename),
+                                  s->path, s->img_number) < 0)
             return AVERROR_IO;
         f = &f1;
         if (url_fopen(f, filename, URL_RDONLY) < 0)
@@ -307,8 +307,8 @@
     picture = (AVPicture *)pkt->data;
 
     if (!img->is_pipe) {
-        if (get_frame_filename(filename, sizeof(filename),
-                               img->path, img->img_number) < 0)
+        if (av_get_frame_filename(filename, sizeof(filename),
+                                  img->path, img->img_number) < 0)
             return AVERROR_IO;
         pb = &pb1;
         if (url_fopen(pb, filename, URL_WRONLY) < 0)
--- a/img2.c	Mon Sep 04 04:25:47 2006 +0000
+++ b/img2.c	Mon Sep 04 09:57:47 2006 +0000
@@ -104,7 +104,7 @@
 
     /* find the first image */
     for(first_index = 0; first_index < 5; first_index++) {
-        if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
+        if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
             *pfirst_index =
             *plast_index = 1;
             return 0;
@@ -124,8 +124,8 @@
                 range1 = 1;
             else
                 range1 = 2 * range;
-            if (get_frame_filename(buf, sizeof(buf), path,
-                                   last_index + range1) < 0)
+            if (av_get_frame_filename(buf, sizeof(buf), path,
+                                      last_index + range1) < 0)
                 goto fail;
             if (!url_exist(buf))
                 break;
@@ -149,7 +149,7 @@
 
 static int image_probe(AVProbeData *p)
 {
-    if (filename_number_test(p->filename) >= 0 && av_str2id(img_tags, p->filename))
+    if (av_filename_number_test(p->filename) && av_str2id(img_tags, p->filename))
         return AVPROBE_SCORE_MAX;
     else
         return 0;
@@ -236,8 +236,8 @@
         if (s1->loop_input && s->img_number > s->img_last) {
             s->img_number = s->img_first;
         }
-        if (get_frame_filename(filename, sizeof(filename),
-                               s->path, s->img_number)<0 && s->img_number > 1)
+        if (av_get_frame_filename(filename, sizeof(filename),
+                                  s->path, s->img_number)<0 && s->img_number > 1)
             return AVERROR_IO;
         for(i=0; i<3; i++){
             if (url_fopen(f[i], filename, URL_RDONLY) < 0)
@@ -317,8 +317,8 @@
     int i;
 
     if (!img->is_pipe) {
-        if (get_frame_filename(filename, sizeof(filename),
-                               img->path, img->img_number) < 0 && img->img_number>1)
+        if (av_get_frame_filename(filename, sizeof(filename),
+                                  img->path, img->img_number) < 0 && img->img_number>1)
             return AVERROR_IO;
         for(i=0; i<3; i++){
             if (url_fopen(pb[i], filename, URL_WRONLY) < 0)
--- a/utils.c	Mon Sep 04 04:25:47 2006 +0000
+++ b/utils.c	Mon Sep 04 09:57:47 2006 +0000
@@ -93,13 +93,13 @@
     /* specific test for image sequences */
 #ifdef CONFIG_IMAGE2_MUXER
     if (!short_name && filename &&
-        filename_number_test(filename) >= 0 &&
+        av_filename_number_test(filename) &&
         av_guess_image2_codec(filename) != CODEC_ID_NONE) {
         return guess_format("image2", NULL, NULL);
     }
 #endif
     if (!short_name && filename &&
-        filename_number_test(filename) >= 0 &&
+        av_filename_number_test(filename) &&
         guess_image_format(filename)) {
         return guess_format("image", NULL, NULL);
     }
@@ -403,12 +403,16 @@
     return 0;
 }
 
-int filename_number_test(const char *filename)
+/**
+ * Allocate the payload of a packet and intialized its fields to default values.
+ *
+ * @param filename possible numbered sequence string
+ * @return 1 if a valid numbered sequence string, 0 otherwise.
+ */
+int av_filename_number_test(const char *filename)
 {
     char buf[1024];
-    if(!filename)
-        return -1;
-    return get_frame_filename(buf, sizeof(buf), filename, 1);
+    return filename && (av_get_frame_filename(buf, sizeof(buf), filename, 1)>=0);
 }
 
 /**
@@ -635,7 +639,7 @@
 
     /* check filename in case of an image number is expected */
     if (fmt->flags & AVFMT_NEEDNUMBER) {
-        if (filename_number_test(filename) < 0) {
+        if (!av_filename_number_test(filename)) {
             err = AVERROR_NUMEXPECTED;
             goto fail;
         }
@@ -2951,12 +2955,18 @@
 
 /**
  * Returns in 'buf' the path with '%d' replaced by number.
- *
+
  * Also handles the '%0nd' format where 'n' is the total number
- * of digits and '%%'. Return 0 if OK, and -1 if format error.
+ * of digits and '%%'.
+ *
+ * @param buf destination buffer
+ * @param buf_size destination buffer size
+ * @param path numbered sequence string
+ * @number frame number
+ * @return 0 if OK, -1 if format error.
  */
-int get_frame_filename(char *buf, int buf_size,
-                       const char *path, int number)
+int av_get_frame_filename(char *buf, int buf_size,
+                          const char *path, int number)
 {
     const char *p;
     char *q, buf1[20], c;