diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96fe570..294207c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(wifi) add_subdirectory(dhcp) add_subdirectory(ctl) add_subdirectory(uibc) +add_subdirectory(stream) set(miracled_SRCS miracled.h miracled.c) add_executable(miracled ${miracled_SRCS}) diff --git a/src/stream/CMakeLists.txt b/src/stream/CMakeLists.txt new file mode 100644 index 0000000..a40e416 --- /dev/null +++ b/src/stream/CMakeLists.txt @@ -0,0 +1,10 @@ +pkg_check_modules(GST REQUIRED gstreamer-1.0) +pkg_check_modules(GST_PBUTILS REQUIRED gstreamer-pbutils-1.0) + +include_directories(${GST_INCLUDE_DIRS} ${GST_PBUTILS_INCLUDE_DIRS}) + +add_executable(miracle-sender sender) + +target_link_libraries(miracle-sender ${GST_LIBRARIES} ${GST_PBUTILS_LIBRARIES}) + +install(TARGETS miracle-sender DESTINATION bin) diff --git a/src/stream/sender.c b/src/stream/sender.c new file mode 100644 index 0000000..26e075f --- /dev/null +++ b/src/stream/sender.c @@ -0,0 +1,86 @@ +/* + * ===================================================================================== + * + * Filename: sender.c + * + * Description: + * + * Version: 1.0 + * Created: 2016年10月17日 18時11分16秒 + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ +#include +#include +#include +#include +#include +#include + +int main(int argc, char *args[]) +{ + GMainLoop *loop; + GstElement *pipeline; + GError *error = NULL; + + gst_init(&argc, &args); + gst_pb_utils_init(); + + GString *desc = g_string_new(""); + g_string_append_printf(desc, + "ximagesrc " + "! videoscale " + "! video/x-raw, width=%d, height=%d, framerate=%d/1 " + "! videoconvert name=vconverter " + "! video/x-raw, format=NV12 " + "! encodebin name=encoder " + "! rtpmp2tpay " + "! udpsink host=%s port=%d ", + 1280, 720, 30, + "127.0.0.1", + 1991); + + pipeline = gst_parse_launch(desc->str, &error); + if(GST_PARSE_ERROR_LINK != error->code) { + g_error("%s", error->message); + goto error; + } + + GstCaps *caps = gst_caps_from_string("video/mpegts, systemstream=true, packetsize=188"); + GstEncodingContainerProfile *container = gst_encoding_container_profile_new("mpeg-ts-profile", + NULL, + caps, + NULL); + gst_caps_unref(caps); + + caps = gst_caps_from_string("video/x-h264, format=YV12, width=1280, height=720"); + GstEncodingVideoProfile *vencoder = gst_encoding_video_profile_new(caps, NULL, NULL, 0); + gst_caps_unref(caps); + + gst_encoding_container_profile_add_profile(container, GST_ENCODING_PROFILE(vencoder)); + /*g_object_unref(vencoder);*/ + + GstElement *encoder = gst_bin_get_by_name(GST_BIN(pipeline), "encoder"); + g_object_set(G_OBJECT(encoder), "profile", container, NULL); + /*g_object_unref(container);*/ + + GstElement *vconverter = gst_bin_get_by_name(GST_BIN(pipeline), "vconverter"); + if(!gst_element_link(vconverter, encoder)) { + printf("failed to link vconverter to encoder\n"); + } + + gst_element_set_state(pipeline, GST_STATE_PLAYING); + + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + +error: + g_object_unref(pipeline); +end: + return 0; +}