remove compile errors (still will not link and JACKPortEngine is not close to done)
[ardour.git] / gtk2_ardour / transcode_ffmpeg.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <sstream>
23 #include <sys/types.h>
24
25 #include "pbd/error.h"
26 #include "pbd/convert.h"
27 #include "pbd/file_utils.h"
28 #include "gui_thread.h"
29
30 #include "transcode_ffmpeg.h"
31 #include "utils_videotl.h"
32
33 #include "i18n.h"
34
35 using namespace PBD;
36
37 TranscodeFfmpeg::TranscodeFfmpeg (std::string f)
38         : infile(f)
39 {
40         probeok = false;
41         ffexecok = false;
42         ffmpeg_exe = "";
43         ffprobe_exe = "";
44         m_duration = 0;
45         m_avoffset = m_lead_in = m_lead_out = 0;
46         m_width = m_height = 0;
47         m_aspect = m_fps = 0;
48 #if 1 /* tentative debug mode */
49         debug_enable = false;
50 #endif
51
52         std::string ff_file_path;
53         if (find_file_in_search_path (SearchPath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) { ffmpeg_exe = ff_file_path; }
54         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
55                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
56         }
57         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
58                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
59         }
60
61         if (find_file_in_search_path (SearchPath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) { ffprobe_exe = ff_file_path; }
62         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
63                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
64         }
65         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
66                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
67         }
68
69         if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
70                 warning << string_compose(
71                                 _(
72                                 "No ffprobe or ffmpeg executables could be found on this system.\n"
73                                 "Video import and export is not possible until you install those tools.\n"
74                                 "%1 requires ffmpeg and ffprobe from ffmpeg.org - version 1.1 or newer.\n"
75                                 "\n"
76                                 "The tools are included with the %1 releases from ardour.org "
77                                 "and also available with the video-server at http://x42.github.com/harvid/\n"
78                                 "\n"
79                                 "Important: the files need to be installed in $PATH and named ffmpeg_harvid and ffprobe_harvid.\n"
80                                 "If you already have a suitable ffmpeg installation on your system, we recommend creating "
81                                 "symbolic links from ffmpeg to ffmpeg_harvid and from ffprobe to ffprobe_harvid.\n"
82                                 ), PROGRAM_NAME) << endmsg;
83                 return;
84         }
85         ffexecok = true;
86
87         if (infile.empty() || !probe()) {
88                 return;
89         }
90         probeok = true;
91 }
92
93 TranscodeFfmpeg::~TranscodeFfmpeg ()
94 {
95   ;
96 }
97
98 bool
99 TranscodeFfmpeg::probe ()
100 {
101         ffoutput = "";
102         char **argp;
103         argp=(char**) calloc(7,sizeof(char*));
104         argp[0] = strdup(ffprobe_exe.c_str());
105         argp[1] = strdup("-print_format");
106         argp[2] = strdup("csv=nk=0");
107         argp[3] = strdup("-show_format");
108         argp[4] = strdup("-show_streams");
109         argp[5] = strdup(infile.c_str());
110         argp[6] = 0;
111         ffcmd = new SystemExec(ffprobe_exe, argp);
112         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffprobeparse, this, _1 ,_2));
113         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
114         if (ffcmd->start(1)) {
115                 ffexit();
116                 return false;
117         }
118
119         /* wait for ffprobe process to exit */
120         ffcmd->wait();
121
122         /* wait for interposer thread to copy all data.
123          * SystemExec::Terminated is emitted and ffcmd set to NULL */
124         int timeout = 300; // 1.5 sec
125         while (ffcmd && --timeout > 0) {
126                 usleep(5000);
127         }
128         if (timeout == 0 || ffoutput.empty()) {
129                 return false;
130         }
131
132         /* parse */
133
134         std::vector<std::vector<std::string> > lines;
135         ParseCSV(ffoutput, lines);
136         double timebase = 0;
137         m_width = m_height = 0;
138         m_fps = m_aspect = 0;
139         m_duration = 0;
140         m_codec.clear();
141         m_audio.clear();
142
143 #define PARSE_FRACTIONAL_FPS(VAR) \
144         { \
145                 std::string::size_type pos; \
146                 VAR = atof(value); \
147                 pos = value.find_first_of('/'); \
148                 if (pos != std::string::npos) { \
149                         VAR = atof(value.substr(0, pos)) / atof(value.substr(pos+1)); \
150                 } \
151         }
152
153         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
154                 if (i->at(0) == X_("format")) {
155                         /* format,filename,#streams,format-name,format-long-name,start-time,duration,size,bitrate */
156                 } else
157                 if (i->at(0) == X_("stream")) {
158                         if (i->at(5) == X_("codec_type=video") && m_width == 0) {
159
160                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
161                                         const size_t kvsep = kv->find('=');
162                                         if(kvsep == std::string::npos) continue;
163                                         std::string key = kv->substr(0, kvsep);
164                                         std::string value = kv->substr(kvsep + 1);
165
166                                         if (key == X_("index")) {
167                                                 m_videoidx = atoi(value);
168                                         } else if (key == X_("width")) {
169                                                 m_width = atoi(value);
170                                         } else if (key == X_("height")) {
171                                                 m_height = atoi(value);
172                                         } else if (key == X_("codec_name")) {
173                                                 if (!m_codec.empty()) m_codec += " ";
174                                                 m_codec += value;
175                                         } else if (key == X_("codec_long_name")) {
176                                                 if (!m_codec.empty()) m_codec += " ";
177                                                 m_codec += "[" + value + "]";
178                                         } else if (key == X_("codec_tag_string")) {
179                                                 if (!m_codec.empty()) m_codec += " ";
180                                                 m_codec += "(" + value + ")";
181                                         } else if (key == X_("r_frame_rate")) {
182                                                 PARSE_FRACTIONAL_FPS(m_fps)
183                                         } else if (key == X_("avg_frame_rate") && m_fps == 0) {
184                                                 PARSE_FRACTIONAL_FPS(m_fps)
185                                         } else if (key == X_("time_base")) {
186                                                 PARSE_FRACTIONAL_FPS(timebase)
187                                         } else if (key == X_("timecode") && m_duration == 0) {
188                                                 int h,m,s; char f[7];
189                                                 if (sscanf(i->at(16).c_str(), "%d:%d:%d:%s",&h,&m,&s,f) == 4) {
190                                                         m_duration = (ARDOUR::framecnt_t) floor(m_fps * (
191                                                                         h * 3600.0
192                                                                 + m * 60.0
193                                                                 + s * 1.0
194                                                                 + atoi(f) / pow(10, strlen(f))
195                                                         ));
196                                                 }
197                                         } else if (key == X_("duration_ts") && m_fps == 0 && timebase !=0 ) {
198                                                 m_duration = atof(value) * m_fps * timebase;
199                                         } else if (key == X_("duration") && m_fps != 0 && m_duration == 0) {
200                                                 m_duration = atof(value) * m_fps;
201                                         } else if (key == X_("display_aspect_ratio")) {
202                                                 std::string::size_type pos;
203                                                 pos = value.find_first_of(':');
204                                                 if (pos != std::string::npos && atof(value.substr(pos+1)) != 0) {
205                                                         m_aspect = atof(value.substr(0, pos)) / atof(value.substr(pos+1));
206                                                 }
207                                         }
208                                 }
209
210                                 if (m_aspect == 0) {
211                                         m_aspect = (double)m_width / (double)m_height;
212                                 }
213
214                         } else if (i->at(5) == X_("codec_type=audio")) { /* new ffprobe */
215                                 FFAudioStream as;
216                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
217                                         const size_t kvsep = kv->find('=');
218                                         if(kvsep == std::string::npos) continue;
219                                         std::string key = kv->substr(0, kvsep);
220                                         std::string value = kv->substr(kvsep + 1);
221
222                                         if (key == X_("channels")) {
223                                                 as.channels   = atoi(value);
224                                         } else if (key == X_("index")) {
225                                                 as.stream_id  = value;
226                                         } else if (key == X_("codec_long_name")) {
227                                                 if (!as.name.empty()) as.name += " ";
228                                                 as.name += value;
229                                         } else if (key == X_("codec_name")) {
230                                                 if (!as.name.empty()) as.name += " ";
231                                                 as.name += value;
232                                         } else if (key == X_("sample_fmt")) {
233                                                 if (!as.name.empty()) as.name += " ";
234                                                 as.name += "FMT:" + value;
235                                         } else if (key == X_("sample_rate")) {
236                                                 if (!as.name.empty()) as.name += " ";
237                                                 as.name += "SR:" + value;
238                                         }
239
240                                 }
241                                 m_audio.push_back(as);
242                         }
243                 }
244         }
245         /* end parse */
246
247 #if 0 /* DEBUG */
248         printf("FPS: %f\n", m_fps);
249         printf("Duration: %lu frames\n",(unsigned long)m_duration);
250         printf("W/H: %ix%i\n",m_width, m_height);
251         printf("aspect: %f\n",m_aspect);
252         printf("codec: %s\n",m_codec.c_str());
253         if (m_audio.size() > 0) {
254                 for (AudioStreams::iterator it = m_audio.begin(); it < m_audio.end(); ++it) {
255                         printf("audio: %s - %i channels\n",(*it).stream_id.c_str(), (*it).channels);
256                 }
257         } else {
258           printf("audio: no audio streams in file.\n");
259         }
260 #endif
261
262         return true;
263 }
264
265 TranscodeFfmpeg::FFSettings
266 TranscodeFfmpeg::default_encoder_settings ()
267 {
268         TranscodeFfmpeg::FFSettings ffs;
269         ffs.clear();
270         ffs["-vcodec"] = "mpeg4";
271         ffs["-acodec"] = "ac3";
272         ffs["-b:v"] = "5000k";
273         ffs["-b:a"] = "160k";
274         return ffs;
275 }
276
277 TranscodeFfmpeg::FFSettings
278 TranscodeFfmpeg::default_meta_data ()
279 {
280         TranscodeFfmpeg::FFSettings ffm;
281         ffm.clear();
282         ffm["comment"] = "Created with ardour";
283         return ffm;
284 }
285
286 char *
287 TranscodeFfmpeg::format_metadata (std::string key, std::string value)
288 {
289         size_t start_pos = 0;
290         std::string v1 = value;
291         while((start_pos = v1.find_first_not_of(
292                         "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(),.\"'",
293                         start_pos)) != std::string::npos)
294         {
295                 v1.replace(start_pos, 1, "_");
296                 start_pos += 1;
297         }
298
299         start_pos = 0;
300         while((start_pos = v1.find("\"", start_pos)) != std::string::npos) {
301                 v1.replace(start_pos, 1, "\\\"");
302                 start_pos += 2;
303         }
304
305         size_t len = key.length() + v1.length() + 4;
306         char *mds = (char*) calloc(len, sizeof(char));
307         snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
308         return mds;
309 }
310
311 bool
312 TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf_v, TranscodeFfmpeg::FFSettings ffs, TranscodeFfmpeg::FFSettings meta, bool map)
313 {
314 #define MAX_FFMPEG_ENCODER_ARGS (100)
315         char **argp;
316         int a=0;
317
318         argp=(char**) calloc(MAX_FFMPEG_ENCODER_ARGS,sizeof(char*));
319         argp[a++] = strdup(ffmpeg_exe.c_str());
320         if (m_avoffset < 0 || m_avoffset > 0) {
321                 std::ostringstream osstream; osstream << m_avoffset;
322                 argp[a++] = strdup("-itsoffset");
323                 argp[a++] = strdup(osstream.str().c_str());
324         }
325         argp[a++] = strdup("-i");
326         argp[a++] = strdup(inf_v.c_str());
327
328         argp[a++] = strdup("-i");
329         argp[a++] = strdup(inf_a.c_str());
330
331         for(TranscodeFfmpeg::FFSettings::const_iterator it = ffs.begin(); it != ffs.end(); ++it) {
332                 argp[a++] = strdup(it->first.c_str());
333                 argp[a++] = strdup(it->second.c_str());
334         }
335         for(TranscodeFfmpeg::FFSettings::const_iterator it = meta.begin(); it != meta.end(); ++it) {
336                 argp[a++] = strdup("-metadata");
337                 argp[a++] = format_metadata(it->first.c_str(), it->second.c_str());
338         }
339         if (m_lead_in != 0 && m_lead_out != 0) {
340                 std::ostringstream osstream;
341                 argp[a++] = strdup("-vf");
342                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in << X_(" [pre]; ");
343                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out << X_(" [post]; ");
344                 osstream << X_("[pre] [in] [post] concat=n=3");
345                 argp[a++] = strdup(osstream.str().c_str());
346         } else if (m_lead_in != 0) {
347                 std::ostringstream osstream;
348                 argp[a++] = strdup("-vf");
349                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in << X_(" [pre]; ");
350                 osstream << X_("[pre] [in] concat=n=2");
351                 argp[a++] = strdup(osstream.str().c_str());
352         } else if (m_lead_out != 0) {
353                 std::ostringstream osstream;
354                 argp[a++] = strdup("-vf");
355                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out << X_(" [post]; ");
356                 osstream << X_("[in] [post] concat=n=2");
357                 argp[a++] = strdup(osstream.str().c_str());
358         }
359
360         if (map) {
361                 std::ostringstream osstream;
362                 argp[a++] = strdup("-map");
363                 osstream << X_("0:") << m_videoidx;
364                 argp[a++] = strdup(osstream.str().c_str());
365                 argp[a++] = strdup("-map");
366                 argp[a++] = strdup("1:0");
367         }
368
369         argp[a++] = strdup("-y");
370         argp[a++] = strdup(outfile.c_str());
371         argp[a] = (char *)0;
372         assert(a<MAX_FFMPEG_ENCODER_ARGS);
373         /* Note: these are free()d in ~SystemExec */
374 #if 1 /* DEBUG */
375         if (debug_enable) { /* tentative debug mode */
376         printf("EXPORT ENCODE:\n");
377         for (int i=0; i< a; ++i) {
378           printf("%s ", argp[i]);
379         }
380         printf("\n");
381         }
382 #endif
383
384         ffcmd = new SystemExec(ffmpeg_exe, argp);
385         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
386         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
387         if (ffcmd->start(2)) {
388                 ffexit();
389                 return false;
390         }
391         return true;
392 }
393
394 bool
395 TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::framecnt_t /*samplerate*/, unsigned int stream)
396 {
397         if (!probeok) return false;
398   if (stream >= m_audio.size()) return false;
399
400         char **argp;
401         int i = 0;
402
403         argp=(char**) calloc(15,sizeof(char*));
404         argp[i++] = strdup(ffmpeg_exe.c_str());
405         argp[i++] = strdup("-i");
406         argp[i++] = strdup(infile.c_str());
407 #if 0 /* ffmpeg write original samplerate, use a3/SRC to resample */
408         argp[i++] = strdup("-ar");
409         argp[i] = (char*) calloc(7,sizeof(char)); snprintf(argp[i++], 7, "%"PRId64, samplerate);
410 #endif
411         argp[i++] = strdup("-ac");
412         argp[i] = (char*) calloc(3,sizeof(char)); snprintf(argp[i++], 3, "%i", m_audio.at(stream).channels);
413         argp[i++] = strdup("-map");
414         argp[i] = (char*) calloc(8,sizeof(char)); snprintf(argp[i++], 8, "0:%s", m_audio.at(stream).stream_id.c_str());
415         argp[i++] = strdup("-vn");
416         argp[i++] = strdup("-acodec");
417         argp[i++] = strdup("pcm_f32le");
418         argp[i++] = strdup("-y");
419         argp[i++] = strdup(outfile.c_str());
420         argp[i++] = (char *)0;
421         /* Note: argp is free()d in ~SystemExec */
422 #if 1 /* DEBUG */
423         if (debug_enable) { /* tentative debug mode */
424         printf("EXTRACT AUDIO:\n");
425         for (int i=0; i< 14; ++i) {
426           printf("%s ", argp[i]);
427         }
428         printf("\n");
429         }
430 #endif
431
432         ffcmd = new SystemExec(ffmpeg_exe, argp);
433         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_a, this, _1 ,_2));
434         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
435         if (ffcmd->start(2)) {
436                 ffexit();
437                 return false;
438         }
439         return true;
440 }
441
442
443 bool
444 TranscodeFfmpeg::transcode (std::string outfile, const int outw, const int outh, const int kbitps)
445 {
446         if (!probeok) return false;
447
448         char **argp;
449         int bitrate = kbitps;
450         int width = outw;
451         int height = outh;
452
453         if (width < 1 || width > m_width) { width = m_width; } /* don't allow upscaling */
454         if (height < 1 || height > m_height) { height = floor(width / m_aspect); }
455
456         if (bitrate == 0) {
457                 const double bitperpixel = .7; /* avg quality */
458                 bitrate = floor(m_fps * width * height * bitperpixel / 10000.0);
459         } else {
460                 bitrate = bitrate / 10;
461         }
462         if (bitrate < 10)  bitrate = 10;
463         if (bitrate > 1000) bitrate = 1000;
464
465         argp=(char**) calloc(16,sizeof(char*));
466         argp[0] = strdup(ffmpeg_exe.c_str());
467         argp[1] = strdup("-i");
468         argp[2] = strdup(infile.c_str());
469         argp[3] = strdup("-b:v");
470         argp[4] = (char*) calloc(7,sizeof(char)); snprintf(argp[4], 7, "%i0k", bitrate);
471         argp[5] = strdup("-s");
472         argp[6] = (char*) calloc(10,sizeof(char)); snprintf(argp[6], 10, "%ix%i", width, height);
473         argp[7] = strdup("-y");
474         argp[8] = strdup("-vcodec");
475         argp[9] = strdup("mjpeg");
476         argp[10] = strdup("-an");
477         argp[11] = strdup("-intra");
478         argp[12] = strdup("-g");
479         argp[13] = strdup("1");
480         argp[14] = strdup(outfile.c_str());
481         argp[15] = (char *)0;
482         /* Note: these are free()d in ~SystemExec */
483 #if 1 /* DEBUG */
484         if (debug_enable) { /* tentative debug mode */
485         printf("TRANSCODE VIDEO:\n");
486         for (int i=0; i< 15; ++i) {
487           printf("%s ", argp[i]);
488         }
489         printf("\n");
490         }
491 #endif
492         ffcmd = new SystemExec(ffmpeg_exe, argp);
493         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
494         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
495         if (ffcmd->start(2)) {
496                 ffexit();
497                 return false;
498         }
499         return true;
500 }
501
502 void
503 TranscodeFfmpeg::cancel ()
504 {
505         if (!ffcmd || !ffcmd->is_running()) { return;}
506         ffcmd->write_to_stdin("q");
507         sleep (1);
508         if (ffcmd) {
509           ffcmd->terminate();
510         }
511 }
512
513 void
514 TranscodeFfmpeg::ffexit ()
515 {
516         delete ffcmd;
517         ffcmd=0;
518         Finished(); /* EMIT SIGNAL */
519 }
520
521 void
522 TranscodeFfmpeg::ffprobeparse (std::string d, size_t /* s */)
523 {
524         ffoutput+=d;
525 }
526
527 void
528 TranscodeFfmpeg::ffmpegparse_a (std::string d, size_t /* s */)
529 {
530         const char *t;
531         int h,m,s; char f[7];
532         ARDOUR::framecnt_t p = -1;
533
534         if (!(t=strstr(d.c_str(), "time="))) { return; }
535
536         if (sscanf(t+5, "%d:%d:%d.%s",&h,&m,&s,f) == 4) {
537                 p = (ARDOUR::framecnt_t) floor( 100.0 * (
538                       h * 3600.0
539                     + m * 60.0
540                     + s * 1.0
541                     + atoi(f) / pow(10, strlen(f))
542                 ));
543                 p = p * m_fps / 100.0;
544                 if (p > m_duration ) { p = m_duration; }
545                 Progress(p, m_duration); /* EMIT SIGNAL */
546         } else {
547                 Progress(0, 0); /* EMIT SIGNAL */
548         }
549 }
550
551 void
552 TranscodeFfmpeg::ffmpegparse_v (std::string d, size_t /* s */)
553 {
554         if (strstr(d.c_str(), "ERROR") || strstr(d.c_str(), "Error") || strstr(d.c_str(), "error")) {
555                 warning << "ffmpeg-error: " << d << endmsg;
556         }
557         if (strncmp(d.c_str(), "frame=",6)) {
558 #if 1 /* DEBUG */
559                 if (debug_enable) {
560                         d.erase(d.find_last_not_of(" \t\r\n") + 1);
561                   printf("ffmpeg: '%s'\n", d.c_str());
562                 }
563 #endif
564                 Progress(0, 0); /* EMIT SIGNAL */
565                 return;
566         }
567         ARDOUR::framecnt_t f = atol(d.substr(6));
568         if (f == 0) {
569                 Progress(0, 0); /* EMIT SIGNAL */
570         } else {
571                 Progress(f, m_duration); /* EMIT SIGNAL */
572         }
573 }