os/mm/mdfdevvideoextensions/nga_mdf_postprocessor/inc/NGAPostProcHwDevice.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2008 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:
    15 *
    16 */
    17 
    18 
    19 #ifndef __NGAPOSTPROCHWDEVICE_H__
    20 #define __NGAPOSTPROCHWDEVICE_H__
    21 
    22 #include <e32std.h> 
    23 #include <w32std.h>
    24 #include <e32base.h>
    25 #include <e32def.h>
    26 #include <e32cmn.h>
    27 #include <stdio.h>
    28 #include <string.h>
    29 #include <stdarg.h>
    30 
    31 #include <mmf/devvideo/videoplayhwdevice.h>
    32 #include <mmf/devvideo/devvideostandardcustominterfaces.h>
    33 #include <mmf/devvideo/devvideovideosurfacecustominterface.h>
    34 #include <graphics/surfacemanager.h> //RSurfaceManager
    35 #include <graphics/surface.h> //TSurfaceId
    36 #include <mmf/common/mmfvideo.h> //TVideoAspectRatio
    37 #include <mmf/devvideo/devvideosurfacehandlecustominterface.h>
    38 #include <mmf/devvideo/devvideoplayratecustominterface.h>  
    39 #include <surface_hints.h>
    40 #include <secureoutputci.h>
    41 #include <advancedsecureoutputci.h>
    42 #include <graphics/suerror.h>
    43 
    44 #include "fetchframecustominterface.h"
    45 #include "MdfRDebug.h"
    46 #include "NGAPostProcHwDevice_UID.hrh"
    47 #include "NGAPostProcSessionManagerObserver.h"
    48 #include "common.h"
    49 
    50 class CNGAPostProcSessionManager;
    51 class CNGAPostProcSurfaceHandler;
    52 class CNGAPostProcTimer;
    53 class RWsSession;
    54 
    55 class CNGAPostProcHwDevice: public CMMFVideoPostProcHwDevice,
    56 							public MMmfVideoBufferManagement,
    57 							public MNGAPostProcSessionManagerObserver,
    58 							public MMMFVideoSurfaceSupport,
    59 							public MMmfVideoPropertiesObserver,
    60 							public MMmfVideoResourceObserver,
    61 							public MMmfVideoSurfaceHandleControl,
    62 							public MMmfVideoPropertiesNotifier,
    63 							public MMmfVideoPlayRateControl,
    64 							public MMmfVideoSecureOutput,
    65 							public MMmfAdvancedVideoSecureOutput
    66 {
    67 
    68 public: 
    69     //  === Constructors and destructor ===
    70     /**
    71     * Two-phased constructor.   
    72     * @return pointer to an instance of CMMFVideoPostProcHwDevice
    73     */
    74     static CMMFVideoPostProcHwDevice* NewL();
    75 
    76     /**
    77     * Destructor.
    78     */
    79     ~CNGAPostProcHwDevice();
    80 
    81 public: 
    82     
    83     // === CMMFVideoPostProcHwDevice ===
    84     
    85     /**
    86     Sets the device input format to an uncompressed video format.
    87 
    88     @param  "aFormat"   "The input format to use."
    89     @leave  "The method will leave if an error occurs. Typical error codes used:
    90             * KErrNotSupported - The input format is not supported."    
    91     @pre    "This method can only be called before the hwdevice has been initialized with Initialize()."
    92     */
    93     void SetInputFormatL(const TUncompressedVideoFormat& aFormat);
    94 
    95     /**
    96     Sets the decoder device that will write data to this post-processor. Decoded pictures will be 
    97     written with WritePictureL() or through a custom interface. After pictures have been processed, 
    98     they must be returned to the decoder using ReturnPicture().
    99 
   100     @param  "aDevice"   "The decoder source plug-in to use."
   101     @pre    "This method can only be called before the hwdevice has been initialized with Initialize()."
   102     */
   103     void SetInputDevice(CMMFVideoDecodeHwDevice* aDevice);
   104 
   105     /**
   106     Writes an uncompressed video picture to the post-processor. The picture must be returned to the 
   107     client or source plug-in after it has been used.
   108 
   109     @param  "aPicture"  "The picture to write."
   110     @leave  "This method may leave with one of the system-wide error codes."
   111     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   112     */
   113     void WritePictureL(TVideoPicture* aPicture);    
   114 
   115     /**
   116     Retrieves post-processing information about this hardware device. 
   117     The device creates a CPostProcessorInfo structure, fills it with correct data, pushes it 
   118     to the cleanup stack and returns it. The client will delete the object when it is no 
   119     longer needed.
   120 
   121     @return "Post-processor information as a CPostProcessorInfo object. 
   122             The object is pushed to the cleanup stack, and must be deallocated by the caller."
   123     @leave  "This method may leave with one of the system-wide error codes.
   124     */
   125     CPostProcessorInfo* PostProcessorInfoLC();
   126 
   127     /**
   128     Retrieves the list of the output formats that the device supports. The list is ordered in 
   129     plug-in preference order, with the preferred formats at the beginning of the list. The list 
   130     can depend on the device source format, and therefore SetSourceFormatL() must be called before 
   131     calling this method.
   132 
   133     @param "aFormats" "An array for the result format list. The array must be created and destroyed by the caller."
   134     @leave  "This method may leave with one of the system-wide error codes.
   135     @pre    "This method may only be called before the hwdevice has been initialized using Initialize()."
   136     */
   137     void GetOutputFormatListL(RArray<TUncompressedVideoFormat>& aFormats);
   138 
   139     /**
   140     Sets the device output format.
   141 
   142     @param  "aFormat" "The format to use."
   143     @leave  "This method may leave with one of the system-wide error codes.
   144     @pre    "This method may only be called before the hwdevice has been initialized using Initialize()."
   145     */
   146     void SetOutputFormatL(const TUncompressedVideoFormat &aFormat);
   147 
   148     /**
   149     Sets the clock source to use for video timing. If no clock source is set. video playback 
   150     will not be synchronized, but will proceed as fast as possible, depending on input data 
   151     and output buffer availability. 
   152 
   153     @param  "aClock" "The clock source to be used."
   154     @pre    "This method can only be called before the hwdevice has been initialized with Initialize()."
   155     */
   156     void SetClockSource(MMMFClockSource* aClock);
   157 
   158     /**
   159     Sets the device video output destination. The destination can be the screen (using direct 
   160     screen access) or memory buffers. By default memory buffers are used. If data is written 
   161     to another device, this method is ignored, and suitable memory buffers are always used.
   162     
   163     @param  "aScreen" "True if video output destination is the screen, false if memory buffers."
   164     @leave  "This method may leave with one of the system-wide error codes.
   165     @pre    "This method can only be called before the hwdevice has been initialized with Initialize()."
   166     */
   167     void SetVideoDestScreenL(TBool aScreen);
   168 
   169     /**
   170     Sets the post-processing types to be used.
   171 
   172     @param  "aPostProcCombination" "The post-processing steps to perform, a bitwise OR of values from TPostProcessType."
   173     @leave  "This method may leave with one of the system-wide error codes.
   174     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   175             If called after initialization, the change must only be committed when CommitL() is called."
   176     */
   177     void SetPostProcessTypesL(TUint32 aPostProcCombination);
   178 
   179     /**
   180     Sets post-processing options for input (pan-scan) cropping.
   181 
   182     @param  "aRect" "The cropping rectangle to use."
   183     @leave  "This method may leave with one of the system-wide error codes.
   184     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   185             If called after initialization, the change must only be committed when CommitL() is called."
   186     */
   187     void SetInputCropOptionsL(const TRect& aRect);
   188 
   189     /**
   190     Sets post-processing options for YUV to RGB color space conversion. 
   191     Specifies the input YUV and output RGB formats to use explicitly. SetSourceFormatL(), 
   192     SetOutputFormatL(), and SetPostProcessTypesL() must be called before this method is used.
   193 
   194     @param  "aOptions"      "The conversion options to use."
   195     @param  "aYuvFormat"    "Conversion source YUV format"
   196     @param  "aRgbFormat"    "Conversion target RGB format"
   197     @leave  "This method may leave with one of the system-wide error codes.
   198     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   199             If called after initialization, the change must only be committed when CommitL() is called."
   200     */
   201     void SetYuvToRgbOptionsL(const TYuvToRgbOptions& aOptions, const TYuvFormat& aYuvFormat, 
   202                                 TRgbFormat aRgbFormat);
   203 
   204     /**
   205     Sets post-processing options for YUV to RGB color space conversion.
   206     Uses the device input and output formats. For decoder devices the default YUV format used is 
   207     the format specified in the input bitstream. SetSourceFormatL(), SetOutputFormatL(), and 
   208     SetPostProcessTypesL() must be called before this method is used.
   209 
   210     @param  "aOptions"      "The conversion options to use."
   211     @leave  "This method may leave with one of the system-wide error codes.
   212     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   213             If called after initialization, the change must only be committed when CommitL() is called."
   214     */
   215     void SetYuvToRgbOptionsL(const TYuvToRgbOptions& aOptions);
   216 
   217     /**
   218     Sets post-processing options for rotation. SetPostProcessTypesL() must be called before 
   219     this method is used.
   220 
   221     @param  "aRotationType" "The rotation to perform."  
   222     @leave  "This method may leave with one of the system-wide error codes.
   223     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   224             If called after initialization, the change must only be committed when CommitL() is called."
   225     */
   226     void SetRotateOptionsL(TRotationType aRotationType);
   227 
   228     /**
   229     Sets post-processing options for scaling. SetPostProcessTypesL() must be called before 
   230     this method is used.
   231     
   232     @param  "aTargetSize"           "Scaling target size. If a fixed scale factor size is used, 
   233                                     the new dimensions must be set to width=floor(factor*width), 
   234                                     height=floor(factor*height). For example, scaling a 
   235                                     QCIF (176x144) picture up by a factor of 4/3 yields a size 
   236                                     of 234x192."
   237     @param  "aAntiAliasFiltering"   "True if anti-aliasing filtering should be used. 
   238                                     If the post-processor does not support anti-aliased scaling, 
   239                                     or supports anti-aliased scaling only, this argument is ignored."
   240     @leave  "This method may leave with one of the system-wide error codes.
   241     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   242             If called after initialization, the change must only be committed when CommitL() is called."
   243     */
   244     void SetScaleOptionsL(const TSize& aTargetSize, TBool aAntiAliasFiltering);
   245 
   246     /**
   247     Sets post-processing options for output cropping. SetPostProcessTypesL() must be called before 
   248     this method is used.
   249     
   250     @param  "aRect" "Output cropping area."
   251     @leave  "This method may leave with one of the system-wide error codes.
   252     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   253             If called after initialization, the change must only be committed when CommitL() is called."
   254     */
   255     void SetOutputCropOptionsL(const TRect& aRect);
   256 
   257     /**
   258     Sets post-processing plug-in specific options. SetPostProcessTypesL() must be called before 
   259     this method is used.
   260 
   261     @param  "aOptions" "The options. The format is plug-in specific."
   262     @leave  "This method may leave with one of the system-wide error codes.
   263     @pre    "This method can be called either before or after the hwdevice has been initialized with Initialize().
   264             If called after initialization, the change must only be committed when CommitL() is called."
   265     */
   266     void SetPostProcSpecificOptionsL(const TDesC8& aOptions);
   267 
   268     /**
   269     Initializes the device. This method is asynchronous, the device will call 
   270     MMFVideoPlayProxy::MdvppInitializeComplete() after initialization has completed. After this 
   271     method has successfully completed, further configuration changes are not possible except where 
   272     separately noted.
   273     */
   274     void Initialize();
   275 
   276     /**
   277     Commit all changes since the last CommitL(), Revert() or Initialize()
   278     to the hardware device.  This only applies to methods which can be called both
   279     before AND after DevVideoPlay has been initialized.
   280 
   281     @see    SetPostProcessTypesL
   282     @see    SetInputCropOptionsL
   283     @see    SetYuvToRgbOptionsL
   284     @see    SetRotateOptionsL
   285     @see    SetScaleOptionsL
   286     @see    SetOutputCropOptionsL
   287     @see    SetPostProcSpecificOptionsL
   288 
   289     @leave  "The method will leave if an error occurs."
   290     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   291     */
   292     void CommitL();
   293 
   294     /**
   295     Revert all changes since the last CommitL(), Revert() or Initialize()
   296     back to their previous settings.  This only applies to methods which can 
   297     be called both before AND after DevVideoPlay has been initialized.
   298 
   299     @see    SetPostProcessTypesL
   300     @see    SetInputCropOptionsL
   301     @see    SetYuvToRgbOptionsL
   302     @see    SetRotateOptionsL
   303     @see    SetScaleOptionsL
   304     @see    SetOutputCropOptionsL
   305     @see    SetPostProcSpecificOptionsL
   306 
   307     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   308     */
   309     void Revert();
   310 
   311     /**
   312     Starts writing output directly to the display frame buffer using Direct Screen Access.
   313 
   314     @param  "aVideoRect"    "The video output rectangle on screen."
   315     @param  "aScreenDevice" "The screen device to use. The screen device object must be valid in the current thread."
   316     @param  "aClipRegion"   "Initial clipping region to use."
   317     
   318     @leave  "This method may leave with one of the system-wide error codes.
   319     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   320     */
   321     void StartDirectScreenAccessL(const TRect& aVideoRect, 
   322         CFbsScreenDevice& aScreenDevice, const TRegion& aClipRegion);
   323 
   324     /**
   325     Sets a new clipping region for Direct Screen Access. After the method returns, no video will 
   326     be drawn outside of the region. If clipping is not supported, or the clipping region is too 
   327     complex, either playback will pause or will resume without video display, depending on the 
   328     current setting of SetPauseOnClipFail(), and the result can be verified with IsPlaying(). 
   329     Clipping can be disabled by setting a new clipping region that includes the whole video window.
   330 
   331     @param  "aRegion" "The new clipping region. After the method returns, no video will be drawn outside the region."
   332     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   333     */
   334     void SetScreenClipRegion(const TRegion& aRegion);
   335 
   336     /**
   337     Sets whether the system should pause playback when it gets a clipping region it cannot handle, 
   338     or Direct Screen Access is aborted completely. If not, processing will proceed normally, but no 
   339     video will be drawn. By default, playback is paused.
   340 
   341     @param "aPause" "True if playback should be paused when clipping fails, false if not. 
   342                     If playback is not paused, it will be continued without video display."
   343     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   344     */
   345     void SetPauseOnClipFail(TBool aPause);
   346 
   347     /**
   348     Aborts Direct Screen Access completely, to be called from MAbortDirectScreenAccess::AbortNow() 
   349     and similar methods. DSA can be resumed by calling StartDirectScreenAccessL().
   350     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   351     */
   352     void AbortDirectScreenAccess();
   353 
   354     /**
   355     Indicates whether playback is proceeding. This method can be used to check whether playback was 
   356     paused or not in response to a new clipping region or DSA abort.
   357 
   358     @return "ETrue if video is still being played (even if not necessarily displayed)."
   359     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   360     */
   361     TBool IsPlaying();
   362 
   363     /**
   364     Re-draws the latest video picture. Only available when DSA is being used. If DSA is aborted or a 
   365     non-supported clipping region has been set, the request may be ignored.
   366     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   367     */
   368     void Redraw();
   369 
   370 
   371     /**
   372     Starts video playback, including decoding, post-processing, and rendering. Playback will proceed 
   373     until it has been stopped or paused, or the end of the bitstream is reached.
   374     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   375     */
   376     void Start();
   377 
   378     /**
   379     Stops video playback. No new pictures will be decoded, post-processed, or rendered.
   380     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   381     */
   382     void Stop();
   383 
   384     /**
   385     Pauses video playback, including decoding, post-processing, and rendering. No pictures will be 
   386     decoded, post-processed, or rendered until playback has been resumed.
   387     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   388     */
   389     void Pause();
   390 
   391     /**
   392     Resumes video playback after a pause.
   393     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   394     */
   395     void Resume();
   396 
   397     /**
   398     Changes to a new decoding and playback position, used for randomly accessing (seeking) the 
   399     input stream. The position change flushes all input and output buffers. Pre-decoder and 
   400     post-decoder buffering are handled as if a new bitstream was being decoded. If the device still
   401     has buffered pictures that precede the new playback position, they will be discarded. If playback
   402     is synchronized to a clock source, the client is responsible for setting the clock source to the 
   403     new position.
   404     
   405     @param "aPlaybackPosition" "The new playback position in the video stream."
   406     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   407     */
   408     void SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition);
   409 
   410     /**
   411     Freezes a picture on the screen. After the picture has been frozen, no new pictures are 
   412     displayed until the freeze is released with ReleaseFreeze(). If the device output is being 
   413     written to memory buffers or to another plug-in, instead of the screen, no decoded pictures 
   414     will be delivered while the freeze is active, and they are simply discarded.
   415 
   416     @param "aTimestamp" "The presentation timestamp of the picture to freeze. The frozen picture 
   417                         will be the first picture with a timestamp greater than or equal to this 
   418                         parameter."
   419     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   420     */
   421     void FreezePicture(const TTimeIntervalMicroSeconds& aTimestamp);
   422 
   423     /**
   424     Releases a picture frozen with FreezePicture().
   425 
   426     @param "aTimestamp" "The presentation timestamp of the picture to release. The first picture 
   427                         displayed after the release will be the first picture with a timestamp 
   428                         greater than or equal to this parameter. To release the freeze immediately, 
   429                         set the timestamp to zero."
   430     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   431     */
   432     void ReleaseFreeze(const TTimeIntervalMicroSeconds& aTimestamp);
   433 
   434 
   435     /**
   436     Returns the current playback position, i.e. the timestamp for the most recently displayed or 
   437     virtually displayed picture. If the device output is written to another device, the most recent 
   438     output picture is used.
   439 
   440     @return "Current playback position."
   441     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   442     */
   443     TTimeIntervalMicroSeconds PlaybackPosition();
   444 
   445     /**
   446     Returns the total amount of memory allocated for uncompressed pictures. This figure only 
   447     includes the pictures actually allocated by the plug-in itself, so that the total number of 
   448     bytes allocated in the system can be calculated by taking the sum of the values from all plug-ins.
   449 
   450     @return "Total number of bytes of memory allocated for uncompressed pictures."
   451     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   452     */
   453     TUint PictureBufferBytes();
   454 
   455     /**
   456     Reads various counters related to decoded pictures. The counters are reset when Initialize() 
   457     or this method is called, and thus they only include pictures processed since the last call.
   458 
   459     Post-processor devices return the number of input pictures in iPicturesDecoded and 
   460     iTotalPictures. If the decoded pictures are written to another plug-in, they are considered 
   461     to be "virtually displayed".
   462 
   463     @param "aCounters" "The counter structure to fill."
   464     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   465     */
   466     void GetPictureCounters(CMMFDevVideoPlay::TPictureCounters& aCounters);
   467 
   468 
   469     /**
   470     Sets the computational complexity level to use. If separate complexity levels are not available, 
   471     the method call is ignored. If the level specified is not available, the results are undefined. 
   472     Typically the device will either ignore the request or use the nearest suitable level.
   473 
   474     The complexity level can be changed at any point during playback.
   475 
   476     @param "aLevel" "The computational complexity level to use. Level zero (0) is the most complex 
   477                     one, with the highest quality. Higher level numbers require less processing 
   478                     and may have lower quality."
   479     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   480     */
   481     void SetComplexityLevel(TUint aLevel);
   482 
   483     /**
   484     Gets the number of complexity levels available.
   485     
   486     @return "The number of complexity control levels available, or zero if the information is not 
   487             available yet. The information may not be available if the number of levels depends on 
   488             the input data, and enough input data has not been read yet. In that case, using level 
   489             zero is safe."
   490     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   491     */
   492     TUint NumComplexityLevels();
   493 
   494     /**
   495     Gets information about a computational complexity level. This method can be called after 
   496     NumComplexityLevels() has returned a non-zero value - at that point the information is guaranteed 
   497     to be available. Some hardware device implementations may not be able to provide all values, 
   498     in that case the values will be approximated.
   499 
   500     @param "aLevel" "The computational complexity level to query. The level numbers range from zero 
   501                     (the most complex) to NumComplexityLevels()-1."
   502     @param "aInfo"  "The information structure to fill."
   503     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   504     */
   505     void GetComplexityLevelInfo(TUint aLevel, CMMFDevVideoPlay::TComplexityLevelInfo& aInfo);
   506 
   507     /**
   508     Returns a picture back to the device. This method is called by CMMFDevVideoPlay to return pictures 
   509     from the client (after they have been written with NewPicture()), or by the output device when 
   510     it has finished using a picture.
   511 
   512     @param "aPicture" "The picture to return. The device can re-use the memory for the picture."
   513     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   514     */
   515     void ReturnPicture(TVideoPicture* aPicture);
   516 
   517     /**
   518     Gets a copy of the latest picture sent to output.
   519 
   520     @param "aPictureData"   "Target picture. The memory for the picture must be allocated by the 
   521                             caller, and initialized properly. The data formats must match the snapshot 
   522                             format requested."
   523     @param "aFormat"        "The picture format to use for the snapshot."
   524 
   525     @return "ETrue if the snapshot was taken, EFalse if a picture is not available. The picture may not 
   526             be available if decoding has not progressed far enough yet."
   527 
   528     @leave  "The method will leave if an error occurs. Typical error codes used:
   529             * KErrNotSupported - The requested data format or picture size is not supported, or the 
   530             plug-in does not support snapshots."
   531     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   532     */
   533 //  TBool GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& aFormat) {return EFalse;};
   534     TBool GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& aFormat);
   535 
   536     /**
   537     When the snapshot is available, it will be returned to the client using the TimedSnapshotComplete()
   538     callback. To cancel a timed snapshot request, use CancelTimedSnapshot(). Only one timed snapshot 
   539     request can be active at a time.
   540 
   541     @param "aPictureData"           "Target picture. The memory for the picture must be allocated by 
   542                                     the caller, and initialized properly. The data formats must match 
   543                                     the snapshot format requested. The picture must remain valid until 
   544                                     the snapshot has been taken or until the request has been cancelled 
   545                                     with CancelTimedSnapshot()."
   546     @param "aFormat"                "The picture format to use for the snapshot."
   547     @param "aPresentationTimestamp" "Presentation timestamp for the picture to copy."
   548 
   549     @leave  "The method will leave if an error occurs. Typical error codes used:
   550             * KErrNotSupported - The requested data format or picture size is not supported or 
   551             the plug-in does not support timed snapshots."
   552     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   553     */
   554     //void GetTimedSnapshotL(TPictureData* aPictureData, const TUncompressedVideoFormat& aFormat, 
   555     //                        const TTimeIntervalMicroSeconds& aPresentationTimestamp){};
   556     void GetTimedSnapshotL(TPictureData*, const TUncompressedVideoFormat&, const TTimeIntervalMicroSeconds&){};
   557 
   558 
   559     /**
   560     When the snapshot is available, it will be returned to the client using the TimedSnapshotComplete()
   561     callback. To cancel a timed snapshot request, use CancelTimedSnapshot(). Only one timed snapshot 
   562     request can be active at a time.
   563 
   564     @param "aPictureData"           "Target picture. The memory for the picture must be allocated by 
   565                                     the caller, and initialized properly. The data formats must match 
   566                                     the snapshot format requested. The picture must remain valid until 
   567                                     the snapshot has been taken or until the request has been cancelled 
   568                                     with CancelTimedSnapshot()."
   569     @param "aFormat"                "The picture format to use for the snapshot."
   570     @param "aPictureId"             "Picture identifier for the picture to copy."
   571 
   572     @leave  "The method will leave if an error occurs. Typical error codes used:
   573             * KErrNotSupported - The requested data format or picture size is not supported or 
   574             the plug-in does not support timed snapshots."
   575     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   576     */
   577 //    void GetTimedSnapshotL(TPictureData* aPictureData, const TUncompressedVideoFormat& aFormat, 
   578 //                            const TPictureId& aPictureId){};
   579     void GetTimedSnapshotL(TPictureData*, const TUncompressedVideoFormat&, const TPictureId& ){};
   580 
   581     /**
   582     Cancels a timed snapshot request.
   583     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   584     */
   585     void CancelTimedSnapshot(){};
   586 
   587     /**
   588     Gets a list of the supported snapshot picture formats.
   589 
   590     @param "aFormats" "An array for the result format list. The array must be created and destroyed by 
   591     the caller."
   592 
   593     @leave "This method may leave with one of the standard error codes."
   594     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   595     */
   596     void GetSupportedSnapshotFormatsL(RArray<TUncompressedVideoFormat>&){};
   597 
   598 
   599     /**
   600 
   601     Notifies the hardware device that the end of input data has been reached and no more input data 
   602     will be written. The hardware device can use this signal to ensure that the remaining data gets 
   603     processed, without waiting for new data. For example when the data type is not EDuCodedPicture,
   604     calling this method is necessary otherwise a hardware device implementation might be looking for 
   605     the start code for the next picture to ensure it has a complete picture before starting to decode
   606     the previous one. 
   607     
   608       
   609     After the remaining data has been processed (and displayed, if applicable), the hardware 
   610     device must notify the proxy with the MdvppStreamEnd() callback.
   611 
   612     DevVideo clients are encouraged to call this method, but its use is not mandatory for synchronized
   613     processing.  For synchronized playback, all video pictures are processed or discarded according to 
   614     their timestamps, and so the client can easily infer when processing is complete.  However, it 
   615     should be noted that the last picture might not be displayed if this method is not called and the 
   616     input data type is not EDuCodedPicture.
   617 
   618     For non-synchronized playback (e.g. file conversion), a client must call this method otherwise it
   619     will never find out when the hardware device has finished processing the data.
   620     
   621     @pre    "This method can only be called after the hwdevice has been initialized with Initialize()."
   622     */
   623     void InputEnd();
   624 
   625     /**
   626     Retrieves a custom interface to the device.
   627     @param  "aInterface"    "Interface UID, defined with the custom interface."
   628     @return "Pointer to the interface implementation, or NULL if the device does not 
   629             implement the interface requested. The return value must be cast to the 
   630             correct type by the user."
   631     */
   632     TAny* CustomInterface(TUid aInterface);  
   633     
   634     // === MNGAPostProcSessionManagerObserver ===
   635     /**
   636     Set the proxy implementation to be used. Called just after the object is constructed.
   637     @param  "aProxy"    "The proxy to use."
   638     */
   639     void BufferAvailable(TInt aBufId, TInt aStatus);
   640     
   641 public: 
   642 
   643     // === MMmfVideoBufferManagement ===
   644     
   645     /** 
   646      * Sets the observer object to use. The observer gets notified
   647      * when new buffers are available and when buffers need to be
   648      * released back to the media device.
   649      *
   650      * This method can only be called before the media device has
   651      * been Initialized with InitializeL().
   652      * 
   653      * @param aObserver The observer object to use.
   654      */
   655     void MmvbmSetObserver(MMmfVideoBufferManagementObserver* aObserver);
   656     
   657     /** 
   658      * Enables input buffer management mode. In buffer management mode
   659      * the target media device allocates memory for input buffers and
   660      * the client can only use input buffers allocated with
   661      * MmvbmGetBufferL().
   662      *
   663      * This method can only be called before the media device has been
   664      * Initialized with InitializeL(). This method must be called if
   665      * the client uses MmvbmGetBufferL().
   666      * 
   667      * @param aEnable ETrue if input buffer management mode is used.
   668      */
   669     void MmvbmEnable(TBool aEnable);
   670     
   671     /** 
   672      * Sets the buffer options to use. The client can request the
   673      * number of input buffers that should be available, but typically
   674      * only few (one or two) buffers can be used.
   675      *
   676      * This method can only be called before the media device has been
   677      * Initialized with InitializeL().
   678      * 
   679      * @param aOptions The buffer options to use, see TBufferOptions.
   680      *
   681      * @leave KErrNotSupported The requested buffer options are not
   682      *   supported. Typically the client has requested too many input
   683      *   buffers.
   684      */
   685     void MmvbmSetBufferOptionsL(const TBufferOptions& aOptions);
   686     
   687     /** 
   688      * Gets the buffer options currently in use.
   689      *
   690      * This method can only be called before the media device has been
   691      * Initialized with InitializeL().
   692      * 
   693      * @param aOptions Target buffer options data structure.
   694      */
   695     void MmvbmGetBufferOptions(TBufferOptions& aOptions);
   696     
   697     /** 
   698      * Gets a new input picture buffer. The client can then write data
   699      * into the buffer and write it back to the media device with
   700      * WritePictureL().
   701      *
   702      * This method can only be called after the media device has been
   703      * Initialized with InitializeL(). This method can only be called
   704      * in buffer management mode, i.e. if the client has called
   705      * MmvbmEnable(ETrue).
   706      *
   707      * Note that target-allocated and client-allocated input buffers
   708      * cannot be mixed. In buffer management mode only input buffers
   709      * allocated with this method can be sent to the media device.
   710      *
   711      * If a client has retrieved buffers with MmvbmGetBufferL(), it
   712      * must be prepated to release them synchronously at any point if
   713      * MmmfBufferManagementObserver::MmvbmoReleaseBuffers() is
   714      * called. This may happen if the target media device suddenly
   715      * loses access to the buffers due to DSA abort, resource
   716      * management conflict, or media device destruction.
   717      * 
   718      * @param aSize The requested buffer size, in pixels. The buffer
   719      *   size should match the picture size set at initialisation phase,
   720      *   or otherwise suitable buffer may not be available. If the size
   721      *   is smaller than the size set at initialisation phase, the
   722      *   allocated buffer may be larger than requested.
   723      * 
   724      * @return A new input picture buffer. If no free buffers are
   725      * available, the return value is NULL.
   726      *
   727      * @leave General The method will leave if an error occurs. Lack
   728      * of free buffers is not considered an error.
   729      */
   730     TVideoPicture* MmvbmGetBufferL(const TSize& aSize);
   731     
   732     /** 
   733      * Releases an input buffer back to the media device without using
   734      * it. This method is mainly used as a response to a
   735      * MmvbmReleaseBuffers() callback.
   736      * 
   737      * @param aBuffer The buffer to release.
   738      */
   739     void MmvbmReleaseBuffer(TVideoPicture* aBuffer);    
   740     
   741 public:
   742     
   743      // === MMMFVideoSurfaceSupport ===
   744     
   745 	/** 
   746     Requests the media device to use graphics surfaces for video rendering. 
   747     The client must call this method before Initialize() to ensure the media 
   748     device allocates the right types of resources for rendering.
   749     */
   750     void MmvssUseSurfaces();
   751     
   752     /** 
   753     Sets a new video surface support observer to receive surface management events 
   754     from the media device.
   755      
   756     @param aObserver New observer object to use.
   757     */
   758     void MmvssSetObserver(MMMFVideoSurfaceObserver& aObserver);
   759     
   760     /** 
   761     Retrieves surface parameters for a display. The client typically calls this in response 
   762     to a MmvsoSurfaceCreated() or MmvsoSurfaceParametersUpdated() observer callback.
   763      
   764     @param  aSurfaceId
   765 	        Surface ID for the display.
   766 	@param  aCropRect
   767 	        Cropping rectangle within the surface. The crop rectangle identifies the area of 
   768 	        the surface that should be shown on the screen.
   769 	@param  aPixelAspectRatio
   770 	        Video picture pixel aspect ratio.
   771 
   772 	@leave KErrNotReady if no surface is available for the display.
   773     */
   774     
   775     void MmvssGetSurfaceParametersL(TSurfaceId& aSurfaceId, TRect& aCropRect, 
   776     					TVideoAspectRatio& aPixelAspectRatio);
   777     /** 
   778     Indicates that the surface is no longer in use and can be destroyed. The client typically calls
   779     this in response to MmvsoSurfaceCreated() (while old surface is already in use and the current
   780     should be removed) or MmvsoRemoveSurface() observer callback.  
   781          
   782     @param aSurfaceId Surface ID that is no longer in use
   783     
   784     @leave KErrNotFound if the surface does not exist
   785     */
   786     void MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId);    
   787 
   788 public:    
   789 
   790     // === MMmfVideoPropertiesObserver ===
   791     
   792     /** 
   793     Decoded video properties updated. The media device implementing the
   794     MMmfVideoPropertiesNotifier extension will call this method immediately
   795     before outputting a picture with the updated properties.
   796     
   797     When the extension is used between a decoder and a post-processor media
   798     device, the post-processor can associate the changed properties with the
   799     correct picture, since the next incoming picture after this call will
   800     be the first updated one. 
   801     
   802     When the extension is used between a DevVideoPlay client and a
   803     post-processor media device, the client can synchronously reconfigure
   804     video display options using SetScaleOptionsL() and related methods. This
   805     lets the client reconfigure the display for the correct picture.
   806     
   807     @param aYuvFormat Updated YUV format parameters. The updated fields are
   808                       iAspectRatioDenom, iAspectRatioNum, and iCoefficients     
   809     @param aPictureSize	Updated picture size. This size will be the true
   810                        	picture display size, excluding any padding that
   811                        	the codec might use.
   812     */
   813     virtual void MmvpoUpdateVideoProperties(const TYuvFormat& aYuvFormat, const TSize& aPictureSize);
   814     
   815 public:
   816 
   817     // === MMmfVideoResourceObserver ===
   818     
   819     /** 
   820     Indicates that a media device has lost its resources. The client must
   821     synchronously pause or stop processing before returning from this method
   822     so that the media device can release its resources to the system. If
   823     the client does not pause or stop, resource loss will be handled as a
   824     fatal error.
   825      
   826     The client may start again or resume after receiving a
   827     MvroResourcesRestored() callback.
   828      
   829     @param aMediaDevice UID for the media device that lost resources. The
   830                         client can use this e.g. to determine whether the
   831                         decoder or the post-processor lost resources. This
   832                         is typically not required though since the client
   833                         must pause DevVideo entirely.
   834     */
   835     virtual void MmvroResourcesLost(TUid aMediaDevice);
   836 
   837     /** 
   838     Indicates that a media device has regained its resources after a
   839     previous resource loss. The client can restart or resume processing.
   840     This can be done either synchronously or asynchronously.
   841      
   842     @param aMediaDevice UID for the media device that regained resources.
   843     */
   844     virtual void MmvroResourcesRestored(TUid aMediaDevice);
   845             
   846     
   847     // === MMmfVideoSurfaceHandleControl ===
   848     
   849     /** 
   850     Sets an external surface ID. This should be called as soon as external surface is created.    
   851      
   852     @param aSurfaceID external surface ID.
   853         
   854     */
   855     
   856     virtual void MmvshcSetSurfaceHandle(const TSurfaceId& aSurfaceHandle);
   857     
   858     /** 
   859     Sets a redraw buffer to be used during resource loss.    
   860      
   861     @param aRedrawBuffer redraw buffer.
   862         
   863     */
   864      virtual void MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer);
   865 public:
   866 	// === MMmfVideoPropertiesNotifier ===
   867     /** 
   868     Sets a new video properties observer. This method can be called at any
   869     time after the media device has been instantiated.
   870      
   871     @param aObserver New observer object.
   872     */
   873     virtual void MmvpnSetObserver(MMmfVideoPropertiesObserver* aObserver);
   874 
   875 public:
   876 	
   877 	void ReturnPicToDecoder(TVideoPicture* aPic);
   878 	TInt AttemptToPost();
   879 	
   880 public:
   881     //=== MMdfTrickPlayControl === =     
   882     /**        
   883      * Query the Direction capabilities from the MDF decoders and       
   884      * post processor.       
   885      *        
   886     */       
   887     virtual void MmvprcGetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCapabilities);
   888 
   889     /**       
   890      * Sets the playback speed. A negative rate means play backward.       
   891      * +/- percentage.       
   892      *        
   893      */       
   894     virtual void MmvprcSetPlayRateL(const TInt aRate);
   895 
   896     /**       
   897      * Gets the playback speed. A negative rate means play backward.       
   898      * +/- percentage.       
   899      *        
   900      */       
   901     virtual TInt MmvprcPlayRateL();
   902 
   903     /**       
   904      * Sets the step frame number in frame step mode       
   905      * +/- frames       
   906      */       
   907     virtual void MmvprcStepFrameL(const TInt aStep);
   908 
   909     /**       
   910      * Registers the observer       
   911      */       
   912     virtual void MmvprcSetObserver(MMmfVideoPlayRateObserver& aObserver); 
   913 
   914 public: 
   915      
   916     // === MMmfVideoSecureOutput ===
   917     /**
   918      * Notifies the media device if the content can only be sent to a
   919      * secure output. The device display is typically considered a
   920      * secure output, but a high-quality unprotected analog or digital
   921      * video output connector is not. By default all content can be
   922      * sent to both secure and insecure outputs.
   923      *
   924      * This method can only be called before the media device has been
   925      * initialised with InitializeL().
   926      *
   927      * @param aSecure Set to ETrue if the content can only be sent to
   928      *     a secure output, EFalse if both secure and unsecure outputs can
   929      *     be used.
   930      *
   931      * @leave KErrNotSupported Insecure outputs cannot be
   932      * disabled. The client should not play protected content.
   933      */    
   934      virtual void MmvsoSetSecureOutputL(TBool aSecure);
   935 
   936 public:
   937      //=== AdvancedVideoSecureOutput === =     
   938      virtual void MmavsoSetAllowedOutputL(TUint aAllowedOutputMask);
   939     
   940 protected: 
   941 
   942     // === CMMFVideoPostProcHwDevice ===
   943     /**
   944     Set the proxy implementation to be used. Called just after the object is constructed.
   945     @param  "aProxy"    "The proxy to use."
   946     */
   947     void SetProxy(MMMFDevVideoPlayProxy& aProxy);
   948     
   949 protected:
   950 
   951     /**
   952      *  Symbian 2nd phase constructor .
   953      */
   954     void ConstructL();
   955     
   956 private:    
   957 	TInt IsTimeToPost(TVideoPicture* frame, TInt64& delta);
   958 	TVideoPicture* CreateBuffersL(TInt aBufId);
   959     void CreateVBMBuffersL();
   960     TInt SetupExternalSurface(const TSurfaceId &aSurfaceID);
   961     void ReleaseInputQ();
   962     void ReleaseProcessQ();
   963     void ReleasePicture(TVideoPicture *pic);
   964     void PublishSurfaceCreated();
   965     void PublishSurfaceUpdated();
   966     TInt SetupSurface(const TSize& aSize);
   967     void SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf);
   968     TInt GetID(TVideoPicture *aPicture);
   969     TInt GetExternalBufferID(TVideoPicture *aPicture);
   970     TInt RegisterSurface(const TSurfaceId& aSurfaceId);
   971     TInt IsGceReady();
   972     void SetTimer(TInt64 aDelta);
   973     TInt ConvertPostProcBuffer(TVideoPicture* pSrc, TVideoPicture* pDest);
   974     void AddPictureToVBMQ(TVideoPicture *pic);
   975     void AddPictureToColorConversionQ(TVideoPicture *pic);
   976     void ResetCountingBuffer();
   977     void PicturesSkipped();
   978     TVideoPicture* DoColorConvert(TVideoPicture* aPicture);
   979 
   980     /**       
   981      Adds a picture to the Input queue. Based on the timestamp of the picture,
   982      it is either appeneded at the end of the queue or inserted at the 
   983      appropriate position. The queue is arranged in the ascending order. 
   984      The ret value indicates if the head of the queue was changed or not.         
   985     */  
   986     TInt AddToQ(TVideoPicture* aPicture);
   987     
   988     /**       
   989      Removes a picture from Input queue based on the playrate.
   990      If the playrate is +ve ie forward playback head will be removed
   991      and if the playrate is -ve ie backward playback tail
   992      will be removed.         
   993     */  
   994     void RemoveFromQ();
   995     
   996     /**       
   997      Returns a picture from Input queue based on the playrate.
   998      If the playrate is +ve ie forward playback head will be returned
   999      and if the playrate is -ve ie backward playback tail  
  1000      will be returned.       
  1001     */  
  1002     TVideoPicture* PeekQ();
  1003 
  1004     /**
  1005     Adds a surface hint to a video surface. If there is any hint already added, 
  1006     the surface is updated with the new hint. 
  1007     */		
  1008     TInt AddHints();
  1009     
  1010 	#ifdef _DUMP_YUV_FRAMES
  1011     void captureYuv(TVideoPicture* aPicture);
  1012     #endif
  1013     
  1014     TInt SetSourceFormat();
  1015     TInt SetSourceRange();
  1016     TInt ColorConvert(tBaseVideoFrame* aInputFrame, TUint8* aDestPtr, tWndParam* aInputCropWindow, tWndParam* aOutputCropWindow);
  1017 
  1018 private:
  1019 
  1020     //
  1021     // C++ default constructor.  
  1022     //
  1023     CNGAPostProcHwDevice();
  1024 
  1025     //
  1026     // State of post processor
  1027     //
  1028     enum TPPState
  1029     {
  1030         EInitializing,
  1031         EInitialized,
  1032         EPlaying,
  1033         EPaused,
  1034         EStopped
  1035     };
  1036     
  1037     enum TTimeToPost
  1038     {
  1039         ESkipIt = -1,
  1040         EPostIt = 0,
  1041         EDelayIt = 1,
  1042     };
  1043     
  1044 private: 
  1045 
  1046     MMMFDevVideoPlayProxy*      				iProxy;															
  1047     CMMFVideoDecodeHwDevice*    				iInputDecoderDevice;															
  1048     RArray<TVideoPicture*>              		iInputQ;															
  1049     RArray<TVideoPicture*>              		iProcessQ;															
  1050     MMMFClockSource*            				iClockSource;															
  1051     TTimeIntervalMicroSeconds					iCurrentPlaybackPosition;															
  1052     TPPState        							iPPState;															
  1053     CNGAPostProcSurfaceHandler*					iSurfaceHandler;
  1054     CNGAPostProcSessionManager*					iSessionManager;
  1055 	
  1056 	RSurfaceManager::TSurfaceCreationAttributesBuf	iAttributes;
  1057 	RChunk										iChunk;
  1058 	RSurfaceManager::TInfoBuf 					iInfo;
  1059 	TSurfaceId									iSurfaceId;
  1060 	TBool           							iIsInputEnded;
  1061 	CNGAPostProcTimer*							iPostingTimer;
  1062 	CMMFDevVideoPlay::TPictureCounters  		iPictureCounters;
  1063 	TBool 										iFirstPictureUpdated;
  1064 	TBool 										iUsingExternalSurface;
  1065     TBool           							iIsColorConversionNeeded;
  1066     RArray<TVideoPicture*>              		iColorConversionQ;
  1067     TBool 										iSurfaceCreatedEventPublished;
  1068     TInt                                		iOverflowPictureCounter;
  1069     TInt 								    	iVideoFrameBufSize;	
  1070     TBool 										iResourceLost;
  1071     TBool 										iRedrawDone;
  1072 	// Flag to indicate that the redraw surface has been created, and
  1073 	// can be used in a subsequent call ro Redraw()
  1074 	TBool										iRedrawSurfaceInUse;
  1075 
  1076     //-- members for buffer management --
  1077     MMmfVideoBufferManagementObserver*  		iVBMObserver;
  1078     TBufferOptions                      		iVBMBufferOptions;
  1079     RArray<TVideoPicture*>              		iVBMBufferReferenceQ;
  1080     RArray<TVideoPicture*>              		iVBMBufferQ;
  1081     TBool                               		iVBMEnabled;
  1082     RArray<TUncompressedVideoFormat>    		iSupportedInputFormats;
  1083     TInt										count;
  1084     
  1085     //-- members for Surface Hints --
  1086     RSurfaceManager::THintPair					iHint;
  1087     TUint 										iSurfaceMask;
  1088     TUid										iSurfaceKey;
  1089             
  1090     //-- members for Surface support --
  1091     MMMFVideoSurfaceObserver*					iVideoSurfaceObserver;
  1092 	MMmfVideoPropertiesObserver*				iVPObserver;
  1093 	RWsSession									iWsSession;
  1094 	TSize										iPicSize;
  1095 	TUint										iAspectRatioNum;
  1096 	TUint										iAspectRatioDenom;
  1097 	//-- members for Trickplay support --
  1098 	TInt                                iStepFrameCount;
  1099     TInt                                iPlayRate;       
  1100     TBool                               iKeyFrameMode;       
  1101     MMmfVideoPlayRateObserver*          iFPObserver;       
  1102     TUint8                              iSkippedFramesCountingBuffer[64];       
  1103     TUint8                              iSkippedFramesInLast64Frames;       
  1104     TUint8                              iCurrentPosInFramesCountingBuffer; 
  1105     TUncompressedVideoFormat 			iVideoFormat;
  1106         //---------- utility variables -------
  1107 	// Image source format
  1108 	TUint8 								iSourceFormat;
  1109 
  1110 	//Image range
  1111 	TUint8		 						iSourceRange;
  1112 };    
  1113 
  1114 /**
  1115  * Timer of Posting
  1116  */
  1117 
  1118 class CNGAPostProcTimer: public CTimer
  1119     {
  1120 public:
  1121     static CNGAPostProcTimer* NewL( CNGAPostProcHwDevice& aParent );
  1122     ~CNGAPostProcTimer();
  1123     
  1124 protected:    
  1125     void RunL();
  1126     
  1127 private:
  1128     CNGAPostProcTimer( CNGAPostProcHwDevice& aParent );
  1129     void ConstructL();
  1130     
  1131 private:
  1132     CNGAPostProcHwDevice& iParent;
  1133 };
  1134 
  1135 #endif //__NGAPOSTPROCHWDEVICE_H__
  1136