BMediaRecorder: Rework to allow external connections

* This required to review various parts of the code, and
isn't probably still perfect. The main problem was an attributes
hell where redondance created a lot of problems, all this data
is now controlled mostly by the node.
* Header indentation changes needed too.
This commit is contained in:
Dario Casalinuovo
2016-02-09 13:33:09 +01:00
parent 801b3e3bf4
commit 2a2e352a4a
4 changed files with 129 additions and 105 deletions
+10 -5
View File
@@ -46,6 +46,7 @@ public:
void SetAcceptedFormat( void SetAcceptedFormat(
const media_format& format); const media_format& format);
const media_format& AcceptedFormat() const;
virtual status_t Start(bool force = false); virtual status_t Start(bool force = false);
virtual status_t Stop(bool force = false); virtual status_t Stop(bool force = false);
@@ -66,13 +67,18 @@ public:
const media_format& Format() const; const media_format& Format() const;
const media_output& MediaOutput() const;
const media_input& MediaInput() const;
protected: protected:
// Get the producer node source
const media_source& MediaSource() const;
// This is the our own input
const media_input& MediaInput() const;
virtual void BufferReceived(void* buffer, size_t size, virtual void BufferReceived(void* buffer, size_t size,
const media_header& header); const media_header& header);
status_t SetUpConnection(media_input ourInput,
media_source outputSource);
private: private:
status_t _Connect(const media_node& mediaNode, status_t _Connect(const media_node& mediaNode,
@@ -98,10 +104,9 @@ private:
NotifyFunc fNotifyHook; NotifyFunc fNotifyHook;
media_node fOutputNode; media_node fOutputNode;
media_output fOutput; media_source fOutputSource;
BMediaRecorderNode* fNode; BMediaRecorderNode* fNode;
media_input fInput;
void* fBufferCookie; void* fBufferCookie;
uint32 fPadding[32]; uint32 fPadding[32];
+2 -1
View File
@@ -27,8 +27,9 @@ public:
// TODO these are not thread safe; we should fix that... // TODO these are not thread safe; we should fix that...
void SetAcceptedFormat(const media_format& format); void SetAcceptedFormat(const media_format& format);
const media_format& AcceptedFormat() const;
status_t GetInput(media_input* outInput); void GetInput(media_input* input);
void SetDataEnabled(bool enabled); void SetDataEnabled(bool enabled);
+44 -42
View File
@@ -72,6 +72,15 @@ BMediaRecorder::SetAcceptedFormat(const media_format& format)
} }
const media_format&
BMediaRecorder::AcceptedFormat() const
{
CALLED();
return fNode->AcceptedFormat();
}
status_t status_t
BMediaRecorder::SetHooks(ProcessFunc recordFunc, NotifyFunc notifyFunc, BMediaRecorder::SetHooks(ProcessFunc recordFunc, NotifyFunc notifyFunc,
void* cookie) void* cookie)
@@ -216,10 +225,13 @@ BMediaRecorder::Disconnect()
if (err != B_OK) if (err != B_OK)
return err; return err;
media_input ourInput;
fNode->GetInput(&ourInput);
// do the disconnect // do the disconnect
err = BMediaRoster::CurrentRoster()->Disconnect( err = BMediaRoster::CurrentRoster()->Disconnect(
fOutputNode.node, fOutput.source, fOutputNode.node, fOutputSource,
fNode->Node().node, fInput.destination); fNode->Node().node, ourInput.destination);
if (fReleaseOutputNode) { if (fReleaseOutputNode) {
BMediaRoster::Roster()->ReleaseNode(fOutputNode); BMediaRoster::Roster()->ReleaseNode(fOutputNode);
@@ -312,12 +324,12 @@ BMediaRecorder::IsConnected() const
} }
const media_output& const media_source&
BMediaRecorder::MediaOutput() const BMediaRecorder::MediaSource() const
{ {
CALLED(); CALLED();
return fOutput; return fOutputSource;
} }
@@ -326,7 +338,9 @@ BMediaRecorder::MediaInput() const
{ {
CALLED(); CALLED();
return fInput; media_input* input = NULL;
fNode->GetInput(input);
return *input;
} }
@@ -335,7 +349,25 @@ BMediaRecorder::Format() const
{ {
CALLED(); CALLED();
return fOutput.format; return fNode->AcceptedFormat();
}
status_t
BMediaRecorder::SetUpConnection(media_input ourInput, media_source outputSource)
{
fOutputSource = outputSource;
// Perform the connection
media_node timeSource;
if ((fOutputNode.kind & B_TIME_SOURCE) != 0)
timeSource = fOutputNode;
else
BMediaRoster::Roster()->GetTimeSource(&timeSource);
// Set time source
return BMediaRoster::Roster()->SetTimeSourceFor(fNode->Node().node,
timeSource.node);
} }
@@ -381,45 +413,15 @@ BMediaRecorder::_Connect(const media_node& node,
if (ourOutput.source == media_source::null) if (ourOutput.source == media_source::null)
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
fOutputSource = ourOutput.source;
// find our Node's free input // find our Node's free input
media_input ourInput; media_input ourInput;
err = fNode->GetInput(&ourInput); fNode->GetInput(&ourInput);
if (err != B_OK)
return err;
media_node timeSource; return BMediaRoster::CurrentRoster()->Connect(fOutputSource,
if ((node.kind & B_TIME_SOURCE) != 0) ourInput.destination, &ourFormat, &ourOutput, &ourInput,
timeSource = node;
else
BMediaRoster::Roster()->GetTimeSource(&timeSource);
// set time source
err = BMediaRoster::Roster()->SetTimeSourceFor(fNode->Node().node,
timeSource.node);
if (err != B_OK)
return err;
// start the recorder node (it's always running)
err = BMediaRoster::CurrentRoster()->StartNode(fOutputNode,
fNode->TimeSource()->Now());
if (err != B_OK)
return err;
// perform the connection
fOutput = ourOutput;
fInput = ourInput;
err = BMediaRoster::CurrentRoster()->Connect(fOutput.source,
fInput.destination, &ourFormat, &fOutput, &fInput,
BMediaRoster::B_CONNECT_MUTED); BMediaRoster::B_CONNECT_MUTED);
if (err != B_OK)
return err;
fConnected = true;
return B_OK;
} }
+23 -7
View File
@@ -10,6 +10,8 @@
#include <Buffer.h> #include <Buffer.h>
#include <scheduler.h> #include <scheduler.h>
#include <MediaRoster.h>
#include <MediaRosterEx.h>
#include <TimedEventQueue.h> #include <TimedEventQueue.h>
#include <TimeSource.h> #include <TimeSource.h>
@@ -27,6 +29,7 @@ BMediaRecorderNode::BMediaRecorderNode(const char* name,
{ {
CALLED(); CALLED();
fInput.node = Node();
fInput.destination.id = 1; fInput.destination.id = 1;
fInput.destination.port = ControlPort(); fInput.destination.port = ControlPort();
@@ -105,15 +108,22 @@ BMediaRecorderNode::SetAcceptedFormat(const media_format& format)
} }
status_t const media_format&
BMediaRecorderNode::AcceptedFormat() const
{
CALLED();
return fOKFormat;
}
void
BMediaRecorderNode::GetInput(media_input* outInput) BMediaRecorderNode::GetInput(media_input* outInput)
{ {
CALLED(); CALLED();
fInput.node = Node(); fInput.node = Node();
*outInput = fInput; *outInput = fInput;
return B_OK;
} }
@@ -287,8 +297,16 @@ BMediaRecorderNode::Connected(const media_source &producer,
fInput.format = withFormat; fInput.format = withFormat;
*outInput = fInput; *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());
roster->GetNodeFor(roster->NodeIDFor(producer.port), &node);
fRecorder->fOutputNode = node;
fRecorder->fReleaseOutputNode = true;
fRecorder->SetUpConnection(fInput, producer);
fRecorder->fConnected = true; fRecorder->fConnected = true;
fRecorder->fInput = fInput;
return B_OK; return B_OK;
} }
@@ -301,10 +319,8 @@ BMediaRecorderNode::Disconnected(const media_source& producer,
CALLED(); CALLED();
fInput.source = media_source::null; fInput.source = media_source::null;
fRecorder->fConnected = false; fRecorder->fConnected = false;
fInput.format = fOKFormat;
fRecorder->fInput.format = fOKFormat;
} }