[FFmpeg-cvslog] r21113 - in trunk/libavcodec: ituh263enc.c mpegvideo_enc.c svq1.c svq1.h svq1enc.c utils.c

michael subversion
Sat Jan 9 19:33:21 CET 2010


Author: michael
Date: Sat Jan  9 19:33:21 2010
New Revision: 21113

Log:
Add a function to match a 2 element vector of uint16_t and use it in h263 and svq1
instead of custom and bloated code to find an index into a w/h array.

Modified:
   trunk/libavcodec/ituh263enc.c
   trunk/libavcodec/mpegvideo_enc.c
   trunk/libavcodec/svq1.c
   trunk/libavcodec/svq1.h
   trunk/libavcodec/svq1enc.c
   trunk/libavcodec/utils.c

Modified: trunk/libavcodec/ituh263enc.c
==============================================================================
--- trunk/libavcodec/ituh263enc.c	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/ituh263enc.c	Sat Jan  9 19:33:21 2010	(r21113)
@@ -82,22 +82,6 @@ static const uint8_t wrong_run[102] = {
 19,  2,  1, 34, 35, 36
 };
 
-int h263_get_picture_format(int width, int height)
-{
-    if (width == 128 && height == 96)
-        return 1;
-    else if (width == 176 && height == 144)
-        return 2;
-    else if (width == 352 && height == 288)
-        return 3;
-    else if (width == 704 && height == 576)
-        return 4;
-    else if (width == 1408 && height == 1152)
-        return 5;
-    else
-        return 7;
-}
-
 /**
  * Returns the 4 bit value that specifies the given aspect ratio.
  * This may be one of the standard aspect ratios or it specifies
@@ -156,7 +140,7 @@ void h263_encode_picture_header(MpegEncC
     put_bits(&s->pb, 1, 0);     /* camera  off */
     put_bits(&s->pb, 1, 0);     /* freeze picture release off */
 
-    format = h263_get_picture_format(s->width, s->height);
+    format = ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height);
     if (!s->h263_plus) {
         /* H.263v1 */
         put_bits(&s->pb, 3, format);

Modified: trunk/libavcodec/mpegvideo_enc.c
==============================================================================
--- trunk/libavcodec/mpegvideo_enc.c	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/mpegvideo_enc.c	Sat Jan  9 19:33:21 2010	(r21113)
@@ -31,6 +31,7 @@
 #include "dsputil.h"
 #include "mpegvideo.h"
 #include "mpegvideo_common.h"
+#include "h263.h"
 #include "mjpegenc.h"
 #include "msmpeg4.h"
 #include "faandct.h"
@@ -570,7 +571,7 @@ av_cold int MPV_encode_init(AVCodecConte
         break;
     case CODEC_ID_H263:
         if (!CONFIG_H263_ENCODER)  return -1;
-        if (h263_get_picture_format(s->width, s->height) == 7) {
+        if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 7) {
             av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height);
             return -1;
         }

Modified: trunk/libavcodec/svq1.c
==============================================================================
--- trunk/libavcodec/svq1.c	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/svq1.c	Sat Jan  9 19:33:21 2010	(r21113)
@@ -37,7 +37,7 @@
 #include "svq1_vlc.h"
 
 /* standard video sizes */
-const struct svq1_frame_size ff_svq1_frame_size_table[8] = {
+const struct svq1_frame_size ff_svq1_frame_size_table[7] = {
   { 160, 120 }, { 128,  96 }, { 176, 144 }, { 352, 288 },
-  { 704, 576 }, { 240, 180 }, { 320, 240 }, {  -1,  -1 }
+  { 704, 576 }, { 240, 180 }, { 320, 240 }
 };

Modified: trunk/libavcodec/svq1.h
==============================================================================
--- trunk/libavcodec/svq1.h	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/svq1.h	Sat Jan  9 19:33:21 2010	(r21113)
@@ -43,8 +43,8 @@
 #define SVQ1_BLOCK_INTRA        3
 
 struct svq1_frame_size {
-    int width;
-    int height;
+    uint16_t width;
+    uint16_t height;
 };
 
 uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length,
@@ -59,6 +59,6 @@ extern const uint8_t ff_svq1_inter_multi
 extern const uint16_t ff_svq1_intra_mean_vlc[256][2];
 extern const uint16_t ff_svq1_inter_mean_vlc[512][2];
 
-extern const struct svq1_frame_size ff_svq1_frame_size_table[8];
+extern const struct svq1_frame_size ff_svq1_frame_size_table[7];
 
 #endif /* AVCODEC_SVQ1_H */

Modified: trunk/libavcodec/svq1enc.c
==============================================================================
--- trunk/libavcodec/svq1enc.c	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/svq1enc.c	Sat Jan  9 19:33:21 2010	(r21113)
@@ -94,19 +94,11 @@ static void svq1_write_header(SVQ1Contex
         /* output 5 unknown bits (2 + 2 + 1) */
         put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
 
-        for (i = 0; i < 7; i++)
-        {
-            if ((ff_svq1_frame_size_table[i].width == s->frame_width) &&
-                (ff_svq1_frame_size_table[i].height == s->frame_height))
-            {
-                put_bits(&s->pb, 3, i);
-                break;
-            }
-        }
+        i= ff_match_2uint16(ff_svq1_frame_size_table, FF_ARRAY_ELEMS(ff_svq1_frame_size_table), s->frame_width, s->frame_height);
+        put_bits(&s->pb, 3, i);
 
         if (i == 7)
         {
-            put_bits(&s->pb, 3, 7);
                 put_bits(&s->pb, 12, s->frame_width);
                 put_bits(&s->pb, 12, s->frame_height);
         }

Modified: trunk/libavcodec/utils.c
==============================================================================
--- trunk/libavcodec/utils.c	Sat Jan  9 19:12:06 2010	(r21112)
+++ trunk/libavcodec/utils.c	Sat Jan  9 19:33:21 2010	(r21113)
@@ -1200,6 +1200,12 @@ int av_parse_video_frame_rate(AVRational
         return 0;
 }
 
+int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
+    int i;
+    for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
+    return i;
+}
+
 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
 {
     av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "



More information about the ffmpeg-cvslog mailing list