khronosfws/openmax_al/src/mmf_adaptation/xangavideosink.cpp
changeset 53 eabc8c503852
parent 48 a493a607b5bf
equal deleted inserted replaced
48:a493a607b5bf 53:eabc8c503852
     1 /*
       
     2 * Copyright (c) 2009 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 Media Helper Class for handling surface events
       
    19 
       
    20 Shy Ward
       
    21 */
       
    22 
       
    23 #include "xangavideosink.h"
       
    24 #include "openmaxalwrapper.h"
       
    25 
       
    26 
       
    27 CNgaVideoSink* CNgaVideoSink::NewL()
       
    28 {
       
    29 	CNgaVideoSink* self = new CNgaVideoSink();
       
    30 	self->ConstructL();
       
    31 	return self;
       
    32 }
       
    33 
       
    34 CNgaVideoSink::~CNgaVideoSink()
       
    35 {
       
    36     RemoveWindow();
       
    37     
       
    38     delete iMediaClientVideoDisplay;
       
    39     if(IsActive())
       
    40     {
       
    41     Cancel();
       
    42     }	
       
    43 }
       
    44     
       
    45 void CNgaVideoSink::RemoveWindow()
       
    46     {
       
    47     iMediaClientVideoDisplay->RemoveDisplayWindow(*m_pWindow);
       
    48     }
       
    49 
       
    50 CNgaVideoSink::CNgaVideoSink()
       
    51                   :CActive(EPriorityStandard)
       
    52 {
       
    53 	iMediaClientVideoDisplay = NULL;
       
    54   CActiveScheduler::Add(this);
       
    55   m_ThreadHandle.Duplicate(RThread());
       
    56   m_MediaHelperInitialized = EInitializedReady;
       
    57   m_rotation = EVideoRotationNone;
       
    58   m_scaleWidth = (100.0f);
       
    59   m_scaleHeight = (100.0f);
       
    60   m_horizPos = (EHorizontalAlignCenter);
       
    61   m_vertPos = (EVerticalAlignCenter);      
       
    62 }
       
    63 
       
    64 void CNgaVideoSink::RunL()
       
    65 {
       
    66 	  iMediaClientVideoDisplay->SurfaceCreated(m_surfaceId,m_cropRect,m_pixelAspectRatio,m_cropRegion);	
       
    67 }
       
    68 
       
    69 void CNgaVideoSink::Activate()
       
    70 {
       
    71     if(!IsActive())
       
    72     {
       
    73         iStatus = KRequestPending;
       
    74         SetActive();
       
    75     }
       
    76 }
       
    77 
       
    78 void CNgaVideoSink::DoCancel()
       
    79 {
       
    80       if(iStatus.Int() == KRequestPending)
       
    81       {
       
    82           TRequestStatus* pStatus = &iStatus;
       
    83           m_ThreadHandle.RequestComplete(pStatus, KErrCancel);
       
    84     }
       
    85 }
       
    86 
       
    87 void CNgaVideoSink::CompleteRequest(TInt status)
       
    88 {
       
    89     // Checking for IsActive alone results in this block getting executed 
       
    90     // from other thread more thanone time. Hence the chk for iStatus
       
    91     if(IsActive() && iStatus == KRequestPending)
       
    92     {
       
    93         TRequestStatus* pStatus = &iStatus;
       
    94         m_ThreadHandle.RequestComplete(pStatus, status);
       
    95     }
       
    96 }
       
    97 
       
    98 void CNgaVideoSink::SurfaceCreated(int surfaceid0,int surfaceid1,int surfaceid2,int surfaceid3,int crop_rect_tl_x,
       
    99                      									 int crop_rect_tl_y,int crop_rect_br_x,int crop_rect_br_y,int aspect_ratio_num,int aspect_ratio_denom)
       
   100 {
       
   101    
       
   102    m_surfaceId.iInternal[0] = surfaceid0;
       
   103    m_surfaceId.iInternal[1] = surfaceid1;
       
   104    m_surfaceId.iInternal[2] = surfaceid2;
       
   105    m_surfaceId.iInternal[3] = surfaceid3;
       
   106    m_cropRect.iTl.iX = crop_rect_tl_x;
       
   107    m_cropRect.iTl.iY = crop_rect_tl_y;
       
   108    m_cropRect.iBr.iX = crop_rect_br_x;
       
   109    m_cropRect.iBr.iY = crop_rect_br_y;
       
   110    m_pixelAspectRatio.iNumerator = aspect_ratio_num;
       
   111    m_pixelAspectRatio.iDenominator = aspect_ratio_denom;  
       
   112    
       
   113    Activate();
       
   114    CompleteRequest(KErrNone);
       
   115    	
       
   116 }
       
   117 
       
   118 void CNgaVideoSink::ConstructL()
       
   119 {
       
   120 	iMediaClientVideoDisplay = CMediaClientVideoDisplay::NewL(0);
       
   121 	Activate();
       
   122 } 
       
   123 
       
   124 void CNgaVideoSink::SetNativeDisplayInformation(void* display_info)
       
   125 {
       
   126 	//display_info is of type XADataSink
       
   127 	//display_info.pLocator is of type XADataLocator_NativeDisplay
       
   128 	XADataLocator_NativeDisplay* nativeDisplay;
       
   129 	XADataSink* videoSink = (XADataSink*)display_info;
       
   130 	
       
   131 	nativeDisplay = (XADataLocator_NativeDisplay*) (videoSink->pLocator);
       
   132 	//TODO: scrDevice is not been passed Properly
       
   133   // Add the display window
       
   134   m_cropRegion = TRect(((RWindow*)(nativeDisplay->hWindow))->Size());
       
   135   m_videoExtent = TRect(((RWindow*)(nativeDisplay->hWindow))->Size());
       
   136   m_cropRect = TRect(((RWindow*)(nativeDisplay->hWindow))->Size());
       
   137   m_clipRect = TRect(((RWindow*)(nativeDisplay->hWindow))->Size());
       
   138   m_cropRegion = TRect(((RWindow*)(nativeDisplay->hWindow))->Size());
       
   139   m_pWindow = ((RWindow*)(nativeDisplay->hWindow));
       
   140   
       
   141 
       
   142   TRAPD(err, iMediaClientVideoDisplay->AddDisplayWindowL(m_pWindow, m_clipRect, m_cropRegion, m_videoExtent, m_scaleWidth, m_scaleHeight,
       
   143                                                m_rotation, EAutoScaleBestFit, m_horizPos, m_vertPos, m_pWindow));  
       
   144 
       
   145 }
       
   146 
       
   147 extern "C" {
       
   148 
       
   149     void* nga_video_sink_init()
       
   150     { 
       
   151           return CNgaVideoSink::NewL();
       
   152     }
       
   153         
       
   154     void surface_created(void* context,int surfaceid0,int surfaceid1,int surfaceid2,int surfaceid3,int crop_rect_tl_x,
       
   155                          									int crop_rect_tl_y,int crop_rect_br_x,int crop_rect_br_y,int aspect_ratio_num,int aspect_ratio_denom)
       
   156     {
       
   157             ((CNgaVideoSink*)(context))->SurfaceCreated(surfaceid0,surfaceid1,surfaceid2,surfaceid3,crop_rect_tl_x,
       
   158                          									                  crop_rect_tl_y,crop_rect_br_x,crop_rect_br_y,aspect_ratio_num,aspect_ratio_denom);
       
   159     }
       
   160         
       
   161     void  setup_native_display(void* context, void* display_info)
       
   162     {
       
   163             ((CNgaVideoSink*)(context))->SetNativeDisplayInformation(display_info);
       
   164     }
       
   165 
       
   166 }