os/mm/mmplugins/mmfwplugins/src/Plugin/Controller/Audio/OggVorbis/OggPlayController/oggdecode.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 
    17 #ifndef OGGDECODE_H
    18 #define OGGDECODE_H
    19 
    20 #include <mmf/server/mmffile.h>
    21 #include <stdlib.h>
    22 #include "OggUtil.h"
    23 #include "VorbisInfo.h"
    24 
    25 static const TInt KNumHeaders = 3;// vorbis has 3 header packets
    26 //Average oggpage is of size 4K. we read 4K buffer during seeking and finding duration sothat we expect
    27 //the page header in it.
    28 static const TInt KReadBufferSize = 0x1000; // 4K
    29 
    30 /**
    31 @internalTechnology
    32 
    33 Interface to be implemented by clients of the class COggDecode. In specific, COggPlayController needs to implement
    34 this interface.MOggDecodeObserver provides interface for the classes that are interested in receiving BufferFilled event 
    35 from COggDecode.
    36 */
    37 class MOggDecodeObserver
    38 	{
    39 public:
    40 	/**
    41 	Function called by COggDecode to indicate that the buffer passed to it is filled.
    42 
    43 	This is a pure virtual function that each derived class must implement.
    44 	This method is used as the callback when the observer(controller in specific) requests COggDecode
    45 	to fill the buffer through FillThisBufferL() call. When the cnotroller gets this callback it knows 
    46 	that the buffer has been filled and can be sent to devsound.
    47 	*/
    48 	virtual void BufferFilled() = 0;
    49 	};
    50 
    51 /**
    52 @internalTechnology
    53 
    54 COggDecode class is mainly responsible for reading the encoded data from the clip and framing an oggpacket from it.
    55 Reads header to retrieve the current audio configuration from the clip. This is useful when the client queries 
    56 the current samplerate, bitrate etc.Also limited seeking is provided by this class.
    57 */
    58 class COggDecode : public CBase, 
    59 				   public MDataSink
    60 {
    61 public:
    62     static COggDecode* NewL(CMMFClip& aClip, MOggDecodeObserver& aObserver);
    63     virtual ~COggDecode();
    64     
    65     void InitializeVorbisL();
    66     void FillThisBufferL(CMMFBuffer* aBuffer);
    67 	void GetPacketSyncL();
    68     void ResetL();
    69     void ResetFile();
    70     TBool IsAllDataSent();
    71     CVorbisInfo* Info();
    72     void SetPlayWindowL(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd);
    73     void ClearPlayWindowL();
    74 	
    75 	//from MDataSink
    76 	TFourCC SinkDataTypeCode(TMediaId aMediaId);
    77 	void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);
    78 	void BufferFilledL(CMMFBuffer* aBuffer);
    79 	TBool CanCreateSinkBuffer();
    80 	CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool& aReference);
    81 	void ConstructSinkL( const TDesC8& aInitData);
    82 	
    83 	//Repositioning methods
    84 	TInt64 ReadHeader(CMMFPtrBuffer* aSourceBuffer, TInt& aPos);
    85 	TTimeIntervalMicroSeconds DurationL();
    86 	void SetPositionL(TTimeIntervalMicroSeconds aPosition);
    87 	TInt GetStreamPositionL(TInt aSamples, TInt64& aGranulePos);
    88 	TTimeIntervalMicroSeconds SeekingTime();
    89 	void SetPositionL(TInt64 aGranulePos);
    90 	void SetLastPageFlag(CMMFPtrBuffer* aSourceBuffer);
    91 private:
    92     COggDecode(CMMFClip& aClip, MOggDecodeObserver& aObserver);
    93     void ConstructL();
    94     
    95 private:
    96     MOggDecodeObserver& iObserver;
    97     CMMFClip* iClip;
    98     TBool iSeek;
    99     TInt iStoredSourcePos;
   100     TInt iSourcePos;
   101     //clip position corresponding to playwindowstart
   102     TInt iPlayWindowStart;
   103     //clip position corresponding to playwindowend
   104     TInt iPlayWindowEnd;
   105     //flag used to avoid calculating duration everytime DurationL() is called
   106     TBool iDurationCalculated;
   107     //we need to resend the codec initialization packets during seeking. 
   108     //This varible maintains number of header packets sent.
   109     TInt iInitSeek;
   110     TInt iHeaderSize;
   111     //Contains the current audio configuration read from the header of the clip
   112     CVorbisInfo* iInfo;
   113     //granulePos corresponding to the current file position
   114     TInt64 iCurrentGranulePos;
   115     //granulePos corresponding to the duration
   116     TInt64 iEndGranulePos;
   117     //set when playwindowend is reached. This flag is checked for stopping the play.
   118     TBool iPlayWindowEndReached;
   119     //set when all data sent to devsound. This flag is checked for proper playcompletion.
   120     TBool iAllDataSent;
   121     TTimeIntervalMicroSeconds iDuration;
   122     CMMFPtrBuffer* iSourceBuffer;
   123     CMMFDataBuffer* iBufferFromSink;
   124     COggPager* iPager;
   125     COggStream* iStream;
   126     TOggPacket iPacket;
   127     TOggPage iPage;
   128     /*data in an oggpacket is not always in one buffer may be spread over several using linked lists.
   129      so data_store is used to keep the extracted data while traversing the linkedlist.
   130      */
   131     unsigned char *iDataStore;
   132     TTimeIntervalMicroSeconds iPlayStartTime;
   133     TTimeIntervalMicroSeconds iPlayEndTime;
   134     TInt64 iPlayStartGranulePos;
   135     TInt64 iPlayEndGranulePos;
   136 #ifdef SYMBIAN_SEP_HEAP    
   137     RHeap* iDefaultHeap;
   138     RHeap* iVorbisHeap;
   139     RChunk iVorbisChunk;
   140 #endif
   141     };
   142 #endif // OGGDECODE_H