Mercurial > libavcodec.hg
changeset 10832:f20726a6d538 libavcodec
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.
author | michael |
---|---|
date | Sat, 09 Jan 2010 18:33:21 +0000 |
parents | 94982978af3b |
children | 81efba80e735 |
files | ituh263enc.c mpegvideo_enc.c svq1.c svq1.h svq1enc.c utils.c |
diffstat | 6 files changed, 16 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/ituh263enc.c Sat Jan 09 18:12:06 2010 +0000 +++ b/ituh263enc.c Sat Jan 09 18:33:21 2010 +0000 @@ -82,22 +82,6 @@ 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 @@ 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);
--- a/mpegvideo_enc.c Sat Jan 09 18:12:06 2010 +0000 +++ b/mpegvideo_enc.c Sat Jan 09 18:33:21 2010 +0000 @@ -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 @@ 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; }
--- a/svq1.c Sat Jan 09 18:12:06 2010 +0000 +++ b/svq1.c Sat Jan 09 18:33:21 2010 +0000 @@ -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 } };
--- a/svq1.h Sat Jan 09 18:12:06 2010 +0000 +++ b/svq1.h Sat Jan 09 18:33:21 2010 +0000 @@ -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 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 */
--- a/svq1enc.c Sat Jan 09 18:12:06 2010 +0000 +++ b/svq1enc.c Sat Jan 09 18:33:21 2010 +0000 @@ -94,19 +94,11 @@ /* 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); }
--- a/utils.c Sat Jan 09 18:12:06 2010 +0000 +++ b/utils.c Sat Jan 09 18:33:21 2010 +0000 @@ -1200,6 +1200,12 @@ 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 "