fixed crashing bug by computing and setting internal latency properly

and checking buffer validity when a buffer is received.  removed the
downstream latency variable because there is no downstream from this
node.  also added helpful comments.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1080 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty
2002-09-18 07:37:15 +00:00
parent 39a0622e4b
commit 378762da1d
2 changed files with 35 additions and 6 deletions
@@ -108,7 +108,7 @@ void MediaWriter::NodeRegistered(void)
// now we can do this // now we can do this
input.node = Node(); input.node = Node();
input.destination.id = 0; input.destination.id = 0;
input.destination.port = input.node.port; input.destination.port = input.node.port; // same as ControlPort()
// creates the parameter web and starts the looper thread // creates the parameter web and starts the looper thread
AbstractFileInterfaceNode::NodeRegistered(); AbstractFileInterfaceNode::NodeRegistered();
@@ -420,8 +420,28 @@ status_t MediaWriter::Connected(
delete group; delete group;
} }
// XXX: set the latency here? // compute the latency or just guess
// SetEventLatency(latency); if (GetCurrentFile() != 0) {
bigtime_t start, end;
uint8 * data = new uint8[input.format.u.multistream.max_chunk_size]; // <- buffer group buffer size
ssize_t bytesWritten = 0;
{ // timed section
start = TimeSource()->RealTime();
bytesWritten = GetCurrentFile()->Write(data,input.format.u.multistream.max_chunk_size);
end = TimeSource()->RealTime();
}
delete data;
GetCurrentFile()->Seek(-bytesWritten,SEEK_CUR); // put it back where we found it
fInternalLatency = end - start;
fprintf(stderr," internal latency from disk write = %i\n",fInternalLatency);
} else {
fInternalLatency = 500; // just guess
fprintf(stderr," internal latency guessed = %i\n",fInternalLatency);
}
SetEventLatency(fInternalLatency);
// record the agreed upon values // record the agreed upon values
input.source = producer; input.source = producer;
@@ -486,8 +506,8 @@ status_t MediaWriter::SeekTagRequested(
uint32 * out_flags) uint32 * out_flags)
{ {
fprintf(stderr,"MediaWriter::SeekTagRequested\n"); fprintf(stderr,"MediaWriter::SeekTagRequested\n");
BBufferConsumer::SeekTagRequested(destination,in_target_time,in_flags, return BBufferConsumer::SeekTagRequested(destination,in_target_time,in_flags,
out_seek_tag,out_tagged_time,out_flags); out_seek_tag,out_tagged_time,out_flags);
} }
// -------------------------------------------------------- // // -------------------------------------------------------- //
@@ -505,6 +525,14 @@ status_t MediaWriter::HandleBuffer(
{ {
fprintf(stderr,"MediaWriter::HandleBuffer\n"); fprintf(stderr,"MediaWriter::HandleBuffer\n");
BBuffer * buffer = const_cast<BBuffer*>((BBuffer*)event->pointer); BBuffer * buffer = const_cast<BBuffer*>((BBuffer*)event->pointer);
if (buffer == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
if (buffer->Header()->destination != input.destination.id) {
fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION\n");
return B_MEDIA_BAD_DESTINATION;
}
WriteFileBuffer(buffer); WriteFileBuffer(buffer);
buffer->Recycle(); buffer->Recycle();
return B_OK; return B_OK;
@@ -575,6 +603,8 @@ status_t MediaWriter::WriteFileBuffer(
fprintf(stderr,"<- B_NO_INIT\n"); fprintf(stderr,"<- B_NO_INIT\n");
return B_NO_INIT; return B_NO_INIT;
} }
fprintf(stderr," writing %i bytes at %i\n",
buffer->SizeUsed(),GetCurrentFile()->Position());
ssize_t bytesWriten = GetCurrentFile()->Write(buffer->Data(),buffer->SizeUsed()); ssize_t bytesWriten = GetCurrentFile()->Write(buffer->Data(),buffer->SizeUsed());
if (bytesWriten < 0) { if (bytesWriten < 0) {
fprintf(stderr,"<- B_FILE_ERROR\n"); fprintf(stderr,"<- B_FILE_ERROR\n");
@@ -184,7 +184,6 @@ private:
bool fInputEnabled; bool fInputEnabled;
BBufferGroup * fBufferGroup; BBufferGroup * fBufferGroup;
bigtime_t fDownstreamLatency;
bigtime_t fInternalLatency; bigtime_t fInternalLatency;
// this is computed from the real (negotiated) chunk size and bit rate, // this is computed from the real (negotiated) chunk size and bit rate,
// not the defaults that are in the parameters // not the defaults that are in the parameters