The patch number 13192 was added via Jean-Francois Moine <moin...@free.fr>
to http://linuxtv.org/hg/v4l-dvb master development tree.

Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel

If anyone has any objections, please let us know by sending a message to:
        Linux Media Mailing List <linux-me...@vger.kernel.org>

------

From: Marton Nemeth  <nm...@freemail.hu>
gspca - pac_common: redesign function for finding Start Of Frame


The original implementation of pac_find_sof() does not always find
the Start Of Frame (SOF) marker. Replace it with a state machine
based design.

Priority: normal

Acked-by: Hans de Goede <hdego...@redhat.com>
Signed-off-by: Marton Nemeth <nm...@freemail.hu>
Signed-off-by: Jean-Francois Moine <moin...@free.fr>


---

 linux/drivers/media/video/gspca/pac_common.h |   84 ++++++++++++++++++-
 1 file changed, 80 insertions(+), 4 deletions(-)

diff -r 87777a17d73d -r ad4a5d890531 
linux/drivers/media/video/gspca/pac_common.h
--- a/linux/drivers/media/video/gspca/pac_common.h      Mon Oct 19 15:29:01 
2009 +0900
+++ b/linux/drivers/media/video/gspca/pac_common.h      Mon Oct 05 10:41:30 
2009 +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 @@
 
        /* 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;
                }
        }


---

Patch is available at: 
http://linuxtv.org/hg/v4l-dvb/rev/ad4a5d89053134fe4113da365c5572925a884168

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to