Fix bug with automatic video scaling

This is sort of hard to explain:  the scale_video_output function was
overwriting the current frame.  If scaling was disabled, it would do
nothing, and return success, and all would be well.  If it was enabled,
it would then call the scaler, and then replace the contents of the
'data' function parameter with the scaled frame data.  The problem with
this is that I was passing video_output::cur_frame directly, which
overwrites its previous value with the scaled frame data.  Then if
cur_frame was not updated on time, it would end up trying to scale the
previously scaled image, if that makes sense.  it would call the video
scaler with the same from for both the source and destination.

So the simple fix was to simply use a local variable and pass that in as
a parameter to prevent this bug from occurring.
This commit is contained in:
jp9000 2014-08-10 12:49:44 -07:00
parent 7608f77e8b
commit 72fbdc7eaa

View File

@ -101,6 +101,8 @@ static inline bool scale_video_output(struct video_input *input,
data->data[i] = frame->data[i];
data->linesize[i] = frame->linesize[i];
}
} else {
blog(LOG_WARNING, "video-io: Could not scale frame!");
}
}
@ -116,8 +118,10 @@ static inline void video_output_cur_frame(struct video_output *video)
for (size_t i = 0; i < video->inputs.num; i++) {
struct video_input *input = video->inputs.array+i;
if (scale_video_output(input, &video->cur_frame))
input->callback(input->param, &video->cur_frame);
struct video_data frame = video->cur_frame;
if (scale_video_output(input, &frame))
input->callback(input->param, &frame);
}
pthread_mutex_unlock(&video->input_mutex);
@ -272,9 +276,9 @@ static inline bool video_input_init(struct video_input *input,
for (size_t i = 0; i < MAX_CONVERT_BUFFERS; i++)
video_frame_init(&input->frame[i],
video->info.format,
video->info.width,
video->info.height);
input->conversion.format,
input->conversion.width,
input->conversion.height);
}
return true;