Ticket #7285: media_mixer.2.diff
File media_mixer.2.diff, 9.2 KB (added by , 13 years ago) |
---|
-
headers/private/media/ServerInterface.h
37 37 38 38 // Raw port based communication 39 39 enum { 40 GENERAL_PURPOSE_WAKEUP = 0, // when no action but wait termination needed 41 40 42 ADD_ON_SERVER_RESCAN_ADD_ON_FLAVORS = 0x50, 41 43 ADD_ON_SERVER_RESCAN_FINISHED_NOTIFY, 42 44 ADD_ON_SERVER_INSTANTIATE_DORMANT_NODE, -
headers/os/media/TimedEventQueue.h
38 38 int32 data; 39 39 int64 bigdata; 40 40 char user_data[64]; 41 bigtime_t queued_time; // Real time when put in queue 41 42 42 uint32 _reserved_media_timed_event_[ 8];43 uint32 _reserved_media_timed_event_[6]; 43 44 }; 44 45 45 46 -
src/kits/media/TimedEventQueuePrivate.cpp
29 29 30 30 /* Implements _event_queue_imp used by BTimedEventQueue, not thread save! 31 31 */ 32 #include <TimedEventQueue.h> 32 #include <string.h> 33 33 34 #include <Autolock.h> 34 35 #include <Buffer.h> 35 36 #include <InterfaceDefs.h> //defines B_DELETE 37 #include <TimedEventQueue.h> 38 #include <TimeSource.h> 39 36 40 #include "TimedEventQueuePrivate.h" 41 37 42 #include "Debug.h" 38 43 #include "debug.h" 39 44 40 #include <string.h>41 42 45 _event_queue_imp::_event_queue_imp() : 43 46 fLock(new BLocker("BTimedEventQueue locker")), 44 47 fEventCount(0), … … 74 77 if (event.type <= 0) { 75 78 return B_BAD_VALUE; 76 79 } 80 81 *(bigtime_t *)&event.queued_time = BTimeSource::RealTime(); 77 82 78 83 //create a new queue 79 84 if (fFirstEntry == NULL) { -
src/kits/media/MediaEventLooper.cpp
31 31 #include <TimeSource.h> 32 32 #include <scheduler.h> 33 33 #include <Buffer.h> 34 #include <ServerInterface.h> 34 35 #include "debug.h" 35 36 36 37 /************************************************************* … … 210 211 status_t err; 211 212 bigtime_t latency; 212 213 bigtime_t waituntil; 214 bigtime_t lateness; 213 215 for (;;) { 214 216 // while there are no events or it is not time for the earliest event, 215 217 // process messages using WaitForMessages. Whenever this funtion times out, … … 222 224 // only the scheduling latency). 223 225 224 226 latency = fEventLatency + fSchedulingLatency; 225 if (fEventQueue.HasEvents() && (TimeSource()->Now() - latency) >= fEventQueue.FirstEventTime()) {226 // printf("node %02d waiting for %12Ld that has already happened, now %12Ld\n", ID(), fEventQueue.FirstEventTime(), system_time());227 is_realtime = false;228 break;229 }230 if (fRealTimeQueue.HasEvents() && (TimeSource()->RealTime() - fSchedulingLatency) >= fRealTimeQueue.FirstEventTime()) {231 latency = fSchedulingLatency;232 is_realtime = true;233 break;234 }235 227 waituntil = B_INFINITE_TIMEOUT; 236 228 if (fEventQueue.HasEvents()) { 237 waituntil = TimeSource()->RealTimeFor(fEventQueue.FirstEventTime(), latency);238 // printf("node %02d waiting for %12Ld that will happen at %12Ld\n", ID(), fEventQueue.FirstEventTime(), waituntil);229 const media_timed_event *firstEvent = fEventQueue.FirstEvent(); 230 waituntil = TimeSource()->RealTimeFor(firstEvent->event_time, latency); 239 231 is_realtime = false; 232 lateness = firstEvent->queued_time - waituntil; 233 if (lateness > 0) { 234 // if (lateness > 1000) 235 // printf("node %02ld handling %12Ld at %12Ld -- %Ld late, queued at %Ld now %12Ld \n", 236 // ID(), fEventQueue.FirstEventTime(), TimeSource()->Now(), lateness, 237 // firstEvent->queued_time, TimeSource()->RealTime()); 238 is_realtime = false; 239 break; 240 } 241 // printf("node %02ld waiting for %12Ld that will happen at %12Ld\n", ID(), fEventQueue.FirstEventTime(), waituntil); 240 242 } 241 243 if (fRealTimeQueue.HasEvents()) { 244 const media_timed_event *firstEvent = fRealTimeQueue.FirstEvent(); 242 245 bigtime_t temp; 243 temp = fRealTimeQueue.FirstEventTime() - fSchedulingLatency; 246 temp = firstEvent->event_time - fSchedulingLatency; 247 lateness = firstEvent->queued_time - temp; 248 if (lateness > 0) { 249 is_realtime = true; 250 break; 251 } 244 252 if (temp < waituntil) { 245 253 waituntil = temp; 246 254 is_realtime = true; 247 latency = fSchedulingLatency;248 255 } 249 256 } 257 lateness = 0; // remove any extraneous value if we get this far 250 258 err = WaitForMessage(waituntil); 251 259 if (err == B_TIMED_OUT) 252 260 break; … … 258 266 else 259 267 err = fEventQueue.RemoveFirstEvent(&event); 260 268 261 // printf("node %02 d handling %12Ld at %12Ld\n", ID(), event.event_time, system_time());269 // printf("node %02ld handling %12Ld at %12Ld\n", ID(), event.event_time, TimeSource()->Now()); 262 270 263 if (err == B_OK) { 264 bigtime_t lateness; 265 if (is_realtime) 266 lateness = TimeSource()->RealTime() - event.event_time; 267 else 268 lateness = TimeSource()->RealTime() - TimeSource()->RealTimeFor(event.event_time, 0) + fEventLatency; 269 DispatchEvent(&event, lateness, is_realtime); 270 } 271 if (err == B_OK) DispatchEvent(&event, lateness, is_realtime); 271 272 } 272 273 } 273 274 … … 388 389 latency = 0; 389 390 390 391 fEventLatency = latency; 392 write_port_etc(ControlPort(), GENERAL_PURPOSE_WAKEUP, 0, 0, B_TIMEOUT, 0); 391 393 } 392 394 393 395 -
src/kits/media/MediaNode.cpp
377 377 TRACE("BMediaNode::WaitForMessage request is: %#lx, node %ld, this %p\n", 378 378 message, fNodeID, this); 379 379 380 if (message == GENERAL_PURPOSE_WAKEUP) return B_OK; // no action needed 381 380 382 if (message > NODE_MESSAGE_START && message < NODE_MESSAGE_END) { 381 383 TRACE("BMediaNode::WaitForMessage calling BMediaNode\n"); 382 384 if (B_OK == BMediaNode::HandleMessage(message, data, size)) -
src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp
1 1 /* 2 2 * Copyright 2002 David Shipman, 3 3 * Copyright 2003-2007 Marcus Overhagen 4 * Copyright 2007-201 0Haiku Inc. All rights reserved.4 * Copyright 2007-2011 Haiku Inc. All rights reserved. 5 5 * 6 6 * Distributed under the terms of the MIT License. 7 7 */ … … 108 108 fDownstreamLatency(1), 109 109 fInternalLatency(1), 110 110 fDisableStop(false), 111 fLastLateNotification(0) 111 fLastLateNotification(0), 112 fLastLateness(0) 112 113 { 113 114 BMediaNode::AddNodeKind(B_SYSTEM_MIXER); 114 115 … … 314 315 void 315 316 AudioMixer::HandleInputBuffer(BBuffer* buffer, bigtime_t lateness) 316 317 { 317 if (lateness > kMaxJitter ) {318 debug_printf(" Receivedbuffer %Ld usec late\n", lateness);318 if (lateness > kMaxJitter && lateness > fLastLateness) { 319 debug_printf("AudioMixer: Dequeued input buffer %Ld usec late\n", lateness); 319 320 if (RunMode() == B_DROP_DATA || RunMode() == B_DECREASE_PRECISION 320 321 || RunMode() == B_INCREASE_LATENCY) { 321 debug_printf(" sending notify\n");322 debug_printf("AudioMixer: sending notify\n"); 322 323 323 324 // Build a media_source out of the header data 324 325 media_source source = media_source::null; … … 328 329 NotifyLateProducer(source, lateness, TimeSource()->Now()); 329 330 330 331 if (RunMode() == B_DROP_DATA) { 331 debug_printf(" dropping buffer\n");332 debug_printf("AudioMixer: dropping buffer\n"); 332 333 return; 333 334 } 334 335 } 335 336 } 337 fLastLateness = lateness; 336 338 337 // printf("Received buffer with lateness %Ld\n", lateness);338 339 339 fCore->Lock(); 340 340 fCore->BufferReceived(buffer, lateness); 341 341 fCore->Unlock(); … … 1001 1001 1002 1002 if (what == fCore->Output()->MediaOutput().source 1003 1003 && RunMode() == B_INCREASE_LATENCY) { 1004 // We need to ignore subsequent notices whose performance time1005 // lies before the performance time of the last notification1004 // We need to ignore subsequent notices whose arrival time here 1005 // lies within the last lateness, because queued-up buffers will all be 'late' 1006 1006 if (performanceTime < fLastLateNotification) 1007 1007 return; 1008 1008 1009 1009 fInternalLatency += howMuch; 1010 1010 1011 1011 // At some point a too large latency can get annoying 1012 // (actually more than annoying, as there won't be enough buffers long before this!) 1012 1013 if (fInternalLatency > kMaxLatency) 1013 1014 fInternalLatency = kMaxLatency; 1014 1015 1015 fLastLateNotification = TimeSource()->Now() ;1016 fLastLateNotification = TimeSource()->Now() + howMuch; 1016 1017 1017 1018 debug_printf("AudioMixer: increasing internal latency to %Ld usec\n", fInternalLatency); 1018 1019 SetEventLatency(fDownstreamLatency + fInternalLatency); -
src/add-ons/media/media-add-ons/mixer/AudioMixer.h
136 136 bool fDisableStop; 137 137 media_format fDefaultFormat; 138 138 bigtime_t fLastLateNotification; 139 bigtime_t fLastLateness; 139 140 }; 140 141 141 142