From 913656a35dbd07cb5131a29330d6ff45509e4282 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Thu, 28 Mar 2013 21:17:25 +0000 Subject: [PATCH] Valid search backwards - find EOI quicker if its there. BUG=210 TEST=out\release\libyuv_unittest --gtest_filter=*Jpeg* Review URL: https://webrtc-codereview.appspot.com/1271004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@627 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/mjpeg_decoder.cc | 26 +++++++------------------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/README.chromium b/README.chromium index 551af2ccd..d99d13d8d 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 626 +Version: 627 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 6fe295167..9554f3590 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 626 +#define LIBYUV_VERSION 627 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/mjpeg_decoder.cc b/source/mjpeg_decoder.cc index 1a08e3bfe..898b441c0 100644 --- a/source/mjpeg_decoder.cc +++ b/source/mjpeg_decoder.cc @@ -76,35 +76,23 @@ MJpegDecoder::~MJpegDecoder() { } // Helper function to validate the jpeg looks ok. -// TODO(fbarchard): Improve performance. Scan backward for EOI? +// TODO(fbarchard): Optimize case where SOI is found but EOI is not. bool ValidateJpeg(const uint8* sample, size_t sample_size) { if (sample_size < 64) { // ERROR: Invalid jpeg size: sample_size return false; } - if (sample[0] != 0xff || sample[1] != 0xd8) { + if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image // ERROR: Invalid jpeg initial start code return false; } - bool soi = true; - int total_eoi = 0; - for (int i = 2; i < static_cast(sample_size) - 1; ++i) { - if (sample[i] == 0xff) { - if (sample[i + 1] == 0xd8) { // Start Of Image - soi = true; - } else if (sample[i + 1] == 0xd9) { // End Of Image - if (soi) { - ++total_eoi; - } - soi = false; - } + for (int i = static_cast(sample_size) - 1; i > 2; --i) { + if (sample[i - 1] == 0xff && sample[i] == 0xd9) { // End Of Image + return true; } } - if (!total_eoi) { - // ERROR: Invalid jpeg end code not found. Size sample_size - return false; - } - return true; + // ERROR: Invalid jpeg end code not found. Size sample_size + return false; } bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) {