    

 ## On this page

  

 

 # shared\_memory\_image\_client\_python

 Last update: 16.07.2025 

[Go to the documentation of this file.](shared__memory__image__client__python_8c.xhtml)<a id="l00001" name="l00001"></a> 1/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

<a id="l00002" name="l00002"></a> 2 \*

<a id="l00003" name="l00003"></a> 3 \* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

<a id="l00004" name="l00004"></a> 4 \* Copyright 2020 ANSYS Inc.

<a id="l00005" name="l00005"></a> 5 \* All Rights Reserved.

<a id="l00006" name="l00006"></a> 6 \*

<a id="l00007" name="l00007"></a> 7 \* Restricted Rights Legend

<a id="l00008" name="l00008"></a> 8 \*

<a id="l00009" name="l00009"></a> 9 \* Government is subject to restrictions as

<a id="l00010" name="l00010"></a> 10 \* set forth in subdivision \[(b)(3)(ii)\] of

<a id="l00011" name="l00011"></a> 11 \* the Rights in Technical Data and Computer

<a id="l00012" name="l00012"></a> 12 \* Software clause at 52.227-7013.

<a id="l00013" name="l00013"></a> 13 \* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

<a id="l00014" name="l00014"></a> 14 \*

<a id="l00015" name="l00015"></a> 15 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

<a id="l00016" name="l00016"></a> 16 

<a id="l00017" name="l00017"></a> 17/\* Warning this is a HACK to get around Python issues mixing debug modules with

<a id="l00018" name="l00018"></a> 18 \* release Python builds. \*/

<a id="l00019" name="l00019"></a> 19 

<a id="l00020" name="l00020"></a> 20\#ifdef \_DEBUG

<a id="l00021" name="l00021"></a> 21\#undef \_DEBUG

<a id="l00022" name="l00022"></a> 22\#include &lt;Python.h&gt;

<a id="l00023" name="l00023"></a> 23\#define \_DEBUG

<a id="l00024" name="l00024"></a> 24\#else

<a id="l00025" name="l00025"></a> 25\#include &lt;Python.h&gt;

<a id="l00026" name="l00026"></a> 26\#endif

<a id="l00027" name="l00027"></a> 27 

<a id="l00028" name="l00028"></a> 28\#include "[shared\_memory\_image\_client\_priv.h](shared__memory__image__client__priv_8h.xhtml)"

<a id="l00029" name="l00029"></a> 29 

<a id="l00030" name="l00030"></a>[ 30](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)\#define MAX\_STREAMS 50 

<a id="l00031" name="l00031"></a> 31static [SharedMemoryImageStream](shared__memory__image__client_8h.xhtml#af5b8eb2ae90823f10e9a17698ea80749) streamlist[[MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)] = { 0 }; 

<a id="l00080" name="l00080"></a> 80\#ifdef DOXYGEN

<a id="l00095" name="l00095"></a>[ 95](shared__memory__image__client__python_8c.xhtml#a68584fd5e8630714c738fc30ad19fa03)stream_id [stream\_create](shared__memory__image__client__python_8c.xhtml#a68584fd5e8630714c738fc30ad19fa03)(str filename, int options=[IMAGESTREAM\_OPTIONS\_NONE](shared__memory__image__client_8h.xhtml#a7fbe522f7a46875a755f07c8ff69e2df));

<a id="l00096" name="l00096"></a> 96 

<a id="l00107" name="l00107"></a>[ 107](shared__memory__image__client__python_8c.xhtml#ac78db99f06d47f7718fdcac4ae3cc374)frame [stream\_lock](shared__memory__image__client__python_8c.xhtml#ac78db99f06d47f7718fdcac4ae3cc374)(stream_id id);

<a id="l00108" name="l00108"></a> 108 

<a id="l00119" name="l00119"></a>[ 119](shared__memory__image__client__python_8c.xhtml#a233ea80003a929e8e60aabd26a3b5c5e)[SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_unlock](shared__memory__image__client__python_8c.xhtml#a233ea80003a929e8e60aabd26a3b5c5e)(stream_id id);

<a id="l00120" name="l00120"></a> 120 

<a id="l00129" name="l00129"></a>[ 129](shared__memory__image__client__python_8c.xhtml#af656cd2bf739307f1d52221d49da37ae)[SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_destroy](shared__memory__image__client__python_8c.xhtml#af656cd2bf739307f1d52221d49da37ae)(stream_id id);

<a id="l00130" name="l00130"></a> 130 

<a id="l00145" name="l00145"></a>[ 145](shared__memory__image__client__python_8c.xhtml#a23b3d9929aaff2a388402452ce5228c1)[SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_putframe](shared__memory__image__client__python_8c.xhtml#a23b3d9929aaff2a388402452ce5228c1)(stream_id id, int width, int height, int framenumber, bytes pixeldata);

<a id="l00146" name="l00146"></a> 146 

<a id="l00147" name="l00147"></a> 147\#endif

<a id="l00148" name="l00148"></a> 148 

<a id="l00149" name="l00149"></a> 149/\* Utility functions PyDict\_SetItemString with DECREF \*/

<a id="l00150" name="l00150"></a> 150static int PyDict_SetItemString_DECREF(PyObject *dict, const char *key, PyObject *val)

<a id="l00151" name="l00151"></a> 151{

<a id="l00152" name="l00152"></a> 152 int ret = PyDict_SetItemString(dict, key, val);

<a id="l00153" name="l00153"></a> 153 if (ret == 0) Py_DECREF(val);

<a id="l00154" name="l00154"></a> 154 return(ret);

<a id="l00155" name="l00155"></a> 155}

<a id="l00156" name="l00156"></a> 156 

<a id="l00157" name="l00157"></a> 157// Given an error code, return the code or raise an exception

<a id="l00158" name="l00158"></a> 158static PyObject *return_error(int err)

<a id="l00159" name="l00159"></a> 159{

<a id="l00160" name="l00160"></a> 160 if (err &gt;= [IMAGESTREAM\_NOERROR](shared__memory__image__client_8h.xhtml#af995dd87ffd7dd178eef1d343f7b72bf)) {

<a id="l00161" name="l00161"></a> 161 return PyLong_FromLong(err);

<a id="l00162" name="l00162"></a> 162 }

<a id="l00163" name="l00163"></a> 163 PyErr_SetString(PyExc_RuntimeError, [SharedMemoryImageStream\_errorstring](shared__memory__image__client_8h.xhtml#a16abb961cf38273321e81cc64d71fad7)(err));

<a id="l00164" name="l00164"></a> 164 return NULL;

<a id="l00165" name="l00165"></a> 165}

<a id="l00166" name="l00166"></a> 166 

<a id="l00167" name="l00167"></a> 167static PyObject *Py_stream_create(PyObject *self, PyObject *args, PyObject *keywds)

<a id="l00168" name="l00168"></a> 168{

<a id="l00169" name="l00169"></a> 169 char *filename = NULL;

<a id="l00170" name="l00170"></a> 170 uint32_t options = 0;

<a id="l00171" name="l00171"></a> 171 static const char *kwlist[] = { "filename", "options", NULL };

<a id="l00172" name="l00172"></a> 172 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"s|i", (char **)kwlist,

<a id="l00173" name="l00173"></a> 173 &amp;filename, &amp;options)) return NULL;

<a id="l00174" name="l00174"></a> 174 int32_t stream_id = -1;

<a id="l00175" name="l00175"></a> 175 for (int i = 0; i &lt; [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9); i++) {

<a id="l00176" name="l00176"></a> 176 if (!streamlist[i]) {

<a id="l00177" name="l00177"></a> 177 stream_id = i;

<a id="l00178" name="l00178"></a> 178 }

<a id="l00179" name="l00179"></a> 179 }

<a id="l00180" name="l00180"></a> 180 if (stream_id == -1) {

<a id="l00181" name="l00181"></a> 181 PyErr_SetString(PyExc_RuntimeError, "Maximum number of simultaneous streams open");

<a id="l00182" name="l00182"></a> 182 return NULL;

<a id="l00183" name="l00183"></a> 183 }

<a id="l00184" name="l00184"></a> 184 [SharedMemoryImageStream](shared__memory__image__client_8h.xhtml#af5b8eb2ae90823f10e9a17698ea80749) stream;

<a id="l00185" name="l00185"></a> 185 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) err = [SharedMemoryImageStream\_create](shared__memory__image__client_8h.xhtml#a03ba052ae823b3e39fef153db8f03ea2)(filename, options, &amp;stream);

<a id="l00186" name="l00186"></a> 186 if (err != [IMAGESTREAM\_NOERROR](shared__memory__image__client_8h.xhtml#af995dd87ffd7dd178eef1d343f7b72bf)) {

<a id="l00187" name="l00187"></a> 187 return return_error(err);

<a id="l00188" name="l00188"></a> 188 }

<a id="l00189" name="l00189"></a> 189 streamlist[stream_id] = stream;

<a id="l00190" name="l00190"></a> 190 return PyLong_FromLong(stream_id);

<a id="l00191" name="l00191"></a> 191}

<a id="l00192" name="l00192"></a> 192 

<a id="l00193" name="l00193"></a> 193static PyObject *Py_stream_lock(PyObject *self, PyObject *args, PyObject *keywds)

<a id="l00194" name="l00194"></a> 194{

<a id="l00195" name="l00195"></a> 195 int32_t stream_id = -1;

<a id="l00196" name="l00196"></a> 196 static const char *kwlist[] = { "stream\_id", NULL };

<a id="l00197" name="l00197"></a> 197 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"i", (char **)kwlist,

<a id="l00198" name="l00198"></a> 198 &amp;stream_id)) return NULL;

<a id="l00199" name="l00199"></a> 199 if ((stream_id &lt; 0) || (stream_id &gt;= [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)) || !streamlist[stream_id]) {

<a id="l00200" name="l00200"></a> 200 PyErr_SetString(PyExc_RuntimeError, "Unknown stream id");

<a id="l00201" name="l00201"></a> 201 return NULL;

<a id="l00202" name="l00202"></a> 202 }

<a id="l00203" name="l00203"></a> 203 [SharedMemoryFrame](struct___shared_memory_frame.xhtml) frame;

<a id="l00204" name="l00204"></a> 204 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) err = [SharedMemoryImageStream\_lock](shared__memory__image__client_8h.xhtml#afefb8f5297147640b46d1f9eb1e77c9e)(streamlist[stream_id], &amp;frame);

<a id="l00205" name="l00205"></a> 205 if (err != [IMAGESTREAM\_NOERROR](shared__memory__image__client_8h.xhtml#af995dd87ffd7dd178eef1d343f7b72bf)) {

<a id="l00206" name="l00206"></a> 206 return return_error(err);

<a id="l00207" name="l00207"></a> 207 }

<a id="l00208" name="l00208"></a> 208 PyObject *ret = PyDict_New();

<a id="l00209" name="l00209"></a> 209 PyDict_SetItemString_DECREF(ret, "width", PyLong_FromLong(frame-&gt;[iWidth](struct___shared_memory_frame.xhtml#a6d26bbffc622333b9f11fbadecbd6f21)));

<a id="l00210" name="l00210"></a> 210 PyDict_SetItemString_DECREF(ret, "height", PyLong_FromLong(frame-&gt;[iHeight](struct___shared_memory_frame.xhtml#ab21b6d402e01098565be5024de341ec7)));

<a id="l00211" name="l00211"></a> 211 PyDict_SetItemString_DECREF(ret, "framenumber", PyLong_FromLong(frame-&gt;[iFrame](struct___shared_memory_frame.xhtml#a412d63c3ef8e7417be98997f72f3b0e5)));

<a id="l00212" name="l00212"></a> 212 PyDict_SetItemString_DECREF(ret, "pixeldata", PyBytes_FromStringAndSize(frame-&gt;[buffer](struct___shared_memory_frame.xhtml#a7cff19a44525e74c5800b1e2f9e4cc98),

<a id="l00213" name="l00213"></a> 213 frame-&gt;[iWidth](struct___shared_memory_frame.xhtml#a6d26bbffc622333b9f11fbadecbd6f21)*3*frame-&gt;[iHeight](struct___shared_memory_frame.xhtml#ab21b6d402e01098565be5024de341ec7)));

<a id="l00214" name="l00214"></a> 214 return ret;

<a id="l00215" name="l00215"></a> 215}

<a id="l00216" name="l00216"></a> 216 

<a id="l00217" name="l00217"></a> 217static PyObject *Py_stream_unlock(PyObject *self, PyObject *args, PyObject *keywds)

<a id="l00218" name="l00218"></a> 218{

<a id="l00219" name="l00219"></a> 219 int32_t stream_id = -1;

<a id="l00220" name="l00220"></a> 220 static const char *kwlist[] = { "stream\_id", NULL };

<a id="l00221" name="l00221"></a> 221 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"i", (char **)kwlist,

<a id="l00222" name="l00222"></a> 222 &amp;stream_id)) return NULL;

<a id="l00223" name="l00223"></a> 223 if ((stream_id &lt; 0) || (stream_id &gt;= [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)) || !streamlist[stream_id]) {

<a id="l00224" name="l00224"></a> 224 PyErr_SetString(PyExc_RuntimeError, "Unknown stream id");

<a id="l00225" name="l00225"></a> 225 return NULL;

<a id="l00226" name="l00226"></a> 226 }

<a id="l00227" name="l00227"></a> 227 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) err = [SharedMemoryImageStream\_unlock](shared__memory__image__client_8h.xhtml#ac885e449551afd5fb5a7f19c5ec785a6)(streamlist[stream_id]);

<a id="l00228" name="l00228"></a> 228 return return_error(err);

<a id="l00229" name="l00229"></a> 229}

<a id="l00230" name="l00230"></a> 230 

<a id="l00231" name="l00231"></a> 231static PyObject *Py_stream_putframe(PyObject *self, PyObject *args, PyObject *keywds)

<a id="l00232" name="l00232"></a> 232{

<a id="l00233" name="l00233"></a> 233 int32_t stream_id = -1;

<a id="l00234" name="l00234"></a> 234 int32_t iWidth = 0;

<a id="l00235" name="l00235"></a> 235 int32_t iHeight = 0;

<a id="l00236" name="l00236"></a> 236 uint32_t iFrame = 0;

<a id="l00237" name="l00237"></a> 237 PyObject *pData = NULL;

<a id="l00238" name="l00238"></a> 238 static const char *kwlist[] = { "stream\_id", "width", "height", "framenumber", "pixeldata", NULL };

<a id="l00239" name="l00239"></a> 239 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"iiiiO", (char **)kwlist,

<a id="l00240" name="l00240"></a> 240 &amp;stream_id, &amp;iWidth, &amp;iHeight, &amp;iFrame, &amp;pData)) return NULL;

<a id="l00241" name="l00241"></a> 241 if ((stream_id &lt; 0) || (stream_id &gt;= [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)) || !streamlist[stream_id]) {

<a id="l00242" name="l00242"></a> 242 PyErr_SetString(PyExc_RuntimeError, "Unknown stream id");

<a id="l00243" name="l00243"></a> 243 return NULL;

<a id="l00244" name="l00244"></a> 244 }

<a id="l00245" name="l00245"></a> 245 int32_t frame_size = iWidth * iHeight * 3;

<a id="l00246" name="l00246"></a> 246 if (frame_size &lt; 1) {

<a id="l00247" name="l00247"></a> 247 PyErr_SetString(PyExc_RuntimeError, "Invalid frame size");

<a id="l00248" name="l00248"></a> 248 return NULL;

<a id="l00249" name="l00249"></a> 249 }

<a id="l00250" name="l00250"></a> 250 if (!PyBytes_Check(pData)) {

<a id="l00251" name="l00251"></a> 251 PyErr_SetString(PyExc_RuntimeError, "Pixeldata must be a bytes object");

<a id="l00252" name="l00252"></a> 252 return NULL;

<a id="l00253" name="l00253"></a> 253 }

<a id="l00254" name="l00254"></a> 254 Py_ssize_t data_size = PyBytes_Size(pData);

<a id="l00255" name="l00255"></a> 255 if (data_size &lt; frame_size) {

<a id="l00256" name="l00256"></a> 256 PyErr_SetString(PyExc_RuntimeError, "Pixeldata is too small for specified frame size");

<a id="l00257" name="l00257"></a> 257 return NULL;

<a id="l00258" name="l00258"></a> 258 }

<a id="l00259" name="l00259"></a> 259 struct [\_SharedMemoryFrame](struct___shared_memory_frame.xhtml) frame;

<a id="l00260" name="l00260"></a> 260 frame.[iFrame](struct___shared_memory_frame.xhtml#a412d63c3ef8e7417be98997f72f3b0e5) = [iFrame](struct___shared_memory_frame.xhtml#a412d63c3ef8e7417be98997f72f3b0e5);

<a id="l00261" name="l00261"></a> 261 frame.[iWidth](struct___shared_memory_frame.xhtml#a6d26bbffc622333b9f11fbadecbd6f21) = [iWidth](struct___shared_memory_frame.xhtml#a6d26bbffc622333b9f11fbadecbd6f21);

<a id="l00262" name="l00262"></a> 262 frame.[iHeight](struct___shared_memory_frame.xhtml#ab21b6d402e01098565be5024de341ec7) = [iHeight](struct___shared_memory_frame.xhtml#ab21b6d402e01098565be5024de341ec7);

<a id="l00263" name="l00263"></a> 263 frame.[buffer](struct___shared_memory_frame.xhtml#a7cff19a44525e74c5800b1e2f9e4cc98) = PyBytes_AsString(pData);

<a id="l00264" name="l00264"></a> 264 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) err = [SharedMemoryImageStream\_putframe](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad)(streamlist[stream_id], &amp;frame);

<a id="l00265" name="l00265"></a> 265 return return_error(err);

<a id="l00266" name="l00266"></a> 266}

<a id="l00267" name="l00267"></a> 267 

<a id="l00268" name="l00268"></a> 268static PyObject *Py_stream_destroy(PyObject *self, PyObject *args, PyObject *keywds)

<a id="l00269" name="l00269"></a> 269{

<a id="l00270" name="l00270"></a> 270 int32_t stream_id = -1;

<a id="l00271" name="l00271"></a> 271 static const char *kwlist[] = { "stream\_id", NULL };

<a id="l00272" name="l00272"></a> 272 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"i", (char **)kwlist,

<a id="l00273" name="l00273"></a> 273 &amp;stream_id)) return NULL;

<a id="l00274" name="l00274"></a> 274 if ((stream_id &lt; 0) || (stream_id &gt;= [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)) || !streamlist[stream_id]) {

<a id="l00275" name="l00275"></a> 275 PyErr_SetString(PyExc_RuntimeError, "Unknown stream id");

<a id="l00276" name="l00276"></a> 276 return NULL;

<a id="l00277" name="l00277"></a> 277 } 

<a id="l00278" name="l00278"></a> 278 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) err = [SharedMemoryImageStream\_destroy](shared__memory__image__client_8h.xhtml#a4ea47b6bda387b71ed5f91db329eff65)(streamlist[stream_id]);

<a id="l00279" name="l00279"></a> 279 streamlist[stream_id] = NULL;

<a id="l00280" name="l00280"></a> 280 return return_error(err);

<a id="l00281" name="l00281"></a> 281}

<a id="l00282" name="l00282"></a> 282 

<a id="l00283" name="l00283"></a> 283static void stream_python_shutdown(void)

<a id="l00284" name="l00284"></a> 284{

<a id="l00285" name="l00285"></a> 285 for (int i = 0; i &lt; [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9); i++) {

<a id="l00286" name="l00286"></a> 286 if (streamlist[i]) [SharedMemoryImageStream\_destroy](shared__memory__image__client_8h.xhtml#a4ea47b6bda387b71ed5f91db329eff65)(streamlist[i]);

<a id="l00287" name="l00287"></a> 287 streamlist[i] = NULL;

<a id="l00288" name="l00288"></a> 288 }

<a id="l00289" name="l00289"></a> 289}

<a id="l00290" name="l00290"></a> 290 

<a id="l00292" name="l00292"></a> 292 

<a id="l00293" name="l00293"></a> 293/\* Module definition \*/

<a id="l00294" name="l00294"></a> 294static PyObject *pmodule = NULL;

<a id="l00295" name="l00295"></a> 295static PyMethodDef py_methods[] = {

<a id="l00296" name="l00296"></a> 296 {(char *)"stream\_create", (PyCFunction)Py_stream_create, METH_VARARGS | METH_KEYWORDS, 

<a id="l00297" name="l00297"></a> 297 (char *)"Create a new shared memory image stream"},

<a id="l00298" name="l00298"></a> 298 {(char *)"stream\_lock", (PyCFunction)Py_stream_lock, METH_VARARGS | METH_KEYWORDS,

<a id="l00299" name="l00299"></a> 299 (char *)"Lock and return the next image from an image stream"},

<a id="l00300" name="l00300"></a> 300 {(char *)"stream\_unlock", (PyCFunction)Py_stream_unlock, METH_VARARGS | METH_KEYWORDS,

<a id="l00301" name="l00301"></a> 301 (char *)"Release the lock on an image stream"},

<a id="l00302" name="l00302"></a> 302 {(char *)"stream\_putframe", (PyCFunction)Py_stream_putframe, METH_VARARGS | METH_KEYWORDS,

<a id="l00303" name="l00303"></a> 303 (char *)"Push a new frame into the image stream"},

<a id="l00304" name="l00304"></a> 304 {(char *)"stream\_destroy", (PyCFunction)Py_stream_destroy, METH_VARARGS | METH_KEYWORDS,

<a id="l00305" name="l00305"></a> 305 (char *)"Destroy an image stream"},

<a id="l00306" name="l00306"></a> 306 {NULL, NULL, 0, NULL}

<a id="l00307" name="l00307"></a> 307};

<a id="l00308" name="l00308"></a> 308 

<a id="l00309" name="l00309"></a> 309\#if PY\_MAJOR\_VERSION &gt;= 3

<a id="l00310" name="l00310"></a> 310 

<a id="l00311" name="l00311"></a> 311static struct PyModuleDef moduledef = {

<a id="l00312" name="l00312"></a> 312 PyModuleDef_HEAD_INIT,

<a id="l00313" name="l00313"></a> 313 "ensight\_grpc\_shmem",

<a id="l00314" name="l00314"></a> 314 "EnSight gRPC shared memory image stream",

<a id="l00315" name="l00315"></a> 315 -1,

<a id="l00316" name="l00316"></a> 316 py_methods,

<a id="l00317" name="l00317"></a> 317 NULL, /\* m\_reload \*/

<a id="l00318" name="l00318"></a> 318 NULL, /\* m\_traverse \*/

<a id="l00319" name="l00319"></a> 319 NULL, /\* m\_clear \*/

<a id="l00320" name="l00320"></a> 320 NULL, /\* m\_free \*/

<a id="l00321" name="l00321"></a> 321};

<a id="l00322" name="l00322"></a> 322 

<a id="l00323" name="l00323"></a> 323PyMODINIT_FUNC PyInit_ensight_grpc_shmem()

<a id="l00324" name="l00324"></a> 324{

<a id="l00325" name="l00325"></a> 325 pmodule = PyModule_Create(&amp;moduledef);

<a id="l00326" name="l00326"></a> 326\#else

<a id="l00327" name="l00327"></a> 327PyMODINIT_FUNC initensight_grpc_shmem()

<a id="l00328" name="l00328"></a> 328{

<a id="l00329" name="l00329"></a> 329 pmodule = Py_InitModule3("ensight\_grpc\_shmem", py_methods, "EnSight gRPC shared memory image stream");

<a id="l00330" name="l00330"></a> 330\#endif

<a id="l00331" name="l00331"></a> 331 

<a id="l00332" name="l00332"></a> 332 // Common (2 &amp; 3) code starts here -------------------------------------------------

<a id="l00333" name="l00333"></a> 333 PyModule_AddStringConstant(pmodule, "version", [IMAGESTREAM\_API\_VERSION](shared__memory__image__client_8h.xhtml#a64df229b0ac6942d9bdee4b94b2c096a));

<a id="l00334" name="l00334"></a> 334 

<a id="l00335" name="l00335"></a> 335 PyModule_AddIntConstant(pmodule, "OPTIONS\_NONE", (int)[IMAGESTREAM\_OPTIONS\_NONE](shared__memory__image__client_8h.xhtml#a7fbe522f7a46875a755f07c8ff69e2df));

<a id="l00336" name="l00336"></a> 336 PyModule_AddIntConstant(pmodule, "OPTIONS\_SERVER", (int)[IMAGESTREAM\_OPTIONS\_SERVER](shared__memory__image__client__priv_8h.xhtml#aa87740042e4f5882fa4c990a6528c2e3));

<a id="l00337" name="l00337"></a> 337 PyModule_AddIntConstant(pmodule, "OPTIONS\_FLIPVERTICAL", (int)[IMAGESTREAM\_OPTIONS\_FLIPVERTICAL](shared__memory__image__client_8h.xhtml#a536935e36e51aade42c2a49f8ecd7ae1));

<a id="l00338" name="l00338"></a> 338 

<a id="l00339" name="l00339"></a> 339 PyModule_AddIntConstant(pmodule, "ERROR\_NOERROR", (int)[IMAGESTREAM\_NOERROR](shared__memory__image__client_8h.xhtml#af995dd87ffd7dd178eef1d343f7b72bf));

<a id="l00340" name="l00340"></a> 340 PyModule_AddIntConstant(pmodule, "ERROR\_NO\_BUFFERAVAILABLE", (int)[IMAGESTREAM\_NO\_BUFFERAVAILABLE](shared__memory__image__client_8h.xhtml#a78414d594aa9bb3f9bcea84c768d2826));

<a id="l00341" name="l00341"></a> 341 PyModule_AddIntConstant(pmodule, "ERROR\_NO\_FRAMEAVAILABLE", (int)[IMAGESTREAM\_NO\_FRAMEAVAILABLE](shared__memory__image__client_8h.xhtml#a7a7491d1019b67d55ac6488c0e3cb637));

<a id="l00342" name="l00342"></a> 342 PyModule_AddIntConstant(pmodule, "ERROR\_RECONNECTING", (int)[IMAGESTREAM\_RECONNECTING](shared__memory__image__client_8h.xhtml#aa17e85c9001e414b9ac1db640884b944));

<a id="l00343" name="l00343"></a> 343 PyModule_AddIntConstant(pmodule, "ERROR\_UNCONNECTED", (int)[IMAGESTREAM\_UNCONNECTED](shared__memory__image__client_8h.xhtml#a2cc13f7eda736fddce876cf5cae2c502));

<a id="l00344" name="l00344"></a> 344 

<a id="l00345" name="l00345"></a> 345 /\* cleanup on exit \*/

<a id="l00346" name="l00346"></a> 346 Py_AtExit(stream_python_shutdown);

<a id="l00347" name="l00347"></a> 347 // Common (2 &amp; 3) code ends here -------------------------------------------------

<a id="l00348" name="l00348"></a> 348 

<a id="l00349" name="l00349"></a> 349\#if PY\_MAJOR\_VERSION &gt;= 3

<a id="l00350" name="l00350"></a> 350 return pmodule;

<a id="l00351" name="l00351"></a> 351}

<a id="l00352" name="l00352"></a> 352\#else

<a id="l00353" name="l00353"></a> 353 return;

<a id="l00354" name="l00354"></a> 354}

<a id="l00355" name="l00355"></a> 355\#endif

<a id="l00356" name="l00356"></a> 356 

[SharedMemoryImageStream\_create](shared__memory__image__client_8h.xhtml#a03ba052ae823b3e39fef153db8f03ea2)

SharedMemoryImageError SharedMemoryImageStream_create(const char *filename, uint32_t options, SharedMemoryImageStream *stream)

SharedMemoryImageStream_create create a stream client instance.



[SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a)

int SharedMemoryImageError

common error codes see the non-hex, non-string IMAGESTREAM macros

**Definition** [shared\_memory\_image\_client.h:109](shared__memory__image__client_8h_source.xhtml#l00109)



[SharedMemoryImageStream\_errorstring](shared__memory__image__client_8h.xhtml#a16abb961cf38273321e81cc64d71fad7)

const char * SharedMemoryImageStream_errorstring(SharedMemoryImageError err)

SharedMemoryImageStream_errorstring convert an error code into a human string.



[IMAGESTREAM\_UNCONNECTED](shared__memory__image__client_8h.xhtml#a2cc13f7eda736fddce876cf5cae2c502)

\#define IMAGESTREAM_UNCONNECTED

**Definition** [shared\_memory\_image\_client.h:84](shared__memory__image__client_8h_source.xhtml#l00084)



[SharedMemoryImageStream\_destroy](shared__memory__image__client_8h.xhtml#a4ea47b6bda387b71ed5f91db329eff65)

SharedMemoryImageError SharedMemoryImageStream_destroy(SharedMemoryImageStream stream)

SharedMemoryImageStream_destroy destroy a stream interface, releasing its resources.



[IMAGESTREAM\_OPTIONS\_FLIPVERTICAL](shared__memory__image__client_8h.xhtml#a536935e36e51aade42c2a49f8ecd7ae1)

\#define IMAGESTREAM_OPTIONS_FLIPVERTICAL

**Definition** [shared\_memory\_image\_client.h:105](shared__memory__image__client_8h_source.xhtml#l00105)



[IMAGESTREAM\_API\_VERSION](shared__memory__image__client_8h.xhtml#a64df229b0ac6942d9bdee4b94b2c096a)

\#define IMAGESTREAM_API_VERSION

**Definition** [shared\_memory\_image\_client.h:81](shared__memory__image__client_8h_source.xhtml#l00081)



[IMAGESTREAM\_NO\_BUFFERAVAILABLE](shared__memory__image__client_8h.xhtml#a78414d594aa9bb3f9bcea84c768d2826)

\#define IMAGESTREAM_NO_BUFFERAVAILABLE

**Definition** [shared\_memory\_image\_client.h:87](shared__memory__image__client_8h_source.xhtml#l00087)



[IMAGESTREAM\_NO\_FRAMEAVAILABLE](shared__memory__image__client_8h.xhtml#a7a7491d1019b67d55ac6488c0e3cb637)

\#define IMAGESTREAM_NO_FRAMEAVAILABLE

**Definition** [shared\_memory\_image\_client.h:86](shared__memory__image__client_8h_source.xhtml#l00086)



[IMAGESTREAM\_OPTIONS\_NONE](shared__memory__image__client_8h.xhtml#a7fbe522f7a46875a755f07c8ff69e2df)

\#define IMAGESTREAM_OPTIONS_NONE

**Definition** [shared\_memory\_image\_client.h:103](shared__memory__image__client_8h_source.xhtml#l00103)



[IMAGESTREAM\_RECONNECTING](shared__memory__image__client_8h.xhtml#aa17e85c9001e414b9ac1db640884b944)

\#define IMAGESTREAM_RECONNECTING

**Definition** [shared\_memory\_image\_client.h:85](shared__memory__image__client_8h_source.xhtml#l00085)



[SharedMemoryImageStream\_unlock](shared__memory__image__client_8h.xhtml#ac885e449551afd5fb5a7f19c5ec785a6)

SharedMemoryImageError SharedMemoryImageStream_unlock(SharedMemoryImageStream stream)

SharedMemoryImageStream_unlock release a frame obtained by SharedMemoryImageStream_lock.



[SharedMemoryImageStream](shared__memory__image__client_8h.xhtml#af5b8eb2ae90823f10e9a17698ea80749)

struct _SharedMemoryImageStream * SharedMemoryImageStream

image transport stream pointer

**Definition** [shared\_memory\_image\_client.h:111](shared__memory__image__client_8h_source.xhtml#l00111)



[IMAGESTREAM\_NOERROR](shared__memory__image__client_8h.xhtml#af995dd87ffd7dd178eef1d343f7b72bf)

\#define IMAGESTREAM_NOERROR

**Definition** [shared\_memory\_image\_client.h:88](shared__memory__image__client_8h_source.xhtml#l00088)



[SharedMemoryImageStream\_lock](shared__memory__image__client_8h.xhtml#afefb8f5297147640b46d1f9eb1e77c9e)

SharedMemoryImageError SharedMemoryImageStream_lock(SharedMemoryImageStream stream, SharedMemoryFrame *frame)

SharedMemoryImageStream_lock get a frame of pixels from the server.



[shared\_memory\_image\_client\_priv.h](shared__memory__image__client__priv_8h.xhtml)

C API the shared memory image transport API server interface.



[IMAGESTREAM\_OPTIONS\_SERVER](shared__memory__image__client__priv_8h.xhtml#aa87740042e4f5882fa4c990a6528c2e3)

\#define IMAGESTREAM_OPTIONS_SERVER

**Definition** [shared\_memory\_image\_client\_priv.h:135](shared__memory__image__client__priv_8h_source.xhtml#l00135)



[SharedMemoryImageStream\_putframe](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad)

DEV SharedMemoryImageError SharedMemoryImageStream_putframe(SharedMemoryImageStream stream, SharedMemoryFrame frame)

SharedMemoryImageStream_putframe push a new image into a server image stream channel.



[stream\_unlock](shared__memory__image__client__python_8c.xhtml#a233ea80003a929e8e60aabd26a3b5c5e)

SharedMemoryImageError stream_unlock(stream_id id)

Unlock the frame allocated by stream_lock().



[stream\_putframe](shared__memory__image__client__python_8c.xhtml#a23b3d9929aaff2a388402452ce5228c1)

SharedMemoryImageError stream_putframe(stream_id id, int width, int height, int framenumber, bytes pixeldata)

Push an image into the shared memory transport buffer.



[MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9)

\#define MAX_STREAMS

**Definition** [shared\_memory\_image\_client\_python.c:30](#l00030)



[stream\_create](shared__memory__image__client__python_8c.xhtml#a68584fd5e8630714c738fc30ad19fa03)

stream_id stream_create(str filename, int options=IMAGESTREAM_OPTIONS_NONE)

Create a shared memory image stream.



[stream\_lock](shared__memory__image__client__python_8c.xhtml#ac78db99f06d47f7718fdcac4ae3cc374)

frame stream_lock(stream_id id)

Get any available image frame.



[stream\_destroy](shared__memory__image__client__python_8c.xhtml#af656cd2bf739307f1d52221d49da37ae)

SharedMemoryImageError stream_destroy(stream_id id)

Close down and destroy a shared memory transport interface.



[\_SharedMemoryFrame](struct___shared_memory_frame.xhtml)

**Definition** [shared\_memory\_image\_client.h:115](shared__memory__image__client_8h_source.xhtml#l00115)



[\_SharedMemoryFrame::iFrame](struct___shared_memory_frame.xhtml#a412d63c3ef8e7417be98997f72f3b0e5)

uint32_t iFrame

monotonically increasing frame number

**Definition** [shared\_memory\_image\_client.h:116](shared__memory__image__client_8h_source.xhtml#l00116)



[\_SharedMemoryFrame::iWidth](struct___shared_memory_frame.xhtml#a6d26bbffc622333b9f11fbadecbd6f21)

uint32_t iWidth

width of a frame in pixels

**Definition** [shared\_memory\_image\_client.h:117](shared__memory__image__client_8h_source.xhtml#l00117)



[\_SharedMemoryFrame::buffer](struct___shared_memory_frame.xhtml#a7cff19a44525e74c5800b1e2f9e4cc98)

uint8_t * buffer

pointer to a packed RGBRGBRGB... (iWidth*iHeight*3) bytes array of pixels

**Definition** [shared\_memory\_image\_client.h:119](shared__memory__image__client_8h_source.xhtml#l00119)



[\_SharedMemoryFrame::iHeight](struct___shared_memory_frame.xhtml#ab21b6d402e01098565be5024de341ec7)

uint32_t iHeight

height of a frame in pixels

**Definition** [shared\_memory\_image\_client.h:118](shared__memory__image__client_8h_source.xhtml#l00118)