wireshark/wsutil/pint.h
Jiri Novak 9090afbfe9 Save RTP audio to file: RTP Stream Analysis dialog allows save audio for non G.711 codecs and mixed codecs
- spaghetti code for save was split into separate functions
- code saves G.711 only, all other codecs are saved as silence with correct duration
  - code is ready to include other codecs
  - code supports 8000 Hz sampling rate only, other rates are rejected with warning
  - bidirectional stream (forward and reverse) creates stereo .au file
- output is based on timestamps in RTP streams
  - save operation is slower than before because it is set of seek() - one per each codec sample
- code allows align of save audio:
  - as it is - each stream is saved from its beginning, no aling
  - to start of each other - later stream is prepended with silence
  - align saved audio to beginning of capture file - each stream is prepended with silence
- save to raw works correctly now - only payload is saved
  - old code was inserting G.711 silence time to time to raw data

Bug: 13242
Change-Id: I74d02a1cc1c75acf9ffe930d078c00a0555cbfb6
Reviewed-on: https://code.wireshark.org/review/19245
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-12-15 05:16:29 +00:00

144 lines
6.2 KiB
C

/* pint.h
* Definitions for extracting and translating integers safely and portably
* via pointers.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __PINT_H__
#define __PINT_H__
#include <glib.h>
/* Pointer versions of g_ntohs and g_ntohl. Given a pointer to a member of a
* byte array, returns the value of the two or four bytes at the pointer.
* The pletohXX versions return the little-endian representation.
*/
#define pntoh16(p) ((guint16) \
((guint16)*((const guint8 *)(p)+0)<<8| \
(guint16)*((const guint8 *)(p)+1)<<0))
#define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
(guint32)*((const guint8 *)(p)+1)<<8| \
(guint32)*((const guint8 *)(p)+2)<<0)
#define pntoh32(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
(guint32)*((const guint8 *)(p)+1)<<16| \
(guint32)*((const guint8 *)(p)+2)<<8| \
(guint32)*((const guint8 *)(p)+3)<<0)
#define pntoh40(p) ((guint64)*((const guint8 *)(p)+0)<<32| \
(guint64)*((const guint8 *)(p)+1)<<24| \
(guint64)*((const guint8 *)(p)+2)<<16| \
(guint64)*((const guint8 *)(p)+3)<<8| \
(guint64)*((const guint8 *)(p)+4)<<0)
#define pntoh48(p) ((guint64)*((const guint8 *)(p)+0)<<40| \
(guint64)*((const guint8 *)(p)+1)<<32| \
(guint64)*((const guint8 *)(p)+2)<<24| \
(guint64)*((const guint8 *)(p)+3)<<16| \
(guint64)*((const guint8 *)(p)+4)<<8| \
(guint64)*((const guint8 *)(p)+5)<<0)
#define pntoh56(p) ((guint64)*((const guint8 *)(p)+0)<<48| \
(guint64)*((const guint8 *)(p)+1)<<40| \
(guint64)*((const guint8 *)(p)+2)<<32| \
(guint64)*((const guint8 *)(p)+3)<<24| \
(guint64)*((const guint8 *)(p)+4)<<16| \
(guint64)*((const guint8 *)(p)+5)<<8| \
(guint64)*((const guint8 *)(p)+6)<<0)
#define pntoh64(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
(guint64)*((const guint8 *)(p)+1)<<48| \
(guint64)*((const guint8 *)(p)+2)<<40| \
(guint64)*((const guint8 *)(p)+3)<<32| \
(guint64)*((const guint8 *)(p)+4)<<24| \
(guint64)*((const guint8 *)(p)+5)<<16| \
(guint64)*((const guint8 *)(p)+6)<<8| \
(guint64)*((const guint8 *)(p)+7)<<0)
#define pletoh16(p) ((guint16) \
((guint16)*((const guint8 *)(p)+1)<<8| \
(guint16)*((const guint8 *)(p)+0)<<0))
#define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
(guint32)*((const guint8 *)(p)+1)<<8| \
(guint32)*((const guint8 *)(p)+0)<<0)
#define pletoh32(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
(guint32)*((const guint8 *)(p)+2)<<16| \
(guint32)*((const guint8 *)(p)+1)<<8| \
(guint32)*((const guint8 *)(p)+0)<<0)
#define pletoh40(p) ((guint64)*((const guint8 *)(p)+4)<<32| \
(guint64)*((const guint8 *)(p)+3)<<24| \
(guint64)*((const guint8 *)(p)+2)<<16| \
(guint64)*((const guint8 *)(p)+1)<<8| \
(guint64)*((const guint8 *)(p)+0)<<0)
#define pletoh48(p) ((guint64)*((const guint8 *)(p)+5)<<40| \
(guint64)*((const guint8 *)(p)+4)<<32| \
(guint64)*((const guint8 *)(p)+3)<<24| \
(guint64)*((const guint8 *)(p)+2)<<16| \
(guint64)*((const guint8 *)(p)+1)<<8| \
(guint64)*((const guint8 *)(p)+0)<<0)
#define pletoh56(p) ((guint64)*((const guint8 *)(p)+6)<<48| \
(guint64)*((const guint8 *)(p)+5)<<40| \
(guint64)*((const guint8 *)(p)+4)<<32| \
(guint64)*((const guint8 *)(p)+3)<<24| \
(guint64)*((const guint8 *)(p)+2)<<16| \
(guint64)*((const guint8 *)(p)+1)<<8| \
(guint64)*((const guint8 *)(p)+0)<<0)
#define pletoh64(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
(guint64)*((const guint8 *)(p)+6)<<48| \
(guint64)*((const guint8 *)(p)+5)<<40| \
(guint64)*((const guint8 *)(p)+4)<<32| \
(guint64)*((const guint8 *)(p)+3)<<24| \
(guint64)*((const guint8 *)(p)+2)<<16| \
(guint64)*((const guint8 *)(p)+1)<<8| \
(guint64)*((const guint8 *)(p)+0)<<0)
/* Pointer routines to put items out in a particular byte order.
* These will work regardless of the byte alignment of the pointer.
*/
#define phton16(p, v) \
{ \
((guint8*)(p))[0] = (guint8)((v) >> 8); \
((guint8*)(p))[1] = (guint8)((v) >> 0); \
}
#define phton32(p, v) \
{ \
((guint8*)(p))[0] = (guint8)((v) >> 24); \
((guint8*)(p))[1] = (guint8)((v) >> 16); \
((guint8*)(p))[2] = (guint8)((v) >> 8); \
((guint8*)(p))[3] = (guint8)((v) >> 0); \
}
/* Subtract two guint32s with respect to wraparound */
#define guint32_wraparound_diff(higher, lower) ((higher>lower)?(higher-lower):(higher+0xffffffff-lower+1))
#endif /* PINT_H */