My pipeline is like this
gst-launch-1.0 v4l2src ! videoconvert ! xvimagesink
and my code is like this
#include <gst/gst.h>
// easier to pass them as callbacks
typedef struct _CustomData{
GstElement *pipeline;
GstElement *source;
GstElement *convert;
GstElement *sink;
}CustomData;
// callback function
// here src is the v4l2src, newpad is gstpad that has just been added to src element. This is usually the pad to which we want to lnk
// data is the pointer we provided when attaching to the signal.
static void pad_added_handler(GstElement *src, GstPad *new_pad,CustomData *data)
{
GstPad *sink_pad = gst_element_get_static_pad(data->convert, "sink");
GstPadLinkReturn ret;
GstCaps *new_pad_caps = NULL;
GstStructure *new_pad_struct = NULL;
const gchar *new_pad_type = NULL;
if(gst_pad_is_linked(sink_pad))
{
g_print("we are linked. igonring\n");
}
// check the new pad types
// we have previously created a piece of pipeline which deals with videoconvert linked with xvimagesink and we will nto be able to link it to a pad producing video.
//gst-pad_get_current_caps()- retrieves current capabilities of pad
new_pad_caps = gst_pad_get_current_caps(new_pad);
new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
new_pad_type = gst_structure_get_name(new_pad_struct);
if(!g_str_has_prefix(new_pad_type, "video/x-raw"))
{
g_print("It has new pad type");
}
// gst_pad_link tries to link two pads . the link must be specified from source to sink and both pads must be owned by elements residing in same pipeline
ret = gst_pad_link(new_pad, sink_pad);
if(GST_PAD_LINK_FAILED(ret))
{
g_print("type is new_pad_type");
}
if(new_pad_caps !=NULL)
{
gst_caps_unref(new_pad_caps);
}
gst_object_unref(sink_pad);
}
int main(int argc, char *argv[])
{
GMainLoop *loop;
CustomData data;
GstBus *bus;
GstMessage *msg;
gboolean terminate = FALSE;
gst_init(&argc, &argv);
// loop = g_main_loop_new(NULL, FALSE);
// create the elements
data.source = gst_element_factory_make("v4l2src", "source");
data.convert = gst_element_factory_make("videoconvert", "convert");
data.sink = gst_element_factory_make("xvimagesink", "sink");
data.pipeline = gst_pipeline_new("new-pipeline");
if(!data.pipeline || !data.source || !data.convert || !data.sink)
{
g_printerr("Not all elements could be created\n");
return -1;
}
//we did not link source at this point of time, we will do it later
gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.convert, data.sink, NULL);
// we link convert element to sink, do not link them with source. we dont have source pads here. so we just have videoconvert->sink unlinked
// gst_element_link(data.source, data.convert);
if(!gst_element_link(data.convert,data.sink))
{
g_printerr("elements could not be linked\n");
gst_object_unref(data.pipeline);
return -1;
}
// we set the device source
//g_object_set(source, "device", "/dev/video0", NULL);
//connect to pad added signal.
// we want to attach pad added signal to source element. to do so, we are using g_signal_connect and provide callback function and datapointer.
// when source element has enough information to start producing data, it will create source pads and trigger the pad added signal. at this point, our callback is called
g_signal_connect(G_OBJECT(data.source), "pad-added", G_CALLBACK(pad_added_handler), &data );
//g_signal_connect(G_OBJECT(data.source), "pad-added", G_CALLBACK(handler), &data);
GstStateChangeReturn ret;
ret =gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (data.pipeline);
return -1;
}
// g_main_loop_run(loop);
/* Listen to the bus */
bus = gst_element_get_bus (data.pipeline);
do {
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
terminate = TRUE;
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
terminate = TRUE;
break;
case GST_MESSAGE_STATE_CHANGED:
/* We are only interested in state-changed messages from the pipeline */
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {
GstState old_state, new_state, pending_state;
gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
g_print ("Pipeline state changed from %s to %s:\n",
gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
}
break;
default:
/* We should not reach here */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
} while (!terminate);
/* Free resources */
gst_object_unref (bus);
gst_element_set_state(data.pipeline, GST_STATE_NULL);
gst_object_unref(data.pipeline);
return 0;
}
and I am getting error like this
Pipeline state changed from NULL to READY:
Pipeline state changed from READY to PAUSED:
Error received from element source: Internal data stream error.
Debugging information: gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:new-pipeline/GstV4l2Src:source:
streaming stopped, reason not-linked (-1)
Please let me know what changes should I make to make my pipeline work. Thanks! the above code is based on dynamic pipeline example from gstreamer tutorials. I dont understand where I am going wrong.
The following works though
#include <gst/gst.h>
int main(int argc, char *argv[])
{
GstElement *pipeline, *source,*filter, *convert, *sink;
GstBus *bus;
GstMessage *msg;
GstCaps *caps;
gst_init(&argc, &argv);
source = gst_element_factory_make("v4l2src", "source");
filter = gst_element_factory_make("capsfilter","filter");
convert = gst_element_factory_make("videoconvert", "convert");
sink = gst_element_factory_make("xvimagesink", "sink");\
pipeline = gst_pipeline_new("pipe");
gst_bin_add_many(GST_BIN(pipeline), source, convert,sink, NULL);
gst_element_link_many(source,convert,sink,NULL);
caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "YUY2", NULL);
g_object_set(G_OBJECT(filter), "caps", caps, NULL);
gst_element_set_state(pipeline,GST_STATE_PLAYING);
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref(bus);
gst_element_set_state(pipeline,GST_STATE_NULL);
gst_object_unref(pipeline);
}
Any ideas why if I add pads, it is not working well??
Even in included HTTP get demo sdk_wifi_station_get_connect_status() returns 255 even before try to connect. And of course it refuses to connect to
There is no any documentation this status.
Is there any suggestion on this issue?
you need to config the esp on user_init() function and call function sdk_wifi_station_get_connect_status() inside a task
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ssid_config.h"
#include "esp8266.h"
void task1(void *pvParameters)
{
while (1)
{
check_wifi_connection();
}
}
void check_wifi_connection()
{
uint8_t status = sdk_wifi_station_get_connect_status();
while (status != STATION_GOT_IP)
{
status = sdk_wifi_station_get_connect_status();
vTaskDelay(ONE_SEC / portTICK_PERIOD_MS);
switch (status)
{
case STATION_WRONG_PASSWORD:
printf("WiFi: wrong password\n\r");
break;
case STATION_NO_AP_FOUND:
printf("WiFi: AP not found\n\r");
break;
case STATION_CONNECT_FAIL:
printf("WiFi: connection failed\r\n");
break;
case STATION_GOT_IP:
break;
default:
printf("%s: status = %d\n\r", __func__, status);
break;
}
}
}
void user_init(void)
{
uart_set_baud(0, BAUDRATE);
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_auto_connect(true);
sdk_wifi_station_set_config(&config);// my config that
gpio_enable(gpio, GPIO_INPUT);
tsqueue = xQueueCreate(2, sizeof(uint32_t));
xTaskCreate(&task1,
"task1",
2048,
NULL,
tskIDLE_PRIORITY,
&task_handler);
}
I was trying to make a simple push button and led with BBB, and I successed to make it work. But my question is, the led supposed to be turned off before I press the button, but with this the led is automatically turned on when I run the code, and turned off when I press the button. I'm trying to set the pull up/down resistor by cd /sys/class/gpio/gpio44/ - echo 0 > value but its "operation not permitted" warning always appears. Can someone help me? Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
void sig_handler(int signo)
{
if (signo == SIGINT)
printf("\nRecieved SIGINT\n");
exit(1);
}
void GPIOREAD(char *url, char* val)
{
FILE *path = fopen(url,"r");
fread(val, 2, 1, path);
fclose(path);
}
int main(void)
{
int status;
unsigned int cnt=0;
status = access("/sys/class/gpio/gpio44/value", F_OK );
if (status == -1)
{
//file doesnt exist
printf("GPIO_44 file doesnt exist dude\n");
exit(1);
}
status = access("/sys/class/gpio/gpio45/value", F_OK );
if (status == -1)
{
//file doesnt exist
printf("GPIO_45 file doesnt exist dude\n");
exit(1);
}
//set GPIO 45 as output
system("echo in > /sys/class/gpio/gpio44/direction");
system("echo out > /sys/class/gpio/gpio45/direction");
sleep(1);
char val[10];
while(1)
{
GPIOREAD("/sys/class/gpio/gpio44/value", val);
printf("BUTTON STAT %s\n", val);
if(!strcmp(val,"1\n"))
{
printf("%u) AAA LED --- ON\n", cnt);
system("echo 1 > /sys/class/gpio/gpio45/value");
}
else
{
printf("%u) AAA LED --- OFF\n", cnt);
system("echo 0 > /sys/class/gpio/gpio45/value");
}
}
return 0;
}
Are you running as root? Typically the files in /sys/class/gpio are owned by root, so you might simply have a permissions problem. Within your code, the mix of file operations and system(3) is unusual. Might be happier focusing on file ops only (but still must run as root). Good luck.
Hello, the question is, when I using libgit2 to clone a repo, it will result : "Failed to send request: A security error occurred", the code is:
#include <windows.h>
#include "include/git2.h"
#pragma comment(lib, "git2.lib")
int main(int argc, char* argv[])
{
git_threads_init();
git_repository* repo = NULL;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
int iRetVal;
opts.bare = true;
iRetVal = git_clone(&repo, "https://github.com/libgit2/libgit2.git", "C:\\test", &opts);
if( (iRetVal < 0) && (giterr_last() != NULL) )
{
MessageBox(NULL, giterr_last()->message, "gittest", MB_ICONERROR | MB_OK);
}
if( repo != NULL )
git_repository_free(repo);
git_threads_shutdown();
return 0;
}
The libgit2 version is 0.21.2
You have to populate the remote_callbacks property of the git_clone_options.
Thoses online::clone.c tests which perform an authenticated cloning should you getting started.
I'm trying to present to the screen an error output when the user enters an incomplete
define , e.g :
#define A // this is wrong , error message should appear
#define A 5 // this is the correct form , no error message would be presented
but it doesn't work , here's the code :
%{
#include <stdio.h>
#include <string.h>
%}
%s FULLCOMMENT
%s LINECOMMENT
%s DEFINE
%s INCLUDE
%s PRINT
%s PSEUDO_C_CODE
STRING [^ \n]*
%%
<FULLCOMMENT>"*/" { BEGIN INITIAL; }
<FULLCOMMENT>. { /* Do Nothing */ }
<INCLUDE>"<stdio.h>"|"<stdlib.h>"|"<string.h>" { BEGIN INITIAL; }
<INCLUDE>. { printf("error\n"); return 0 ; }
<DEFINE>[ \t] { printf("eat a space within define\n"); }
<DEFINE>{STRING} { printf("eat string %s\n" , yytext);}
<DEFINE>\n { printf("eat a break line within define\n"); BEGIN INITIAL; }
"#include" { BEGIN INCLUDE; }
"#define" { printf("you gonna to define\n"); BEGIN DEFINE; }
"#define"+. { printf("error\n"); }
%%
int yywrap(void) { return 1; } // Callback at end of file
int main(void) {
yylex();
return 0 ;
}
Where did I go wrong ?
Here is the output :
a#ubuntu:~/Desktop$ ./a.out
#define A 4
error
A 4
#define A
error
A
The rule "#define"+. is longer and gets precedence over the earlier #define even for correct input. You could say just this :-
"#define"[:space:]*$ {printf("error\n"); }
Consider using the -dvT options with flex to get detailed debug output. Also I am not sure if you need such extensive use of states for anything except maybe comments. But you would know better.