-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathADTSReader.h
More file actions
125 lines (104 loc) · 3.31 KB
/
ADTSReader.h
File metadata and controls
125 lines (104 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (C) 2017 peak3d (http://www.peak3d.de)
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include <stdint.h>
#include <bento4/Ap4Types.h>
#include <bento4/Ap4DataBuffer.h>
#include <kodi/addon-instance/Inputstream.h>
// Forwards
class AP4_ByteStream;
namespace adaptive
{
enum class AdtsType;
}
class ATTR_DLL_LOCAL ID3TAG
{
public:
enum PARSECODE
{
PARSE_SUCCESS,
PARSE_FAIL,
PARSE_NO_ID3
};
PARSECODE parse(AP4_ByteStream* stream);
void SkipID3Data(AP4_ByteStream* stream);
bool getPts(uint64_t &pts) { if (m_timestamp) { pts = m_timestamp; m_timestamp = 0; return true; } return false; }
private:
static uint64_t getSize(const uint8_t *data, unsigned int size, unsigned int shift);
static const unsigned int HEADER_SIZE = 10;
uint8_t m_majorVer;
uint8_t m_revisionVer;
uint8_t m_flags;
uint64_t m_timestamp;
};
class ATTR_DLL_LOCAL ADTSFrame
{
public:
enum CODEC_FLAG
{
CODEC_FLAG_NONE = 0,
CODEC_FLAG_ATMOS = 1 << 0
};
// \brief Generic frame info struct for all codec types.
struct ADTSFrameInfo
{
adaptive::AdtsType m_codecType{0};
int m_codecProfile{-1}; // For his definition refer to the type of codec parsed, -1 for unset value
int m_codecFlags{CODEC_FLAG_NONE}; // Refer to CODEC_FLAG enum
AP4_Size m_frameSize{0};
uint32_t m_frameCount{0};
uint32_t m_sampleRate{0};
uint32_t m_channels{0};
};
/*!
* \brief Adjust the stream position to advance over padding if neccessary (end of file)
* \param stream The stream to check
*/
void AdjustStreamForPadding(AP4_ByteStream* stream);
ADTSFrameInfo GetFrameInfo(AP4_ByteStream* stream);
bool parse(AP4_ByteStream *stream);
bool ParseAac(AP4_ByteStream* stream);
bool ParseAacHeader(AP4_ByteStream* stream, ADTSFrameInfo& frameInfo);
bool ParseAc3(AP4_ByteStream* stream);
bool ParseAc3Header(AP4_ByteStream* stream, ADTSFrameInfo& frameInfo);
bool ParseAc4(AP4_ByteStream* stream);
bool ParseAc4Header(AP4_ByteStream* stream, ADTSFrameInfo& frameInfo);
bool ParseEc3(AP4_ByteStream* stream);
bool ParseEc3Header(AP4_ByteStream* stream, ADTSFrameInfo& frameInfo);
void reset();
void resetFrameCount() { m_summedFrameCount = 0; }
uint64_t getPtsOffset() const;
uint64_t getDuration() const;
const AP4_Byte *getData() const { return m_dataBuffer.GetData(); }
AP4_Size getDataSize() const { return m_dataBuffer.GetDataSize(); }
private:
uint64_t m_summedFrameCount{0};
ADTSFrameInfo m_frameInfo;
AP4_DataBuffer m_dataBuffer;
};
class ATTR_DLL_LOCAL ADTSReader
{
public:
ADTSReader(AP4_ByteStream *stream);
virtual ~ADTSReader();
void Reset();
bool SeekTime(uint64_t timeInTs, bool preceeding);
bool GetInformation(kodi::addon::InputstreamInfo& info);
bool ReadPacket();
uint64_t GetPts() const { return m_pts; }
uint64_t GetDuration() const { return m_frameParser.getDuration(); }
const AP4_Byte *GetPacketData() const { return m_frameParser.getData(); };
const AP4_Size GetPacketSize() const { return m_frameParser.getDataSize(); };
static const uint64_t ADTS_PTS_UNSET = 0x1ffffffffULL;
private:
AP4_ByteStream *m_stream;
ID3TAG m_id3TagParser;
ADTSFrame m_frameParser;
uint64_t m_basePts{0};
uint64_t m_pts{0};
};