qshinoの日記

Powershell関係と徒然なこと

SLVS

SLVS

Scalable Lowvoltage signaling

コモンモード電圧 0.8v 差動電圧 400mv, プラスマイナス200mv コモンモード電流 6ma ?

因みに、LVDSのコモンモード電流3.5ma

項目  LVDS SLVS
差動振幅  700mv 400mv
コモンモード電圧 1.25V 0.2V
コモンモード電流 3.5mA 6mA?

参考

https://ednjapan.com/edn/spv/1109/20/news120_2.html

gstreamer test app

gstreamer test app src

include <gst/gst.h> static gboolean bus_call (GstBus bus, GstMessage msg, gpointer data) { GMainLoop loop = data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End-of-stream\n"); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR: { gchar debug = NULL; GError err = NULL; gst_message_parse_error (msg, &err, &debug); g_print ("Error: %s\n", err->message); g_error_free (err); if (debug) { g_print ("Debug details: %s\n", debug); g_free (debug); } g_main_loop_quit (loop); break; } default: break; } return TRUE; } gint main (gint argc, gchar argv[]) { GstStateChangeReturn ret; GstElement pipeline, filesrc, decoder, filter, sink; GstElement convert1, convert2, resample; GMainLoop loop; GstBus bus; guint watch_id; / initialization / gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); if (argc != 2) { g_print ("Usage: %s \n", argv[0]); return 01; } / create elements / pipeline = gst_pipeline_new ("my_pipeline"); / watch for messages on the pipeline's bus (note that this will only * work like this when a GLib main loop is running) / bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); filesrc = gst_element_factory_make ("filesrc", "my_filesource"); decoder = gst_element_factory_make ("mad", "my_decoder"); / putting an audioconvert element here to convert the output of the * decoder into a format that my_filter can handle (we are assuming it * will handle any sample rate here though) / convert1 = gst_element_factory_make ("audioconvert", "audioconvert1"); / use "identity" here for a filter that does nothing / filter = gst_element_factory_make ("my_filter", "my_filter"); / there should always be audioconvert and audioresample elements before * the audio sink, since the capabilities of the audio sink usually vary * depending on the environment (output used, sound card, driver etc.) / convert2 = gst_element_factory_make ("audioconvert", "audioconvert2"); resample = gst_element_factory_make ("audioresample", "audioresample"); sink = gst_element_factory_make ("pulsesink", "audiosink"); if (!sink || !decoder) { g_print ("Decoder or output could not be found - check your install\n"); return -1; } else if (!convert1 || !convert2 || !resample) { g_print ("Could not create audioconvert or audioresample element, " "check your installation\n"); return -1; } else if (!filter) { g_print ("Your self-written filter could not be found. Make sure it " "is installed correctly in $(libdir)/gstreamer-1.0/ or " "~/.gstreamer-1.0/plugins/ and that gst-inspect-1.0 lists it. " "If it doesn't, check with 'GST_DEBUG=:2 gst-inspect-1.0' for " "the reason why it is not being loaded."); return -1; } g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, convert1, filter, convert2, resample, sink, NULL); / link everything together / if (!gst_element_link_many (filesrc, decoder, convert1, filter, convert2, resample, sink, NULL)) { g_print ("Failed to link one or more elements!\n"); return -1; } / run / ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { GstMessage msg; g_print ("Failed to start up pipeline!\n"); / check if there is an error message with details on the bus / msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); if (msg) { GError err = NULL; gst_message_parse_error (msg, &err, NULL); g_print ("ERROR: %s\n", err->message); g_error_free (err); gst_message_unref (msg); } return -1; } g_main_loop_run (loop); / clean up */ gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); g_source_remove (watch_id); g_main_loop_unref (loop); return 0; }

shm on gstreamer

shmsrc/sink on gstreamer

gstreamerでの共有メモリshm プラグインの仕組みを確認。

参考

audio 向け

http://gstreamer-devel.966125.n4.nabble.com/Reading-an-shmsink-stream-from-an-external-application-td4655511.html

ipcpipelne

https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.collabora.com/news-and-blog/blog/2017/11/17/ipcpipeline-splitting-a-gstreamer-pipeline-into-multiple-processes/&ved=2ahUKEwiP_pHn-6jiAhVIWbwKHUW1D48QFjADegQIARAB&usg=AOvVaw3ElSQ8m3JNab09mWEcceGl

c でpython module 作成

Cでpyton module

Cでpython module を作成する流れは下記の通り。

  1. cでソースを作成。
  2. setup.py でコンパイルし、.soを作成。
  3. python から利用。

Cソース

#define PY_SSIZE_T_CLEAN
#include <Python.h>

static PyObject * spam_system( 
  PyObject *self, 
  PyObject *args) { 

  const char *command; 
  int sts; 

  if (!PyArg_ParseTuple(args, "s", &command)) 
    return NULL; 
  sts = system(command);
  return PyLong_FromLong(sts); 
}


static PyObject* hello (
  PyObject *self, PyObject *args) { 

  printf("How are you?\n");

  Py_RETURN_NONE; 
} 

static PyObject* push(
  PyObject *self, PyObject *args){ 

  PyObject *p_list, *inthert_val, *receive_list;  
 
  if(!PyArg_ParseTuple(args, "O!i", &PyList_Type, &p_list, &inthert_val)) 
    return NULL;
  receive_list = PySequence_List(p_list);
  printf("pushing %d\n", inthert_val); 
  PyList_Append(receive_list, Py_BuildValue("i", inthert_val));

  return receive_list;
} 

static PyObject* pop (
  PyObject *self, PyObject *args){ 
  PyObject *p_list, *p_value; int size; long val; 
  if(!PyArg_ParseTuple(args, "O!", &PyList_Type, &p_list)) 
  return NULL;
  size = PyList_Size(p_list);
  p_value = PyList_GetItem(p_list, size - 1); 
  val = PyLong_AsLong(p_value);   
  printf("poping %d\n", val);
  return p_value; 
}

static PyMethodDef pmethod[] = { 
   {"spam_system", (PyCFunction) spam_system, METH_NOARGS, "primer: ststem"}, 
  {"hello", (PyCFunction) hello, METH_NOARGS, "primer: hello"}, 
  {"push", (PyCFunction) push, METH_VARARGS, "primer: push"},   
  {"pop", (PyCFunction)pop, METH_VARARGS, "primer: pop"}, 
  {NULL, NULL, 0, NULL} 
};

static struct PyModuleDef pm = { 
  PyModuleDef_HEAD_INIT,  "primer", NULL, -1, pmethod 
};

PyMODINIT_FUNC PyInit_primer (void) { 
  return PyModule_Create( &pm ); 
}

return NULLの所、大丈夫なのだろうか? python document でもNULLを返しているが、NULLとPy_RETURN_NONEの違いは? NULLはエラーらしい。例外処理に関しては、また後で。

  • note: "Python.h" は下記をインクルード:  <stdio.h> 、 <string.h> 、 <errno.h> 、 <stdlib.h> 

初期化

int main(int argc, char *argv[]) { 
  wchar_t *program = Py_DecodeLocale(argv[0], NULL); 

  if ( program == NULL ) { 
    fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); 
    exit(1); 
  } 

/* Add a built-in module, before Py_Initialize */

  PyImport_AppendInittab( "primer",  PyInit_primer ); 

/* Pass argv[0] to the Python interpreter */ 

  Py_SetProgramName( program );

 /* Initialize the Python interpreter. Required. */ 

  Py_Initialize(); 

  /* Optionally import the module; alternatively, import can be deferred until the embedded script imports it. */

  PyImport_ImportModule( "primer" ); 
  ... 
  PyMem_RawFree( program ); 
  return 0; 
}

setup.py

Cソースをコンパイルするsetup.pyを作成する。

# python setup.py build_ext -i
# setup.py

from distutils.core import setup, Extension 

setup(
  name='primer', 
  version='1.0', 
  ext_modules=[
    Extension('primer', ['primer.c'])
  ] 
)

コンパイル

python setup.py build_ext -i

モジュール利用

# python usecase

import primer

primer.hello()

lista = primer.push([1, 2], 3) 
print(list) 

val = primer.pop(lista) 
print(val) 


出力

How are you?
pushing 3
[1, 2, 3] 
poping 3
3

参考

https://docs.python.org/ja/3/extending/extending.html

https://qiita.com/Kashiwara/items/2088ba011446637aa8f4