| 1 |
/* |
| 2 |
* Copyright (C) 2013-2021 Jean-Luc Barrière |
| 3 |
* Copyright (C) 2005-2014 Team Kodi (https://kodi.tv) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef BITSTREAM_H |
| 10 |
#define BITSTREAM_H |
| 11 |
|
| 12 |
#include <inttypes.h> |
| 13 |
#include <stddef.h> |
| 14 |
|
| 15 |
namespace TSDemux |
| 16 |
{ |
| 17 |
class CBitstream |
| 18 |
{ |
| 19 |
private: |
| 20 |
uint8_t *m_data; |
| 21 |
size_t m_offset; |
| 22 |
const size_t m_len; |
| 23 |
bool m_error; |
| 24 |
const bool m_doEP3; |
| 25 |
|
| 26 |
public: |
| 27 |
CBitstream(uint8_t *data, size_t bits) |
| 28 |
: m_data(data) |
| 29 |
, m_offset(0) |
| 30 |
, m_len(bits) |
| 31 |
, m_error(false) |
| 32 |
, m_doEP3(false) |
| 33 |
{} |
| 34 |
|
| 35 |
// this is a bitstream that has embedded emulation_prevention_three_byte |
| 36 |
// sequences that need to be removed as used in HECV. |
| 37 |
// Data must start at byte 2 |
| 38 |
CBitstream(uint8_t *data, size_t bits, bool doEP3) |
| 39 |
: m_data(data) |
| 40 |
, m_offset(16) // skip header and use as sentinel for EP3 detection |
| 41 |
, m_len(bits) |
| 42 |
, m_error(false) |
| 43 |
, m_doEP3(true) |
| 44 |
{} |
| 45 |
|
| 46 |
void skipBits(unsigned int num); |
| 47 |
unsigned int readBits(int num); |
| 48 |
unsigned int showBits(int num); |
| 49 |
unsigned int readBits1() { return readBits(1); } |
| 50 |
unsigned int readGolombUE(int maxbits = 32); |
| 51 |
signed int readGolombSE(); |
| 52 |
size_t length() { return m_len; } |
| 53 |
bool isError() { return m_error; } |
| 54 |
}; |
| 55 |
} |
| 56 |
|
| 57 |
#endif /* BITSTREAM_H */ |