Exemplo n.º 1
0
        private void TestStream()
        {
            int             i;
            IWMStreamConfig sc, sc2, sc3;

            m_pProfile.CreateNewStream(MediaType.Video, out sc);
            Debug.Assert(sc != null);

            sc.SetStreamNumber(12);

            m_pProfile.AddStream(sc);
            m_pProfile.GetStreamCount(out i);
            Debug.Assert(i == 1);

            m_pProfile.GetStream(0, out sc2);
            Debug.Assert(sc2 != null);

            m_pProfile.ReconfigStream(sc2);

            m_pProfile.GetStreamByNumber(12, out sc3);
            Debug.Assert(sc3 != null);

            m_pProfile.RemoveStream(sc3);
            m_pProfile.GetStreamCount(out i);
            Debug.Assert(i == 0);

            m_pProfile.AddStream(sc);
            m_pProfile.GetStreamCount(out i);
            Debug.Assert(i == 1);

            m_pProfile.RemoveStreamByNumber(12);
            m_pProfile.GetStreamCount(out i);
            Debug.Assert(i == 0);
        }
Exemplo n.º 2
0
        public void Initialize(IWMProfile profile, string filePath)
        {
            if (filePath == null || filePath.Length == 0)
            {
                throw new ArgumentNullException("filePath", "Invalid string parameter.");
            }

            //
            // assign profile to writer
            //
            _writer.SetProfile(profile);

            Logger.WriteLogMessage("Set profile on writer.");

            _writer.SetOutputFilename(filePath);

            Logger.WriteLogMessage("Set output filename [" + filePath + "] for writing.");

            _writer.GetInputCount(out _writerInputCount);

            Logger.WriteLogMessage("Found " + _writerInputCount + " writer inputs.");

            profile.GetStreamCount(out _writerStreamCount);

            Logger.WriteLogMessage("Found " + _writerStreamCount + " writer streams.");
        }
Exemplo n.º 3
0
        private void SetStreams(string sName)
        {
            // First find the mapping between the output name and
            // the stream number
            IWMProfile pProfile = m_pReader as IWMProfile;

            int iCount;

            pProfile.GetStreamCount(out iCount);
            short[]           sss = new short[iCount];
            StreamSelection[] ss  = new StreamSelection[iCount];

            StringBuilder sSName;

            for (short j = 0; j < iCount; j++)
            {
                IWMStreamConfig pConfig;
                pProfile.GetStream(j, out pConfig);

                try
                {
                    pConfig.GetStreamNumber(out sss[j]);

                    short iSName = 0;
                    sSName = null;
                    pConfig.GetConnectionName(sSName, ref iSName);
                    sSName = new StringBuilder(iSName);
                    pConfig.GetConnectionName(sSName, ref iSName);
                }
                finally
                {
                    Marshal.ReleaseComObject(pConfig);
                }

                // Turn the stream on or off depending on whether
                // this is the one that matches the output we're
                // looking for
                if (sSName.ToString() == sName)
                {
                    ss[j] = StreamSelection.On;
                }
                else
                {
                    ss[j] = StreamSelection.Off;
                }
            }

            // Use the array we've built to specify the streams we want
            IWMReaderAdvanced ra = m_pReader as IWMReaderAdvanced;

            ra.SetStreamsSelected((short)iCount, sss, ss);

            // Learn the maximum sample size that will be send to OnSample
            ra.GetMaxOutputSampleSize(m_dwAudioOutputNum, out m_MaxSampleSize);

            // Have the Samples allocated using IWMReaderCallbackAdvanced::AllocateForOutput
            ra.SetAllocateForOutput(m_dwAudioOutputNum, true);
        }
Exemplo n.º 4
0
        public void SetProfile(IWMProfile profile)
        {
            //
            // assign profile to writer
            //
            _writer.SetProfile(profile);

            Logger.WriteLogMessage("Set profile on writer.");

            profile.GetStreamCount(out _writerStreamCount);

            Logger.WriteLogMessage("Found " + _writerStreamCount + " writer streams.");
        }
Exemplo n.º 5
0
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::GetProfileInfo()
        // Desc: Gets the profile information from the reader.
        //------------------------------------------------------------------------------
        protected void GetProfileInfo()
        {
            IWMStreamConfig pStreamConfig  = null;
            IWMMediaProps   pMediaProperty = null;

            //
            // Get the profile of the reader
            //
            m_pReaderProfile = m_pReader as IWMProfile;

            //
            // Get stream count
            //
            m_pReaderProfile.GetStreamCount(out m_dwStreamCount);

            //
            // Allocate memory for the stream type array and stream number array
            //
            m_pguidStreamType = new Guid[m_dwStreamCount];
            m_pwStreamNumber  = new short[m_dwStreamCount];

            for (int i = 0; i < m_dwStreamCount; i++)
            {
                m_pReaderProfile.GetStream(i, out pStreamConfig);

                try
                {
                    //
                    // Get the stream number of the current stream
                    //
                    pStreamConfig.GetStreamNumber(out m_pwStreamNumber[i]);

                    //
                    // Set the stream to be received in compressed mode
                    //
                    m_pReaderAdvanced.SetReceiveStreamSamples(m_pwStreamNumber[i], true);

                    pMediaProperty = pStreamConfig as IWMMediaProps;

                    //
                    // Get the stream type of the current stream
                    //
                    pMediaProperty.GetType(out m_pguidStreamType[i]);
                }
                finally
                {
                    Marshal.ReleaseComObject(pStreamConfig);
                }
            }
        }
Exemplo n.º 6
0
        public void Open(string filePath, TimeSpan startTime, TimeSpan duration)
        {
            if (Utility.IsEmptyString(filePath))
            {
                throw new ArgumentNullException("inputFilePath", "Invalid string parameter.");
            }

            _reader.Open(filePath);

            Logger.WriteLogMessage("Opened file [" + filePath + "] for reading.");

            WMHeaderInfo readerHeaderInfo = new WMHeaderInfo((IWMHeaderInfo)_reader);

            WM_ATTR  attr           = readerHeaderInfo.GetAttribute(Constants.g_wszWMDuration);
            TimeSpan readerDuration = new TimeSpan((long)(ulong)attr.Value);

            Logger.WriteLogMessage("Found input duration [" + readerDuration + "].");

            if (startTime != TimeSpan.Zero)
            {
                //
                // startTime, duration are in 100-nsec ticks
                //
                _reader.SetRange((ulong)startTime.Ticks, duration.Ticks); // seek

                Logger.WriteLogMessage("Set range on reader, startTime [" + startTime + "], duration [" + duration + "].");
            }

            _reader.GetOutputCount(out _readerOutputCount);

            Logger.WriteLogMessage("Found " + _readerOutputCount + " reader outputs.");

            IWMProfile readerProfile = (IWMProfile)_reader;

            readerProfile.GetStreamCount(out _readerStreamCount);
        }
Exemplo n.º 7
0
        private void SetCutomProfile(int vidbitrate, int audbitrate, int vidheight, int vidwidth, double fps)
        {
            //seperate method atm braindump for adjusting an existing profile (prx file)
            //method call is not enabled yet
            IWMProfileManager  profileManager  = null;
            IWMProfileManager2 profileManager2 = null;
            IWMProfile         profile         = null;
            IWMStreamConfig    streamConfig;
            //IWMInputMediaProps inputProps = null;
            IWMProfileManagerLanguage profileManagerLanguage = null;
            WMVersion     wmversion   = WMVersion.V8_0;
            int           nbrProfiles = 0;
            short         langID;
            StringBuilder profileName        = new StringBuilder(MAXLENPROFNAME);
            StringBuilder profileDescription = new StringBuilder(MAXLENPROFDESC);
            int           profileNameLen     = MAXLENPROFNAME;
            int           profileDescLen     = MAXLENPROFDESC;

            profileName.Length        = 0;
            profileDescription.Length = 0;
            double videoFps          = fps;
            long   singleFramePeriod = (long)((10000000L / fps));
            //Guid guidInputType;
            //int dwInputCount = 0;
            int           hr;
            int           videoBitrate        = vidbitrate;
            int           audioBitrate        = audbitrate;
            int           videoHeight         = vidheight;
            int           videoWidth          = vidwidth;
            double        videofps            = fps;
            int           streamCount         = 0;
            IWMMediaProps streamMediaProps    = null;
            IntPtr        mediaTypeBufferPtr  = IntPtr.Zero;
            uint          mediaTypeBufferSize = 0;
            Guid          streamType          = Guid.Empty;
            WmMediaType   videoMediaType      = new WmMediaType();
            //Set WMVIDEOHEADER
            WMVIDEOINFOHEADER videoInfoHeader = new WMVIDEOINFOHEADER();

            //Setup the profile manager
            hr = WMLib.WMCreateProfileManager(out profileManager);
            profileManager2 = (IWMProfileManager2)profileManager;
            //Set profile version - possibly not needed in this case.
            profileManager2.SetSystemProfileVersion(WMVersion.V8_0);
            //get the profile to modify
            string strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPCustom.prx");
            //read the profile contents
            string profileContents = "";

            using (StreamReader prx = new StreamReader(strprofileType))
            {
                profileContents = prx.ReadToEnd();
            }

            profileManager2        = profileManager as IWMProfileManager2;
            profileManagerLanguage = profileManager as IWMProfileManagerLanguage;
            hr = profileManager2.GetSystemProfileVersion(out wmversion);
            Log.Info("DVRMS2WMV: WM version=" + wmversion.ToString());
            hr = profileManagerLanguage.GetUserLanguageID(out langID);
            Log.Info("DVRMS2WMV: WM language ID=" + langID.ToString());
            hr = profileManager2.SetSystemProfileVersion(DefaultWMversion);
            hr = profileManager2.GetSystemProfileCount(out nbrProfiles);
            Log.Info("DVRMS2WMV: ProfileCount=" + nbrProfiles.ToString());
            //load the profile contents
            hr = profileManager.LoadProfileByData(profileContents, out profile);
            //get the profile name
            hr = profile.GetName(profileName, ref profileNameLen);
            Log.Info("DVRMS2WMV: profile name {0}", profileName.ToString());
            //get the profile description
            hr = profile.GetDescription(profileDescription, ref profileDescLen);
            Log.Info("DVRMS2WMV: profile description {0}", profileDescription.ToString());
            //get the stream count
            hr = profile.GetStreamCount(out streamCount);
            for (int i = 0; i < streamCount; i++)
            {
                profile.GetStream(i, out streamConfig);
                streamMediaProps = (IWMMediaProps)streamConfig;
                streamConfig.GetStreamType(out streamType);
                if (streamType == MediaType.Video)
                {
                    //adjust the video details based on the user input values.
                    streamConfig.SetBitrate(videoBitrate);
                    streamConfig.SetBufferWindow(-1); //3 or 5 seconds ???
                    streamMediaProps.GetMediaType(IntPtr.Zero, ref mediaTypeBufferSize);
                    mediaTypeBufferPtr = Marshal.AllocHGlobal((int)mediaTypeBufferSize);
                    streamMediaProps.GetMediaType(mediaTypeBufferPtr, ref mediaTypeBufferSize);
                    Marshal.PtrToStructure(mediaTypeBufferPtr, videoMediaType);
                    Marshal.FreeHGlobal(mediaTypeBufferPtr);
                    Marshal.PtrToStructure(videoMediaType.pbFormat, videoInfoHeader);
                    videoInfoHeader.TargetRect.right  = 0; // set to zero to take source size
                    videoInfoHeader.TargetRect.bottom = 0; // set to zero to take source size
                    videoInfoHeader.BmiHeader.Width   = videoWidth;
                    videoInfoHeader.BmiHeader.Height  = videoHeight;
                    videoInfoHeader.BitRate           = videoBitrate;
                    videoInfoHeader.AvgTimePerFrame   = singleFramePeriod; //Need to check how this is to be calculated
                    IntPtr vidInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WMVIDEOINFOHEADER)));
                    Marshal.StructureToPtr(videoInfoHeader, vidInfoPtr, false);
                    videoMediaType.pbFormat = vidInfoPtr;
                    hr = streamMediaProps.SetMediaType(videoMediaType);
                    Marshal.FreeHGlobal(vidInfoPtr);
                }
                if (streamType == MediaType.Audio)
                {
                    //adjust the audio details based on the user input
                    //audio is determined from bitrate selection and thus effects audio profile.
                    hr = streamConfig.SetBitrate(audioBitrate);
                    hr = streamConfig.SetBufferWindow(-1); //3 or 5 seconds ???
                    //TODO: set the WaveformatEx profile info etc
                }
                //recofigures the stream ready for saving
                hr = profile.ReconfigStream(streamConfig);
            }
            //save the profile
            //You should make two calls to SaveProfile.
            //On the first call, pass NULL as pwszProfile.
            int profileLength = 0;

            hr = profileManager2.SaveProfile(profile, null, ref profileLength);
            //On return, the value of pdwLength is set to the length required to hold the profile in string form.
            //TODO: set memory buffer to profileLength
            //Then you can allocate the required amount of memory for the buffer and pass a pointer to it as pwszProfile on the second call.
            hr = profileManager2.SaveProfile(profile, profileContents, ref profileLength);
        }
Exemplo n.º 8
0
        // Use IWMStreamConfig interface to access
        // number of streams, each stream number, and bitrate
        ///////////////////////////////////////////////////////////////////////////////
        void GetPropertiesFromProfile(IWMProfile pProfile)
        {
            int dwStreamCount = 0;

            pProfile.GetStreamCount(out dwStreamCount);

            Console.WriteLine(string.Format("This Windows Media file has {0} stream(s)", dwStreamCount));

            for (int dwIndex = 0; dwIndex < dwStreamCount; dwIndex++)
            {
                IWMStreamConfig pConfig = null;
                pProfile.GetStream(dwIndex, out pConfig);

                try
                {
                    Guid guid;
                    pConfig.GetStreamType(out guid);
                    if (MediaType.Video == guid)
                    {
                        short wStreamNum = -1;
                        int   dwBitrate  = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Video Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps", dwBitrate));

                        PrintCodecName(pConfig);
                    }
                    else if (MediaType.Audio == guid)
                    {
                        short wStreamNum = -1;
                        int   dwBitrate  = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Audio Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps", dwBitrate));

                        PrintCodecName(pConfig);
                    }
                    else if (MediaType.ScriptCommand == guid)
                    {
                        short wStreamNum = -1;
                        int   dwBitrate  = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Script Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps\n", dwBitrate));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(pConfig);
                }
            }
        }
Exemplo n.º 9
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;
		}
Exemplo n.º 10
0
        public static void CopyWmv(string inputFilePath, string outputFilePath, ulong startTime, long duration)
        {
            IWMWriterAdvanced writerAdvanced = null;
            IWMProfile        profile        = null;
            IWMStreamConfig   streamConfig   = null;
            uint streamCount = 0;
            uint inputCount  = 0;

            ushort[] streamNumbers = null;
            WMT_STREAM_SELECTION[] streamSelections = null;
            ulong      sampleTime, sampleDuration;
            uint       flags, outputNum;
            ushort     streamNum;
            INSSBuffer sample = null;

            IWMSyncReader reader = Helpers.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);
            IWMWriter     writer = Helpers.CreateWriter();

            try
            {
                reader.Open(inputFilePath);

                Logger.WriteLogMessage("Opened file [" + inputFilePath + "] for reading.");

                profile = (IWMProfile)reader;

                profile.GetStreamCount(out streamCount);

                streamNumbers = new ushort[streamCount];

                streamSelections = new WMT_STREAM_SELECTION[streamCount];

                for (uint i = 0; i < streamCount; i++)
                {
                    profile.GetStream(i, out streamConfig);

                    streamConfig.GetStreamNumber(out streamNumbers[i]);

                    streamSelections[i] = WMT_STREAM_SELECTION.WMT_ON;

                    //
                    // Read compressed samples
                    //
                    reader.SetReadStreamSamples(streamNumbers[i], true);
                }

                //
                // select all streams
                //
                reader.SetStreamsSelected((ushort)streamCount, streamNumbers, streamSelections);

                writer.SetProfile(profile);

                writer.GetInputCount(out inputCount);

                for (uint i = 0; i < inputCount; i++)
                {
                    writer.SetInputProps(i, null);                     // write compressed samples
                }

                writer.SetOutputFilename(outputFilePath);

                Logger.WriteLogMessage("Set output filename [" + outputFilePath + "] for writing.");

                writerAdvanced = (IWMWriterAdvanced)writer;

                // Copy attributes avoided
                // Copy Codec Info avoided
                // Copy all scripts in the header avoided

                writer.BeginWriting();

                //
                // startTime, duration are in 100-nsec ticks
                //
                reader.SetRange(startTime, duration);                 // seek

                Logger.WriteLogMessage("Set range on reader, startTime [" + startTime + "], duration [" + duration + "].");

                for (uint streamsRead = 0; streamsRead < streamCount;)
                {
                    try
                    {
                        streamNum = 0;

                        reader.GetNextSample(0, out sample, out sampleTime, out sampleDuration, out flags, out outputNum, out streamNum);

                        Logger.WriteLogMessage("Grabbed next video sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "].");

                        writerAdvanced.WriteStreamSample(streamNum, sampleTime, 0, sampleDuration, flags, sample);

                        Logger.WriteLogMessage("Wrote sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "].");
                    }
                    catch (COMException e)
                    {
                        if (e.ErrorCode == Constants.NS_E_NO_MORE_SAMPLES)
                        {
                            streamsRead++;
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                writer.EndWriting();
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public void SetProfile(IWMProfile profile)
        {
            //
            // assign profile to writer
            //
            _writer.SetProfile(profile);

            Logger.WriteLogMessage("Set profile on writer.");

            profile.GetStreamCount(out _writerStreamCount);

            Logger.WriteLogMessage("Found " + _writerStreamCount + " writer streams.");
        }
Exemplo n.º 13
0
        public void Initialize(IWMProfile profile, string filePath)
        {
            if (filePath == null || filePath.Length == 0)
                throw new ArgumentNullException("filePath", "Invalid string parameter.");

            //
            // assign profile to writer
            //
            _writer.SetProfile(profile);

            Logger.WriteLogMessage("Set profile on writer.");

            _writer.SetOutputFilename(filePath);

            Logger.WriteLogMessage("Set output filename [" + filePath + "] for writing.");

            _writer.GetInputCount(out _writerInputCount);

            Logger.WriteLogMessage("Found " + _writerInputCount + " writer inputs.");

            profile.GetStreamCount(out _writerStreamCount);

            Logger.WriteLogMessage("Found " + _writerStreamCount + " writer streams.");
        }
Exemplo n.º 14
0
        // Use IWMStreamConfig interface to access
        // number of streams, each stream number, and bitrate
        ///////////////////////////////////////////////////////////////////////////////
        void GetPropertiesFromProfile(IWMProfile pProfile)
        {
            int dwStreamCount = 0;
            pProfile.GetStreamCount(out dwStreamCount);

            Console.WriteLine(string.Format("This Windows Media file has {0} stream(s)", dwStreamCount));

            for (int dwIndex = 0; dwIndex < dwStreamCount; dwIndex++)
            {
                IWMStreamConfig pConfig = null;
                pProfile.GetStream(dwIndex, out pConfig);

                try
                {
                    Guid guid;
                    pConfig.GetStreamType(out guid);
                    if (MediaType.Video == guid)
                    {
                        short wStreamNum = -1;
                        int dwBitrate = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Video Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps", dwBitrate));

                        PrintCodecName(pConfig);
                    }
                    else if (MediaType.Audio == guid)
                    {
                        short wStreamNum = -1;
                        int dwBitrate = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Audio Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps", dwBitrate));

                        PrintCodecName(pConfig);
                    }
                    else if (MediaType.ScriptCommand == guid)
                    {
                        short wStreamNum = -1;
                        int dwBitrate = -1;

                        try
                        {
                            pConfig.GetStreamNumber(out wStreamNum);
                        }
                        catch { }
                        try
                        {
                            pConfig.GetBitrate(out dwBitrate);
                        }
                        catch { }

                        Console.WriteLine("Script Stream properties:");
                        Console.WriteLine(string.Format("Stream number: {0}", wStreamNum));
                        Console.WriteLine(string.Format("Bitrate: {0} bps\n", dwBitrate));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(pConfig);
                }
            }
        }