spacing and make sws_context static global so we don't have to keep initializing it when playing back from mp4 in eventstream.

This commit is contained in:
Isaac Connor 2020-05-01 15:22:32 -04:00
parent 1bd340d602
commit ffcef8a42a
2 changed files with 52 additions and 41 deletions

View File

@ -48,6 +48,8 @@ static short *g_v_table;
static short *g_u_table;
static short *b_u_table;
struct SwsContext *sws_convert_context = NULL;
jpeg_compress_struct *Image::writejpg_ccinfo[101] = { 0 };
jpeg_compress_struct *Image::encodejpg_ccinfo[101] = { 0 };
jpeg_decompress_struct *Image::readjpg_dcinfo = 0;
@ -167,8 +169,10 @@ Image::Image( const AVFrame *frame ) {
width = frame->width;
height = frame->height;
pixels = width*height;
colours = ZM_COLOUR_RGB32;
subpixelorder = ZM_SUBPIX_ORDER_RGBA;
size = pixels*colours;
buffer = 0;
holdbuffer = 0;
@ -183,24 +187,26 @@ Image::Image( const AVFrame *frame ) {
#endif
#if HAVE_LIBSWSCALE
struct SwsContext *mConvertContext = sws_getContext(
sws_convert_context = sws_getCachedContext(
sws_convert_context,
width,
height,
(AVPixelFormat)frame->format,
width, height,
AV_PIX_FMT_RGBA, SWS_BICUBIC, NULL,
NULL, NULL);
if ( mConvertContext == NULL )
if ( sws_convert_context == NULL )
Fatal("Unable to create conversion context");
if ( sws_scale(mConvertContext, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize) < 0 )
if ( sws_scale(sws_convert_context, frame->data, frame->linesize, 0, frame->height,
dest_frame->data, dest_frame->linesize) < 0 )
Fatal("Unable to convert raw format %u to target format %u", frame->format, AV_PIX_FMT_RGBA);
#else // HAVE_LIBSWSCALE
Fatal("You must compile ffmpeg with the --enable-swscale option to use ffmpeg cameras");
#endif // HAVE_LIBSWSCALE
av_frame_free(&dest_frame);
update_function_pointers();
}
} // end Image::Image(const AVFrame *frame)
Image::Image(const Image &p_image) {
if ( !initialised )
@ -225,7 +231,7 @@ Image::~Image() {
/* Should be called as part of program shutdown to free everything */
void Image::Deinitialise() {
if ( initialised ) {
if ( !initialised ) return;
/*
delete[] y_table;
delete[] uv_table;
@ -252,8 +258,12 @@ void Image::Deinitialise() {
writejpg_ccinfo[quality] = NULL;
}
} // end foreach quality
if ( sws_convert_context ) {
sws_freeContext(sws_convert_context);
sws_convert_context = NULL;
}
}
} // end void Image::Deinitialise()
void Image::Initialise() {
/* Assign the blend pointer to function */
@ -655,7 +665,8 @@ void Image::Assign( const Image &image ) {
return;
}
if ( !buffer || image.width != width || image.height != height || image.colours != colours || image.subpixelorder != subpixelorder) {
if ( !buffer || image.width != width || image.height != height
|| image.colours != colours || image.subpixelorder != subpixelorder) {
if ( holdbuffer && buffer ) {
if ( new_size > allocation ) {