[vlc-commits] avcodec: deindent, cleanup and fix comments

Rémi Denis-Courmont git at videolan.org
Tue Apr 21 21:31:33 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Apr 21 22:06:35 2015 +0300| [ad092de0e6c2e342778349130aacf69f3c03acb5] | committer: Rémi Denis-Courmont

avcodec: deindent, cleanup and fix comments

No functional changes.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ad092de0e6c2e342778349130aacf69f3c03acb5
---

 modules/codec/avcodec/video.c |  118 +++++++++++++++++++----------------------
 1 file changed, 56 insertions(+), 62 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 4b45ab0..af560b1 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -96,7 +96,6 @@ struct decoder_sys_t
  * Local prototypes
  *****************************************************************************/
 static void ffmpeg_InitCodec      ( decoder_t * );
-static void ffmpeg_CopyPicture    ( decoder_t *, picture_t *, AVFrame * );
 #if LIBAVCODEC_VERSION_MAJOR >= 55
 static int lavc_GetFrame(struct AVCodecContext *, AVFrame *, int);
 #else
@@ -206,6 +205,60 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
     return decoder_NewPicture( p_dec );
 }
 
+/**
+ * Copies a picture from the libavcodec-allocate buffer to a picture_t.
+ * This is used when not in direct rendering mode.
+ */
+static void lavc_CopyPicture(decoder_t *dec, picture_t *pic, AVFrame *frame)
+{
+    decoder_sys_t *sys = dec->p_sys;
+
+    if (sys->p_va != NULL)
+    {
+        vlc_va_Extract(sys->p_va, pic, frame->opaque, frame->data[3]);
+        return;
+    }
+
+    if (!FindVlcChroma(sys->p_context->pix_fmt))
+    {
+        const char *name = av_get_pix_fmt_name(sys->p_context->pix_fmt);
+
+        msg_Err(dec, "Unsupported decoded output format %d (%s)",
+                sys->p_context->pix_fmt, (name != NULL) ? name : "unknown");
+        dec->b_error = true;
+        return;
+    }
+
+    for (int plane = 0; plane < pic->i_planes; plane++)
+    {
+        const uint8_t *src = frame->data[plane];
+        uint8_t *dst = pic->p[plane].p_pixels;
+        size_t src_stride = frame->linesize[plane];
+        size_t dst_stride = pic->p[plane].i_pitch;
+        size_t size = __MIN(src_stride, dst_stride);
+
+        for (int line = 0; line < pic->p[plane].i_visible_lines; line++)
+        {
+            memcpy(dst, src, size);
+            src += src_stride;
+            dst += dst_stride;
+        }
+    }
+
+    if (unlikely(sys->p_context->pix_fmt == PIX_FMT_PAL8))
+    {
+        if (pic->format.p_palette == NULL)
+            pic->format.p_palette = calloc(1, sizeof (video_palette_t));
+
+        if (likely(pic->format.p_palette != NULL))
+        {
+            pic->format.p_palette->i_entries = AVPALETTE_COUNT;
+            memcpy(pic->format.p_palette->palette, frame->data[1],
+                   AVPALETTE_SIZE);
+        }
+    }
+}
+
 static int OpenVideoCodec( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -762,9 +815,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
                 return NULL;
             }
 
-            /* Fill p_picture_t from AVVideoFrame and do chroma conversion
-             * if needed */
-            ffmpeg_CopyPicture( p_dec, p_pic, p_sys->p_ff_pic );
+            /* Fill picture_t from AVFrame */
+            lavc_CopyPicture(p_dec, p_pic, p_sys->p_ff_pic);
         }
         else
         {
@@ -910,64 +962,6 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
     }
 }
 
-/*****************************************************************************
- * ffmpeg_CopyPicture: copy a picture from ffmpeg internal buffers to a
- *                     picture_t structure (when not in direct rendering mode).
- *****************************************************************************/
-static void ffmpeg_CopyPicture( decoder_t *p_dec,
-                                picture_t *p_pic, AVFrame *p_ff_pic )
-{
-    decoder_sys_t *p_sys = p_dec->p_sys;
-
-    if( p_sys->p_va )
-    {
-        vlc_va_Extract( p_sys->p_va, p_pic, p_ff_pic->opaque,
-                        p_ff_pic->data[3] );
-    }
-    else if( FindVlcChroma( p_sys->p_context->pix_fmt ) )
-    {
-        int i_plane, i_size, i_line;
-        uint8_t *p_dst, *p_src;
-        int i_src_stride, i_dst_stride;
-
-        if( p_sys->p_context->pix_fmt == PIX_FMT_PAL8 )
-        {
-            if( !p_pic->format.p_palette )
-                p_pic->format.p_palette = calloc( 1, sizeof(video_palette_t) );
-
-            if( p_pic->format.p_palette )
-            {
-                p_pic->format.p_palette->i_entries = AVPALETTE_COUNT;
-                memcpy( p_pic->format.p_palette->palette, p_ff_pic->data[1], AVPALETTE_SIZE );
-            }
-        }
-
-        for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
-        {
-            p_src  = p_ff_pic->data[i_plane];
-            p_dst = p_pic->p[i_plane].p_pixels;
-            i_src_stride = p_ff_pic->linesize[i_plane];
-            i_dst_stride = p_pic->p[i_plane].i_pitch;
-
-            i_size = __MIN( i_src_stride, i_dst_stride );
-            for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
-                 i_line++ )
-            {
-                memcpy( p_dst, p_src, i_size );
-                p_src += i_src_stride;
-                p_dst += i_dst_stride;
-            }
-        }
-    }
-    else
-    {
-        const char *name = av_get_pix_fmt_name( p_sys->p_context->pix_fmt );
-        msg_Err( p_dec, "Unsupported decoded output format %d (%s)",
-                 p_sys->p_context->pix_fmt, name ? name : "unknown" );
-        p_dec->b_error = 1;
-    }
-}
-
 #if LIBAVCODEC_VERSION_MAJOR >= 55
 static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
                             int flags)



More information about the vlc-commits mailing list