gnome-record-screen / GNOME-Record-Screen / src / VideoEncoder.cs

/**
 * VideoEncoder.cs
 *
 * :copyright: 2008 mitsuhiko.
 * :license: BSD
 */


using System;
using System.Collections.Generic;

using Gnome.RecordScreen.UI;
using Gnome.RecordScreen.Implementations;


namespace Gnome.RecordScreen {
	
	public class RectangleTooSmallException : SystemException {
		
		public RectangleTooSmallException () :
			base ("The rectangle is smaller than the supported size.")
		{}
	}
	
	public class VideoContainer : IGstObject {
		private string name;
		private string gstKey;
		private string[] extensions;
		private AudioEncoder audioCodec;
		private bool requiresMultiFileSink;
		
		public VideoContainer (string name, string gstKey, string[] extensions,
		                       AudioEncoder audioCodec, bool requiresMultiFileSink)
		{
			this.name = name;
			this.gstKey = gstKey;
			this.extensions = extensions;
			this.audioCodec = audioCodec;
			this.requiresMultiFileSink = requiresMultiFileSink;
		}
		
		public string Name {
			get { return name; }
		}
		
		public string GstKey {
			get { return gstKey; }
		}
		
		public string[] Extensions {
			get { return extensions; }
		}
		
		public AudioEncoder AudioCodec {
			get { return audioCodec; }
		}
		
		public bool IsAvailable {
			get {
				// some containers are actually not containers
				// but just dummies.  In that case such a thing
				// always exists.
				if (GstKey == null)
					return true;
				return GStreamerInterface.SupportsObject (this);
			}
		}

		public bool RequiresMultiFileSink {
			get { return requiresMultiFileSink; }
		}
				
		private static VideoContainer avi =
			new VideoContainer ("AVI", "avimux", new string[] { ".avi" },
			                    AudioEncoder.Mp3, false);
		public static VideoContainer Avi {
			get { return avi; }
		}
		
		private static VideoContainer ogg =
			new VideoContainer ("Ogg", "oggmux", new string[] { ".ogg", ".ogv" },
			                    AudioEncoder.Vorbis, false);
		public static VideoContainer Ogg {
			get { return ogg; }
		}
		
		private static VideoContainer png =
			new VideoContainer ("PNG", null, new string[] { ".png" },
			                    AudioEncoder.Null, true);
		public static VideoContainer Png {
			get { return png; }
		}
	}
	
	
	/**
	 * Subclasses of this class represent video encoders.
	 */
	public class VideoEncoder : IEncoder {
		private string name;
		private string gstKey;
		private VideoContainer container;

		protected VideoEncoder (string name, string gstKey, VideoContainer container)
		{
			this.name = name;
			this.gstKey = gstKey;
			this.container = container;
		}
		
		public string Name {
			get { return name; }
		}
		
		public string GstKey {
			get { return gstKey; }
		}
		
		public VideoContainer Container {
			get { return container; }
		}
		
		public virtual Gdk.Rectangle OptimizeRectangle (Gdk.Rectangle rectangle)
		{
			return rectangle;
		}
		
		public virtual ConfigurationPane CreateConfigurationPane ()
		{
			return null;
		}
		
		public virtual bool IsAvailable {
			get { return (GStreamerInterface.SupportsObject (this) &&
			              Container.IsAvailable); }
		}
		
		/**
		 * This method is passed a configuration pane and should return the
		 * encoder arguments as string based on the values from that pane.  If
		 * the pane is unsupported (pane from different encoder for example)
		 * the return value must be null.
		 */
		public virtual string GetEncoderArguments (ConfigurationPane pane)
		{
			return null;
		}
		
		private static VideoEncoder h264 = new H264VideoEncoder ();
		public static VideoEncoder H264 {
			get { return h264; }
		}

		private static VideoEncoder theora = new TheoraVideoEncoder ();
		public static VideoEncoder Theora {
			get { return theora; }
		}
		
		private static VideoEncoder mpeg = new MpegVideoEncoder ();		
		public static VideoEncoder Mpeg {
			get { return mpeg; }
		}
		
		private static VideoEncoder png = new PngVideoEncoder ();
		public static VideoEncoder Png {
			get { return png; }
		}
	}
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.