Re: [PATCH v2 1/2] display-gst: small refactor get_decoded_frame()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> From: Victor Toso <me@xxxxxxxxxxxxxx>
> 
> Small refactor to make each code block a bit more obvious.
> 
> This code should (1) find the @buffer in the queue; (2) remove all old
> elements from queue. That perfectly fit in two loops in sequence, but
> they don't need to be nested and they don't need to use the same
> pointer (gstframe).
> 
> As @num_frames_dropped is only used in the second block, this was
> moved as well, together with the debug.
> 
> Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>
> ---
>  src/channel-display-gst.c | 36 ++++++++++++++++++------------------
>  1 file changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
> index 08c9f8f..fb0f345 100644
> --- a/src/channel-display-gst.c
> +++ b/src/channel-display-gst.c
> @@ -212,8 +212,6 @@ static void schedule_frame(SpiceGstDecoder *decoder)
>   */
>  static SpiceGstFrame *get_decoded_frame(SpiceGstDecoder *decoder, GstBuffer
>  *buffer)
>  {
> -    guint num_frames_dropped = 0;
> -
>      /* Gstreamer sometimes returns the same buffer twice
>       * or buffers that have a modified, and thus unrecognizable, PTS.
>       * Blindly removing frames from the decoding_queue until we find a
> @@ -226,27 +224,29 @@ static SpiceGstFrame *get_decoded_frame(SpiceGstDecoder
> *decoder, GstBuffer *buf
>      while (l) {
>          gstframe = l->data;
>          if (gstframe->timestamp == GST_BUFFER_PTS(buffer)) {
> -
> -            /* Now that we know there is a match, remove it and the older
> -             * frames from the decoding queue.
> -             */
> -            while ((gstframe = g_queue_pop_head(decoder->decoding_queue))) {
> -                if (gstframe->timestamp == GST_BUFFER_PTS(buffer)) {
> -                    break;
> -                }
> -                /* The GStreamer pipeline dropped the corresponding
> -                 * buffer.
> -                 */
> -                num_frames_dropped++;
> -                free_gst_frame(gstframe);
> -            }
>              break;
>          }
>          gstframe = NULL;
>          l = l->next;
>      }
> -    if (num_frames_dropped != 0) {
> -        SPICE_DEBUG("the GStreamer pipeline dropped %u frames",
> num_frames_dropped);
> +
> +    /* Now that we know there is a match, remove it and the older
> +     * frames from the decoding queue.
> +     */

This comment is not correct here, should be inside the "if".

> +    if (gstframe != NULL) {
> +        guint num_frames_dropped = 0;
> +        SpiceGstFrame *late_frame = NULL;

Initialization is not required here.

> +        /* The GStreamer pipeline dropped the corresponding
> +         * buffer.
> +         */

I think now this comment can take just one line.

> +        while ((late_frame = g_queue_pop_head(decoder->decoding_queue)) !=
> gstframe) {
> +            num_frames_dropped++;
> +            free_gst_frame(late_frame);
> +        }
> +
> +        if (num_frames_dropped != 0) {
> +            SPICE_DEBUG("the GStreamer pipeline dropped %u frames",
> num_frames_dropped);
> +        }
>      }
>      return gstframe;
>  }

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]