2 #include "BlueDriver_p.h"
\r
8 #define BLUE_HANC_INVALID_DID (0x0)
\r
10 #define BLUE_HANC_AUDIOGROUP1 (0x2FF)
\r
11 #define BLUE_HANC_AUDIOGROUP2 (0x1FD)
\r
12 #define BLUE_HANC_AUDIOGROUP3 (0x1FB)
\r
13 #define BLUE_HANC_AUDIOGROUP4 (0x2F9)
\r
14 #define BLUE_HANC_RP188 (0x260)
\r
15 #define BLUE_HANC_AUDIOGROUP1_CONTROL (0x1EF)
\r
16 #define BLUE_HANC_AUDIOGROUP2_CONTROL (0x2EE)
\r
17 #define BLUE_HANC_AUDIOGROUP3_CONTROL (0x2ED)
\r
18 #define BLUE_HANC_AUDIOGROUP4_CONTROL (0x1EC)
\r
19 #define BLUE_HANC_AUDIOGROUP1_EXTENDED (0x1FE)
\r
20 #define BLUE_HANC_AUDIOGROUP2_EXTENDED (0x2FC)
\r
21 #define BLUE_HANC_AUDIOGROUP3_EXTENDED (0x2FA)
\r
22 #define BLUE_HANC_AUDIOGROUP4_EXTENDED (0x1F8)
\r
25 #define HANC_PACKET_HEADER_CONST (0xBFFFFC00)
\r
27 #define BLUE_HANC_START_NEWLINE(line_number) ((0xC0000000)| (line_number << 16))
\r
29 #define BLUE_HANC_CONTROL_WORD (0xC0000000)
\r
30 #define BLUE_HANC_3DATA_PACKET_WORD (0x80000000)
\r
31 #define BLUE_HANC_2DATA_PACKET_WORD (0x40000000)
\r
32 #define BLUE_HANC_1DATA_PACKET_WORD (0x00000000)
\r
33 #define BLUE_HANC_ENDOF_FRAME() ((0xC0000000)| (1 << 15))
\r
36 #define AESAUDIO_DATA_BLOCKSIZE (192)
\r
37 #define MAX_HANC_BUFFER_SIZE (65536) //256*256
\r
38 #define MAX_HANC_BUFFER_SIZE_BYTES (256*1024)
\r
40 HANC Packet header structure
\r
41 Contains 2 type of structure ,
\r
42 which makes it easier to parse the data
\r
45 struct GenericV210_structure
\r
47 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
48 BLUE_UINT32 first_word:10,second_word:10,third_word:10,unused:2;
\r
50 BLUE_UINT32 unused:2,third_word:10,second_word:10,first_word:10;
\r
53 }__attribute__((packed));
\r
58 union GenericV210_union
\r
60 struct GenericV210_structure v210_struct;
\r
61 BLUE_UINT32 v210_word;
\r
64 /* HANC packet header*/
\r
65 struct HancPacketHeaderStruct
\r
67 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
68 union GenericV210_union ancillary_data_flag; // 0x0,0x3FF,0x3FF, This is a constant defined by smpte
\r
69 union GenericV210_union packet_info; // first 10 bit word --> Data ID
\r
70 // Commonly used Data ID packet values are
\r
71 // 1) 0x2FF --> Group1 Embedded Audio packet
\r
72 // 2) 0x1FD --> Group2 Embedded Audio Packet
\r
73 // 3) 0x1FB --> Group3 Embedded Audio Packet
\r
74 // 4) 0x2F9 --> Group4 Embedded Audio packet
\r
75 // second 10 bit word --> Data Block Number
\r
76 // This is used for type 1 packets.
\r
77 // third 10 bit word --> Data Count
\r
78 // This 10 bit word specifies the amount of user data
\r
79 // that this hanc will contain.
\r
81 union GenericV210_union packet_info;
\r
82 union GenericV210_union ancillary_data_flag;
\r
85 }__attribute__((packed));
\r
91 /* Audio SubFrame Packet */
\r
92 struct BlueAudioSubFrameStruct
\r
94 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
95 BLUE_UINT32 ZBit:1, //bit 0 set to declare start of channel status word
\r
96 Channel:2, //bit 1-2
\r
97 AudioData_0_5:6, //bit 3-8
\r
99 AudioData_6_14:9, //bit 10-18
\r
100 NotBit18:1, //bit 19 use same value as NotBit8 (bit 9)
\r
101 AudioData_15_19:5, //bit 20-24
\r
102 AESSampleValidityBit:1, //bit 25
\r
103 AESUserBit:1, //bit 26
\r
104 AESAudioChannelStatusBit:1, //bit 27 one bit of the channel status word
\r
105 ParityBit:1, //bit 28 xor of all bits except (NotBit8 (bit 9) and NotBit18 (bit 19))
\r
106 NotBit31:1, //bit 29 not of ParityBit (bit 28)
\r
107 akiraControlBits:2; //bit 30-31
\r
109 BLUE_UINT32 akiraControlBits:2,
\r
112 AESAudioChannelStatusBit:1,
\r
114 AESSampleValidityBit:1,
\r
125 }__attribute__((packed));
\r
130 union BlueAudioSubFrameHeader
\r
132 struct BlueAudioSubFrameStruct audioSubFrame;
\r
133 BLUE_UINT32 BlueAudioSubFrameWord;
\r
134 struct GenericV210_structure audioSubFrame_v210;
\r
137 #define MAX_AUDIO_SUBFRAMES_IN_A_LINE (64) // 4 samples per audio group and 4 channesl for each audio group per sample
\r
141 Time code structure that the function expects is the same format as LTC time code
\r
142 bits 0 - 3 :units of frame
\r
143 bits 4 - 7: binary group1
\r
144 bits 8 - 9: tens of frame
\r
145 bits 10 -11: flags
\r
146 bits 12 -15: binary group2
\r
147 bits 16-19 : units of seconds
\r
148 bits 20-23 : binary group3
\r
150 bits 24 - 26: tens of seconds
\r
152 bits 28 - 31: group binary4
\r
153 bits 32 -35: units of minutes
\r
155 bits 36 - 39 :binary5
\r
156 bits 40 - 42: tens of minutes
\r
158 bits 44 - 47: binary group6
\r
160 bits 48 - 51: units of hours
\r
161 bits 52 - 55: binary group7
\r
162 bits 56 - 57: tens of hours
\r
164 bits 60 - 63: binary8
\r
167 struct LTC_TimeCode
\r
169 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
170 BLUE_UINT64 unit_frame:4,binary1:4,ten_frame:2,drop_frame_flag:1,color_frame_flag:1,
\r
171 binary2:4,unit_second:4,binary3:4,ten_second:3,unsued_1:1,binary4:4,
\r
172 unit_minute:4,binary5:4,ten_minute:3,unsued_2:1,binary6:4,unit_hours:4,
\r
173 binary7:4,ten_hours:2,unsued_3:2,binary8:4;
\r
175 BLUE_UINT64 binary8:4,unsued_3:2,ten_hours:2,binary7:4,
\r
176 unit_hours:4,binary6:4,unused_2:1,ten_minute:3,binary5:4,unit_minute:4,
\r
177 binary4:4,unused_1:1,ten_second:3,binary3:4,unit_second:4,binary2:4,
\r
178 color_frame_flag:1,drop_frame_flag:1,ten_frame:2,binary1:4,unit_frame:4;
\r
182 }__attribute__((packed));
\r
187 struct LTC_TimeCode_union
\r
191 struct LTC_TimeCode struct_ltc;
\r
192 BLUE_UINT64 lt_64_value;
\r
197 This is used to unpack the timecode word properly and quickly
\r
198 in RP188 each 4 bits of the timecode is put into a 10 bit word.
\r
199 So this structure helps in decoding
\r
201 struct nibble_struct
\r
203 BLUE_UINT8 first_half:4,second_half:4;
\r
206 }__attribute__((packed));
\r
215 struct LTC_TimeCode struct_ltc;
\r
217 struct nibble_struct ltc_char[8];
\r
221 }__attribute__((packed));
\r
226 struct HANCTimeCodeStruct
\r
228 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
229 BLUE_UINT32 zero_0:3,
\r
244 akiraControlBits:2;
\r
246 BLUE_UINT32 akiraControlBits:2,
\r
265 }__attribute__((packed));
\r
272 struct HANCTimeCodeStruct hanc_struct;
\r
273 BLUE_UINT32 hanc_word;
\r
276 struct BAG2VancTimeCodeStruct
\r
278 #if defined(__LITTLE_ENDIAN__) || defined(_WINDOWS) || defined(BLUE_LINUX_CODE)
\r
279 BLUE_UINT16 zero_0:3,
\r
285 BLUE_UINT16 NotBit8_0:1,
\r
293 }__attribute__((packed));
\r
298 union BAG2VancTimeCode
\r
300 struct BAG2VancTimeCodeStruct vanc_struct;
\r
301 BLUE_UINT16 vanc_word;
\r
305 inline BLUE_UINT64 convert_countto_timecode(BLUE_UINT32 frame_count,BLUE_UINT32 framePerSec)
\r
307 unsigned int frames ,second,minutes ,hour ;
\r
308 struct TimeCode rp188_timcode;
\r
309 hour = frame_count/(60*60*framePerSec);
\r
310 minutes = frame_count%(60*60*framePerSec);
\r
311 second = minutes%(60*framePerSec);
\r
312 frames = second %framePerSec;
\r
313 second = second/(framePerSec);
\r
314 minutes=minutes/(60*framePerSec);
\r
315 rp188_timcode.ltc = 0;
\r
316 rp188_timcode.struct_ltc.unit_frame = (frames%10);
\r
317 rp188_timcode.struct_ltc.ten_frame = (frames/10);
\r
318 rp188_timcode.struct_ltc.unit_second = (second%10);
\r
319 rp188_timcode.struct_ltc.ten_second = (second/10);
\r
320 rp188_timcode.struct_ltc.unit_minute = (minutes%10);
\r
321 rp188_timcode.struct_ltc.ten_minute = (minutes/10);
\r
322 rp188_timcode.struct_ltc.unit_hours = (hour%10);
\r
323 rp188_timcode.struct_ltc.ten_hours = (hour/10);
\r
325 return rp188_timcode.ltc;
\r
329 inline BLUE_UINT64 convert_timecode_to_count(BLUE_UINT64 timecode,
\r
330 BLUE_UINT32 framePerSec,
\r
331 unsigned int & frames ,
\r
332 unsigned int & second,
\r
333 unsigned int & minutes ,
\r
334 unsigned int & hours)
\r
337 struct TimeCode rp188_timecode;
\r
338 rp188_timecode.ltc = timecode;
\r
339 hours = (BLUE_UINT32)((unsigned int)rp188_timecode.struct_ltc.ten_hours*10)+(unsigned int)rp188_timecode.struct_ltc.unit_hours;
\r
340 minutes = (BLUE_UINT32)((unsigned int)rp188_timecode.struct_ltc.ten_minute*10)+(unsigned int)rp188_timecode.struct_ltc.unit_minute;
\r
341 second = (BLUE_UINT32)((unsigned int)rp188_timecode.struct_ltc.ten_second*10)+(unsigned int)rp188_timecode.struct_ltc.unit_second;
\r
342 frames = (BLUE_UINT32)((unsigned int)rp188_timecode.struct_ltc.ten_frame*10)+(unsigned int)rp188_timecode.struct_ltc.unit_frame;
\r
343 return rp188_timecode.ltc;
\r
346 // Determine endianess at run-time
\r
347 inline BLUE_UINT32 Int32SwapBigLittle(const BLUE_UINT32 i)
\r
349 unsigned char c1, c2, c3, c4;
\r
350 const int endian = 1;
\r
351 #define is_bigendian() ( (*(char*) & endian) == 0 )
\r
353 if (is_bigendian())
\r
356 c2 = (i >> 8) & 255;
\r
357 c3 = (i >> 16) & 255;
\r
358 c4 = (i >> 24) & 255;
\r
360 return ((int)c1 << 24) + ((int)c2 << 16) + ((int)c3 << 8) + c4;
\r