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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
* decoder.h: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#ifndef __decoder_h_
#define __decoder_h_
#define __STDC_CONSTANT_MACROS
#include <vdr/tools.h> // needed for (d/e/i)syslog
#include <stdint.h>
#include <sched.h>
#ifndef DECLARE_ALIGNED
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
#endif
#ifndef CPU_COUNT
#define CPU_COUNT(i) 1 // very crude ;)
#endif
#ifndef uchar
typedef unsigned char uchar;
#endif
#ifdef HAVE_AVCODEC
extern "C"
{
#include <libavcodec/avcodec.h>
#if LIBAVCODEC_VERSION_INT < ((52<<16)+(23<<8)+0)
#include <libavformat/avformat.h>
#endif
}
#endif
#include "global.h"
class cMarkAdDecoder
{
private:
int recvnumber;
#ifdef HAVE_AVCODEC
AVCodecContext *ac3_context;
AVCodecContext *mp2_context;
AVCodecContext *video_context;
AVFrame *video_frame;
uchar *temp_pictureplane[4];
bool SetAudioInfos(MarkAdContext *maContext, AVCodecContext *Audio_Context);
void PAR2DAR(AVRational a, AVRational *erg);
bool SetVideoInfos(MarkAdContext *maContext,AVCodecContext *Video_Context,
AVFrame *Video_Frame, AVRational *DAR);
#endif
// taken from femon
enum
{
NAL_SEI = 0x06, // Supplemental Enhancement Information
NAL_SPS = 0x07, // Sequence Parameter Set
NAL_AUD = 0x09, // Access Unit Delimiter
NAL_END_SEQ = 0x0A // End of Sequence
};
int nalUnescape(uint8_t *dst, const uint8_t *src, int len);
void FindH264VideoInfos(MarkAdContext *maContext, uchar *pkt, int len);
void FindH262VideoInfos(MarkAdContext *maContext, uchar *pkt, int len);
public:
void FindVideoInfos(MarkAdContext *maContext, uchar *pkt, int len);
bool DecodeVideo(MarkAdContext *maContext, uchar *pkt, int len);
bool DecodeMP2(MarkAdContext *maContext, uchar *espkt, int eslen);
void FindAC3AudioInfos(MarkAdContext *maContext, uchar *espkt, int eslen);
bool DecodeAC3(MarkAdContext *maContext, uchar *espkt, int eslen);
cMarkAdDecoder(int recvnumber, bool useH264, bool hasAC3);
~cMarkAdDecoder();
};
// taken from femon
class cBitStream
{
private:
const uint8_t *data;
int count; // in bits
int index; // in bits
public:
cBitStream(const uint8_t *buf, const int len);
~cBitStream();
int getBit();
uint32_t getBits(uint32_t n);
void skipBits(uint32_t n);
uint32_t getUeGolomb();
int32_t getSeGolomb();
void skipGolomb();
void skipUeGolomb();
void skipSeGolomb();
void byteAlign();
void skipBit()
{
skipBits(1);
}
uint32_t getU8()
{
return getBits(8);
}
uint32_t getU16()
{
return ((getBits(8) << 8) | getBits(8));
}
uint32_t getU24()
{
return ((getBits(8) << 16) | (getBits(8) << 8) | getBits(8));
}
uint32_t getU32()
{
return ((getBits(8) << 24) | (getBits(8) << 16) | (getBits(8) << 8) | getBits(8));
}
bool isEOF()
{
return (index >= count);
}
void reset()
{
index = 0;
}
int getIndex()
{
return (isEOF() ? count : index);
}
const uint8_t *getData()
{
return (isEOF() ? NULL : data + (index / 8));
}
};
#endif
|