1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/lib3gp/impl/src/endian.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,159 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <3gplibrary/mp4config.h>
1.20 +
1.21 +/*
1.22 + * Function:
1.23 + *
1.24 + * mp4_u16 u16endian(mp4_u16 u)
1.25 + *
1.26 + * Description:
1.27 + *
1.28 + * This function converts the input parameter u between network byte
1.29 + * order (big endian) and current computer byte order.
1.30 + *
1.31 + * Note: Intel based Windows system is little endian.
1.32 + * ARM based Symbian OS is little endian.
1.33 + *
1.34 + * Parameters:
1.35 + *
1.36 + * u Input value
1.37 + *
1.38 + * Return value:
1.39 + *
1.40 + * Converted value
1.41 + *
1.42 + */
1.43 +mp4_u16 u16endian(mp4_u16 u)
1.44 +{
1.45 + mp4_u16 result;
1.46 +
1.47 + ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[1];
1.48 + ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[0];
1.49 +
1.50 + return result;
1.51 +}
1.52 +
1.53 +
1.54 +/*
1.55 + * Function:
1.56 + *
1.57 + * mp4_u32 u32endian(mp4_u32 u)
1.58 + *
1.59 + * Description:
1.60 + *
1.61 + * This function converts the input parameter u between network byte
1.62 + * order (big endian) and current computer byte order.
1.63 + *
1.64 + * Note: Intel based Windows system is little endian.
1.65 + * ARM based Symbian OS is little endian.
1.66 + *
1.67 + * Parameters:
1.68 + *
1.69 + * u Input value
1.70 + *
1.71 + * Return value:
1.72 + *
1.73 + * Converted value
1.74 + *
1.75 + */
1.76 +mp4_u32 u32endian(mp4_u32 u)
1.77 +{
1.78 + mp4_u32 result;
1.79 +
1.80 + ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[3];
1.81 + ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[2];
1.82 + ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&u)[1];
1.83 + ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&u)[0];
1.84 +
1.85 + return result;
1.86 +}
1.87 +
1.88 +
1.89 +/*
1.90 + * Function:
1.91 + *
1.92 + * mp4_i32 i32endian(mp4_i32 i)
1.93 + *
1.94 + * Description:
1.95 + *
1.96 + * This function converts the input parameter i between network byte
1.97 + * order (big endian) and current computer byte order.
1.98 + *
1.99 + * Note: Intel based Windows system is little endian.
1.100 + * ARM based Symbian OS is little endian.
1.101 + *
1.102 + * Parameters:
1.103 + *
1.104 + * i Input value
1.105 + *
1.106 + * Return value:
1.107 + *
1.108 + * Converted value
1.109 + *
1.110 + */
1.111 +mp4_i32 i32endian(mp4_i32 i)
1.112 +{
1.113 + mp4_i32 result;
1.114 +
1.115 + ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&i)[3];
1.116 + ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&i)[2];
1.117 + ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&i)[1];
1.118 + ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&i)[0];
1.119 +
1.120 + return result;
1.121 +}
1.122 +
1.123 +
1.124 +/*
1.125 + * Function:
1.126 + *
1.127 + * mp4_u64 u64endian(mp4_u64 u)
1.128 + *
1.129 + * Description:
1.130 + *
1.131 + * This function converts the input parameter u between network byte
1.132 + * order (big endian) and current computer byte order.
1.133 + *
1.134 + * Note: Intel based Windows system is little endian.
1.135 + * ARM based Symbian OS is little endian.
1.136 + *
1.137 + * Parameters:
1.138 + *
1.139 + * u Input value
1.140 + *
1.141 + * Return value:
1.142 + *
1.143 + * Converted value
1.144 + *
1.145 + */
1.146 +mp4_u64 u64endian(mp4_u64 u)
1.147 +{
1.148 + mp4_u64 result;
1.149 +
1.150 + ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[7];
1.151 + ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[6];
1.152 + ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&u)[5];
1.153 + ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&u)[4];
1.154 + ((mp4_u8 *)&result)[4] = ((mp4_u8 *)&u)[3];
1.155 + ((mp4_u8 *)&result)[5] = ((mp4_u8 *)&u)[2];
1.156 + ((mp4_u8 *)&result)[6] = ((mp4_u8 *)&u)[1];
1.157 + ((mp4_u8 *)&result)[7] = ((mp4_u8 *)&u)[0];
1.158 +
1.159 + return result;
1.160 +}
1.161 +
1.162 +// End of File