Hi.
I'm a new with gstreamer and glib. Why can't I init pipeline in function and then use it somewhere else. Here is the code example: void initPipeline( GstElement * pipeline ) { pipeline = gst_pipeline_new( "camera" ) } void main() { GstElement * pipeline; initPipeline( pipeline ); // And here pipeline == 0 !!! Why? } -- Regards, Igor Mironchick ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
You're passing the pointer by value, you need to pass its address. Also, you need to call gst_init beforehand, so your code should look like:
#include <gst/gst.h> void initPipeline(GstElement **pipeline) { *pipeline = gst_pipeline_new("camera"); } int main(int argc, char **argv) { gst_init(&argc, &argv); GstElement *pipeline; initPipeline(&pipeline); return 0; } 2010/4/22 Igor Mironchick <[hidden email]> Hi. -- Tristan Matthews email: [hidden email] web: http://tristanswork.blogspot.com ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
Administrator
|
In reply to this post by Igor Mironchick
You can't change the function arguments in C, as they are passed by value.
You can, however, pass a pointer (a memory address) to a function, and it can write something to that address. This will cause changing of values of some variables outside the function. You must return the pointer from the function. gst_pipeline_new allocates the memory and stores it in the variable pipeline, but this variable is lost when the function returns. |
Administrator
|
I mean, make outside-visible changes of arguments. |
In reply to this post by Tristan Matthews-2
You're passing the pointer by value, you need to pass its address. Also, you need to call gst_init beforehand, so your code should look like: Thx for your reply. I've already found the solution. But a little bit in another way: void initPipeline( GstElement *& pipeline ) { pipeline = ... } void main() { ... GstElement * pipeline; initPipeline( pipeline ); ... } -- Regards, Igor Mironchick ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
Try in this Way:
#include <gst/gst.h> GstElement* initPipeline() { return(gst_pipeline_new("camera")); } int main(int argc, char **argv) { gst_init(&argc, &argv); GstElement *pipeline = initPipeline(); // // Now you can use pipeline // return 0; } Giorgio Il giorno gio, 22/04/2010 alle 10.58 +0300, Igor Mironchick ha scritto: > > > You're passing the pointer by value, you need to pass its > address. Also, you need to call gst_init beforehand, so your > code should look like: > > #include <gst/gst.h> > > void initPipeline(GstElement **pipeline) > { > *pipeline = gst_pipeline_new("camera"); > } > > int main(int argc, char **argv) > { > gst_init(&argc, &argv); > GstElement *pipeline; > initPipeline(&pipeline); > return 0; > } > > Thx for your reply. I've already found the solution. But a little bit > in another way: > > void initPipeline( GstElement *& pipeline ) > { > pipeline = ... > } > > void main() > { > ... > GstElement * pipeline; > initPipeline( pipeline ); > ... > } > > > > > -- > Regards, > Igor Mironchick > ------------------------------------------------------------------------------ > _______________________________________________ > gstreamer-devel mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/gstreamer-devel ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
In reply to this post by Igor Mironchick
uisng:
(* pipeline) = gst_pipeline_new( "camera" ); in initPipeline should work, but I don't see what this extra function call in main() actually buys you. ________________________________________ From: Igor Mironchick [[hidden email]] Sent: Thursday, April 22, 2010 2:08 AM To: Discussion of the development of GStreamer Subject: [gst-devel] Init pipeline in the function Hi. I'm a new with gstreamer and glib. Why can't I init pipeline in function and then use it somewhere else. Here is the code example: void initPipeline( GstElement * pipeline ) { pipeline = gst_pipeline_new( "camera" ) } void main() { GstElement * pipeline; initPipeline( pipeline ); // And here pipeline == 0 !!! Why? } -- Regards, Igor Mironchick ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
Administrator
|
In reply to this post by Igor Mironchick
The correct answer since nobody was able to come up with it (although
one was very close): -------------------------------- static GstElement * createPipeline (void) { GstElement * pipeline; pipeline = gst_pipeline_new ("mylittleponypipeline"); /* Do stuff with the pipeline, fill it in, etc... */ return pipeline; } void main (int argc, gchar **argv) { GstElement * pipeline; /* Initialize GStreamer, parse arguments, etc.. */ pipeline = createPipeline (); /* Use pipeline */ } --------------------------------------- I recommend everybody who replied to the list to read Kernighan & Ritchie "The C programming language" [1] as well as reading examples and learning how to use google. Edward [1] http://en.wikipedia.org/wiki/The_C_Programming_Language_%28book%29 On Thu, 2010-04-22 at 10:08 +0300, Igor Mironchick wrote: > Hi. > > I'm a new with gstreamer and glib. > > Why can't I init pipeline in function and then use it somewhere else. > > Here is the code example: > > void initPipeline( GstElement * pipeline ) > { > pipeline = gst_pipeline_new( "camera" ) > } > > void main() > { > GstElement * pipeline; > > initPipeline( pipeline ); > > // And here pipeline == 0 !!! Why? > } > > -- > Regards, > Igor Mironchick > ------------------------------------------------------------------------------ > _______________________________________________ > gstreamer-devel mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/gstreamer-devel ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
2010/4/23 Edward Hervey <[hidden email]> The correct answer since nobody was able to come up with it (although Could you clarify what you considered incorrect in my response? -------------------------------- -- Tristan Matthews email: [hidden email] web: http://tristanswork.blogspot.com ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
2010/4/23 Tristan Matthews <[hidden email]>
Unless it's a mixed declarations and code issue (C90 and earlier), in which case you'll have to forgive my c++ contaminated style :)
-- Tristan Matthews email: [hidden email] web: http://tristanswork.blogspot.com ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
Administrator
|
In reply to this post by Tristan Matthews-2
On Fri, 2010-04-23 at 10:45 -0400, Tristan Matthews wrote:
> > Could you clarify what you considered incorrect in my response? You answer was compilable code alright. Just way too obfuscated for a simple answer which, considering the basic error the person asking the question did, was much needed :) Edward ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
2010/4/23 Edward Hervey <[hidden email]>
Fair enough, I wanted to demonstrate pointer semantics...but a stack overflow link might have been more appropriate. Best, Tristan
-- Tristan Matthews email: [hidden email] web: http://tristanswork.blogspot.com ------------------------------------------------------------------------------ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |