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