Commit | Line | Data |
---|---|---|
26b4bb70 | 1 | /* |
115329f1 | 2 | * Null Video Hook |
26b4bb70 PG |
3 | * Copyright (c) 2002 Philip Gladstone |
4 | * | |
b78e7197 DB |
5 | * This file is part of FFmpeg. |
6 | * | |
7 | * FFmpeg is free software; you can redistribute it and/or | |
26b4bb70 PG |
8 | * modify it under the terms of the GNU Lesser General Public |
9 | * License as published by the Free Software Foundation; either | |
b78e7197 | 10 | * version 2.1 of the License, or (at your option) any later version. |
26b4bb70 | 11 | * |
b78e7197 | 12 | * FFmpeg is distributed in the hope that it will be useful, |
26b4bb70 PG |
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. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
b78e7197 | 18 | * License along with FFmpeg; if not, write to the Free Software |
5509bffa | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
26b4bb70 PG |
20 | */ |
21 | #include <stdio.h> | |
22 | ||
23 | #include "framehook.h" | |
be484a2c VP |
24 | #include "swscale.h" |
25 | ||
26 | static int sws_flags = SWS_BICUBIC; | |
26b4bb70 PG |
27 | |
28 | typedef struct { | |
29 | int dummy; | |
be484a2c VP |
30 | |
31 | // This vhook first converts frame to RGB ... | |
32 | struct SwsContext *toRGB_convert_ctx; | |
33 | ||
34 | // ... and later converts back frame from RGB to initial format | |
35 | struct SwsContext *fromRGB_convert_ctx; | |
36 | ||
26b4bb70 PG |
37 | } ContextInfo; |
38 | ||
6c11d48c PG |
39 | void Release(void *ctx) |
40 | { | |
41 | ContextInfo *ci; | |
42 | ci = (ContextInfo *) ctx; | |
43 | ||
be484a2c VP |
44 | if (ctx) { |
45 | sws_freeContext(ci->toRGB_convert_ctx); | |
46 | sws_freeContext(ci->fromRGB_convert_ctx); | |
6c11d48c | 47 | av_free(ctx); |
be484a2c | 48 | } |
6c11d48c | 49 | } |
26b4bb70 PG |
50 | |
51 | int Configure(void **ctxp, int argc, char *argv[]) | |
52 | { | |
53 | fprintf(stderr, "Called with argc=%d\n", argc); | |
54 | ||
55 | *ctxp = av_mallocz(sizeof(ContextInfo)); | |
56 | return 0; | |
57 | } | |
58 | ||
0c1a9eda | 59 | void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts) |
26b4bb70 PG |
60 | { |
61 | ContextInfo *ci = (ContextInfo *) ctx; | |
62 | char *buf = 0; | |
63 | AVPicture picture1; | |
64 | AVPicture *pict = picture; | |
65 | ||
66 | (void) ci; | |
67 | ||
68 | if (pix_fmt != PIX_FMT_RGB24) { | |
69 | int size; | |
70 | ||
71 | size = avpicture_get_size(PIX_FMT_RGB24, width, height); | |
72 | buf = av_malloc(size); | |
73 | ||
74 | avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height); | |
be484a2c VP |
75 | |
76 | // if we already got a SWS context, let's realloc if is not re-useable | |
a8824a79 VP |
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); | |
be484a2c | 81 | if (ci->toRGB_convert_ctx == NULL) { |
a8824a79 VP |
82 | av_log(NULL, AV_LOG_ERROR, |
83 | "Cannot initialize the toRGB conversion context\n"); | |
ca345e44 | 84 | return; |
26b4bb70 | 85 | } |
be484a2c VP |
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, | |
a8824a79 | 89 | picture->data, picture->linesize, 0, height, |
be484a2c VP |
90 | picture1.data, picture1.linesize); |
91 | ||
26b4bb70 PG |
92 | pict = &picture1; |
93 | } | |
94 | ||
95 | /* Insert filter code here */ | |
96 | ||
97 | if (pix_fmt != PIX_FMT_RGB24) { | |
a8824a79 VP |
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"); | |
ca345e44 | 105 | return; |
a8824a79 VP |
106 | } |
107 | // img_convert parameters are 2 first destination, then 4 source | |
108 | // sws_scale parameters are context, 4 first source, then 2 destination | |
be484a2c | 109 | sws_scale(ci->fromRGB_convert_ctx, |
a8824a79 | 110 | picture1.data, picture1.linesize, 0, height, |
be484a2c | 111 | picture->data, picture->linesize); |
26b4bb70 PG |
112 | } |
113 | ||
114 | av_free(buf); | |
115 | } | |
116 |