mmplugins/lib3gp/impl/src/endian.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <3gplibrary/mp4config.h>
       
    17 
       
    18 /*
       
    19  * Function:
       
    20  *
       
    21  *   mp4_u16 u16endian(mp4_u16 u)
       
    22  *
       
    23  * Description:
       
    24  *
       
    25  *   This function converts the input parameter u between network byte
       
    26  *   order (big endian) and current computer byte order.
       
    27  *
       
    28  *   Note: Intel based Windows system is little endian.
       
    29  *         ARM based Symbian OS is little endian.
       
    30  *
       
    31  * Parameters:
       
    32  *
       
    33  *   u     Input value
       
    34  *
       
    35  * Return value:
       
    36  *
       
    37  *   Converted value
       
    38  *
       
    39  */
       
    40 mp4_u16 u16endian(mp4_u16 u)
       
    41 {
       
    42   mp4_u16 result;
       
    43 
       
    44   ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[1];
       
    45   ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[0];
       
    46 
       
    47   return result;
       
    48 }
       
    49 
       
    50 
       
    51 /*
       
    52  * Function:
       
    53  *
       
    54  *   mp4_u32 u32endian(mp4_u32 u)
       
    55  *
       
    56  * Description:
       
    57  *
       
    58  *   This function converts the input parameter u between network byte
       
    59  *   order (big endian) and current computer byte order.
       
    60  *
       
    61  *   Note: Intel based Windows system is little endian.
       
    62  *         ARM based Symbian OS is little endian.
       
    63  *
       
    64  * Parameters:
       
    65  *
       
    66  *   u     Input value
       
    67  *
       
    68  * Return value:
       
    69  *
       
    70  *   Converted value
       
    71  *
       
    72  */
       
    73 mp4_u32 u32endian(mp4_u32 u)
       
    74 {
       
    75   mp4_u32 result;
       
    76 
       
    77   ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[3];
       
    78   ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[2];
       
    79   ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&u)[1];
       
    80   ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&u)[0];
       
    81 
       
    82   return result;
       
    83 }
       
    84 
       
    85 
       
    86 /*
       
    87  * Function:
       
    88  *
       
    89  *   mp4_i32 i32endian(mp4_i32 i)
       
    90  *
       
    91  * Description:
       
    92  *
       
    93  *   This function converts the input parameter i between network byte
       
    94  *   order (big endian) and current computer byte order.
       
    95  *
       
    96  *   Note: Intel based Windows system is little endian.
       
    97  *         ARM based Symbian OS is little endian.
       
    98  *
       
    99  * Parameters:
       
   100  *
       
   101  *   i     Input value
       
   102  *
       
   103  * Return value:
       
   104  *
       
   105  *   Converted value
       
   106  *
       
   107  */
       
   108 mp4_i32 i32endian(mp4_i32 i)
       
   109 {
       
   110   mp4_i32 result;
       
   111 
       
   112   ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&i)[3];
       
   113   ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&i)[2];
       
   114   ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&i)[1];
       
   115   ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&i)[0];
       
   116 
       
   117   return result;
       
   118 }
       
   119 
       
   120 
       
   121 /*
       
   122  * Function:
       
   123  *
       
   124  *   mp4_u64 u64endian(mp4_u64 u)
       
   125  *
       
   126  * Description:
       
   127  *
       
   128  *   This function converts the input parameter u between network byte
       
   129  *   order (big endian) and current computer byte order.
       
   130  *
       
   131  *   Note: Intel based Windows system is little endian.
       
   132  *         ARM based Symbian OS is little endian.
       
   133  *
       
   134  * Parameters:
       
   135  *
       
   136  *   u     Input value
       
   137  *
       
   138  * Return value:
       
   139  *
       
   140  *   Converted value
       
   141  *
       
   142  */
       
   143 mp4_u64 u64endian(mp4_u64 u)
       
   144 {
       
   145   mp4_u64 result;
       
   146 
       
   147   ((mp4_u8 *)&result)[0] = ((mp4_u8 *)&u)[7];
       
   148   ((mp4_u8 *)&result)[1] = ((mp4_u8 *)&u)[6];
       
   149   ((mp4_u8 *)&result)[2] = ((mp4_u8 *)&u)[5];
       
   150   ((mp4_u8 *)&result)[3] = ((mp4_u8 *)&u)[4];
       
   151   ((mp4_u8 *)&result)[4] = ((mp4_u8 *)&u)[3];
       
   152   ((mp4_u8 *)&result)[5] = ((mp4_u8 *)&u)[2];
       
   153   ((mp4_u8 *)&result)[6] = ((mp4_u8 *)&u)[1];
       
   154   ((mp4_u8 *)&result)[7] = ((mp4_u8 *)&u)[0];
       
   155 
       
   156   return result;
       
   157 }
       
   158 
       
   159 // End of File