Exemple #1
0
        private void LockRestartSession(MM_TASK openTask)
        {
            if (UIThreadCheck())
            {
                return;
            }

            _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_CLOSE, 0, IntPtr.Zero, 0));
            if (openTask == null)
            {
                _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_OPEN, 0, IntPtr.Zero, 0));
            }
            else
            {
                _interface.InvokeMMTask(openTask);
            }
            _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_PLAY, 0, IntPtr.Zero, 0));

            // set any source parameters
            if (_interface._parms.Source.SourceParms.Flags != 0)
            {
                _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_DICT, mmSessionDictionaryKeys.CLI_SOURCE, IntPtr.Zero, 0));
            }
            // set any dewarp params
            if (_interface._parms.Dewarp.DewarpParms.BSessionEnabled == 1)
            {
                _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_DICT, mmSessionDictionaryKeys.CLI_DEWARP, IntPtr.Zero, 0));
            }
            // set any zoom rect params
            if (_interface._parms.Zoom.ZoomParms.Right > 0 || _interface._parms.Zoom.ZoomParms.Bottom > 0)
            {
                _interface.InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_DICT, mmSessionDictionaryKeys.CLI_ZOOM, IntPtr.Zero, 0));
            }
        }
Exemple #2
0
      private MM_TASK PopNextTask()
      {
         lock (_taskLock)
         {
#if GET_HIGHEST_PRIORITY_TASK_FIRST
            MM_TASK nextTask = new MM_TASK(MM_TASK_ITEM.MM_NONE, 0, IntPtr.Zero, 0);

            foreach (var task in _taskList) // iterating from the first added item to the last
               if (task._item < nextTask._item) nextTask = task; // get highest priority or oldest of any duplicates (DICT only)

            if (nextTask._item != MM_TASK_ITEM.MM_NONE)
               _taskList.Remove(nextTask);

            return nextTask;
#else
            MM_TASK nextTask;
            if (_taskList.Count > 0)
            {
               nextTask = _taskList[0];
               _taskList.Remove(nextTask);
            }
            else
               nextTask = new MM_TASK(MM_TASK_ITEM.MM_NONE, 0, IntPtr.Zero, 0);

            return nextTask;
#endif
         }
         
      }
Exemple #3
0
 private void executeTask(MM_TASK task)
 {
    mmStatus sts = mmStatus.MM_STS_NONE;
    switch (task._item)
    {
       case MM_TASK_ITEM.MM_STOP:
          _run = false;
          goto case MM_TASK_ITEM.MM_CLOSE;
       case MM_TASK_ITEM.MM_CLOSE:
          sts = closeSession(task._dictKey, task._lpData);
          _state = MM_TASK_ITEM.MM_CLOSE;
          break;
       case MM_TASK_ITEM.MM_OPEN:
          sts = openSesssion(task._dictKey, task._lpData);
          _state = MM_TASK_ITEM.MM_OPEN;
          break;
       case MM_TASK_ITEM.MM_PLAY:
          sts = playSesssion(task._dictKey, task._lpData);
          _state = MM_TASK_ITEM.MM_PLAY;
          break;
       case MM_TASK_ITEM.MM_PAUSE:
          sts = pauseSesssion(task._dictKey, task._lpData);
          _state = MM_TASK_ITEM.MM_PAUSE;
          break;
       case MM_TASK_ITEM.MM_DICT:
          sts = dictSession(task._dictKey, task._lpData);
          break;
       default:
          Debug.Assert(false);
          break;
    }
 }
Exemple #4
0
      public void InvokeMMTask(MM_TASK newTask)
      {
         if (!_run)
            return;
     
         lock (_taskLock)
         {
            // at this point, drop all other tasks for the session
            if (newTask._item == MM_TASK_ITEM.MM_CLOSE || newTask._item ==  MM_TASK_ITEM.MM_STOP)
            {
               foreach (var task in _taskList)
                  FreeTask(task);

               _taskList.Clear();
               _taskList.Add(newTask);
            }
            else
            {
               MM_TASK tasksToReplace = null; // ie multiple PLAY commands in the list

               foreach (var task in _taskList)
                  if (task._item == newTask._item &&
                     task._dictKey == newTask._dictKey &&
                     ReplaceableTask(task)) // optomize our list of tasks
                  {
                     tasksToReplace = task;
                     break;
                  }

               if (tasksToReplace != null) // keep the order and drop any out of date tasks
               {
#if REPLACE_TASK_IN_ITS_ORG_ORDER
                  int index = _taskList.IndexOf(tasksToReplace); // replace a task
                  if (index != -1)
                  {
                     if (tasksToReplace._lpData != IntPtr.Zero)
                        FreeTask(tasksToReplace);
                     _taskList[index] = newTask; // keep the tasks original order
                  }
                  else
                     Debug.Assert(false)
#else
                  _taskList.Remove(tasksToReplace);
                  if (tasksToReplace._lpData != IntPtr.Zero)
                     FreeTask(tasksToReplace);
#endif
               }
               _taskList.Add(newTask); // this will add to the end of the list
            }
            _ewh.Set(); // wake up the task thread
         }
      }
Exemple #5
0
      private void threadLoop()
      {
         while (_run)
         {
            MM_TASK task = PopNextTask();

            if (task._item == MM_TASK_ITEM.MM_NONE)
               _ewh.WaitOne();
            else
               executeTask(task);

            FreeTask(task);
         }
      }
Exemple #6
0
 private bool ReplaceableTask(MM_TASK task)
 {
    switch (task._dictKey)
    {
       case mmSessionDictionaryKeys.NO_OP:
          return true;
       case mmSessionDictionaryKeys.CLI_DEWARP:
          return true;
       case mmSessionDictionaryKeys.CLI_SOURCE:
          return false; // TODO: start inspecting structure flags
       case mmSessionDictionaryKeys.CLI_ZOOM:
          return true;
       case mmSessionDictionaryKeys.CLI_CHILD:
          return false; // TODO: start inspecting structure flags
       case mmSessionDictionaryKeys.CLI_RESET:
          return true;
       default:
          Debug.Assert(false);
          return false;
    }
 }
Exemple #7
0
      public void Stop()
      {           
         do // drain task list, safe as we do not use _taskLock in threadLoop()
         {
            MM_TASK task = PopNextTask();
            if (task._item == MM_TASK_ITEM.MM_NONE)
               break;
            else
               FreeTask(task);
         }
         while (true);

         if (_thread != null)
         {
            // stop the task thread threadLoop()
            InvokeMMTask(new MM_TASK(MM_TASK_ITEM.MM_STOP, 0, IntPtr.Zero, 0));
            if (_thread.Join(35000) == false) // mmOpen could of just been called and not return for 20+ seconds..
               Debug.Assert(false);
         }
         // stay in sync with the calling thread
         _ewh.Close();
      }
Exemple #8
0
 private void FreeTask(MM_TASK task)
 {
    if (task._lpData != IntPtr.Zero)
       Marshal.FreeHGlobal(task._lpData);
    task = null;
 }