forked from carlonluca/pot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omx_mediaprocessor.h
253 lines (205 loc) · 6.69 KB
/
omx_mediaprocessor.h
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* Project: PiOmxTextures
* Author: Luca Carlon
* Date: 11.01.2012
*
* Copyright (c) 2012, 2013 Luca Carlon. All rights reserved.
*
* This file is part of PiOmxTextures.
*
* PiOmxTextures 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 3 of the License, or
* (at your option) any later version.
*
* PiOmxTextures 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 PiOmxTextures. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OMX_MEDIAPROCESSOR_H
#define OMX_MEDIAPROCESSOR_H
/*------------------------------------------------------------------------------
| includes
+-----------------------------------------------------------------------------*/
#include <QString>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QVariantMap>
#include <GLES2/gl2.h>
#include <stdexcept>
#include <memory>
#include <lc_logging.h>
#include "omx_qthread.h"
using namespace std;
/*------------------------------------------------------------------------------
| defintions
+-----------------------------------------------------------------------------*/
class OMX_TextureData;
class OMX_TextureProvider;
class OMXCore;
class OMXClock;
class OMXPlayerVideo;
class OMX_PlayerAudio;
#ifdef ENABLE_SUBTITLES
class OMXPlayerSubtitles;
#endif
class OMX_Reader;
class OMXPacket;
class AVFormatContext;
class AVStream;
class AVPacket;
class CRBP;
class COMXCore;
class COMXStreamInfo;
typedef shared_ptr<OMX_TextureProvider> OMX_TextureProviderSh;
/*------------------------------------------------------------------------------
| OMX_MediaProcessor class
+-----------------------------------------------------------------------------*/
/**
* @brief The OMX_MediaProcessor class Plays the media passed to the constructor
* using the HDMI as audio output and a texture as the rendering surface. The
* ID of the texture is sent when it is ready.
*/
class OMX_MediaProcessor : public QObject
{
Q_OBJECT
public:
enum OMX_MediaProcessorState {
STATE_STOPPED,
STATE_INACTIVE,
STATE_PAUSED,
STATE_PLAYING
};
enum OMX_MediaProcessorError {
ERROR_CANT_OPEN_FILE,
ERROR_WRONG_THREAD
};
OMX_MediaProcessor(OMX_TextureProviderSh provider);
~OMX_MediaProcessor();
bool setFilename(QString filename, OMX_TextureData*& textureData);
QString filename();
QStringList streams();
qint64 streamPosition();
OMX_TextureData* textureData();
bool hasAudio();
bool hasVideo();
qint64 streamLength();
#ifdef ENABLE_SUBTITLES
inline bool hasSubtitle() {
return m_has_subtitle;
}
#endif
OMX_MediaProcessorState state();
void setVolume(long volume, bool linear);
long volume(bool linear);
void setMute(bool muted);
bool muted();
QVariantMap getMetaData();
public slots:
bool play();
bool stop();
bool pause();
bool seek(qint64 position);
void onTextureReady(const OMX_TextureData* textureData);
signals:
void metadataChanged(const QVariantMap metadata);
void playbackStarted();
void playbackCompleted();
void textureInvalidated();
void textureReady(const OMX_TextureData* textureData);
void errorOccurred(OMX_MediaProcessor::OMX_MediaProcessorError error);
void stateChanged(OMX_MediaProcessor::OMX_MediaProcessorState state);
private slots:
void mediaDecoding();
void cleanup();
private:
bool setFilenameInt(QString filename, OMX_TextureData*& textureData);
void setState(OMX_MediaProcessorState state);
void setSpeed(int iSpeed);
void flushStreams(double pts);
bool checkCurrentThread();
void convertMetaData();
OMX_QThread m_thread;
QString m_filename;
OMX_TextureData* m_textureData;
AVFormatContext* fmt_ctx;
AVStream* streamVideo;
AVPacket* pkt;
volatile OMX_MediaProcessorState m_state;
QMutex m_sendCmd;
OMXClock* m_av_clock;
OMXPlayerVideo* m_player_video;
OMX_PlayerAudio* m_player_audio;
#ifdef ENABLE_SUBTITLES
OMXPlayerSubtitles* m_player_subtitles;
#endif
OMX_Reader* m_omx_reader;
OMXPacket* m_omx_pkt;
CRBP* m_RBP;
COMXCore* m_OMX;
bool m_has_video;
bool m_has_audio;
#ifdef ENABLE_SUBTITLES
bool m_has_subtitle;
#endif
bool m_buffer_empty;
bool m_pendingStop;
bool m_pendingPause;
int m_subtitle_index;
int m_audio_index;
OMX_TextureProviderSh m_provider;
QMutex m_mutexPending;
QWaitCondition m_waitPendingCommand;
volatile long m_incr;
COMXStreamInfo* m_hints_audio;
COMXStreamInfo* m_hints_video;
float m_audio_fifo_size; // zero means use default
float m_video_fifo_size;
float m_audio_queue_size;
float m_video_queue_size;
int m_playspeedCurrent;
bool m_seekFlush;
bool m_packetAfterSeek;
double startpts;
QVariantMap m_metadata;
bool m_loop;
double m_loop_from;
float m_fps;
};
/*------------------------------------------------------------------------------
| OMX_MediaProcessor::hasAudio
+-----------------------------------------------------------------------------*/
inline bool OMX_MediaProcessor::hasAudio() {
return m_has_audio;
}
/*------------------------------------------------------------------------------
| OMX_MediaProcessor::hasVideo
+-----------------------------------------------------------------------------*/
inline bool OMX_MediaProcessor::hasVideo() {
return m_has_video;
}
/*------------------------------------------------------------------------------
| OMX_MediaProcessor::state
+-----------------------------------------------------------------------------*/
inline OMX_MediaProcessor::OMX_MediaProcessorState OMX_MediaProcessor::state() {
return m_state;
}
/*------------------------------------------------------------------------------
| OMX_MediaProcessor::setState
+-----------------------------------------------------------------------------*/
inline void OMX_MediaProcessor::setState(OMX_MediaProcessorState state) {
m_state = state;
emit stateChanged(state);
}
/*------------------------------------------------------------------------------
| OMX_MediaProcessor::getMetaData
+-----------------------------------------------------------------------------*/
inline QVariantMap OMX_MediaProcessor::getMetaData() {
return m_metadata;
}
#endif // OMX_MEDIAPROCESSOR_H