From 37ddd3833219fa7b913fff3f5cccc6878b047e6b Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Fri, 4 May 2012 10:27:03 -0700 Subject: [PATCH 01/15] celp filters: Do not read earlier than the start of the 'out' vector. CC: libav-stable@libav.org --- libavcodec/celp_filters.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/celp_filters.c b/libavcodec/celp_filters.c index 25a6744b04..849cda439e 100644 --- a/libavcodec/celp_filters.c +++ b/libavcodec/celp_filters.c @@ -133,9 +133,8 @@ void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, out2 -= val * old_out2; out3 -= val * old_out3; - old_out3 = out[-5]; - for (i = 5; i <= filter_length; i += 2) { + old_out3 = out[-i]; val = filter_coeffs[i-1]; out0 -= val * old_out3; @@ -154,7 +153,6 @@ void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, FFSWAP(float, old_out0, old_out2); old_out1 = old_out3; - old_out3 = out[-i-2]; } tmp0 = out0; From 273e6af47b38391f2bcc157cca0423fe7fcbf55c Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 4 May 2012 16:06:26 -0700 Subject: [PATCH 02/15] ea: check chunk_size for validity. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavformat/electronicarts.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index 47ef40f69d..b215547f33 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -487,12 +487,17 @@ static int ea_read_packet(AVFormatContext *s, while (!packet_read) { chunk_type = avio_rl32(pb); - chunk_size = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8; + chunk_size = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb); + if (chunk_size <= 8) + return AVERROR_INVALIDDATA; + chunk_size -= 8; switch (chunk_type) { /* audio data */ case ISNh_TAG: /* header chunk also contains data; skip over the header portion*/ + if (chunk_size < 32) + return AVERROR_INVALIDDATA; avio_skip(pb, 32); chunk_size -= 32; case ISNd_TAG: From d2205d6543881f2e6fa18c8a354bbcf91a1235f7 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 2 May 2012 10:58:55 -0700 Subject: [PATCH 03/15] png: check bit depth for PAL8/Y400A pixel formats. Wrong bit depth can lead to invalid rowsize values, which crashes the decoder further down. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavcodec/pngdec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 087abaed89..871f2b2ba3 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -479,9 +479,11 @@ static int decode_frame(AVCodecContext *avctx, } else if (s->bit_depth == 1 && s->color_type == PNG_COLOR_TYPE_GRAY) { avctx->pix_fmt = PIX_FMT_MONOBLACK; - } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) { + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_PALETTE) { avctx->pix_fmt = PIX_FMT_PAL8; - } else if (s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { avctx->pix_fmt = PIX_FMT_Y400A; } else { goto fail; From de26a4b6993ff3dc91f17d110326736c96bfc9ec Mon Sep 17 00:00:00 2001 From: Ivan Kovtunov Date: Fri, 4 May 2012 22:31:46 +0300 Subject: [PATCH 04/15] rtpdec_h264: Add input size checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes crashes if given too short data packets. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index 32a57d3ec7..51447f9703 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -173,11 +173,18 @@ static int h264_handle_packet(AVFormatContext *ctx, const uint8_t * buf, int len, int flags) { - uint8_t nal = buf[0]; - uint8_t type = (nal & 0x1f); + uint8_t nal; + uint8_t type; int result= 0; uint8_t start_sequence[] = { 0, 0, 0, 1 }; + if (!len) { + av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n"); + return AVERROR_INVALIDDATA; + } + nal = buf[0]; + type = nal & 0x1f; + #ifdef DEBUG assert(data); assert(data->cookie == MAGIC_COOKIE); @@ -271,7 +278,7 @@ static int h264_handle_packet(AVFormatContext *ctx, case 28: // FU-A (fragmented nal) buf++; len--; // skip the fu_indicator - { + if (len > 1) { // these are the same as above, we just redo them here for clarity... uint8_t fu_indicator = nal; uint8_t fu_header = *buf; // read the fu_header. @@ -302,6 +309,9 @@ static int h264_handle_packet(AVFormatContext *ctx, av_new_packet(pkt, len); memcpy(pkt->data, buf, len); } + } else { + av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n"); + result = AVERROR_INVALIDDATA; } break; From 5245adb963e35660a70115c437cd67ea0c398885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 4 May 2012 22:45:11 +0300 Subject: [PATCH 05/15] rtpdec_h264: Check the available data length before reading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure the length is checked for STAP-A type packets. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index 51447f9703..8b56ada397 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -218,7 +218,7 @@ static int h264_handle_packet(AVFormatContext *ctx, const uint8_t *src= buf; int src_len= len; - do { + while (src_len > 2) { uint16_t nal_size = AV_RB16(src); // this going to be a problem if unaligned (can it be?) // consume the length of the aggregate... @@ -252,7 +252,7 @@ static int h264_handle_packet(AVFormatContext *ctx, if (src_len < 0) av_log(ctx, AV_LOG_ERROR, "Consumed more bytes than we got! (%d)\n", src_len); - } while (src_len > 2); // because there could be rtp padding.. + } if(pass==0) { // now we know the total size of the packet (with the start sequences added) From b7b7354c336a0e3df8b6e7ca8baebe8750ed0f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 5 May 2012 00:29:15 +0300 Subject: [PATCH 06/15] rtpdec_h264: Return proper error codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index 8b56ada397..f3793f5ec6 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -272,7 +272,7 @@ static int h264_handle_packet(AVFormatContext *ctx, av_log(ctx, AV_LOG_ERROR, "Unhandled type (%d) (See RFC for implementation details\n", type); - result= -1; + result = AVERROR(ENOSYS); break; case 28: // FU-A (fragmented nal) @@ -319,7 +319,7 @@ static int h264_handle_packet(AVFormatContext *ctx, case 31: // undefined default: av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type); - result= -1; + result = AVERROR_INVALIDDATA; break; } From 5a571d324129ce367584ad9d92aae1d286f389a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 4 May 2012 23:49:45 +0300 Subject: [PATCH 07/15] rtpdec_h264: Remove useless memory corruption checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index f3793f5ec6..eb20397811 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -53,8 +53,6 @@ RTP/H264 specific private data. */ struct PayloadContext { - unsigned long cookie; ///< sanity check, to make sure we get the pointer we're expecting. - //sdp setup parameters uint8_t profile_idc; ///< from the sdp setup parameters. uint8_t profile_iop; ///< from the sdp setup parameters. @@ -65,9 +63,6 @@ struct PayloadContext { #endif }; -#define MAGIC_COOKIE (0xdeadbeef) ///< Cookie for the extradata; to verify we are what we think we are, and that we haven't been freed. -#define DEAD_COOKIE (0xdeaddead) ///< Cookie for the extradata; once it is freed. - /* ---------------- private code */ static int sdp_parse_fmtp_config_h264(AVStream * stream, PayloadContext * h264_data, @@ -187,7 +182,6 @@ static int h264_handle_packet(AVFormatContext *ctx, #ifdef DEBUG assert(data); - assert(data->cookie == MAGIC_COOKIE); #endif assert(buf); @@ -331,15 +325,7 @@ static int h264_handle_packet(AVFormatContext *ctx, /* ---------------- public code */ static PayloadContext *h264_new_context(void) { - PayloadContext *data = - av_mallocz(sizeof(PayloadContext) + - FF_INPUT_BUFFER_PADDING_SIZE); - - if (data) { - data->cookie = MAGIC_COOKIE; - } - - return data; + return av_mallocz(sizeof(PayloadContext) + FF_INPUT_BUFFER_PADDING_SIZE); } static void h264_free_context(PayloadContext *data) @@ -354,13 +340,6 @@ static void h264_free_context(PayloadContext *data) } #endif - assert(data); - assert(data->cookie == MAGIC_COOKIE); - - // avoid stale pointers (assert) - data->cookie = DEAD_COOKIE; - - // and clear out this... av_free(data); } @@ -376,7 +355,6 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index, stream = s->streams[st_index]; codec = stream->codec; - assert(h264_data->cookie == MAGIC_COOKIE); if (av_strstart(p, "framesize:", &p)) { char buf1[50]; From 8d43b8b8e84495deeebc1f01a2035ba76ba24a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 4 May 2012 23:46:18 +0300 Subject: [PATCH 08/15] rtpdec_h264: Remove outdated/useless/incorrect comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RTCP is handled elsewhere, not in the depacketizer for an individual format. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index eb20397811..d98be07366 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -30,10 +30,6 @@ * Single Nal Unit Mode (0), or * Non-Interleaved Mode (1). It currently does not support * Interleaved Mode (2). (This requires implementing STAP-B, MTAP16, MTAP24, FU-B packet types) - * - * @note TODO: - * 1) RTCP sender reports for udp streams are required.. - * */ #include "libavutil/base64.h" @@ -49,21 +45,17 @@ #include "rtpdec.h" #include "rtpdec_formats.h" -/** - RTP/H264 specific private data. -*/ struct PayloadContext { //sdp setup parameters - uint8_t profile_idc; ///< from the sdp setup parameters. - uint8_t profile_iop; ///< from the sdp setup parameters. - uint8_t level_idc; ///< from the sdp setup parameters. - int packetization_mode; ///< from the sdp setup parameters. + uint8_t profile_idc; + uint8_t profile_iop; + uint8_t level_idc; + int packetization_mode; #ifdef DEBUG int packet_types_received[32]; #endif }; -/* ---------------- private code */ static int sdp_parse_fmtp_config_h264(AVStream * stream, PayloadContext * h264_data, char *attr, char *value) @@ -99,7 +91,6 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream, buffer[0] = value[4]; buffer[1] = value[5]; level_idc = strtol(buffer, NULL, 16); - // set the parameters... av_log(codec, AV_LOG_DEBUG, "RTP Profile IDC: %x Profile IOP: %x Level: %x\n", profile_idc, profile_iop, level_idc); @@ -136,7 +127,6 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream, { if(codec->extradata_size) { - // av_realloc? memcpy(dest, codec->extradata, codec->extradata_size); av_free(codec->extradata); } @@ -213,7 +203,7 @@ static int h264_handle_packet(AVFormatContext *ctx, int src_len= len; while (src_len > 2) { - uint16_t nal_size = AV_RB16(src); // this going to be a problem if unaligned (can it be?) + uint16_t nal_size = AV_RB16(src); // consume the length of the aggregate... src += 2; @@ -275,7 +265,7 @@ static int h264_handle_packet(AVFormatContext *ctx, if (len > 1) { // these are the same as above, we just redo them here for clarity... uint8_t fu_indicator = nal; - uint8_t fu_header = *buf; // read the fu_header. + uint8_t fu_header = *buf; uint8_t start_bit = fu_header >> 7; // uint8_t end_bit = (fu_header & 0x40) >> 6; uint8_t nal_type = (fu_header & 0x1f); @@ -322,7 +312,6 @@ static int h264_handle_packet(AVFormatContext *ctx, return result; } -/* ---------------- public code */ static PayloadContext *h264_new_context(void) { return av_mallocz(sizeof(PayloadContext) + FF_INPUT_BUFFER_PADDING_SIZE); @@ -380,12 +369,9 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index, // could use this if we wanted. } - return 0; // keep processing it the normal way... + return 0; } -/** -This is the structure for expanding on the dynamic rtp protocols (makes everything static. yay!) -*/ RTPDynamicProtocolHandler ff_h264_dynamic_handler = { .enc_name = "H264", .codec_type = AVMEDIA_TYPE_VIDEO, From 44f99fe0f5e688833cb671efbaa0beb6b74c9389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 4 May 2012 23:53:10 +0300 Subject: [PATCH 09/15] rtpdec_h264: Remove a useless ifdef MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit assert is a no-op if DEBUG isn't defined. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index d98be07366..399ca47ff7 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -170,9 +170,7 @@ static int h264_handle_packet(AVFormatContext *ctx, nal = buf[0]; type = nal & 0x1f; -#ifdef DEBUG assert(data); -#endif assert(buf); if (type >= 1 && type <= 23) From 363c3a44ff9afbf85fc2c4ba460173e39b0d043c Mon Sep 17 00:00:00 2001 From: Mashiat Sarker Shakkhar Date: Thu, 3 May 2012 10:14:47 -0700 Subject: [PATCH 10/15] WMAL: Restore removed code in mclms_predict() Based on observations made by Jakub Stachowski Signed-off-by: Kostya Shishkov --- libavcodec/wmalosslessdec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index ff6308343e..7510b12ef9 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -655,6 +655,8 @@ static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred) for (ich = 0; ich < num_channels; ich++) { pred[ich] = 0; + if (!s->is_channel_coded[ich]) + continue; for (i = 0; i < order * num_channels; i++) pred[ich] += s->mclms_prevvalues[i + s->mclms_recent] * s->mclms_coeffs[i + order * num_channels * ich]; From ddffe3de4352eb025b78843cf3b44501056b54bb Mon Sep 17 00:00:00 2001 From: Jakub Stachowski Date: Thu, 3 May 2012 19:36:48 +0200 Subject: [PATCH 11/15] WMAL: Shift output samples by the specified number of padding zeroes. Signed-off-by: Kostya Shishkov --- libavcodec/wmalosslessdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 7510b12ef9..d4c9c5a828 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -979,10 +979,10 @@ static int decode_subframe(WmallDecodeCtx *s) for (j = 0; j < subframe_len; j++) { if (s->bits_per_sample == 16) { - *s->samples_16[c] = (int16_t) s->channel_residues[c][j]; + *s->samples_16[c] = (int16_t) s->channel_residues[c][j] << padding_zeroes; s->samples_16[c] += s->num_channels; } else { - *s->samples_32[c] = s->channel_residues[c][j]; + *s->samples_32[c] = s->channel_residues[c][j] << padding_zeroes; s->samples_32[c] += s->num_channels; } } From 5cb4f1a1276193c12805e5e871e10bc3fffc207f Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Tue, 17 Apr 2012 18:31:25 +0200 Subject: [PATCH 12/15] vsrc_buffer: return EAGAIN if no frame is available. This is not an erroneous condition, do not print a warning. Signed-off-by: Anton Khirnov --- libavfilter/vsrc_buffer.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 742943aa57..1ace368413 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -175,9 +175,7 @@ static int request_frame(AVFilterLink *link) if (!av_fifo_size(c->fifo)) { if (c->eof) return AVERROR_EOF; - av_log(link->src, AV_LOG_ERROR, - "request_frame() called with no available frame!\n"); - return AVERROR(EINVAL); + return AVERROR(EAGAIN); } av_fifo_generic_read(c->fifo, &buf, sizeof(buf), NULL); From b5a3c6038d559582236b4faf6dbbc0f1984d4107 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Apr 2012 10:33:49 +0200 Subject: [PATCH 13/15] build: Drop leftover .exp pattern from LIBSUFFIXES list. --- common.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.mak b/common.mak index 7f2c36774e..98c274e366 100644 --- a/common.mak +++ b/common.mak @@ -47,6 +47,6 @@ OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS)) CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver DISTCLEANSUFFIXES = *.pc -LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp +LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a -include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d)) From 814208a7a697274994ee3eeb0da225c0fda6d1c7 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Apr 2012 16:29:26 +0200 Subject: [PATCH 14/15] tests: Mark some file-internal symbols as static. --- tests/rotozoom.c | 14 +++++++------- tests/videogen.c | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/rotozoom.c b/tests/rotozoom.c index 9ce45cd9f4..9bba6e3489 100644 --- a/tests/rotozoom.c +++ b/tests/rotozoom.c @@ -160,8 +160,8 @@ static void pgmyuv_save(const char *filename, int w, int h, free(cr_tab); } -unsigned char *rgb_tab; -int width, height, wrap; +static unsigned char *rgb_tab; +static int width, height, wrap; static void put_pixel(int x, int y, int r, int g, int b) { @@ -177,12 +177,12 @@ static void put_pixel(int x, int y, int r, int g, int b) p[2] = b; } -unsigned char tab_r[256 * 256]; -unsigned char tab_g[256 * 256]; -unsigned char tab_b[256 * 256]; +static unsigned char tab_r[256 * 256]; +static unsigned char tab_g[256 * 256]; +static unsigned char tab_b[256 * 256]; -int h_cos[360]; -int h_sin[360]; +static int h_cos[360]; +static int h_sin[360]; static int ipol(uint8_t *src, int x, int y) { diff --git a/tests/videogen.c b/tests/videogen.c index 1aad70031e..14996da7a4 100644 --- a/tests/videogen.c +++ b/tests/videogen.c @@ -137,8 +137,8 @@ static void pgmyuv_save(const char *filename, int w, int h, free(cr_tab); } -unsigned char *rgb_tab; -int width, height, wrap; +static unsigned char *rgb_tab; +static int width, height, wrap; static void put_pixel(int x, int y, int r, int g, int b) { @@ -200,9 +200,9 @@ typedef struct VObj { int r, g, b; } VObj; -VObj objs[NB_OBJS]; +static VObj objs[NB_OBJS]; -unsigned int seed = 1; +static unsigned int seed = 1; static void gen_image(int num, int w, int h) { From f0ccd53a3b0bbe704a7bc94dbc8caac7be81e079 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Apr 2012 16:44:31 +0200 Subject: [PATCH 15/15] tests: Refactor rotozoom/videogen common code into a separate file. --- tests/Makefile | 3 + tests/rotozoom.c | 126 +---------------------------------------- tests/utils.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++ tests/videogen.c | 129 +----------------------------------------- 4 files changed, 150 insertions(+), 252 deletions(-) create mode 100644 tests/utils.c diff --git a/tests/Makefile b/tests/Makefile index 19fbe11fd2..cbd3fd2434 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,6 +7,9 @@ $(AREF): avconv$(EXESUF) tests/data/asynth1.sw OBJDIRS += tests/data tests/vsynth1 tests/vsynth2 +# Required due to missing automatic dependency tracking for HOSTOBJS. +tests/rotozoom.o tests/videogen.o: tests/utils.c + tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) | tests/vsynth1 $(M)./$< 'tests/vsynth1/' diff --git a/tests/rotozoom.c b/tests/rotozoom.c index 9bba6e3489..48c06b017e 100644 --- a/tests/rotozoom.c +++ b/tests/rotozoom.c @@ -24,6 +24,8 @@ #include #include +#include "utils.c" + #define FIXP (1 << 16) #define MY_PI 205887 // (M_PI * FIX) @@ -53,130 +55,6 @@ static int64_t int_sin(int64_t a) return a - int_pow(a, 3) / 6 + int_pow(a, 5) / 120 - int_pow(a, 7) / 5040; } -#define SCALEBITS 8 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) - -static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, - unsigned char *cr, unsigned char *src, - int width, int height) -{ - int wrap, wrap3, x, y; - int r, g, b, r1, g1, b1; - unsigned char *p; - - wrap = width; - wrap3 = width * 3; - p = src; - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 2) { - r = p[0]; - g = p[1]; - b = p[2]; - r1 = r; - g1 = g; - b1 = b; - lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - r = p[3]; - g = p[4]; - b = p[5]; - r1 += r; - g1 += g; - b1 += b; - lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - p += wrap3; - lum += wrap; - - r = p[0]; - g = p[1]; - b = p[2]; - r1 += r; - g1 += g; - b1 += b; - lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - r = p[3]; - g = p[4]; - b = p[5]; - r1 += r; - g1 += g; - b1 += b; - lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - - cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + - FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; - cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - - FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; - - cb++; - cr++; - p += -wrap3 + 2 * 3; - lum += -wrap + 2; - } - p += wrap3; - lum += wrap; - } -} - -/* cif format */ -#define DEFAULT_WIDTH 352 -#define DEFAULT_HEIGHT 288 -#define DEFAULT_NB_PICT 50 - -static void pgmyuv_save(const char *filename, int w, int h, - unsigned char *rgb_tab) -{ - FILE *f; - int i, h2, w2; - unsigned char *cb, *cr; - unsigned char *lum_tab, *cb_tab, *cr_tab; - - lum_tab = malloc(w * h); - cb_tab = malloc(w * h / 4); - cr_tab = malloc(w * h / 4); - - rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); - - f = fopen(filename, "wb"); - fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255); - fwrite(lum_tab, 1, w * h, f); - h2 = h / 2; - w2 = w / 2; - cb = cb_tab; - cr = cr_tab; - for (i = 0; i < h2; i++) { - fwrite(cb, 1, w2, f); - fwrite(cr, 1, w2, f); - cb += w2; - cr += w2; - } - fclose(f); - - free(lum_tab); - free(cb_tab); - free(cr_tab); -} - -static unsigned char *rgb_tab; -static int width, height, wrap; - -static void put_pixel(int x, int y, int r, int g, int b) -{ - unsigned char *p; - - if (x < 0 || x >= width || - y < 0 || y >= height) - return; - - p = rgb_tab + y * wrap + x * 3; - p[0] = r; - p[1] = g; - p[2] = b; -} - static unsigned char tab_r[256 * 256]; static unsigned char tab_g[256 * 256]; static unsigned char tab_b[256 * 256]; diff --git a/tests/utils.c b/tests/utils.c new file mode 100644 index 0000000000..2a85bd8e06 --- /dev/null +++ b/tests/utils.c @@ -0,0 +1,144 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#define SCALEBITS 8 +#define ONE_HALF (1 << (SCALEBITS - 1)) +#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) + +static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, + unsigned char *cr, unsigned char *src, + int width, int height) +{ + int wrap, wrap3, x, y; + int r, g, b, r1, g1, b1; + unsigned char *p; + + wrap = width; + wrap3 = width * 3; + p = src; + for (y = 0; y < height; y += 2) { + for (x = 0; x < width; x += 2) { + r = p[0]; + g = p[1]; + b = p[2]; + r1 = r; + g1 = g; + b1 = b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + r = p[3]; + g = p[4]; + b = p[5]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + p += wrap3; + lum += wrap; + + r = p[0]; + g = p[1]; + b = p[2]; + r1 += r; + g1 += g; + b1 += b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + r = p[3]; + g = p[4]; + b = p[5]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + + cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + + FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - + FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + + cb++; + cr++; + p += -wrap3 + 2 * 3; + lum += -wrap + 2; + } + p += wrap3; + lum += wrap; + } +} + +/* cif format */ +#define DEFAULT_WIDTH 352 +#define DEFAULT_HEIGHT 288 +#define DEFAULT_NB_PICT 50 + +static void pgmyuv_save(const char *filename, int w, int h, + unsigned char *rgb_tab) +{ + FILE *f; + int i, h2, w2; + unsigned char *cb, *cr; + unsigned char *lum_tab, *cb_tab, *cr_tab; + + lum_tab = malloc(w * h); + cb_tab = malloc(w * h / 4); + cr_tab = malloc(w * h / 4); + + rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); + + f = fopen(filename, "wb"); + fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255); + fwrite(lum_tab, 1, w * h, f); + h2 = h / 2; + w2 = w / 2; + cb = cb_tab; + cr = cr_tab; + for (i = 0; i < h2; i++) { + fwrite(cb, 1, w2, f); + fwrite(cr, 1, w2, f); + cb += w2; + cr += w2; + } + fclose(f); + + free(lum_tab); + free(cb_tab); + free(cr_tab); +} + +static unsigned char *rgb_tab; +static int width, height, wrap; + +static void put_pixel(int x, int y, int r, int g, int b) +{ + unsigned char *p; + + if (x < 0 || x >= width || + y < 0 || y >= height) + return; + + p = rgb_tab + y * wrap + x * 3; + p[0] = r; + p[1] = g; + p[2] = b; +} diff --git a/tests/videogen.c b/tests/videogen.c index 14996da7a4..8c3d53976e 100644 --- a/tests/videogen.c +++ b/tests/videogen.c @@ -25,134 +25,7 @@ #include #include -#define SCALEBITS 8 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) - -static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr, - uint8_t *src, int width, int height) -{ - int wrap, wrap3, x, y; - int r, g, b, r1, g1, b1; - uint8_t *p; - - wrap = width; - wrap3 = width * 3; - p = src; - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 2) { - r = p[0]; - g = p[1]; - b = p[2]; - r1 = r; - g1 = g; - b1 = b; - lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - r = p[3]; - g = p[4]; - b = p[5]; - r1 += r; - g1 += g; - b1 += b; - lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - p += wrap3; - lum += wrap; - - r = p[0]; - g = p[1]; - b = p[2]; - r1 += r; - g1 += g; - b1 += b; - lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - r = p[3]; - g = p[4]; - b = p[5]; - r1 += r; - g1 += g; - b1 += b; - lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + - FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - - cb[0] = 128 + ((- FIX(0.16874) * r1 - - FIX(0.33126) * g1 + - FIX(0.50000) * b1 + - 4 * ONE_HALF - 1) - >> (SCALEBITS + 2)); - cr[0] = 128 + ((FIX(0.50000) * r1 - - FIX(0.41869) * g1 - - FIX(0.08131) * b1 + - 4 * ONE_HALF - 1) - >> (SCALEBITS + 2)); - - cb++; - cr++; - p += -wrap3 + 2 * 3; - lum += -wrap + 2; - } - p += wrap3; - lum += wrap; - } -} - -/* cif format */ -#define DEFAULT_WIDTH 352 -#define DEFAULT_HEIGHT 288 -#define DEFAULT_NB_PICT 50 /* 2 seconds */ - -static void pgmyuv_save(const char *filename, int w, int h, - unsigned char *rgb_tab) -{ - FILE *f; - int i, h2, w2; - unsigned char *cb, *cr; - unsigned char *lum_tab, *cb_tab, *cr_tab; - - lum_tab = malloc(w * h); - cb_tab = malloc((w * h) / 4); - cr_tab = malloc((w * h) / 4); - - rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); - - f = fopen(filename, "wb"); - fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255); - fwrite(lum_tab, 1, w * h, f); - h2 = h / 2; - w2 = w / 2; - cb = cb_tab; - cr = cr_tab; - for (i = 0; i < h2; i++) { - fwrite(cb, 1, w2, f); - fwrite(cr, 1, w2, f); - cb += w2; - cr += w2; - } - fclose(f); - - free(lum_tab); - free(cb_tab); - free(cr_tab); -} - -static unsigned char *rgb_tab; -static int width, height, wrap; - -static void put_pixel(int x, int y, int r, int g, int b) -{ - unsigned char *p; - - if (x < 0 || x >= width || - y < 0 || y >= height) - return; - - p = rgb_tab + y * wrap + x * 3; - p[0] = r; - p[1] = g; - p[2] = b; -} +#include "utils.c" static unsigned int myrnd(unsigned int *seed_ptr, int n) {