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