os/mm/mmhais/videohai/devvideo/src/DevVideo/devvideobase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-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 "devvideobase.h"
sl@0
    17
#include "devvideoconstants.h"
sl@0
    18
sl@0
    19
//Include the following headers here just to check they can be compiled OK. 
sl@0
    20
#include "Mpeg4Visual.h"
sl@0
    21
#include "AVC.h"
sl@0
    22
#include "H263.h"
sl@0
    23
#include "vc1.h"
sl@0
    24
#include "on2vp6.h"
sl@0
    25
#include "sorensonspark.h"
sl@0
    26
sl@0
    27
EXPORT_C CCompressedVideoFormat* CCompressedVideoFormat::NewL(const TDesC8& aMimeType,const TDesC8& aOptionalData)
sl@0
    28
	{
sl@0
    29
	CCompressedVideoFormat* s = new(ELeave) CCompressedVideoFormat;
sl@0
    30
	CleanupStack::PushL(s);
sl@0
    31
	s->ConstructL(aMimeType, aOptionalData);
sl@0
    32
	CleanupStack::Pop(s);
sl@0
    33
	return s;
sl@0
    34
	}
sl@0
    35
sl@0
    36
EXPORT_C CCompressedVideoFormat* CCompressedVideoFormat::NewL(const CCompressedVideoFormat& aFormat)
sl@0
    37
	{
sl@0
    38
	CCompressedVideoFormat* s = new(ELeave) CCompressedVideoFormat;
sl@0
    39
	CleanupStack::PushL(s);
sl@0
    40
	s->ConstructL(aFormat.MimeType(), aFormat.OptionalData());
sl@0
    41
	CleanupStack::Pop(s);
sl@0
    42
	return s;
sl@0
    43
	}
sl@0
    44
sl@0
    45
EXPORT_C CCompressedVideoFormat::~CCompressedVideoFormat()
sl@0
    46
	{
sl@0
    47
	delete iMimeType;
sl@0
    48
	delete iOptionalData;
sl@0
    49
	}
sl@0
    50
sl@0
    51
EXPORT_C const TDesC8& CCompressedVideoFormat::MimeType() const
sl@0
    52
	{
sl@0
    53
	return *iMimeType;
sl@0
    54
	}
sl@0
    55
sl@0
    56
EXPORT_C const TDesC8& CCompressedVideoFormat::OptionalData() const
sl@0
    57
	{
sl@0
    58
	return *iOptionalData;
sl@0
    59
	}
sl@0
    60
sl@0
    61
CCompressedVideoFormat::CCompressedVideoFormat()
sl@0
    62
	{
sl@0
    63
	}
sl@0
    64
sl@0
    65
void CCompressedVideoFormat::ConstructL(const TDesC8& aMimeType, const TDesC8& aOptionalData)
sl@0
    66
	{
sl@0
    67
	iMimeType = aMimeType.AllocL();
sl@0
    68
	iOptionalData = aOptionalData.AllocL();
sl@0
    69
	}
sl@0
    70
sl@0
    71
EXPORT_C TBool CCompressedVideoFormat::operator==(const CCompressedVideoFormat& aOther) const
sl@0
    72
	{
sl@0
    73
	TBool retval = EFalse;
sl@0
    74
	// only test optionalData if aOther has an optional data of length > 0.  Need a
sl@0
    75
	// check like this for performing matches on mimetype only.
sl@0
    76
	if (aOther.OptionalData().Length() > 0)
sl@0
    77
		retval = ((aOther.MimeType().CompareF(*iMimeType) == 0) && (aOther.OptionalData().CompareF(*iOptionalData) == 0));
sl@0
    78
	else
sl@0
    79
		retval = ((aOther.MimeType().CompareF(*iMimeType) == 0));
sl@0
    80
	return retval;
sl@0
    81
	}
sl@0
    82
sl@0
    83
sl@0
    84
sl@0
    85
EXPORT_C CSystemClockSource* CSystemClockSource::NewL()
sl@0
    86
	{
sl@0
    87
	CSystemClockSource* s = new(ELeave) CSystemClockSource;
sl@0
    88
	CleanupStack::PushL(s);
sl@0
    89
	s->ConstructL();
sl@0
    90
	CleanupStack::Pop(s);
sl@0
    91
	return s;
sl@0
    92
	}
sl@0
    93
sl@0
    94
CSystemClockSource::CSystemClockSource()
sl@0
    95
	{
sl@0
    96
	iStartTime.UniversalTime();
sl@0
    97
	iTimeSuspended = 0;
sl@0
    98
	}
sl@0
    99
sl@0
   100
void CSystemClockSource::ConstructL()
sl@0
   101
	{
sl@0
   102
	User::LeaveIfError(iCriticalSection.CreateLocal());
sl@0
   103
	}
sl@0
   104
sl@0
   105
EXPORT_C CSystemClockSource::~CSystemClockSource()
sl@0
   106
	{
sl@0
   107
	iCriticalSection.Close();
sl@0
   108
	}
sl@0
   109
sl@0
   110
TAny* CSystemClockSource::CustomInterface(TUid /*aInterface*/)
sl@0
   111
	{
sl@0
   112
	return NULL;
sl@0
   113
	}
sl@0
   114
sl@0
   115
EXPORT_C void CSystemClockSource::Reset()
sl@0
   116
	{
sl@0
   117
	iCriticalSection.Wait();
sl@0
   118
	iStartTime.UniversalTime();
sl@0
   119
	iOffset = 0;
sl@0
   120
	iTimeSuspended = 0;
sl@0
   121
	iCriticalSection.Signal();
sl@0
   122
	}
sl@0
   123
sl@0
   124
EXPORT_C void CSystemClockSource::Reset(const TTimeIntervalMicroSeconds& aOffset)
sl@0
   125
	{
sl@0
   126
	iCriticalSection.Wait();
sl@0
   127
	iStartTime.UniversalTime();
sl@0
   128
	iOffset = aOffset;
sl@0
   129
	iTimeSuspended = 0;
sl@0
   130
	iCriticalSection.Signal();
sl@0
   131
	}
sl@0
   132
sl@0
   133
TTimeIntervalMicroSeconds CSystemClockSource::Time()
sl@0
   134
	{
sl@0
   135
	iCriticalSection.Wait();
sl@0
   136
	TTimeIntervalMicroSeconds elapsed(0);
sl@0
   137
	if (!iSuspended)
sl@0
   138
		{
sl@0
   139
		iCurrentTime.UniversalTime();
sl@0
   140
		elapsed = iCurrentTime.MicroSecondsFrom(iStartTime);
sl@0
   141
		}
sl@0
   142
	else
sl@0
   143
		{
sl@0
   144
		// If we're currently suspended, current time == time when we were suspended
sl@0
   145
		elapsed = iTimeWhenSuspended.MicroSecondsFrom(iStartTime);
sl@0
   146
		}
sl@0
   147
sl@0
   148
	// Perceived elapsed time == true elapsed + offset - time spent suspended
sl@0
   149
	TInt64 time = elapsed.Int64() + iOffset.Int64() - iTimeSuspended.Int64();
sl@0
   150
	iCriticalSection.Signal();
sl@0
   151
	return time;
sl@0
   152
	}
sl@0
   153
sl@0
   154
EXPORT_C void CSystemClockSource::Suspend()
sl@0
   155
	{
sl@0
   156
	__ASSERT_DEBUG(!iSuspended, DevVideoPanic(EDevVideoPanicPreConditionViolation));
sl@0
   157
	iCriticalSection.Wait();
sl@0
   158
	iTimeWhenSuspended.UniversalTime();
sl@0
   159
	iSuspended = ETrue;
sl@0
   160
	iCriticalSection.Signal();
sl@0
   161
	}
sl@0
   162
sl@0
   163
EXPORT_C void CSystemClockSource::Resume()
sl@0
   164
	{
sl@0
   165
	__ASSERT_DEBUG(iSuspended, DevVideoPanic(EDevVideoPanicPreConditionViolation));
sl@0
   166
	iCriticalSection.Wait();
sl@0
   167
	iSuspended = EFalse;
sl@0
   168
	iCurrentTime.UniversalTime();
sl@0
   169
	iTimeSuspended = iTimeSuspended.Int64() + iCurrentTime.MicroSecondsFrom(iTimeWhenSuspended).Int64();
sl@0
   170
	iCriticalSection.Signal();
sl@0
   171
	}
sl@0
   172
sl@0
   173
sl@0
   174
EXPORT_C CMMFClockSourcePeriodicUtility* CMMFClockSourcePeriodicUtility::NewL(MMMFClockSource& aClockSource, MMMFClockSourcePeriodicUtilityObserver& aObserver)
sl@0
   175
	{
sl@0
   176
	CMMFClockSourcePeriodicUtility* s = new(ELeave) CMMFClockSourcePeriodicUtility(aClockSource, aObserver);
sl@0
   177
	CleanupStack::PushL(s);
sl@0
   178
	s->ConstructL();
sl@0
   179
	CleanupStack::Pop(s);
sl@0
   180
	return s;
sl@0
   181
	}
sl@0
   182
sl@0
   183
CMMFClockSourcePeriodicUtility::CMMFClockSourcePeriodicUtility(MMMFClockSource& aClockSource, MMMFClockSourcePeriodicUtilityObserver& aObserver) :
sl@0
   184
	iClockSource(aClockSource),
sl@0
   185
	iObserver(aObserver)
sl@0
   186
	{
sl@0
   187
	}
sl@0
   188
sl@0
   189
void CMMFClockSourcePeriodicUtility::ConstructL()
sl@0
   190
	{
sl@0
   191
	iTimer = CPeriodic::NewL(EPriorityNormal);
sl@0
   192
	}
sl@0
   193
sl@0
   194
EXPORT_C void CMMFClockSourcePeriodicUtility::Start(TTimeIntervalMicroSeconds32 aPeriod)
sl@0
   195
	{
sl@0
   196
	TCallBack callback(CMMFClockSourcePeriodicUtility::Callback, this);
sl@0
   197
	iTimer->Start(aPeriod, aPeriod, callback);
sl@0
   198
	}
sl@0
   199
sl@0
   200
EXPORT_C void CMMFClockSourcePeriodicUtility::Stop()
sl@0
   201
	{
sl@0
   202
	iTimer->Cancel();
sl@0
   203
	}
sl@0
   204
sl@0
   205
EXPORT_C CMMFClockSourcePeriodicUtility::~CMMFClockSourcePeriodicUtility()
sl@0
   206
	{
sl@0
   207
	delete iTimer;
sl@0
   208
	}
sl@0
   209
sl@0
   210
TInt CMMFClockSourcePeriodicUtility::Callback(TAny* aAny)
sl@0
   211
	{
sl@0
   212
	CMMFClockSourcePeriodicUtility* me = reinterpret_cast<CMMFClockSourcePeriodicUtility*>(aAny);
sl@0
   213
	me->DoCallback();
sl@0
   214
	return KErrNone;
sl@0
   215
	}
sl@0
   216
sl@0
   217
void CMMFClockSourcePeriodicUtility::DoCallback()
sl@0
   218
	{
sl@0
   219
	iObserver.MmcspuoTick(iClockSource.Time());
sl@0
   220
	}
sl@0
   221
sl@0
   222