• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

vhook/null.c

Go to the documentation of this file.
00001 /*
00002  * Null Video Hook
00003  * Copyright (c) 2002 Philip Gladstone
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 #include <stdio.h>
00022 
00023 #include "libavformat/framehook.h"
00024 #include "libswscale/swscale.h"
00025 
00026 static int sws_flags = SWS_BICUBIC;
00027 
00028 typedef struct {
00029     int dummy;
00030 
00031     // This vhook first converts frame to RGB ...
00032     struct SwsContext *toRGB_convert_ctx;
00033 
00034     // ... and later converts back frame from RGB to initial format
00035     struct SwsContext *fromRGB_convert_ctx;
00036 
00037 } ContextInfo;
00038 
00039 void Release(void *ctx)
00040 {
00041     ContextInfo *ci;
00042     ci = (ContextInfo *) ctx;
00043 
00044     if (ctx) {
00045         sws_freeContext(ci->toRGB_convert_ctx);
00046         sws_freeContext(ci->fromRGB_convert_ctx);
00047         av_free(ctx);
00048     }
00049 }
00050 
00051 int Configure(void **ctxp, int argc, char *argv[])
00052 {
00053     av_log(NULL, AV_LOG_DEBUG, "Called with argc=%d\n", argc);
00054 
00055     *ctxp = av_mallocz(sizeof(ContextInfo));
00056     return 0;
00057 }
00058 
00059 void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
00060 {
00061     ContextInfo *ci = (ContextInfo *) ctx;
00062     char *buf = 0;
00063     AVPicture picture1;
00064     AVPicture *pict = picture;
00065 
00066     (void) ci;
00067 
00068     if (pix_fmt != PIX_FMT_RGB24) {
00069         int size;
00070 
00071         size = avpicture_get_size(PIX_FMT_RGB24, width, height);
00072         buf = av_malloc(size);
00073 
00074         avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
00075 
00076         // if we already got a SWS context, let's realloc if is not re-useable
00077         ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
00078                                     width, height, pix_fmt,
00079                                     width, height, PIX_FMT_RGB24,
00080                                     sws_flags, NULL, NULL, NULL);
00081         if (ci->toRGB_convert_ctx == NULL) {
00082             av_log(NULL, AV_LOG_ERROR,
00083                    "Cannot initialize the toRGB conversion context\n");
00084             return;
00085         }
00086 // img_convert parameters are          2 first destination, then 4 source
00087 // sws_scale   parameters are context, 4 first source,      then 2 destination
00088         sws_scale(ci->toRGB_convert_ctx,
00089             picture->data, picture->linesize, 0, height,
00090             picture1.data, picture1.linesize);
00091 
00092         pict = &picture1;
00093     }
00094 
00095     /* Insert filter code here */
00096 
00097     if (pix_fmt != PIX_FMT_RGB24) {
00098         ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
00099                                         width, height, PIX_FMT_RGB24,
00100                                         width, height, pix_fmt,
00101                                         sws_flags, NULL, NULL, NULL);
00102         if (ci->fromRGB_convert_ctx == NULL) {
00103             av_log(NULL, AV_LOG_ERROR,
00104                    "Cannot initialize the fromRGB conversion context\n");
00105             return;
00106         }
00107 // img_convert parameters are          2 first destination, then 4 source
00108 // sws_scale   parameters are context, 4 first source,      then 2 destination
00109         sws_scale(ci->fromRGB_convert_ctx,
00110             picture1.data, picture1.linesize, 0, height,
00111             picture->data, picture->linesize);
00112     }
00113 
00114     av_free(buf);
00115 }
00116 

Generated on Tue Nov 4 2014 12:59:24 for ffmpeg by  doxygen 1.7.1