summaryrefslogtreecommitdiff
path: root/video.h
blob: c728bcf16000982b2f1ab022864dc43b7a4724f2 (plain)
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
/*
 * rpihddevice - VDR HD output device for Raspberry Pi
 * Copyright (C) 2014, 2015, 2016 Thomas Reufer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef VIDEO_H
#define VIDEO_H

#include <vdr/thread.h>

#include "tools.h"
#include "omx.h"

class cRpiVideoDecoder
{

public:

	cRpiVideoDecoder(cVideoCodec::eCodec codec,
			void (*onStreamStart)(void*, const cVideoFrameFormat *format),
			void (*onEndOfStream)(void*), void* callbackData);
	virtual ~cRpiVideoDecoder();

	cVideoCodec::eCodec GetCodec(void) { return m_codec; };

	virtual bool WriteData(const unsigned char *data,
			unsigned int length, int64_t pts, bool eof) = 0;

	virtual bool Poll(void) { return true; };
	virtual void Clear(bool flushVideoRender = false) { };
	virtual void Flush(void) { };

	const cVideoFrameFormat *GetFrameFormat(void) { return &m_format; }

	virtual int GetBufferUsage(void) { return 0; };

protected:

	static const unsigned char s_mpeg2EndOfSequence[4];
	static const unsigned char s_h264EndOfSequence[8];

	cVideoCodec::eCodec m_codec;
	cVideoFrameFormat   m_format;

	void NotifyStreamStart(void);
	void NotifyEndOfStream(void);

	void (*m_onStreamStart)(void*, const cVideoFrameFormat *format);
	void (*m_onEndOfStream)(void*);
	void *m_callbackData;

};

/* ------------------------------------------------------------------------- */

class cRpiOmxVideoDecoder : public cRpiVideoDecoder, protected cOmxEventHandler
{

public:

	cRpiOmxVideoDecoder(cVideoCodec::eCodec codec, cOmx *omx,
			void (*onStreamStart)(void*, const cVideoFrameFormat *format),
			void (*onEndOfStream)(void*), void* callbackData);
	virtual ~cRpiOmxVideoDecoder();

	virtual bool WriteData(const unsigned char *data,
			unsigned int length, int64_t pts, bool eof);

	virtual bool Poll(void);
	virtual void Clear(bool flushRender = false);
	virtual void Flush(void);

	virtual int GetBufferUsage(void);

protected:

	virtual void PortSettingsChanged(int port);
	virtual void EndOfStreamReceived(int port);
	virtual void BufferEmptied(cOmx::eOmxComponent comp);
	virtual void BufferStalled(void);
	virtual void Tick(void);

	OMX_BUFFERHEADERTYPE* GetBuffer(void);
	bool EmptyBuffer(OMX_BUFFERHEADERTYPE *buf);

	void SetupDeinterlacer(cDeinterlacerMode::eMode mode);

	cMutex m_mutex;
	cOmx  *m_omx;
	int    m_usedBuffers[BUFFERSTAT_FILTER_SIZE];
	bool   m_setDiscontinuity;
	bool   m_setStartTime;

	OMX_BUFFERHEADERTYPE *m_spareBuffers;

private:

};

/*
class cRpiFfmpegVideoDecoder : public cRpiVideoDecoder, public cThread
{

public:

	cRpiFfmpegVideoDecoder();
	virtual ~cRpiFfmpegVideoDecoder();

protected:

	static void Log(void* ptr, int level, const char* fmt, va_list vl);

	struct Codec
	{
		class AVCodec		 *codec;
	    class AVCodecContext *context;
	};

	Codec m_codec;

private:

};
*/
#endif