Create Project for repo.or.cz
[vp.git] / src / ludp / common.h
blob281cde382a89bbf90c05ee7e0d7b62d377979789
1 /*******************************************************************************
2 * File : ludp.h
3 *
4 * Author : Henry He
5 * Created : 2009-10-7 8:51:58
6 * Description :
7 ******************************************************************************/
9 #ifndef __LUDP_INC_20091007_085158_HENRY__
10 #define __LUDP_INC_20091007_085158_HENRY__
13 /*******************************************************************************
14 * Desc : Macro Definations
15 ******************************************************************************/
17 ////////////////////////////////////////////////////////////////////////////////
18 // Slice Type
20 #define LUDP_SLICE_BASE_TYPE_VIDEO 0x12
21 #define LUDP_SLICE_BASE_TYPE_AUDIO 0x13
23 #define LUDP_SLICE_SUB_TYPE_DATA 0x12
24 #define LUDP_SLICE_SUB_TYPE_RESEND 0x13
26 #define LUDP_SLICE_TYPE(base_type, sub_type) \
27 ( ( (UINT16)(base_type) << 8 ) | ( (UINT8)(sub_type) ) )
29 #define LUDP_SLICE_BASE_TYPE(type) \
30 ( (UINT16)(type) >> 8 )
32 #define LUDP_SLICE_SUB_TYPE(type) \
33 ( (UINT8)(type) )
36 #define LUDP_SLICE_TYPE_VIDEO_DATA LUDP_SLICE_TYPE (LUDP_SLICE_BASE_TYPE_VIDEO, LUDP_SLICE_SUB_TYPE_DATA)
37 #define LUDP_SLICE_TYPE_VIDEO_RESEND LUDP_SLICE_TYPE (LUDP_SLICE_BASE_TYPE_VIDEO, LUDP_SLICE_SUB_TYPE_RESEND)
38 #define LUDP_SLICE_TYPE_AUDIO_DATA LUDP_SLICE_TYPE (LUDP_SLICE_BASE_TYPE_AUDIO, LUDP_SLICE_SUB_TYPE_DATA)
39 #define LUDP_SLICE_TYPE_AUDIO_RESEND LUDP_SLICE_TYPE (LUDP_SLICE_BASE_TYPE_AUDIO, LUDP_SLICE_SUB_TYPE_RESEND)
42 /*******************************************************************************
43 * Desc : Type Definations
44 ******************************************************************************/
46 ////////////////////////////////////////////////////////////////////////////////
47 // Structure of Slice
49 typedef struct tagSlice
52 UINT16 usType; // Type of this Slice
53 UINT16 usDataLen; // Length of acData
54 UINT16 usSliceNum; // Number of Slices in Package
55 UINT16 usSliceSN; // Serial Number of Slice in Package
56 UINT32 unTimestamp; // Timestamp of this Slice
58 UINT8 aucData [4]; // Data of Current Slice
60 } Slice;
63 #define HLH_SLICE_LENGTH(pzsSlice) \
64 ( sizeof (Slice) - 4 + (pzsSlice)->usDataLen )
68 /******************************************************************************
69 * Func : CloneSlice
70 * Desc : Clone slice and return a new cloned slice
71 * Args : pzsSlice slice to clone
72 * Outs : if success, return a new cloned slice, otherwise return NULL
73 ******************************************************************************/
74 static inline Slice * CloneSlice (const Slice *pzsSlice)
77 Slice *pzsSliceNew;
78 UINT32 unSliceLen;
80 // Check arguments
81 if (pzsSlice == NULL) {
82 goto failed;
85 unSliceLen = HLH_SLICE_LENGTH (pzsSlice);
87 // Allocate memory
88 pzsSliceNew = (Slice *) malloc ( unSliceLen );
89 if (pzsSliceNew == NULL) {
90 goto failed;
93 // Copy data
94 memcpy (pzsSliceNew, pzsSlice, unSliceLen);
96 return pzsSliceNew;
98 failed:
99 return NULL;
106 /*******************************************************************************
107 * Desc : Includes Files
108 ******************************************************************************/
110 #include "ludp/LudpReceiver.h"
111 #include "ludp/LudpSender.h"
115 #endif /* __LUDP_INC_20091007_085158_HENRY__ */