Esempio n. 1
0
        public void LockCloseWindow(uint childMarker)
        {
            try
            {
                if (UIThreadCheck())
                {
                    return;
                }

                // all done close program
                // Note, any mmOpen call can take 20+ seconds if the URL does not exist,
                // this is when the UI thread will also be writing error ststus to the screen
                // _thread.Join() in _interface.Stop(); will deadlock (see InvokeRequired calls in MMWindow)
                // if we use the UI thread for the sync functionality (ie we want to clean up properly)
                // we use a new task thread which we should be on
                _closing = true;   // used in _watchDog
                _interface.Stop(); // stop and cleanup nicely
                while (_watchDog.Enabled != false)
                {
                    System.Threading.Thread.Sleep(100);
                }
                _watchDog.Close(); // safe to close correctly
                // call this function with lParam set
                MMInterop.SendMessage(GetHWND(), MMInterop.WM_CLOSE, IntPtr.Zero, (IntPtr)1);
            }
            catch { Debug.Assert(false); }
            return;
        }
Esempio n. 2
0
        public static bool MMLoad(ref MM_LOAD load, string baseDirectory)
        {
            string mmLibPath = GetMultiMediaPath(baseDirectory);

            if (!string.IsNullOrEmpty(mmLibPath))
            {
                try
                {
                    if (!MMInterop.SetDllDirectory(mmLibPath))
                    {
                        Exception e = new System.ComponentModel.Win32Exception();
                        throw new DllNotFoundException("Error, Unable to load library: " + mmLibPath, e);
                    }
                    else
                    {
                        load.Size = (uint)Marshal.SizeOf(typeof(MM_LOAD));
                        mmStatus sts = mmMethods.mmLoad(ref load);
                        if (sts == mmStatus.MM_STS_NONE)
                        {
                            return(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            Console.WriteLine($"Error, failed to Load mmAPI from {baseDirectory}");
            return(false);
        }
Esempio n. 3
0
 public MM_TASK(MM_TASK_ITEM item, mmSessionDictionaryKeys dictKey, IntPtr lpData, int dataSize)
 {
    _item = item;
    _dictKey = dictKey;
    if (dataSize > 0) // not using internal parameters (_parms)
    {
       try
       {
          _lpData = Marshal.AllocHGlobal(dataSize);
          MMInterop.memcpy(_lpData, lpData, new UIntPtr((uint)dataSize));
       }
       catch { Debug.Assert(false); }
    }
 }
Esempio n. 4
0
        public static bool MMLoad(ref MM_LOAD load, string baseDirectory)
        {
            string mmLibPath = GetMultiMediaPath(baseDirectory);

            if (!string.IsNullOrEmpty(mmLibPath))
            {
                try
                {
                    if (!MMInterop.SetDllDirectory(mmLibPath))
                    {
                        Exception e = new System.ComponentModel.Win32Exception();
                        throw new DllNotFoundException("Error, Unable to load library: " + mmLibPath, e);
                    }
                    else
                    {
                        load.Size = (uint)Marshal.SizeOf(typeof(MM_LOAD));
                        mmStatus sts = mmMethods.mmLoad(ref load);
                        if (sts == mmStatus.MM_STS_NONE)
                        {
                            bool activated = false;
                            if ((load.OutFlags & MM_LOAD_CONTEXT.MM_LOAD_CONTEXT_ACTIVATED) == MM_LOAD_CONTEXT.MM_LOAD_CONTEXT_ACTIVATED)
                            {
                                activated = true;
                            }

                            String loadString = String.Format("mmAPI v{0}.{1}.{2} activated={3} flags={4}",
                                                              load.Version.Major.ToString().PadLeft(2, '0'), load.Version.Minor.ToString().PadLeft(2, '0'), load.Version.Micro.ToString().PadLeft(2, '0'),
                                                              activated, load.OutFlags);

                            Console.WriteLine(loadString);
                            return(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            Console.WriteLine($"Error, failed to Load mmAPI from {baseDirectory}");
            return(false);
        }
Esempio n. 5
0
 public static bool MMLoadEx(ref MM_LOAD load, string path)
 {
     try
     {
         if (MMInterop.SetDllDirectory(path))
         {
             load.Size = (uint)Marshal.SizeOf(typeof(MM_LOAD));
             mmStatus sts = mmMethods.mmLoad(ref load);
             if (sts == mmStatus.MM_STS_NONE)
             {
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         //Console.WriteLine(e.ToString());
     }
     return(false);
 }
Esempio n. 6
0
        private void Window_Load(object sender, EventArgs e)
        {
            // allow simple inter process communication via SendMessage now we have the hWnd
            MMInterop.CHANGEFILTERSTRUCT changeFilter = new MMInterop.CHANGEFILTERSTRUCT();
            changeFilter.size = (uint)Marshal.SizeOf(changeFilter);
            changeFilter.info = 0;
            if (!MMInterop.ChangeWindowMessageFilterEx
                    (this.Handle, MMInterop.WM_COPYDATA,
                    MMInterop.ChangeWindowMessageFilterExAction.Allow, ref changeFilter))
            {
                int error = Marshal.GetLastWin32Error();
                Debug.WriteLine(String.Format(String.Format("ChangeWindowMessageFilterEx error {0} occurred.", error)));
                Debug.Assert(false);
            }

            this.Hide(); // the function below will show upon completion of setting itself up, avoids flashing window on startup
            // set the window position first, important as auto GPU selection depends on this placement
            if (updateWindowMethod(_interface._parms.Window.WindowParms))
            {
                _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_DICT, mmSessionDictionaryKeys.CLI_RESET, IntPtr.Zero, 0));
            }
        }
Esempio n. 7
0
      private mmStatus playSesssion(mmSessionDictionaryKeys flags, IntPtr lpData)
      {
         if (_hSession == IntPtr.Zero)
            return mmStatus.MM_STS_LIB_ERROR_INVALID_STATE;

         if (lpData != IntPtr.Zero) // else a re-connect on error case using existing params
         {
            _parms.Play.PlayParms = (MM_CLIENT_PLAY)Marshal.PtrToStructure(lpData, typeof(MM_CLIENT_PLAY));
            if (_parms.Play.PlayParms.Size == (Marshal.SizeOf(typeof(MM_CLIENT_PLAY))))
            {
               _parms.Play.StartTime = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_PLAY)));
               _parms.Play.EndTime = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_PLAY)) + (2 * (_parms.Play.StartTime.Length + 1)));
            }
            else
               return mmStatus.MM_STS_SRC_ERROR_INCOMPATIBLE_API;
         }

         if (string.IsNullOrEmpty(_parms.Play.StartTime))
            _parms.Play.PlayParms.PStartTime = IntPtr.Zero;
         else
            _parms.Play.PlayParms.PStartTime = (IntPtr)Marshal.StringToHGlobalAnsi(_parms.Play.StartTime);

         if (string.IsNullOrEmpty(_parms.Play.EndTime))
            _parms.Play.PlayParms.PEndTime = IntPtr.Zero;
         else
            _parms.Play.PlayParms.PEndTime = (IntPtr)Marshal.StringToHGlobalAnsi(_parms.Play.EndTime);

         mmStatus sts = mmMethods.mmClientPlay(_hSession, ref _parms.Play.PlayParms);

         if (_parms.Play.PlayParms.PStartTime != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Play.PlayParms.PStartTime);
         if (_parms.Play.PlayParms.PEndTime != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Play.PlayParms.PEndTime);

         return sts; // any play error makes its way back via the callback
      }
Esempio n. 8
0
      private mmStatus openSesssion(mmSessionDictionaryKeys flags, IntPtr lpData)
      {
         if (_hSession != IntPtr.Zero)
            return mmStatus.MM_STS_LIB_ERROR_INVALID_STATE;

         if (lpData != IntPtr.Zero) // else a re-connect on error case using existing params
         {
            _parms.Open.OpenParms = (MM_CLIENT_OPEN)Marshal.PtrToStructure(lpData, typeof(MM_CLIENT_OPEN));
            if (_parms.Open.OpenParms.Size == (Marshal.SizeOf(typeof(MM_CLIENT_OPEN))))
            {
               _parms.Open.URL = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)));
               _parms.Open.UserName = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)) + (2 * (_parms.Open.URL.Length + 1)));
               _parms.Open.PassWord = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)) + (2 * ((_parms.Open.URL.Length + 1) + (_parms.Open.UserName.Length + 1))));
            }
            else
               return mmStatus.MM_STS_SRC_ERROR_INCOMPATIBLE_API;
         }
         
         string basicAuth = _parms.Open.URL;
         if( (uint)flags != 0x80000000) // playlist case
            _windowParent.LockPaintSessionStatus("Opening URL: " + _parms.Open.URL);

         _windowParent.LockSetSessionWindowText(_parms.Open.URL);

         if (!string.IsNullOrEmpty(_parms.Open.UserName))
         {
            var index = _parms.Open.URL.IndexOf("://");
            if (index != -1)
               basicAuth = basicAuth.Insert(index + 3, _parms.Open.UserName + ":" + _parms.Open.PassWord + "@");
         }

         _parms.Open.OpenParms.HWnd = _windowParent.GetHWND();

         // account for UTF8 encoded data
         int len = Encoding.UTF8.GetByteCount(basicAuth);
         byte[] utf8Bytes = new byte[len + 1];
         Encoding.UTF8.GetBytes(basicAuth, 0, basicAuth.Length, utf8Bytes, 0);
         _parms.Open.OpenParms.PURL = Marshal.AllocHGlobal(utf8Bytes.Length); 
         Marshal.Copy(utf8Bytes, 0, _parms.Open.OpenParms.PURL, utf8Bytes.Length);

         if (_parms.Open.Reserved != 0)
         {
            _parms.Open.OpenParms.PReserved = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
            Marshal.WriteInt32(_parms.Open.OpenParms.PReserved, 0, ((int)_parms.Open.Reserved));
         }
         else
            _parms.Open.OpenParms.PReserved = IntPtr.Zero;

         mmStatus sts = mmMethods.mmClientOpen(out _hSession, ref _parms.Open.OpenParms);
         if (sts != mmStatus.MM_STS_NONE)
         {
            _windowParent.LockPaintSessionStatus($"STATUS 0x{sts:X} Opening URL: " + _parms.Open.URL);
            _windowParent._watchDog.Enabled = true;
            // start a fresh
            _parms.Play.StartTime = null;
            _parms.Play.EndTime = null;
         }
         else
            _windowParent.LockPaintSessionStatus("");

         if (_parms.Open.OpenParms.PReserved != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Open.OpenParms.PReserved);
         
         Marshal.FreeHGlobal(_parms.Open.OpenParms.PURL);
         return sts;
      }