Example #1
0
 protected object setStreamConfigSetting(IAMStreamConfig streamConfig, string fieldName, object newValue)
 {
     if (streamConfig == null)
     {
         throw new NotSupportedException();
     }
     this.assertStopped();
     this.derenderGraph();
     IntPtr zero = IntPtr.Zero;
     AMMediaType structure = new AMMediaType();
     try
     {
         object obj3;
         int format = streamConfig.GetFormat(out zero);
         if (format != 0)
         {
             Marshal.ThrowExceptionForHR(format);
         }
         Marshal.PtrToStructure(zero, structure);
         if (structure.formatType == FormatType.WaveEx)
         {
             obj3 = new WaveFormatEx();
         }
         else if (structure.formatType == FormatType.VideoInfo)
         {
             obj3 = new VideoInfoHeader();
         }
         else
         {
             if (structure.formatType != FormatType.VideoInfo2)
             {
                 throw new NotSupportedException("This device does not support a recognized format block.");
             }
             obj3 = new VideoInfoHeader2();
         }
         Marshal.PtrToStructure(structure.formatPtr, obj3);
         FieldInfo field = obj3.GetType().GetField(fieldName);
         if (field == null)
         {
             throw new NotSupportedException("Unable to find the member '" + fieldName + "' in the format block.");
         }
         field.SetValue(obj3, newValue);
         Marshal.StructureToPtr(obj3, structure.formatPtr, false);
         format = streamConfig.SetFormat(structure);
         if (format != 0)
         {
             Marshal.ThrowExceptionForHR(format);
         }
     }
     finally
     {
         DsUtils.FreeAMMediaType(structure);
         Marshal.FreeCoTaskMem(zero);
     }
     this.renderGraph();
     this.startPreviewIfNeeded();
     return null;
 }
Example #2
0
        protected object setStreamConfigSetting(DShowNET.IAMStreamConfig streamConfig, string fieldName, object newValue)
        {
            if (streamConfig == null)
            {
                throw new NotSupportedException();
            }

            object returnValue = null;
            IntPtr pmt         = IntPtr.Zero;

            DShowNET.AMMediaType mediaType = new DShowNET.AMMediaType();

            try
            {
                // Get the current format info
                int hr = streamConfig.GetFormat(out pmt);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                Marshal.PtrToStructure(pmt, mediaType);

                // The formatPtr member points to different structures
                // dependingon the formatType
                object formatStruct;
                if (mediaType.formatType == DShowNET.FormatType.WaveEx)
                {
                    formatStruct = new DShowNET.WaveFormatEx();
                }
                else if (mediaType.formatType == DShowNET.FormatType.VideoInfo)
                {
                    formatStruct = new VideoInfoHeader();
                }
                else if (mediaType.formatType == DShowNET.FormatType.VideoInfo2)
                {
                    formatStruct = new DShowNET.VideoInfoHeader2();
                }
                else
                {
                    throw new NotSupportedException("This device does not support a recognized format block.");
                }

                // Retrieve the nested structure
                Marshal.PtrToStructure(mediaType.formatPtr, formatStruct);

                // Find the required field
                Type      structType = formatStruct.GetType();
                FieldInfo fieldInfo  = structType.GetField(fieldName);
                if (fieldInfo == null)
                {
                    throw new NotSupportedException("Unable to find the member '" + fieldName + "' in the format block.");
                }

                // Update the value of the field
                fieldInfo.SetValue(formatStruct, newValue);

                // PtrToStructure copies the data so we need to copy it back
                Marshal.StructureToPtr(formatStruct, mediaType.formatPtr, false);

                // Save the changes
                hr = streamConfig.SetFormat(mediaType);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            finally
            {
                //DShowNET.DsUtils.FreeAMMediaType(mediaType);
                Marshal.FreeCoTaskMem(pmt);
            }

            return(returnValue);
        }
Example #3
0
		/// <summary>
		///  Set the value of one member of the IAMStreamConfig format block.
		///  Helper function for several properties that expose
		///  video/audio settings from IAMStreamConfig.GetFormat().
		///  IAMStreamConfig.GetFormat() returns a AMMediaType struct.
		///  AMMediaType.formatPtr points to a format block structure.
		///  This format block structure may be one of several 
		///  types, the type being determined by AMMediaType.formatType.
		/// </summary>
		protected object setStreamConfigSetting( IAMStreamConfig streamConfig, string fieldName, object newValue)
		{
			//if ( streamConfig == null )
			//	throw new NotSupportedException();
			assertStopped();
			derenderGraph();

			object returnValue = null;
			IntPtr pmt = IntPtr.Zero;
			AMMediaType mediaType = new AMMediaType();

			try 
			{
				// Get the current format info
				int hr = streamConfig.GetFormat( out pmt );
				//if ( hr != 0 )
				//	Marshal.ThrowExceptionForHR( hr );
				Marshal.PtrToStructure( pmt, mediaType );

				// The formatPtr member points to different structures
				// dependingon the formatType
				object formatStruct;
				if ( mediaType.formatType == FormatType.WaveEx )
					formatStruct = new WaveFormatEx();
				else if ( mediaType.formatType == FormatType.VideoInfo )
					formatStruct = new VideoInfoHeader();
				else if ( mediaType.formatType == FormatType.VideoInfo2 )
					formatStruct = new VideoInfoHeader2();
				else
					throw new NotSupportedException( "This device does not support a recognized format block." );

				// Retrieve the nested structure
				Marshal.PtrToStructure( mediaType.formatPtr, formatStruct );

				// Find the required field
				Type structType = formatStruct.GetType();
				FieldInfo fieldInfo = structType.GetField( fieldName );
				if ( fieldInfo == null )
					throw new NotSupportedException( "Unable to find the member '" + fieldName + "' in the format block." );

				// Update the value of the field
				fieldInfo.SetValue( formatStruct, newValue );

				// PtrToStructure copies the data so we need to copy it back
				Marshal.StructureToPtr( formatStruct, mediaType.formatPtr, false ); 

				// Save the changes
				hr = streamConfig.SetFormat( mediaType );
				//if ( hr != 0 )
				//	Marshal.ThrowExceptionForHR( hr );
			}
			finally
			{
				DsUtils.FreeAMMediaType( mediaType );
				Marshal.FreeCoTaskMem( pmt );
			}
			renderStream = false;
			renderGraph();
			startPreviewIfNeeded();

			return( returnValue );
		}
Example #4
0
        protected object getStreamConfigSetting(IAMStreamConfig streamConfig, string fieldName)
        {
            if (streamConfig == null)
                throw new NotSupportedException();

            object returnValue = null;
            IntPtr pmt = IntPtr.Zero;
            AMMediaType mediaType = new AMMediaType();

            try
            {
                // Get the current format info
                int hr = streamConfig.GetFormat(out pmt);
                if (hr != 0)
                    Marshal.ThrowExceptionForHR(hr);
                Marshal.PtrToStructure(pmt, mediaType);

                // The formatPtr member points to different structures
                // dependingon the formatType
                object formatStruct;
                if (mediaType.formatType == FormatType.WaveEx)
                    formatStruct = new WaveFormatEx();
                else if (mediaType.formatType == FormatType.VideoInfo)
                    formatStruct = new VideoInfoHeader();
                else if (mediaType.formatType == FormatType.VideoInfo2)
                    formatStruct = new VideoInfoHeader2();
                else
                    throw new NotSupportedException("This device does not support a recognized format block.");

                // Retrieve the nested structure
                Marshal.PtrToStructure(mediaType.formatPtr, formatStruct);

                // Find the required field
                Type structType = formatStruct.GetType();
                FieldInfo fieldInfo = structType.GetField(fieldName);
                if (fieldInfo == null)
                    throw new NotSupportedException("Unable to find the member '" + fieldName + "' in the format block.");

                // Extract the field's current value
                returnValue = fieldInfo.GetValue(formatStruct);

            }
            finally
            {
                //DsUtils.FreeAMMediaType(mediaType);
                Marshal.FreeCoTaskMem(pmt);
            }

            return (returnValue);
        }