Home | History | Annotate | Download | only in inc
      1 /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #ifndef __MM_QCAMERA_SOCKET_H__
     31 #define __MM_QCAMERA_SOCKET_H__
     32 
     33 #include <stdint.h>
     34 #include <pthread.h>
     35 #include <fcntl.h>
     36 #include <stdio.h>
     37 #include <string.h>
     38 #include <unistd.h>
     39 #include <termios.h>
     40 #include <assert.h>
     41 #include <stdlib.h>
     42 #include <ctype.h>
     43 #include <signal.h>
     44 #include <errno.h>
     45 #include <stdarg.h>
     46 #include <sys/mman.h>
     47 #include <sys/time.h>
     48 #include <linux/socket.h>
     49 #include <arpa/inet.h>
     50 #include <utils/Log.h>
     51 
     52 #undef __FD_SET
     53 #define __FD_SET(fd, fdsetp) \
     54   (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1<<((fd) & 31)))
     55 
     56 #undef __FD_CLR
     57 #define __FD_CLR(fd, fdsetp) \
     58   (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] &= ~(1<<((fd) & 31)))
     59 
     60 #undef  __FD_ISSET
     61 #define __FD_ISSET(fd, fdsetp) \
     62   ((((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] & (1<<((fd) & 31))) != 0)
     63 
     64 #undef  __FD_ZERO
     65 #define __FD_ZERO(fdsetp) \
     66   (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp))))
     67 
     68 #define TUNESERVER_MAX_RECV 2048
     69 #define TUNESERVER_MAX(a, b)  (((a) > (b)) ? (a) : (b))
     70 
     71 #define TUNESERVER_GET_LIST 1014
     72 #define TUNESERVER_GET_PARMS 1015
     73 #define TUNESERVER_SET_PARMS 1016
     74 #define TUNESERVER_MISC_CMDS 1021
     75 
     76 #define TUNE_PREV_GET_INFO        0x0001
     77 #define TUNE_PREV_CH_CNK_SIZE     0x0002
     78 #define TUNE_PREV_GET_PREV_FRAME  0x0003
     79 #define TUNE_PREV_GET_JPG_SNAP    0x0004
     80 #define TUNE_PREV_GET_RAW_SNAP    0x0005
     81 #define TUNE_PREV_GET_RAW_PREV    0x0006
     82 
     83 typedef struct {
     84   char data[128];
     85 } tuneserver_misc_cmd;
     86 
     87 typedef enum {
     88   TUNESERVER_RECV_COMMAND = 1,
     89   TUNESERVER_RECV_PAYLOAD_SIZE,
     90   TUNESERVER_RECV_PAYLOAD,
     91   TUNESERVER_RECV_RESPONSE,
     92   TUNESERVERER_RECV_INVALID,
     93 } tuneserver_recv_cmd_t;
     94 
     95 typedef struct {
     96   uint16_t          current_cmd;
     97   tuneserver_recv_cmd_t next_recv_code;
     98   uint32_t          next_recv_len;
     99   void              *recv_buf;
    100   uint32_t          recv_len;
    101   uint32_t          send_len;
    102   void              *send_buf;
    103 } tuneserver_protocol_t;
    104 
    105 typedef enum {
    106   TUNE_PREV_RECV_COMMAND = 1,
    107   TUNE_PREV_RECV_NEWCNKSIZE,
    108   TUNE_PREV_RECV_INVALID
    109 } tune_prev_cmd_t;
    110 
    111 typedef struct _eztune_preview_protocol_t {
    112   uint16_t         current_cmd;
    113   tune_prev_cmd_t  next_recv_code;
    114   uint32_t         next_recv_len;
    115   int32_t          send_len;
    116   char*            send_buf;
    117   uint32_t         send_buf_size;
    118   uint32_t         new_cnk_size;
    119   uint32_t         new_cmd_available;
    120 } prserver_protocol_t;
    121 
    122 
    123 int eztune_server_start(void *lib_handle);
    124 
    125 #endif /*__MM_QCAMERA_SOCKET_H__*/
    126