camcordermmfplugin/filecomposer/Inc/CamC3GPDataSinkImp.h
changeset 0 9b3e960ffc8a
child 16 130a995b5096
equal deleted inserted replaced
-1:000000000000 0:9b3e960ffc8a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  3GP data sink implementation class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CAMC3GPDATASINKIMP_H__
       
    20 #define __CAMC3GPDATASINKIMP_H__
       
    21 
       
    22 //  INCLUDES
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32std.h>
       
    26 #include <f32file.h>
       
    27 #include <3gplibrary/mp4lib.h>
       
    28 #include <mmf/common/mmffourcc.h>
       
    29 
       
    30 #include "CCMRMediaSink.h"
       
    31 #include "CamC3GPDataSink.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class CMMFFile;
       
    35 
       
    36 // CLASS DECLARATION
       
    37 
       
    38 /**
       
    39 *  CCamC3GPDataSinkImp class.
       
    40 *  This class implements the 3GP data sink methods.
       
    41 *
       
    42 *  @lib camc3gpsink
       
    43 *  @since 2.1
       
    44 */
       
    45 class CCamC3GPDataSinkImp : public CCamC3GPDataSink, public M3GPMP4LibAsyncTempFileRemoverObserver
       
    46     {
       
    47     public: // Methods called internally or by the controller
       
    48 
       
    49         /**
       
    50         * Default constructor.
       
    51         */
       
    52         CCamC3GPDataSinkImp() : CCamC3GPDataSink() {};
       
    53 
       
    54         /**
       
    55         * Destructor.
       
    56         */
       
    57 		~CCamC3GPDataSinkImp(void);
       
    58 
       
    59         /**
       
    60         * Constructor.
       
    61         */
       
    62     	void ConstructL(M3GPDataSinkObserver *aObserver);
       
    63 
       
    64         /**
       
    65         * Open a file for writing.
       
    66         * @since 2.1
       
    67         * @param aFileName File name
       
    68         * @param aAudioCodecType Four CC code of the used audio codec
       
    69         * @param aVideoCodecType Four CC code of the used video codec
       
    70         * @param aFileFormat Used file format TCamCSinkFileFormat
       
    71         * @return No return value
       
    72         */
       
    73         void OpenFileL(TFileName aFileName, TFourCC aAudioCodecType, const TDesC8& aVideoCodecType, TCamCSinkFileFormat aFileFormat );
       
    74 
       
    75         /**
       
    76         * Open a 3GP file for writing.
       
    77         * @since 3.2
       
    78         * @param aMMFFile CMMFFile from MMF
       
    79         * @param aAudioCodecType Four CC code of the used audio codec
       
    80         * @param aVideoCodecType Four CC code of the used video codec
       
    81         * @param aFileFormat Used file format TCamCSinkFileFormat
       
    82         * @return No return value
       
    83         */
       
    84         void OpenFileL(CMMFFile* aMMFFile, TFourCC aAudioCodecType, const TDesC8& aVideoCodecType, TCamCSinkFileFormat aFileFormat );
       
    85 
       
    86         /**
       
    87         * Order the sink to finalize and close the current 3GP file.
       
    88         * @since 2.1
       
    89         * @param None
       
    90         * @return No return value
       
    91         */
       
    92         void SinkStopL();
       
    93 
       
    94         /**
       
    95         * Set size limit of the 3GP file to be recorded in bytes.
       
    96         * @since 2.1
       
    97         * @param aSize Limit
       
    98         * @return No return value
       
    99         */
       
   100         void SetSizeLimit(TUint aSize);
       
   101 
       
   102         /**
       
   103         * Return the amount of time recording has been on in microseconds.
       
   104         * @since 2.1
       
   105         * @param None
       
   106         * @return Elapsed time
       
   107         */
       
   108         TTimeIntervalMicroSeconds GetElapsedTime();
       
   109 
       
   110         /**
       
   111         * Return the estimated remaining time for the recording in microseconds.
       
   112         * @since 2.1
       
   113         * @param None
       
   114         * @return Remaining time
       
   115         */
       
   116         TTimeIntervalMicroSeconds GetRemainingTimeL();
       
   117 
       
   118 
       
   119     public: // Methods called from MCMRMediaSink
       
   120 
       
   121         /**
       
   122         * Give video frame size to sink.
       
   123         * @since 2.1
       
   124         * @param aSize Frame size
       
   125         * @return Error code
       
   126         */
       
   127         TInt SetVideoFrameSize(TSize aSize);
       
   128 
       
   129         /**
       
   130         * Give average video bitrate to sink.
       
   131         * @since 2.1
       
   132         * @param aBitRate Average bitrate
       
   133         * @return Error code
       
   134         */
       
   135         TInt SetAverageVideoBitRate(TInt aBitRate);
       
   136 
       
   137         /**
       
   138         * Give maximum video bitrate to sink.
       
   139         * @since 2.1
       
   140         * @param aBitRate Maximum bitrate
       
   141         * @return Error code
       
   142         */
       
   143         TInt SetMaxVideoBitRate(TInt aBitRate);
       
   144 
       
   145         /**
       
   146         * Give average audio bitrate to sink.
       
   147         * @since 2.1
       
   148         * @param aBitRate Average bitrate
       
   149         * @return Error code
       
   150         */
       
   151         TInt SetAverageAudioBitRate(TInt aBitRate);
       
   152 
       
   153         /**
       
   154         * Write an audio/video buffer to the sink.
       
   155         * @since 2.1
       
   156         * @param aBuffer Buffer containing audio/video data
       
   157         * @return Errorcode
       
   158         */
       
   159         void WriteBufferL(CCMRMediaBuffer* aBuffer);
       
   160 
       
   161 
       
   162     public: // Methods from M3GPMP4LibAsyncTempFileRemoverObserver
       
   163         void M3GPMP4LibDeleteTempFileName( MP4FileName tempFileName );
       
   164 
       
   165     private: // Private methods
       
   166 
       
   167         /**
       
   168         * Estimate current file size
       
   169         * @since 2.1
       
   170         * @param None
       
   171         * @return File size
       
   172         */
       
   173         TUint CurrentFileSize() const;
       
   174 
       
   175         /**
       
   176         * Estimate current metadata size
       
   177         * @since 2.1
       
   178         * @param None
       
   179         * @return File size
       
   180         */
       
   181         TUint CurrentMetadataSize() const;
       
   182 
       
   183         /**
       
   184         * Calculate free space on a drive in bytes.
       
   185         * @since 2.1
       
   186         * @param None
       
   187         * @return File size
       
   188         */
       
   189         TInt64 DriveFreeSpaceL();
       
   190 
       
   191         /**
       
   192         * Determines AAC audio frame duration.
       
   193         * @since 2.8
       
   194         * @param Incoming buffer with audio dec spec info
       
   195         * @return None
       
   196         */
       
   197         void DetermineAACFrameDurationL(CCMRMediaBuffer* aBuffer);
       
   198 
       
   199         /**
       
   200         * Convert AVC specific decoder config info from NAL (GenericPayload) encapsulation to
       
   201         * AVC Decoder Configuration Record -format
       
   202         * @since 3.2
       
   203         * @param Source buffer with AVC specific decoder config info.
       
   204         * @param Destination buffer to write AVC Decoder Configuration Record.
       
   205         * @return None
       
   206         */
       
   207         void ConvertAVCHeaderNALL( CCMRMediaBuffer* aBuffer, TDes8& aDstBuf );
       
   208 
       
   209         /**
       
   210         * Convert AVC specific decoder config info from Bytestream (ElementaryStream) encapsulation to
       
   211         * AVC Decoder Configuration Record -format
       
   212         * @since 3.2
       
   213         * @param Source buffer with AVC specific decoder config info.
       
   214         * @param Destination buffer to write AVC Decoder Configuration Record.
       
   215         * @return None
       
   216         */
       
   217         void ConvertAVCHeaderByteStreamL( CCMRMediaBuffer* aBuffer, TDes8& aDstBuf );
       
   218 
       
   219         /**
       
   220         * Converts AVC frame from Bytestream (ElementaryStream) encapsulation to
       
   221         * file format AVC sample structure by replacing bytestream headers with NAL unit sizes.
       
   222         * @since 5.0
       
   223         * @param Source buffer with one or more bytestream header seperated NAL units.
       
   224         * @return None
       
   225         */
       
   226         void ConvertBytestreamHeadersToNALSizes( CCMRMediaBuffer* aBuffer );
       
   227 
       
   228         /**
       
   229         * Converts AVC frame from NAL (EGenericPayload) encapsulation to
       
   230         * file format AVC sample structure by replacing NAL encapsulation with NAL unit sizes.
       
   231         * @since 5.0
       
   232         * @param Source buffer with one or more NAL header seperated NAL units.
       
   233         * @param Destination buffer to write NAL units with length information.
       
   234         * @param Destination buffer size.
       
   235         * @return None
       
   236         */
       
   237         void ConvertNALEncapsulationToNALSizes( CCMRMediaBuffer* aBuffer );
       
   238 
       
   239     private:
       
   240 
       
   241         static TInt IdleDelete( TAny* aCont );
       
   242 
       
   243     public:
       
   244 
       
   245         TInt DoIdleDelete();
       
   246 
       
   247     private:
       
   248 
       
   249         // Observer to inform controller
       
   250         M3GPDataSinkObserver *iObserver;
       
   251 
       
   252         // 3GP library handle
       
   253         MP4Handle   iMP4Handle;
       
   254 
       
   255         // Number of bytes received from media recorder
       
   256         TUint       iBytesReceived;
       
   257 
       
   258         // Number of bytes of metadata currently accumulated
       
   259         TUint       iBytesOfMetadata;
       
   260 
       
   261         // Horizontal resolution of video
       
   262         TInt        iVideoXResolution;
       
   263 
       
   264         // Vertical resolution of video
       
   265         TInt        iVideoYResolution;
       
   266 
       
   267         // Average bitrate of video
       
   268         TInt        iVideoAverageBitRate;
       
   269 
       
   270         // Maximum bitrate of video
       
   271         TInt        iVideoMaxBitRate;
       
   272 
       
   273         // Average bitrate of audio
       
   274         TInt        iAudioAverageBitRate;
       
   275 
       
   276         // Type of buffer coming from media recorder
       
   277         CCMRMediaBuffer::TBufferType iBufferType;
       
   278 
       
   279         // Size of buffer coming from media recorder
       
   280         TInt        iBufferSize;
       
   281 
       
   282         // Types of codecs used in the output file
       
   283         TUint       iFileCodecType;
       
   284 
       
   285         // Timestamp of video frame coming from media recorder
       
   286         TTimeIntervalMicroSeconds   iVideoTimestamp;
       
   287 
       
   288         // Timestamp of video frame buffered in the sink
       
   289         TTimeIntervalMicroSeconds   iVideoBufferTimestamp;
       
   290 
       
   291         // Timestamp of the first video frame
       
   292         TTimeIntervalMicroSeconds   iFirstVideoFrameTimestamp;
       
   293 
       
   294         // Duration of the video frame buffered in the sink
       
   295         TUint       iVideoFrameDuration;
       
   296 
       
   297         // Is current video frame a random access point
       
   298         TBool       iVideoRandomAccessPoint;
       
   299 
       
   300         // Is the buffered video frame a random access point
       
   301         TBool       iVideoBufferRandomAccessPoint;
       
   302 
       
   303         // Sink buffers one video frame in this buffer
       
   304         TUint8*     iVideoBuffer;
       
   305 
       
   306         // Size of buffered video frame
       
   307         TUint       iVideoBufferFrameSize;
       
   308 
       
   309         // Size of video buffer
       
   310         TUint       iVideoBufferSize;
       
   311 
       
   312         // Number of video frames
       
   313         TUint       iVideoFrameNumber;
       
   314 
       
   315         // Number of intra video frames
       
   316         TUint       iVideoIntraFrameNumber;
       
   317 
       
   318         // Video decoder specific info size
       
   319         TInt        iVideoDecSpecInfoSize;
       
   320 
       
   321         // Audio decoder specific info size
       
   322         TInt        iAudioDecSpecInfoSize;
       
   323 
       
   324         // Sink buffers audio frames in this buffer
       
   325         TUint8*     iAudioBuffer;
       
   326 
       
   327         // Size of buffered audio frames
       
   328         TUint       iAudioBufferFrameSize;
       
   329 
       
   330         // Size of audio buffer
       
   331         TUint       iAudioBufferSize;
       
   332 
       
   333         // Number of audio frames
       
   334         TUint       iAudioFrameNumber;
       
   335 
       
   336         // Number of audio frames in the buffer
       
   337         TUint       iAudioFramesInBuffer;
       
   338 
       
   339         // Size limit of the file in bytes
       
   340         TInt64       iSizeLimit;
       
   341 
       
   342         // Has file size limit bee reached?
       
   343         TBool       iFileSizeLimitReached;
       
   344 
       
   345         // File server session handle
       
   346         RFs*        iFS;
       
   347 
       
   348         // Drive number of the output file
       
   349         TInt        iDriveNumber;
       
   350 
       
   351         // Has the disk been filled to the safety limit?
       
   352         TBool       iDiskFull;
       
   353 
       
   354         // Output filename
       
   355         TFileName   iFileName;
       
   356 
       
   357         // Temporary filename
       
   358         TFileName   iTmpFileName;
       
   359 
       
   360         // MMF resource to acquire file handle
       
   361         CMMFFile* iMMFFile;
       
   362 
       
   363         // File handle from MMF
       
   364         RFile * iFile;
       
   365 
       
   366         // Used to determine whether file handles or descriptors are used
       
   367         TBool iFileHandleExists;
       
   368 
       
   369         // Amount of remaining recording time
       
   370         TTimeIntervalMicroSeconds   iRemainingTime;
       
   371 
       
   372         // Remaining free disk space
       
   373         TInt64      iFreeDiskSpace;
       
   374 
       
   375         // Counter to check the real free disk space
       
   376         TInt        iFreeDiskSpaceCounter;
       
   377 
       
   378         // Available space on disk at start of recording
       
   379         TInt64  iAvailableSpaceAtStart;
       
   380 
       
   381         // Avarage of end time
       
   382         TTimeIntervalMicroSeconds  iAvarageEndTime;
       
   383 
       
   384         // Duration of AAC frame
       
   385         TInt iAudioAACFrameDuration;
       
   386 
       
   387         // AAC Audio Samplerate
       
   388         TInt iAudioAACSamplerate;
       
   389 
       
   390         // AVC video level id
       
   391         TInt iAVCOutputLevel;
       
   392 
       
   393         // Critical level for current target disk
       
   394         TInt iCriticalDiskVal;
       
   395 
       
   396         // File name queue for the temporary meta data files to be deleted.
       
   397         RPointerArray<MP4FileName>* iDeleteFileQueue;
       
   398 
       
   399         // Async file deletion on background
       
   400         CIdle* iIdleDelete;
       
   401 
       
   402     };
       
   403 
       
   404 #endif