qtms/src/qtmsmembuffer.cpp
changeset 27 cbb1bfb7ebfb
child 32 edd273b3192a
equal deleted inserted replaced
25:d881023c13eb 27:cbb1bfb7ebfb
       
     1 /*
       
     2  * Copyright (c) 2010 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: QT Bindings for TMS
       
    15  *
       
    16  */
       
    17 
       
    18 #include <qtms.h>
       
    19 #include <qtmsbuffer.h>
       
    20 #include "qtmsmembuffer.h"
       
    21 #include "tmsutility.h"
       
    22 
       
    23 using namespace QTMS;
       
    24 using namespace TMS;
       
    25 
       
    26 QTMSMemBuffer::QTMSMemBuffer() :
       
    27     iBufferSize(0),
       
    28     iTimeStamp(0),
       
    29     iDataPtr(NULL),
       
    30     iOwnsBuffer(FALSE)
       
    31     {
       
    32     }
       
    33 
       
    34 QTMSMemBuffer::~QTMSMemBuffer()
       
    35     {
       
    36     if (iOwnsBuffer)
       
    37         {
       
    38         free(iDataPtr);
       
    39         }
       
    40     }
       
    41 
       
    42 gint QTMSMemBuffer::Create(guint size, QTMSBuffer*& tmsbuffer)
       
    43     {
       
    44     gint ret(TMS_RESULT_INSUFFICIENT_MEMORY);
       
    45     TRACE_PRN_FN_ENT;
       
    46     QTMSMemBuffer* self = new QTMSMemBuffer();
       
    47     if (self)
       
    48         {
       
    49         ret = self->PostConstruct(size);
       
    50         if (ret != TMS_RESULT_SUCCESS)
       
    51             {
       
    52             delete self;
       
    53             self = NULL;
       
    54             }
       
    55         }
       
    56     tmsbuffer = self;
       
    57     TRACE_PRN_FN_EXT;
       
    58     return ret;
       
    59     }
       
    60 
       
    61 gint QTMSMemBuffer::PostConstruct(guint size)
       
    62     {
       
    63     gint ret(TMS_RESULT_SUCCESS);
       
    64     TRACE_PRN_FN_ENT;
       
    65     iDataPtr = (guint8*) malloc(size);
       
    66     if (!iDataPtr)
       
    67         {
       
    68         ret = TMS_RESULT_INSUFFICIENT_MEMORY;
       
    69         }
       
    70     iOwnsBuffer = TRUE;
       
    71     iBufferSize = size;
       
    72     TRACE_PRN_FN_EXT;
       
    73     return ret;
       
    74     }
       
    75 
       
    76 gint QTMSMemBuffer::GetType(QTMSBufferType& buffertype)
       
    77     {
       
    78     gint ret(TMS_RESULT_SUCCESS);
       
    79     buffertype = TMS_BUFFER_MEMORY;
       
    80     return ret;
       
    81     }
       
    82 
       
    83 // Implementation of TMSBuffer interface begins
       
    84 /**
       
    85  Gets the timestamp on the Buffer so that the framework can
       
    86  determine the time at which this buffer has to be rendered
       
    87  by the output device sink.
       
    88 
       
    89  @param ts
       
    90  timestamp in microseconds
       
    91 
       
    92  */
       
    93 gint QTMSMemBuffer::GetTimeStamp(guint64& ts)
       
    94     {
       
    95     gint ret(TMS_RESULT_SUCCESS);
       
    96     ts = iTimeStamp;
       
    97     return ret;
       
    98     }
       
    99 
       
   100 /**
       
   101  Sets the timestamp on the Buffer so that the framework can
       
   102  determine the time at which this buffer has to be rendered
       
   103  by the output device sink.
       
   104 
       
   105  @param ts
       
   106  timestamp in milliseconds
       
   107 
       
   108  */
       
   109 gint QTMSMemBuffer::SetTimeStamp(const guint64 ts)
       
   110     {
       
   111     gint ret(TMS_RESULT_SUCCESS);
       
   112     iTimeStamp = ts;
       
   113     return ret;
       
   114     }
       
   115 
       
   116 /**
       
   117  Gets the size of data in the buffer specified by the client.
       
   118 
       
   119  @param size
       
   120  size of data in bytes
       
   121 
       
   122  */
       
   123 gint QTMSMemBuffer::GetDataSize(guint& size)
       
   124     {
       
   125     gint ret(TMS_RESULT_SUCCESS);
       
   126     size = iBufferSize;
       
   127     return ret;
       
   128     }
       
   129 
       
   130 /**
       
   131  Sets the size of data in the buffer after the client
       
   132  fill it.
       
   133 
       
   134  @param size
       
   135  size of data in bytes
       
   136 
       
   137  */
       
   138 gint QTMSMemBuffer::SetDataSize(const guint size)
       
   139     {
       
   140     gint ret(TMS_RESULT_SUCCESS);
       
   141     iBufferSize = size;
       
   142     return ret;
       
   143     }
       
   144 
       
   145 /**
       
   146  Gets the pointer to the memory location associated with this
       
   147  buffer where the data is stored.
       
   148 
       
   149  @param bufptr
       
   150  ptr to the data stored in the buffer.
       
   151 
       
   152  */
       
   153 gint QTMSMemBuffer::GetDataPtr(guint8*& bufptr)
       
   154     {
       
   155     gint ret(TMS_RESULT_SUCCESS);
       
   156     bufptr = iDataPtr;
       
   157     return ret;
       
   158     }
       
   159