* Automatic white space cleanup

* Small hack to display at least some frames (one every 15 frames) when the
  CPU is utterly incapable of decoding video fast enough.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31610 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-07-16 22:20:43 +00:00
parent da82d38f42
commit 36c088531f
@@ -90,7 +90,7 @@ VideoProducer::AddOn(int32* _internalId) const
} }
status_t status_t
VideoProducer::HandleMessage(int32 message, const void* data, size_t size) VideoProducer::HandleMessage(int32 message, const void* data, size_t size)
{ {
return B_ERROR; return B_ERROR;
@@ -112,7 +112,7 @@ VideoProducer::RequestCompleted(const media_request_info& info)
} }
void void
VideoProducer::NodeRegistered() VideoProducer::NodeRegistered()
{ {
if (fInitStatus != B_OK) { if (fInitStatus != B_OK) {
@@ -124,7 +124,7 @@ VideoProducer::NodeRegistered()
fOutput.source.port = ControlPort(); fOutput.source.port = ControlPort();
fOutput.source.id = 0; fOutput.source.id = 0;
fOutput.destination = media_destination::null; fOutput.destination = media_destination::null;
strcpy(fOutput.name, Name()); strcpy(fOutput.name, Name());
// fill with wild cards at this point in time // fill with wild cards at this point in time
fOutput.format.type = B_MEDIA_RAW_VIDEO; fOutput.format.type = B_MEDIA_RAW_VIDEO;
@@ -190,7 +190,7 @@ printf("VideoProducer::SetRunMode(%d)\n", mode);
} }
void void
VideoProducer::HandleEvent(const media_timed_event* event, VideoProducer::HandleEvent(const media_timed_event* event,
bigtime_t lateness, bool realTimeEvent) bigtime_t lateness, bool realTimeEvent)
{ {
@@ -219,7 +219,7 @@ VideoProducer::HandleEvent(const media_timed_event* event,
} }
void void
VideoProducer::CleanUpEvent(const media_timed_event *event) VideoProducer::CleanUpEvent(const media_timed_event *event)
{ {
BMediaEventLooper::CleanUpEvent(event); BMediaEventLooper::CleanUpEvent(event);
@@ -247,7 +247,7 @@ VideoProducer::DeleteHook(BMediaNode* node)
} }
status_t status_t
VideoProducer::FormatSuggestionRequested(media_type type, int32 quality, VideoProducer::FormatSuggestionRequested(media_type type, int32 quality,
media_format* _format) media_format* _format)
{ {
@@ -263,11 +263,11 @@ VideoProducer::FormatSuggestionRequested(media_type type, int32 quality,
} }
status_t status_t
VideoProducer::FormatProposal(const media_source& output, media_format* format) VideoProducer::FormatProposal(const media_source& output, media_format* format)
{ {
#ifdef TRACE_VIDEO_PRODUCER #ifdef TRACE_VIDEO_PRODUCER
char string[256]; char string[256];
string_for_format(*format, string, 256); string_for_format(*format, string, 256);
FUNCTION("FormatProposal(%s)\n", string); FUNCTION("FormatProposal(%s)\n", string);
#endif #endif
@@ -292,11 +292,11 @@ VideoProducer::FormatProposal(const media_source& output, media_format* format)
// change any wild cards to specific values // change any wild cards to specific values
return ret; return ret;
} }
status_t status_t
VideoProducer::FormatChangeRequested(const media_source& source, VideoProducer::FormatChangeRequested(const media_source& source,
const media_destination& destination, media_format* ioFormat, const media_destination& destination, media_format* ioFormat,
int32 *_deprecated_) int32 *_deprecated_)
@@ -305,12 +305,12 @@ VideoProducer::FormatChangeRequested(const media_source& source,
if (source != fOutput.source) if (source != fOutput.source)
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
return B_ERROR; return B_ERROR;
} }
status_t status_t
VideoProducer::GetNextOutput(int32* cookie, media_output* outOutput) VideoProducer::GetNextOutput(int32* cookie, media_output* outOutput)
{ {
if (!outOutput) if (!outOutput)
@@ -318,7 +318,7 @@ VideoProducer::GetNextOutput(int32* cookie, media_output* outOutput)
if ((*cookie) != 0) if ((*cookie) != 0)
return B_BAD_INDEX; return B_BAD_INDEX;
*outOutput = fOutput; *outOutput = fOutput;
(*cookie)++; (*cookie)++;
@@ -326,7 +326,7 @@ VideoProducer::GetNextOutput(int32* cookie, media_output* outOutput)
} }
status_t status_t
VideoProducer::DisposeOutputCookie(int32 cookie) VideoProducer::DisposeOutputCookie(int32 cookie)
{ {
TOUCH(cookie); TOUCH(cookie);
@@ -335,7 +335,7 @@ VideoProducer::DisposeOutputCookie(int32 cookie)
} }
status_t status_t
VideoProducer::SetBufferGroup(const media_source& forSource, VideoProducer::SetBufferGroup(const media_source& forSource,
BBufferGroup *group) BBufferGroup *group)
{ {
@@ -350,7 +350,7 @@ VideoProducer::SetBufferGroup(const media_source& forSource,
} }
status_t status_t
VideoProducer::VideoClippingChanged(const media_source& forSource, VideoProducer::VideoClippingChanged(const media_source& forSource,
int16 numShorts, int16* clipData, const media_video_display_info& display, int16 numShorts, int16* clipData, const media_video_display_info& display,
int32* _deprecated_) int32* _deprecated_)
@@ -362,7 +362,7 @@ VideoProducer::VideoClippingChanged(const media_source& forSource,
} }
status_t status_t
VideoProducer::GetLatency(bigtime_t* _latency) VideoProducer::GetLatency(bigtime_t* _latency)
{ {
if (!_latency) if (!_latency)
@@ -374,7 +374,7 @@ VideoProducer::GetLatency(bigtime_t* _latency)
} }
status_t status_t
VideoProducer::PrepareToConnect(const media_source& source, VideoProducer::PrepareToConnect(const media_source& source,
const media_destination& destination, media_format* format, const media_destination& destination, media_format* format,
media_source* outSource, char* outName) media_source* outSource, char* outName)
@@ -390,7 +390,7 @@ VideoProducer::PrepareToConnect(const media_source& source,
if (source != fOutput.source) if (source != fOutput.source)
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
if (fOutput.destination != media_destination::null) { if (fOutput.destination != media_destination::null) {
ERROR("PrepareToConnect() - destination != null.\n"); ERROR("PrepareToConnect() - destination != null.\n");
return B_MEDIA_ALREADY_CONNECTED; return B_MEDIA_ALREADY_CONNECTED;
@@ -423,7 +423,7 @@ VideoProducer::PrepareToConnect(const media_source& source,
#define NODE_LATENCY 20000 #define NODE_LATENCY 20000
void void
VideoProducer::Connect(status_t error, const media_source& source, VideoProducer::Connect(status_t error, const media_source& source,
const media_destination& destination, const media_format& format, const media_destination& destination, const media_format& format,
char* _name) char* _name)
@@ -459,7 +459,7 @@ VideoProducer::Connect(status_t error, const media_source& source,
* 1000000 / fOutput.format.u.raw_video.field_rate); * 1000000 / fOutput.format.u.raw_video.field_rate);
fFrameBase = fFrame; fFrameBase = fFrame;
} }
fConnectedFormat = format.u.raw_video; fConnectedFormat = format.u.raw_video;
if (fConnectedFormat.display.bytes_per_row == 0) { if (fConnectedFormat.display.bytes_per_row == 0) {
ERROR("Connect() - connected format still has BPR wildcard!\n"); ERROR("Connect() - connected format still has BPR wildcard!\n");
@@ -495,7 +495,7 @@ VideoProducer::Connect(status_t error, const media_source& source,
} }
void void
VideoProducer::Disconnect(const media_source& source, VideoProducer::Disconnect(const media_source& source,
const media_destination& destination) const media_destination& destination)
{ {
@@ -528,7 +528,7 @@ VideoProducer::Disconnect(const media_source& source,
} }
void void
VideoProducer::LateNoticeReceived(const media_source &source, VideoProducer::LateNoticeReceived(const media_source &source,
bigtime_t how_much, bigtime_t performanceTime) bigtime_t how_much, bigtime_t performanceTime)
{ {
@@ -537,7 +537,7 @@ VideoProducer::LateNoticeReceived(const media_source &source,
} }
void void
VideoProducer::EnableOutput(const media_source& source, bool enabled, VideoProducer::EnableOutput(const media_source& source, bool enabled,
int32* _deprecated_) int32* _deprecated_)
{ {
@@ -550,7 +550,7 @@ VideoProducer::EnableOutput(const media_source& source, bool enabled,
} }
status_t status_t
VideoProducer::SetPlayRate(int32 numer, int32 denom) VideoProducer::SetPlayRate(int32 numer, int32 denom)
{ {
TOUCH(numer); TOUCH(denom); TOUCH(numer); TOUCH(denom);
@@ -559,7 +559,7 @@ VideoProducer::SetPlayRate(int32 numer, int32 denom)
} }
void void
VideoProducer::AdditionalBufferRequested(const media_source& source, VideoProducer::AdditionalBufferRequested(const media_source& source,
media_buffer_id prevBuffer, bigtime_t prevTime, media_buffer_id prevBuffer, bigtime_t prevTime,
const media_seek_tag* prevTag) const media_seek_tag* prevTag)
@@ -568,7 +568,7 @@ VideoProducer::AdditionalBufferRequested(const media_source& source,
} }
void void
VideoProducer::LatencyChanged(const media_source& source, VideoProducer::LatencyChanged(const media_source& source,
const media_destination& destination, const media_destination& destination,
bigtime_t newLatency, uint32 flags) bigtime_t newLatency, uint32 flags)
@@ -659,12 +659,14 @@ VideoProducer::_FrameGeneratorThreadEntry(void* data)
} }
int32 int32
VideoProducer::_FrameGeneratorThread() VideoProducer::_FrameGeneratorThread()
{ {
bool forceSendingBuffer = true; bool forceSendingBuffer = true;
bigtime_t lastFrameSentAt = 0; bigtime_t lastFrameSentAt = 0;
int64 lastPlaylistFrame = 0; int64 lastPlaylistFrame = 0;
int32 droppedFrames = 0;
const int32 kMaxDroppedFrames = 15;
bool running = true; bool running = true;
while (running) { while (running) {
TRACE("_FrameGeneratorThread: loop: %Ld\n", fFrame); TRACE("_FrameGeneratorThread: loop: %Ld\n", fFrame);
@@ -744,7 +746,8 @@ VideoProducer::_FrameGeneratorThread()
if (ignoreEvent || !fRunning || !fEnabled) { if (ignoreEvent || !fRunning || !fEnabled) {
TRACE("_FrameGeneratorThread: ignore event\n"); TRACE("_FrameGeneratorThread: ignore event\n");
// nothing to do // nothing to do
} else if (nextWaitUntil < system_time()) { } else if (nextWaitUntil < system_time()
&& droppedFrames < kMaxDroppedFrames) {
// Drop frame if it's at least a frame late. // Drop frame if it's at least a frame late.
printf("VideoProducer: dropped frame (%Ld)\n", fFrame); printf("VideoProducer: dropped frame (%Ld)\n", fFrame);
if (fManager->LockWithTimeout(10000) == B_OK) { if (fManager->LockWithTimeout(10000) == B_OK) {
@@ -752,6 +755,7 @@ VideoProducer::_FrameGeneratorThread()
fManager->Unlock(); fManager->Unlock();
} }
// next frame // next frame
droppedFrames++;
fFrame++; fFrame++;
} else if (playingDirection != 0 || forceSendingBuffer) { } else if (playingDirection != 0 || forceSendingBuffer) {
// Send buffers only, if playing, the node is running and // Send buffers only, if playing, the node is running and
@@ -759,16 +763,16 @@ VideoProducer::_FrameGeneratorThread()
TRACE("_FrameGeneratorThread: produce frame\n"); TRACE("_FrameGeneratorThread: produce frame\n");
BAutolock _(fLock); BAutolock _(fLock);
// Fetch a buffer from the buffer group // Fetch a buffer from the buffer group
BBuffer *buffer = fUsedBufferGroup->RequestBuffer( BBuffer* buffer = fUsedBufferGroup->RequestBuffer(
fConnectedFormat.display.bytes_per_row fConnectedFormat.display.bytes_per_row
* fConnectedFormat.display.line_count, 0LL); * fConnectedFormat.display.line_count, 0LL);
if (buffer) { if (buffer != NULL) {
// Fill out the details about this buffer. // Fill out the details about this buffer.
media_header *h = buffer->Header(); media_header* h = buffer->Header();
h->type = B_MEDIA_RAW_VIDEO; h->type = B_MEDIA_RAW_VIDEO;
h->time_source = TimeSource()->ID(); h->time_source = TimeSource()->ID();
h->size_used = fConnectedFormat.display.bytes_per_row h->size_used = fConnectedFormat.display.bytes_per_row
* fConnectedFormat.display.line_count; * fConnectedFormat.display.line_count;
// For a buffer originating from a device, you might // For a buffer originating from a device, you might
// want to calculate this based on the // want to calculate this based on the
// PerformanceTimeFor the time your buffer arrived at // PerformanceTimeFor the time your buffer arrived at
@@ -777,7 +781,7 @@ VideoProducer::_FrameGeneratorThread()
// TODO: Fix the runmode stuff! Setting the consumer to B_OFFLINE does // TODO: Fix the runmode stuff! Setting the consumer to B_OFFLINE does
// not do the trick. I made the VideoConsumer check the performance // not do the trick. I made the VideoConsumer check the performance
// time of the buffer and if it is 0, it plays it regardless. // time of the buffer and if it is 0, it plays it regardless.
if (playingMode < 0) { if (playingMode < 0 || droppedFrames >= kMaxDroppedFrames) {
h->start_time = 0; h->start_time = 0;
} }
h->file_pos = 0; h->file_pos = 0;
@@ -797,7 +801,7 @@ h->start_time = 0;
TRACE("_FrameGeneratorThread: frame: %Ld, " TRACE("_FrameGeneratorThread: frame: %Ld, "
"playlistFrame: %Ld\n", fFrame, playlistFrame); "playlistFrame: %Ld\n", fFrame, playlistFrame);
bool forceOrWasCached = forceSendingBuffer; bool forceOrWasCached = forceSendingBuffer;
err = fSupplier->FillBuffer(playlistFrame, err = fSupplier->FillBuffer(playlistFrame,
buffer->Data(), &mf, forceOrWasCached); buffer->Data(), &mf, forceOrWasCached);
// clean the buffer if something went wrong // clean the buffer if something went wrong
@@ -834,6 +838,7 @@ h->start_time = 0;
} }
// next frame // next frame
fFrame++; fFrame++;
droppedFrames = 0;
} else { } else {
TRACE("_FrameGeneratorThread: not playing\n"); TRACE("_FrameGeneratorThread: not playing\n");
// next frame // next frame