OSDN Git Service

[UI][Qt] Not liking config, using_flags directly.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / tab_movie_h264.cpp
1 #include <QHBoxLayout>
2 #include <QVBoxLayout>
3 #include <QGridLayout>
4 #include <QWidget>
5 #include <QPushButton>
6 #include <QSlider>
7 #include <QComboBox>
8 #include <QLabel>
9 #include <QApplication>
10
11 #include "tab_movie_h264.h"
12 #include "dialog_movie.h"
13 #include "../avio/movie_saver.h"
14 #include "../../config.h"
15 #include "menu_flags.h"
16
17 CSP_TabMovieH264::CSP_TabMovieH264(MOVIE_SAVER *ms, CSP_DialogMovie *parent_window,  USING_FLAGS *p, QWidget *parent) : QWidget(parent)
18 {
19         QString tmps;
20         using_flags = p;
21         p_wid = parent;
22         p_movie = ms;
23         p_window = parent_window;
24
25         video_maxq = using_flags->get_config_ptr()->video_h264_maxq;
26         video_minq = using_flags->get_config_ptr()->video_h264_minq;
27
28         label_video_bframes = new QLabel(QApplication::translate("MainWindow", "Max B Frames", 0), this);
29         combo_video_bframes = new QComboBox(this);
30         label_video_b_adapt = new QLabel(QApplication::translate("MainWindow", "B Adaption", 0), this);
31         combo_video_b_adapt = new QComboBox(this);
32         label_video_subme = new QLabel(QApplication::translate("MainWindow", "Subpixel motion estimate", 0), this);
33         combo_video_subme = new QComboBox(this);
34
35         // Video bitrates
36         label_video_bitrate = new QLabel(QApplication::translate("MainWindow", "Bitrate", 0), this);
37         combo_video_bitrate = new QComboBox(this);
38         combo_video_bitrate->addItem(QString::fromUtf8("128Kbps"), 128);        
39         combo_video_bitrate->addItem(QString::fromUtf8("256Kbps"), 256);
40         combo_video_bitrate->addItem(QString::fromUtf8("300Kbps"), 300);
41         combo_video_bitrate->addItem(QString::fromUtf8("512Kbps"), 512);
42         combo_video_bitrate->addItem(QString::fromUtf8("600Kbps"), 600);
43         combo_video_bitrate->addItem(QString::fromUtf8("768Kbps"), 768);
44         combo_video_bitrate->addItem(QString::fromUtf8("900Kbps"), 900);
45         combo_video_bitrate->addItem(QString::fromUtf8("1000Kbps"), 1000);
46         combo_video_bitrate->addItem(QString::fromUtf8("1200Kbps"), 1200);
47         combo_video_bitrate->addItem(QString::fromUtf8("1500Kbps"), 1500);
48         combo_video_bitrate->addItem(QString::fromUtf8("1800Kbps"), 1800);
49         combo_video_bitrate->addItem(QString::fromUtf8("3000Kbps"), 3000);
50         combo_video_bitrate->addItem(QString::fromUtf8("4500Kbps"), 4500);
51         for(int i = 0; i < combo_video_bitrate->count(); i++) {
52                 int br = combo_video_bitrate->itemData(i).toInt();
53                 if(br == using_flags->get_config_ptr()->video_h264_bitrate) {
54                         combo_video_bitrate->setCurrentIndex(i);
55                 }
56         }
57         connect(combo_video_bitrate, SIGNAL(activated(int)), this, SLOT(do_set_video_bitrate(int)));
58         video_bitrate = using_flags->get_config_ptr()->video_h264_bitrate;
59
60         // Video bframes
61         combo_video_bframes->addItem(QString::fromUtf8("0"), 0);
62         combo_video_bframes->addItem(QString::fromUtf8("1"), 1);
63         combo_video_bframes->addItem(QString::fromUtf8("2"), 2);
64         combo_video_bframes->addItem(QString::fromUtf8("3"), 3);
65         combo_video_bframes->addItem(QString::fromUtf8("4"), 4);
66         combo_video_bframes->addItem(QString::fromUtf8("5"), 5);
67         combo_video_bframes->addItem(QString::fromUtf8("6"), 6);
68         combo_video_bframes->addItem(QString::fromUtf8("7"), 7);
69         combo_video_bframes->addItem(QString::fromUtf8("8"), 8);
70         for(int i = 0; i < combo_video_bframes->count(); i++) {
71                 int br = combo_video_bframes->itemData(i).toInt();
72                 if(br == using_flags->get_config_ptr()->video_h264_bframes) {
73                         combo_video_bframes->setCurrentIndex(i);
74                 }
75         }
76         video_bframes = using_flags->get_config_ptr()->video_h264_bframes;
77         connect(combo_video_bframes, SIGNAL(activated(int)), this, SLOT(do_set_bframes(int)));
78
79         // B adapt
80         combo_video_b_adapt->addItem(QApplication::translate("MainWindow", "None", 0), 0);
81         combo_video_b_adapt->addItem(QApplication::translate("MainWindow", "Fast", 0), 1);
82         combo_video_b_adapt->addItem(QApplication::translate("MainWindow", "Optimal (Slow with high B-Frames)", 0), 2);
83         for(int i = 0; i < combo_video_b_adapt->count(); i++) {
84                 int br = combo_video_b_adapt->itemData(i).toInt();
85                 if(br == using_flags->get_config_ptr()->video_h264_b_adapt) {
86                         combo_video_b_adapt->setCurrentIndex(i);
87                 }
88         }
89         video_b_adapt = using_flags->get_config_ptr()->video_h264_b_adapt;
90         connect(combo_video_b_adapt, SIGNAL(activated(int)), this, SLOT(do_set_b_adapt(int)));
91
92         slider_qmin = new QSlider(Qt::Horizontal, this);
93         slider_qmin->setMinimum(0);
94         slider_qmin->setMaximum(63);
95         slider_qmin->setValue(using_flags->get_config_ptr()->video_h264_minq);
96         label_qmin_val = new QLabel(this);
97         tmps.setNum(using_flags->get_config_ptr()->video_h264_minq);
98         label_qmin_val->setText(tmps);
99         label_qmin_name = new QLabel(QString::fromUtf8("QP Min"), this);
100         video_minq = using_flags->get_config_ptr()->video_h264_minq;
101         connect(slider_qmin, SIGNAL(valueChanged(int)), this, SLOT(do_set_qmin(int)));
102                 
103         slider_qmax = new QSlider(Qt::Horizontal, this);
104         slider_qmax->setMinimum(0);
105         slider_qmax->setMaximum(63);
106         slider_qmax->setValue(using_flags->get_config_ptr()->video_h264_maxq);
107         label_qmax_val = new QLabel(this);
108         tmps.setNum(using_flags->get_config_ptr()->video_h264_maxq);
109         label_qmax_val->setText(tmps);
110         label_qmax_name = new QLabel(QString::fromUtf8("QP Max"), this);
111         connect(slider_qmax, SIGNAL(valueChanged(int)), this, SLOT(do_set_qmax(int)));
112         video_maxq = using_flags->get_config_ptr()->video_h264_maxq;
113         
114         // Subme
115         combo_video_subme->addItem(QApplication::translate("MainWindow", "RD mode decision for I/P-frames", 0), 6);
116         combo_video_subme->addItem(QApplication::translate("MainWindow", "RD mode decision for all frames", 0), 7);
117         combo_video_subme->addItem(QApplication::translate("MainWindow", "RD refinement for  I/P-frames", 0), 8);
118         combo_video_subme->addItem(QApplication::translate("MainWindow", "RD refinement for all frames", 0), 9);
119         combo_video_subme->addItem(QApplication::translate("MainWindow", "QP-RD", 0), 10); // Trellis 2, admode > 0
120         combo_video_subme->addItem(QApplication::translate("MainWindow", "Full RD: disable all early terminations", 0), 11);
121         for(int i = 0; i < combo_video_subme->count(); i++) {
122                 int br = combo_video_subme->itemData(i).toInt();
123                 if(br == using_flags->get_config_ptr()->video_h264_subme) {
124                         combo_video_subme->setCurrentIndex(i);
125                 }
126         }
127         video_subme = using_flags->get_config_ptr()->video_h264_subme;
128         connect(combo_video_subme, SIGNAL(activated(int)), this, SLOT(do_set_subme(int)));
129                 
130         label_title = new QLabel(QApplication::translate("MainWindow", "Set H.264 parameter.", 0), this);
131         grid_layout = new QGridLayout(this);
132
133         grid_layout->addWidget(label_title, 0, 0);
134         
135         grid_layout->addWidget(label_qmin_name, 1, 0);
136         grid_layout->addWidget(label_qmin_val, 1, 3);
137         grid_layout->addWidget(slider_qmin, 2, 0, 1, 4);
138         grid_layout->addWidget(label_qmax_name, 3, 0);
139         grid_layout->addWidget(label_qmax_val, 3, 3);
140         grid_layout->addWidget(slider_qmax, 4, 0, 1, 4);
141         grid_layout->addWidget(label_video_bitrate, 5, 0);
142         grid_layout->addWidget(combo_video_bitrate, 5, 1);
143         
144         
145         grid_layout->addWidget(label_video_bframes, 6, 0);
146         grid_layout->addWidget(combo_video_bframes, 6, 1);
147         
148         grid_layout->addWidget(label_video_b_adapt, 6, 2);
149         grid_layout->addWidget(combo_video_b_adapt, 6, 3);
150         
151         grid_layout->addWidget(label_video_subme, 7, 0);
152         grid_layout->addWidget(combo_video_subme, 7, 1);
153         
154         this->setLayout(grid_layout);
155
156         connect(this, SIGNAL(sig_video_add_option(QString, QString)), p_movie, SLOT(do_add_option(QString, QString)));
157         connect(this, SIGNAL(sig_set_video_bitrate(int)), p_movie, SLOT(do_set_video_bitrate(int)));
158         this->show();
159 }
160
161
162 CSP_TabMovieH264::~CSP_TabMovieH264()
163 {
164 }
165
166 void CSP_TabMovieH264::do_set_codecs(void)
167 {
168         QString value;
169         // See:
170         // https://libav.org/avconv.html#Video-Options
171         using_flags->get_config_ptr()->video_h264_bitrate = video_bitrate;
172
173         using_flags->get_config_ptr()->video_h264_maxq = video_maxq;
174         using_flags->get_config_ptr()->video_h264_minq = video_minq;
175         using_flags->get_config_ptr()->video_h264_bframes = video_bframes;
176         using_flags->get_config_ptr()->video_h264_b_adapt = video_b_adapt;
177         using_flags->get_config_ptr()->video_h264_subme = video_subme;
178 }
179
180 void CSP_TabMovieH264::do_set_qmin(int n)
181 {
182         if(n < 0) n = 0;
183         if(n > 63) n = 63;
184         QString tmps;
185         video_minq = n;
186         tmps.setNum(n);
187         label_qmin_val->setText(tmps);
188 }
189
190 void CSP_TabMovieH264::do_set_qmax(int n)
191 {
192         if(n < 0) n = 0;
193         if(n > 63) n = 63;
194         
195         QString tmps;
196         video_maxq = n;
197         tmps.setNum(n);
198         label_qmax_val->setText(tmps);
199 }
200
201 void CSP_TabMovieH264::do_set_bframes(int n)
202 {
203         int val = combo_video_bframes->itemData(n).toInt();
204         if(val < 0) val = 0;
205         if(val > 10) val = 10;
206         video_bframes = val;
207 }
208
209 void CSP_TabMovieH264::do_set_video_bitrate(int n)
210 {
211         int val = combo_video_bitrate->itemData(n).toInt();
212         if(val < 64) val = 64;
213         video_bitrate = val;
214 }
215
216 void CSP_TabMovieH264::do_set_b_adapt(int n)
217 {
218         int val = combo_video_b_adapt->itemData(n).toInt();
219         if(val < 0) val = 0;
220         if(val > 2) val = 2;
221         video_b_adapt = val;
222 }
223
224 void CSP_TabMovieH264::do_set_subme(int n)
225 {
226         int val = combo_video_subme->itemData(n).toInt();
227         if(val < 4) val = 4;
228         if(val > 11) val = 11;
229         video_subme = val;
230 }