Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 1 | /* |
| 2 | * SN9C2028 common functions |
| 3 | * |
| 4 | * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu> |
| 5 | * |
| 6 | * Based closely upon the file gspca/pac_common.h |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 18 | */ |
| 19 | |
Vasily Khoruzhick | d8fd9f5 | 2015-04-24 04:04:04 -0300 | [diff] [blame] | 20 | static const unsigned char sn9c2028_sof_marker[] = { |
| 21 | 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96, |
| 22 | 0x00, |
| 23 | 0x00, /* seq */ |
| 24 | 0x00, |
| 25 | 0x00, |
| 26 | 0x00, /* avg luminance lower 8 bit */ |
| 27 | 0x00, /* avg luminance higher 8 bit */ |
| 28 | }; |
Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 29 | |
| 30 | static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev, |
| 31 | unsigned char *m, int len) |
| 32 | { |
| 33 | struct sd *sd = (struct sd *) gspca_dev; |
| 34 | int i; |
| 35 | |
| 36 | /* Search for the SOF marker (fixed part) in the header */ |
| 37 | for (i = 0; i < len; i++) { |
Vasily Khoruzhick | d8fd9f5 | 2015-04-24 04:04:04 -0300 | [diff] [blame] | 38 | if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) || |
| 39 | (sd->sof_read > 5)) { |
Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 40 | sd->sof_read++; |
Vasily Khoruzhick | d8fd9f5 | 2015-04-24 04:04:04 -0300 | [diff] [blame] | 41 | if (sd->sof_read == 11) |
| 42 | sd->avg_lum_l = m[i]; |
| 43 | if (sd->sof_read == 12) |
| 44 | sd->avg_lum = (m[i] << 8) + sd->avg_lum_l; |
Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 45 | if (sd->sof_read == sizeof(sn9c2028_sof_marker)) { |
Joe Perches | 37d5efb | 2017-09-22 15:20:33 -0400 | [diff] [blame] | 46 | gspca_dbg(gspca_dev, D_FRAM, |
| 47 | "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n", |
| 48 | len, i + 1); |
Theodore Kilgore | 5bdd00b | 2009-12-25 05:16:32 -0300 | [diff] [blame] | 49 | sd->sof_read = 0; |
| 50 | return m + i + 1; |
| 51 | } |
| 52 | } else { |
| 53 | sd->sof_read = 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return NULL; |
| 58 | } |