1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /** 19 * @file pvmf_media_clock.h 20 * @brief Provides a time clock that can be paused and resumed, 21 * set the start time, adjusted based on outside source feedback, 22 * and accepts user specified source for the free running clock. 23 * 24 */ 25 26 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED 27 #define PVMF_MEDIA_CLOCK_H_INCLUDED 28 29 #ifndef OSCL_BASE_H_INCLUDED 30 #include "oscl_base.h" 31 #endif 32 33 #ifndef OSCL_TICKCOUNT_H_INCLUDED 34 #include "oscl_tickcount.h" 35 #endif 36 37 #ifndef OSCL_INT64_UTILS_H_INCLUDED 38 #include "oscl_int64_utils.h" 39 #endif 40 41 #ifndef OSCL_VECTOR_H_INCLUDED 42 #include "oscl_vector.h" 43 #endif 44 45 #ifndef OSCL_MEM_H_INCLUDED 46 #include "oscl_mem.h" 47 #endif 48 49 #ifndef PVMF_RETURN_CODES_H_INCLUDED 50 #include "pvmf_return_codes.h" 51 #endif 52 53 #ifndef PVMF_TIMESTAMP_H_INCLUDED 54 #include "pvmf_timestamp.h" 55 #endif 56 57 #ifndef OSCL_PRIQUEUE_H_INCLUDED 58 #include "oscl_priqueue.h" 59 #endif 60 61 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 62 #include "oscl_scheduler_ao.h" 63 #endif 64 65 #ifndef PV_INTERFACE_H_INCLUDED 66 #include "pv_interface.h" 67 #endif 68 69 #ifndef TIME_COMPARISON_UTILS_H_INCLUDED 70 #include "time_comparison_utils.h" 71 #endif 72 73 #ifndef PVLOGGER_H_INCLUDED 74 #include "pvlogger.h" 75 #endif 76 77 #define MSECS_IN_30_MINS 0x1B7740 78 79 80 #define PVMFMediaClockControlInterfaceUuid PVUuid(0xca20319a,0x33f9,0x484f,0x8d,0x1c,0xa5,0x1e,0x23,0x4c,0xe6,0x03) 81 #define PVMFMediaClockAccessInterfaceUuid PVUuid(0xca20319a,0x33f9,0x484f,0x8d,0x1c,0xa5,0x1e,0x23,0x4c,0xe6,0x04) 82 #define PVMFMediaClockNPTClockPositionAccessInterfaceUuid PVUuid(0xca20319a,0x33f9,0x484f,0x8d,0x1c,0xa5,0x1e,0x23,0x4c,0xe6,0x05) 83 84 //playback rate unit is milli-percent of real time 85 #define REALTIME_PLAYBACK_RATE 100000 86 87 class PVMFMediaClock; 88 class PVMFMediaClockNotificationsObs; 89 90 /* 91 * Enum for the time units used in OSCL Media Clock 92 */ 93 enum PVMFMediaClock_TimeUnits 94 { 95 PVMF_MEDIA_CLOCK_USEC = 0, 96 PVMF_MEDIA_CLOCK_MSEC = 1, 97 PVMF_MEDIA_CLOCK_SEC = 2, 98 PVMF_MEDIA_CLOCK_MIN = 3, 99 PVMF_MEDIA_CLOCK_HOUR = 4, 100 PVMF_MEDIA_CLOCK_DAY = 5 101 }; 102 103 /* 104 * Enum for return error codes for AdjustClock32() API 105 */ 106 enum PVMFMediaClockAdjustTimeStatus 107 { 108 PVMF_MEDIA_CLOCK_ADJUST_SUCCESS, 109 PVMF_MEDIA_CLOCK_ADJUST_ERR_INVALID_STATE, // If adjustment is attempted when clock is not running. 110 PVMF_MEDIA_CLOCK_ADJUST_ERR_INVALID_TIMEBASE_TIME, // If Adjustment is older than latest adjustment 111 PVMF_MEDIA_CLOCK_ADJUST_ERR_CORRUPT_CLOCK_TIME // If Clock time arg passed is later than current time 112 }; 113 114 enum PVMFMediaClockCheckTimeWindowStatus 115 { 116 PVMF_MEDIA_CLOCK_MEDIA_EARLY_OUTSIDE_WINDOW_CALLBACK_SET, 117 PVMF_MEDIA_CLOCK_MEDIA_EARLY_WITHIN_WINDOW, 118 PVMF_MEDIA_CLOCK_MEDIA_ONTIME_WITHIN_WINDOW, 119 PVMF_MEDIA_CLOCK_MEDIA_LATE_WITHIN_WINDOW, 120 PVMF_MEDIA_CLOCK_MEDIA_LATE_OUTSIDE_WINDOW, 121 PVMF_MEDIA_CLOCK_MEDIA_ERROR 122 }; 123 124 typedef struct _PVMFMediaClockCheckTimeWindowArgs 125 { 126 /*IN*/ 127 PVMFTimestamp aTimeStampToBeChecked; 128 /*IN*/ 129 PVMFMediaClock_TimeUnits aUnits; 130 /*IN*/ 131 uint32 aWindowEarlyMargin; 132 /*IN*/ 133 uint32 aWindowLateMargin; 134 /*OUT*/ 135 uint32 aDelta; 136 /*IN*/ 137 uint32 aCallbackToleranceWindow; 138 /*IN*/ 139 PVMFMediaClockNotificationsObs* aCallbackObserver; 140 /*IN*/ 141 bool aThreadLock; 142 /*IN*/ 143 const OsclAny* aContextData; 144 /*OUT*/ 145 uint32 aCallBackID; 146 } PVMFMediaClockCheckTimeWindowArgs; 147 148 149 class PVMFMediaClockNotificationsObsBase 150 { 151 public: ~PVMFMediaClockNotificationsObsBase()152 virtual ~PVMFMediaClockNotificationsObsBase() {} 153 /** 154 * This event happens when the clock has been Reset or destroyed and notification 155 * interface object that observer is using has been destroyed. Observer should 156 * set its pointer to PVMFMediaClockNotificationsInterface object as NULL. 157 */ 158 virtual void NotificationsInterfaceDestroyed() = 0; 159 }; 160 161 /** 162 PVMFMediaClockNotificationsObs is an observer class for PVMFMediaClock for Callbacks. 163 ProcessCallBack() is called when the timer expires. 164 */ 165 class PVMFMediaClockNotificationsObs : public virtual PVMFMediaClockNotificationsObsBase 166 { 167 public: 168 /** 169 * This callback function is called when a callback expires or has become invalid. 170 * @param callBackID Callback ID of the timer that has expired 171 * Units is msec. 172 * @param aTimerAccuracy Accuracy of timer. Value is from enum PVTimeComparisonUtils::MediaTimeStatus 173 * @param aDelta delta of scheduled callback time and actual time of callback 174 * @param aContextData Context data passed while setting the timer 175 * @param aStatus Status of timer. Value can be PVMFSuccess, PVMFErrCallbackClockStopped 176 * or PVMFErrCallbackHasBecomeInvalid. aStatus is PVMFErrCallbackHasBecomeInvalid 177 * if the direction of NPT Clock has changed. aStatus can be PVMFErrCallbackHasBecomeInvalid 178 * only for a NPT callback. 179 * @return NONE 180 * 181 */ 182 virtual void ProcessCallBack(uint32 callBackID, PVTimeComparisonUtils::MediaTimeStatus aTimerAccuracy, uint32 aDelta, 183 const OsclAny* aContextData, PVMFStatus aStatus) = 0; 184 185 /** 186 * This callback function is called when the notification interface 187 * being used by the object has been destroyed. 188 */ 189 virtual void NotificationsInterfaceDestroyed() = 0; 190 }; 191 192 /** 193 PVMFMediaClockObserver is an observer class for PVMFMediaClock. Modules 194 can optionally register themselves as clock observers. There 195 can be multiple observers for a single clock. 196 */ 197 class PVMFMediaClockObserver : public virtual PVMFMediaClockNotificationsObsBase 198 { 199 public: 200 201 /** 202 * This callback function is called when the timebase for this clock 203 * has been updated 204 */ 205 virtual void ClockTimebaseUpdated() = 0; 206 207 /** 208 * This callback function is called for counting timebases only, when the 209 * count has been updated. 210 */ 211 virtual void ClockCountUpdated() = 0; 212 213 /** 214 * This callback function is called when the clock has been adjusted. 215 */ 216 virtual void ClockAdjusted() = 0; 217 ~PVMFMediaClockObserver()218 virtual ~PVMFMediaClockObserver() {} 219 }; 220 221 /** 222 PVMFMediaClockStateObserver is an observer class for PVMFMediaClock. Modules 223 can optionally register themselves as clock state observers. There 224 can be multiple observers for a single clock. 225 */ 226 class PVMFMediaClockStateObserver : public virtual PVMFMediaClockNotificationsObsBase 227 { 228 public: 229 /** 230 * This callback function is called when the clock state changes. 231 */ 232 virtual void ClockStateUpdated() = 0; 233 ~PVMFMediaClockStateObserver()234 virtual ~PVMFMediaClockStateObserver() {} 235 }; 236 237 /** 238 PVMFCountTimebase is an extension to the standard timebase to allow 239 controlled stepping rather than continuous flow timebase. 240 */ 241 class PVMFCountTimebase 242 { 243 public: 244 /** 245 * Set a new value for the count. Will trigger a ClockCountUpdated callback 246 * to all observers of the clock in which this timebase resides. 247 * @param aCount (input): the new count 248 */ 249 virtual void SetCount(int32 aCount) = 0; 250 251 /** 252 * Read current value of the count. 253 * @param aCount (output): the current count 254 */ 255 virtual void GetCount(int32& aCount) = 0; 256 ~PVMFCountTimebase()257 virtual ~PVMFCountTimebase() {} 258 private: 259 /** 260 * Each PVMFCountTimebase will be contained within an PVMFMediaClock 261 * class. That PVMFMediaClock instance will set itself as the observer of 262 * the PVMFCountTimebase. To get notices from the timebase, modules 263 * can register through the SetClockObserver method of the PVMFMediaClock. 264 */ 265 friend class PVMFMediaClock; 266 virtual void SetClockObserver(PVMFMediaClockObserver* aObserver) = 0; 267 }; 268 269 /** 270 PVMFTimebase is a base class to obtain the timebase clock time. 271 Common source of the timebase clock is the system tickcount which is implemented 272 as PVMFTimebase_Tickcount further below. PVMFTimebase is expected to return the time 273 in units of microseconds even if the timebase itself does not have the resolution of microseconds. 274 */ 275 class PVMFTimebase 276 { 277 public: 278 ~PVMFTimebase()279 virtual ~PVMFTimebase() {} 280 281 /** 282 * Gets the timebase clock's smallest time resolution in microseconds 283 * @param aResolution: unsigned 32-bit value for the clock resolution 284 */ 285 virtual void GetTimebaseResolution(uint32& aResolution) = 0; 286 287 /** 288 * Returns the timebase clock's smallest time resolution in microseconds 289 * @param aResolution: unsigned 32-bit value for the clock resolution 290 */ 291 292 /** 293 * Read current value of the count. 294 * @param aResolution: unsigned 32-bit value. Playback rate unit is milli-percent of real time 295 */ 296 virtual int32 GetRate(void) = 0; 297 298 /** 299 * Returns current tickcount. PVMFMediaClock sources this value from the timebase. If no 300 * timebase is set, aTimebaseTickCount is set to 0. 301 * @param aTime: a reference to an unsigned 32-bit integer to return the current time 302 * @param aUnits: the requested time units for aTime 303 * @param aTimebaseTime: a reference to an unsigned 32-bit integer to return the timebase time 304 */ 305 virtual void GetCurrentTick32(uint32& aTimebaseTickCount, bool& aOverflow) = 0; 306 307 /** 308 * This API returns pointer to clock's timebase if timebase being used is a PVMFCountTimebase 309 * object. Otherwise, NULL is returned. PVMFCountTimebase is used for a stepping clock. 310 * @return pointer to PVMFCountTimebase implementation, or NULL if not supported. 311 */ 312 virtual PVMFCountTimebase* GetCountTimebase() = 0; 313 314 }; 315 316 /* 317 PVMFMediaClockControlInterface interface class is implemented by PVMFMediaClock. 318 This class contains methods for controlling PVMFMediaClock 319 */ 320 class PVMFMediaClockControlInterface: public PVInterface 321 { 322 public: 323 /** 324 * Starts the clock from the start time or 325 * resumes the clock from the last paused time. Clock goes to RUNNING state. 326 * @return true if the clock is resumed or started, false otherwise 327 */ 328 329 virtual OSCL_IMPORT_REF bool Start() = 0; 330 331 /** 332 * Pauses the running clock. Saves the clock time when pausing as the paused time. 333 * Clock goes to PAUSED state. Returns true if the clock is paused, false otherwise. 334 * Will trigger a ClockStateUpdated notice to all state observers of this clock. 335 * @return true if the clock is paused, false otherwise 336 */ 337 virtual OSCL_IMPORT_REF bool Pause() = 0; 338 339 /** 340 * Stops the running or paused clock and start time is reset to 0. Clock goes to STOPPED state. 341 * Will trigger a ClockStateUpdated notice to all state observers of this clock. State 342 * observers and clock observers are not automatically removed when clock is stopped. However, 343 * any active callbacks will be fired with error code PVMFErrCallbackClockStopped. 344 * 345 * @return true if the clock is stopped, false otherwise 346 */ 347 virtual OSCL_IMPORT_REF bool Stop() = 0; 348 349 /** 350 * Sets the starting clock time with unsigned 32-bit integer in the specified time units 351 * while in STOPPED state. Clock's internal timekeeping units are changed to usecs if aUnits 352 * is usecs. Otherwise, internal units remain msecs(default). High probability of overflow if 353 * units are given as usecs. 354 * @param aTime: a reference to an unsigned 32-bit integer to set the start time 355 * @param aUnits: the time units of aTime 356 * @param aOverFlow: true if operation resulted in overflow, false otherwise 357 * @return true if start time was set, false otherwise 358 */ 359 virtual OSCL_IMPORT_REF bool SetStartTime32(uint32& aTime, PVMFMediaClock_TimeUnits aUnits, bool& aOverFlow) = 0; 360 361 /** 362 * Adjusts the clock time with unsigned 32-bit integer in the specified time units while in 363 * RUNNING state. For backward adjustments, clock freezes internally till the adjusted time. 364 * @param aClockTime: a reference to an unsigned 32-bit integer to the observation clock time 365 * @param aTimebaseTime: a reference to an unsigned 32-bit integer to the observation timebase time 366 * @param aAdjustedTime: a reference to an unsigned 32-bit integer to the adjusted clock time 367 * @param aUnits: the time units of aClockTime and aAdjustedTime 368 * @return true if AdjustClockTime32 is successful 369 */ 370 virtual OSCL_IMPORT_REF PVMFMediaClockAdjustTimeStatus AdjustClockTime32(uint32& aClockTime, uint32& aTimebaseTime, uint32& aAdjustedTime, PVMFMediaClock_TimeUnits aUnits, bool& aOverFlow) = 0; 371 372 /** 373 * Stops the running or paused clock and start time is reset to 0. Clock goes to STOPPED state. 374 * Will trigger a ClockStateUpdated notice to all state observers of this clock.Clock observers 375 * and clock state observers are automatically removed when clock is Reset. Any active callbacks 376 * will be fired with error code PVMFErrCallbackClockStopped. All PVMFMediaClockNotificationsInterface 377 * objects are deleted. 378 * @return true if reset is successful. 379 */ 380 virtual OSCL_IMPORT_REF bool Reset() = 0; 381 addRef()382 void addRef() {} removeRef()383 void removeRef() {} queryInterface(const PVUuid & uuid,PVInterface * & iface)384 bool queryInterface(const PVUuid& uuid, PVInterface*& iface) 385 { 386 OSCL_UNUSED_ARG(uuid); 387 OSCL_UNUSED_ARG(iface); 388 return false; 389 } 390 }; 391 392 /* 393 PVMFMediaClockAccessInterface interface class is implemented by PVMFMediaClock. 394 This class contains method for accessing start time from PVMFMediaClock. 395 */ 396 class PVMFMediaClockAccessInterface: public PVInterface 397 { 398 public: 399 400 /** 401 * Gets the starting clock time as an unsigned 32-bit integer in the specified time units 402 * @param aTime: a reference to an unsigned 32-bit integer to copy the start time 403 * @param aOverflow: a reference to a flag which is set if time value cannot fit in unsigned 32-bit integer 404 * @param aUnits: the requested time units for aTime 405 */ 406 virtual OSCL_IMPORT_REF void GetStartTime32(uint32& aTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits) = 0; 407 408 /** 409 * Gets the starting clock time as an unsigned 32-bit integer in the specified time units 410 * @param aClockTime: a reference to an unsigned 32-bit integer to return current time in specified time units 411 * @param aOverflow: a reference to a flag which is set if time value cannot fit in unsigned 32-bit integer 412 * @param aUnits: the requested time units for aTime 413 */ 414 virtual OSCL_IMPORT_REF void GetCurrentTime32(uint32& aClockTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits) = 0; 415 416 /** 417 * This API is used to get current clock time in time units specified. If the value does not fit 418 * in 32 bit uint (aTime), aOverflow flag is set. This API also provides current timebase tickcount. 419 * This is not the absolute tickcount value from timebase. PVMFMediaClock uses scaled version of 420 * timebase tickcount by subtracting the tickcount value at clock start time from the current tickcount value. 421 * Thus, the clock starts from tickcount value 0 and probability of overflow is reduced. 422 * @param aClockTime: a reference to an unsigned 32-bit integer to return current time in specified time units 423 * @param aOverflow: a reference to a flag which is set if time value cannot fit in unsigned 32-bit integer 424 * @param aUnits: the requested time units for aTime 425 * @param aTimebaseTime: uint32 value used to return current (scaled) timebase tickcount 426 */ 427 virtual OSCL_IMPORT_REF void GetCurrentTime32(uint32& aClockTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits, uint32& aTimebaseTime) = 0; 428 addRef()429 void addRef() {} removeRef()430 void removeRef() {} queryInterface(const PVUuid & uuid,PVInterface * & iface)431 bool queryInterface(const PVUuid& uuid, PVInterface*& iface) 432 { 433 OSCL_UNUSED_ARG(uuid); 434 OSCL_UNUSED_ARG(iface); 435 return false; 436 } 437 }; 438 439 /* 440 PVMFMediaClockNotificationsInterface interface is implemented by 441 PVMFMediaClockNotificationsInterfaceImpl class. This interface contains all callbacks related methods. 442 This class has methods related to both regular callbacks and NPT callbacks. 443 */ 444 445 class PVMFMediaClockNotificationsInterface 446 { 447 public: 448 449 /*!********************************************************************* 450 ** 451 ** Function: SetCallbackAbsoluteTime 452 ** 453 ** Synopsis: Set a callback timer specifying an absolute time in clock for timer expiry. 454 ** 455 ** Arguments : 456 ** @param [absoluteTime] -- Absolute time in clock when callBack should be called. 457 ** Units is msec. If there is a latency associated with the 458 ** calling module, then callback will fire when latency adjusted time 459 ** reaches absoluteTime. PVMFMediaClock time may be different at that time. 460 ** @param [window] -- Error tolerance available in callback time. If T is the desired 461 ** callback time and w is the allowed tolerance window, then callback 462 ** can come between T-w to T+w time. 463 ** @param [aObserver] -- observer object to be called on timeout. 464 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 465 ** not. Making callback threadsafe might add overheads. 466 ** @param [aContextData] -- context pointer that will be returned back with the callback. 467 ** @param [callBackID] -- ID used to identify the timer for cancellation 468 ** 469 ** Returns: 470 ** @return PVMFStatus -- success or error code 471 ** 472 ** 473 ** Notes: 474 ** 475 **********************************************************************/ 476 virtual OSCL_IMPORT_REF PVMFStatus SetCallbackAbsoluteTime( 477 /*IN*/ uint32 aAbsoluteTime, 478 /*IN*/ uint32 aWindow, 479 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 480 /*IN*/ bool aThreadLock, 481 /*IN*/ const OsclAny* aContextData, 482 /*OUT*/ uint32& aCallBackID) = 0; 483 484 /*!********************************************************************* 485 ** 486 ** Function: SetCallbackDeltaTime 487 ** 488 ** Synopsis: Set a callback timer specifying a delta time from current time for timer expiry. 489 ** 490 ** Arguments : 491 ** @param [deltaTime] -- delta time in clock when callBack should be called. 492 ** Units is msec. 493 ** @param [window] -- Error tolerance available in callback time. If T is the desired 494 ** callback time and w is the allowed tolerance window, then callback 495 ** can come between T-w to T+w time. 496 ** @param [aObserver] -- observer object to be called on timeout. 497 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 498 ** not. Making callback threadsafe might add overheads. 499 ** @param [aContextData] -- context pointer that will be returned back with the callback. 500 ** @param [callBackID] -- ID used to identify the timer for cancellation 501 ** 502 ** Returns: 503 ** @return PVMFStatus -- success or error code 504 ** 505 ** 506 ** Notes: 507 ** 508 **********************************************************************/ 509 virtual OSCL_IMPORT_REF PVMFStatus SetCallbackDeltaTime( 510 /*IN*/ uint32 aDeltaTime, 511 /*IN*/ uint32 aWindow, 512 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 513 /*IN*/ bool aThreadLock, 514 /*IN*/ const OsclAny* aContextData, 515 /*OUT*/ uint32 &aCallBackID) = 0; 516 517 /*!********************************************************************* 518 ** 519 ** Function: CancelCallback 520 ** 521 ** Synopsis: Cancel callback timer set with SetCallBackDeltaTime() or SetCallbackAbsoluteTime() 522 ** 523 ** Arguments : 524 ** @param [callbackID] -- timer ID returned by SetCallBackDeltaTime() 525 ** or SetCallbackAbsoluteTime() 526 ** @param : [aThreadLock] -- whether this call needs to be threadsafe 527 ** Returns: 528 ** @return PVMFStatus 529 ** 530 ** Notes: 531 ** 532 **********************************************************************/ 533 virtual OSCL_IMPORT_REF PVMFStatus CancelCallback( 534 /*IN*/ uint32 aCallbackID, bool aThreadLock) = 0; 535 536 /*!********************************************************************* 537 ** 538 ** Function: SetNPTCallbackAbsoluteTime 539 ** 540 ** Synopsis: Set a callback timer specifying an absolute time in clock for timer expiry. 541 ** 542 ** Arguments : 543 ** @param [absoluteTime] -- absolute time in clock when callBack should be called. 544 ** Units is msec. If there is a latency associated with the 545 ** calling module, then callback will fire when latency adjusted NPT time 546 ** reaches absoluteTime. PVMFMediaClock time may be different at that time. 547 ** @param [window] -- Error tolerance available in callback time. If T is the desired 548 ** callback time and w is the allowed tolerance window, then callback 549 ** can come between T-w to T+w time. 550 ** @param [aObserver] -- observer object to be called on timeout. 551 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 552 ** not. Making callback threadsafe might add overheads. 553 ** @param [aContextData] -- context pointer that will be returned back with the callback. 554 ** @param [callBackID] -- ID used to identify the timer for cancellation 555 ** 556 ** Returns: 557 ** @return PVMFStatus -- success or error code 558 ** 559 ** 560 ** Notes: 561 ** 562 **********************************************************************/ 563 564 virtual OSCL_IMPORT_REF PVMFStatus SetNPTCallbackAbsoluteTime( 565 /*IN*/ uint32 aAbsoluteTime, 566 /*IN*/ uint32 aWindow, 567 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 568 /*IN*/ bool aThreadLock, 569 /*IN*/ const OsclAny* aContextData, 570 /*OUT*/ uint32& aCallBackID) = 0; 571 572 /*!********************************************************************* 573 ** 574 ** Function: SetNPTCallbackDeltaTime 575 ** 576 ** Synopsis: Set a callback timer specifying a delta time from current time for timer expiry. 577 ** 578 ** Arguments : 579 ** @param [deltaTime] -- delta time in clock when callBack should be called. 580 ** Units is msec. 581 ** @param [window] -- Error tolerance available in callback time. If T is the desired 582 ** callback time and w is the allowed tolerance window, then callback 583 ** can come between T-w to T+w time. 584 ** @param [aObserver] -- observer object to be called on timeout. 585 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 586 ** not. Making callback threadsafe might add overheads. 587 ** @param [aContextData] -- context pointer that will be returned back with the callback. 588 ** @param [callBackID] -- ID used to identify the timer for cancellation 589 ** 590 ** Returns: 591 ** @return PVMFStatus -- success or error code 592 ** 593 ** 594 ** Notes: 595 ** 596 **********************************************************************/ 597 virtual OSCL_IMPORT_REF PVMFStatus SetNPTCallbackDeltaTime( 598 /*IN*/ uint32 aDeltaTime, 599 /*IN*/ uint32 aWindow, 600 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 601 /*IN*/ bool aThreadLock, 602 /*IN*/ const OsclAny* aContextData, 603 /*OUT*/ uint32& aCallBackID) = 0; 604 605 /*!********************************************************************* 606 ** 607 ** Function: CancelCallback 608 ** 609 ** Synopsis: Cancel callback timer set with SetCallBackDeltaTime() or SetCallbackAbsoluteTime() 610 ** 611 ** Arguments : 612 ** @param : [callbackID] -- timer ID returned by SetCallBackDeltaTime() 613 ** or SetCallbackAbsoluteTime() 614 ** @param : [aThreadLock] -- whether this call needs to be threadsafe 615 ** Returns: 616 ** @return PVMFStatus 617 ** 618 ** Notes: 619 ** 620 **********************************************************************/ 621 virtual OSCL_IMPORT_REF PVMFStatus CancelNPTCallback( 622 /*IN*/ uint32 aCallbackID, bool aThreadLock) = 0; 623 624 /** 625 * This API sets the object passed as a ClockObserver. The object's callback 626 * functions (ClockTimebaseUpdated(),ClockCountUpdated(),ClockAdjusted() ) 627 * will be called on corresponding events. 628 * @param aObserver: the observer implemenation 629 */ 630 virtual OSCL_IMPORT_REF void SetClockObserver(PVMFMediaClockObserver& aObserver) = 0; 631 632 /** 633 * This API removes aObserver obeject from the list of ClockObservers if aObserver 634 * is set as an observer. 635 * @param aObserver: the observer implemenation 636 */ 637 virtual OSCL_IMPORT_REF void RemoveClockObserver(PVMFMediaClockObserver& aObserver) = 0; 638 639 /** 640 * This API sets the object passed as a ClockStateObserver. The object's callback 641 * function ClockStateUpdated() will be called on clock state change. 642 * @param aObserver: the observer implemenation 643 */ 644 virtual OSCL_IMPORT_REF void SetClockStateObserver(PVMFMediaClockStateObserver& aObserver) = 0; 645 646 /** 647 * Removes an observer for this clock. If the observer is not registered, this 648 * call does nothing. 649 * @param aObserver: the observer implemenation 650 */ 651 virtual OSCL_IMPORT_REF void RemoveClockStateObserver(PVMFMediaClockStateObserver& aObserver) = 0; 652 653 /*!********************************************************************* 654 ** 655 ** Function: CheckTimeWindowAndSetCallback 656 ** 657 ** Synopsis: Check if given timestamp falls within the given window of current time. Returns status of the 658 ** timestamp w.r.t current time. If the timestamp is early and is outside the given 659 ** window, a callback is automatically set. This API adjusts for 660 ** the latency associated with the calling module. 661 ** 662 ** Arguments : 663 ** @param [aArgsStruct] -- Reference to a PVMFMediaClockCheckTimeWindowArgs structure. This structure 664 ** all the arguments for this API. For description of arguments, please see notes. 665 ** Returns: 666 ** @return PVMFMediaClockCheckTimeWindowStatus -- One of the following values from enum PVMFMediaClockCheckTimeWindowStatus 667 ** will be returned - 668 ** PVMF_MEDIA_CLOCK_MEDIA_EARLY_OUTSIDE_WINDOW_CALLBACK_SET, 669 ** PVMF_MEDIA_CLOCK_MEDIA_EARLY_WITHIN_WINDOW, 670 ** PVMF_MEDIA_CLOCK_MEDIA_ONTIME_WITHIN_WINDOW, 671 ** PVMF_MEDIA_CLOCK_MEDIA_LATE_WITHIN_WINDOW, 672 ** PVMF_MEDIA_CLOCK_MEDIA_LATE_OUTSIDE_WINDOW, 673 ** PVMF_MEDIA_CLOCK_MEDIA_ERROR 674 ** Notes: Following are the members of PVMFMediaClockCheckTimeWindowArgs structure. 675 ** [aTimeStampToBeChecked] -- Timestamp to be checked w.r.t. the current time. 676 ** [aWindowEarlyMargin] -- early margin of the window. 677 ** [aWindowLateMargin] -- late margin of the window. 678 ** [aDelta] -- This will return the difference between timestamp and current time 679 ** in positive form. 680 ** [aCallbackToleranceWindow] -- Error tolerance available in callback time. If T is the desired 681 ** callback time and w is the allowed tolerance window, then callback 682 ** can come between T-w to T+w time. This argument is used if callback 683 ** is set. 684 ** [aCallbackObserver] -- observer object to be called on timeout. This argument is used if 685 ** callback is set. 686 ** [aThreadLock] -- If threadLock is true, callback will be threadsafe otherwise 687 ** not. Making callback threadsafe might add overheads. This argument 688 ** is used if callback is set. 689 ** [aContextData] -- context pointer that will be returned back with the callback. This argument 690 ** is used if callback is set. 691 ** [callBackID] -- If callback is successfully set, this will contain a non-zero ID associated 692 ** with the callback. This ID can be used to identify the timer for cancellation. 693 **********************************************************************/ 694 695 virtual PVMFMediaClockCheckTimeWindowStatus CheckTimeWindow( 696 PVMFMediaClockCheckTimeWindowArgs &aArgsStruct) = 0; 697 698 699 /*!********************************************************************* 700 ** 701 ** Function: GetLatencyAdjustedCurrentTime32 702 ** 703 ** Synopsis: Get the latency adjusted current clock time as an unsigned 32-bit integer in specified time units. 704 ** 705 ** Arguments : 706 ** @param [aClockTime] -- A reference to an unsigned 32-bit integer to return current time in specified time units. 707 ** @param [aOverflow] -- A reference to a flag which is set if time value cannot fit in unsigned 32-bit integer. 708 ** @param [aUnits] -- The requested time units for aTime. 709 ** Returns: 710 ** @return NONE 711 ** Notes: 712 ** 713 **********************************************************************/ 714 virtual void GetLatencyAdjustedCurrentTime32( 715 /*OUT*/ uint32& aClockTime, 716 /*IN*/ bool& aOverflow, 717 /*IN*/ PVMFMediaClock_TimeUnits aUnits) = 0; 718 ~PVMFMediaClockNotificationsInterface()719 virtual ~PVMFMediaClockNotificationsInterface() {} 720 }; 721 722 /* 723 PVMFMediaClockNotificationsImplInterface class is implemented by PVMFMediaClock. This class contains 724 corresponding PVMFMediaClock side functions of interface PVMFMediaClockNotifications. 725 */ 726 727 class PVMFMediaClockNotificationsImplInterface 728 { 729 public: 730 731 /*!********************************************************************* 732 ** 733 ** Function: SetCallbackAbsoluteTime 734 ** 735 ** Synopsis: Set a callback timer specifying an absolute time in clock for timer expiry. 736 ** 737 ** Arguments : 738 ** @param [absoluteTime] -- absolute time in clock when callBack should be called. 739 ** Units is msec. 740 ** @param [window] -- Error tolerance available in callback time. If T is the desired 741 ** callback time and w is the allowed tolerance window, then callback 742 ** can come between T-w to T+w time. 743 ** @param [aObserver] -- observer object to be called on timeout. 744 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 745 ** not. Making callback threadsafe might add overheads. 746 ** @param [aContextData] -- context pointer that will be returned back with the callback. 747 ** @param [callBackID] -- ID used to identify the timer for cancellation 748 ** @param [aInterfaceObject] -- self pointer of interface object which calls this function 749 ** Returns: 750 ** @return PVMFStatus -- success or error code 751 ** 752 ** 753 ** Notes: 754 ** 755 **********************************************************************/ 756 virtual OSCL_IMPORT_REF PVMFStatus SetCallbackAbsoluteTime( 757 /*IN*/ uint32 aAbsoluteTime, 758 /*IN*/ uint32 aWindow, 759 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 760 /*IN*/ bool aThreadLock, 761 /*IN*/ const OsclAny* aContextData, 762 /*OUT*/ uint32& aCallBackID, 763 /*IN*/ const OsclAny* aInterfaceObject) = 0; 764 765 /*!********************************************************************* 766 ** 767 ** Function: SetCallbackDeltaTime 768 ** 769 ** Synopsis: Set a callback timer specifying a delta time from current time for timer expiry. 770 ** 771 ** Arguments : 772 ** @param [deltaTime] -- delta time in clock when callBack should be called. 773 ** Units is msec. 774 ** @param [window] -- Error tolerance available in callback time. If T is the desired 775 ** callback time and w is the allowed tolerance window, then callback 776 ** can come between T-w to T+w time. 777 ** @param [aObserver] -- observer object to be called on timeout. 778 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 779 ** not. Making callback threadsafe might add overheads. 780 ** @param [aContextData] -- context pointer that will be returned back with the callback. 781 ** @param [callBackID] -- ID used to identify the timer for cancellation 782 ** @param [aInterfaceObject] -- self pointer of interface object which calls this function 783 ** Returns: 784 ** @return PVMFStatus -- success or error code 785 ** 786 ** 787 ** Notes: 788 ** 789 **********************************************************************/ 790 virtual OSCL_IMPORT_REF PVMFStatus SetCallbackDeltaTime( 791 /*IN*/ uint32 aDeltaTime, 792 /*IN*/ uint32 aWindow, 793 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 794 /*IN*/ bool aThreadLock, 795 /*IN*/ const OsclAny* aContextData, 796 /*OUT*/ uint32 &aCallBackID, 797 /*IN*/ const OsclAny* aInterfaceObject) = 0; 798 799 /*!********************************************************************* 800 ** 801 ** Function: CancelCallback 802 ** 803 ** Synopsis: Cancel callback timer set with SetCallBackDeltaTime() or SetCallbackAbsoluteTime() 804 ** 805 ** Arguments : 806 ** @param [callbackID] -- timer ID returned by SetCallBackDeltaTime() 807 ** or SetCallbackAbsoluteTime() 808 ** @param : [aThreadLock] -- whether this call needs to be threadsafe 809 ** Returns: 810 ** @return PVMFStatus 811 ** 812 ** Notes: 813 ** 814 **********************************************************************/ 815 virtual OSCL_IMPORT_REF PVMFStatus CancelCallback( 816 /*IN*/ uint32 aCallbackID, bool aThreadLock) = 0; 817 818 /*!********************************************************************* 819 ** 820 ** Function: SetNPTCallbackAbsoluteTime 821 ** 822 ** Synopsis: Set a callback timer specifying an absolute time in clock for timer expiry. 823 ** 824 ** Arguments : 825 ** @param [absoluteTime] -- absolute time in clock when callBack should be called. 826 ** Units is msec. 827 ** @param [window] -- Error tolerance available in callback time. If T is the desired 828 ** callback time and w is the allowed tolerance window, then callback 829 ** can come between T-w to T+w time. 830 ** @param [aObserver] -- observer object to be called on timeout. 831 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 832 ** not. Making callback threadsafe might add overheads. 833 ** @param [aContextData] -- context pointer that will be returned back with the callback. 834 ** @param [callBackID] -- ID used to identify the timer for cancellation 835 ** @param [aInterfaceObject] -- self pointer of interface object which calls this function 836 ** Returns: 837 ** @return PVMFStatus -- success or error code 838 ** 839 ** 840 ** Notes: 841 ** 842 **********************************************************************/ 843 844 virtual OSCL_IMPORT_REF PVMFStatus SetNPTCallbackAbsoluteTime( 845 /*IN*/ uint32 aAbsoluteTime, 846 /*IN*/ uint32 aWindow, 847 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 848 /*IN*/ bool aThreadLock, 849 /*IN*/ const OsclAny* aContextData, 850 /*OUT*/ uint32& aCallBackID, 851 /*IN*/ const OsclAny* aInterfaceObject) = 0; 852 853 /*!********************************************************************* 854 ** 855 ** Function: SetNPTCallbackDeltaTime 856 ** 857 ** Synopsis: Set a callback timer specifying a delta time from current time for timer expiry. 858 ** 859 ** Arguments : 860 ** @param [deltaTime] -- delta time in clock when callBack should be called. 861 ** Units is msec. 862 ** @param [window] -- Error tolerance available in callback time. If T is the desired 863 ** callback time and w is the allowed tolerance window, then callback 864 ** can come between T-w to T+w time. 865 ** @param [aObserver] -- observer object to be called on timeout. 866 ** @param [threadLock] -- If threadLock is true, callback will to be threadsafe otherwise 867 ** not. Making callback threadsafe might add overheads. 868 ** @param [aContextData] -- context pointer that will be returned back with the callback. 869 ** @param [callBackID] -- ID used to identify the timer for cancellation 870 ** @param [aInterfaceObject] -- self pointer of interface object which calls this function 871 ** Returns: 872 ** @return PVMFStatus -- success or error code 873 ** 874 ** 875 ** Notes: 876 ** 877 **********************************************************************/ 878 virtual OSCL_IMPORT_REF PVMFStatus SetNPTCallbackDeltaTime( 879 /*IN*/ uint32 aDeltaTime, 880 /*IN*/ uint32 aWindow, 881 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 882 /*IN*/ bool aThreadLock, 883 /*IN*/ const OsclAny* aContextData, 884 /*OUT*/ uint32& aCallBackID, 885 /*IN*/ const OsclAny* aInterfaceObject) = 0; 886 887 /*!********************************************************************* 888 ** 889 ** Function: CancelCallback 890 ** 891 ** Synopsis: Cancel callback timer set with SetCallBackDeltaTime() or SetCallbackAbsoluteTime() 892 ** 893 ** Arguments : 894 ** @param [callbackID] -- timer ID returned by SetCallBackDeltaTime() 895 ** or SetCallbackAbsoluteTime() 896 ** @param : [aThreadLock] -- whether this call needs to be threadsafe 897 ** Returns: 898 ** @return PVMFStatus 899 ** 900 ** Notes: 901 ** 902 **********************************************************************/ 903 virtual OSCL_IMPORT_REF PVMFStatus CancelNPTCallback( 904 /*IN*/ uint32 aCallbackID, bool aThreadLock) = 0; 905 906 /** 907 * Adds an observer for this clock. 908 * @param aObserver: the observer implemenation 909 */ 910 virtual OSCL_IMPORT_REF void SetClockObserver(PVMFMediaClockObserver& aObserver) = 0; 911 912 /** 913 * Removes an observer for this clock. If the observer is not registered, this 914 * call does nothing. 915 * @param aObserver: the observer implemenation 916 */ 917 virtual OSCL_IMPORT_REF void RemoveClockObserver(PVMFMediaClockObserver& aObserver) = 0; 918 919 /** 920 * Sets an observer for this clock. May leave if memory allocation fails. 921 * @param aObserver: the observer implemenation 922 */ 923 virtual OSCL_IMPORT_REF void SetClockStateObserver(PVMFMediaClockStateObserver& aObserver) = 0; 924 925 /** 926 * Removes an observer for this clock. If the observer is not registered, this 927 * call does nothing. 928 * @param aObserver: the observer implemenation 929 */ 930 virtual OSCL_IMPORT_REF void RemoveClockStateObserver(PVMFMediaClockStateObserver& aObserver) = 0; 931 ~PVMFMediaClockNotificationsImplInterface()932 virtual ~PVMFMediaClockNotificationsImplInterface() {} 933 }; 934 935 936 /* 937 PVMFMediaClockNPTClockPositionAccessInterface interface class is implemented by PVMFMediaClock. 938 This class contains methods for accessing and updating NPT clock position values 939 */ 940 941 class PVMFMediaClockNPTClockPositionAccessInterface: public PVInterface 942 { 943 944 public: 945 946 /** 947 * NPT clock position is not same as playback clock position. PVMFMediaClock 948 * can store the mapping between the two clocks. UpdateNPTClockPosition() API is 949 * called by the user to update change in NPT clock position. User can change the 950 * direction of NPT by specifying aIsPlayBackDirectionBackwards flag. 951 * @param aStartNPT: uint32 value containing new startNPT value 952 * @param aIsPlayBackDirectionBackwards: Should be set as false if 953 * NPT playback direction is forward from this point and should 954 * be set as true if NPT clock direction is backwards. 955 */ 956 virtual void UpdateNPTClockPosition( 957 /*IN*/ uint32 aStartNPT, 958 /*IN*/ bool aIsPlayBackDirectionBackwards) = 0; 959 960 /** 961 * Gets NPT clock position 962 * @param aCurrentPosition: uint32 value to store the current NPT clock position. 963 * @return PVMFSuccess/PVMFErrArgument. PVMFErrArgument is returned when there is 964 * overflow i.e. 32 bit aCurrentPosition is not enough to store current NPT 965 * clock value or if there is an internal overflow. 966 */ 967 virtual PVMFStatus GetNPTClockPosition( 968 /*OUT*/ uint32& aCurrentPosition) = 0; 969 970 /** 971 * This API clears the NPT clock mapping and resets internal variables to 0. 972 */ 973 virtual void ClearNPTClockPosition() = 0; 974 975 /** 976 * This API is used to schedule a NPT clock transition(time change) in future. All 977 * parameters are described above. 978 * @param aMediaClockPosition: Absolute media clock position when NPT clock change 979 * should take place. 980 * @param aStartNPT: new startNPT value to be set 981 * @param aIsPlayBackDirectionBackwards: flag specifying if NPT clock should run 982 * backwards after NPT time update. 983 * @param aWindow: margin window for scheduling the time change. i.e. NPT clock 984 * time change can be scheduled within window [aMediaClockPosition-aWindow, 985 * aMediaClockPosition+aWindow]. 986 * @param aClockTransitionEventID: clockTransitionID returned to user. This can be used 987 * to cancel a transition after it has been set. 988 * @return PVMFSuccess/PVMFFailure 989 */ 990 virtual PVMFStatus QueueNPTClockTransitionEvent(uint32 aMediaClockPosition, uint32 aStartNPT, 991 bool aIsPlayBackDirectionBackwards, uint32 aWindow, uint32& aClockTransitionEventID) = 0; 992 993 /** 994 * This API is used to cancel a NPTClockTransition event set by using QueueNPTClockTransitionEvent() 995 * @param aClockTransitionEventID: ID returned from QueueNPTClockTransitionEvent()function. 996 * @return PVMFSuccess/PVMFFailure 997 */ 998 virtual PVMFStatus CancelNPTClockTransitionEvent(uint32 aClockTransitionEventID) = 0; 999 addRef()1000 void addRef() {} removeRef()1001 void removeRef() {} queryInterface(const PVUuid & uuid,PVInterface * & iface)1002 bool queryInterface(const PVUuid& uuid, PVInterface*& iface) 1003 { 1004 OSCL_UNUSED_ARG(uuid); 1005 OSCL_UNUSED_ARG(iface); 1006 return false; 1007 } 1008 }; 1009 1010 /* 1011 PVMFMediaClockNotificationsInterfaceImpl is the implementation class for 1012 PVMFMediaClockNotificationsInterface. 1013 */ 1014 1015 class PVMFMediaClockNotificationsInterfaceImpl: public PVMFMediaClockNotificationsInterface 1016 { 1017 1018 public: 1019 1020 //constructor 1021 1022 OSCL_IMPORT_REF PVMFMediaClockNotificationsInterfaceImpl(PVMFMediaClock *, uint32 aLatency, 1023 PVMFMediaClockNotificationsObsBase& aNotificationInterfaceDestroyedCallback); 1024 1025 /** 1026 The default destructor 1027 */ 1028 OSCL_IMPORT_REF ~PVMFMediaClockNotificationsInterfaceImpl(); 1029 1030 //From PVMFMediaClockNotificationsInterface 1031 1032 OSCL_IMPORT_REF PVMFStatus SetCallbackAbsoluteTime( 1033 /*IN*/ uint32 aAbsoluteTime, 1034 /*IN*/ uint32 aWindow, 1035 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1036 /*IN*/ bool aThreadLock, 1037 /*IN*/ const OsclAny* aContextData, 1038 /*OUT*/ uint32& aCallBackID); 1039 1040 OSCL_IMPORT_REF PVMFStatus SetCallbackDeltaTime( 1041 /*IN*/ uint32 aDeltaTime, 1042 /*IN*/ uint32 aWindow, 1043 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1044 /*IN*/ bool aThreadLock, 1045 /*IN*/ const OsclAny* aContextData, 1046 /*OUT*/ uint32& aCallBackID); 1047 1048 OSCL_IMPORT_REF PVMFStatus CancelCallback( 1049 /*IN*/ uint32 aCallbackID, bool aThreadLock); 1050 1051 OSCL_IMPORT_REF PVMFStatus SetNPTCallbackAbsoluteTime( 1052 /*IN*/ uint32 aAbsoluteTime, 1053 /*IN*/ uint32 aWindow, 1054 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1055 /*IN*/ bool aThreadLock, 1056 /*IN*/ const OsclAny* aContextData, 1057 /*OUT*/ uint32& aCallBackID); 1058 1059 OSCL_IMPORT_REF PVMFStatus SetNPTCallbackDeltaTime( 1060 /*IN*/ uint32 aDeltaTime, 1061 /*IN*/ uint32 aWindow, 1062 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1063 /*IN*/ bool aThreadLock, 1064 /*IN*/ const OsclAny* aContextData, 1065 /*OUT*/ uint32& aCallBackID); 1066 1067 OSCL_IMPORT_REF PVMFStatus CancelNPTCallback( 1068 /*IN*/ uint32 aCallbackID, bool aThreadLock); 1069 1070 OSCL_IMPORT_REF void SetClockObserver(PVMFMediaClockObserver& aObserver); 1071 1072 OSCL_IMPORT_REF void RemoveClockObserver(PVMFMediaClockObserver& aObserver); 1073 1074 OSCL_IMPORT_REF void SetClockStateObserver(PVMFMediaClockStateObserver& aObserver); 1075 1076 OSCL_IMPORT_REF void RemoveClockStateObserver(PVMFMediaClockStateObserver& aObserver); 1077 1078 OSCL_IMPORT_REF PVMFMediaClockCheckTimeWindowStatus CheckTimeWindow( 1079 PVMFMediaClockCheckTimeWindowArgs &aArgs); 1080 1081 OSCL_IMPORT_REF void GetLatencyAdjustedCurrentTime32( 1082 /*OUT*/ uint32& aClockTime, 1083 /*IN*/ bool& aOverflow, 1084 /*IN*/ PVMFMediaClock_TimeUnits aUnits); 1085 1086 //End PVMFMediaClockNotificationsInterface 1087 1088 protected: 1089 1090 /*PVMFMediaClock will have a vector of PVMFMediaClockNotificationsInterfaceImpl 1091 instances. PVMFMediaClock will access iLatency from this class*/ 1092 friend class PVMFMediaClock; 1093 PVMFMediaClockStateObserver *iClockStateObserver; 1094 uint32 iLatency; 1095 PVMFMediaClock *iContainer; 1096 PVMFMediaClockNotificationsObsBase* iNotificationInterfaceDestroyedCallback; 1097 }; 1098 1099 /*This structure represents one callback element inserted in PVMFMediaClock's internal timer queues */ 1100 class PVMFMediaClockTimerQueueElement 1101 { 1102 public: 1103 /** 1104 * Equality comparison for use with OsclPriorityQueue 1105 */ 1106 bool operator==(const PVMFMediaClockTimerQueueElement &other) const 1107 { 1108 return callBackID == other.callBackID; 1109 } 1110 uint32 timeOut; 1111 uint32 callBackID; 1112 bool isNPTTimer; 1113 uint32 window; 1114 PVMFMediaClockNotificationsObs* obs; 1115 const OsclAny* contextData; 1116 const OsclAny* pInterfaceObject; 1117 } ; 1118 1119 1120 /*This structure represents one NPT Clock transition event */ 1121 typedef struct _PVMFMediaClockNPTTransitionEventElement 1122 { 1123 uint32 mediaClockPosition; 1124 uint32 startNPT; 1125 bool isPlayBackDirectionBackwards; 1126 uint32 window; 1127 uint32 eventID; 1128 } PVMFMediaClockNPTTransitionEventElement; 1129 1130 /*This structure represents one clock start notification event */ 1131 typedef struct _PVMFMediaClockStartNotificationEventElement 1132 { 1133 PVMFMediaClockStateObserver *clockStateObserver; 1134 uint32 eventID; 1135 } PVMFMediaClockStartNotificationEventElement; 1136 1137 /*This is the comparison class supplied to PVMFMediaClock's priority queues */ 1138 class PVMFMediaClockTimerQueueCompareLess 1139 { 1140 public: compare(PVMFMediaClockTimerQueueElement & a,PVMFMediaClockTimerQueueElement & b)1141 int compare(PVMFMediaClockTimerQueueElement& a, PVMFMediaClockTimerQueueElement& b) const 1142 { 1143 uint32 delta = 0; 1144 return PVTimeComparisonUtils::IsEarlier(b.timeOut, a.timeOut, delta); 1145 } 1146 }; 1147 1148 /*This comparison class is used for backwards NPT priority queue. This queue needs to maintain timers in 1149 Descending fashion*/ 1150 class PVMFMediaClockTimerQueueCompareLessForNPTBackwards 1151 { 1152 public: compare(PVMFMediaClockTimerQueueElement & a,PVMFMediaClockTimerQueueElement & b)1153 int compare(PVMFMediaClockTimerQueueElement& a, PVMFMediaClockTimerQueueElement& b) const 1154 { 1155 uint32 delta = 0; 1156 return PVTimeComparisonUtils::IsEarlier(a.timeOut, b.timeOut, delta); 1157 } 1158 }; 1159 1160 1161 class PVMFMediaClock : public OsclTimerObject, 1162 public PVMFTimebase, 1163 public PVMFMediaClockObserver, 1164 public PVMFMediaClockControlInterface, 1165 public PVMFMediaClockAccessInterface, 1166 public PVMFMediaClockNPTClockPositionAccessInterface, 1167 public PVMFMediaClockNotificationsImplInterface, 1168 public PVMFMediaClockNotificationsObs /*Media clock uses itself to set callback*/ 1169 { 1170 1171 public: 1172 1173 /** 1174 The default constructor initializes the clock to 0 and goes to STOPPED state 1175 */ 1176 OSCL_IMPORT_REF PVMFMediaClock(); 1177 1178 /** 1179 The default destructor 1180 */ 1181 OSCL_IMPORT_REF ~PVMFMediaClock(); 1182 1183 /** 1184 * Sets the timebase to use for this clock. 1185 * Will trigger an ClockTimebaseUpdated notice to all observers of this clock. 1186 * The clock timebase can only be set while in STOPPED and PAUSED states. 1187 * @param aTimebase: a reference to an PVMFTimebase-derived object 1188 * @return true if the new clock timebase has been accepted, false otherwise 1189 */ 1190 OSCL_IMPORT_REF bool SetClockTimebase(PVMFTimebase& aTimebase); 1191 1192 /** 1193 * This API constructs a PVMFMediaClockNotificationsInterface object. This API does not 1194 * work when clock is in running state and if called while clock is running, it returns 1195 * PVMFErrInvalidState. Object created using this API must be explicitly destroyed using 1196 * DestroyMediaClockNotificationsInterface(). 1197 * @param aIface: PVMFMediaClockNotificationsInterface* variable to store reference to 1198 * constructed notifications object. 1199 * @param aNotificationInterfaceDestroyedCallback: Implementation of callback function 1200 * which would be called when the interface 1201 * is destroyed. 1202 * @param aLatency: uint32 variable containing latency value associated with the module. 1203 * @return true if the new clock timebase has been accepted, false otherwise 1204 */ 1205 OSCL_IMPORT_REF PVMFStatus ConstructMediaClockNotificationsInterface(PVMFMediaClockNotificationsInterface*& aIface, 1206 PVMFMediaClockNotificationsObsBase &aNotificationInterfaceDestroyedCallback, uint32 aLatency = 0); 1207 1208 /* This API destroys the PVMFMediaClockNotificationsInterface object created 1209 * by ConstructMediaClockNotificationsInterface(). 1210 * @param aIface: PVMFMediaClockNotificationsInterface* variable containing reference to 1211 * object to be destroyed. 1212 */ 1213 OSCL_IMPORT_REF void DestroyMediaClockNotificationsInterface(PVMFMediaClockNotificationsInterface* aInf); 1214 1215 1216 1217 // From PVMFTimebase 1218 1219 OSCL_IMPORT_REF void GetCurrentTick32(uint32& aTimebaseTickCount, bool& aOverflow); 1220 GetCountTimebase()1221 PVMFCountTimebase* GetCountTimebase() 1222 { 1223 if (iClockTimebase) 1224 return iClockTimebase->GetCountTimebase(); 1225 return NULL; 1226 } 1227 1228 OSCL_IMPORT_REF void GetTimebaseResolution(uint32& aResolution); 1229 1230 1231 OSCL_IMPORT_REF int32 GetRate(void); 1232 1233 1234 // From PVMFMediaClockControlInterface 1235 1236 OSCL_IMPORT_REF bool Start(); 1237 1238 OSCL_IMPORT_REF bool Pause(); 1239 1240 OSCL_IMPORT_REF bool Stop(); 1241 1242 OSCL_IMPORT_REF bool SetStartTime32(uint32& aTime, PVMFMediaClock_TimeUnits aUnits, bool& aOverFlow); 1243 1244 OSCL_IMPORT_REF PVMFMediaClockAdjustTimeStatus AdjustClockTime32(uint32& aClockTime, uint32& aTimebaseTime, uint32& aAdjustedTime, PVMFMediaClock_TimeUnits aUnits, bool& aOverFlow); 1245 1246 OSCL_IMPORT_REF bool Reset(); 1247 1248 // End PVMFMediaClockControlInterface 1249 1250 // From PVMFMediaClockAccessInterface 1251 1252 OSCL_IMPORT_REF void GetStartTime32(uint32& aTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits); 1253 OSCL_IMPORT_REF void GetCurrentTime32(uint32& aTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits, uint32& aTimebaseTime); 1254 OSCL_IMPORT_REF void GetCurrentTime32(uint32& aTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits); 1255 1256 // End PVMFMediaClockAccessInterface 1257 1258 1259 OSCL_IMPORT_REF bool QueryInterface(const PVUuid& uuid, PVInterface*& iface); 1260 1261 // From PVMFMediaClockNPTClockPositionAccessInterface 1262 1263 void UpdateNPTClockPosition( 1264 /*IN*/ uint32 aStartNPT, 1265 /*IN*/ bool aIsPlayBackDirectionBackwards); 1266 1267 PVMFStatus GetNPTClockPosition( 1268 /*OUT*/ uint32& aCurrentPosition); 1269 1270 void ClearNPTClockPosition(); 1271 1272 PVMFStatus QueueNPTClockTransitionEvent(uint32 aMediaClockPosition, uint32 aStartNPT, 1273 bool aIsPlayBackDirectionBackwards, uint32 aWindow, uint32& aClockTransitionEventID); 1274 1275 PVMFStatus CancelNPTClockTransitionEvent(uint32 aClockTransitionEventID); 1276 // End PVMFMediaClockNPTClockPositionAccessInterface 1277 1278 /* 1279 * Enum for PVMFMediaClock's internal states 1280 */ 1281 enum PVMFMediaClockState 1282 { 1283 STOPPED, 1284 RUNNING, 1285 PAUSED 1286 }; 1287 1288 /*Returns the current state of MediaClock*/ GetState()1289 PVMFMediaClockState GetState() 1290 { 1291 return iState; 1292 } 1293 1294 1295 protected: 1296 1297 friend class PVMFMediaClockNotificationsInterfaceImpl; 1298 1299 //start PVMFMediaClockNotificationsImplInterface functions 1300 /** 1301 Sets an observer for this clock. May leave if memory allocation fails. 1302 @param aObserver: the observer implemenation 1303 */ 1304 OSCL_IMPORT_REF void SetClockObserver(PVMFMediaClockObserver& aObserver); 1305 1306 /** 1307 Removes an observer for this clock. If the observer is not registered, this 1308 call does nothing. 1309 @param aObserver: the observer implemenation 1310 */ 1311 OSCL_IMPORT_REF void RemoveClockObserver(PVMFMediaClockObserver& aObserver); 1312 1313 /** 1314 Sets an observer for this clock. May leave if memory allocation fails. 1315 @param aObserver: the observer implemenation 1316 */ SetClockStateObserver(PVMFMediaClockStateObserver & aObserver)1317 void SetClockStateObserver(PVMFMediaClockStateObserver& aObserver) 1318 {/*Dummy function*/ 1319 OSCL_UNUSED_ARG(aObserver); 1320 } 1321 /** 1322 Removes an observer for this clock. If the observer is not registered, this 1323 call does nothing. 1324 @param aObserver: the observer implemenation 1325 */ RemoveClockStateObserver(PVMFMediaClockStateObserver & aObserver)1326 void RemoveClockStateObserver(PVMFMediaClockStateObserver& aObserver) 1327 {/*Dummy function*/ 1328 OSCL_UNUSED_ARG(aObserver); 1329 } 1330 1331 1332 PVMFStatus SetCallbackAbsoluteTime( 1333 /*IN*/ uint32 aAbsoluteTime, 1334 /*IN*/ uint32 aWindow, 1335 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1336 /*IN*/ bool aThreadLock, 1337 /*IN*/ const OsclAny* aContextData, 1338 /*OUT*/ uint32& aCallBackID, 1339 /*IN*/ const OsclAny* aInterfaceObject); 1340 1341 PVMFStatus SetCallbackDeltaTime( 1342 /*IN*/ uint32 aDeltaTime, 1343 /*IN*/ uint32 aWindow, 1344 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1345 /*IN*/ bool aThreadLock, 1346 /*IN*/ const OsclAny* aContextData, 1347 /*OUT*/ uint32& aCallBackID, 1348 /*IN*/ const OsclAny* aInterfaceObject); 1349 1350 PVMFStatus CancelCallback( 1351 /*IN*/ uint32 aCallbackID, bool aThreadLock); 1352 1353 PVMFStatus SetNPTCallbackAbsoluteTime( 1354 /*IN*/ uint32 aAbsoluteTime, 1355 /*IN*/ uint32 aWindow, 1356 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1357 /*IN*/ bool aThreadLock, 1358 /*IN*/ const OsclAny* aContextData, 1359 /*OUT*/ uint32& aCallBackID, 1360 /*IN*/ const OsclAny* aInterfaceObject); 1361 1362 PVMFStatus SetNPTCallbackDeltaTime( 1363 /*IN*/ uint32 aDeltaTime, 1364 /*IN*/ uint32 aWindow, 1365 /*IN*/ PVMFMediaClockNotificationsObs* aObs, 1366 /*IN*/ bool aThreadLock, 1367 /*IN*/ const OsclAny* aContextData, 1368 /*OUT*/ uint32& aCallBackID, 1369 /*IN*/ const OsclAny* aInterfaceObject); 1370 1371 PVMFStatus CancelNPTCallback( 1372 /*IN*/ uint32 aCallbackID, bool aThreadLock); 1373 1374 //End PVMFMediaClockNotificationsInterface 1375 /** 1376 Changes the clock's state to the specified state 1377 @param aState: the new state to change to 1378 */ 1379 void SetClockState(PVMFMediaClockState aState); 1380 /** 1381 Updates the iLatestTime and iLatestSourceVal to specified values 1382 @param aTime: the new iLatestTime value to change to 1383 @param aSourceVal: the new iLatestSourceVal value to change to 1384 */ 1385 void UpdateLatestTimes(uint32 aTime, uint32 aSourceVal); 1386 1387 /* Gets delta between iStartTimebaseTickValue and current tickcount*/ 1388 void GetScaledTimebaseTickCount(uint32& aScaledTickCount, bool& aOverFlow); 1389 /** 1390 Updates the iLatestRunningClockTime and iLatestRunningTimebaseTime to new units 1391 */ 1392 void AdjustClockInternalsToNewUnits(bool& aOverFlow); 1393 /** 1394 Converts a time value in the specified time units to microseconds 1395 @param aSrcVal: unsigned 32-bit time value in units specified by aSrcUnits 1396 @param aSrcUnits: time units of aSrcVal 1397 @param aUSecVal: reference to unsigned 32-bit integer to store the microsecond time value 1398 */ 1399 void ToClockUnit(uint32& aSrcVal, PVMFMediaClock_TimeUnits aSrcUnits, uint32& aDestVal, bool& aOverFlow); 1400 /** 1401 Converts a millisecond time value to the specified time units 1402 @param aUSecVal: unsigned 32-bit integer in microsecond time value 1403 @param aDstVal: reference to unsigned 32-bit integer which will contain aUSecVal in the 1404 specified aDstUnits time units 1405 @param aDstUnits: requested time units for aDstVal 1406 */ 1407 1408 void FromClockUnit(uint32& aClockUnitVal, uint32& aDstVal, 1409 PVMFMediaClock_TimeUnits aDstUnits, bool& aOverFlow); 1410 1411 /** 1412 Converts a time value in the specified time units to microseconds 1413 @param aSrcVal: unsigned 32-bit time value in units specified by aSrcUnits 1414 @param aSrcUnits: time units of aSrcVal 1415 @param aUSecVal: reference to unsigned 32-bit integer to store the microsecond time value 1416 */ 1417 void ToUSec(uint32& aSrcVal, PVMFMediaClock_TimeUnits aSrcUnits, 1418 uint32& aUSecVal, bool& aOverflow); 1419 1420 /** 1421 Converts timebase ticks to clock units 1422 @param aDelta: unsigned 32-bit tickcount value 1423 @param aDeltaTime: reference to unsigned 32-bit integer to store time 1424 */ 1425 void ConvertTickcountToClockUnits(uint32 aTickcount, uint32& aTimeValue, bool& aOverflowFlag); 1426 /** 1427 Updates the internal clock parameters based on the adjustment information provided. 1428 This function can be overridden in the derived classes to allow variety in the adjustment algorithm 1429 @param aObsTime: unsigned 32-bit integer in microsecond for the observed clock time 1430 @param aObsTimebase: unsigned 32-bit integer in microsecond for the observed timebase time 1431 @param aAdjTime: unsigned 32-bit integer in microsecond for the adjusted clock time 1432 @param aCurrentTime: unsigned 32-bit integer in microsecond for the current clock time 1433 @param aCurrentTimebase: unsigned 32-bit integer in microsecond for the current timebase time 1434 */ 1435 PVMFMediaClockAdjustTimeStatus AdjustClock(uint32& aObsTime, uint32& aObsTimebase, uint32& aAdjTime, 1436 uint32& aCurrentTime, uint32& aCurrentTimebase); 1437 1438 /** 1439 Returns the adjusted current clock time when the clock is running 1440 This function can be overridden in the derived classes to allow variety in the adjustment algorithm 1441 @param aDstTime: unsigned 32-bit integer in microseconds to output the adjusted current clock time 1442 @param aTimebaseVal: unsigned 32-bit integer in microseconds of the current timebase time 1443 */ 1444 void GetAdjustedRunningClockTime(uint32& aDstTime, uint32& aTimebaseVal); 1445 1446 //Possible units for time keeping 1447 enum PVMFMediaClock_ClockUnit 1448 { 1449 PVMF_MEDIA_CLOCK_CLOCKUNIT_USEC = 0, 1450 PVMF_MEDIA_CLOCK_CLOCKUNIT_MSEC = 1 1451 }; 1452 1453 PVLogger* iLogger; 1454 1455 1456 // Timebase time is stored as unsigned 32-bit value in microseconds 1457 uint32 iLatestRunningClockTime; // Last reference clock time due to starting/resuming, pausing, and adjustment 1458 uint32 iLatestRunningTimebaseTime; // Timebase time corresponding to the latest running clock time 1459 uint32 iStartTimebaseTickValue; // Timebase tick value at clock start time. 1460 uint32 iStartClockTime; // Starting clock time. Set by the SetStartTime...() APIs 1461 uint32 iPauseClockTime; // Clock time when Pause() API is called. 1462 uint32 iLastAdjustObsTimebaseTime; // The observed timebase time corresponding to the adjusted time passed in 1463 uint32 iAdjustmentTimebaseTime; // The timebase time of the last successful AdjustClockTime...() call 1464 PVMFMediaClock_ClockUnit iClockUnit; // unit of above values in clock implementation 1465 PVMFMediaClock_ClockUnit iPreviousClockUnit; // unit of above values in clock implementation 1466 1467 PVMFMediaClockState iState; // Internal state of the clock 1468 1469 PVMFTimebase* iClockTimebase; // Pointer to this clock's timebase 1470 //vector of clock observers. 1471 Oscl_Vector<PVMFMediaClockObserver*, OsclMemAllocator> iClockObservers; 1472 1473 //from PVMFMediaClockObserver, for callbacks from an PVMFCountTimebase. 1474 void ClockCountUpdated(); 1475 void ClockTimebaseUpdated(); 1476 void ClockAdjusted(); 1477 1478 // for NPT mapping 1479 bool iIsNPTPlayBackDirectionBackwards; 1480 PVMFTimestamp iStartNPT; 1481 PVMFTimestamp iStartMediaClockTS; 1482 1483 //for npt transition queueing 1484 Oscl_Vector<PVMFMediaClockNPTTransitionEventElement, OsclMemAllocator> iNPTTransitionEventQueue; 1485 1486 //for clock-start notification event queuing 1487 Oscl_Vector<PVMFMediaClockStartNotificationEventElement, OsclMemAllocator> iClockStartNotificationEventQueue; 1488 1489 //vector of PVMFMediaClockNotificationsInterfaceImpl objects. Each object represents a session 1490 Oscl_Vector<PVMFMediaClockNotificationsInterfaceImpl*, OsclMemAllocator> iMediaClockSetCallbackObjects; 1491 1492 //latency handling 1493 uint32 iHighestLatency; 1494 void UpdateHighestLatency(uint32 alatency); 1495 1496 //callback related functions, members 1497 1498 OsclPriorityQueue < PVMFMediaClockTimerQueueElement, OsclMemAllocator, Oscl_Vector<PVMFMediaClockTimerQueueElement, OsclMemAllocator>, 1499 PVMFMediaClockTimerQueueCompareLess > iTimersPriQueue; 1500 1501 //Mutex for multithreading support 1502 OsclMutex *iMutex; 1503 1504 //For keeping count of active timers 1505 uint32 iActiveTimersCount; 1506 1507 //For keeping track of timer ID count. 1508 uint32 iTimerIDCount; 1509 1510 //This stores the current thread ID when clock is constructed. 1511 TOsclThreadId iOrigThreadID; 1512 1513 // Variables to be used when timebase is swapped. 1514 int32 iLastTimebaseRate; 1515 1516 bool iIsTimebaseCountBased; 1517 1518 //common setCallback() for regular and NPT timers 1519 PVMFStatus SetCallbackCommon(uint32 aDeltaTime, uint32 aWindow, 1520 PVMFMediaClockNotificationsObs* aCallback, bool aThreadLock, const OsclAny* aContextData, 1521 uint32& aCallBackID, const OsclAny* aInterfaceObject, uint32 aCurrentTime, bool aIsNPT); 1522 1523 //common CancelCallback() for regular and NPT timers 1524 PVMFStatus CommonCancelCallback(uint32 aCallbackID, bool aThreadLock, bool aIsNPT); 1525 1526 /** 1527 This is a generic function for doing fresh scheduling of PVMFMediaClock object 1528 This function is called when a new callback is created. a callback is cancelled or 1529 when clock state changes. 1530 @param aIsNPT: signifies if aCurrentTime is NPT time 1531 @param aCurrentTime: This is passed for optimization. More often than not, the calling 1532 function has the current time value. If no argument is supplied, GetCurrentTime() is called. 1533 */ 1534 void AdjustScheduling(bool aIsNPT = false, uint32 aCurrentTime = 0); 1535 1536 //for AO 1537 void Run(); 1538 1539 //Destoys all callback interface objects created. This is called from the destructor. 1540 void CleanCallbackInfImplObjects(); 1541 1542 /** 1543 This function calculates the optimum time period after which Run() should be called. 1544 @param aIsNPT: signifies if aCurrentTime is NPT time 1545 @param aCurrentTime: This is passed for optimization as calling function has current time value. 1546 @param aDelta: Time value to be passed in RunIfNotActive() 1547 */ 1548 void CalculateRunLTimerValue(bool aIsNPT, uint32 aCurrentTime, int32& aDelta); 1549 1550 //NPT callbacks related members 1551 OsclPriorityQueue < PVMFMediaClockTimerQueueElement, OsclMemAllocator, Oscl_Vector<PVMFMediaClockTimerQueueElement, OsclMemAllocator>, 1552 PVMFMediaClockTimerQueueCompareLess > iTimersPriQueueNPT; 1553 1554 OsclPriorityQueue < PVMFMediaClockTimerQueueElement, OsclMemAllocator, Oscl_Vector<PVMFMediaClockTimerQueueElement, OsclMemAllocator>, 1555 PVMFMediaClockTimerQueueCompareLessForNPTBackwards > iTimersPriQueueNPTBackwards; 1556 1557 //For flushing out queue when playback direction changes. This is done with NPT clock 1558 void ClearPresentNPTQueue(); 1559 1560 void ClearAllQueues(); 1561 1562 //From PVMFMediaClockNotificationsObs interface 1563 void ProcessCallBack(uint32 aCallBackID, PVTimeComparisonUtils::MediaTimeStatus aTimerAccuracy, uint32 delta, 1564 const OsclAny* acontextData, PVMFStatus aStatus); 1565 void NotificationsInterfaceDestroyed(); 1566 1567 void QueueClockStartNotificationEvent(uint32 aDelta, PVMFMediaClockStateObserver *aClockStateObserver); 1568 }; 1569 1570 /** 1571 PVMFTimebase_Tickcount is PVMFTimebase-derived class which uses 1572 the OSCL's system tickcount as the timebase. This class is provided 1573 as the default PVMFTimebase that is available on any platform with OSCL support. 1574 */ 1575 class OSCL_IMPORT_REF PVMFTimebase_Tickcount : public PVMFTimebase 1576 { 1577 public: 1578 /** 1579 Constructor. Retrieves the constant to convert OSCL tickcount value to microseconds 1580 */ PVMFTimebase_Tickcount()1581 PVMFTimebase_Tickcount() 1582 { 1583 iMicrosecPerTick = OsclTickCount::TickCountPeriod(); 1584 iPrevTickcount = 0; 1585 } 1586 1587 /** 1588 Destructor 1589 */ ~PVMFTimebase_Tickcount()1590 ~PVMFTimebase_Tickcount() 1591 { 1592 } 1593 1594 // From PVMFTimebase 1595 /** 1596 Returns the OSCL tickcount's time resolution in microseconds 1597 Implementation of virtual function from PVMFTimebase 1598 @param aResolution: On function completion, contains OSCL tickcount resolution 1599 */ GetTimebaseResolution(uint32 & aResolution)1600 void GetTimebaseResolution(uint32& aResolution) 1601 { 1602 aResolution = iMicrosecPerTick; 1603 } GetRate(void)1604 int32 GetRate(void) 1605 { 1606 return REALTIME_PLAYBACK_RATE; 1607 } 1608 OSCL_IMPORT_REF void GetCurrentTick32(uint32& aTimebaseTickCount, bool& aOverflow); 1609 OSCL_IMPORT_REF void GetCurrentTime32(uint32& aTime, bool& aOverflow, PVMFMediaClock_TimeUnits aUnits); 1610 GetCountTimebase()1611 PVMFCountTimebase* GetCountTimebase() 1612 { 1613 return NULL; 1614 } 1615 1616 protected: 1617 uint32 iMicrosecPerTick; 1618 uint32 iPrevTickcount; 1619 1620 }; 1621 1622 /** 1623 PVMFTimebase_Count is PVMFTimebase-derived class that can be used to 1624 implement a simple count-based timebase. 1625 */ 1626 class PVMFTimebase_Count : public PVMFTimebase, public PVMFCountTimebase 1627 { 1628 public: 1629 /** 1630 Constructor. 1631 */ PVMFTimebase_Count()1632 PVMFTimebase_Count() 1633 { 1634 iCurrentCount = 0; 1635 iObserver = NULL; 1636 } 1637 1638 /** 1639 Destructor 1640 */ ~PVMFTimebase_Count()1641 ~PVMFTimebase_Count() 1642 { 1643 } 1644 1645 // From PVMFTimebase 1646 /** 1647 Returns the OSCL tickcount's time resolution in microseconds 1648 Implementation of virtual function from PVMFTimebase 1649 @param aResolution: On function completion, contains OSCL tickcount resolution 1650 */ GetTimebaseResolution(uint32 & aResolution)1651 void GetTimebaseResolution(uint32& aResolution) 1652 { 1653 aResolution = 0; //not meaningful for a count-based timebase. 1654 } 1655 GetRate(void)1656 int32 GetRate(void) 1657 { 1658 return 0; //not meaningful for a count-based timebase. 1659 } 1660 /** 1661 Returns the current clock time as unsigned 32-bit integer object in the specified time units 1662 @param aTime: a reference to an unsigned 32-bit integer to return the current time 1663 @param aUnits: the requested time units for aTime 1664 @param aTimebaseTime: a reference to an unsigned 32-bit integer to return the timebase time 1665 */ GetCurrentTick32(uint32 & aTick,bool & aOverflow)1666 void GetCurrentTick32(uint32& aTick, bool& aOverflow) 1667 { 1668 //not meaningful for a count-based timebase. 1669 aTick = 0; 1670 aOverflow = false; 1671 } 1672 /** 1673 Returns the PVMFCountTimebase implementation pointer 1674 */ GetCountTimebase()1675 PVMFCountTimebase* GetCountTimebase() 1676 { 1677 return this; 1678 } 1679 1680 //From PVMFCountTimebase 1681 /** 1682 Used to adjust the current count. 1683 @param aCount (input): new count value. 1684 */ SetCount(int32 aCount)1685 void SetCount(int32 aCount) 1686 { 1687 iCurrentCount = aCount; 1688 if (iObserver) 1689 { 1690 iObserver->ClockCountUpdated(); 1691 } 1692 } 1693 1694 /** 1695 Used to retreive the current count. 1696 @param aCount (output): new count value. 1697 */ GetCount(int32 & aCount)1698 void GetCount(int32& aCount) 1699 { 1700 aCount = iCurrentCount; 1701 } 1702 1703 protected: 1704 int32 iCurrentCount; 1705 PVMFMediaClockObserver* iObserver; 1706 1707 private: 1708 friend class PVMFMediaClock; 1709 //From PVMFCountTimebase SetClockObserver(PVMFMediaClockObserver * aObserver)1710 void SetClockObserver(PVMFMediaClockObserver* aObserver) 1711 { 1712 iObserver = aObserver; 1713 } 1714 1715 }; 1716 #endif //PVMF_MEDIA_CLOCK_H_INCLUDED 1717