From c1ad6121ca4471bbfd0e967f7b593009caf38e40 Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Tue, 9 Feb 2016 20:24:54 +0100 Subject: [PATCH] BMediaRecorder: Solve possible problem with node references * Since the BMediaRecorder have an it's own estabilished policy relating releasing the producer node we will not interfere with it except when we are controlled from Cortex. --- headers/private/media/MediaRecorderNode.h | 4 ++- src/kits/media/MediaRecorder.cpp | 10 ++++--- src/kits/media/MediaRecorderNode.cpp | 33 +++++++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/headers/private/media/MediaRecorderNode.h b/headers/private/media/MediaRecorderNode.h index 746e5ace46..616ef2da6b 100644 --- a/headers/private/media/MediaRecorderNode.h +++ b/headers/private/media/MediaRecorderNode.h @@ -1,5 +1,5 @@ /* - * Copyright 2014, Dario Casalinuovo + * Copyright 2014-2016, Dario Casalinuovo * Copyright 1999, Be Incorporated * All Rights Reserved. * This file may be used under the terms of the Be Sample Code License. @@ -32,6 +32,7 @@ public: void GetInput(media_input* input); void SetDataEnabled(bool enabled); + void ActivateInternalConnect(bool connectMode); protected: @@ -106,6 +107,7 @@ protected: media_format fOKFormat; media_input fInput; BString fName; + bool fConnectMode; }; } diff --git a/src/kits/media/MediaRecorder.cpp b/src/kits/media/MediaRecorder.cpp index dd3347cbd5..2871dbe35a 100644 --- a/src/kits/media/MediaRecorder.cpp +++ b/src/kits/media/MediaRecorder.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015, Hamish Morrison - * Copyright 2014, Dario Casalinuovo + * Copyright 2014-2016, Dario Casalinuovo * Copyright 1999, Be Incorporated * All Rights Reserved. * This file may be used under the terms of the Be Sample Code License. @@ -388,7 +388,7 @@ BMediaRecorder::_Connect(const media_node& node, fOutputNode = node; - // figure out the output provided + // Figure out the output provided if (output != NULL) { ourOutput = *output; } else if (err == B_OK) { @@ -413,10 +413,14 @@ BMediaRecorder::_Connect(const media_node& node, if (ourOutput.source == media_source::null) return B_MEDIA_BAD_SOURCE; - // find our Node's free input + // Find our Node's free input media_input ourInput; fNode->GetInput(&ourInput); + // Acknowledge the node that we already know + // who is our producer node. + fNode->ActivateInternalConnect(false); + return BMediaRoster::CurrentRoster()->Connect(ourOutput.source, ourInput.destination, &ourFormat, &ourOutput, &ourInput, BMediaRoster::B_CONNECT_MUTED); diff --git a/src/kits/media/MediaRecorderNode.cpp b/src/kits/media/MediaRecorderNode.cpp index 40371ac43a..40609cd237 100644 --- a/src/kits/media/MediaRecorderNode.cpp +++ b/src/kits/media/MediaRecorderNode.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014, Dario Casalinuovo + * Copyright 2014-2016, Dario Casalinuovo * Copyright 1999, Be Incorporated * All Rights Reserved. * This file may be used under the terms of the Be Sample Code License. @@ -25,7 +25,8 @@ BMediaRecorderNode::BMediaRecorderNode(const char* name, BMediaNode(name), BMediaEventLooper(), BBufferConsumer(type), - fRecorder(recorder) + fRecorder(recorder), + fConnectMode(true) { CALLED(); @@ -140,6 +141,13 @@ BMediaRecorderNode::SetDataEnabled(bool enabled) } +void +BMediaRecorderNode::ActivateInternalConnect(bool connectMode) +{ + fConnectMode = connectMode; +} + + void BMediaRecorderNode::HandleEvent(const media_timed_event* event, bigtime_t lateness, bool realTimeEvent) @@ -298,16 +306,17 @@ BMediaRecorderNode::Connected(const media_source &producer, fInput.format = withFormat; *outInput = fInput; - // This is a workaround needed for us to get the node - // so that our owner class can do it's operations. - media_node node; - BMediaRosterEx* roster = MediaRosterEx(BMediaRoster::CurrentRoster()); - if (roster->GetNodeFor(roster->NodeIDFor(producer.port), &node) != B_OK) - return B_MEDIA_BAD_NODE; - - fRecorder->fOutputNode = node; - fRecorder->fReleaseOutputNode = true; + if (fConnectMode == true) { + // This is a workaround needed for us to get the node + // so that our owner class can do it's operations. + media_node node; + BMediaRosterEx* roster = MediaRosterEx(BMediaRoster::CurrentRoster()); + if (roster->GetNodeFor(roster->NodeIDFor(producer.port), &node) != B_OK) + return B_MEDIA_BAD_NODE; + fRecorder->fOutputNode = node; + fRecorder->fReleaseOutputNode = true; + } fRecorder->SetUpConnection(producer); fRecorder->fConnected = true; @@ -322,6 +331,8 @@ BMediaRecorderNode::Disconnected(const media_source& producer, CALLED(); fInput.source = media_source::null; + // Reset the connection mode + fConnectMode = true; fRecorder->fConnected = false; fInput.format = fOKFormat; }