]> git.sesse.net Git - ffmpeg/blobdiff - vhook/fish.c
Add OS-specific executable suffix to temporary executable name.
[ffmpeg] / vhook / fish.c
index 8d859fead14bbac9a481cca494304adfd7f840f4..be23dc644aaef61646e69e34406b22228f28e739 100644 (file)
  * -d                turn debugging on
  * -D <directory>    where to put the fish images
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include <stdlib.h>
@@ -92,8 +94,6 @@ typedef struct {
     int inset;
     int min_width;
     struct SwsContext *toRGB_convert_ctx;
-    enum PixelFormat sws_pix_fmt;   // Sws_Context is opaque, we need to save
-    int sws_width, sws_height;      // this to check if we can re-use contexts
 } ContextInfo;
 
 static void dorange(const char *s, int *first, int *second, int maxval)
@@ -124,7 +124,7 @@ int Configure(void **ctxp, int argc, char *argv[])
     *ctxp = av_mallocz(sizeof(ContextInfo));
     ci = (ContextInfo *) *ctxp;
 
-    optind = 0;
+    optind = 1;
 
     ci->dir = "/tmp";
     ci->threshold = 100;
@@ -230,7 +230,7 @@ static void get_hsv(HSV *hsv, int r, int g, int b)
 void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
 {
     ContextInfo *ci = (ContextInfo *) ctx;
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     int rowsize = picture->linesize[0];
 
 #if 0
@@ -338,46 +338,31 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
             }
 
             if (foundfile < ci->file_limit) {
+                FILE *f;
+                char fname[256];
+
                 size = avpicture_get_size(PIX_FMT_RGB24, width, height);
                 buf = av_malloc(size);
 
                 avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
 
                 // if we already got a SWS context, let's realloc if is not re-useable
-                if (ci->toRGB_convert_ctx != NULL) {
-                    if ((ci->sws_pix_fmt != pix_fmt) ||
-                         (ci->sws_width != width) || (ci->sws_height != height)) {
-                        sws_freeContext(ci->toRGB_convert_ctx);
-                        ci->toRGB_convert_ctx = NULL;
-                    }
-                }
+                ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
+                                            width, height, pix_fmt,
+                                            width, height, PIX_FMT_RGB24,
+                                            sws_flags, NULL, NULL, NULL);
                 if (ci->toRGB_convert_ctx == NULL) {
-                    ci->sws_pix_fmt = pix_fmt;
-                    ci->sws_width = width;
-                    ci->sws_height = height;
-                    ci->toRGB_convert_ctx = sws_getContext(
-                                                     ci->sws_width, ci->sws_height,
-                                                     ci->sws_pix_fmt,
-                                                     ci->sws_width, ci->sws_height,
-                                                     PIX_FMT_RGB24,
-                                                     sws_flags, NULL, NULL, NULL);
-                    if (ci->toRGB_convert_ctx == NULL) {
-                        av_log(NULL, AV_LOG_ERROR,
-                               "Cannot initialize the toRGB conversion context\n");
-                        exit(1);
-                    }
+                    av_log(NULL, AV_LOG_ERROR,
+                           "Cannot initialize the toRGB conversion context\n");
+                    return;
                 }
                 // img_convert parameters are          2 first destination, then 4 source
                 // sws_scale   parameters are context, 4 first source,      then 2 destination
                 sws_scale(ci->toRGB_convert_ctx,
-                              picture->data, picture->linesize, 0, ci->sws_height,
+                              picture->data, picture->linesize, 0, height,
                               picture1.data, picture1.linesize);
 
                     /* Write out the PPM file */
-
-                    FILE *f;
-                    char fname[256];
-
                     snprintf(fname, sizeof(fname), "%s/fishimg%ld_%"PRId64".ppm", ci->dir, (long)(av_gettime() / 1000000), pts);
                     f = fopen(fname, "w");
                     if (f) {