pjsip pj_timer_heap_schedule crashes - c

I'm trying to make a simple timer that fires a specific call back when its time come.
I have written this code:
void testTimer()
{
pj_timer_heap_t *timer_heap;
pj_timer_entry registrationTimer;
char *username="test_data";
pj_timer_entry_init(&registrationTimer, 50, username, &on_timer_event);
pj_time_val delay;
delay.sec = 5;
delay.msec = 0;
pj_status_t status = pj_timer_heap_create(global.pool, 256, &timer_heap);
status=pj_timer_heap_schedule(timer_heap,&registrationTimer, &delay);
}
I don't know whats wrong with the code. This code crashes on pj_timer_heap_schedule.I am unable to figure out whats missing. Pls Help.

It's a little impossible to know the problem without the
pj_timer_heap_schedule
function

Try and initialize as
`pj_bzero(&registrationTimer, sizeof(registrationTimer));`
then ensure you have done
`registrationTimer.id = PJSUA_INVALID_ID;`
`registrationTimer.cb = &my_callback;`
finally don't forget to define and declare your callback my_callback
Good luck

Related

Monitor flashing when running a Windows SendInput API

Well, I certainly should go to python since I did several functions of this type, keyboard event and mouse event, but decide to try to learn the windows api.
My goal is to know when button 1 of the mouse is pressed.
I created this file in a very beginner way, it returns in mouseData only 0.
The curious thing is that whenever I run it, it flashes my monitor at short intervals in blinks, but between 1 second with it off. Very strange that, execution is not viable.
Could someone help me understand and try to execute to see if it is only here.
Code:
int main()
{
DWORD mouseData = 0;
MOUSEINPUT tagMouse;
tagMouse.dx = 0;
tagMouse.dy = 0;
tagMouse.mouseData = mouseData;
tagMouse.dwFlags = MOUSEEVENTF_XDOWN;
tagMouse.dwExtraInfo = 0;
INPUT tagInput;
tagInput.type = INPUT_MOUSE;
tagInput.mi = tagMouse;
while (true) {
if (GetAsyncKeyState(VK_DELETE)) break;
SendInput(1, &tagInput, sizeof(INPUT));
printf("KEYWORD: %d\n", mouseData);
Sleep(500);
}
system("pause");
return 0;
}
I can reproduce your reported 'symptoms' - and the effect is really brutal!
Now, while I cannot offer a full explanation, I can offer a fix! You have an uninitialized field in your tagMouse structure (the time member, which is a time-stamp used by the system). Setting this to zero (which tells the system to generate its own time-stamp) fixes the problem. So, just add this line to your other initializer statements:
//...
tagMouse.dwExtraInfo = 0;
tagMouse.time = 0; // Adding this line fixes it!
//...
Note: I, too, would appreciate a fuller explanation; however, an uninitialized field, to me, smells like undefined behaviour! I have tried a variety of other values (i.e. not zero) for the time field but haven't yet found one that works.
The discussion here on devblogs may help. This quote seems relevant:
And who knows what sort of havoc that will create if a program checks
the timestamps and notices that they are either from the future or
have traveled back in time.

After setting change_state in class_init function, nothing else works

I followed the gstreamer's tutorial on how to write plugins, and my goal is to create a video sink. For now I will just post relevant code, but if needed, I can upload whole plugin code somewhere. It will be an opensource anyway.
The class structure looks like this:
struct _GstIviOpenglSinkClass
{
GstVideoSinkClass base_iviopenglsink_class;
};
and my class_init() function looks like this:
static void
gst_iviopenglsink_class_init (GstIviOpenglSinkClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass);
GstVideoSinkClass *gstvideosink_class = GST_VIDEO_SINK_CLASS (klass);
GST_DEBUG ("START");
gobject_class->set_property = gst_iviopenglsink_set_property;
gobject_class->get_property = gst_iviopenglsink_get_property;
gobject_class->finalize = gst_iviopenglsink_finalize;
gst_element_class_add_pad_template (gstelement_class,
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
gst_caps_from_string (VIDEO_SINK_CAPS)));
gst_element_class_set_static_metadata (gstelement_class,
"desc", "Sink/Video",
"desc",
"me <me#com.com>");
gstbasesink_class->get_caps = gst_iviopenglsink_get_caps;
gstbasesink_class->set_caps = gst_iviopenglsink_set_caps;
/* makes problems?!? */
gstelement_class->change_state = gst_iviopenglsink_change_state;
gstvideosink_class->show_frame = gst_iviopenglsink_show_frame;
GST_DEBUG ("END");
}
If I leave the class_init function like this, then the callbacks set_caps, get_caps, and show_frame, are not working (not being called at all). If I outcomment the assignment of the change_state, then these 3 callbacks are being called.
Am I doing something wrong in the class_init function, or is the problem lieing somewhere else? What can I do to debug this?
This comment was correct - the problem is indeed in the function dealing with change_state. I took a look into the source code for waylandsink and found this weird line:
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
I have no idea what that line is doing, but apparently it is needed. And it is nowhere explained neither in the tutorial for plugins, nor in the page describing GstElementClass.
If someone can explain why is that needed, I would really appreciate it :)

Error in output.println() on Processing

I'm trying to read some data from Processing and write it to a file. The data is correct, since I can plot it without problem. However, when I attempt to write it to a file it throws me the following error:
Error, disabling serialEvent() for /dev/ttyACM0
null
Specifically, I've found out where the problem is. It's in this function:
void serialEvent(Serial myPort) {
int inByte = myPort.read();
if (inByte >= 0 && inByte <= 255)
{
// This is what makes the problem arise
output.println("test: " + inByte);
// ...
}
}
I've even changed the line output.println(); with this and then the same function works, printing it to the correct file (but it's obviously not what I want):
// This does work
point(mouseX, mouseY);
output.println(mouseX);
Any idea where the problem might be? I'm using arduino and it passes values from 0 to 255 from serial. The values seem correct, since I can plot them without problem. I've also tried changing println() for print() with no luck.
EDIT. After some testing, I find this really odd. This works:
point(mouseX, mouseY);
output.println(inByte);
While, without the point(), it doesn't work (same error). As a temporary solution, I can put the output.println at the end of the function, but this is obviously not a long-term solution.
I ended up doing a simple check in my code:
if (output != null) {
output.println(t + " " + inByte);
}
It just works. However, I think that polymorphism would be even better here. Having an object that absorbs the text if the output is not initialized, and that prints it to the file if it is.
I had the same problem but here is my solution and it works perfectly.
at the beginning of the code write sth like this:
boolean outputInitialized = false;
after output = createWriter(filename.txt); put following:
outputInitialized = true;
the output.print function has to be included in an if-function:
if (outputInitialized) {
output.println(filename);
}

gtk_container_get_children

When list of stations is printed in Preset rol list and you are at the begining or at the end of the list, you see many empty items.
I create list of about 20 stations and try to display them, go to the begining and to the end of the list.
I think the problem is in this piece of code:
static void add_button_clicked_cb(GtkWidget *widget, gpointer data)
{
preset *ps;
gchar *buffer;
GtkTreeIter iter = {0};
GtkAdjustment* v_scb;
GtkTreePath *path = NULL;
GList* menuitems;
GtkWidget *menuitem;
ps = malloc(sizeof(preset));
ps->title = g_strdup(_("unnamed"));
ps->freq = rint(gtk_adjustment_get_value(adj)) / STEPS;
settings.presets = g_list_append(settings.presets, (gpointer) ps);
buffer = g_strdup_printf("%.2f", ps->freq);
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter, 0, ps->title, 1, buffer, -1);
g_free(buffer);
gtk_tree_selection_unselect_all(selection);
v_scb = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list_view));
gtk_adjustment_set_value(v_scb, gtk_adjustment_get_upper(v_scb));
if (main_visible) {
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), ps->title);
mom_ps = g_list_length(settings.presets) - 1;
preset_combo_set_item(mom_ps);
menuitems = gtk_container_get_children(GTK_CONTAINER(tray_menu));
menuitem = gtk_menu_item_new_with_label(ps->title);
gtk_menu_shell_insert(GTK_MENU_SHELL(tray_menu), menuitem, mom_ps);
g_signal_connect(G_OBJECT(menuitem), "activate", (GCallback)preset_menuitem_activate_cb, (gpointer)mom_ps);
gtk_widget_show(menuitem);
}
buffer = g_strdup_printf("%d", g_list_length(settings.presets) - 1);
path = gtk_tree_path_new_from_string(buffer);
g_free(buffer);
gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view), path, NULL, FALSE);
gtk_tree_path_free(path);
}
Could you please suggest me how can correct it?
Inside of the if (main_visible), you have:
menuitems = gtk_container_get_children(GTK_CONTAINER(tray_menu));
That is, you're setting the value of menuitems to the return value of that function call. However, none of the rest of your code actually does anything with menuitems. So, the compiler gives you that warning.
Fixing it might be as easy as simply getting rid of menuitems:
gtk_container_get_children(GTK_CONTAINER(tray_menu));
That would definitely get rid of the warning. But you have to think about it: Maybe you should be doing something with the return value of that function call, and the reason that you're not doing anything with it is that you forgot to (or whatever).
warning: variable 'menuitems' set but not used
Your compiler in layman's terms is saying the following:
Dude... youve created a class with a few attributes, one of which are called 'menuitems'. That's all well mate, but when you actually create an instance and assign all the variables, youve set 'menuitems' but youre never using that variable to do anything with it. its just sitting there doing nothing at all. So mate it's no problem at all as I can still run your program but im just warning you that the 'menuitems' variable is doing ** all as you're never using the variable itself. Just warning you bro :D other than that have a good day
So its just a warning to let you know you have a variable no being used for any specific reason other than storing a value in there but never accessing it to do something useful. So either comment it out since youre not actually doing anything with it.. or use it, or just enjoy reading the warning but it wont affect the way your program runs.
The warnings get displayed mainly to get the developer more aware of their own code and whats happening.

How to call threadsafe rrd_update_r Round Robin Database function with C API?

Can anybody help me to find out how to call rrd_update_r function of the rrdtool c API from http://oss.oetiker.ch/rrdtool/index.en.html?
It was quite easy to call the non-threadsafe version of rrd_update, but this one is more tricky...
normal rrd_update:
char *updateparams[] = {
"rrdupdate",
rrd_file,
values,
NULL
};
rrd_clear_error();
result = rrd_update(3, updateparams); //argc is first arg
Because the programm has to run in a multithreaded environment I got several errors by not using the threadsafe functions!
But it is not so easy to use rrd_update_r, because it requires a template too...
int rrd_update_r(const char *filename, const char *_template,
int argc, const char **argv);
and I really have no idea how to create one...
char *updateparams[] = {
"rrdupdate",
rrd_file,
values,
NULL
};
rrd_clear_error();
result = rrd_update_r(rrd_file, NULL,3, updateparams);
does not work and produces the following error when executing it...
error: /var/tmp/rrds/1.rrd: expected timestamp not found in data source from rrdupdate
Hopefully someone can help me!
thx and br,
roegi
Well, looking at the source code...
It appears that rrd_update_r does not want to see the "rrupdate" argument. So try just passing rrd_file and values as a 2-element argv.
Actually the source for rrd_update is not hard to read; you can find it in src/rrd_update.c. And rrd_update_r appears to be a much lower-level function that rrd_update itself calls. So this may not actually fix your underlying problem.
Now it is working!
Nemo - thx for your help!
It was not exactly your solution but it was a hint to the right direction!
It works with:
/*
rrd_file is a char * to "/var/tmp/1.rrd"
NULL says not to use a template
1 --> argc
values is a char * to "N:value-1:value-2:.....:value-n"
*/
result = rrd_update_r(rrd_file, NULL, 1, (void *) &values);

Resources