frame_compress.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/core/frame_compress.c
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 #include "wmp_config.h"
00038 #include "config/compiler.h"
00039 
00040 #include "include/ml_com.h"
00041 #include "include/ll_com.h"
00042 
00043 char zFrame[2500];
00044 
00045 #ifdef WMP_USE_FRAME_COMPRESSION
00046 #include <zlib.h>
00047 
00048 long long max = 0;
00049 
00050 int cmp_send(char * f, int size){
00051         uLongf len = 2500;
00052         WMP_DBG(FRAME_COMPRESS,"sending %d bytes\n", size);
00053 
00054         unsigned long long ts1 = getRawActualTimeus();
00055         int ret = compress(zFrame,&len,f,size);
00056         unsigned long long ts2 = getRawActualTimeus();
00057         long long ts = ts2 - ts1;
00058         if (ts > max) max = ts;
00059         WMP_DBG(FRAME_COMPRESS,"cmp_time = %lld max:%lld \n",ts,max);
00060 
00061         if (ret != Z_OK){
00062                 WMP_DBG(FRAME_COMPRESS,"cmp err\n");
00063                 return -1;
00064         }
00065         WMP_DBG(FRAME_COMPRESS,"sending %d bytes (compressed) \n", len);
00066         return llpsend(zFrame,len,ZWMP_TYPE_FIELD);
00067 }
00068 
00069 rxInfo  cmp_receive(char * f,  int timeout){
00070         rxInfo rxi = llreceive(zFrame,timeout);
00071         if (rxi.proto == 0x6970){
00072                 WMP_DBG(FRAME_COMPRESS,"recvd %d bytes proto: %x\n", rxi.size, rxi.proto);
00073                 uLongf len = 2500;
00074                 unsigned long long ts1 = getRawActualTimeus();
00075                 int ret = uncompress(f,&len,zFrame,rxi.size);
00076                 unsigned long long ts2 = getRawActualTimeus();
00077                 long long ts = ts2 -ts1;
00078 
00079                 WMP_DBG(FRAME_COMPRESS,"decmp_time = %lld\n",ts);
00080 
00081                 if (ret != Z_OK){
00082                         WMP_DBG(FRAME_COMPRESS,"uncmp err\n");
00083                         rxi.error = 1;
00084                         return rxi;
00085                 }
00086                 rxi.size = len;
00087                 WMP_DBG(FRAME_COMPRESS,"returning %d bytes\n",len);
00088         }else{
00089                 memcpy(f,zFrame,rxi.size);
00090         }
00091         return rxi;
00092 }
00093 #else
00094 
00095 int cmp_send(char * f, int size){
00096         return llsend(f,size);
00097 }
00098 
00099 rxInfo cmp_receive(char * f,  int timeout){
00100         return llreceive(f,timeout);
00101 }
00102 
00103 #endif
00104 
00105 
00106 
00107 


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54