[Bf-blender-cvs] [1e09dd094b0] master: Cleanup: don't index the same array multiple times

Sybren A. Stüvel noreply at git.blender.org
Thu Sep 19 15:13:14 CEST 2019


Commit: 1e09dd094b0187ef7b7b202154bc810dc1479034
Author: Sybren A. Stüvel
Date:   Thu Sep 19 11:59:33 2019 +0200
Branches: master
https://developer.blender.org/rB1e09dd094b0187ef7b7b202154bc810dc1479034

Cleanup: don't index the same array multiple times

There is now a clearer distinction between `video_stream` (the stream itself)
and `video_stream_index` (its index), and no more repetition of accessing
the same item of an array. This also makes the code a bit more readable in
preparation for an upcoming functional change.

===================================================================

M	source/blender/imbuf/intern/anim_movie.c

===================================================================

diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 52d8db95054..da7dcc54343 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -493,12 +493,13 @@ BLI_INLINE bool need_aligned_ffmpeg_buffer(struct anim *anim)
 
 static int startffmpeg(struct anim *anim)
 {
-  int i, videoStream;
+  int i, video_stream_index;
 
   AVCodec *pCodec;
   AVFormatContext *pFormatCtx = NULL;
   AVCodecContext *pCodecCtx;
   AVRational frame_rate;
+  AVStream *video_stream;
   int frs_num;
   double frs_den;
   int streamcount;
@@ -528,7 +529,7 @@ static int startffmpeg(struct anim *anim)
   av_dump_format(pFormatCtx, 0, anim->name, 0);
 
   /* Find the video stream */
-  videoStream = -1;
+  video_stream_index = -1;
 
   for (i = 0; i < pFormatCtx->nb_streams; i++) {
     if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
@@ -536,17 +537,18 @@ static int startffmpeg(struct anim *anim)
         streamcount--;
         continue;
       }
-      videoStream = i;
+      video_stream_index = i;
       break;
     }
   }
 
-  if (videoStream == -1) {
+  if (video_stream_index == -1) {
     avformat_close_input(&pFormatCtx);
     return -1;
   }
 
-  pCodecCtx = pFormatCtx->streams[videoStream]->codec;
+  video_stream = pFormatCtx->streams[video_stream_index];
+  pCodecCtx = video_stream->codec;
 
   /* Find the decoder for the video stream */
   pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
@@ -567,9 +569,9 @@ static int startffmpeg(struct anim *anim)
     return -1;
   }
 
-  frame_rate = av_get_r_frame_rate_compat(pFormatCtx, pFormatCtx->streams[videoStream]);
-  if (pFormatCtx->streams[videoStream]->nb_frames != 0) {
-    anim->duration = pFormatCtx->streams[videoStream]->nb_frames;
+  frame_rate = av_get_r_frame_rate_compat(pFormatCtx, video_stream);
+  if (video_stream->nb_frames != 0) {
+    anim->duration = video_stream->nb_frames;
   }
   else {
     anim->duration = (int)(pFormatCtx->duration * av_q2d(frame_rate) / AV_TIME_BASE + 0.5f);
@@ -596,7 +598,7 @@ static int startffmpeg(struct anim *anim)
   anim->pFormatCtx = pFormatCtx;
   anim->pCodecCtx = pCodecCtx;
   anim->pCodec = pCodec;
-  anim->videoStream = videoStream;
+  anim->videoStream = video_stream_index;
 
   anim->interlacing = 0;
   anim->orientation = 0;



More information about the Bf-blender-cvs mailing list