Merge pull request #26273 from 78andyp/blurayfixes2
[xbmc.git] / xbmc / cores / AudioEngine / Utils / AEPackIEC61937.h
blob7a6e72741c36b22c3972ca581055ce768215f2f0
1 /*
2 * Copyright (C) 2010-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include <list>
12 #include <stdint.h>
14 #define MAX_IEC61937_PACKET 61440
15 #define IEC61937_DATA_OFFSET 8
17 #define DTS1_FRAME_SIZE 512
18 #define DTS2_FRAME_SIZE 1024
19 #define DTS3_FRAME_SIZE 2048
20 #define AC3_FRAME_SIZE 1536
21 #define EAC3_FRAME_SIZE 6144
22 #define TRUEHD_FRAME_SIZE 15360
24 #define OUT_SAMPLESIZE 16
25 #define OUT_CHANNELS 2
26 #define OUT_FRAMESTOBYTES(a) ((a) * OUT_CHANNELS * (OUT_SAMPLESIZE>>3))
28 class CAEPackIEC61937
30 public:
31 CAEPackIEC61937() = default;
32 typedef int (*PackFunc)(uint8_t *data, unsigned int size, uint8_t *dest);
34 static int PackAC3 (uint8_t *data, unsigned int size, uint8_t *dest);
35 static int PackEAC3 (uint8_t *data, unsigned int size, uint8_t *dest);
36 static int PackDTS_512 (uint8_t *data, unsigned int size, uint8_t *dest, bool littleEndian);
37 static int PackDTS_1024(uint8_t *data, unsigned int size, uint8_t *dest, bool littleEndian);
38 static int PackDTS_2048(uint8_t *data, unsigned int size, uint8_t *dest, bool littleEndian);
39 static int PackTrueHD(const uint8_t* data, unsigned int size, uint8_t* dest);
40 static int PackDTSHD(uint8_t* data, unsigned int size, uint8_t* dest, unsigned int period);
41 static int PackPause(uint8_t *dest, unsigned int millis, unsigned int framesize, unsigned int samplerate, unsigned int rep_period, unsigned int encodedRate);
42 private:
44 static int PackDTS(uint8_t *data, unsigned int size, uint8_t *dest, bool littleEndian,
45 unsigned int frameSize, uint16_t type);
47 enum IEC61937DataType
49 IEC61937_TYPE_NULL = 0x00,
50 IEC61937_TYPE_AC3 = 0x01,
51 IEC61937_TYPE_DTS1 = 0x0B, /* 512 samples */
52 IEC61937_TYPE_DTS2 = 0x0C, /* 1024 samples */
53 IEC61937_TYPE_DTS3 = 0x0D, /* 2048 samples */
54 IEC61937_TYPE_DTSHD = 0x11,
55 IEC61937_TYPE_EAC3 = 0x15,
56 IEC61937_TYPE_TRUEHD = 0x16
59 #ifdef __GNUC__
60 struct __attribute__((__packed__)) IEC61937Packet
61 #else
62 __pragma(pack(push, 1))
63 struct IEC61937Packet
64 #endif
66 uint16_t m_preamble1;
67 uint16_t m_preamble2;
68 uint16_t m_type;
69 uint16_t m_length;
70 uint8_t m_data[MAX_IEC61937_PACKET - IEC61937_DATA_OFFSET];
72 #ifndef __GNUC__
73 __pragma(pack(pop))
74 #endif