From 7b83e044e7b0115b8e2a6e483efb3720b6d4fc4c Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Tue, 9 Feb 2016 13:23:14 +0100 Subject: [PATCH] SoundRecorder: Fix connection and disconnection from Cortex * SoundRecorder can now be connected and disconnected safely, due to some unknown reason, probably format negotiation problems, ATM we need a system mixer between. * The normal behavior is unchanged, when the record button is pressed it will record from the preferred audio interface and disconnect on stop. But when the connection is made manually it will stay connected until the user explictly disconnect it. * To make it work, instantiate a system mixer, connect the output to SoundRecorder, instantiate a node like the ToneProducer, and connect it's output to the mixer input. Press the record button and check the Mixer has started from the Cortex transport, if not, start it. --- src/apps/soundrecorder/RecorderWindow.cpp | 32 ++++++++++++----------- src/apps/soundrecorder/RecorderWindow.h | 1 + 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/apps/soundrecorder/RecorderWindow.cpp b/src/apps/soundrecorder/RecorderWindow.cpp index aebfc7fda8..06bcdc6391 100644 --- a/src/apps/soundrecorder/RecorderWindow.cpp +++ b/src/apps/soundrecorder/RecorderWindow.cpp @@ -125,6 +125,7 @@ RecorderWindow::RecorderWindow() fInputField = NULL; fRecorder = NULL; fRecording = false; + fExternalConnection = false; fTempCount = -1; fButtonState = btnPaused; @@ -693,7 +694,7 @@ RecorderWindow::Record(BMessage * message) fRecFile.Seek(sizeof(struct wave_struct), SEEK_SET); - // Hook up input + // Hook up input err = MakeRecordConnection(fAudioInputNode); if (err < B_OK) { ErrorAlert(B_TRANSLATE("Cannot connect to the selected sound input"), @@ -702,7 +703,6 @@ RecorderWindow::Record(BMessage * message) fRecEntry.Unset(); return; } - fRecorder->Start(); } @@ -892,15 +892,14 @@ RecorderWindow::MakeRecordConnection(const media_node & input) return B_BUSY; } + // Get a format, any format. + fRecordFormat.u.raw_audio = audioOutput.format.u.raw_audio; + fExternalConnection = false; } else { - CONNECT((stderr, "RecorderWindow::MakeRecordConnection():" - " audio input node already connected\n")); - - return B_BUSY; + fRecordFormat.u.raw_audio = fRecorder->AcceptedFormat().u.raw_audio; + fExternalConnection = true; } - // Get a format, any format. - fRecordFormat.u.raw_audio = audioOutput.format.u.raw_audio; fRecordFormat.type = B_MEDIA_RAW_AUDIO; // Tell the consumer where we want data to go. @@ -932,12 +931,6 @@ RecorderWindow::MakeRecordConnection(const media_node & input) status_t RecorderWindow::BreakRecordConnection() { - status_t err = B_OK; - - err = fRecorder->Stop(true); - if (err < B_OK) - return err; - return fRecorder->Disconnect(); } @@ -949,7 +942,16 @@ RecorderWindow::StopRecording() return B_OK; fRecording = false; - BreakRecordConnection(); + status_t err = B_OK; + err = fRecorder->Stop(true); + if (err < B_OK) + return err; + + // We maintain the connection active + // if the user connected us from Cortex. + if (!fExternalConnection) { + BreakRecordConnection(); + } fRecorder->SetHooks(NULL, NULL, NULL); diff --git a/src/apps/soundrecorder/RecorderWindow.h b/src/apps/soundrecorder/RecorderWindow.h index d0c405ed8a..9cf0893061 100644 --- a/src/apps/soundrecorder/RecorderWindow.h +++ b/src/apps/soundrecorder/RecorderWindow.h @@ -96,6 +96,7 @@ private: BMediaRecorder * fRecorder; BSoundPlayer * fPlayer; bool fRecording; + bool fExternalConnection; SoundListView * fSoundList; BDirectory fTempDir; int fTempCount;