void VideoRecorder::recorderStateChanged(QMediaRecorder::State state)
{
    qDebug() << "REC STATE " << state;
    switch (state) {
    case QMediaRecorder::StoppedState:
        emit stoppedRecording();
        break;
    case QMediaRecorder::RecordingState:
        emit startedRecording();
        break;
    }
}
void Call::startRecording(bool force) {
	if (force)
		hideConfirmation(2);

	if (isRecording)
		return;

	if (handler->isConferenceRecording(confID)) {
		debug(QString("Call %1: call is part of a conference that is already being recorded").arg(id));
		return;
	}

	if (force) {
		emit showLegalInformation();
	} else {
		setShouldRecord();
		if (shouldRecord == 0)
			return;
		if (shouldRecord == 1)
			ask();
		else // shouldRecord == 2
			emit showLegalInformation();
	}

	debug(QString("Call %1: start recording").arg(id));

	// set up encoder for appropriate format

	timeStartRecording = QDateTime::currentDateTime();
	QString fn = constructFileName();

	stereo = preferences.get(Pref::OutputStereo).toBool();
	stereoMix = preferences.get(Pref::OutputStereoMix).toInt();

	QString format = preferences.get(Pref::OutputFormat).toString();

	if (format == "wav")
		writer = new WaveWriter;
	else if (format == "mp3")
		writer = new Mp3Writer;
	else /*if (format == "vorbis")*/
		writer = new VorbisWriter;

	if (preferences.get(Pref::OutputSaveTags).toBool())
		writer->setTags(constructCommentTag(), timeStartRecording);

	bool b = writer->open(fn, skypeSamplingRate, stereo);
	fileName = writer->fileName();

	if (!b) {
		QMessageBox *box = new QMessageBox(QMessageBox::Critical, PROGRAM_NAME " - Error",
			QString(PROGRAM_NAME " could not open the file %1.  Please verify the output file pattern.").arg(fileName));
		box->setWindowModality(Qt::NonModal);
		box->setAttribute(Qt::WA_DeleteOnClose);
		box->show();
		removeFile();
		delete writer;
		return;
	}

	serverLocal = new QTcpServer(this);
	serverLocal->listen();
	connect(serverLocal, SIGNAL(newConnection()), this, SLOT(acceptLocal()));
	serverRemote = new QTcpServer(this);
	serverRemote->listen();
	connect(serverRemote, SIGNAL(newConnection()), this, SLOT(acceptRemote()));

	QString rep1 = skype->sendWithReply(QString("ALTER CALL %1 SET_CAPTURE_MIC PORT=\"%2\"").arg(id).arg(serverLocal->serverPort()));
	QString rep2 = skype->sendWithReply(QString("ALTER CALL %1 SET_OUTPUT SOUNDCARD=\"default\" PORT=\"%2\"").arg(id).arg(serverRemote->serverPort()));

	if (!rep1.startsWith("ALTER CALL ") || !rep2.startsWith("ALTER CALL")) {
		QMessageBox *box = new QMessageBox(QMessageBox::Critical, PROGRAM_NAME " - Error",
			QString(PROGRAM_NAME " could not obtain the audio streams from Skype and can thus not record this call.\n\n"
			"The replies from Skype were:\n%1\n%2").arg(rep1, rep2));
		box->setWindowModality(Qt::NonModal);
		box->setAttribute(Qt::WA_DeleteOnClose);
		box->show();
		removeFile();
		delete writer;
		delete serverRemote;
		delete serverLocal;
		return;
	}

	if (preferences.get(Pref::DebugWriteSyncFile).toBool()) {
		syncFile.setFileName(fn + ".sync");
		syncFile.open(QIODevice::WriteOnly);
		syncTime.start();
	}

	isRecording = true;
	emit startedRecording(id);
}