videditor/SimpleCutVideo/inc/VeiSimpleCutVideoContainer.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef VEICUTVIDEOCONTAINER_H
       
    21 #define VEICUTVIDEOCONTAINER_H
       
    22 
       
    23 #include <coecntrl.h>
       
    24 #include <VideoPlayer.h>
       
    25 #include <VedCommon.h>
       
    26 #include <VedMovie.h>
       
    27 #include <aknprogressdialog.h>
       
    28 #include <coedef.h>
       
    29 
       
    30 #include "VeiVideoDisplay.h"
       
    31 #include "VeiImageConverter.h"
       
    32 #include "VeiRemConTarget.h"
       
    33 #include "mveinavipanecontrolobserver.h" 
       
    34 
       
    35 
       
    36 class CVeiSimpleCutVideoView;
       
    37 class CVeiCutterBar;
       
    38 class CAknsBasicBackgroundControlContext;
       
    39 class CVeiErrorUI;
       
    40 class CVeiVideoDisplay;
       
    41 class CVeiTextDisplay;
       
    42 #ifdef RD_TACTILE_FEEDBACK 
       
    43 class MTouchFeedback; 
       
    44 #endif /* RD_TACTILE_FEEDBACK  */
       
    45 
       
    46 //const TInt KMinVolumeLevel = 1;			
       
    47 const TInt KVeiCutBarHeight = 20;
       
    48 const TInt KProgressbarFinalValue = 50;
       
    49 _LIT(KEncoderType, "JPEG" );			// encoder type for image conversion	
       
    50 
       
    51 /**
       
    52  * CVeiSimpleCutVideoContainer container control class.
       
    53  *  
       
    54  * Container for CVeiSimpleCutVideoView.
       
    55  */
       
    56 class CVeiSimpleCutVideoContainer :	public CCoeControl,
       
    57 								public MCoeControlObserver,
       
    58 								public MVedVideoClipFrameObserver,
       
    59 								public MVedVideoClipInfoObserver, 
       
    60 								public MConverterController, 
       
    61 								public MProgressDialogCallback,
       
    62 								public MVeiVideoDisplayObserver,
       
    63 								public MVeiMediakeyObserver,
       
    64 						        public MVeiNaviPaneControlObserver
       
    65     {
       
    66 	public:
       
    67 		/**
       
    68 		 * Edit state.
       
    69 		 */
       
    70 		enum TCutVideoState
       
    71 			{
       
    72 			EStateInitializing = 1,
       
    73 			EStateOpening,
       
    74 			EStateStoppedInitial,
       
    75 			EStateStopped,
       
    76 			EStatePlaying,
       
    77 			EStatePlayingMenuOpen,
       
    78 			EStatePaused,
       
    79 			EStateGettingFrame,
       
    80 			EStateBuffering,
       
    81 			EStateTerminating
       
    82 			};
       
    83 			
       
    84 		/**
       
    85 		 * Start or end mark.
       
    86 		 */
       
    87 		enum TCutMark
       
    88 			{
       
    89 			ENoMark,
       
    90 			EStartMark,
       
    91 			EEndMark,
       
    92 			EPlayHead
       
    93 			};
       
    94 			
       
    95     public:
       
    96 		/**
       
    97 		 * Creates a CVeiSimpleCutVideoContainer object, which will draw itself to aRect.
       
    98 		 *
       
    99 		 * @param aRect Frame rectangle for container.
       
   100 		 * @param aView 
       
   101 		 *
       
   102 		 * @return a pointer to the created instance of CStoryboardContainer
       
   103 		 */
       
   104 		 static CVeiSimpleCutVideoContainer* NewL( const TRect& aRect, CVeiSimpleCutVideoView& aView, CVeiErrorUI& aErrorUI );
       
   105 
       
   106 		/**  
       
   107 		* Creates a CVeiSimpleCutVideoContainer object, which will draw itself to aRect.
       
   108 		* Leaves the created object in the cleanup stack.
       
   109 		*
       
   110 		* @param aRect Frame rectangle for container.
       
   111 		* @param aMovie  movie being edited
       
   112 		*
       
   113 		* @return a pointer to the created instance of CStoryboardContainer
       
   114 		*/
       
   115 		static CVeiSimpleCutVideoContainer* NewLC( const TRect& aRect, CVeiSimpleCutVideoView& aView, CVeiErrorUI& aErrorUI );
       
   116 
       
   117 	     /**
       
   118          * Default constructor.
       
   119 		 *
       
   120          * @param aRect  Frame rectangle for container.
       
   121 		 * @param aView  pointer to the view.
       
   122          */
       
   123         void ConstructL(const TRect& aRect, CVeiSimpleCutVideoView& aView, CVeiErrorUI& aErrorUI );
       
   124 
       
   125         /**
       
   126         * Destructor.
       
   127         */
       
   128         virtual ~CVeiSimpleCutVideoContainer();
       
   129 
       
   130     public: 
       
   131 		/**
       
   132 		 * Takes one thumbnail bitmap from given file.
       
   133 		 *
       
   134 		 * @param aFilename	name of video clip file
       
   135 		 */
       
   136 		void GetThumbL( const TDesC& aFilename );
       
   137 
       
   138 		/**
       
   139 		 * ###Missin' description###
       
   140 		 *
       
   141 		 * @param aState
       
   142 		 */
       
   143 		void SetStateL( CVeiSimpleCutVideoContainer::TCutVideoState aState, TBool aUpdateCBA = ETrue);
       
   144 		/**
       
   145 		 * Starts playing.
       
   146 		 *
       
   147 		 * @param aStartTime
       
   148 		 */
       
   149 		void PlayL( const TDesC& aFilename );
       
   150 		void PlayMarkedL( 	const TDesC& aFilename, 
       
   151 							const TTimeIntervalMicroSeconds& aStartTime, 
       
   152 							const TTimeIntervalMicroSeconds& aEndTime );
       
   153 		/**
       
   154 		 * Stops playing.
       
   155 		 */
       
   156 		void StopL();
       
   157 
       
   158 		/**
       
   159 		 * Pauses playing.
       
   160 		 */
       
   161 		void PauseL( TBool aUpdateCBA = ETrue );
       
   162 
       
   163 		/**
       
   164 		 * Closes the stream.
       
   165 		 */
       
   166 		void CloseStreamL();
       
   167 
       
   168 		/**
       
   169 		 * Returns the playback position.
       
   170 		 *
       
   171 		 * @return  playback position
       
   172 		 */
       
   173 		TTimeIntervalMicroSeconds PlaybackPositionL();
       
   174 
       
   175 		/**
       
   176 		 * Marks the in point.
       
   177 		 */
       
   178 		void MarkedInL();
       
   179 
       
   180 		/**
       
   181 		 * Marks the out point.
       
   182 		 */
       
   183 		void MarkedOutL();
       
   184 
       
   185 		/**
       
   186 		 * Sets cut in time to cut video bar.
       
   187 		 *
       
   188 		 * @param aTime	Cut ín time
       
   189 		 */
       
   190 		void SetInTime( const TTimeIntervalMicroSeconds& aTime );
       
   191 
       
   192 		/**
       
   193 		 * Sets cut out time to cut video bar.
       
   194 		 *
       
   195 		 * @param aTime	Cut out time
       
   196 		 */
       
   197 		void SetOutTime( const TTimeIntervalMicroSeconds& aTime );
       
   198 
       
   199 		/**
       
   200 		* Takes the snapshot from current frame
       
   201 		*/
       
   202 		void TakeSnapshotL();
       
   203 		
       
   204 		void MuteL();
       
   205     public: 
       
   206 	
       
   207 		/**
       
   208 		 * Update function that is called by the static callback method.
       
   209 		 */
       
   210 		void DoUpdate();
       
   211 		// from MVeiVideoDisplayObserver
       
   212 		virtual void NotifyVideoDisplayEvent( const TPlayerEvent aEvent, const TInt& aInfo = 0 );
       
   213 
       
   214 		virtual void NotifyVideoClipFrameCompleted(CVedVideoClipInfo& aInfo, 
       
   215 											   TInt aError, 
       
   216 							 				   CFbsBitmap* aFrame);
       
   217 		/**
       
   218 		 * Called to notify that video clip info is ready
       
   219 		 * for reading.
       
   220 		 *
       
   221 		 * Possible error codes:
       
   222 		 *	- <code>KErrNotFound</code> if there is no file with the specified name
       
   223 		 *    in the specified directory (but the directory exists)
       
   224 		 *	- <code>KErrPathNotFound</code> if the specified directory
       
   225 		 *    does not exist
       
   226 		 *	- <code>KErrUnknown</code> if the specified file is of unknown format
       
   227 		 *
       
   228 		 * @param aInfo   video clip info
       
   229 		 * @param aError  <code>KErrNone</code> if info is ready
       
   230 		 *                for reading; one of the system wide
       
   231 		 *                error codes if reading file failed
       
   232 		 */
       
   233 		virtual void NotifyVideoClipInfoReady(CVedVideoClipInfo& aInfo, 
       
   234 										  TInt aError);
       
   235 		
       
   236        /**
       
   237         * From CCoeControl, OfferKeyEventL.
       
   238 		*
       
   239 		* @param aKeyEvent  key event
       
   240 		* @param aType  event code
       
   241         */
       
   242 		TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
       
   243 
       
   244 		/**
       
   245 		 * From MProgressDialogCallback, DialogDismissedL.
       
   246 		 *
       
   247 		 * @param aButtonId  button id
       
   248 		 */
       
   249 		virtual void DialogDismissedL( TInt aButtonId );
       
   250 
       
   251 		/**
       
   252 		 * Opens a video clip file and initializes videoplayerutility.
       
   253 		 *
       
   254 		 * @param aFilename  file to open
       
   255 		 */
       
   256 		void OpenFileL( const TDesC& aFilename/*, TBool aStartPlaying = EFalse */);
       
   257 		
       
   258 		/**
       
   259 		 * Prepares the control for termination; stops video playback
       
   260 		 * and sets the state to EStateTerminating.
       
   261 		 * 
       
   262 		 */
       
   263 		void PrepareForTerminationL();
       
   264 
       
   265 		// From MConverterController
       
   266 		void NotifyCompletion( TInt aErr );
       
   267 
       
   268 		void ResolveCaptionNameL( TApaAppCaption& aCaption ) const;
       
   269 		
       
   270 		void FocusChanged(TDrawNow aDrawNow);
       
   271     
       
   272 	private: 
       
   273 		/**
       
   274 		 * Callback function for the timer.
       
   275 		 *
       
   276 		 * @param aThis  self pointer
       
   277 		 *
       
   278 		 * @return  dummy value
       
   279 		 */
       
   280 		static TInt DoAudioBarUpdate( TAny* aThis );
       
   281 
       
   282 		/**
       
   283 		* Time increment.
       
   284 		*
       
   285 		* @param aKeyCount number a key events
       
   286 		* @return time 
       
   287 		*/
       
   288 		TInt TimeIncrement( TInt aKeyCount ) const;
       
   289 	
       
   290 		/**
       
   291 		 * Constructor.
       
   292 		 *
       
   293 		 * @param aView	instance of cut video view
       
   294 		 * @param aErrorUI instance of CVeiErrorUI
       
   295 		 */
       
   296 		CVeiSimpleCutVideoContainer( const TRect& aRect, CVeiSimpleCutVideoView& aView, CVeiErrorUI& aErrorUI );
       
   297 
       
   298 		/**
       
   299 		 * Gets intra frame bitmap from video clip.
       
   300 		 *
       
   301 		 * @param aTime	intra frame time.
       
   302 		 */
       
   303 		void GetThumbAtL( const TTimeIntervalMicroSeconds& aTime );
       
   304 
       
   305 		/**
       
   306         * From CoeControl, MopSupplyObject.
       
   307 		*
       
   308 		* @param aId  
       
   309         */
       
   310 		virtual TTypeUid::Ptr MopSupplyObject( TTypeUid aId );
       
   311 
       
   312        /**
       
   313         * From CoeControl, SizeChanged.
       
   314         */
       
   315         void SizeChanged();
       
   316 
       
   317        /**
       
   318         * From CoeControl, CountComponentControls.
       
   319 		* 
       
   320 		* @return  number of component controls in this control
       
   321         */
       
   322         TInt CountComponentControls() const;
       
   323 
       
   324         /**
       
   325         * From CCoeControl, ComponentControl.
       
   326 		*
       
   327 		* @param aIndex  index of the control to return
       
   328         */
       
   329         CCoeControl* ComponentControl(TInt aIndex) const;
       
   330 
       
   331         /**
       
   332         * From CCoeControl,Draw.
       
   333 		*
       
   334 		* @param aRect  region of the control to be redrawn
       
   335         */
       
   336         void Draw(const TRect& aRect) const;
       
   337 
       
   338         /**
       
   339          * From CCoeControl, gets the control's help context. Associates the
       
   340          * control with a particular Help file and topic in a context sensitive
       
   341          * application.
       
   342          *
       
   343          * @param aContext Control's help context.
       
   344          */
       
   345         void GetHelpContext( TCoeHelpContext& aContext ) const;
       
   346 
       
   347        /**
       
   348         * From CCoeControl, HandleControlEventL
       
   349         */
       
   350         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
       
   351 
       
   352 	    /**
       
   353 	    * HandlePointerEventL
       
   354 	    * Handles pen inputs
       
   355 	    *
       
   356 	    * @param aPointerEvent  pointer event
       
   357 	    */
       
   358 	    void HandlePointerEventL(const TPointerEvent& aPointerEvent );
       
   359 
       
   360 		/**
       
   361 		* Handles progress bar touch events
       
   362 		* @param aPBRect Current progress bar rectangle 
       
   363 		* @param aPressedPoint The x coordinate value that was pressed
       
   364 		* 			inside the progress bar
       
   365 		* @param aDragMarks ETrue if the user drags start or end marks.
       
   366 		*					EFalse otherwise
       
   367 		*/
       
   368 		void HandleProgressBarTouchL( TRect aPBRect, TInt aPressedPoint, TBool aDragMarks, CVeiSimpleCutVideoContainer::TCutMark aCutMark = ENoMark );
       
   369 
       
   370 		/**
       
   371 		* Rounds the parameter value to nearest second value
       
   372 		* @param aMicroSecs Time value in microseconds
       
   373 		* @return Rounded value in seconds
       
   374 		*/
       
   375 		TInt RoundMicroSecsToSecs( TTimeIntervalMicroSeconds aMicroSecs );
       
   376 
       
   377 		/*
       
   378 		* Indicates ProgressNote. 
       
   379 		*
       
   380 		*/
       
   381 		void ShowProgressNoteL();
       
   382 
       
   383 		/**
       
   384 		 * Shows information note with given message.
       
   385 		 * 
       
   386 		 * @param aMessage message to show.
       
   387 		 */
       
   388 		void ShowInformationNoteL( const TDesC& aMessage ) const;
       
   389 
       
   390 		/**
       
   391         * The entity of ProgressCallBackL() function
       
   392         * @return 0 when work is done, otherwise return 1.
       
   393         */
       
   394         TInt UpdateProgressNote();
       
   395 
       
   396 		/**
       
   397 		* Saves snapshot.
       
   398 		*/
       
   399 		void SaveSnapshotL();
       
   400 
       
   401 		/**
       
   402 		* Cancels saving of the snapshot.
       
   403 		*/
       
   404 		void CancelSnapshotSave();				
       
   405 		
       
   406 		void StopProgressDialog();
       
   407 		
       
   408 		void ShowGlobalErrorNote(const TInt aErr);
       
   409 
       
   410 		/**	HandleVolumeUpL 
       
   411 		*
       
   412 		*   @see MVeiMediakeyObserver
       
   413 		*/
       
   414 		virtual void HandleVolumeUpL();	
       
   415 		
       
   416 		/**
       
   417 		* From MVeiNaviPaneControlObserver
       
   418 		*/
       
   419 		void SetVolumeLevelL( TInt aVolume );			
       
   420 
       
   421 		/**	HandleVolumeDownL 
       
   422 		*
       
   423 		*   @see MVeiMediakeyObserver
       
   424 		*/
       
   425 		virtual void HandleVolumeDownL();
       
   426 		
       
   427 		/** Callback function */
       
   428 		static TInt AsyncTakeSnapshot(TAny* aThis);
       
   429 		/** Callback function */
       
   430 		static TInt AsyncSaveSnapshot(TAny* aThis);
       
   431 		
       
   432 	    /**	LaunchSavingDialogsL
       
   433 		*   
       
   434 		*	Displays Avkon file handling queries
       
   435 		*
       
   436 		* 	@param 
       
   437 		*   @return ETrue if a file name is successfully created
       
   438 		*			EFalse otherwise	 
       
   439 		*	
       
   440 		*/		
       
   441 		TBool LaunchSavingDialogsL();
       
   442 
       
   443 	protected:		
       
   444 		// implementation
       
   445 	    void HandleVideoClickedL();
       
   446 
       
   447     private: //data
       
   448 		/** cut video view */
       
   449 		CVeiSimpleCutVideoView& iView;
       
   450 
       
   451 		/** Error UI */
       
   452 		CVeiErrorUI&	iErrorUI;
       
   453 
       
   454 		/** Video clip info*/
       
   455 		CVedVideoClipInfo*	iVideoClipInfo;
       
   456 
       
   457 		/** Current state. */
       
   458 		TCutVideoState iState;
       
   459 		
       
   460 		/** Previous state. */
       
   461 		TCutVideoState iPreviousState;
       
   462 
       
   463 		/** Previous state. */
       
   464 		TCutVideoState iPrevState;
       
   465 
       
   466 		/** cut video bar. */
       
   467 		CVeiCutterBar* iCutVideoBar;
       
   468 
       
   469 		/** Last position. */
       
   470 		TTimeIntervalMicroSeconds iLastPosition; 
       
   471 
       
   472 		/** Video clip duration */
       
   473 		TTimeIntervalMicroSeconds iDuration;
       
   474 
       
   475 		/**
       
   476 		 * Control context that provides a layout background with a 
       
   477 		 * background bitmap and its layout rectangle.
       
   478 		 */
       
   479 		CAknsBasicBackgroundControlContext*	iBgContext;
       
   480 
       
   481 		/** Key repeat count in seek function. */
       
   482 		TInt iKeyRepeatCount;
       
   483 
       
   484 		/** Seek thumbnail position in video clip. */
       
   485 		TTimeIntervalMicroSeconds iSeekPos;
       
   486 
       
   487 		/** Seek - flag. */
       
   488 		TBool iSeeking;
       
   489 
       
   490 		/** Frame ready - flag */
       
   491 		TBool iFrameReady;
       
   492 
       
   493 		/** Last keycode, used in OfferKeyEventL(); */
       
   494 		TUint iLastKeyCode;
       
   495 
       
   496 		/** The actuall calls to ICL are done from this image converter. */
       
   497 		CVeiImageConverter* iConverter;
       
   498 		
       
   499 		//** Whether we need to take snapshot. */
       
   500 		TBool iTakeSnapshot;
       
   501 
       
   502 		/** Progress dialog */
       
   503 		CAknProgressDialog* iProgressDialog;
       
   504 
       
   505 		HBufC*	            iSaveToFileName;	        
       
   506 		TSize               iFrameSize;
       
   507 		CPeriodic*	        iVideoBarTimer;
       
   508 		CVeiVideoDisplay*	iVideoDisplay;
       
   509 		TRect				iDisplayRect;
       
   510 		TRect				iCutTimeDisplayRect;
       
   511 		CVeiTextDisplay*	iCutTimeDisplay;
       
   512 		TBool				iPlayOrPlayMarked;
       
   513 		
       
   514 		TRect				iIconDisplayRect;
       
   515 		CFbsBitmap*			iPauseBitmap;
       
   516 		CFbsBitmap*			iPauseBitmapMask;
       
   517 		CFbsBitmap*			iPlayBitmap;
       
   518 		CFbsBitmap*			iPlayBitmapMask;
       
   519 		
       
   520 		/** Callback utility */
       
   521 		CAsyncCallBack* 	iCallBackSaveSnapshot;
       
   522 		CAsyncCallBack* 	iCallBackTakeSnapshot;
       
   523 
       
   524 		/** Remote connection API used to handle the volume keys. */
       
   525 		CVeiRemConTarget* 	iRemConTarget;
       
   526 		
       
   527 		TBool 				iTakeSnapshotWaiting;
       
   528 
       
   529 		/** ETrue if user is dragging the start or end mark with a pen,
       
   530 			EFalse otherwise */
       
   531 		TBool iIsMarkDrag;
       
   532 		
       
   533 		/** ETrue if the pen is in start or end mark area when it goes down,
       
   534 			EFalse otherwise */		
       
   535 		TBool iIsMarkTapped;
       
   536 		
       
   537 		/** ETrue if the pen is in display area or in play/pause button area 
       
   538 		    when it goes down, EFalse otherwise */
       
   539 		TBool iIsIconOrDisplayTapped;
       
   540 		
       
   541 		/** Indicates which mark the user has tapped */						
       
   542 		TCutMark iTappedMark;
       
   543 		
       
   544 		/// Point where button down event has occured.
       
   545 		TPoint iButtonDownPoint;
       
   546         
       
   547 		/** File name that is used when saving the snapshot */						        
       
   548         TFileName           iSnapshotFileName; 
       
   549 		
       
   550     	// Feedback for screen touch:
       
   551 #ifdef RD_TACTILE_FEEDBACK 
       
   552 		MTouchFeedback* iTouchFeedBack;
       
   553 #endif /* RD_TACTILE_FEEDBACK  */ 
       
   554 
       
   555 #include "veicutvideocontainer.inl"
       
   556 
       
   557     };
       
   558 #endif
       
   559 
       
   560 // End of File