video-encoder: Use enumeration for encode_frame result type

Better clear the result type instead of a generic "int".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-03-24 02:34:45 +00:00
parent 153e408f9f
commit 271dd5de41
5 changed files with 37 additions and 33 deletions

View File

@ -1687,7 +1687,7 @@ static bool red_marshall_stream_data(RedChannelClient *rcc,
SpiceCopy *copy;
uint32_t frame_mm_time;
int is_sized;
int ret;
VideoEncodeResults ret;
spice_assert(drawable->red_drawable->type == QXL_DRAW_COPY);

View File

@ -1347,10 +1347,11 @@ static void unmap_and_release_memory(GstMapInfo *map, GstBuffer *buffer)
}
/* A helper for spice_gst_encoder_encode_frame() */
static int push_raw_frame(SpiceGstEncoder *encoder,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque)
static VideoEncodeResults
push_raw_frame(SpiceGstEncoder *encoder,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque)
{
uint32_t height = src->bottom - src->top;
// GStreamer require the stream to be 4 bytes aligned
@ -1465,12 +1466,13 @@ static void spice_gst_encoder_destroy(VideoEncoder *video_encoder)
g_free(encoder);
}
static int spice_gst_encoder_encode_frame(VideoEncoder *video_encoder,
uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque,
VideoBuffer **outbuf)
static VideoEncodeResults
spice_gst_encoder_encode_frame(VideoEncoder *video_encoder,
uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque,
VideoBuffer **outbuf)
{
SpiceGstEncoder *encoder = (SpiceGstEncoder*)video_encoder;
g_return_val_if_fail(outbuf != NULL, VIDEO_ENCODER_FRAME_UNSUPPORTED);

View File

@ -717,11 +717,12 @@ static void mjpeg_encoder_adjust_fps(MJpegEncoder *encoder, uint64_t now)
* MJPEG_ENCODER_FRAME_ENCODE_DONE : frame encoding started. Continue with
* mjpeg_encoder_encode_scanline.
*/
static int mjpeg_encoder_start_frame(MJpegEncoder *encoder,
SpiceBitmapFmt format,
const SpiceRect *src,
MJpegVideoBuffer *buffer,
uint32_t frame_mm_time)
static VideoEncodeResults
mjpeg_encoder_start_frame(MJpegEncoder *encoder,
SpiceBitmapFmt format,
const SpiceRect *src,
MJpegVideoBuffer *buffer,
uint32_t frame_mm_time)
{
uint32_t quality;
@ -936,12 +937,13 @@ static bool encode_frame(MJpegEncoder *encoder, const SpiceRect *src,
return TRUE;
}
static int mjpeg_encoder_encode_frame(VideoEncoder *video_encoder,
uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque,
VideoBuffer **outbuf)
static VideoEncodeResults
mjpeg_encoder_encode_frame(VideoEncoder *video_encoder,
uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque,
VideoBuffer **outbuf)
{
MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder, base);
MJpegVideoBuffer *buffer = create_mjpeg_video_buffer();
@ -949,8 +951,8 @@ static int mjpeg_encoder_encode_frame(VideoEncoder *video_encoder,
return VIDEO_ENCODER_FRAME_UNSUPPORTED;
}
int ret = mjpeg_encoder_start_frame(encoder, bitmap->format, src,
buffer, frame_mm_time);
VideoEncodeResults ret = mjpeg_encoder_start_frame(encoder, bitmap->format, src,
buffer, frame_mm_time);
if (ret == VIDEO_ENCODER_FRAME_ENCODE_DONE) {
if (encode_frame(encoder, src, bitmap, top_down)) {
buffer->base.size = mjpeg_encoder_end_frame(encoder);

View File

@ -206,9 +206,9 @@ input_frames(GstSample *sample, void *param)
TestFrame *frame = gst_to_spice_frame(sample);
// send frame to our video encoder (must be from a single thread)
int res = video_encoder->encode_frame(video_encoder, frame_mm_time, frame->bitmap,
&clipping_rect, top_down, frame,
&p_outbuf);
VideoEncodeResults res =
video_encoder->encode_frame(video_encoder, frame_mm_time, frame->bitmap,
&clipping_rect, top_down, frame, &p_outbuf);
switch (res) {
case VIDEO_ENCODER_FRAME_ENCODE_DONE:
// save frame into queue for comparison later

View File

@ -42,11 +42,11 @@ struct VideoBuffer {
void (*free)(VideoBuffer *buffer);
};
enum {
typedef enum {
VIDEO_ENCODER_FRAME_UNSUPPORTED = -1,
VIDEO_ENCODER_FRAME_DROP,
VIDEO_ENCODER_FRAME_ENCODE_DONE,
};
} VideoEncodeResults;
typedef struct VideoEncoderStats {
uint64_t starting_bit_rate;
@ -77,10 +77,10 @@ struct VideoEncoder {
* VIDEO_ENCODER_FRAME_DROP if the frame was dropped. This value can
* only happen if rate control is active.
*/
int (*encode_frame)(VideoEncoder *encoder, uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque, VideoBuffer** outbuf);
VideoEncodeResults (*encode_frame)(VideoEncoder *encoder, uint32_t frame_mm_time,
const SpiceBitmap *bitmap,
const SpiceRect *src, int top_down,
gpointer bitmap_opaque, VideoBuffer** outbuf);
/*
* Bit rate control methods.