diff --git a/Makefile b/Makefile index ee45db4..7ab9a12 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ OMVS_VERSION = 0.1 TARGET = omvs OBJS = \ - omvs_main.o + omvs_main.o \ + omvs_gst.o CC = gcc LD = gcc RM = rm -rf diff --git a/omvs_gst.c b/omvs_gst.c new file mode 100644 index 0000000..ab1d88f --- /dev/null +++ b/omvs_gst.c @@ -0,0 +1,71 @@ +/* + Oh! Multicast Video Scanner + Copyright (C) 2016 Taeho Oh + + This file is part of Oh! Multicast Video Scanner. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include "omvs_gst.h" + +typedef struct _OMVSGstImpl { + GstElement *play; +} OMVSGstImpl; + +OMVSGst omvs_gst_open(const gchar *uri, const gchar *filename) { + OMVSGstImpl *gst_impl; + GstElement *play; + GstElement *png; + GstElement *file; + GstElement *pngfile; + GstPad *pad; + GstPad *ghostpad; + + gst_impl = g_malloc0(sizeof(OMVSGstImpl)); + gst_impl->play = play = gst_element_factory_make("playbin", "play"); + g_object_set(G_OBJECT(play), "uri", uri, NULL); + png = gst_element_factory_make("pngenc", "png"); + g_object_set(G_OBJECT(png), "snapshot", 1, NULL); + file = gst_element_factory_make("multifilesink", "file"); + g_object_set(G_OBJECT(file), "max-files", 1, "location", filename, NULL); + + pngfile = gst_bin_new("pngfile"); + gst_bin_add_many(GST_BIN(pngfile), png, file, NULL); + pad = gst_element_get_static_pad(png, "sink"); + ghostpad = gst_ghost_pad_new("sink", pad); + gst_element_add_pad(pngfile, ghostpad); + gst_object_unref(GST_OBJECT(pad)); + + g_object_set(play, "video-sink", pngfile, NULL); + g_object_set(play, "mute", TRUE, NULL); + + gst_element_set_state(play, GST_STATE_PLAYING); + + return (OMVSGst)gst_impl; +} + +gint omvs_gst_close(OMVSGst gst) { + OMVSGstImpl *gst_impl; + + gst_impl = (OMVSGstImpl *)gst; + if (gst_impl) { + gst_element_set_state(gst_impl->play, GST_STATE_NULL); + gst_object_unref(gst_impl->play); + g_free(gst_impl); + } + + return 0; +} diff --git a/omvs_gst.h b/omvs_gst.h new file mode 100644 index 0000000..633879d --- /dev/null +++ b/omvs_gst.h @@ -0,0 +1,31 @@ +/* + Oh! Multicast Video Scanner + Copyright (C) 2016 Taeho Oh + + This file is part of Oh! Multicast Video Scanner. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _OMVS_GST_H_ +#define _OMVS_GST_H_ + +#include + +typedef void *OMVSGst; + +extern OMVSGst omvs_gst_open(const gchar *uri, const gchar *filename); +extern gint omvs_gst_close(OMVSGst gst); + +#endif /* _OMVS_GST_H_ */