omxilvideocomps/omxil3gpdemuxer/src/c3gpdemuxer.cpp
author hgs
Fri, 08 Oct 2010 22:09:17 +0100
changeset 0 5d29cba61097
permissions -rw-r--r--
2010wk38_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     1
/*
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     2
* Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     3
* All rights reserved.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     8
*
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
     9
* Initial Contributors:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    11
*
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    12
* Contributors:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    13
*
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    14
* Description:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    15
*
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    16
*/
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    17
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    18
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    19
/**
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    20
 @file
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    21
 @internalComponent
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    22
 */
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    23
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    24
#include "log.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    25
#include <openmax/il/common/omxilcallbacknotificationif.h>
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    26
#include <openmax/il/common/omxilutil.h>
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    27
#include "c3gpdemuxer.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    28
#include "omxil3gpdemuxerpanic.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    29
#include "comxil3gpdemuxertimeinputport.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    30
#include "comxil3gpdemuxeraudiooutputport.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    31
#include "comxil3gpdemuxervideooutputport.h"
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    32
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    33
C3GPDemuxer::CPort* C3GPDemuxer::CPort::NewL(TInt aBufferCount)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    34
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    35
	CPort* self = new (ELeave) CPort();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    36
	CleanupStack::PushL(self);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    37
	self->ConstructL(aBufferCount);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    38
	CleanupStack::Pop(self);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    39
	return self;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    40
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    41
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    42
C3GPDemuxer::CPort::CPort() :
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    43
	iEOS(EFalse)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    44
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    45
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    46
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    47
void C3GPDemuxer::CPort::ConstructL(TInt aBufferCount)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    48
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    49
	iBuffers.ReserveL(aBufferCount);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    50
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    51
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    52
C3GPDemuxer::CPort::~CPort()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    53
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    54
	iBuffers.Reset();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    55
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    56
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    57
C3GPDemuxer* C3GPDemuxer::NewL(MOmxILCallbackNotificationIf& aCallbacks)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    58
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    59
	C3GPDemuxer* self = new (ELeave) C3GPDemuxer(aCallbacks);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    60
	CleanupStack::PushL(self);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    61
	self->ConstructL();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    62
	CleanupStack::Pop(self);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    63
	return self;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    64
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    65
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    66
void C3GPDemuxer::ConstructL()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    67
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    68
	i3GPParser = C3GPParse::NewL();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    69
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    70
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    71
C3GPDemuxer::C3GPDemuxer(MOmxILCallbackNotificationIf& aCallbacks) :
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    72
	CActive(EPriorityStandard),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    73
	iCallbacks(aCallbacks),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    74
	iVideoType(E3GPNoVideo),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    75
	iAudioType(E3GPNoAudio),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    76
	iFirstVideoFrame(ETrue),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    77
	iFirstAudioFrame(ETrue),
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    78
	iAsyncBuf(0, 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    79
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    80
	iOmxAudioFormat.iCoding = OMX_AUDIO_CodingMax;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    81
	iOmxVideoFormat.iCoding = OMX_VIDEO_CodingMax;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    82
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    83
	for (TInt port = 0; port < COmxIL3GPDemuxer::EPortIndexMax; ++port)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    84
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    85
		iPort[port] = NULL;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    86
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    87
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    88
	CActiveScheduler::Add(this);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    89
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    90
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    91
C3GPDemuxer::~C3GPDemuxer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    92
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    93
	Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    94
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    95
	DeleteBufferQueue();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    96
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    97
	if (i3GPParser)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    98
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
    99
		HandleIfError(i3GPParser->Complete());
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   100
		delete i3GPParser;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   101
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   102
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   103
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   104
OMX_ERRORTYPE C3GPDemuxer::AcquireResources(const TDesC& aFilename)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   105
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   106
	DEBUG_PRINTF(_L8("C3GPDemuxer::AcquireResources"));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   107
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   108
	TInt error = i3GPParser->Open(aFilename);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   109
	if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   110
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   111
		iParserOpened = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   112
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   113
		if (iStartTimePosition != 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   114
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   115
			SetPosition(iStartTimePosition, iStartKeyFrame);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   116
			iSeekPosition = iStartTimePosition;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   117
			iStartTimePosition = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   118
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   119
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   120
		TRAP(error, CreateBufferQueueL());
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   121
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   122
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   123
	return SymbianOSErrorToOmx(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   124
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   125
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   126
void C3GPDemuxer::ReleaseResources()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   127
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   128
	DeleteBufferQueue();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   129
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   130
	if (i3GPParser)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   131
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   132
		HandleIfError(i3GPParser->Complete());
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   133
		iParserOpened = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   134
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   135
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   136
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   137
void C3GPDemuxer::Start()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   138
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   139
	if (iPaused && iState != EStateWaitingToStart)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   140
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   141
		if (iState != EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   142
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   143
			Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   144
			
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   145
			// Self complete so that we start to process any buffer received while
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   146
			// we were in paused state
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   147
			CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   148
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   149
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   150
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   151
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   152
		Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   153
		iState = EStateWaitingForBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   154
		// Self complete so that we start to process any buffer received while
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   155
		// we were in idle state
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   156
		CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   157
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   158
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   159
	iPaused = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   160
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   161
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   162
OMX_ERRORTYPE C3GPDemuxer::Stop()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   163
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   164
	Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   165
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   166
	if (iState == EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   167
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   168
	 	i3GPParser->CancelReadFrame();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   169
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   170
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   171
	iState = EStateWaitingToStart;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   172
	StartWaitingForBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   173
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   174
	iAudioHeadersSent = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   175
	iFirstAudioFrame = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   176
	iVideoHeadersSent = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   177
	iFirstVideoFrame = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   178
	iPaused = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   179
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   180
	TInt error = SetPosition(0, EFalse);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   181
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   182
	return SymbianOSErrorToOmx(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   183
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   184
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   185
void C3GPDemuxer::Pause()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   186
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   187
	iPaused = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   188
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   189
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   190
TBool C3GPDemuxer::Invalid() const
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   191
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   192
	return iInvalid;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   193
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   194
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   195
void C3GPDemuxer::ProcessThisBufferL(OMX_BUFFERHEADERTYPE* aBufferHeader,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   196
		TUint32 aPortIndex)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   197
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   198
	__ASSERT_DEBUG(iBufferQueueCreated, Panic(EProcessThisBufferLNoBufferQueue));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   199
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   200
	aBufferHeader->nFilledLen = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   201
	aBufferHeader->nOffset = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   202
	aBufferHeader->nTimeStamp = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   203
	aBufferHeader->nFlags = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   204
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   205
	if (iBufferQueueCreated)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   206
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   207
		TBufferMessage buffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   208
		buffer.iBufferHeader = aBufferHeader;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   209
		buffer.iPortIndex = aPortIndex;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   210
		User::LeaveIfError(iBufferQueue.Send(buffer));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   211
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   212
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   213
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   214
		User::Leave(KErrNotReady);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   215
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   216
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   217
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   218
void C3GPDemuxer::FlushBuffers(TUint32 aPortIndex)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   219
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   220
	__ASSERT_DEBUG(aPortIndex == OMX_ALL || aPortIndex < COmxIL3GPDemuxer::EPortIndexMax, User::Invariant());
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   221
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   222
	if (aPortIndex == OMX_ALL || aPortIndex < COmxIL3GPDemuxer::EPortIndexMax)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   223
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   224
		Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   225
		ReceiveQueuedBuffers();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   226
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   227
		if (aPortIndex == OMX_ALL || iCurrentPort == aPortIndex)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   228
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   229
			if (iState == EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   230
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   231
				// We are about to flush a buffer that is being filled.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   232
			 	// Cancel the read operation.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   233
			 	i3GPParser->CancelReadFrame();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   234
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   235
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   236
		 	iState = EStateWaitingForBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   237
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   238
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   239
		if (aPortIndex == OMX_ALL)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   240
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   241
			for (TInt portIndex = 0; portIndex < COmxIL3GPDemuxer::EPortIndexMax; ++portIndex)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   242
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   243
				DoFlushBuffers(portIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   244
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   245
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   246
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   247
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   248
			DoFlushBuffers(aPortIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   249
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   250
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   251
		// Unless we are waiting for a read to complete, we need to self
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   252
		// complete just in case the ReceiveQueuedBuffers() call above
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   253
		// received new buffers
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   254
		if (iState != EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   255
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   256
			CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   257
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   258
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   259
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   260
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   261
void C3GPDemuxer::DoFlushBuffers(TUint32 aPortIndex)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   262
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   263
	if (iPort[aPortIndex])
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   264
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   265
		OMX_DIRTYPE direction = OMX_DirOutput;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   266
		if (aPortIndex == COmxIL3GPDemuxer::EPortIndexTimeInput)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   267
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   268
			direction = OMX_DirInput;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   269
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   270
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   271
		RQueuedBuffers& buffers = iPort[aPortIndex]->iBuffers;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   272
		while (buffers.Count() > 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   273
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   274
			iCallbacks.BufferDoneNotification(buffers[0], aPortIndex, direction);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   275
			buffers.Remove(0);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   276
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   277
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   278
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   279
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   280
TBool C3GPDemuxer::RemoveBuffer(OMX_BUFFERHEADERTYPE* aBufferHeader,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   281
                                OMX_DIRTYPE aDirection)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   282
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   283
	TInt port = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   284
	if (aDirection == OMX_DirOutput)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   285
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   286
		port = aBufferHeader->nOutputPortIndex;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   287
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   288
	else if (aDirection == OMX_DirInput)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   289
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   290
		port = aBufferHeader->nInputPortIndex;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   291
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   292
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   293
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   294
		Panic(ERemoveBufferInvalidDirection);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   295
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   296
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   297
	__ASSERT_DEBUG(port >= 0 && port < COmxIL3GPDemuxer::EPortIndexMax, Panic(ERemoveBufferInvalidPort));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   298
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   299
	TBool found = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   300
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   301
	if (port >= 0 && port < COmxIL3GPDemuxer::EPortIndexMax)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   302
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   303
		Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   304
		ReceiveQueuedBuffers();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   305
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   306
		if (iPort[port])
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   307
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   308
			RQueuedBuffers& buffers = iPort[port]->iBuffers;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   309
			for (TInt buf = 0; buf < buffers.Count(); ++buf)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   310
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   311
				if (buffers[buf] == aBufferHeader)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   312
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   313
					if (iCurrentPort == port && buf == 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   314
						{				
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   315
						if (iState == EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   316
							{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   317
							// We are about to remove a buffer that is being filled.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   318
			 				// Cancel the read operation.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   319
			 				i3GPParser->CancelReadFrame();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   320
							}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   321
		 				iState = EStateWaitingForBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   322
						}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   323
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   324
					buffers[buf]->nFilledLen = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   325
					buffers.Remove(buf);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   326
					found = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   327
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   328
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   329
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   330
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   331
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   332
		// Unless we are waiting for a read to complete, we need to self
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   333
		// complete just in case the ReceiveQueuedBuffers() call above
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   334
		// received new buffers
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   335
		if (iState != EStateFillingBuffer)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   336
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   337
			CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   338
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   339
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   340
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   341
	return found;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   342
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   343
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   344
TBool C3GPDemuxer::GetVideoFormat(TSize& aFrameSize, TVideoFormat& aFormat) const
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   345
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   346
	if (!iVideoPropertiesRead)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   347
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   348
		return EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   349
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   350
	aFrameSize.iWidth = iVideoWidth;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   351
	aFrameSize.iHeight = iVideoHeight;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   352
	aFormat = iOmxVideoFormat;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   353
	return ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   354
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   355
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   356
TBool C3GPDemuxer::GetAudioFormat(TAudioFormat& aFormat) const
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   357
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   358
	if (!iAudioPropertiesRead)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   359
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   360
		return EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   361
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   362
	aFormat = iOmxAudioFormat;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   363
	return ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   364
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   365
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   366
OMX_ERRORTYPE C3GPDemuxer::GetVideoTimestamp(OMX_TICKS& aOmxticks)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   367
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   368
	TInt err = KErrNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   369
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   370
	TUint timestampInMilliSec(0);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   371
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   372
	if (iParserOpened)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   373
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   374
		// return last requested seek time
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   375
		timestampInMilliSec = iSeekPosition;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   376
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   377
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   378
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   379
		timestampInMilliSec = iStartTimePosition;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   380
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   381
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   382
	if (err == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   383
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   384
		aOmxticks = timestampInMilliSec * 1000;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   385
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   386
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   387
	return SymbianOSErrorToOmx(err);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   388
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   389
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   390
OMX_ERRORTYPE C3GPDemuxer::Seek(const OMX_TICKS& aOmxticks, OMX_TIME_SEEKMODETYPE aSeekModeType)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   391
    {
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   392
	TInt err = KErrNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   393
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   394
	//Set the firstFrame flags to true
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   395
	iFirstVideoFrame = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   396
	iFirstAudioFrame = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   397
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   398
	TUint timeInMilliSec = aOmxticks / 1000;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   399
	TBool keyFrame(aSeekModeType == OMX_TIME_SeekModeFast);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   400
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   401
	if (iParserOpened)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   402
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   403
		err = SetPosition(timeInMilliSec, keyFrame);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   404
		if (err != KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   405
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   406
			iSeekPosition = timeInMilliSec;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   407
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   408
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   409
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   410
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   411
		iStartTimePosition = timeInMilliSec;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   412
		iStartKeyFrame = keyFrame;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   413
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   414
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   415
	return SymbianOSErrorToOmx(err);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   416
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   417
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   418
OMX_ERRORTYPE C3GPDemuxer::DetectStreams()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   419
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   420
	iAudioPropertiesRead = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   421
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   422
	TUint s_audioLength;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   423
	TInt s_audioFramesPerSample;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   424
	TUint s_audioAvgBitRate;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   425
	TUint s_audioTimeScale;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   426
	TInt error = i3GPParser->GetAudioProperties(iAudioType, s_audioLength,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   427
			s_audioFramesPerSample, s_audioAvgBitRate, s_audioTimeScale);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   428
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   429
	if (error != KErrNotSupported)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   430
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   431
		if (error)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   432
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   433
			return SymbianOSErrorToOmx(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   434
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   435
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   436
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   437
			iOmxAudioFormat.iFramesPerSample = s_audioFramesPerSample;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   438
			iOmxAudioFormat.iSampleRate = s_audioTimeScale;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   439
			iOmxAudioFormat.iAverageBitrate = s_audioAvgBitRate;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   440
			switch (iAudioType)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   441
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   442
				case E3GPQcelp13K:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   443
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   444
					iOmxAudioFormat.iCoding = OMX_AUDIO_CodingQCELP13;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   445
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   446
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   447
				case E3GPMpeg4Audio:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   448
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   449
					iOmxAudioFormat.iCoding = OMX_AUDIO_CodingAAC;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   450
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   451
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   452
				case E3GPAmrNB:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   453
				case E3GPAmrWB:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   454
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   455
					iOmxAudioFormat.iCoding = OMX_AUDIO_CodingAMR;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   456
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   457
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   458
				default:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   459
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   460
					iOmxAudioFormat.iCoding = OMX_AUDIO_CodingMax;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   461
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   462
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   463
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   464
			iAudioPropertiesRead = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   465
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   466
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   467
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   468
	iVideoPropertiesRead = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   469
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   470
	TSize vidSize(iVideoWidth, iVideoHeight);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   471
	TUint s_vidLength = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   472
	TReal s_vidFrameRate = 0.0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   473
	TUint s_vidAvgBitRate = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   474
	TSize s_vidSize;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   475
	TUint s_vidTimeScale = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   476
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   477
	error = i3GPParser->GetVideoProperties(iVideoType, s_vidLength,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   478
			s_vidFrameRate, s_vidAvgBitRate, s_vidSize, s_vidTimeScale);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   479
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   480
	if (error != KErrNotSupported)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   481
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   482
		if (error)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   483
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   484
			return SymbianOSErrorToOmx(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   485
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   486
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   487
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   488
			iVideoWidth = s_vidSize.iWidth;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   489
			iVideoHeight = s_vidSize.iHeight;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   490
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   491
			// translate library video type to OpenMAX IL coding and profile type
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   492
			switch (iVideoType)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   493
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   494
				case E3GPMpeg4Video:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   495
					iOmxVideoFormat.iCoding = OMX_VIDEO_CodingMPEG4;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   496
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   497
				case E3GPH263Profile0:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   498
					iOmxVideoFormat.iCoding = OMX_VIDEO_CodingH263;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   499
					iOmxVideoFormat.iProfile.h263
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   500
							= OMX_VIDEO_H263ProfileBaseline;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   501
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   502
				case E3GPH263Profile3:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   503
					iOmxVideoFormat.iCoding = OMX_VIDEO_CodingH263;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   504
					iOmxVideoFormat.iProfile.h263 = OMX_VIDEO_H263ProfileISWV2;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   505
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   506
				case E3GPAvcProfileBaseline:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   507
					iOmxVideoFormat.iCoding = OMX_VIDEO_CodingAVC;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   508
					iOmxVideoFormat.iProfile.avc = OMX_VIDEO_AVCProfileBaseline;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   509
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   510
				default:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   511
					// do not return an error here, the error is signalled after the transition to Executing
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   512
					iOmxVideoFormat.iCoding = OMX_VIDEO_CodingMax;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   513
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   514
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   515
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   516
			iVideoPropertiesRead = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   517
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   518
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   519
	return OMX_ErrorNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   520
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   521
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   522
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   523
OMX_ERRORTYPE C3GPDemuxer::GetMetadataL(OMX_CONFIG_METADATAITEMTYPE* aMetadata)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   524
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   525
	// Metadata key size must be at least 4
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   526
	if (aMetadata->nKeySizeUsed < 4)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   527
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   528
		return OMX_ErrorBadParameter;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   529
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   530
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   531
	T3GPUdtaLocation udtaLocation;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   532
	TUint32 udtaAtomType = Pack32(aMetadata->nKey);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   533
	TUint32 buffersize = aMetadata->nValueMaxSize;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   534
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   535
	RBuf8 buffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   536
	CleanupClosePushL(buffer);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   537
	User::LeaveIfError(buffer.Create(buffersize));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   538
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   539
	TUint atomIndex = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   540
	if (aMetadata->nMetadataItemIndex != OMX_ALL)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   541
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   542
		atomIndex = aMetadata->nMetadataItemIndex;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   543
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   544
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   545
	TInt error = KErrNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   546
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   547
	switch (aMetadata->eScopeMode)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   548
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   549
		case OMX_MetadataScopeAllLevels:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   550
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   551
			TUint subatomCount = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   552
			udtaLocation = E3GPUdtaMoov;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   553
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   554
			error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation,	buffer, subatomCount);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   555
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   556
			if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   557
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   558
				if (atomIndex == 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   559
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   560
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   561
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   562
				else if (atomIndex <= subatomCount)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   563
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   564
					error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation, buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   565
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   566
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   567
				else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   568
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   569
					atomIndex -= (subatomCount + 1);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   570
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   571
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   572
			else if (error != KErrNotFound)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   573
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   574
				break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   575
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   576
			
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   577
			subatomCount = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   578
			udtaLocation = E3GPUdtaVideoTrak;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   579
			error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   580
					buffer, subatomCount);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   581
			if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   582
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   583
				if (atomIndex == 0)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   584
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   585
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   586
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   587
				else if (atomIndex <= subatomCount)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   588
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   589
					error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation, buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   590
					break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   591
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   592
				else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   593
					{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   594
					atomIndex -= (subatomCount + 1);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   595
					}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   596
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   597
			else if (error != KErrNotFound)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   598
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   599
				break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   600
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   601
			
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   602
			udtaLocation = E3GPUdtaAudioTrak;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   603
			error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   604
					buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   605
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   606
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   607
		case OMX_MetadataScopeTopLevel:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   608
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   609
			udtaLocation = E3GPUdtaMoov;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   610
			error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   611
					buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   612
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   613
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   614
		case OMX_MetadataScopePortLevel:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   615
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   616
			if (aMetadata->nScopeSpecifier
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   617
					== COmxIL3GPDemuxer::EPortIndexVideoOutput)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   618
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   619
				udtaLocation = E3GPUdtaVideoTrak;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   620
				error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   621
						buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   622
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   623
			else if (aMetadata->nScopeSpecifier == COmxIL3GPDemuxer::EPortIndexAudioOutput)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   624
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   625
				udtaLocation = E3GPUdtaAudioTrak;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   626
				error = i3GPParser->GetUserDataAtom(udtaAtomType, udtaLocation, buffer, atomIndex);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   627
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   628
			else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   629
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   630
				error = KErrArgument;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   631
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   632
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   633
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   634
		default:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   635
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   636
			error = KErrArgument;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   637
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   638
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   639
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   640
	if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   641
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   642
		// strip size and atom type from the buffer
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   643
		Mem::Copy(aMetadata->nValue, (buffer.Ptr() + 8), (buffer.Size() - 8));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   644
		aMetadata->nValueSizeUsed = (buffer.Size() - 8);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   645
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   646
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   647
	CleanupStack::PopAndDestroy();//buffer
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   648
	return SymbianOSErrorToOmx(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   649
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   650
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   651
void C3GPDemuxer::RunL()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   652
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   653
	iWaitingOnBufferQueue = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   654
	ReceiveQueuedBuffers();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   655
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   656
	if (iPaused || iInvalid || iState == EStateWaitingToStart)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   657
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   658
		StartWaitingForBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   659
		return;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   660
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   661
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   662
	if (iState == EStateWaitingToSubmit)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   663
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   664
		SubmitBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   665
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   666
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   667
	if (!ProcessBuffers())
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   668
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   669
		iState = EStateWaitingForBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   670
		StartWaitingForBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   671
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   672
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   673
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   674
void C3GPDemuxer::DoCancel()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   675
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   676
	if (iWaitingOnBufferQueue)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   677
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   678
		iWaitingOnBufferQueue = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   679
		iBufferQueue.CancelDataAvailable();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   680
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   681
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   682
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   683
TBool C3GPDemuxer::ProcessBuffers()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   684
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   685
	TUint32 startPort = iCurrentPort;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   686
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   687
	do
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   688
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   689
		if (iPort[iCurrentPort]->iBuffers.Count() > 0 && !iPort[iCurrentPort]->iEOS)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   690
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   691
			DoProcessBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   692
			return ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   693
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   694
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   695
	while (NextPort() != startPort);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   696
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   697
	return EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   698
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   699
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   700
void C3GPDemuxer::DoProcessBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   701
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   702
	iState = EStateFillingBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   703
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   704
	iCurrentBuffer = iPort[iCurrentPort]->iBuffers[0];
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   705
	iPort[iCurrentPort]->iBuffers.Remove(0);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   706
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   707
	switch(iCurrentPort)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   708
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   709
		case COmxIL3GPDemuxer::EPortIndexTimeInput:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   710
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   711
			ProcessTimeBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   712
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   713
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   714
		case COmxIL3GPDemuxer::EPortIndexAudioOutput:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   715
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   716
			FillAudioBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   717
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   718
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   719
		case COmxIL3GPDemuxer::EPortIndexVideoOutput:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   720
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   721
			FillVideoBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   722
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   723
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   724
		}				
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   725
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   726
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   727
void C3GPDemuxer::ProcessTimeBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   728
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   729
	// TODO
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   730
	User::Invariant();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   731
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   732
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   733
void C3GPDemuxer::FillAudioBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   734
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   735
	if (!iAudioHeadersSent)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   736
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   737
		TPtr8 audioBuffer(iCurrentBuffer->pBuffer + iCurrentBuffer->nOffset + iCurrentBuffer->nFilledLen,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   738
				0,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   739
				static_cast<TInt>(iCurrentBuffer->nAllocLen - iCurrentBuffer->nOffset - iCurrentBuffer->nFilledLen));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   740
		TInt error = i3GPParser->GetAudioDecoderSpecificInfo(audioBuffer);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   741
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   742
		if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   743
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   744
			iCurrentBuffer->nFilledLen = audioBuffer.Length();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   745
			iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   746
			iAudioHeadersSent = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   747
			SubmitBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   748
			CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   749
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   750
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   751
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   752
			HandleIfError(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   753
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   754
		return;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   755
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   756
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   757
	iAsyncBuf.Set(iCurrentBuffer->pBuffer + iCurrentBuffer->nOffset + iCurrentBuffer->nFilledLen
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   758
	              ,0
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   759
	              ,static_cast<TInt>(iCurrentBuffer->nAllocLen - iCurrentBuffer->nOffset - iCurrentBuffer->nFilledLen));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   760
	i3GPParser->ReadAudioFrames(*this, iAsyncBuf);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   761
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   762
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   763
void C3GPDemuxer::FillVideoBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   764
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   765
	if (!iVideoHeadersSent)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   766
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   767
		iCurrentBuffer->nOffset = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   768
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   769
		TPtr8 videoBuffer(iCurrentBuffer->pBuffer + iCurrentBuffer->nOffset + iCurrentBuffer->nFilledLen,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   770
				0,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   771
				static_cast<TInt>(iCurrentBuffer->nAllocLen - iCurrentBuffer->nOffset - iCurrentBuffer->nFilledLen));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   772
		TInt error = i3GPParser->GetVideoDecoderSpecificInfo(videoBuffer);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   773
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   774
		if (error == KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   775
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   776
			iCurrentBuffer->nFilledLen = videoBuffer.Length();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   777
			iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   778
			iVideoHeadersSent = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   779
			SubmitBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   780
			CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   781
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   782
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   783
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   784
			HandleIfError(error);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   785
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   786
		return;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   787
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   788
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   789
	iAsyncBuf.Set(&iCurrentBuffer->pBuffer[0]
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   790
	              ,static_cast<TInt>((iCurrentBuffer->nFilledLen + iCurrentBuffer->nOffset))
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   791
	              ,static_cast<TInt>(iCurrentBuffer->nAllocLen));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   792
	i3GPParser->ReadVideoFrame(*this, iAsyncBuf);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   793
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   794
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   795
void C3GPDemuxer::AudioFramesAvailable(TInt aError, TUint /*aReturnedFrames*/,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   796
		TUint aTimeStampInMs, TUint /*aTimeStampInTimescale*/)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   797
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   798
	HandleIfError(aError);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   799
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   800
	if (!iInvalid)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   801
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   802
		// Check if this is the last frame. It is the last frame if
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   803
		// GetAudioFramesSize returns KErrNotFound
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   804
		TUint frameSize = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   805
		TInt nextFrameError = i3GPParser->GetAudioFramesSize(frameSize);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   806
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   807
		FileReadComplete(nextFrameError, aTimeStampInMs, iFirstAudioFrame, EFalse);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   808
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   809
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   810
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   811
void C3GPDemuxer::VideoFrameAvailable(TInt aError, TBool aKeyFrame, TUint
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   812
aTimeStampInMs, TUint /*aTimeStampInTimescale*/)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   813
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   814
	HandleIfError(aError);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   815
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   816
	if (!iInvalid)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   817
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   818
		// Check if this is the last frame. It is the last frame if
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   819
		// GetVideoFramesSize returns KErrNotFound
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   820
		TUint frameSize = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   821
		TInt nextFrameError = i3GPParser->GetVideoFrameSize(frameSize);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   822
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   823
		FileReadComplete(nextFrameError, aTimeStampInMs, iFirstVideoFrame, aKeyFrame);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   824
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   825
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   826
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   827
void C3GPDemuxer::FileReadComplete(TInt aNextFrameError, TUint32 aTimeStamp, TBool& aFirstFrame, TBool aKeyFrame)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   828
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   829
	// aNextFrameError is the error code returned when checking the size of the
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   830
	// next audio or video frame. If the error code is KErrNotFound, this
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   831
	// shows that no more frames exist in that stream so the end of stream flag
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   832
	// should be set when sending out the buffer.
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   833
	if (aNextFrameError == KErrNotFound)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   834
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   835
		iPort[iCurrentPort]->iEOS = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   836
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   837
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   838
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   839
		HandleIfError(aNextFrameError);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   840
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   841
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   842
	if (!iInvalid)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   843
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   844
		iCurrentBuffer->nFilledLen += iAsyncBuf.Length();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   845
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   846
		// Set presentation time 	
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   847
		iCurrentBuffer->nTimeStamp = aTimeStamp * 1000;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   848
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   849
		if (aFirstFrame)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   850
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   851
			iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_STARTTIME;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   852
			aFirstFrame = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   853
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   854
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   855
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   856
			iCurrentBuffer->nFlags &= ~OMX_BUFFERFLAG_STARTTIME;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   857
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   858
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   859
		if (aKeyFrame)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   860
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   861
			iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   862
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   863
		else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   864
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   865
			iCurrentBuffer->nFlags &= ~OMX_BUFFERFLAG_SYNCFRAME;			
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   866
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   867
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   868
		// Demuxer just puts one whole frame into a buffer so we
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   869
		// can set the end of frame flag
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   870
		iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   871
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   872
		SubmitBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   873
		CompleteSelf();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   874
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   875
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   876
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   877
void C3GPDemuxer::SubmitBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   878
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   879
	if (!iPaused)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   880
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   881
		if (iPort[iCurrentPort]->iEOS)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   882
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   883
			iCurrentBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   884
			iCallbacks.EventNotification(OMX_EventBufferFlag, iCurrentPort,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   885
					iCurrentBuffer->nFlags, NULL);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   886
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   887
		#if 0
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   888
		else if (iCurrentBuffer->nFlags & OMX_BUFFERFLAG_STARTTIME)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   889
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   890
			iCallbacks.EventNotification(OMX_EventBufferFlag, iCurrentPort,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   891
				iCurrentBuffer->nFlags, NULL);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   892
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   893
		#endif
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   894
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   895
		iCallbacks.BufferDoneNotification(iCurrentBuffer, iCurrentPort,
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   896
				OMX_DirOutput);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   897
	
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   898
		iState = EStateWaitingForBuffer;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   899
		NextPort();	
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   900
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   901
	else
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   902
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   903
		iState = EStateWaitingToSubmit;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   904
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   905
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   906
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   907
void C3GPDemuxer::CreateBufferQueueL()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   908
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   909
	DEBUG_PRINTF(_L8("C3GPDemuxer::CreateBufferQueueL++"));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   910
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   911
	iPort[COmxIL3GPDemuxer::EPortIndexTimeInput] = CPort::NewL(KMaxTimeBuffers);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   912
	iPort[COmxIL3GPDemuxer::EPortIndexAudioOutput] = CPort::NewL(KMaxAudioBuffers);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   913
	iPort[COmxIL3GPDemuxer::EPortIndexVideoOutput] = CPort::NewL(KMaxVideoBuffers);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   914
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   915
	User::LeaveIfError(iBufferQueue.CreateLocal(KMaxTimeBuffers + KMaxAudioBuffers + KMaxVideoBuffers));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   916
	iBufferQueueCreated = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   917
	iState = EStateWaitingToStart;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   918
	StartWaitingForBuffer();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   919
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   920
	DEBUG_PRINTF(_L8("C3GPDemuxer::CreateBufferQueueL--"));
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   921
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   922
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   923
void C3GPDemuxer::DeleteBufferQueue()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   924
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   925
	if (iBufferQueueCreated)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   926
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   927
		Cancel();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   928
		iBufferQueueCreated = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   929
		iBufferQueue.Close();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   930
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   931
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   932
	for (TInt port = 0; port < COmxIL3GPDemuxer::EPortIndexMax; ++port)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   933
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   934
		delete iPort[port];
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   935
		iPort[port] = NULL;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   936
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   937
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   938
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   939
void C3GPDemuxer::HandleIfError(TInt aError)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   940
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   941
	OMX_ERRORTYPE omxError = SymbianOSErrorToOmx(aError);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   942
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   943
	if (omxError != OMX_ErrorNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   944
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   945
		iInvalid = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   946
		iCallbacks.ErrorEventNotification(omxError);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   947
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   948
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   949
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   950
// Helper function to convert Symbian OS standard error code to c style error code 
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   951
OMX_ERRORTYPE C3GPDemuxer::SymbianOSErrorToOmx(TInt aError) const
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   952
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   953
	OMX_ERRORTYPE error = OMX_ErrorUndefined;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   954
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   955
	switch (aError)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   956
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   957
		case (KErrNone):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   958
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   959
			error = OMX_ErrorNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   960
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   961
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   962
		case (KErrNoMemory):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   963
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   964
			error = OMX_ErrorInsufficientResources;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   965
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   966
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   967
		case (KErrOverflow):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   968
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   969
			error = OMX_ErrorOverflow;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   970
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   971
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   972
		case (KErrAccessDenied):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   973
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   974
			error = OMX_ErrorContentPipeOpenFailed;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   975
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   976
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   977
		case (KErrCorrupt):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   978
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   979
			error = OMX_ErrorStreamCorrupt;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   980
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   981
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   982
		case (KErrArgument):
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   983
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   984
			error = OMX_ErrorUnsupportedSetting;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   985
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   986
			break;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   987
		default:
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   988
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   989
			error = OMX_ErrorUndefined;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   990
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   991
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   992
	return error;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   993
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   994
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   995
void C3GPDemuxer::ReceiveQueuedBuffers()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   996
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   997
	if (iBufferQueueCreated)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   998
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
   999
		TBufferMessage message;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1000
		while(iBufferQueue.Receive(message) != KErrUnderflow)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1001
			{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1002
			// Port buffers are pre-reserved so append should always work
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1003
			if (iPort[message.iPortIndex]->iBuffers.Append(message.iBufferHeader) != KErrNone)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1004
				{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1005
				Panic(EReceiveQueuedBuffersAppendFailed);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1006
				}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1007
			}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1008
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1009
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1010
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1011
void C3GPDemuxer::StartWaitingForBuffer()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1012
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1013
	if (iBufferQueueCreated)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1014
		{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1015
		iWaitingOnBufferQueue = ETrue;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1016
		iBufferQueue.NotifyDataAvailable(iStatus);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1017
		SetActive();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1018
		}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1019
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1020
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1021
void C3GPDemuxer::CompleteSelf()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1022
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1023
	iStatus = KRequestPending;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1024
	SetActive();
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1025
	TRequestStatus* status = &iStatus;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1026
	User::RequestComplete(status, KErrNone);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1027
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1028
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1029
TInt C3GPDemuxer::NextPort()
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1030
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1031
	++iCurrentPort;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1032
	iCurrentPort %= COmxIL3GPDemuxer::EPortIndexMax;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1033
	return iCurrentPort;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1034
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1035
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1036
/** Packs four bytes into a 32bit number */
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1037
TUint32 C3GPDemuxer::Pack32(const TUint8* aPtr)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1038
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1039
	TUint32 x = *aPtr++ << 24;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1040
	x |= *aPtr++ << 16;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1041
	x |= *aPtr++ << 8;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1042
	x |= *aPtr++;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1043
	return x;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1044
	}
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1045
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1046
TInt C3GPDemuxer::SetPosition(TUint aTimePosition, TBool aKeyFrame)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1047
	{
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1048
	TUint audioPosition = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1049
	TUint videoPosition = 0;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1050
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1051
	TInt err = i3GPParser->Seek(aTimePosition, aKeyFrame, audioPosition, videoPosition);
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1052
	if(err)
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1053
	    {
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1054
	    return err;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1055
	    }
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1056
	
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1057
	// clear EOS state so buffer handling resumes if previously hit EOS
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1058
	// TODO is this thread safe?
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1059
	iPort[0]->iEOS = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1060
	iPort[1]->iEOS = EFalse;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1061
	
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1062
	return KErrNone;
5d29cba61097 2010wk38_02
hgs
parents:
diff changeset
  1063
	}