\hypertarget{ecore_pipe_gstreamer_example_8c-example}{}\doxysection{ecore\+\_\+pipe\+\_\+gstreamer\+\_\+example.\+c}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/o\ ecore\_pipe\_gstreamer\_example\ ecore\_pipe\_gstreamer\_example.c\ `pkg-\/config\ -\/-\/libs\ -\/-\/cflags\ ecore\ gstreamer-\/1.0`}}
\DoxyCodeLine{\textcolor{comment}{//\ or}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/o\ ecore\_pipe\_gstreamer\_example\ ecore\_pipe\_gstreamer\_example.c\ `pkg-\/config\ -\/-\/libs\ -\/-\/cflags\ ecore\ gstreamer-\/0.10`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <gst/gst.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ nbr\ =\ 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ GstElement\ *\_build\_pipeline(gchar\ *filename,\ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ \ \ \ \ \ \ \ new\_decoded\_pad\_cb(GstElement\ *demuxer,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GstPad\ *new\_pad,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ gpointer\ user\_data);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{handler(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{void}\ *buf,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ len\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ GstBuffer\ *buffer\ =\ *((GstBuffer\ **)buf);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}handler\ :\ \%p\(\backslash\)n"{}},\ buffer);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}frame\ \ :\ \%d\ \%p\ \%lld\ \%p\(\backslash\)n"{}},\ nbr++,\ data,\ (\textcolor{keywordtype}{long}\ \textcolor{keywordtype}{long})GST\_BUFFER\_DURATION(buffer),\ buffer);}
\DoxyCodeLine{\ \ \ gst\_buffer\_unref(buffer);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{handoff(GstElement\ *\textcolor{keywordtype}{object}\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ GstBuffer\ *arg0,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ GstPad\ *arg1\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gpointer\ user\_data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ pipe\ =\ (\mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *)user\_data;}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}handoff\ :\ \%p\(\backslash\)n"{}},\ arg0);}
\DoxyCodeLine{\ \ \ gst\_buffer\_ref(arg0);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga5336bc71e829c391926c26750ae0f407}{ecore\_pipe\_write}}(pipe,\ \&arg0,\ \textcolor{keyword}{sizeof}(arg0));}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ GstElement\ *pipeline;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ *filename;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ gst\_init(\&argc,\ \&argv);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}())}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gst\_deinit();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ pipe\ =\ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa1fb078d1865197887f558e19532e02d}{ecore\_pipe\_add}}(handler,\ NULL);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!pipe)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gst\_deinit();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (argc\ <\ 2)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ g\_print(\textcolor{stringliteral}{"{}usage:\ \%s\ file.avi\(\backslash\)n"{}},\ argv[0]);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa7ed35ca29f47097e30ccd83776d5866}{ecore\_pipe\_del}}(pipe);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gst\_deinit();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ filename\ =\ argv[1];}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ pipeline\ =\ \_build\_pipeline(filename,\ pipe);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!pipeline)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ g\_print(\textcolor{stringliteral}{"{}Error\ during\ the\ pipeline\ building\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa7ed35ca29f47097e30ccd83776d5866}{ecore\_pipe\_del}}(pipe);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gst\_deinit();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ gst\_element\_set\_state(pipeline,\ GST\_STATE\_PLAYING);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Pipe__Group_gaa7ed35ca29f47097e30ccd83776d5866}{ecore\_pipe\_del}}(pipe);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{\ \ \ gst\_deinit();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{new\_decoded\_pad\_cb(GstElement\ *demuxer\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GstPad\ *new\_pad,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ gpointer\ user\_data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ GstElement\ *decoder;}
\DoxyCodeLine{\ \ \ GstPad\ *pad;}
\DoxyCodeLine{\ \ \ GstCaps\ *caps;}
\DoxyCodeLine{\ \ \ GstStructure\ *s;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ gchar\ *str;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#if\ GST\_CHECK\_VERSION(1,0,0)}}
\DoxyCodeLine{\ \ \ caps\ =\ gst\_pad\_get\_current\_caps(new\_pad);}
\DoxyCodeLine{\textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\ \ \ caps\ =\ gst\_pad\_get\_caps(new\_pad);}
\DoxyCodeLine{\textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\ \ \ s\ =\ gst\_caps\_get\_structure(caps,\ 0);}
\DoxyCodeLine{\ \ \ str\ =\ gst\_structure\_get\_name(s);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (g\_str\_has\_prefix(str,\ \textcolor{stringliteral}{"{}video/"{}}))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ decoder\ =\ GST\_ELEMENT(user\_data);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#if\ GST\_CHECK\_VERSION(1,0,0)}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ pad\ =\ gst\_element\_get\_static\_pad(decoder,\ \textcolor{stringliteral}{"{}sink"{}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ pad\ =\ gst\_element\_get\_pad(decoder,\ \textcolor{stringliteral}{"{}sink"{}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (GST\_PAD\_LINK\_FAILED(gst\_pad\_link(new\_pad,\ pad)))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ g\_warning(\textcolor{stringliteral}{"{}Failed\ to\ link\ \%s:\%s\ to\ \%s:\%s"{}},\ GST\_DEBUG\_PAD\_NAME(new\_pad),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GST\_DEBUG\_PAD\_NAME(pad));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gst\_object\_unref(pad);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ gst\_caps\_unref(caps);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ GstElement\ *}
\DoxyCodeLine{\_build\_pipeline(gchar\ *filename,\ \mbox{\hyperlink{group__Ecore__Pipe__Group_ga0092a6b764881362d1a051d7af215b3f}{Ecore\_Pipe}}\ *pipe)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ GstElement\ *pipeline;}
\DoxyCodeLine{\ \ \ GstElement\ *filesrc;}
\DoxyCodeLine{\ \ \ GstElement\ *demuxer;}
\DoxyCodeLine{\ \ \ GstElement\ *decoder;}
\DoxyCodeLine{\ \ \ GstElement\ *sink;}
\DoxyCodeLine{\ \ \ GstStateChangeReturn\ res;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ pipeline\ =\ gst\_pipeline\_new(\textcolor{stringliteral}{"{}pipeline"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!pipeline)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ filesrc\ =\ gst\_element\_factory\_make(\textcolor{stringliteral}{"{}filesrc"{}},\ \textcolor{stringliteral}{"{}filesrc"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!filesrc)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}no\ filesrc"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ g\_object\_set(G\_OBJECT(filesrc),\ \textcolor{stringliteral}{"{}location"{}},\ filename,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ demuxer\ =\ gst\_element\_factory\_make(\textcolor{stringliteral}{"{}oggdemux"{}},\ \textcolor{stringliteral}{"{}demuxer"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!demuxer)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}no\ demux"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ decoder\ =\ gst\_element\_factory\_make(\textcolor{stringliteral}{"{}theoradec"{}},\ \textcolor{stringliteral}{"{}decoder"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!decoder)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}no\ dec"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ g\_signal\_connect(demuxer,\ \textcolor{stringliteral}{"{}pad-\/added"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ G\_CALLBACK(new\_decoded\_pad\_cb),\ decoder);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ sink\ =\ gst\_element\_factory\_make(\textcolor{stringliteral}{"{}fakesink"{}},\ \textcolor{stringliteral}{"{}sink"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!sink)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}no\ sink"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ g\_object\_set(G\_OBJECT(sink),\ \textcolor{stringliteral}{"{}sync"{}},\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}},\ NULL);}
\DoxyCodeLine{\ \ \ g\_object\_set(G\_OBJECT(sink),\ \textcolor{stringliteral}{"{}signal-\/handoffs"{}},\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}},\ NULL);}
\DoxyCodeLine{\ \ \ g\_signal\_connect(sink,\ \textcolor{stringliteral}{"{}handoff"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ G\_CALLBACK(handoff),\ pipe);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ gst\_bin\_add\_many(GST\_BIN(pipeline),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ filesrc,\ demuxer,\ decoder,\ sink,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!gst\_element\_link(filesrc,\ demuxer))}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!gst\_element\_link(decoder,\ sink))}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ res\ =\ gst\_element\_set\_state(pipeline,\ GST\_STATE\_PAUSED);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (res\ ==\ GST\_STATE\_CHANGE\_FAILURE)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ res\ =\ gst\_element\_get\_state(pipeline,\ NULL,\ NULL,\ GST\_CLOCK\_TIME\_NONE);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (res\ !=\ GST\_STATE\_CHANGE\_SUCCESS)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{goto}\ failure;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ pipeline;}
\DoxyCodeLine{}
\DoxyCodeLine{failure:}
\DoxyCodeLine{\ \ \ gst\_object\_unref(GST\_OBJECT(pipeline));}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 