os/mm/mmplugins/mmfwplugins/src/Plugin/Controller/Video/AviPlayController/avireader.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef AVIREADER_H
    17 #define AVIREADER_H
    18 
    19 
    20 #include <mmf/server/mmffile.h>
    21 #include <e32std.h>
    22 #include <e32base.h>
    23 #include <mmf/devvideo/devvideoplay.h>
    24 
    25 
    26 //Observer class for CAviReader
    27 class MAviReaderObserver
    28 	{
    29 public:
    30 	virtual void AudioBufferFilled() = 0;
    31 	virtual void VideoBufferFilled(TVideoInputBuffer* aBuffer) = 0;
    32 	};
    33 
    34 
    35 //The main class to read from an.avi file.
    36 class CAviReader:public CBase,public MDataSink
    37 	{
    38 public:
    39 	static CAviReader* NewL(CMMFClip& aClip,MAviReaderObserver& aObserver);
    40 	virtual ~CAviReader();
    41 	TTimeIntervalMicroSeconds Duration() const ;
    42 	void SetPositionL(TInt aPosition);
    43 	void ResetL();
    44 	void SetPlayWindowL(TTimeIntervalMicroSeconds aStart,TTimeIntervalMicroSeconds aEnd);
    45 	void FillVideoBufferL(TVideoInputBuffer* aBuffer);
    46 	void FillAudioBufferL(CMMFBuffer* aBuffer);  	  	
    47   	void ReadNextFrameL(TUid aMediaType, TInt& aPosition);
    48   	TBool ReadNextFrameStartL(TInt& aStart);
    49   	TBool IsValidBlock(TUint aChunkId);
    50 	TBool IsVideoInputEnd();
    51 	TBool IsAudioInputEnd();
    52 	void ReadComplete();
    53   	void AudioEnabled(TBool& aEnabled);
    54 	void FrameRate(TReal32& aFramesPerSecond);
    55 	void AudioCodec(TFourCC& aCodec);
    56 	TInt SampleRate();
    57 	void VideoMimeType(TDes8& aMimeType);
    58 	void VideoFrameSize(TSize& aSize);
    59 	TInt Channels();
    60 	TInt BitsPerSample();
    61 	TBool IsAudioDataAvailableL(TInt aStartPos);
    62 			
    63     //MDataSink
    64 	TFourCC SinkDataTypeCode(TMediaId aMediaId);
    65 	void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);
    66 	void BufferFilledL(CMMFBuffer* aBuffer);
    67 	TBool CanCreateSinkBuffer();
    68 	CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool& aReference);
    69 	void ConstructSinkL( const TDesC8& aInitData);
    70 private:
    71 	
    72 	//Main Avi Header
    73 	struct TAviMainHeader	
    74 		{
    75 		TUint	iMicroSecPerFrame; 
    76 		TUint	iMaxBytesPerSec;
    77 		TUint   iPaddingGranularity;
    78 		TUint	iFlags;
    79 		TUint	iTotalFrames;
    80 		TUint	iInitialFrames;
    81 		TUint	iStreams;	
    82 		TUint	iSuggestedBufferSize;
    83 		TUint	iWidth;
    84 		TUint	iHeight;
    85 		TUint   iReserved[4];
    86 		} iMainHeader;
    87 	
    88 	struct TAviStreamHeader	//represents stream header
    89 		{
    90 		TUint	iFccType;
    91 		TUint	iFccHandler;
    92 		TUint	iFlags;	
    93 		TUint	iReserved;
    94 		TUint	iInitialFrames;
    95 		TUint	iScale;
    96 		TUint	iRate;		
    97 		TUint	iStart;
    98 		TUint	iLength;	
    99 		TUint	iSuggestedBufferSize;
   100 		TUint   iQuality;
   101 		TUint	iSampleSize;
   102 		struct
   103 			{
   104 			TInt16 iLeft;
   105 			TInt16 iTop;
   106 			TInt16 iRight;
   107 			TInt16 iBottom;
   108 			}iRcFrame;
   109 		};
   110 	TAviStreamHeader iStreamHeader[2];
   111 	
   112     struct TPcmWaveFormat
   113 		{
   114 		struct TWaveFormat
   115              { 
   116              TUint16  iFormatTag; 
   117              TUint16  iNChannels; 
   118              TUint  iNSamplesPerSec; 
   119              TUint  iNAvgBytesPerSec; 
   120              TUint16  iNBlockAlign;
   121              } iWaveFormat;
   122         TUint16 iBitsPerSample;
   123         } iPCMWaveFormat;
   124 
   125     //Video Stream Format
   126 
   127 
   128 	struct TBitmapInfoHeader
   129 		{
   130 		TUint  iBiSize;
   131         TUint   iBiWidth;
   132         TUint   iBiHeight;
   133         TUint16   iBiPlanes;
   134         TUint16   iBiBitCount;
   135 		TUint  iBiCompression;
   136 		TUint  iBiSizeImage;
   137 		TUint   iBiXPelsPerMeter;
   138 		TUint   iBiYPelsPerMeter;
   139 		TUint  iBiClrUsed;
   140 		TUint  iBiClrImportant;
   141 		}iBitmapInfoHeader;
   142 	
   143 private:
   144 	TInt ReadFormatL();
   145   	void ProcessFormatL();
   146  	TInt FindRiffChunksL();
   147  	CAviReader(CMMFClip& aClip, MAviReaderObserver& aObserver);
   148   	void ConstructL();
   149   	void DoReadL(TInt aReadPosition);
   150   	void SetMediaEOS(TUid aMediaType);
   151 private:
   152 	MAviReaderObserver& iObserver;
   153 	CMMFClip& iClip;
   154 	CMMFDescriptorBuffer* iSourceBuffer;
   155 	CMMFDescriptorBuffer* iAudioBuffer;
   156 	CMMFDescriptorBuffer* iVideoBuffer;
   157 	TInt iNumberOfStreams;
   158 	TBool iAudioEos;
   159 	TBool iVideoEos;	
   160 	TInt iSourcePos;
   161 	TInt iAudioPos;
   162 	TInt iVideoPos;
   163 	TUint8* iClipPos;
   164 	TBool iAudioEnabled;
   165 	TVideoInputBuffer* iBufferFromDevVideo;
   166 	CMMFBuffer* iBufferFromDevSound;
   167 	TBool iVideoRequestMade;
   168 	TBool iAudioRequestMade;
   169 	TBool iReadCompleted;
   170 	TBool iReadRequestMade;
   171 	TInt iFileSize;
   172 	TInt iAudioIdx;
   173 	TInt iVideoIdx;
   174 	};
   175 #endif