Wasabi ExpressPlay SDK for Embedded Systems  1.10
Ts2BitUtils.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | MPEG2 Transport Stream - Bit Utils (adapted from Fluo and Bento4)
4 |
5 | $Id: Ts2BitUtils.h 296 2014-06-25 11:20:09Z jebaseelir $
6 | Original author: Gilles Boccon-Gibod
7 |
8 | This software is provided to you pursuant to your agreement
9 | with Intertrust Technologies Corporation ("Intertrust").
10 | This software may be used only in accordance with the terms
11 | of the agreement.
12 |
13 | Copyright (c) 2005-2014 by Intertrust. All rights reserved.
14 |
15 ****************************************************************/
16 
17 #ifndef _TS2_BIT_UTILS_H_
18 #define _TS2_BIT_UTILS_H_
19 
20 /*----------------------------------------------------------------------
21 | includes
22 +---------------------------------------------------------------------*/
23 #include "Atomix.h"
24 
25 /*----------------------------------------------------------------------
26 | types helpers
27 +---------------------------------------------------------------------*/
28 /* use long by default */
29 typedef ATX_UInt32 TS2_BitsWord;
30 #define TS2_WORD_BITS 32
31 #define TS2_WORD_BYTES 4
32 
33 /*----------------------------------------------------------------------
34 | types
35 +---------------------------------------------------------------------*/
36 typedef struct {
37  const ATX_Byte* data;
38  ATX_Size data_size;
39  ATX_UInt32 pos;
41  ATX_UInt8 bits_cached;
43 
44 typedef struct {
45  ATX_Byte* data;
46  ATX_Size data_size;
47  ATX_UInt64 bit_count;
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif /* __cplusplus */
53 
54 /*----------------------------------------------------------------------
55 | TS2_BitStream functions
56 +---------------------------------------------------------------------*/
57 ATX_Result TS2_BitStream_SetData(TS2_BitStream* bits,
58  const ATX_Byte* data,
59  ATX_Size data_size);
60 
61 ATX_Result TS2_BitStream_Reset(TS2_BitStream* bits);
62 
64 
65 ATX_Result TS2_BitStream_Rewind(TS2_BitStream* bits, ATX_UInt32 n);
66 
67 ATX_UInt32 TS2_BitStream_ReadBits(TS2_BitStream* bits, ATX_UInt32 n);
68 
69 ATX_UInt32 TS2_BitStream_ReadBit(TS2_BitStream* bits);
70 
71 ATX_UInt64 TS2_BitStream_Read64(TS2_BitStream* bits, ATX_UInt32 n);
72 
73 ATX_Result TS2_BitStream_ReadTimecode(TS2_BitStream* bits, ATX_UInt64* timecode);
74 
75 ATX_UInt32 TS2_BitStream_PeekBits(const TS2_BitStream* bits, ATX_UInt32 n);
76 
77 ATX_UInt32 TS2_BitStream_PeekBit(const TS2_BitStream* bits);
78 
79 void TS2_BitStream_SkipBits(TS2_BitStream* bits, ATX_UInt32 n);
80 
82 
83 /*----------------------------------------------------------------------
84 | TS2_BitWriter functions
85 +---------------------------------------------------------------------*/
87 ATX_Result TS2_BitWriter_SetData(TS2_BitWriter* writer,
88  ATX_Byte* data,
89  ATX_Size data_size);
90 
91 ATX_Result TS2_BitWriter_Write(TS2_BitWriter* writer,
92  ATX_UInt32 bits,
93  ATX_UInt32 bit_count);
94 
96  ATX_Byte* data,
97  ATX_Size data_size);
98 
99 #define TS2_BitWriter_IsByteAligned(writer) ((writer)->bit_count%8 == 0)
100 
101 #define TS2_BitWriter_ByteCount(writer) ((ATX_UInt32)((writer)->bit_count / 8))
102 
103 #ifdef __cplusplus
104 }
105 #endif /* __cplusplus */
106 
107 
108 #endif /* _TS2_BIT_UTILS_H_ */