diff --git a/NanaRecorder/NanaRecorder.cpp b/NanaRecorder/NanaRecorder.cpp index 323cdfc..55aab38 100644 --- a/NanaRecorder/NanaRecorder.cpp +++ b/NanaRecorder/NanaRecorder.cpp @@ -66,7 +66,10 @@ void NanaRecorder::startBtnClicked() { info.insert("recordPath", path); m_recorder = onlyet::createRecorder(info); } - m_recorder->startRecord(); + if (-1 == m_recorder->startRecord()) { + qDebug() << "startRecord failed"; + return; + } m_recordDuration = 0; ui.durationLabel->setText("00:00:00"); diff --git a/RecordCore/src/AudioCapture.cpp b/RecordCore/src/AudioCapture.cpp index 56fa6e1..bcadb80 100644 --- a/RecordCore/src/AudioCapture.cpp +++ b/RecordCore/src/AudioCapture.cpp @@ -92,6 +92,7 @@ int AudioCapture::initCapture(AudioCaptureDevice dev) { string audioDeviceName = FFmpegHelper::getAudioDevice(dev); if ("" == audioDeviceName) { + qCritical() << "Can not find audio device"; return -1; } if ((ret = avformat_open_input(&m_aFmtCtx, audioDeviceName.c_str(), ifmt, &options)) != 0) { diff --git a/RecordCore/src/FFmpegHelper.cpp b/RecordCore/src/FFmpegHelper.cpp index ff89c28..0beedd2 100644 --- a/RecordCore/src/FFmpegHelper.cpp +++ b/RecordCore/src/FFmpegHelper.cpp @@ -113,7 +113,6 @@ std::string FFmpegHelper::getAudioDevice(AudioCaptureDevice type) { hr = pCreateDevEnum->CreateClassEnumerator(guid, &pEm, 0); if (hr != NOERROR) { ::CoUninitialize(); - //return ""; return ret; } @@ -137,14 +136,9 @@ std::string FFmpegHelper::getAudioDevice(AudioCaptureDevice type) { for (const auto& dev : audioDevSet) { if (tmpName.find(dev) != string::npos) { -#if 0 - tmpName = QString::fromLocal8Bit(tmpName.c_str()).toStdString(); - qDebug() << "Audio device:" << QString::fromLocal8Bit(tmpName.c_str()); -#else // 包含中文需要转UTF8编码 tmpName = AnsiToUTF8(tmpName.c_str(), tmpName.length()); qInfo() << "Audio device:" << QString::fromStdString(tmpName); -#endif ret = tmpName; isFound = true; break; diff --git a/RecordCore/src/Recorder.cpp b/RecordCore/src/Recorder.cpp index 11750a3..6c095e2 100644 --- a/RecordCore/src/Recorder.cpp +++ b/RecordCore/src/Recorder.cpp @@ -138,11 +138,12 @@ int Recorder::startRecord() { FFmpegHelper::registerAll(); - startCapture(); - // init + int ret = 0; + ret = startCapture(); + if (ret != 0) return ret; + m_videoFrameQueue->initBuf(g_record.outWidth, g_record.outHeight, AV_PIX_FMT_YUV420P); - int ret = 0; if (m_amixFilter) { ret = m_amixFilter->init( {nullptr, nullptr, @@ -158,7 +159,7 @@ int Recorder::startRecord() { m_microphoneCap->channel(), m_microphoneCap->channelLayout()}, {nullptr, nullptr, {1, AV_TIME_BASE}, g_record.sampleRate, AV_SAMPLE_FMT_FLTP, g_record.channel, av_get_default_channel_layout(g_record.channel)}); - if (ret != 0) return -1; + if (ret != 0) return ret; m_amixFilter->setFilterFrameCb(bind(static_cast(&Recorder::writeAudioFrameCb), this, _1)); m_amixFilter->start(); @@ -179,7 +180,7 @@ int Recorder::startRecord() { ctx_out.sample_rate = g_record.sampleRate; ret = m_resampleFilter->init(ctx_in, ctx_out); - if (ret != 0) return -1; + if (ret != 0) return ret; m_resampleFilter->setFilterFrameCb(bind(static_cast(&Recorder::writeAudioFrameCb), this, _1)); m_resampleFilter->start(); @@ -187,14 +188,13 @@ int Recorder::startRecord() { m_outputer->init(); - // start m_startTime = duration_cast(chrono::system_clock::now().time_since_epoch()).count(); qInfo() << "start time:" << QDateTime::fromMSecsSinceEpoch(m_startTime / 1000).toString("yyyy-MM-dd hh:mm:ss.zzz"); m_outputer->start(m_startTime); g_record.status = Running; - return 0; + return ret; } int Recorder::pauseRecord() { @@ -236,15 +236,17 @@ int Recorder::stopRecord() { return 0; } -void Recorder::startCapture() { - int ret; - m_videoCap->startCapture(); +int Recorder::startCapture() { + int ret = 0; + ret = m_videoCap->startCapture(); + if (-1 == ret) return ret; if (g_record.enableAudio) { if (m_speakerCap) { ret = m_speakerCap->startCapture(AudioCaptureDevice::Speaker); // 找不到音频或打开失败 if (-1 == ret) { g_record.enableAudio = false; + return ret; } } if (m_microphoneCap) { @@ -252,9 +254,11 @@ void Recorder::startCapture() { // 找不到音频或打开失败 if (-1 == ret) { g_record.enableAudio = false; + return ret; } } } + return ret; } void Recorder::stopCapture() { diff --git a/RecordCore/src/Recorder.h b/RecordCore/src/Recorder.h index a1c61b1..8714f39 100644 --- a/RecordCore/src/Recorder.h +++ b/RecordCore/src/Recorder.h @@ -40,7 +40,7 @@ class Recorder : public IRecorder { int stopRecord() override; private: - void startCapture(); + int startCapture(); void stopCapture(); void writeVideoFrameCb(AVFrame* frame, const VideoCaptureInfo& info);