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