Example #1
0
        public bool FindAudioInfo(ref WM_MEDIA_TYPE mediaType, ref WaveFormat waveFormat)
        {
            bool            success = false;
            IWMStreamConfig stream  = null;
            IWMMediaProps   props   = null;
            Guid            mediaTypeGuid;

            IWMProfile profile = (IWMProfile)_reader;

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

                props = (IWMMediaProps)stream;

                WMMediaProps mediaProps = new WMMediaProps(props);

                mediaType     = mediaProps.MediaType;
                mediaTypeGuid = mediaType.majortype;

                if (mediaTypeGuid == MediaTypes.WMMEDIATYPE_Audio)
                {
                    Logger.WriteLogMessage("Found audio stream [" + i + "], format type [" + mediaType.formattype + "].");

                    waveFormat = (WaveFormat)Marshal.PtrToStructure(mediaType.pbFormat, typeof(WaveFormat));
                    success    = true;
                    break;
                }
            }

            return(success);
        }
Example #2
0
        private void Config()
        {
            IWMWriter          m_Writer;
            IWMInputMediaProps pProps;

            WMUtils.WMCreateWriter(IntPtr.Zero, out m_Writer);
            m_Writer.SetProfileByID(g);
            m_Writer.GetInputProps(0, out pProps);

            m_Props = pProps as IWMMediaProps;
        }
Example #3
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);
                }
            }
        }
Example #4
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);
        }
Example #5
0
        // Use IWMStreamConfig interface to access codec names
        ///////////////////////////////////////////////////////////////////////////////
        void PrintCodecName(IWMStreamConfig pConfig)
        {
            IWMMediaProps pMediaProps = null;

            pMediaProps = (IWMMediaProps)pConfig;

            int cbType = 0;

            pMediaProps.GetMediaType(null, ref cbType);

            AMMediaType mt = new AMMediaType();

            mt.formatSize = cbType;

            pMediaProps.GetMediaType(mt, ref cbType);

            try
            {
                //
                // Audio Codec Names
                //

                if (mt.subType == MediaSubType.WMAudioV9)
                {
                    Console.WriteLine("Codec Name: Windows Media Audio V9");
                }
                else if (mt.subType == MediaSubType.WMAudio_Lossless)
                {
                    Console.WriteLine("Codec Name: Windows Media Audio V9 (Lossless Mode)");
                }
                else if (mt.subType == MediaSubType.WMAudioV7)
                {
                    Console.WriteLine("Codec Name: Windows Media Audio V7/V8");
                }
                else if (mt.subType == MediaSubType.WMSP1)
                {
                    Console.WriteLine("Codec Name: Windows Media Speech Codec V9");
                }
                else if (mt.subType == MediaSubType.WMAudioV2)
                {
                    Console.WriteLine("Codec Name: Windows Media Audio V2");
                }
                else if (mt.subType == MediaSubType.ACELPnet)
                {
                    Console.WriteLine("Codec Name: ACELP.net");
                }

                // Video Codec Names
                //

                else if (mt.subType == MediaSubType.WMV1)
                {
                    Console.WriteLine("Codec Name: Windows Media Video V7");
                }
                else if (mt.subType == MediaSubType.MSS1)
                {
                    Console.WriteLine("Codec Name: Windows Media Screen V7");
                }
                else if (mt.subType == MediaSubType.MSS2)
                {
                    Console.WriteLine("Codec Name: Windows Media Screen V9");
                }
                else if (mt.subType == MediaSubType.WMV2)
                {
                    Console.WriteLine("Codec Name: Windows Media Video V8");
                }
                else if (mt.subType == MediaSubType.WMV3)
                {
                    Console.WriteLine("Codec Name: Windows Media Video V9");
                }
                else if (mt.subType == MediaSubType.MP43)
                {
                    Console.WriteLine("Codec Name: Microsoft MPEG-4 Video Codec V3 ");
                }
                else if (mt.subType == MediaSubType.MP4S)
                {
                    Console.WriteLine("Codec Name: ISO MPEG-4 Video V1");
                }
                else
                {
                    Console.WriteLine("Codec Name: {0}", AMToString.MediaSubTypeToString(mt.subType));
                }
                Console.WriteLine();
            }
            finally
            {
                WMUtils.FreeWMMediaType(mt);
            }
        }
Example #6
0
		public WMMediaProps(IWMMediaProps mediaProps)
		{
			_mediaProps = mediaProps;
		}
Example #7
0
 public WMMediaProps(IWMMediaProps mediaProps)
 {
     _mediaProps = mediaProps;
 }