Skip to content

Commit

Permalink
fixed running on imx6 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yjdwbj committed Jul 28, 2024
1 parent f266efc commit b0fbec5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
EXE=gwc

ifeq ($(ARCH),arm)
CFLAGS :=-g -Wall -fno-omit-frame-pointer
CFLAGS :=-g -Wall -fno-omit-frame-pointer -DJETSON_NANO=0
ARCH := arm
CROSS_COMPILE := arm-linux-gnueabi-
CC :=$(CROSS_COMPILE)gcc
Expand All @@ -15,6 +15,7 @@ endif

ifeq ($(ARCH),arm64)
CFLAGS :=-g -Wall -fno-omit-frame-pointer -DJETSON_NANO=$$(bash -c 'if [ -f /etc/nv_tegra_release ]; then echo 1; else echo 0; fi')

ARCH := arm64
CROSS_COMPILE := aarch64-linux-gnu-
CC :=$(CROSS_COMPILE)gcc
Expand All @@ -24,7 +25,7 @@ LDFLAGS :=--sysroot=${SYSROOT} -L${SYSROOT}/usr/lib/aarch64-linux-gnu -Wl,-dynam
endif

ifeq ($(ARCH),amd64)
CFLAGS :=-g -Wall -fno-omit-frame-pointer
CFLAGS :=-g -Wall -fno-omit-frame-pointer -DJETSON_NANO=0

endif

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ You'll need `meson`, the `gstreamer-plugins-bad,gstreamer-plugins-good` library,
## Install runtime Environment

```sh
~$ sudo apt-get install -y
gstreamer1.0-x gstreamer1.0-opencv \
~$ sudo apt-get install \
gstreamer1.0-x \
gstreamer1.0-nice \
gstreamer1.0-opencv \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-base \
Expand All @@ -42,7 +44,7 @@ You'll need `meson`, the `gstreamer-plugins-bad,gstreamer-plugins-good` library,
libgstreamer-plugins-base1.0-0 \
libgstreamer-opencv1.0-0 \
libgstreamer1.0-0 libsoup-3.0-0 \
libjson-glib-1.0-0 sqlite3
libjson-glib-1.0-0 sqlite3 -y
```

## Install Development Environment (Optional)
Expand Down
4 changes: 3 additions & 1 deletion gst-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@ static GstElement *get_video_src() {
jpegdec = gst_element_factory_make("vajpegdec", NULL);
else if (gst_element_factory_find("vaapijpegdec"))
jpegdec = gst_element_factory_make("vaapijpegdec", NULL);
#if 0
else if (gst_element_factory_find("v4l2jpegdec"))
jpegdec = gst_element_factory_make("v4l2jpegdec", NULL);
#endif
else {
jpegdec = gst_element_factory_make("jpegdec", NULL);
jpegparse = gst_element_factory_make("jpegparse", NULL);
Expand Down Expand Up @@ -2167,7 +2169,7 @@ int start_av_udpsink() {
if (g_str_has_prefix(config_data.videnc, "h26")) {
g_object_set(video_pay, "config-interval", -1, "aggregate-mode", 1, NULL);
}
g_object_set(vqueue, "max-size-time", 100000000, NULL);
// g_object_set(vqueue, "max-size-time", 100000000, NULL);

if (g_strcmp0(config_data.videnc, "vp8")) {
// vp8parse not avavilable ?
Expand Down
58 changes: 45 additions & 13 deletions webrtc-sendonly.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ struct _APPData {
int port;
gchar *udphost; // for udpsink and udpsrc
int udpport;
gchar *iface; // multicast iface
};

static AppData gs_app = {
NULL, NULL, NULL, NULL,
"/dev/video0", "video/x-raw,width=800,height=600,format=YUY2,framerate=25/1", NULL, "test", "test1234", 57778, "127.0.0.1", 5000};
"/dev/video0",
"video/x-raw,width=800,height=600,format=YUY2,framerate=25/1",
NULL,
"test",
"test1234", 57778, "127.0.0.1", 5000,
"lo"};

static void start_http(AppData *app);

Expand Down Expand Up @@ -145,6 +151,7 @@ ReceiverEntry *
create_receiver_entry(SoupWebsocketConnection *connection, AppData *app) {
ReceiverEntry *receiver_entry;
gchar *cmdline = NULL;
GError *error = NULL;

receiver_entry = g_new0(ReceiverEntry, 1);
receiver_entry->connection = connection;
Expand All @@ -155,16 +162,16 @@ create_receiver_entry(SoupWebsocketConnection *connection, AppData *app) {

// gchar *turn_srv = NULL;
gchar *webrtc_name = g_strdup_printf("send_%" G_GUINT64_FORMAT, (u_long)(receiver_entry->connection));
gchar *video_src = g_strdup_printf("udpsrc port=%d multicast-group=%s multicast-iface=lo ! "
gchar *video_src = g_strdup_printf("udpsrc port=%d multicast-group=%s multicast-iface=%s ! "
" application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96 ! "
" rtph264depay ! rtph264pay config-interval=-1 aggregate-mode=1 ! %s. ",
app->udpport, app->udphost, webrtc_name);
app->udpport, app->udphost, app->iface, webrtc_name);
if (app->audio_dev != NULL) {
gchar *audio_src = g_strdup_printf("udpsrc port=%d multicast-group=%s multicast-iface=lo ! "
gchar *audio_src = g_strdup_printf("udpsrc port=%d multicast-group=%s multicast-iface=%s ! "
" application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)OPUS,payload=(int)97 ! "
" rtpopusdepay ! rtpopuspay ! "
" queue leaky=1 ! %s.",
app->udpport + 1, app->udphost, webrtc_name);
app->udpport + 1, app->udphost, app->iface, webrtc_name);
cmdline = g_strdup_printf("webrtcbin name=%s stun-server=%s %s %s ", webrtc_name, STUN_SERVER, audio_src, video_src);
g_print("webrtc cmdline: %s \n", cmdline);
g_free(audio_src);
Expand All @@ -177,7 +184,14 @@ create_receiver_entry(SoupWebsocketConnection *connection, AppData *app) {
// g_free(turn_srv);
}
g_print("webrtc cmdline: %s\n", cmdline);
receiver_entry->pipeline = gst_parse_launch(cmdline, NULL);
receiver_entry->pipeline = gst_parse_launch(cmdline, &error);
if (error) {
gchar *message = g_strdup_printf("Unable to start cmdline: %s\n", error->message);
g_print("%s", message);
g_free(message);
g_error_free(error);
}

gst_element_set_state(receiver_entry->pipeline, GST_STATE_READY);
g_free(cmdline);

Expand Down Expand Up @@ -424,12 +438,24 @@ void soup_websocket_closed_cb(SoupWebsocketConnection *connection,
gst_print("Closed websocket connection %p\n", (gpointer)connection);
}

static gchar full_web_path[MAX_URL_LEN] = {0};

#include <sys/stat.h>
static void
do_get(SoupServer *server, SoupServerMessage *msg, const char *path) {
struct stat st;

if (stat(path, &st) == -1) {
gchar *tpath = g_strconcat("/home/", g_getenv("USER"), "/.config/gwc/", path[0] == '.' ? &path[1] : path, NULL);
if (strlen(tpath) >= MAX_URL_LEN) {
soup_server_message_set_status(msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
g_free(tpath);
return;
}
memset(&full_web_path, 0, MAX_URL_LEN);
memcpy(full_web_path, tpath, strlen(tpath));
g_free(tpath);

if (stat(full_web_path, &st) == -1) {
if (errno == EPERM)
soup_server_message_set_status(msg, SOUP_STATUS_FORBIDDEN, NULL);
else if (errno == ENOENT)
Expand All @@ -451,7 +477,7 @@ do_get(SoupServer *server, SoupServerMessage *msg, const char *path) {
if (soup_server_message_get_method(msg) == SOUP_METHOD_GET) {
GMappedFile *mapping;
GBytes *buffer;
mapping = g_mapped_file_new(path, FALSE, NULL);
mapping = g_mapped_file_new(full_web_path, FALSE, NULL);
if (!mapping) {
soup_server_message_set_status(msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
return;
Expand Down Expand Up @@ -667,6 +693,7 @@ static GOptionEntry entries[] = {
{"port", 0, 0, G_OPTION_ARG_INT, &gs_app.port, "Port to listen on (default: 57778 )", "PORT"},
{"udphost", 0, 0, G_OPTION_ARG_STRING, &gs_app.udphost, "Address for udpsink (default : 224.1.1.5)", "ADDR"},
{"udpport", 0, 0, G_OPTION_ARG_INT, &gs_app.udpport, "Port for udpsink (default: 5000 )", "PORT"},
{"iface", 0, 0, G_OPTION_ARG_STRING, &gs_app.iface, "multicast iface (default: lo )", "IFACE"},
{NULL}};

int main(int argc, char *argv[]) {
Expand Down Expand Up @@ -701,7 +728,7 @@ int main(int argc, char *argv[]) {
if (gst_element_factory_find("vaapih264enc"))
enc = g_strdup("vaapih264enc");
else if (gst_element_factory_find("v4l2h264enc"))
enc = g_strdup(" video/x-raw,format=I420 ! v4l2h264enc");
enc = g_strdup(" video/x-raw,format=I420 ! v4l2h264enc ");
else
enc = g_strdup(" video/x-raw,format=I420 ! x264enc ! h264parse");

Expand All @@ -718,11 +745,16 @@ int main(int argc, char *argv[]) {
jpegdec = g_strdup("vaapijpegdec");
strvcaps = g_strdup_printf("%s ! %s ", app->video_caps, jpegdec);
} else {
#if 0
if (gst_element_factory_find("v4l2jpegdec")) {
jpegdec = g_strdup("v4l2jpegdec");
} else {
jpegdec = g_strdup("jpegdec");
}
#else
jpegdec = g_strdup("jpegdec");
#endif

strvcaps = g_strdup_printf("%s ! jpegparse ! %s ", app->video_caps, jpegdec);
}

Expand All @@ -732,16 +764,16 @@ int main(int argc, char *argv[]) {
gchar *cmdline = g_strdup_printf(
"v4l2src device=%s ! %s ! videoconvert ! %s ! %s ! %s ! rtph264pay config-interval=-1 aggregate-mode=1 ! "
" application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96 ! "
" queue leaky=1 ! udpsink port=%d host=%s multicast-iface=lo async=false sync=false ",
app->video_dev, strvcaps, clockstr, textoverlay, enc, app->udpport, app->udphost);
" queue leaky=1 ! udpsink port=%d host=%s multicast-iface=%s async=false sync=false ",
app->video_dev, strvcaps, clockstr, textoverlay, enc, app->udpport, app->udphost, app->iface);
g_free(strvcaps);
g_free(enc);

if (app->audio_dev != NULL) {
gchar *tmp = g_strdup_printf("alsasrc device=%s ! audioconvert ! opusenc ! rtpopuspay ! "
" application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)OPUS,payload=(int)97 ! "
" queue leaky=1 ! udpsink port=%d host=%s multicast-iface=lo async=false sync=false %s",
app->audio_dev, app->udpport + 1, app->udphost, cmdline);
" queue leaky=1 ! udpsink port=%d host=%s multicast-iface=%s async=false sync=false %s",
app->audio_dev, app->udpport + 1, app->udphost, app->iface, cmdline);
g_free(cmdline);
cmdline = g_strdup(tmp);
g_free(tmp);
Expand Down

0 comments on commit b0fbec5

Please sign in to comment.