test/encode/avcenc: Fixed bug about B frame display order wrong.
authorZhou Chang <chang.zhou@intel.com>
Wed, 27 Jul 2011 06:44:32 +0000 (14:44 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Tue, 28 May 2013 08:46:48 +0000 (16:46 +0800)
Signed-off-by: Zhou Chang <chang.zhou@intel.com>
test/encode/avcenc.c

index 0627bfd..197b284 100644 (file)
@@ -1069,23 +1069,7 @@ encode_picture(FILE *yuv_fp, FILE *avc_fp,
     end_picture(slice_type, next_is_bpic);
 }
 
-static void encode_i_picture(FILE *yuv_fp, FILE *avc_fp, int f, int is_idr)
-{
-    encode_picture(yuv_fp, avc_fp,
-                   enc_frame_number, f,
-                   is_idr,
-                   SLICE_TYPE_I, 0, f + 1);
-}
-
-static void encode_p_picture(FILE *yuv_fp, FILE *avc_fp, int f)
-{
-    encode_picture(yuv_fp, avc_fp,
-                   enc_frame_number, f,
-                   0,
-                   SLICE_TYPE_P, 0, f + 1);
-}
-
-static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes)
+static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes, int next_f)
 {
     int i;
     encode_picture(yuv_fp, avc_fp,
@@ -1103,7 +1087,7 @@ static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes)
     encode_picture(yuv_fp, avc_fp,
                    enc_frame_number + 1, f + nbframes - 1,
                    0,
-                   SLICE_TYPE_B, 0, f + nbframes + 1);
+                   SLICE_TYPE_B, 0, next_f);
 }
 
 static void show_help()
@@ -1315,28 +1299,47 @@ int main(int argc, char *argv[])
 
     enc_frame_number = 0;
     for ( f = 0; f < frame_number; ) {         //picture level loop
-        int is_intra = i_frame_only?1:(enc_frame_number % intra_period == 0);
-        int is_idr = (f == 0);
-        int is_bslice = 0;
-               
-        if ( ! is_intra && pb_period > 0) {
-            is_bslice = i_p_frame_only?0:(f % pb_period == 1) && (f < frame_number - 1);       
-        }
-       
-        if ( is_intra ) {
-            encode_i_picture(yuv_fp, avc_fp, f, is_idr);
-            f++;
-            enc_frame_number++;
-        } else if ( is_bslice) {
-            encode_pb_pictures(yuv_fp, avc_fp, f, 2);   //last parameter is continue B frames number
-            f += (1 + 2);
-            enc_frame_number++;
-        } else {
-            encode_p_picture(yuv_fp, avc_fp, f);
+        static int const frame_type_pattern[][2] = { {SLICE_TYPE_I,1}, 
+                                                     {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3},
+                                                     {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3},
+                                                     {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3},
+                                                     {SLICE_TYPE_P,2} };
+
+        if ( i_frame_only ) {
+            encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, f+1);
             f++;
             enc_frame_number++;
+        } else if ( i_p_frame_only ) {
+            if ( (f % intra_period) == 0 ) {
+                encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, f+1);
+                f++;
+                enc_frame_number++;
+            } else {
+                encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_P, 0, f+1);
+                f++;
+                enc_frame_number++;
+            }
+        } else { // follow the i,p,b pattern
+            static int fcurrent = 0;
+            int fnext;
+            
+            fcurrent = fcurrent % sizeof(frame_type_pattern)/sizeof(int[2]);
+            fnext = (fcurrent+1) % sizeof(frame_type_pattern)/sizeof(int[2]);
+            
+            if ( frame_type_pattern[fcurrent][0] == SLICE_TYPE_I ) {
+                encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, 
+                        f+frame_type_pattern[fnext][1]);
+                f++;
+                enc_frame_number++;
+            } else {
+                encode_pb_pictures(yuv_fp, avc_fp, f, frame_type_pattern[fcurrent][1]-1, 
+                        f + frame_type_pattern[fcurrent][1] + frame_type_pattern[fnext][1] -1 );
+                f += frame_type_pattern[fcurrent][1];
+                enc_frame_number++;
+            }
+            fcurrent++;
         }
-       
         printf("\r %d/%d ...", f+1, frame_number);
         fflush(stdout);
     }