Mac OSX Cocoa / interface builder example...
Stefan Sauer
ensonic at hora-obscura.de
Sun Aug 12 15:11:38 PDT 2012
On 08/12/2012 11:59 PM, Gerard Toonstra wrote:
> Hi all,
>
> I've managed to find some code online that nicely demonstrates the use
> of osxvideosink and
> gstreamer integration into a standard Cocoa Application project, using
> interface builder and
> normal Xcode tools:
>
> http://blog.angrymango.com/post/2012/01/04/Playing-a-video-using-gstreamer-on-OSX.aspx#comment
>
> This is (eventually) using the osxvideosink and therefore can be used
> directly with the streamer
> installation packages that were developed for the mac. CPU usage on
> 720p video using this play bin
> amounts to 80-100% or so, whereas the movie player gets up to 7-10% or
> so, probably using
> video acceleration of some kind (or the play bin uses some unnecessary
> conversions).
>
> I modified the code to use an existing 'frame' (dummy area) where the
> video is going to be embedded.
> It does not resize properly and there are some other issues probably,
> but it' s a good start.
>
> I think this example is great to show others how to develop players
> that use osxvideosink and which can integrate
> gstreamer in applications built with interface builder, without
> jumping through 20 hoops to get there.
>
> Please let me know your concerns and what needs to happen before this
> can be integrated somewhere in the
> gstreamer example code.
You can make a patch for gst-plugins-good/tests/examples/ to add this
code (+ a README if helpful). Then post this to bugzilla. Hopefully
other developers that work on OSX can help to make it work fully and
then the patch can be applied.
Stefan
>
> Rgds,
>
> Gerard
>
>
>
> -----------
>
> //
> // AppDelegate.m
> //
>
> #import "AppDelegate.h"
> #include <gst/gst.h>
> #include <gst/interfaces/xoverlay.h>
> #import "MainWindow.h"
>
> /* ============================================================= */
> /* */
> /* gstreamer callbacks */
> /* */
> /* ============================================================= */
> typedef struct context_t {
> void *appDelegate;
> void *viewingArea;
> } context_t;
>
> staticGMainLoop*loop;
>
> static gboolean bus_call(GstBus *bus, GstMessage *msg, void *user_data)
> {
> context_t *context;
>
>
>
> switch(GST_MESSAGE_TYPE(msg)) {
> caseGST_MESSAGE_EOS: {
> g_message("End-of-stream");
> g_main_loop_quit(loop);
> break;
> }
> caseGST_MESSAGE_ERROR: {
> GError *err;
> gst_message_parse_error(msg, &err, NULL);
> g_error("%s", err->message);
> g_error_free(err);
>
>
>
> g_main_loop_quit(loop);
> break;
> }
> default:
> context = (context_t *)user_data;
> if (gst_structure_has_name(msg->structure, "have-ns-view")) {
> NSView* myView = (__bridge
> NSView*)g_value_get_pointer(gst_structure_get_value(msg->structure,
> "nsview"));
> AppDelegate* del = (__bridge
> AppDelegate*)context->appDelegate;
> NSRect viewFrame = [(__bridge
> NSView*)context->viewingArea frame];
> [[del.window contentView] addSubview:myView];
> [myView setFrame: viewFrame];
> [myView setNeedsDisplay:YES];
> //[del.window setContentView: myWindow];
> }
>
>
>
> break;
> }
>
>
>
> returntrue;
> }
>
> static void gst_finish(GstElement* object, gpointer user_data)
> {
> //set uri to the next clip
> }
>
> static void play_uri(const char *uri, void *user_data)
> {
> GstElement *pipeline;
> GstBus *bus;
>
>
>
> loop= g_main_loop_new(NULL, FALSE);
> pipeline = gst_element_factory_make("playbin2", "player");
>
>
>
> if (uri)
> g_object_set(G_OBJECT(pipeline), "uri", uri, NULL);
>
>
>
> bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
> gst_bus_add_watch(bus, bus_call, user_data);
> gst_object_unref(bus);
>
>
>
> g_signal_connect(pipeline, "about-to-finish",
> G_CALLBACK(gst_finish), user_data);
>
>
>
> gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
>
>
>
> g_main_loop_run(loop);
>
>
>
> gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL);
> gst_object_unref(GST_OBJECT(pipeline));
> }
>
> @implementationAppDelegate
> @synthesize videoView = _videoView;
> @synthesize window = _window;
>
> -(void)g_init:(id)param
> {
> gst_init(NULL, NULL);
> context_t *context = malloc(sizeof(context_t));
> context->appDelegate = (__bridge void*)self;
> context->viewingArea = (__bridge void*)_videoView;
> play_uri("file:///Users/Shared/movies/holiday.mp4", context);
> }
>
> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
> {
> NSThread *g_thread = [[NSThread alloc] initWithTarget:self
> selector:@selector(g_init:) object:nil];
> [g_thread start];
> }
>
> @end
>
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20120813/5f63cac4/attachment-0001.html>
More information about the gstreamer-devel
mailing list