forked from carlonluca/pot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
135 lines (118 loc) · 4.16 KB
/
main.cpp
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
/*
* Project: PiOmxTextures
* Author: Luca Carlon
* Date: 12.03.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/>.
*/
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include <QApplication>
#include <QQuickView>
#include <bcm_host.h>
#include <signal.h>
#include <execinfo.h>
extern "C" {
#include "libavformat/avformat.h"
}
#include "omx_imageelement.h"
#include "omx_videosurfaceelement.h"
#include "omx_camerasurfaceelement.h"
#include "omx_mediaprocessorelement.h"
#include "omx_audioprocessor.h"
#include "omx_mediaprocessor.h"
#include "lc_logging.h"
#define ENABLE_QML_SAMPLE 1
/*----------------------------------------------------------------------
| handlerSigsegv
+---------------------------------------------------------------------*/
void handlerSigsegv(int sig)
{
void *array[10];
size_t size;
size = backtrace(array, 10);
// Print out all the frames to stderr.
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, 2);
exit(1);
}
/*----------------------------------------------------------------------
| handlerSigterm
+---------------------------------------------------------------------*/
void handlerSigint(int sig)
{
Q_UNUSED(sig);
LOG_INFORMATION(LOG_TAG, "Terminating...");
qApp->quit();
}
/*----------------------------------------------------------------------
| definitions
+---------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
#if 0
signal(SIGSEGV, handlerSigsegv);
signal(SIGINT, handlerSigint);
#endif
QApplication a(argc, argv);
// Registers all the codecs.
av_register_all();
#ifdef ENABLE_CUBE_SAMPLE
// Check arguments.
if (argc < 3) {
LOG_ERROR(LOG_TAG, "You have to provide a prefix for the textures to use and the path to the video.");
LOG_ERROR(LOG_TAG, "You'll need 6 textures whose abs path is <prefix><n>.jpg with <n> in [0, 5].");
LOG_ERROR(LOG_TAG, "Then start the application with <prefix> as the"
" first param and <video_path> as the second.");
return -1;
}
// Check file existance.
for (int i = 0; i < 6; i++) {
QString filePath = QString("%1%2%3").arg(a.arguments().at(1)).arg(i).arg(".jpg");
if (!QFile(filePath).exists()) {
LOG_ERROR(LOG_TAG, "Couldn't find %s.", qPrintable(filePath));
return -1;
}
}
if (!QFile(a.arguments().at(2)).exists()) {
LOG_ERROR(LOG_TAG, "Video file does not exist.");
return -1;
}
// Build scene.
GLWidget widget(a.arguments().at(1), a.arguments().at(2));
widget.show();
#elif ENABLE_QML_SAMPLE
#ifdef ENABLE_VIDEO_TEST
qRegisterMetaType<GLuint>("GLuint");
qRegisterMetaType<OMX_TextureData*>("OMX_TextureData*");
qmlRegisterType<OMX_ImageElement>("com.luke.qml", 1, 0, "OMXImage");
qmlRegisterType<OMX_VideoSurfaceElement>("com.luke.qml", 1, 0, "OMXVideoSurface");
qmlRegisterType<OMX_CameraSurfaceElement>("com.luke.qml", 1, 0, "OMXCameraSurface");
qmlRegisterType<OMX_MediaProcessorElement>("com.luke.qml", 1, 0, "OMXMediaProcessor");
QQuickView view;
view.setSource(QUrl("qrc:///main.qml"));
view.setResizeMode(view.SizeRootObjectToView);
view.showFullScreen();
#else
OMX_AudioProcessor proc;
proc.play();
#endif // ENABLE_VIDEO_TEST
#endif // ENABLE_CUBE_SAMPLE
return a.exec();
}