Inheritance: Gst.Base.BaseSink
Esempio n. 1
0
 static void Eos_cb(IntPtr inst)
 {
     try {
         AppSink __obj = GLib.Object.GetObject(inst, false) as AppSink;
         __obj.OnEos();
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
Esempio n. 2
0
 static IntPtr TryPullSampleEvent_cb(IntPtr inst, ulong timeout)
 {
     try {
         AppSink    __obj = GLib.Object.GetObject(inst, false) as AppSink;
         Gst.Sample __result;
         __result = __obj.OnTryPullSampleEvent(timeout);
         return(__result == null ? IntPtr.Zero : __result.OwnedCopy);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, true);
         // NOTREACHED: above call does not return.
         throw e;
     }
 }
Esempio n. 3
0
 static int NewSample_cb(IntPtr inst)
 {
     try {
         AppSink        __obj = GLib.Object.GetObject(inst, false) as AppSink;
         Gst.FlowReturn __result;
         __result = __obj.OnNewSample();
         return((int)__result);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, true);
         // NOTREACHED: above call does not return.
         throw e;
     }
 }
Esempio n. 4
0
		/// <summary>
		/// Loads the video. Setup playbin2 and start polling thread
		/// </summary>
		/// <param name='uri'>
		/// video URI.
		/// </param>
		public void LoadVideo(string uri){

			if (gstThread != null)
			{
				isrunning = false;
				gstThread.Join();
				gstThread = new Thread(new ThreadStart(KeepPolling));
			}

			if(playBin != null){
				playerState = VideoPlayerState.STOPPED;
				Console.WriteLine("STOPPED");
				
				//Dispose playbin2 and appsink
				playBin.SetState(State.Null);
				playBin.Dispose();
				appSink.SetState(State.Null);
				appSink.Dispose();
				
				//Create playbin2 and appsink
				playBin = new PlayBin2();
				
				appSink = ElementFactory.Make("appsink", "sink") as AppSink;
				//appSink.Caps = new Caps("video/x-raw-yuv", new object[]{});
				appSink.Caps = new Caps("video/x-raw-rgb", new object[] { "bpp", 24 });
				appSink.Drop = true;
				appSink.MaxBuffers = 1;
				playBin.VideoSink = appSink;
			}else{
				//Create playbin2 and appsink
				playBin = new PlayBin2();
				appSink = ElementFactory.Make("appsink", "sink") as AppSink;
				//appSink.Caps = new Caps("video/x-raw-yuv", new object[]{});
				appSink.Caps = new Caps("video/x-raw-rgb", new object[] { "bpp", 24 });
				appSink.Drop = true;
				appSink.MaxBuffers = 1;
				playBin.VideoSink = appSink;
			}

			//init variables
            texturesOK = false;
            width = 0;
            height = 0;
			
			//Set file uri
            string validUri = uri;
            if (!validUri.StartsWith("file://"))
            {
                validUri = "file://" + uri;
            }
            playBin.Uri = validUri;
			StateChangeReturn sr = playBin.SetState(State.Playing);
			Console.WriteLine(sr.ToString());
            playerState = VideoPlayerState.LOADING;
            Console.WriteLine("LOADING:" + validUri);

            if (gstThread == null)
            {
                gstThread = new Thread(new ThreadStart(KeepPolling));
            }
			
			//Start polling thread...future thought, using async queue?
            isrunning = true;
            gstThread.Start();

            return;
		}
Esempio n. 5
0
		/// <summary>
		/// Polling thread. Pull buffer data from GST thread.
		/// </summary>
		void KeepPolling(){
			while(isrunning){
				switch (playerState)
                {
					case VideoPlayerState.STOPPED:
                        break;
                    case VideoPlayerState.LOADING:
                        //get video width/height
                        int w = 0, h = 0;
						//Query video information
                        Gst.Buffer buf = appSink.PullBuffer();
					    if(buf != null){
							Console.WriteLine(buf.Caps.ToString());
							//string format = buf.Caps[0].GetValue("format").Val.ToString();
							//Console.WriteLine("format: " + format);
                            int.TryParse(buf.Caps[0].GetValue("width").Val.ToString(), out w);
                            int.TryParse(buf.Caps[0].GetValue("height").Val.ToString(), out h);
                            if (w * h != 0)
                            {
								//Create decoded buffer
                                lock (lockFrameBuf)
                                {
                                    width = w;
                                    height = h;
                                    buffer = new byte[width * height * 3];
                                    Marshal.Copy(buf.Data, buffer, 0, width * height * 3);
                                    isFrameNew = true;
									//Dispose handle to avoid memory leak
                                    //gst_mini_object_unref(buf.Handle);
                                    buf.Dispose();
                                }
                                Console.WriteLine("PLAYING");
                                playerState = VideoPlayerState.PLAYING;
								continue;
                            }
						}
                        break;
                    case VideoPlayerState.PLAYING:
                        Gst.Buffer buf2 = appSink.PullBuffer();
					    if(buf2 != null){
						    lock(lockFrameBuf){
								//Update buffer
							    Marshal.Copy(buf2.Data, buffer, 0, width * height * 3);
							    isFrameNew = true;
                                //gst_mini_object_unref(buf2.Handle);
                                //buf2.Dispose();
						    }
						
						    buf2.Dispose();
					    }else{
                            lock (lockFrameBuf)
                            {
                                //Clear buffer
                                buffer = new byte[width * height * 3];
                            }
                            playerState = VideoPlayerState.STOPPED;
                            Console.WriteLine("STOPPED");

					    }
                        break;
                    case VideoPlayerState.PAUSED:
						//Do nothing
                        break;
                    default:
						//Do nothing
                        break;
                }
				Thread.Sleep(10);
			}
			
			//Clean up
            this.PlayerState = VideoPlayerState.STOPPED;
            playBin.SetState(State.Null);
            playBin.Dispose();
            appSink.SetState(State.Null);
            appSink.Dispose();
            playBin = null;
            appSink = null;
		}