Example #1
0
        private void FindDefaultAsfItem(AsfFormatSelection avformat)
        {
            for (int i = 0; i < InnerList.Count; i++)
            {
                switch (avformat)
                {
                // Video selections:
                case AsfFormatSelection.AllFormats:
                case AsfFormatSelection.Video:
                case AsfFormatSelection.VideoOnly:
                    if ((this[i].Guid != Guid.Empty) && (this[i].Guid == DefaultVideoProfile))
                    {
                        CurrentProfile = this[i];
                        return;
                    }
                    break;

                case AsfFormatSelection.AudioOnly:
                    if ((this[i].Guid != Guid.Empty) && (this[i].Guid == DefaultAudioProfile))
                    {
                        CurrentProfile = this[i];
                        return;
                    }
                    break;
                }
            }
        }
Example #2
0
		/// <summary>
		/// Add profile item to the list
		/// </summary>
		/// <param name="avformat"></param>
		/// <param name="profile"></param>
		/// <param name="guid"></param>
		/// <param name="filename"></param>
		/// <returns></returns>
		public bool AddProfileItem(AsfFormatSelection avformat, IWMProfile profile, Guid guid, string filename)
		{

			if(profile == null)
			{
				return false;
			}

			try
			{
				StringBuilder profileName = new StringBuilder(MAXLENPROFNAME);
				StringBuilder profileDescription = new StringBuilder(MAXLENPROFDESC);
				int profileNameLen = MAXLENPROFNAME;
				int profileDescLen = MAXLENPROFDESC;
				int streamCount = 0;
				bool audio = false;
				bool video = false;
				int audioBitrate = 0;
				int videoBitrate = 0;
				profileName.Length = 0;
				profileDescription.Length = 0;

				int hr = profile.GetName(profileName, ref profileNameLen);
#if DEBUG
				if(hr < 0)
				{
					Debug.WriteLine("GetName failed");
				}
#endif
				
				if(hr >= 0)
				{
					hr = profile.GetDescription(profileDescription, ref profileDescLen);
#if DEBUG
					if(hr < 0)
					{
						Debug.WriteLine("GetDescription failed");
					}
#endif
				}

				if(hr >= 0)
				{
					hr = profile.GetStreamCount(out streamCount);
#if DEBUG
					if(hr < 0)
					{
						Debug.WriteLine("GetStreamCount failed");
					}
#endif
				}

				if((streamCount > 0)&&(hr >= 0))
				{
					IWMStreamConfig streamConfig = null;
					Guid streamGuid = Guid.Empty;
					audio = false;
					video = false;
					audioBitrate = 0;
					videoBitrate = 0;

					for(short i = 1;(i <= streamCount)&&(hr >= 0); i++)
					{
						hr = profile.GetStreamByNumber(i, out streamConfig);
						if((hr >= 0)&&(streamConfig != null))
						{
							hr = streamConfig.GetStreamType(out streamGuid);
							if(hr >= 0)
							{
								if(streamGuid == MediaType.Video)
								{
									video = true;
									hr = streamConfig.GetBitrate(out videoBitrate);
									if(hr < 0)
									{
										videoBitrate = 0;
									}
								} 
								else
									if(streamGuid == MediaType.Audio)
								{
									audio = true;
									hr = streamConfig.GetBitrate(out audioBitrate);
									if(hr < 0)
									{
										audioBitrate = 0;
									}
								}
								hr = 0; // Allow possible unreadable bitrates
							}
#if DEBUG
							else
							{
								Debug.WriteLine("GetStreamByNumber failed");
							}
#endif
						} // for i
					}
					// Create profile format item
					if(hr >= 0)
					{
						WMProfileData profileInfo = new WMProfileData(
							guid, profileName.ToString(), profileDescription.ToString(), audioBitrate, videoBitrate, audio, video);

						bool StoreInfo = false;

						// Check if all profiles are allowed
						switch(avformat)
						{
							case AsfFormatSelection.AllFormats:
								StoreInfo = true;
								break;
							case AsfFormatSelection.AudioOnly:
								if((profileInfo.Audio)&&(!profileInfo.Video))
								{
									StoreInfo = true;
								}
								break;
							case AsfFormatSelection.Video:
								if(profileInfo.Video)
								{
									StoreInfo = true;
								}
								break;
							case AsfFormatSelection.VideoOnly:
								if((profileInfo.Video)&&(!profileInfo.Audio))
								{
									StoreInfo = true;
								}
								break;
							default:
								break;
						}

						if(StoreInfo)
						{

							if((guid == Guid.Empty)&&(filename != null)&&(filename.Length > 0))
							{
								// Store filename
								profileInfo.Filename = filename;
							} 
							else
								if(guid != Guid.Empty)
							{
								profileInfo.Filename = "";
							}
							else
							{
								// Either a filename or guid must be supplied
								profileInfo.Dispose();
								return false;
							}

							this.InnerList.Add(profileInfo);
							return true;
						}
					}
				}
			}
			catch
			{
				// Fatal error occured ...
			}
			return false;
		}
Example #3
0
		/// <summary>
		/// Initialize collection with the specified type of profiles.
		/// </summary>
		/// <param name="avformat"></param>
		internal AsfFormat(AsfFormatSelection avformat)
		{
			InnerList.Capacity = 1;
			GetProfileFormatInfo(avformat);
		}
Example #4
0
		/// <summary>
		/// Get asf profile information
		/// </summary>
		/// <returns></returns>
		public bool GetProfileFormatInfo(AsfFormatSelection avformat)
		{
			int hr;
			IWMProfileManager profileManager = null;
			IWMProfile profile = null;

			if(this.InnerList.Count > 0)
			{
				// Profile information already loaded
				return true;
			}

#if DEBUG
			Debug.WriteLine("Look for Windows Media profile information: " + avformat.ToString());
#endif
			try
			{
				IWMProfileManager2 profileManager2 = null;
				IWMProfileManagerLanguage profileManagerLanguage = null;
				WMVersion wmversion = WMVersion.V4_0;
				int nbrProfiles = 0;
				int totalItems = 0;
				short langID;

				// Open the profile manager
                try
                {
                    hr = WMLib.WMCreateProfileManager(out profileManager);
                }
                catch (Exception) { hr = -1; }
				if(hr >= 0)
				{
					// Convert pWMProfileManager to a IWMProfileManager2
					profileManager2 = profileManager as IWMProfileManager2;
					profileManagerLanguage = profileManager as IWMProfileManagerLanguage;

					hr = profileManager2.GetSystemProfileVersion(out wmversion);
#if DEBUG
					Debug.WriteLine("WM version=" + wmversion.ToString());
#endif

					hr = profileManagerLanguage.GetUserLanguageID(out langID);
#if DEBUG
					Debug.WriteLine("WM language ID=" + langID.ToString());
#endif

					//IWMProfileManagerLanguage
					// Specify the version number of the profiles to use
					hr = profileManager2.SetSystemProfileVersion(DefaultWMversion);
					// Marshal.ThrowExceptionForHR(hr);

					if(hr >= 0)
					{
						hr = profileManager2.GetSystemProfileCount(out nbrProfiles);
						if(hr < 0)
						{
							// No profiles available, so nothing to do
							return false;
						}
#if DEBUG
						Debug.WriteLine("ProfileCount=" + nbrProfiles.ToString());
#endif
					} 
					else
					{
						// Error occured when setting profile version
						return false;
					}

				} 
				else
				{
					// Error occured when creating profile manager
					return false;
				}

				// There are profiles to look for!
				for(int p = 0;(p < nbrProfiles)&&(hr >= 0); p++)
				{
					Guid guid = Guid.Empty;
					// Load the profile specified by the caller
					//hr = profileManager2.LoadProfileByID(guid, out profile);
					// Marshal.ThrowExceptionForHR(hr);
					hr = profileManager2.LoadSystemProfile(p, out profile);
					if(hr >= 0)
					{
						IWMProfile2 profile2 = profile as IWMProfile2;
						hr = profile2.GetProfileID(out guid);
#if DEBUG
						if(hr < 0)
						{
							Debug.WriteLine("GetProfileID failed for item " + p.ToString());
						}
#endif
					}
#if DEBUG
					else
					{
						Debug.WriteLine("LoadSystemProfile failed for item " + p.ToString());
					}
#endif
					if(hr >= 0)
					{
						// Add item to list
						if(AddProfileItem(avformat, profile, guid, null))
						{
							totalItems++;
						}
					}
				} // for p


				// Start of NEW
				// Look for profile (*.prx) files in the current directory.
				// If found, then add the profile(s) to the list
				string profileData;
				string pathProfile = System.IO.Directory.GetCurrentDirectory();
				string filterProfile = "*.prx";

				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(pathProfile, filterProfile); 

				foreach (string filename in directoryEntries) 
				{
					Debug.WriteLine(filename);
					if(GetProfileDataFromFile(filename, out profileData))
					{					
						hr = profileManager.LoadProfileByData(profileData, out profile);
						if(hr >= 0)
						{
							if(AddProfileItem(avformat, profile, Guid.Empty, filename))
							{
								totalItems++;
							}
						}
					}
				}
				// End of NEW
			}
			finally
			{
				FindDefaultAsfItem(avformat);

				// Release the locals
				if (profile != null)
				{
					Marshal.ReleaseComObject(profile);
					profile = null;
				}
				if (profileManager != null)
				{
					Marshal.ReleaseComObject(profileManager);
					profileManager = null;
				}
			}
			return false;
		}
Example #5
0
		private bool FindDefaultAsfItem(AsfFormatSelection avformat)
		{
			for(int i = 0; i < this.InnerList.Count; i++)
			{
				switch(avformat)
				{
						// Video selections:
					case AsfFormatSelection.AllFormats:
					case AsfFormatSelection.Video:
					case AsfFormatSelection.VideoOnly:
						if((this[i].Guid != Guid.Empty)&&(this[i].Guid == DefaultVideoProfile))
						{
							CurrentProfile = this[i];
							return true;
						}
						break;
					case AsfFormatSelection.AudioOnly:
						if((this[i].Guid != Guid.Empty)&&(this[i].Guid == DefaultAudioProfile))
						{
							CurrentProfile = this[i];
							return true;
						}
						break;
					default:
						break;
				}
			}
			return false;
		}
Example #6
0
        /// <summary>
        /// Add profile item to the list
        /// </summary>
        /// <param name="avformat"></param>
        /// <param name="profile"></param>
        /// <param name="guid"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool AddProfileItem(AsfFormatSelection avformat, IWMProfile profile, Guid guid, string filename)
        {
            if (profile == null)
            {
                return(false);
            }

            try
            {
                StringBuilder profileName        = new StringBuilder(MAXLENPROFNAME);
                StringBuilder profileDescription = new StringBuilder(MAXLENPROFDESC);
                int           profileNameLen     = MAXLENPROFNAME;
                int           profileDescLen     = MAXLENPROFDESC;
                int           streamCount        = 0;
                bool          audio        = false;
                bool          video        = false;
                int           audioBitrate = 0;
                int           videoBitrate = 0;
                profileName.Length        = 0;
                profileDescription.Length = 0;

                int hr = profile.GetName(profileName, ref profileNameLen);
#if DEBUG
                if (hr < 0)
                {
                    Debug.WriteLine("GetName failed");
                }
#endif

                if (hr >= 0)
                {
                    hr = profile.GetDescription(profileDescription, ref profileDescLen);
#if DEBUG
                    if (hr < 0)
                    {
                        Debug.WriteLine("GetDescription failed");
                    }
#endif
                }

                if (hr >= 0)
                {
                    hr = profile.GetStreamCount(out streamCount);
#if DEBUG
                    if (hr < 0)
                    {
                        Debug.WriteLine("GetStreamCount failed");
                    }
#endif
                }

                if ((streamCount > 0) && (hr >= 0))
                {
                    IWMStreamConfig streamConfig = null;
                    Guid            streamGuid   = Guid.Empty;
                    audio        = false;
                    video        = false;
                    audioBitrate = 0;
                    videoBitrate = 0;

                    for (short i = 1; (i <= streamCount) && (hr >= 0); i++)
                    {
                        hr = profile.GetStreamByNumber(i, out streamConfig);
                        if ((hr >= 0) && (streamConfig != null))
                        {
                            hr = streamConfig.GetStreamType(out streamGuid);
                            if (hr >= 0)
                            {
                                if (streamGuid == MediaType.Video)
                                {
                                    video = true;
                                    hr    = streamConfig.GetBitrate(out videoBitrate);
                                    if (hr < 0)
                                    {
                                        videoBitrate = 0;
                                    }
                                }
                                else
                                if (streamGuid == MediaType.Audio)
                                {
                                    audio = true;
                                    hr    = streamConfig.GetBitrate(out audioBitrate);
                                    if (hr < 0)
                                    {
                                        audioBitrate = 0;
                                    }
                                }
                                hr = 0;                                 // Allow possible unreadable bitrates
                            }
#if DEBUG
                            else
                            {
                                Debug.WriteLine("GetStreamByNumber failed");
                            }
#endif
                        }                         // for i
                    }
                    // Create profile format item
                    if (hr >= 0)
                    {
                        WMProfileData profileInfo = new WMProfileData(
                            guid, profileName.ToString(), profileDescription.ToString(), audioBitrate, videoBitrate, audio, video);

                        bool StoreInfo = false;

                        // Check if all profiles are allowed
                        switch (avformat)
                        {
                        case AsfFormatSelection.AllFormats:
                            StoreInfo = true;
                            break;

                        case AsfFormatSelection.AudioOnly:
                            if ((profileInfo.Audio) && (!profileInfo.Video))
                            {
                                StoreInfo = true;
                            }
                            break;

                        case AsfFormatSelection.Video:
                            if (profileInfo.Video)
                            {
                                StoreInfo = true;
                            }
                            break;

                        case AsfFormatSelection.VideoOnly:
                            if ((profileInfo.Video) && (!profileInfo.Audio))
                            {
                                StoreInfo = true;
                            }
                            break;
                        }

                        if (StoreInfo)
                        {
                            if ((guid == Guid.Empty) && (filename != null) && (filename.Length > 0))
                            {
                                // Store filename
                                profileInfo.Filename = filename;
                            }
                            else
                            if (guid != Guid.Empty)
                            {
                                profileInfo.Filename = "";
                            }
                            else
                            {
                                // Either a filename or guid must be supplied
                                profileInfo.Dispose();
                                return(false);
                            }

                            InnerList.Add(profileInfo);
                            return(true);
                        }
                    }
                }
            }
            catch
            {
                // Fatal error occured ...
            }
            return(false);
        }
Example #7
0
 /// <summary>
 /// Initialize collection with the specified type of profiles.
 /// </summary>
 /// <param name="avformat"></param>
 internal AsfFormat(AsfFormatSelection avformat)
 {
     InnerList.Capacity = 1;
     GetProfileFormatInfo(avformat);
 }
Example #8
0
        /// <summary>
        /// Get asf profile information
        /// </summary>
        /// <returns></returns>
        public bool GetProfileFormatInfo(AsfFormatSelection avformat)
        {
            IWMProfileManager profileManager = null;
            IWMProfile        profile        = null;

            if (InnerList.Count > 0)
            {
                // Profile information already loaded
                return(true);
            }

#if DEBUG
            Debug.WriteLine("Look for Windows Media profile information: " + avformat);
#endif
            try
            {
                IWMProfileManager2        profileManager2;
                IWMProfileManagerLanguage profileManagerLanguage;
                int   nbrProfiles;
                int   totalItems = 0;
                short langID;

                // Open the profile manager
                var hr = WMLib.WMCreateProfileManager(out profileManager);
                if (hr >= 0)
                {
                    // Convert pWMProfileManager to a IWMProfileManager2
                    profileManager2        = profileManager as IWMProfileManager2;
                    profileManagerLanguage = (IWMProfileManagerLanguage)profileManager;

                    profileManager2.GetSystemProfileVersion(out var wmversion);
#if DEBUG
                    Debug.WriteLine("WM version=" + wmversion);
#endif

                    profileManagerLanguage.GetUserLanguageID(out langID);
#if DEBUG
                    Debug.WriteLine("WM language ID=" + langID);
#endif

                    //IWMProfileManagerLanguage
                    // Specify the version number of the profiles to use
                    hr = profileManager2.SetSystemProfileVersion(DefaultWMversion);
                    // Marshal.ThrowExceptionForHR(hr);

                    if (hr >= 0)
                    {
                        hr = profileManager2.GetSystemProfileCount(out nbrProfiles);
                        if (hr < 0)
                        {
                            // No profiles available, so nothing to do
                            return(false);
                        }
#if DEBUG
                        Debug.WriteLine("ProfileCount=" + nbrProfiles);
#endif
                    }
                    else
                    {
                        // Error occured when setting profile version
                        return(false);
                    }
                }
                else
                {
                    // Error occured when creating profile manager
                    return(false);
                }

                // There are profiles to look for!
                for (int p = 0; (p < nbrProfiles) && (hr >= 0); p++)
                {
                    Guid guid = Guid.Empty;
                    // Load the profile specified by the caller
                    //hr = profileManager2.LoadProfileByID(guid, out profile);
                    // Marshal.ThrowExceptionForHR(hr);
                    hr = profileManager2.LoadSystemProfile(p, out profile);
                    if (hr >= 0)
                    {
                        IWMProfile2 profile2 = profile as IWMProfile2;
                        if (profile2 != null)
                        {
                            hr = profile2.GetProfileID(out guid);
                        }
#if DEBUG
                        if (hr < 0)
                        {
                            Debug.WriteLine("GetProfileID failed for item " + p);
                        }
#endif
                    }
#if DEBUG
                    else
                    {
                        Debug.WriteLine("LoadSystemProfile failed for item " + p);
                    }
#endif
                    if (hr >= 0)
                    {
                        // Add item to list
                        if (AddProfileItem(avformat, profile, guid, null))
                        {
                            totalItems++;
                        }
                    }
                }                 // for p


                // Start of NEW
                // Look for profile (*.prx) files in the current directory.
                // If found, then add the profile(s) to the list
                string profileData;
                string pathProfile   = Directory.GetCurrentDirectory();
                string filterProfile = "*.prx";

                // Obtain the file system entries in the directory path.
                string[] directoryEntries =
                    Directory.GetFileSystemEntries(pathProfile, filterProfile);

                foreach (string filename in directoryEntries)
                {
                    Debug.WriteLine(filename);
                    if (GetProfileDataFromFile(filename, out profileData))
                    {
                        hr = profileManager.LoadProfileByData(profileData, out profile);
                        if (hr >= 0)
                        {
                            if (AddProfileItem(avformat, profile, Guid.Empty, filename))
                            {
                                totalItems++;
                            }
                        }
                    }
                }
                // End of NEW
            }
            finally
            {
                FindDefaultAsfItem(avformat);

                // Release the locals
                if (profile != null)
                {
                    Marshal.ReleaseComObject(profile);
                    profile = null;
                }
                if (profileManager != null)
                {
                    Marshal.ReleaseComObject(profileManager);
                    profileManager = null;
                }
            }
            return(false);
        }