Merge branch 'master' of http://repo.or.cz/r/FFMpeg-mirror
[FFMpeg-mirror/DVCPRO-HD.git] / vhook / null.c
blob6f310371c0a76a856fde51abd0ee2044889309c9
1 /*
2 * Null Video Hook
3 * Copyright (c) 2002 Philip Gladstone
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <stdio.h>
23 #include "libavformat/framehook.h"
24 #include "libswscale/swscale.h"
26 static int sws_flags = SWS_BICUBIC;
28 typedef struct {
29 int dummy;
31 // This vhook first converts frame to RGB ...
32 struct SwsContext *toRGB_convert_ctx;
34 // ... and later converts back frame from RGB to initial format
35 struct SwsContext *fromRGB_convert_ctx;
37 } ContextInfo;
39 void Release(void *ctx)
41 ContextInfo *ci;
42 ci = (ContextInfo *) ctx;
44 if (ctx) {
45 sws_freeContext(ci->toRGB_convert_ctx);
46 sws_freeContext(ci->fromRGB_convert_ctx);
47 av_free(ctx);
51 int Configure(void **ctxp, int argc, char *argv[])
53 fprintf(stderr, "Called with argc=%d\n", argc);
55 *ctxp = av_mallocz(sizeof(ContextInfo));
56 return 0;
59 void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
61 ContextInfo *ci = (ContextInfo *) ctx;
62 char *buf = 0;
63 AVPicture picture1;
64 AVPicture *pict = picture;
66 (void) ci;
68 if (pix_fmt != PIX_FMT_RGB24) {
69 int size;
71 size = avpicture_get_size(PIX_FMT_RGB24, width, height);
72 buf = av_malloc(size);
74 avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
76 // if we already got a SWS context, let's realloc if is not re-useable
77 ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
78 width, height, pix_fmt,
79 width, height, PIX_FMT_RGB24,
80 sws_flags, NULL, NULL, NULL);
81 if (ci->toRGB_convert_ctx == NULL) {
82 av_log(NULL, AV_LOG_ERROR,
83 "Cannot initialize the toRGB conversion context\n");
84 return;
86 // img_convert parameters are 2 first destination, then 4 source
87 // sws_scale parameters are context, 4 first source, then 2 destination
88 sws_scale(ci->toRGB_convert_ctx,
89 picture->data, picture->linesize, 0, height,
90 picture1.data, picture1.linesize);
92 pict = &picture1;
95 /* Insert filter code here */
97 if (pix_fmt != PIX_FMT_RGB24) {
98 ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
99 width, height, PIX_FMT_RGB24,
100 width, height, pix_fmt,
101 sws_flags, NULL, NULL, NULL);
102 if (ci->fromRGB_convert_ctx == NULL) {
103 av_log(NULL, AV_LOG_ERROR,
104 "Cannot initialize the fromRGB conversion context\n");
105 return;
107 // img_convert parameters are 2 first destination, then 4 source
108 // sws_scale parameters are context, 4 first source, then 2 destination
109 sws_scale(ci->fromRGB_convert_ctx,
110 picture1.data, picture1.linesize, 0, height,
111 picture->data, picture->linesize);
114 av_free(buf);