plugins/multimedia/symbian/mmf/mediaplayer/s60mediarecognizer.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "s60mediarecognizer.h"
       
    43 #include <e32def.h>
       
    44 #include <e32cmn.h>
       
    45 #include <QtCore/qurl.h>
       
    46 #include <QtCore/qdir.h>
       
    47 #include <QtCore/qdebug.h>
       
    48 
       
    49 #include <apgcli.h>
       
    50 
       
    51 static const TInt KMimeTypePrefixLength = 6; // "audio/" or "video/"
       
    52 _LIT(KMimeTypePrefixAudio, "audio/");
       
    53 _LIT(KMimeTypePrefixVideo, "video/");
       
    54 
       
    55 S60MediaRecognizer::S60MediaRecognizer(QObject *parent) : QObject(parent)
       
    56 {
       
    57 }
       
    58 
       
    59 S60MediaRecognizer::~S60MediaRecognizer()
       
    60 {
       
    61     m_file.Close();
       
    62     m_fileServer.Close();
       
    63     m_recognizer.Close();
       
    64 }
       
    65 
       
    66 S60MediaRecognizer::MediaType S60MediaRecognizer::mediaType(const QUrl &url)
       
    67 {
       
    68     bool isStream = (url.scheme() == "file")?false:true;
       
    69 
       
    70     if (isStream)
       
    71         return Url;
       
    72     else
       
    73         return identifyMediaType(url.toLocalFile());
       
    74 }
       
    75 
       
    76 S60MediaRecognizer::MediaType S60MediaRecognizer::identifyMediaType(const QString& fileName)
       
    77 {
       
    78     S60MediaRecognizer::MediaType result = Video; // default to videoplayer
       
    79     bool recognizerOpened = false;
       
    80 
       
    81     TInt err = m_recognizer.Connect();
       
    82     if (err == KErrNone) {
       
    83         recognizerOpened = true;
       
    84     }
       
    85 
       
    86     err = m_fileServer.Connect();
       
    87     if (err == KErrNone) {
       
    88         recognizerOpened = true;
       
    89     }
       
    90 
       
    91     // This is needed for sharing file handles for the recognizer
       
    92     err = m_fileServer.ShareProtected();
       
    93     if (err == KErrNone) {
       
    94         recognizerOpened = true;
       
    95     }
       
    96 
       
    97     if (recognizerOpened) {
       
    98         m_file.Close();
       
    99         err = m_file.Open(m_fileServer, QString2TPtrC(QDir::toNativeSeparators(fileName)), EFileRead |
       
   100             EFileShareReadersOnly);
       
   101 
       
   102         if (err == KErrNone) {
       
   103             TDataRecognitionResult recognizerResult;
       
   104             err = m_recognizer.RecognizeData(m_file, recognizerResult);
       
   105             if (err == KErrNone) {
       
   106                 const TPtrC mimeType = recognizerResult.iDataType.Des();
       
   107 
       
   108                 if (mimeType.Left(KMimeTypePrefixLength).Compare(KMimeTypePrefixAudio) == 0) {
       
   109                     result = Audio;
       
   110                 } else if (mimeType.Left(KMimeTypePrefixLength).Compare(KMimeTypePrefixVideo) == 0) {
       
   111                     result = Video;
       
   112                 }
       
   113             }
       
   114         }
       
   115     }
       
   116     return result;
       
   117 }
       
   118 
       
   119 TPtrC S60MediaRecognizer::QString2TPtrC( const QString& string )
       
   120 {
       
   121     // Returned TPtrC is valid as long as the given parameter is valid and unmodified
       
   122     return TPtrC16(static_cast<const TUint16*>(string.utf16()), string.length());
       
   123 }