1e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent/*
2e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *
4e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  Use of this source code is governed by a BSD-style license
5e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  that can be found in the LICENSE file in the root of the source
6e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  tree. An additional intellectual property rights grant can be found
7e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  in the file PATENTS.  All contributing project authors may
8e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  be found in the AUTHORS file in the root of the source tree.
9e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent */
10e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
11c55a96383497a772a307b346368133960b02ad03Eric Laurent// This file contains platform-specific typedefs and defines.
12c55a96383497a772a307b346368133960b02ad03Eric Laurent
13c55a96383497a772a307b346368133960b02ad03Eric Laurent#ifndef WEBRTC_TYPEDEFS_H_
14c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_TYPEDEFS_H_
15e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
16c55a96383497a772a307b346368133960b02ad03Eric Laurent// Reserved words definitions
17c55a96383497a772a307b346368133960b02ad03Eric Laurent// TODO(andrew): Look at removing these.
18e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_EXTERN extern
19e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define G_CONST const
20e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_INLINE extern __inline
21e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
22c55a96383497a772a307b346368133960b02ad03Eric Laurent// Define WebRTC preprocessor identifiers based on the current build platform.
23c55a96383497a772a307b346368133960b02ad03Eric Laurent// TODO(andrew): Clean these up. We can probably remove everything in this
24c55a96383497a772a307b346368133960b02ad03Eric Laurent// block.
25c55a96383497a772a307b346368133960b02ad03Eric Laurent//   - TARGET_MAC_INTEL and TARGET_MAC aren't used anywhere.
26c55a96383497a772a307b346368133960b02ad03Eric Laurent//   - In the few places where TARGET_PC is used, it should be replaced by
27c55a96383497a772a307b346368133960b02ad03Eric Laurent//     something more specific.
28c55a96383497a772a307b346368133960b02ad03Eric Laurent//   - Do we really support PowerPC? Probably not. Remove WEBRTC_MAC_INTEL
29c55a96383497a772a307b346368133960b02ad03Eric Laurent//     from build/common.gypi as well.
30e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#if defined(WIN32)
31c55a96383497a772a307b346368133960b02ad03Eric Laurent    // Windows & Windows Mobile.
32e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #if !defined(WEBRTC_TARGET_PC)
33e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent        #define WEBRTC_TARGET_PC
34e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #endif
35e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#elif defined(__APPLE__)
36c55a96383497a772a307b346368133960b02ad03Eric Laurent    // Mac OS X.
37c55a96383497a772a307b346368133960b02ad03Eric Laurent    #if defined(__LITTLE_ENDIAN__ )
38e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent        #if !defined(WEBRTC_TARGET_MAC_INTEL)
39e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent            #define WEBRTC_TARGET_MAC_INTEL
40c55a96383497a772a307b346368133960b02ad03Eric Laurent        #endif
41e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #else
42e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent        #if !defined(WEBRTC_TARGET_MAC)
43e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent            #define WEBRTC_TARGET_MAC
44c55a96383497a772a307b346368133960b02ad03Eric Laurent        #endif
45e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #endif
46e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#else
47e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Linux etc.
48e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #if !defined(WEBRTC_TARGET_PC)
49e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent        #define WEBRTC_TARGET_PC
50e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #endif
51e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif
52e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
53c55a96383497a772a307b346368133960b02ad03Eric Laurent// Derived from Chromium's build/build_config.h
54c55a96383497a772a307b346368133960b02ad03Eric Laurent// Processor architecture detection.  For more info on what's defined, see:
55c55a96383497a772a307b346368133960b02ad03Eric Laurent//   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
56c55a96383497a772a307b346368133960b02ad03Eric Laurent//   http://www.agner.org/optimize/calling_conventions.pdf
57c55a96383497a772a307b346368133960b02ad03Eric Laurent//   or with gcc, run: "echo | gcc -E -dM -"
58c55a96383497a772a307b346368133960b02ad03Eric Laurent// TODO(andrew): replace WEBRTC_LITTLE_ENDIAN with WEBRTC_ARCH_LITTLE_ENDIAN?
59c55a96383497a772a307b346368133960b02ad03Eric Laurent#if defined(_M_X64) || defined(__x86_64__)
60c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_X86_FAMILY
61c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_X86_64
62c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_64_BITS
63c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_LITTLE_ENDIAN
64c55a96383497a772a307b346368133960b02ad03Eric Laurent#elif defined(_M_IX86) || defined(__i386__)
65c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_X86_FAMILY
66c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_X86
67c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_32_BITS
68c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_LITTLE_ENDIAN
69c55a96383497a772a307b346368133960b02ad03Eric Laurent#elif defined(__ARMEL__)
70c55a96383497a772a307b346368133960b02ad03Eric Laurent// TODO(andrew): We'd prefer to control platform defines here, but this is
71c55a96383497a772a307b346368133960b02ad03Eric Laurent// currently provided by the Android makefiles. Commented to avoid duplicate
72c55a96383497a772a307b346368133960b02ad03Eric Laurent// definition warnings.
73c55a96383497a772a307b346368133960b02ad03Eric Laurent//#define WEBRTC_ARCH_ARM
74c55a96383497a772a307b346368133960b02ad03Eric Laurent// TODO(andrew): Chromium uses the following two defines. Should we switch?
75c55a96383497a772a307b346368133960b02ad03Eric Laurent//#define WEBRTC_ARCH_ARM_FAMILY
76c55a96383497a772a307b346368133960b02ad03Eric Laurent//#define WEBRTC_ARCH_ARMEL
77c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_32_BITS
78c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_ARCH_LITTLE_ENDIAN
79504679fd9254fe78e5d5264c8d28367cf558e942Craig Barber#elif defined(__aarch64__)
80504679fd9254fe78e5d5264c8d28367cf558e942Craig Barber#define WEBRTC_ARCH_64_BITS
81504679fd9254fe78e5d5264c8d28367cf558e942Craig Barber#define WEBRTC_ARCH_LITTLE_ENDIAN
82f636b09e392c2d336df73a12ae55ed8950526643Raghu Gandham#elif defined(__mips__)
83f636b09e392c2d336df73a12ae55ed8950526643Raghu Gandham#define WEBRTC_ARCH_32_BITS
84f636b09e392c2d336df73a12ae55ed8950526643Raghu Gandham#define WEBRTC_ARCH_LITTLE_ENDIAN
85c55a96383497a772a307b346368133960b02ad03Eric Laurent#else
86c55a96383497a772a307b346368133960b02ad03Eric Laurent#error Please add support for your architecture in typedefs.h
87c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif
88c55a96383497a772a307b346368133960b02ad03Eric Laurent
89c55a96383497a772a307b346368133960b02ad03Eric Laurent#if defined(__SSE2__) || defined(_MSC_VER)
90c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_USE_SSE2
91c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif
92c55a96383497a772a307b346368133960b02ad03Eric Laurent
93e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#if defined(WEBRTC_TARGET_PC)
94e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
95e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#if !defined(_MSC_VER)
96e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent  #include <stdint.h>
97e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#else
98e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Define C99 equivalent types.
99e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Since MSVC doesn't include these headers, we have to write our own
100e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // version to provide a compatibility layer between MSVC and the WebRTC
101e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // headers.
102e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef signed char         int8_t;
103e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef signed short        int16_t;
104e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef signed int          int32_t;
105e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef signed long long    int64_t;
106e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef unsigned char       uint8_t;
107e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef unsigned short      uint16_t;
108e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef unsigned int        uint32_t;
109e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef unsigned long long  uint64_t;
110e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif
111e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
112e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#if defined(WIN32)
113e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef __int64             WebRtc_Word64;
114e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef unsigned __int64    WebRtc_UWord64;
115e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#else
116e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int64_t             WebRtc_Word64;
117e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint64_t            WebRtc_UWord64;
118e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif
119e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int32_t             WebRtc_Word32;
120e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint32_t            WebRtc_UWord32;
121e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int16_t             WebRtc_Word16;
122e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint16_t            WebRtc_UWord16;
123e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef char                WebRtc_Word8;
124e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint8_t             WebRtc_UWord8;
125e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
126c55a96383497a772a307b346368133960b02ad03Eric Laurent    // Define endian for the platform
127e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #define WEBRTC_LITTLE_ENDIAN
128e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
129e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#elif defined(WEBRTC_TARGET_MAC_INTEL)
130e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #include <stdint.h>
131e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
132e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int64_t             WebRtc_Word64;
133e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint64_t            WebRtc_UWord64;
134e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int32_t             WebRtc_Word32;
135e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint32_t            WebRtc_UWord32;
136e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef int16_t             WebRtc_Word16;
137e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef char                WebRtc_Word8;
138e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint16_t            WebRtc_UWord16;
139e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    typedef uint8_t             WebRtc_UWord8;
140e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
141c55a96383497a772a307b346368133960b02ad03Eric Laurent    // Define endian for the platform
142e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    #define WEBRTC_LITTLE_ENDIAN
143e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
144e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#else
145c55a96383497a772a307b346368133960b02ad03Eric Laurent    #error "No platform defined for WebRTC type definitions (typedefs.h)"
146e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif
147e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
148c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif  // WEBRTC_TYPEDEFS_H_
149