From patchwork Sun Oct 4 20:55:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TsODwqltZXRoIE3Dg8KhcnRvbg==?= X-Patchwork-Id: 51637 X-Patchwork-Delegate: dougsland@redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n94L3UAj026481 for ; Sun, 4 Oct 2009 21:03:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758044AbZJDU4M (ORCPT ); Sun, 4 Oct 2009 16:56:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758041AbZJDU4M (ORCPT ); Sun, 4 Oct 2009 16:56:12 -0400 Received: from mail00d.mail.t-online.hu ([84.2.42.5]:60483 "EHLO mail00d.mail.t-online.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757971AbZJDU4L (ORCPT ); Sun, 4 Oct 2009 16:56:11 -0400 Received: from [192.168.1.64] (dsl54029FEE.pool.t-online.hu [84.2.159.238]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail00d.mail.t-online.hu (Postfix) with ESMTPSA id D04F2758611; Sun, 4 Oct 2009 22:49:45 +0200 (CEST) Message-ID: <4AC90BBF.9040803@freemail.hu> Date: Sun, 04 Oct 2009 22:55:27 +0200 From: =?UTF-8?B?TsOpbWV0aCBNw6FydG9u?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; hu-HU; rv:1.8.1.21) Gecko/20090402 SeaMonkey/1.1.16 MIME-Version: 1.0 To: Jean-Francois Moine , Thomas Kaiser , Kyle Guinn , Theodore Kilgore CC: V4L Mailing List , LKML , ltp-list@lists.sourceforge.net Subject: [PATCH] pac_common: redesign function for finding Start Of Frame X-DCC-mail.t-online.hu-Metrics: mail00d.mail.t-online.hu 32710; Body=7 Fuz1=7 Fuz2=7 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org --- linux-2.6.32-rc1.orig/drivers/media/video/gspca/pac_common.h 2009-09-10 00:13:59.000000000 +0200 +++ linux-2.6.32-rc1/drivers/media/video/gspca/pac_common.h 2009-10-04 21:49:19.000000000 +0200 @@ -33,6 +33,45 @@ static const unsigned char pac_sof_marker[5] = { 0xff, 0xff, 0x00, 0xff, 0x96 }; +/* + The following state machine finds the SOF marker sequence + 0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream. + + +----------+ + | 0: START |<---------------\ + +----------+<-\ | + | \---/otherwise | + v 0xff | + +----------+ otherwise | + | 1 |--------------->* + | | ^ + +----------+ | + | | + v 0xff | + +----------+<-\0xff | + /->| |--/ | + | | 2 |--------------->* + | | | otherwise ^ + | +----------+ | + | | | + | v 0x00 | + | +----------+ | + | | 3 | | + | | |--------------->* + | +----------+ otherwise ^ + | | | + 0xff | v 0xff | + | +----------+ | + \--| 4 | | + | |----------------/ + +----------+ otherwise + | + v 0x96 + +----------+ + | FOUND | + +----------+ +*/ + static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, unsigned char *m, int len) { @@ -41,17 +80,54 @@ static unsigned char *pac_find_sof(struc /* Search for the SOF marker (fixed part) in the header */ for (i = 0; i < len; i++) { - if (m[i] == pac_sof_marker[sd->sof_read]) { - sd->sof_read++; - if (sd->sof_read == sizeof(pac_sof_marker)) { + switch (sd->sof_read) { + case 0: + if (m[i] == 0xff) + sd->sof_read = 1; + break; + case 1: + if (m[i] == 0xff) + sd->sof_read = 2; + else + sd->sof_read = 0; + break; + case 2: + switch (m[i]) { + case 0x00: + sd->sof_read = 3; + break; + case 0xff: + /* stay in this state */ + break; + default: + sd->sof_read = 0; + } + break; + case 3: + if (m[i] == 0xff) + sd->sof_read = 4; + else + sd->sof_read = 0; + break; + case 4: + switch (m[i]) { + case 0x96: + /* Pattern found */ PDEBUG(D_FRAM, "SOF found, bytes to analyze: %u." " Frame starts at byte #%u", len, i + 1); sd->sof_read = 0; return m + i + 1; + break; + case 0xff: + sd->sof_read = 2; + break; + default: + sd->sof_read = 0; } - } else { + break; + default: sd->sof_read = 0; } }