omxilvideocomps/omxil3gpdemuxer/src/c3gpdemuxer.h
changeset 0 5d29cba61097
equal deleted inserted replaced
-1:000000000000 0:5d29cba61097
       
     1 /*
       
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalComponent
       
    22 */
       
    23 
       
    24 #ifndef C3GPDEMUXER_H
       
    25 #define C3GPDEMUXER_H
       
    26 
       
    27 #include <f32file.h>
       
    28 #include <e32msgqueue.h>
       
    29 #include <c3gplibrary.h>
       
    30 
       
    31 #include "comxil3gpdemuxer.h"
       
    32 #include "tvideoformat.h"
       
    33 #include "taudioformat.h"
       
    34 
       
    35 class MOmxILCallbackNotificationIf;
       
    36 
       
    37 NONSHARABLE_CLASS(C3GPDemuxer) : public CActive
       
    38 								,public M3GPParseCallback
       
    39 
       
    40 	{
       
    41 public:	
       
    42 	static C3GPDemuxer* NewL(MOmxILCallbackNotificationIf& aCallbacks);
       
    43 	~C3GPDemuxer();
       
    44 
       
    45 	OMX_ERRORTYPE AcquireResources(const TDesC& aFilename);
       
    46 	void ReleaseResources();
       
    47 	void Start();
       
    48 	OMX_ERRORTYPE Stop();
       
    49 	void Pause();
       
    50 	TBool Invalid() const;
       
    51 
       
    52 	void ProcessThisBufferL(OMX_BUFFERHEADERTYPE* aBufferHeader, TUint32 aPortIndex);
       
    53 	void FlushBuffers(TUint32 aPortIndex);
       
    54 	TBool RemoveBuffer(OMX_BUFFERHEADERTYPE* aBufferHeader, OMX_DIRTYPE aDirection);
       
    55 
       
    56 	TBool GetVideoFormat(TSize& aFrameSize, TVideoFormat& aFormat) const;
       
    57 	TBool GetAudioFormat(TAudioFormat& aFormat) const;
       
    58 	OMX_ERRORTYPE GetVideoTimestamp(OMX_TICKS& aOmxTicks);
       
    59 	OMX_ERRORTYPE Seek(const OMX_TICKS& aOmxTicks, OMX_TIME_SEEKMODETYPE aSeekModeType);
       
    60 	OMX_ERRORTYPE DetectStreams();
       
    61 	OMX_ERRORTYPE GetMetadataL(OMX_CONFIG_METADATAITEMTYPE* aMetadata);
       
    62 
       
    63 protected:
       
    64 	void RunL();
       
    65 	void DoCancel();
       
    66 
       
    67 private:
       
    68 	typedef RPointerArray<OMX_BUFFERHEADERTYPE> RQueuedBuffers;
       
    69 
       
    70 	class CPort : public CBase
       
    71 		{
       
    72 	public:
       
    73 		static CPort* NewL(TInt aBufferCount);
       
    74 		~CPort();
       
    75 	
       
    76 	private:	
       
    77 		CPort();	
       
    78 		void ConstructL(TInt aBufferCount);
       
    79 
       
    80 	public:
       
    81 		// Queue of buffers waiting to be processed. Buffers are not owned.
       
    82 		RQueuedBuffers iBuffers;
       
    83 		TBool iEOS;
       
    84 		};
       
    85 		
       
    86 	class TBufferMessage
       
    87 		{
       
    88 	public:
       
    89 		OMX_BUFFERHEADERTYPE* iBufferHeader;
       
    90 		TUint32 iPortIndex;
       
    91 		};
       
    92 
       
    93 	enum TState
       
    94 		{
       
    95 		EStateWaitingToStart,
       
    96 		EStateWaitingForBuffer,
       
    97 		EStateFillingBuffer,
       
    98 		EStateWaitingToSubmit
       
    99 		};
       
   100 
       
   101 private:
       
   102 	C3GPDemuxer(MOmxILCallbackNotificationIf& aCallbacks);
       
   103 	void ConstructL();
       
   104 	void DoFlushBuffers(TUint32 aPortIndex);
       
   105 	TBool ProcessBuffers();
       
   106 	void DoProcessBuffer();
       
   107 	void ProcessTimeBuffer();
       
   108 	void FillAudioBuffer();
       
   109 	void FillVideoBuffer();
       
   110 	void FileReadComplete(TInt aNextFrameError, TUint32 aTimeStamp, TBool& aFirstFrame, TBool aKeyFrame);
       
   111 	void SubmitBuffer();
       
   112 	void CreateBufferQueueL();
       
   113 	void DeleteBufferQueue();
       
   114 	void HandleIfError(TInt aError);
       
   115 	OMX_ERRORTYPE SymbianOSErrorToOmx(TInt aError) const;
       
   116 	void ReceiveQueuedBuffers();
       
   117 	void StartWaitingForBuffer();
       
   118 	void CompleteSelf();
       
   119 	TInt NextPort();
       
   120 	TUint32 Pack32(const TUint8* aPtr);
       
   121 	TInt SetPosition(TUint aTimePosition, TBool aKeyFrame);
       
   122 
       
   123 	//M3GPParseCallback functions
       
   124 	void AudioFramesAvailable(TInt aError, TUint aReturnedFrames, TUint aTimeStampInMs, TUint aTimeStampInTimescale);
       
   125 	void VideoFrameAvailable(TInt aError, TBool aKeyFrame, TUint aTimeStampInMs, TUint aTimeStampInTimescale);
       
   126 	
       
   127 private:
       
   128 	MOmxILCallbackNotificationIf& iCallbacks;
       
   129 	TUint32 iCurrentPort;
       
   130 	OMX_BUFFERHEADERTYPE* iCurrentBuffer;  // Not owned
       
   131 	CPort* iPort[COmxIL3GPDemuxer::EPortIndexMax];
       
   132 	C3GPParse* i3GPParser;
       
   133 
       
   134 	TBool iVideoPropertiesRead;
       
   135 	T3GPVideoType iVideoType;
       
   136 	TVideoFormat iOmxVideoFormat;
       
   137 	TUint32 iVideoWidth;
       
   138 	TUint32 iVideoHeight;
       
   139 	
       
   140 	TBool iAudioPropertiesRead;
       
   141 	T3GPAudioType iAudioType;
       
   142 	TAudioFormat iOmxAudioFormat;
       
   143 
       
   144 	TBool iInvalid;
       
   145 	TBool iPaused;
       
   146 	TState iState;
       
   147 
       
   148 	TBool iVideoHeadersSent;
       
   149 	TBool iAudioHeadersSent;
       
   150 	TBool iFirstVideoFrame;
       
   151 	TBool iFirstAudioFrame;
       
   152 
       
   153 	RMsgQueue<TBufferMessage> iBufferQueue;
       
   154 	TBool iBufferQueueCreated;
       
   155 	TBool iWaitingOnBufferQueue;
       
   156 
       
   157 	TPtr8 iAsyncBuf;
       
   158 
       
   159 	TBool iParserOpened;
       
   160 	TUint iStartTimePosition;
       
   161 	TBool iStartKeyFrame;
       
   162 	TUint iSeekPosition; // The requested seek time in ms.
       
   163 	};
       
   164 
       
   165 #endif //C3GPDEMUXER_H