2002-11-21 03:50:36 +00:00
|
|
|
/*
|
2005-12-17 18:14:38 +00:00
|
|
|
* Null Video Hook
|
2002-11-21 03:50:36 +00:00
|
|
|
* Copyright (c) 2002 Philip Gladstone
|
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-11-21 03:50:36 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-21 03:50:36 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-21 03:50:36 +00:00
|
|
|
* 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
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-21 03:50:36 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-05-09 11:56:36 +00:00
|
|
|
#include "libavformat/framehook.h"
|
|
|
|
#include "libswscale/swscale.h"
|
2006-08-28 11:57:19 +00:00
|
|
|
|
|
|
|
static int sws_flags = SWS_BICUBIC;
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int dummy;
|
2006-08-28 11:57:19 +00:00
|
|
|
|
|
|
|
// This vhook first converts frame to RGB ...
|
|
|
|
struct SwsContext *toRGB_convert_ctx;
|
|
|
|
|
|
|
|
// ... and later converts back frame from RGB to initial format
|
|
|
|
struct SwsContext *fromRGB_convert_ctx;
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
} ContextInfo;
|
|
|
|
|
2002-11-30 17:17:58 +00:00
|
|
|
void Release(void *ctx)
|
|
|
|
{
|
|
|
|
ContextInfo *ci;
|
|
|
|
ci = (ContextInfo *) ctx;
|
|
|
|
|
2006-08-28 11:57:19 +00:00
|
|
|
if (ctx) {
|
|
|
|
sws_freeContext(ci->toRGB_convert_ctx);
|
|
|
|
sws_freeContext(ci->fromRGB_convert_ctx);
|
2002-11-30 17:17:58 +00:00
|
|
|
av_free(ctx);
|
2006-08-28 11:57:19 +00:00
|
|
|
}
|
2002-11-30 17:17:58 +00:00
|
|
|
}
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
int Configure(void **ctxp, int argc, char *argv[])
|
|
|
|
{
|
2008-09-04 20:45:13 +00:00
|
|
|
av_log(NULL, AV_LOG_DEBUG, "Called with argc=%d\n", argc);
|
2002-11-21 03:50:36 +00:00
|
|
|
|
|
|
|
*ctxp = av_mallocz(sizeof(ContextInfo));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-11 16:35:48 +00:00
|
|
|
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
|
2002-11-21 03:50:36 +00:00
|
|
|
{
|
|
|
|
ContextInfo *ci = (ContextInfo *) ctx;
|
|
|
|
char *buf = 0;
|
|
|
|
AVPicture picture1;
|
|
|
|
AVPicture *pict = picture;
|
|
|
|
|
|
|
|
(void) ci;
|
|
|
|
|
|
|
|
if (pix_fmt != PIX_FMT_RGB24) {
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = avpicture_get_size(PIX_FMT_RGB24, width, height);
|
|
|
|
buf = av_malloc(size);
|
|
|
|
|
|
|
|
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
|
2006-08-28 11:57:19 +00:00
|
|
|
|
|
|
|
// if we already got a SWS context, let's realloc if is not re-useable
|
2006-10-11 12:16:07 +00:00
|
|
|
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
|
|
|
|
width, height, pix_fmt,
|
|
|
|
width, height, PIX_FMT_RGB24,
|
|
|
|
sws_flags, NULL, NULL, NULL);
|
2006-08-28 11:57:19 +00:00
|
|
|
if (ci->toRGB_convert_ctx == NULL) {
|
2006-10-11 12:16:07 +00:00
|
|
|
av_log(NULL, AV_LOG_ERROR,
|
|
|
|
"Cannot initialize the toRGB conversion context\n");
|
2007-04-01 17:23:15 +00:00
|
|
|
return;
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
2006-08-28 11:57:19 +00:00
|
|
|
// 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,
|
2006-10-11 12:16:07 +00:00
|
|
|
picture->data, picture->linesize, 0, height,
|
2006-08-28 11:57:19 +00:00
|
|
|
picture1.data, picture1.linesize);
|
|
|
|
|
2002-11-21 03:50:36 +00:00
|
|
|
pict = &picture1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert filter code here */
|
|
|
|
|
|
|
|
if (pix_fmt != PIX_FMT_RGB24) {
|
2006-10-11 12:16:07 +00:00
|
|
|
ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
|
|
|
|
width, height, PIX_FMT_RGB24,
|
|
|
|
width, height, pix_fmt,
|
|
|
|
sws_flags, NULL, NULL, NULL);
|
|
|
|
if (ci->fromRGB_convert_ctx == NULL) {
|
|
|
|
av_log(NULL, AV_LOG_ERROR,
|
|
|
|
"Cannot initialize the fromRGB conversion context\n");
|
2007-04-01 17:23:15 +00:00
|
|
|
return;
|
2006-10-11 12:16:07 +00:00
|
|
|
}
|
|
|
|
// img_convert parameters are 2 first destination, then 4 source
|
|
|
|
// sws_scale parameters are context, 4 first source, then 2 destination
|
2006-08-28 11:57:19 +00:00
|
|
|
sws_scale(ci->fromRGB_convert_ctx,
|
2006-10-11 12:16:07 +00:00
|
|
|
picture1.data, picture1.linesize, 0, height,
|
2006-08-28 11:57:19 +00:00
|
|
|
picture->data, picture->linesize);
|
2002-11-21 03:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
av_free(buf);
|
|
|
|
}
|
|
|
|
|