internal/gstplayer/src/GSTPlayerappui.cpp
changeset 14 32e421e6175c
child 16 8e837d1bf446
equal deleted inserted replaced
2:5505e8908944 14:32e421e6175c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
     3 *
       
     4 * This library is free software; you can redistribute it and/or
       
     5 * modify it under the terms of the GNU Lesser General Public
       
     6 * License as published by the Free Software Foundation; either
       
     7 * version 2 of the License, or (at your option) any later version.
       
     8 *
       
     9 * This library is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12 * Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public
       
    15 * License along with this library; if not, write to the
       
    16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    17 * Boston, MA 02111-1307, USA.
       
    18 *
       
    19 * Description:
       
    20 *
       
    21 */
       
    22 /*
       
    23 * ==============================================================================
       
    24 *  Name        : gstplayerappui.cpp
       
    25 *  Part of     : gstplayer
       
    26 *  Interface   : 
       
    27 *  Description : 
       
    28 *  Version     : 
       
    29 *
       
    30 
       
    31 * ==============================================================================
       
    32 */
       
    33 
       
    34 // INCLUDE FILES
       
    35 #include <avkon.hrh>
       
    36 #include <aknnotewrappers.h>
       
    37 #include <stringloader.h>
       
    38 #include <GSTPlayer.rsg>
       
    39 #include <CAknMemorySelectionDialog.h>
       
    40 #include <f32file.h>
       
    41 #include <s32file.h>
       
    42 #include <PathInfo.h>
       
    43 #include <gst/gst.h>
       
    44 
       
    45 #include "GSTPlayer.pan"
       
    46 #include "GSTPlayerAppUi.h"
       
    47 #include "GSTPlayerAppView.h"
       
    48 #include "GSTPlayer.hrh"
       
    49 
       
    50 #include "GlibEventHandler.h"
       
    51 #include "gstreamer.h"
       
    52 
       
    53 TFileName fileName;
       
    54 
       
    55 _LIT( KHelloFileName, "\\private\\A000017F\\Hello.txt" );
       
    56 _LIT( KHelloText, "HELLO WORLD!");
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CGSTPlayerAppUi::ConstructL()
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CGSTPlayerAppUi::ConstructL()
       
    67     {
       
    68     // Initialise app UI with standard value.
       
    69     BaseConstructL(CAknAppUi::EAknEnableSkin);
       
    70     // Here the Hello.txt file can be created, if it is not copied automatically.
       
    71     /*
       
    72      RFs fsSession;
       
    73      User::LeaveIfError(fsSession.Connect());            
       
    74 
       
    75      RFile file;
       
    76      
       
    77      // Create a file to write the text to       
       
    78      if ( file.Replace(fsSession, KHelloFileName, EFileWrite ) != KErrNone )
       
    79      {
       
    80      return;
       
    81      }
       
    82      CleanupClosePushL( file );            
       
    83      
       
    84      RFileWriteStream outputFileStream( file );
       
    85      CleanupClosePushL( outputFileStream );
       
    86      outputFileStream << KHelloText;
       
    87 
       
    88      CleanupStack::PopAndDestroy(2); // file, outputFileStream
       
    89 
       
    90      fsSession.Close();	
       
    91      */
       
    92 
       
    93     // Create view object
       
    94     iAppView = CGSTPlayerAppView::NewL(ClientRect() );
       
    95 
       
    96     iGstView = iAppView;
       
    97 
       
    98     }
       
    99 // -----------------------------------------------------------------------------
       
   100 // CGSTPlayerAppUi::CGSTPlayerAppUi()
       
   101 // C++ default constructor can NOT contain any code, that might leave.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CGSTPlayerAppUi::CGSTPlayerAppUi()
       
   105     {
       
   106     // No implementation required
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CGSTPlayerAppUi::~CGSTPlayerAppUi()
       
   111 // Destructor.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CGSTPlayerAppUi::~CGSTPlayerAppUi()
       
   115     {
       
   116 
       
   117     if (iAppView)
       
   118         {
       
   119         delete iAppView;
       
   120         iAppView = NULL;
       
   121         }
       
   122 
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CGSTPlayerAppUi::HandleCommandL()
       
   127 // Takes care of command handling.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CGSTPlayerAppUi::HandleCommandL(TInt aCommand)
       
   131     {
       
   132     switch (aCommand)
       
   133         {
       
   134         case EEikCmdExit:
       
   135         case EAknSoftkeyExit:
       
   136             if (pipeline!=NULL && pipeline ->current_state
       
   137                     == GST_STATE_PLAYING)
       
   138                 {
       
   139 
       
   140                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   141                 gst_object_unref(GST_OBJECT (pipeline));
       
   142 
       
   143                 }
       
   144             Exit();
       
   145             break;
       
   146 
       
   147         case EGSTPlayerNewSong:
       
   148             {
       
   149             /*TDes& aPath;
       
   150              TBool aMemoryCardStorageAllowed;*/
       
   151             if (pipeline!=NULL && pipeline ->current_state
       
   152                     == GST_STATE_PLAYING)
       
   153                 {
       
   154 
       
   155                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   156                 gst_object_unref(GST_OBJECT (pipeline));
       
   157 
       
   158                 }
       
   159             CAknMemorySelectionDialog* memoryDialog =
       
   160                     CAknMemorySelectionDialog::NewL(ECFDDialogTypeSave, 
       
   161                     R_MUSICSHOP_MEMORY_SELECTION_DIALOG, EFalse);
       
   162             CleanupStack::PushL(memoryDialog);
       
   163 
       
   164             CAknMemorySelectionDialog::TMemory
       
   165                     mem(CAknMemorySelectionDialog::EPhoneMemory);
       
   166             TFileName ignore;
       
   167             //TFileName path;
       
   168             if (! (memoryDialog->ExecuteL(mem, &fileName, &ignore) ))
       
   169                 {
       
   170                 // User dnt select the memory location.
       
   171                 //	retVal = EFalse;
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 //aPath.Copy( path );
       
   176                 }
       
   177             CleanupStack::PopAndDestroy(); // memoryDialog        
       
   178 
       
   179 
       
   180             //if user has pressed cancel button, then just return
       
   181             if (!ShowDirListL(fileName))
       
   182                 {
       
   183                 return;
       
   184                 } //end if
       
   185             if (GstreamerNew(fileName) == -1)
       
   186                 {
       
   187                 // Load a string from the resource file and display it
       
   188                 HBufC* textResource =
       
   189                         StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT);
       
   190                 CAknInformationNote* informationNote;
       
   191 
       
   192                 informationNote = new ( ELeave ) CAknInformationNote;
       
   193 
       
   194                 // Show the information Note with
       
   195                 // textResource loaded with StringLoader.
       
   196                 informationNote->ExecuteLD( *textResource);
       
   197 
       
   198                 // Pop HBuf from CleanUpStack and Destroy it.
       
   199                 CleanupStack::PopAndDestroy(textResource);
       
   200 
       
   201                 }
       
   202 
       
   203             }
       
   204             break;
       
   205         case EGSTPlayerPlay:
       
   206             if (pipeline!=NULL && pipeline ->current_state
       
   207                     == GST_STATE_PLAYING)
       
   208                 {
       
   209 
       
   210                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   211                 //gst_object_unref (GST_OBJECT (pipeline));  			 	
       
   212 
       
   213                 }
       
   214             if (GstreamerNew(fileName) == -1)
       
   215                 {
       
   216                 // Load a string from the resource file and display it
       
   217                 HBufC* textResource =
       
   218                         StringLoader::LoadLC( R_HEWB_COMMAND2_TEXT);
       
   219                 CAknInformationNote* informationNote;
       
   220 
       
   221                 informationNote = new ( ELeave ) CAknInformationNote;
       
   222 
       
   223                 // Show the information Note with
       
   224                 // textResource loaded with StringLoader.
       
   225                 informationNote->ExecuteLD( *textResource);
       
   226 
       
   227                 // Pop HBuf from CleanUpStack and Destroy it.
       
   228                 CleanupStack::PopAndDestroy(textResource);
       
   229 
       
   230                 }
       
   231 
       
   232             break;
       
   233         case EGSTPlayerStop:
       
   234             if (pipeline!=NULL)
       
   235                 {
       
   236 
       
   237                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   238                 gst_object_unref (GST_OBJECT (pipeline));  			 	
       
   239                 pipeline = NULL;
       
   240                 }
       
   241             break;
       
   242         case EGSTRecorderStop:
       
   243             if (pipeline!=NULL)
       
   244                 {
       
   245                 gst_element_send_event (pipeline, gst_event_new_eos ());
       
   246                 }
       
   247             break;
       
   248             
       
   249         case EGSTPlayerPause:
       
   250                    if (pipeline!=NULL )
       
   251                        {
       
   252 
       
   253                        gst_element_set_state(pipeline, GST_STATE_PAUSED);
       
   254                        //gst_object_unref (GST_OBJECT (pipeline));                 
       
   255 
       
   256                        }
       
   257                    break;    
       
   258                    
       
   259         case EGSTPlayerResume:
       
   260                if (pipeline!=NULL)
       
   261                    {
       
   262 
       
   263                    gst_element_set_state(pipeline, GST_STATE_PLAYING);
       
   264                    //gst_object_unref (GST_OBJECT (pipeline));                 
       
   265 
       
   266                    }
       
   267                break;               
       
   268 
       
   269         case EGSTPlayerRecordWav:
       
   270             {
       
   271             if (pipeline!=NULL && pipeline ->current_state
       
   272                     == GST_STATE_PLAYING)
       
   273                 {
       
   274 
       
   275                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   276                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   277 
       
   278                 }
       
   279             gst_record_wav();
       
   280             }
       
   281             break;
       
   282 
       
   283         case EGSTPlayerRecordRaw:
       
   284             {
       
   285             if (pipeline!=NULL && pipeline ->current_state
       
   286                     == GST_STATE_PLAYING)
       
   287                 {
       
   288 
       
   289                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   290                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   291 
       
   292                 }
       
   293             gst_record_raw();
       
   294             }
       
   295             break;
       
   296         
       
   297         case EGSTPlayerRecordAmr:
       
   298             {
       
   299             if (pipeline!=NULL && pipeline ->current_state
       
   300                     == GST_STATE_PLAYING)
       
   301                 {
       
   302 
       
   303                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   304                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   305 
       
   306                 }
       
   307             gst_record_amr();
       
   308             }
       
   309             break;
       
   310 
       
   311         case EGSTPlayerRecordG711:
       
   312             {
       
   313             if (pipeline!=NULL && pipeline ->current_state
       
   314                     == GST_STATE_PLAYING)
       
   315                 {
       
   316 
       
   317                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   318                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   319 
       
   320                 }
       
   321             gst_record_g711();
       
   322             }
       
   323             break;
       
   324         case EGSTPlayerRecordG729:
       
   325             {
       
   326             if (pipeline!=NULL && pipeline ->current_state
       
   327                     == GST_STATE_PLAYING)
       
   328                 {
       
   329 
       
   330                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   331                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   332 
       
   333                 }
       
   334             gst_record_g729();
       
   335             }
       
   336             break;
       
   337         case EGSTPlayerRecordIlbc:
       
   338             {
       
   339             if (pipeline!=NULL && pipeline ->current_state
       
   340                     == GST_STATE_PLAYING)
       
   341                 {
       
   342 
       
   343                 gst_element_set_state(pipeline, GST_STATE_NULL);
       
   344                 //gst_object_unref (GST_OBJECT (pipeline));                 
       
   345 
       
   346                 }
       
   347             gst_record_ilbc();
       
   348             }
       
   349             break;
       
   350             
       
   351         case EGSTPlayerCurrentVolume:
       
   352             gst_current_volume();
       
   353             break;
       
   354         case EGSTPlayerMaxVolume:
       
   355             gst_max_volume();
       
   356             break;
       
   357         case EGSTPlayerVolumeUp:
       
   358             gst_volume_up();
       
   359             break;
       
   360         case EGSTPlayerVolumeDown:
       
   361             gst_volume_down();
       
   362             break;
       
   363         case EGSTPlayerLeftBalance:
       
   364         case EGSTPlayerRightBalance:    
       
   365               gst_balance();
       
   366               break;
       
   367         case EGSTPlayerCurrentGain:
       
   368              gst_current_gain();
       
   369              break;
       
   370          case EGSTPlayerMaxGain:
       
   371              gst_max_gain();
       
   372              break;
       
   373          case EGSTPlayerGainUp:
       
   374              gst_gain_up();
       
   375              break;
       
   376          case EGSTPlayerGainDown:
       
   377              gst_gain_down();
       
   378              break;      
       
   379         case EGSTPlayerSamplesPlayed:
       
   380             samplesplayed();
       
   381             break;
       
   382         case EGSTPlayerSamplesRecorded:
       
   383              samplesrecorded();
       
   384              break;    
       
   385         case EGSTPlayerSinkPadCaps:
       
   386             getsinkpadcaps();
       
   387             break;
       
   388         case EGSTPlayerSrcPadCaps:
       
   389             getsrcpadcaps();
       
   390             break;
       
   391         case EGSTPlayerNegotiatedSinkCaps:
       
   392             negotiatedsinkcaps();
       
   393             break;
       
   394         case EGSTPlayerNegotiatedSrcCaps:
       
   395              negotiatedsrccaps();
       
   396              break;    
       
   397         default:
       
   398             Panic(EGSTPlayerUi);
       
   399             break;
       
   400         }
       
   401     }
       
   402 // -----------------------------------------------------------------------------
       
   403 //  Called by the framework when the application status pane
       
   404 //  size is changed.  Passes the new client rectangle to the
       
   405 //  AppView
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void CGSTPlayerAppUi::HandleStatusPaneSizeChange()
       
   409     {
       
   410     iAppView->SetRect(ClientRect() );
       
   411 
       
   412     }
       
   413 
       
   414 TBool CGSTPlayerAppUi::ShowDirListL(TFileName &filePath)
       
   415     {
       
   416 
       
   417     _LIT(KDialogTitle, "Select File");
       
   418 
       
   419     TBool ret = CAknFileSelectionDialog::RunDlgLD(filePath, // on return, contains the selected file's name
       
   420             PathInfo::PhoneMemoryRootPath(), // default root path for browsing
       
   421             KDialogTitle, // Dialog's title
       
   422             0 // Pointer to class implementing 
       
   423             // MAknFileSelectionObserver. OkToExitL is called
       
   424             // when user has selected an file.
       
   425             );
       
   426 
       
   427     return ret;
       
   428 
       
   429     }
       
   430 
       
   431 void ShowNoteL()
       
   432     {
       
   433     // Load a string from the resource file and display it
       
   434     HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT);
       
   435     CAknInformationNote* informationNote;
       
   436 
       
   437     informationNote = new ( ELeave ) CAknInformationNote;
       
   438 
       
   439     // Show the information Note with
       
   440     // textResource loaded with StringLoader.
       
   441     informationNote->ExecuteLD( *textResource);
       
   442 
       
   443     // Pop HBuf from CleanUpStack and Destroy it.
       
   444     CleanupStack::PopAndDestroy(textResource);
       
   445     }
       
   446 // End of File
       
   447