examples/Multimedia/MmfExFormatPlugin/mmfrawformat.h

00001 /*
00002 Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #ifndef __MMF_RAW_FORMAT_H__
00032 #define __MMF_RAW_FORMAT_H__
00033 
00034 // MMF framework headers
00035 #include <mmfformat.h>
00036 #include <mmfdatabuffer.h>
00037 #include <mmfaudiooutput.h>
00038 #include <mmfclip.h>
00039 #include <implementationproxy.h>
00040 #include <mmfutilities.h>
00041 
00042 /* Audio decoder plug-in to read .RAW audio.
00043  It implements MDataSource to pass data to the controller, and MDataSink to read data from 
00044  the source clip.
00045  Also implements MAsyncEventHandler to send an event to the client */
00046 class CMMFRawFormatRead : public CMMFFormatDecode, public MAsyncEventHandler
00047         {
00048 public:
00049         // Factory function
00050         static CMMFFormatDecode* NewL(MDataSource* aSource);
00051         ~CMMFRawFormatRead();
00052 
00053         //from MDataSource
00054         void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId aMediaId);
00055         CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference); 
00056         CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
00057         TFourCC SourceDataTypeCode(TMediaId aMediaId);
00058         TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId); 
00059         TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
00060         void SourceThreadLogoff();
00061         void SourcePrimeL();
00062         void SourcePlayL();
00063         void SourcePauseL();
00064         void SourceStopL();
00065 
00066         //from MDataSink
00067         void BufferFilledL(CMMFBuffer* aBuffer);
00068 
00069         // from CMMFFormatDecode
00070         TUint Streams(TUid aMediaType) const;
00071         TTimeIntervalMicroSeconds FrameTimeInterval(TMediaId aMediaType) const;
00072         TTimeIntervalMicroSeconds Duration(TMediaId aMediaType) const;
00073         TUint NumChannels() {return iChannels;};
00074         TUint SampleRate() {return iSampleRate;};
00075         TUint BitRate() {return iSampleRate * iBitsPerSample;};
00076         TInt SetNumChannels(TUint aChannels);
00077         TInt SetSampleRate(TUint aSampleRate);
00078         void GetSupportedSampleRatesL(RArray<TUint>& aSampleRates);
00079         void GetSupportedNumChannelsL(RArray<TUint>& aNumChannels);
00080         void GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes);
00081         void SuggestSourceBufferSize(TUint aSuggestedBufferSize);       
00082 
00083         //from MAsyncEventHandler
00084         TInt SendEventToClient(const TMMFEvent& /*aEvent*/) {return KErrNone;}
00085 
00086 private:
00087         // Construction
00088         void ConstructL(MDataSource* aSource);
00089         // Helper functions
00090         CMMFDataBuffer* CreateSourceBufferOfSizeL(TUint aSize);
00091         void DoReadL(TInt aReadPosition);
00092         void NegotiateSourceBufferL(CMMFBuffer& aBuffer);
00093         void CalculateFrameTimeInterval();
00094 
00095 protected:
00096         MDataSource* iClip; //for decode format MDatasource; for encode format MDataSink
00097         MDataSink* iDataPath; //for decode format MDataSink; for encode format MDataSource
00098         TFourCC iFourCC;        
00099 
00100 private:
00101         CMMFDataBuffer* iBuffer;
00102         TUint iStartPosition;
00103         TUint iPos;
00104         TUint iChannels;
00105         TUint iSampleRate;
00106         TUint iBitsPerSample;
00107         TTimeIntervalMicroSeconds iFrameTimeInterval;
00108         TUint iFrameSize;
00109         TUint iClipLength;
00110         };
00111 
00112 
00113 /* Audio encoder plug-in to write .RAW audio.
00114  It implements MDataSink to get data from the controller, and MDataSource to write data to 
00115  the target clip.
00116  Also implements MAsyncEventHandler to send an event to the client */
00117 class CMMFRawFormatWrite : public CMMFFormatEncode, public MAsyncEventHandler
00118         {
00119 public:
00120         // Factory function
00121         static CMMFFormatEncode* NewL(MDataSink* aSink);
00122         ~CMMFRawFormatWrite();
00123 
00124         //from MDataSink
00125         CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference); 
00126         TFourCC SinkDataTypeCode(TMediaId aMediaId); //returns FourCC code for the mediaId
00127         TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId); 
00128         TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
00129         void SinkThreadLogoff();
00130         void Negotiate(MDataSource& aSource);
00131         void SinkPrimeL();
00132         void SinkPlayL();
00133         void SinkPauseL();
00134         void SinkStopL();
00135         void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);
00136 
00137         //from MDataSource
00138         void BufferEmptiedL(CMMFBuffer* aBuffer);
00139 
00140         // from CMMFFormatEncode
00141         TTimeIntervalMicroSeconds FrameTimeInterval(TMediaId aMediaType) const;
00142         TTimeIntervalMicroSeconds Duration(TMediaId aMediaType) const;
00143         TInt SetNumChannels(TUint aChannels);
00144         TInt SetSampleRate(TUint aSampleRate);
00145         TUint NumChannels() {return iChannels;};
00146         TUint SampleRate() {return iSampleRate;};
00147         TUint BitRate() {return iSampleRate * iBitsPerSample;};
00148         TInt64 BytesPerSecond()  ;
00149         void GetSupportedSampleRatesL(RArray<TUint>& aSampleRates);
00150         void GetSupportedNumChannelsL(RArray<TUint>& aNumChannels);
00151         void GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes);
00152         void SetMaximumClipSize(TInt aBytes);
00153         void CropL(TTimeIntervalMicroSeconds aPosition, TBool aToEnd ) ;
00154 
00155         //from MAsyncEventHandler
00156         TInt SendEventToClient(const TMMFEvent& /*aEvent*/) {return KErrNone;}
00157 
00158 private:
00159         // construction
00160         void ConstructL(MDataSink* aSink);
00161         // helper functions
00162         CMMFDataBuffer* CreateSinkBufferOfSizeL(TUint aSize);
00163         void CalculateFrameTimeInterval();
00164         void DoReadL(TInt aReadPosition);
00165         void DoWriteL(TInt aWritePosition);
00166 
00167 private:
00168         MDataSink* iClip; //for decode format MDatasource; for encode format MDataSink
00169         MDataSource* iDataPath; //for decode format MDataSink; for encode format MDataSource
00170         TFourCC iFourCC;        
00171         CMMFDataBuffer* iBuffer;
00172         TBool iClipAlreadyExists;
00173         TBool iBufferCreated;
00174         TBool iFileHasChanged;
00175         TUint iStartPosition;
00176         TUint iDataLength;
00177         TUint iPos;
00178         TUint iMaxPos;
00179         TUint iChannels;
00180         TUint iSampleRate;
00181         TUint iSourceChannels;
00182         TUint iSourceSampleRate;
00183         TFourCC iSourceFourCC;
00184         TUint iBitsPerSample;
00185         TTimeIntervalMicroSeconds iFrameTimeInterval;
00186         TUint iFrameSize;
00187         TUint iClipLength;
00188         TUint iDataSize;
00189         CMMFChannelAndSampleRateConverterFactory* iChannelAndSampleRateConverterFactory;
00190         CMMFChannelAndSampleRateConverter* iChannelAndSampleRateConverter; 
00191         CMMFDataBuffer* iConvertBuffer;
00192         CMMFBuffer* iBufferToEmpty; //pointer to store buffr to empty - needed if buffer passed to clip is different
00193         TBool iSourceWillSampleConvert;
00194         TInt iMaximumClipSize;
00195         };
00196 
00197 #endif
00198 

Generated by  doxygen 1.6.2