forked from danielkucera/Mixer-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdmi.cpp
136 lines (88 loc) · 3.06 KB
/
hdmi.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
#include "hdmi.h"
#include "ui_hdmi.h"
HDMI::HDMI(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::HDMI)
{
ui->setupUi(this);
this->setAttribute(Qt::WA_DeleteOnClose, true);
connect(ui->enableBox, SIGNAL(stateChanged(int)), this, SLOT(enableHDMI(int)));
QTimer* statusbarClock = new QTimer(this);
statusbarClock->start(1000);
connect(statusbarClock,SIGNAL(timeout()),this,SLOT(updateStatusbar()));
}
void HDMI::Init(Buffer* bufin)
{
buffer = bufin;
}
HDMI::~HDMI()
{
ui->enableBox->setEnabled(false);
delete ui;
}
void HDMI::updateStatusbar(){
ui->statusbar->showMessage(QString("%1x%2 %3FPS %4FRM" ).arg(jpg_w).arg(jpg_h).arg(frame_cnt-old_f).arg(frame_cnt));
old_f = frame_cnt;
}
void HDMI::enableHDMI(int status){
if (status==2){
QHostAddress ip = QHostAddress(ui->ipEdit->text());
number = ui->outputSelect->value();
dest = buffer->Open(number);
recvr = new Reciever();
recvr->start(ip);
QThread* recvThread = new QThread();
recvr->moveToThread(recvThread);
recvThread->start();
connect(recvr,SIGNAL(imageReceived(QByteArray)),this,SLOT(process(QByteArray)));
}else{
delete recvr;
}
}
void local_error_exit (jpeg_common_struct* cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, 1);
}
void HDMI::process(QByteArray image){
std::ofstream outfile;
outfile.open ("/tmp/filename.jpg");
outfile.write (image.data(),image.length());
outfile.close();
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
JSAMPARRAY jpeg_buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = local_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
return;
}
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, (uchar*)image.data(),image.length());
(void) jpeg_read_header(&cinfo, TRUE);
cinfo.dct_method = JDCT_FASTEST;
cinfo.two_pass_quantize = FALSE;
//cinfo.out_color_space = JCS_EXT_RGBA;
cinfo.out_color_space = JCS_EXT_BGRA;
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
jpeg_buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
int counter=0;
while (cinfo.output_scanline < cinfo.output_height) {
(void) jpeg_read_scanlines(&cinfo, jpeg_buffer, 1);
memcpy(dest + counter,jpeg_buffer[0],row_stride);
counter += row_stride;
}
emit(buffer->newFrame(number));
frame_cnt++;
jpg_w=cinfo.output_width;
jpg_h=cinfo.output_height;
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
// QImage rgb = QImage::fromData((uchar*)inp, off).scaled(buffer->width, buffer->height).convertToFormat(QImage::Format_RGB888);
// memcpy(dest,rgb.bits(),rgb.byteCount());
}