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 <mmfclip.h>
00038 #include <implementationproxy.h>
00039 #include <mmfutilities.h>
00040 
00041 /* Audio decoder plug-in to read .RAW audio.
00042  It implements MDataSource to pass data to the controller, and MDataSink to read data from 
00043  the source clip.
00044  Also implements MAsyncEventHandler to send an event to the client */
00045 class CMMFRawFormatRead : public CMMFFormatDecode, public MAsyncEventHandler
00046         {
00047 public:
00048         // Factory function
00049         static CMMFFormatDecode* NewL(MDataSource* aSource);
00050         ~CMMFRawFormatRead();
00051 
00052         //from MDataSource
00053         void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId aMediaId);
00054         CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference); 
00055         CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
00056         TFourCC SourceDataTypeCode(TMediaId aMediaId);
00057         TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId); 
00058         TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
00059         void SourceThreadLogoff();
00060         void SourcePrimeL();
00061         void SourcePlayL();
00062         void SourcePauseL();
00063         void SourceStopL();
00064 
00065         //from MDataSink
00066         void BufferFilledL(CMMFBuffer* aBuffer);
00067 
00068         // from CMMFFormatDecode
00069         TUint Streams(TUid aMediaType) const;
00070         TTimeIntervalMicroSeconds FrameTimeInterval(TMediaId aMediaType) const;
00071         TTimeIntervalMicroSeconds Duration(TMediaId aMediaType) const;
00072         TUint NumChannels() {return iChannels;};
00073         TUint SampleRate() {return iSampleRate;};
00074         TUint BitRate() {return iSampleRate * iBitsPerSample;};
00075         TInt SetNumChannels(TUint aChannels);
00076         TInt SetSampleRate(TUint aSampleRate);
00077         void GetSupportedSampleRatesL(RArray<TUint>& aSampleRates);
00078         void GetSupportedNumChannelsL(RArray<TUint>& aNumChannels);
00079         void GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes);
00080         void SuggestSourceBufferSize(TUint aSuggestedBufferSize);       
00081 
00082         //from MAsyncEventHandler
00083         TInt SendEventToClient(const TMMFEvent& /*aEvent*/) {return KErrNone;}
00084 
00085 private:
00086         // Construction
00087         void ConstructL(MDataSource* aSource);
00088         // Helper functions
00089         CMMFDataBuffer* CreateSourceBufferOfSizeL(TUint aSize);
00090         void DoReadL(TInt aReadPosition);
00091         void NegotiateSourceBufferL(CMMFBuffer& aBuffer);
00092         void CalculateFrameTimeInterval();
00093 
00094 protected:
00095         MDataSource* iClip; //for decode format MDatasource; for encode format MDataSink
00096         MDataSink* iDataPath; //for decode format MDataSink; for encode format MDataSource
00097         TFourCC iFourCC;        
00098 
00099 private:
00100         CMMFDataBuffer* iBuffer;
00101         TUint iStartPosition;
00102         TUint iPos;
00103         TUint iChannels;
00104         TUint iSampleRate;
00105         TUint iBitsPerSample;
00106         TTimeIntervalMicroSeconds iFrameTimeInterval;
00107         TUint iFrameSize;
00108         TUint iClipLength;
00109         };
00110 
00111 
00112 /* Audio encoder plug-in to write .RAW audio.
00113  It implements MDataSink to get data from the controller, and MDataSource to write data to 
00114  the target clip.
00115  Also implements MAsyncEventHandler to send an event to the client */
00116 class CMMFRawFormatWrite : public CMMFFormatEncode, public MAsyncEventHandler
00117         {
00118 public:
00119         // Factory function
00120         static CMMFFormatEncode* NewL(MDataSink* aSink);
00121         ~CMMFRawFormatWrite();
00122 
00123         //from MDataSink
00124         CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference); 
00125         TFourCC SinkDataTypeCode(TMediaId aMediaId); //returns FourCC code for the mediaId
00126         TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId); 
00127         TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
00128         void SinkThreadLogoff();
00129         void Negotiate(MDataSource& aSource);
00130         void SinkPrimeL();
00131         void SinkPlayL();
00132         void SinkPauseL();
00133         void SinkStopL();
00134         void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);
00135 
00136         //from MDataSource
00137         void BufferEmptiedL(CMMFBuffer* aBuffer);
00138 
00139         // from CMMFFormatEncode
00140         TTimeIntervalMicroSeconds FrameTimeInterval(TMediaId aMediaType) const;
00141         TTimeIntervalMicroSeconds Duration(TMediaId aMediaType) const;
00142         TInt SetNumChannels(TUint aChannels);
00143         TInt SetSampleRate(TUint aSampleRate);
00144         TUint NumChannels() {return iChannels;};
00145         TUint SampleRate() {return iSampleRate;};
00146         TUint BitRate() {return iSampleRate * iBitsPerSample;};
00147         TInt64 BytesPerSecond()  ;
00148         void GetSupportedSampleRatesL(RArray<TUint>& aSampleRates);
00149         void GetSupportedNumChannelsL(RArray<TUint>& aNumChannels);
00150         void GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes);
00151         void SetMaximumClipSize(TInt aBytes);
00152         void CropL(TTimeIntervalMicroSeconds aPosition, TBool aToEnd ) ;
00153 
00154         //from MAsyncEventHandler
00155         TInt SendEventToClient(const TMMFEvent& /*aEvent*/) {return KErrNone;}
00156 
00157 private:
00158         // construction
00159         void ConstructL(MDataSink* aSink);
00160         // helper functions
00161         CMMFDataBuffer* CreateSinkBufferOfSizeL(TUint aSize);
00162         void CalculateFrameTimeInterval();
00163         void DoReadL(TInt aReadPosition);
00164         void DoWriteL(TInt aWritePosition);
00165 
00166 private:
00167         MDataSink* iClip; //for decode format MDatasource; for encode format MDataSink
00168         MDataSource* iDataPath; //for decode format MDataSink; for encode format MDataSource
00169         TFourCC iFourCC;        
00170         CMMFDataBuffer* iBuffer;
00171         TBool iClipAlreadyExists;
00172         TBool iBufferCreated;
00173         TBool iFileHasChanged;
00174         TUint iStartPosition;
00175         TUint iDataLength;
00176         TUint iPos;
00177         TUint iMaxPos;
00178         TUint iChannels;
00179         TUint iSampleRate;
00180         TUint iSourceChannels;
00181         TUint iSourceSampleRate;
00182         TFourCC iSourceFourCC;
00183         TUint iBitsPerSample;
00184         TTimeIntervalMicroSeconds iFrameTimeInterval;
00185         TUint iFrameSize;
00186         TUint iClipLength;
00187         TUint iDataSize;
00188         CMMFChannelAndSampleRateConverterFactory* iChannelAndSampleRateConverterFactory;
00189         CMMFChannelAndSampleRateConverter* iChannelAndSampleRateConverter; 
00190         CMMFDataBuffer* iConvertBuffer;
00191         CMMFBuffer* iBufferToEmpty; //pointer to store buffr to empty - needed if buffer passed to clip is different
00192         TBool iSourceWillSampleConvert;
00193         TInt iMaximumClipSize;
00194         };
00195 
00196 #endif
00197 

Generated by  doxygen 1.6.2