aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2010-01-09 18:33:21 +0000
committerMichael Niedermayer <michaelni@gmx.at>2010-01-09 18:33:21 +0000
commitc46eeae2a80dfe0046c15b542e8b9a2c78f19bf7 (patch)
tree8c0378f0ae122dd5fcd3b101f7b55d0d233188f2 /libavcodec
parentaa11ce6568a190b7c843c57bcbc8f5e1785af99b (diff)
downloadffmpeg-c46eeae2a80dfe0046c15b542e8b9a2c78f19bf7.tar.gz
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. Originally committed as revision 21113 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/ituh263enc.c18
-rw-r--r--libavcodec/mpegvideo_enc.c3
-rw-r--r--libavcodec/svq1.c4
-rw-r--r--libavcodec/svq1.h6
-rw-r--r--libavcodec/svq1enc.c12
-rw-r--r--libavcodec/utils.c6
6 files changed, 16 insertions, 33 deletions
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index ce64497984..5031dd5672 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -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(MpegEncContext * s, int picture_number)
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);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index e1df08e137..44cf3694cc 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -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(AVCodecContext *avctx)
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;
}
diff --git a/libavcodec/svq1.c b/libavcodec/svq1.c
index 580b1113f8..cae76104e5 100644
--- a/libavcodec/svq1.c
+++ b/libavcodec/svq1.c
@@ -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 }
};
diff --git a/libavcodec/svq1.h b/libavcodec/svq1.h
index bcae245e6e..283bc18399 100644
--- a/libavcodec/svq1.h
+++ b/libavcodec/svq1.h
@@ -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_multistage_vlc[6][8][2];
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 */
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 1c5ac5dfe2..ebe39c6c14 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -94,19 +94,11 @@ static void svq1_write_header(SVQ1Context *s, int frame_type)
/* 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);
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 670803b6a5..f583cd284e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1200,6 +1200,12 @@ int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
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 "