os/mm/mmdevicefw/mdf/src/video/hwdevicevideoutils/mdfplayerengine.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32debug.h>
sl@0
    17
sl@0
    18
#include "mdfplayerengine.h"
sl@0
    19
sl@0
    20
#if defined (SYMBIAN_MDFPLAYERENGINE_DEBUG)
sl@0
    21
#define DEBUG_PRINT RDebug::Print
sl@0
    22
#else
sl@0
    23
#define DEBUG_PRINT
sl@0
    24
#endif // defined(SYMBIAN_MDFPLAYERENGINE_DEBUG)
sl@0
    25
sl@0
    26
const TInt KOneSecond = 1000000;
sl@0
    27
sl@0
    28
/* 
sl@0
    29
 Constructs a new instance of CMdfVideoPlayerEngine.
sl@0
    30
 @return    "CMdfVideoPlayerEngine*"
sl@0
    31
            A pointer to the newly constructed CMdfVideoPlayerEngine
sl@0
    32
 */
sl@0
    33
CMdfVideoPlayerEngine* CMdfVideoPlayerEngine::NewL(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver)
sl@0
    34
	{
sl@0
    35
	CMdfVideoPlayerEngine* self = new (ELeave) CMdfVideoPlayerEngine(aDeviceObserver);
sl@0
    36
	CleanupStack::PushL(self);
sl@0
    37
	self->ConstructL();
sl@0
    38
	CleanupStack::Pop(self);
sl@0
    39
	return self;	
sl@0
    40
	}
sl@0
    41
sl@0
    42
sl@0
    43
/** 
sl@0
    44
 Constructs and initialises a new instance of CMdfVideoPlayerEngine.
sl@0
    45
 
sl@0
    46
 @param     "MMdfVideoPlayerHwDeviceObserver& aDeviceObserver"
sl@0
    47
            A reference to the HwDevice on which it will operate
sl@0
    48
 */
sl@0
    49
CMdfVideoPlayerEngine::CMdfVideoPlayerEngine(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver)
sl@0
    50
	: iDeviceObserver(aDeviceObserver)
sl@0
    51
	{	
sl@0
    52
	}
sl@0
    53
sl@0
    54
sl@0
    55
void CMdfVideoPlayerEngine::ConstructL()
sl@0
    56
	{
sl@0
    57
	iTimer = CPeriodic::NewL(EPriorityHigh);		
sl@0
    58
	}
sl@0
    59
sl@0
    60
/** 
sl@0
    61
 Default destructor
sl@0
    62
 */
sl@0
    63
CMdfVideoPlayerEngine::~CMdfVideoPlayerEngine()
sl@0
    64
	{
sl@0
    65
	// stop if we need to
sl@0
    66
	Stop();
sl@0
    67
	}
sl@0
    68
sl@0
    69
/** 
sl@0
    70
 Starts the player engine.
sl@0
    71
 
sl@0
    72
 @param     "TUint aFrameRate"
sl@0
    73
            The actual frame rate for display, or KUnsynchronized
sl@0
    74
 @leave		May leave with KErrNotReady if the frame rate is not initialized.            
sl@0
    75
 */
sl@0
    76
void CMdfVideoPlayerEngine::StartL(TUint aFrameRate)
sl@0
    77
	{
sl@0
    78
	if(aFrameRate == 0) 
sl@0
    79
		{
sl@0
    80
		User::Leave(KErrNotReady);
sl@0
    81
		}
sl@0
    82
	
sl@0
    83
	iFrameRate = aFrameRate;
sl@0
    84
	
sl@0
    85
	// get current tick count, save this
sl@0
    86
	iStartTime = iDeviceObserver.Time();
sl@0
    87
	iFrameCount = 0;
sl@0
    88
	
sl@0
    89
	DEBUG_PRINT(_L("+++ PlayerEngine: Starting"));
sl@0
    90
    iTimer->Cancel();
sl@0
    91
    iTimer->Start(KMaxFrameRate, KMaxFrameRate, TCallBack(DisplayFrame, this));
sl@0
    92
	}
sl@0
    93
      
sl@0
    94
/** 
sl@0
    95
 Stops the player engine.
sl@0
    96
 */
sl@0
    97
void CMdfVideoPlayerEngine::Stop()
sl@0
    98
	{
sl@0
    99
	if(iTimer) 
sl@0
   100
		{
sl@0
   101
		DEBUG_PRINT(_L("+++ PlayerEngine: Stopping"));
sl@0
   102
	    iTimer->Cancel();
sl@0
   103
	    delete iTimer;
sl@0
   104
	    iTimer = NULL;
sl@0
   105
		}
sl@0
   106
	}
sl@0
   107
	
sl@0
   108
/**
sl@0
   109
 Returns the frame rate.
sl@0
   110
 
sl@0
   111
 @return The frame rate.
sl@0
   112
*/	
sl@0
   113
TInt CMdfVideoPlayerEngine::FrameRate()
sl@0
   114
	{
sl@0
   115
	return iFrameRate;
sl@0
   116
	}
sl@0
   117
	
sl@0
   118
/**
sl@0
   119
 Returns the frame count.
sl@0
   120
 
sl@0
   121
 @return The frame count.
sl@0
   122
*/	
sl@0
   123
TInt CMdfVideoPlayerEngine::FrameCount()
sl@0
   124
	{
sl@0
   125
	return iFrameCount;
sl@0
   126
	}
sl@0
   127
sl@0
   128
/** 
sl@0
   129
 Static callback method for the CPeriodic timer
sl@0
   130
 */
sl@0
   131
TInt CMdfVideoPlayerEngine::DisplayFrame(TAny* aObject)
sl@0
   132
	{
sl@0
   133
    // cast, and call non-static function
sl@0
   134
    (reinterpret_cast<CMdfVideoPlayerEngine*>(aObject))->DoDisplayFrame();
sl@0
   135
    return KErrNone;
sl@0
   136
	}
sl@0
   137
sl@0
   138
/** 
sl@0
   139
 Processes one frame if available.
sl@0
   140
 */
sl@0
   141
void CMdfVideoPlayerEngine::DoDisplayFrame()
sl@0
   142
	{
sl@0
   143
	if(iDeviceObserver.FrameAvailable()) 
sl@0
   144
		{
sl@0
   145
		// if we're playing unsynchronized, then return the frame
sl@0
   146
		// regardless of time
sl@0
   147
		if(iFrameRate == KUnsynchronized) 
sl@0
   148
			{
sl@0
   149
			iFrameCount++;	
sl@0
   150
			DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo"));
sl@0
   151
			iDeviceObserver.DisplayFrame();
sl@0
   152
			}
sl@0
   153
		else 
sl@0
   154
			{
sl@0
   155
			TUint curPlayTime = iDeviceObserver.Time();
sl@0
   156
		
sl@0
   157
			// if we've missed a tick, then discard the frame.
sl@0
   158
			// (unless it's the first frame; always display this)
sl@0
   159
			if(iFrameCount) 
sl@0
   160
				{
sl@0
   161
				TUint nextNextFrameTime = iStartTime + ((iFrameCount + 1) * (KOneSecond / iFrameRate));
sl@0
   162
				if(nextNextFrameTime <= curPlayTime) 
sl@0
   163
					{
sl@0
   164
					iFrameCount++;	
sl@0
   165
					DEBUG_PRINT(_L("+++ PlayerEngine: Discarding frame buffer"));
sl@0
   166
					iDeviceObserver.DiscardFrame();
sl@0
   167
					return;
sl@0
   168
					}
sl@0
   169
				}
sl@0
   170
			// else if we're past the expected display time
sl@0
   171
			// then display the frame.
sl@0
   172
			TUint nextFrameTime = iStartTime + (iFrameCount * (KOneSecond / iFrameRate));
sl@0
   173
			if(!iFrameCount || nextFrameTime <= curPlayTime) 
sl@0
   174
				{
sl@0
   175
				iFrameCount++;	
sl@0
   176
				DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo"));
sl@0
   177
				iDeviceObserver.DisplayFrame();
sl@0
   178
				}
sl@0
   179
			}
sl@0
   180
		}
sl@0
   181
	}
sl@0
   182
sl@0
   183
// end