1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * SN9C2028 common functions 4 * 5 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu> 6 * 7 * Based closely upon the file gspca/pac_common.h 8 */ 9 10 static const unsigned char sn9c2028_sof_marker[] = { 11 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96, 12 0x00, 13 0x00, /* seq */ 14 0x00, 15 0x00, 16 0x00, /* avg luminance lower 8 bit */ 17 0x00, /* avg luminance higher 8 bit */ 18 }; 19 20 static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev, 21 unsigned char *m, int len) 22 { 23 struct sd *sd = (struct sd *) gspca_dev; 24 int i; 25 26 /* Search for the SOF marker (fixed part) in the header */ 27 for (i = 0; i < len; i++) { 28 if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) || 29 (sd->sof_read > 5)) { 30 sd->sof_read++; 31 if (sd->sof_read == 11) 32 sd->avg_lum_l = m[i]; 33 if (sd->sof_read == 12) 34 sd->avg_lum = (m[i] << 8) + sd->avg_lum_l; 35 if (sd->sof_read == sizeof(sn9c2028_sof_marker)) { 36 gspca_dbg(gspca_dev, D_FRAM, 37 "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n", 38 len, i + 1); 39 sd->sof_read = 0; 40 return m + i + 1; 41 } 42 } else { 43 sd->sof_read = 0; 44 } 45 } 46 47 return NULL; 48 } 49