simplifies null vhook by using sws_getCachedContext()
Patch by Victor Paesa %wzrlpy A arsystel P com% Original thread: Date: Sep 15, 2006 6:21 PM Subject: Re: [Ffmpeg-devel] [PATCH] enable libswscale Originally committed as revision 6651 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
df117196d3
commit
a8824a790f
61
vhook/null.c
61
vhook/null.c
@ -34,11 +34,6 @@ typedef struct {
|
|||||||
// ... and later converts back frame from RGB to initial format
|
// ... and later converts back frame from RGB to initial format
|
||||||
struct SwsContext *fromRGB_convert_ctx;
|
struct SwsContext *fromRGB_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
|
|
||||||
// Contexts will be re-used 99% of time,
|
|
||||||
// I know of width/height changes only in DVB broadcasts
|
|
||||||
|
|
||||||
} ContextInfo;
|
} ContextInfo;
|
||||||
|
|
||||||
void Release(void *ctx)
|
void Release(void *ctx)
|
||||||
@ -79,46 +74,19 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
|
|||||||
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
|
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 we already got a SWS context, let's realloc if is not re-useable
|
||||||
if (ci->toRGB_convert_ctx != NULL) {
|
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
|
||||||
if ((ci->sws_pix_fmt != pix_fmt) ||
|
width, height, pix_fmt,
|
||||||
(ci->sws_width != width) || (ci->sws_height != height)) {
|
width, height, PIX_FMT_RGB24,
|
||||||
sws_freeContext(ci->toRGB_convert_ctx);
|
sws_flags, NULL, NULL, NULL);
|
||||||
ci->toRGB_convert_ctx = NULL;
|
|
||||||
sws_freeContext(ci->fromRGB_convert_ctx);
|
|
||||||
ci->fromRGB_convert_ctx = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ci->toRGB_convert_ctx == NULL) {
|
if (ci->toRGB_convert_ctx == NULL) {
|
||||||
ci->sws_pix_fmt = pix_fmt;
|
av_log(NULL, AV_LOG_ERROR,
|
||||||
ci->sws_width = width;
|
"Cannot initialize the toRGB conversion context\n");
|
||||||
ci->sws_height = height;
|
exit(1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
ci->fromRGB_convert_ctx = sws_getContext(
|
|
||||||
ci->sws_width, ci->sws_height,
|
|
||||||
PIX_FMT_RGB24,
|
|
||||||
ci->sws_width, ci->sws_height,
|
|
||||||
ci->sws_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");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// img_convert parameters are 2 first destination, then 4 source
|
// img_convert parameters are 2 first destination, then 4 source
|
||||||
// sws_scale parameters are context, 4 first source, then 2 destination
|
// sws_scale parameters are context, 4 first source, then 2 destination
|
||||||
sws_scale(ci->toRGB_convert_ctx,
|
sws_scale(ci->toRGB_convert_ctx,
|
||||||
picture->data, picture->linesize, 0, ci->sws_height,
|
picture->data, picture->linesize, 0, height,
|
||||||
picture1.data, picture1.linesize);
|
picture1.data, picture1.linesize);
|
||||||
|
|
||||||
pict = &picture1;
|
pict = &picture1;
|
||||||
@ -127,8 +95,19 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
|
|||||||
/* Insert filter code here */
|
/* Insert filter code here */
|
||||||
|
|
||||||
if (pix_fmt != PIX_FMT_RGB24) {
|
if (pix_fmt != PIX_FMT_RGB24) {
|
||||||
|
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");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// img_convert parameters are 2 first destination, then 4 source
|
||||||
|
// sws_scale parameters are context, 4 first source, then 2 destination
|
||||||
sws_scale(ci->fromRGB_convert_ctx,
|
sws_scale(ci->fromRGB_convert_ctx,
|
||||||
picture1.data, picture1.linesize, 0, ci->sws_height,
|
picture1.data, picture1.linesize, 0, height,
|
||||||
picture->data, picture->linesize);
|
picture->data, picture->linesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user