PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/animeplugin3/FFDShowAPI/FFDShowAPI.cs

https://bitbucket.org/gibwar/jmm-test
C# | 2224 lines | 1578 code | 177 blank | 469 comment | 278 complexity | 202026f85ddaad6bb9082b3dc51a6ed7 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. using System.Diagnostics;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Collections;
  9. using Microsoft.Win32;
  10. using System.IO;
  11. using System.Runtime.Remoting.Messaging;
  12. using FFDShowAPI.Interfaces;
  13. namespace FFDShowAPI
  14. {
  15. /// <summary>
  16. /// FFDShowAPI library class. Use this class to get/set FFDShow live settings
  17. /// </summary>
  18. public class FFDShowAPI : IDisposable
  19. {
  20. #region Guids
  21. public static readonly Guid FFDShowVideoGuid = new Guid("04FE9017-F873-410E-871E-AB91661A4EF7");
  22. public static readonly Guid FFDShowVideoDXVAGuid = new Guid("0B0EFF97-C750-462C-9488-B10E7D87F1A6");
  23. public static readonly Guid FFDShowVideoRawGuid = new Guid("0B390488-D80F-4A68-8408-48DC199F0E97");
  24. #endregion
  25. #region Constants
  26. /// <summary>
  27. /// Identifier of Window messages structure that can carry string for interprocess communication
  28. /// </summary>
  29. public const int WM_COPYDATA = 0x004A;
  30. /// <summary>
  31. /// List of commands understood by FFDShow remote API
  32. /// These are commands that concern integers transmission (get or set) or
  33. /// single commands such as "Pause video"
  34. /// </summary>
  35. private enum FFD_WPRM : int
  36. {
  37. SET_PARAM_NAME = 0,
  38. SET_PARAM_VALUE_INT = 1,
  39. GET_PARAM_NAME = 2,
  40. GET_PARAM_VALUE_INT = 3,
  41. PAUSE_VIDEO = 4,
  42. RESUME_VIDEO = 5,
  43. GET_STATE = 6,
  44. GET_DURATION = 7,
  45. GET_CUR_TIME = 8,
  46. SET_PARAM_VALUE_STR = 9,
  47. //GET_PARAM_VALUE_STR = 13,
  48. SET_CURTIME = 13,
  49. SET_ADDTOROT = 14,
  50. FASTFORWARD = 15,
  51. FASTREWIND = 16,
  52. GETFASTFORWARDSPEED = 17,
  53. CAPTUREIMAGE = 18,
  54. SET_OSD_POSX = 19,
  55. SET_OSD_POSY = 20,
  56. //SET_STREAM = 21,
  57. //GET_CURRENT_AUDIO_STREAM = 22,
  58. //GET_CURRENT_SUBTITLE_STREAM = 23,
  59. GET_FRAMERATE = 24,
  60. SET_AUDIO_STREAM = 25,
  61. SET_SUBTITLE_STREAM = 26,
  62. SET_FFRW_NO_OSD = 27
  63. }
  64. /// <summary>
  65. /// List of commands understood by FFDShow remote API.
  66. /// These are commands that require strings transmissions
  67. /// </summary>
  68. #pragma warning disable 1591
  69. public enum FFD_MSG
  70. {
  71. GET_PARAMSTR = 19,
  72. GET_CURRENT_SUBTITLES = 20,
  73. GET_PRESETLIST = 21,
  74. GET_SOURCEFILE = 22,
  75. GET_SUBTITLEFILESLIST = 23,
  76. GET_CHAPTERSLIST = 25,
  77. GET_AUDIOSTREAMSLIST = 300,
  78. GET_SUBTITLESTREAMSLIST = 301
  79. }
  80. #pragma warning restore 1591
  81. //Copy data flags
  82. private const int FFDSM_SET_ACTIVE_PRESET_STR = 10;
  83. private const int FFDSM_SET_SHORTOSD_MSG = 18;
  84. private const int FFDSM_SET_OSD_MSG = 19;
  85. /// <summary>
  86. /// Playing state
  87. /// </summary>
  88. public enum PlayState : int
  89. {
  90. /// <summary>
  91. /// Stop state
  92. /// </summary>
  93. StopState = 0,
  94. /// <summary>
  95. /// Pause state
  96. /// </summary>
  97. PauseState = 1,
  98. /// <summary>
  99. /// Play state
  100. /// </summary>
  101. PlayState = 2,
  102. /// <summary>
  103. /// Fast forwarding or rewinding state
  104. /// </summary>
  105. FastForwardRewind = 3
  106. };
  107. /// <summary>
  108. /// Running object table registration
  109. /// </summary>
  110. public enum ROTRegistration : int
  111. {
  112. /// <summary>
  113. /// Register the DirectShow graph in the running object table (graph can be read and modified after that)
  114. /// Don't forget to unregister it.
  115. /// </summary>
  116. RegisterToRot = 1,
  117. /// <summary>
  118. /// Unregister the DirectShow graph from the running object table
  119. /// </summary>
  120. UnregisterToRot = 0
  121. };
  122. /// <summary>
  123. /// File name mode
  124. /// </summary>
  125. public enum FileNameMode : int
  126. {
  127. /// <summary>
  128. /// Full path (including drive and directories)
  129. /// </summary>
  130. FullPath,
  131. /// <summary>
  132. /// File name with extension but without the directory path
  133. /// </summary>
  134. FileName,
  135. /// <summary>
  136. /// File name without extension and without the directory path
  137. /// </summary>
  138. FileNameWithoutExtension
  139. }
  140. private const int FALSE = 0;
  141. private const int TRUE = 1;
  142. public const int minRevision = 3452;
  143. #endregion Constants
  144. #region Structures
  145. /// <summary>
  146. /// FFDShow instance structure
  147. /// </summary>
  148. public struct FFDShowInstance
  149. {
  150. /// <summary>
  151. /// Unique identifier for this FFDShow instance
  152. /// </summary>
  153. public int handle;
  154. /// <summary>
  155. /// File name of the media being played by this instance (may be null)
  156. /// </summary>
  157. public string fileName;
  158. }
  159. #endregion Structures
  160. #region Variables
  161. private static string ffdshowRegKey = @"SOFTWARE\GNU\ffdshow";
  162. private static string ffdshowAudioRegKey = @"SOFTWARE\GNU\ffdshow_audio";
  163. private uint FFDShowAPIRemoteId = 32786;
  164. /// <summary>
  165. /// Unique identifier of the running instance of FFDShow
  166. /// </summary>
  167. protected int ffDShowInstanceHandle = 0;
  168. private int requestTimeout = 2000;
  169. private FFDShowReceiver receiver = null;
  170. private bool IsFFDShowActive = false;
  171. private static string strAppName = "ffdshow_remote_class";
  172. private string fileName = null;
  173. private FileNameMode fileNameMode = FileNameMode.FullPath;
  174. private int initFFDShowInstanceHandle = 0;
  175. private static bool ffrwNoOSD = false;
  176. private IffdshowDec ffdshowDec = null;
  177. private IffDecoder ffDecoder = null;
  178. private IffdshowBase ffdshowBase = null;
  179. private IffdshowDecVideo ffdshowDecVideo = null;
  180. private IAMStreamSelect streamSelect = null;
  181. public enum FFDShowAPIMode { DirectShowMode, InterProcessMode };
  182. private FFDShowAPIMode ffdshowAPIMode = FFDShowAPIMode.InterProcessMode;
  183. //private AutoResetEvent resetEvent = new AutoResetEvent(false);
  184. #endregion Variables
  185. #region WIN32 Class
  186. #pragma warning disable 1591
  187. /// <summary>
  188. /// Win32 COM methods and constants
  189. /// </summary>
  190. public class Win32
  191. {
  192. // The CopyData Constant for SendMessage
  193. public const Int32 WM_COPYDATA = 0x004A;
  194. public const Int32 WM_KEYDOWN = 0x0100;
  195. public const Int32 WM_APPCOMMAND = 0x0319;
  196. public const Int32 WM_INPUT = 0x00FF;
  197. [StructLayout(LayoutKind.Sequential)]
  198. public struct COPYDATASTRUCT
  199. {
  200. internal UIntPtr dwData;
  201. internal uint cbData;
  202. internal IntPtr lpData;
  203. }
  204. // Import the SendMessage function for use with COPYDATASTRUCT
  205. [DllImport("User32.Dll")]
  206. public static extern IntPtr SendMessage(IntPtr hwnd, Int32 msg, Int32 hwndFrom, ref COPYDATASTRUCT cds);
  207. [DllImport("User32.Dll")]
  208. public static extern IntPtr SendMessage(IntPtr hwnd, Int32 msg, Int32 hwndFrom, IntPtr cds);
  209. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  210. public static extern IntPtr SendMessageTimeout(
  211. IntPtr windowHandle,
  212. int Msg,
  213. IntPtr wParam,
  214. ref COPYDATASTRUCT cds,
  215. SendMessageTimeoutFlags flags,
  216. int timeout,
  217. out IntPtr result);
  218. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  219. public static extern IntPtr SendMessageTimeout(
  220. IntPtr windowHandle,
  221. [MarshalAs(UnmanagedType.U4)]
  222. int Msg,
  223. IntPtr wParam,
  224. IntPtr lParam,
  225. SendMessageTimeoutFlags flags,
  226. int timeout,
  227. out IntPtr result);
  228. public enum SendMessageTimeoutFlags
  229. {
  230. SMTO_NORMAL = 0x0000,
  231. SMTO_BLOCK = 0x0001,
  232. SMTO_ABORTIFHUNG = 0x0002,
  233. SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
  234. }
  235. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  236. public static extern IntPtr PostMessage(IntPtr hwnd, Int32 msg, Int32 hwndFrom, ref COPYDATASTRUCT cds);
  237. // Use COM interop to call the Win32 API GetLocalInfo.
  238. [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
  239. public static extern int GetLocaleInfo(
  240. // The locale identifier.
  241. int Locale,
  242. // The information type.
  243. int LCType,
  244. // The buffer size.
  245. [In, MarshalAs(UnmanagedType.LPWStr)] string lpLCData, int cchData
  246. );
  247. // Import the GlobalSize function
  248. [DllImport("kernel32.dll")]
  249. public static extern Int32 GlobalSize(IntPtr hmem);
  250. public const int WM_SYSCOMMAND = 0x0112;
  251. public const int SC_CLOSE = 0xF060;
  252. [DllImport("User32.Dll")]
  253. public static extern int FindWindow(string lpClassName,
  254. string lpWindowName);
  255. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  256. public static extern IntPtr SendMessage(int hWnd, uint Msg,
  257. int wParam, int lParam);
  258. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  259. public static extern IntPtr PostMessage(int hWnd, uint Msg,
  260. int wParam, int lParam);
  261. public delegate bool CallBack(int hwnd, IntPtr lParam);
  262. [DllImport("User32.Dll")]
  263. public static extern int EnumWindows(CallBack x, IntPtr y);
  264. [DllImport("User32.Dll")]
  265. public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
  266. [DllImport("User32.Dll")]
  267. public static extern void GetClassName(int h, StringBuilder s, int nMaxCount);
  268. [DllImport("User32.Dll")]
  269. public static extern int IsWindow(int hwnd);
  270. }
  271. #pragma warning restore 1591
  272. #endregion WIN32 Class
  273. #region Base Properties
  274. /// <summary>
  275. /// Gets the FFDShow instance handle (number that identifies the FFDShow instance)
  276. /// </summary>
  277. public int FFDShowInstanceHandle
  278. {
  279. get
  280. {
  281. return ffDShowInstanceHandle;
  282. }
  283. }
  284. /// <summary>
  285. /// Gets or sets the FFDShow remote identifier
  286. /// </summary>
  287. public uint FFDShowAPIRemote
  288. {
  289. get
  290. {
  291. return FFDShowAPIRemoteId;
  292. }
  293. set
  294. {
  295. FFDShowAPIRemoteId = value;
  296. }
  297. }
  298. /// <summary>
  299. /// Gets or sets the FFDShow registry key. Used sometimes when ffdshow is not active (for presets)
  300. /// </summary>
  301. public static string FFDShowRegKey
  302. {
  303. get
  304. {
  305. return ffdshowRegKey;
  306. }
  307. set
  308. {
  309. ffdshowRegKey = value;
  310. }
  311. }
  312. /// <summary>
  313. /// Gets or sets the registry key of FFDShow audio
  314. /// Used to get or set the default audio preset
  315. /// </summary>
  316. public static string FFDShowAudioRegKey
  317. {
  318. get
  319. {
  320. return ffdshowAudioRegKey;
  321. }
  322. set
  323. {
  324. ffdshowAudioRegKey = value;
  325. }
  326. }
  327. private static int osdX = 0;
  328. private static int osdY = 10;
  329. private bool updateOSD = false;
  330. /// <summary>
  331. /// Horizontal OSD position
  332. /// </summary>
  333. public static int OSDX
  334. {
  335. get
  336. {
  337. return osdX;
  338. }
  339. set
  340. {
  341. osdX = value;
  342. }
  343. }
  344. /// <summary>
  345. /// Vertical OSD position
  346. /// </summary>
  347. public static int OSDY
  348. {
  349. get
  350. {
  351. return osdY;
  352. }
  353. set
  354. {
  355. osdY = value;
  356. }
  357. }
  358. /// <summary>
  359. /// Gets or sets the OSD display when doing FastForward/Rewind
  360. /// This is a static parameter that will be applied to all the running FFDShow instances
  361. /// </summary>
  362. public static bool FFRWNoOSD
  363. {
  364. get
  365. {
  366. return ffrwNoOSD;
  367. }
  368. set
  369. {
  370. ffrwNoOSD = value;
  371. }
  372. }
  373. #endregion Base Properties
  374. #region Presets properties
  375. /// <summary>
  376. /// Gets or sets the default video preset (does not apply to currently running instances)
  377. /// </summary>
  378. public static String DefaultVideoPreset
  379. {
  380. get
  381. {
  382. using (RegistryKey preferencesKey = Registry.CurrentUser.OpenSubKey(ffdshowRegKey))
  383. {
  384. if (preferencesKey != null)
  385. {
  386. return (string)preferencesKey.GetValue("activePreset");
  387. }
  388. else return null;
  389. }
  390. }
  391. set
  392. {
  393. string[] presetList = VideoPresets;
  394. // Check if we set an existing preset
  395. bool found = false;
  396. for (int i = 0; i < presetList.Length; i++)
  397. {
  398. if (presetList[i].Equals(value))
  399. {
  400. found = true;
  401. break;
  402. }
  403. }
  404. if (found)
  405. using (RegistryKey preferencesKey = Registry.CurrentUser.CreateSubKey(ffdshowRegKey))
  406. {
  407. if (preferencesKey != null)
  408. {
  409. preferencesKey.SetValue("activePreset", value);
  410. }
  411. }
  412. }
  413. }
  414. /// <summary>
  415. /// Gets or sets the default audio preset (does not apply to currently running instances)
  416. /// </summary>
  417. public static string DefaultAudioPreset
  418. {
  419. get
  420. {
  421. using (RegistryKey preferencesKey = Registry.CurrentUser.OpenSubKey(ffdshowAudioRegKey))
  422. {
  423. if (preferencesKey != null)
  424. {
  425. return (string)preferencesKey.GetValue("activePreset");
  426. }
  427. else return null;
  428. }
  429. }
  430. set
  431. {
  432. string[] presetList = AudioPresets;
  433. // Check if we set an existing preset
  434. bool found = false;
  435. for (int i = 0; i < presetList.Length; i++)
  436. {
  437. if (presetList[i].Equals(value))
  438. {
  439. found = true;
  440. break;
  441. }
  442. }
  443. if (!found) return;
  444. using (RegistryKey preferencesKey = Registry.CurrentUser.CreateSubKey(ffdshowAudioRegKey))
  445. {
  446. if (preferencesKey != null)
  447. {
  448. preferencesKey.SetValue("activePreset", value);
  449. }
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// Gets or sets the video preset for the current instance. Also sets the preset as default.
  455. /// </summary>
  456. public String ActivePreset
  457. {
  458. get
  459. {
  460. string tmpStr = getStringParam(FFDShowConstants.FFDShowDataId.IDFF_OSDcurPreset);
  461. if (tmpStr != null && !tmpStr.Equals(""))
  462. {
  463. return tmpStr;
  464. }
  465. else
  466. {
  467. return DefaultVideoPreset;
  468. }
  469. }
  470. set
  471. {
  472. if (IsFFDShowActive)
  473. {
  474. PlayState playState = getState();
  475. if (playState == PlayState.PlayState || playState == PlayState.FastForwardRewind)
  476. pauseVideo();
  477. Win32.COPYDATASTRUCT cd = new Win32.COPYDATASTRUCT();
  478. cd.dwData = new UIntPtr((uint)FFDSM_SET_ACTIVE_PRESET_STR);
  479. #if UNICODE
  480. cd.lpData = Marshal.StringToHGlobalUni(value);
  481. #else
  482. cd.lpData = Marshal.StringToHGlobalAnsi(value);
  483. #endif
  484. cd.cbData = (uint)Win32.GlobalSize(cd.lpData);
  485. if (receiver == null)
  486. receiver = new FFDShowReceiver(Thread.CurrentThread);
  487. receiver.ReceivedString = null;
  488. receiver.ReceivedType = 0;
  489. //receiver.ParentThread = Thread.CurrentThread;
  490. Win32.SendMessage(new IntPtr(ffDShowInstanceHandle), Win32.WM_COPYDATA, receiver.Handle.ToInt32(), ref cd);
  491. if (playState == PlayState.PlayState || playState == PlayState.FastForwardRewind)
  492. startVideo();
  493. }
  494. DefaultVideoPreset = value;
  495. }
  496. }
  497. /// <summary>
  498. /// Gets or sets the default audio preset (does not apply to currently running instances).
  499. /// Same behaviour as DefaultAudioPreset property
  500. /// </summary>
  501. public string ActiveAudioPreset
  502. {
  503. get
  504. {
  505. return DefaultAudioPreset;
  506. }
  507. set
  508. {
  509. DefaultAudioPreset = value;
  510. }
  511. }
  512. #endregion Presets properties
  513. #region Enabled Properties
  514. // Show/hide subtitles
  515. /// <summary>
  516. /// Enable or disable subtitles filter
  517. /// </summary>
  518. public bool DoShowSubtitles
  519. {
  520. get
  521. {
  522. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles);
  523. if (value == 1)
  524. return true;
  525. else return false;
  526. }
  527. set
  528. {
  529. if (value)
  530. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles, 1);
  531. else
  532. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles, 0);
  533. }
  534. }
  535. /// <summary>
  536. /// Enable/disable crop and zoom
  537. /// </summary>
  538. public bool DoCropZoom
  539. {
  540. get
  541. {
  542. return (getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isCropNzoom) == 1);
  543. }
  544. set
  545. {
  546. if (value)
  547. {
  548. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isCropNzoom, 1);
  549. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationLocked, 0);
  550. //IDFF_cropNzoomMode => 2
  551. }
  552. else
  553. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isCropNzoom, 0);
  554. }
  555. }
  556. /// <summary>
  557. /// Enable/disable lock of cropping
  558. /// </summary>
  559. public bool isCropZoomLocked
  560. {
  561. get
  562. {
  563. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationLocked);
  564. if (value == 1)
  565. return true;
  566. else return false;
  567. }
  568. set
  569. {
  570. if (value)
  571. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationLocked, 1);
  572. else
  573. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationLocked, 0);
  574. }
  575. }
  576. /// <summary>
  577. /// Enable/disable picture properties
  578. /// </summary>
  579. public bool DoPictureProperties
  580. {
  581. get
  582. {
  583. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPictProp);
  584. if (value == 1)
  585. return true;
  586. else return false;
  587. }
  588. set
  589. {
  590. if (value)
  591. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPictProp, 1);
  592. else
  593. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPictProp, 0);
  594. }
  595. }
  596. /// <summary>
  597. /// Enable/disable crop and zoom
  598. /// </summary>
  599. public bool DoPostProcessing
  600. {
  601. get
  602. {
  603. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPostproc);
  604. if (value == 1)
  605. return true;
  606. else return false;
  607. }
  608. set
  609. {
  610. if (value)
  611. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPostproc, 1);
  612. else
  613. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isPostproc, 0);
  614. }
  615. }
  616. /// <summary>
  617. /// Enable/disable crop and zoom
  618. /// </summary>
  619. public bool DoResize
  620. {
  621. get
  622. {
  623. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isResize);
  624. if (value == 1)
  625. return true;
  626. else return false;
  627. }
  628. set
  629. {
  630. if (value)
  631. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isResize, 1);
  632. else
  633. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isResize, 0);
  634. }
  635. }
  636. /// <summary>
  637. /// Enable/disable noise reduction
  638. /// </summary>
  639. public bool DoNoiseReduction
  640. {
  641. get
  642. {
  643. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isBlur);
  644. if (value == 1)
  645. return true;
  646. else return false;
  647. }
  648. set
  649. {
  650. if (value)
  651. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isBlur, 1);
  652. else
  653. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isBlur, 0);
  654. }
  655. }
  656. /// <summary>
  657. /// Enable/disable sharpen
  658. /// </summary>
  659. public bool DoSharpen
  660. {
  661. get
  662. {
  663. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSharpen);
  664. if (value == 1)
  665. return true;
  666. else return false;
  667. }
  668. set
  669. {
  670. if (value)
  671. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSharpen, 1);
  672. else
  673. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSharpen, 0);
  674. }
  675. }
  676. /// <summary>
  677. /// Get/Set deinterlace
  678. /// </summary>
  679. public bool DoDeinterlace
  680. {
  681. get
  682. {
  683. int value = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isDeinterlace);
  684. if (value == 1)
  685. return true;
  686. else return false;
  687. }
  688. set
  689. {
  690. if (value)
  691. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isDeinterlace, 1);
  692. else
  693. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isDeinterlace, 0);
  694. }
  695. }
  696. #endregion Enabled Properties
  697. #region Subtitles/Audio streams Properties
  698. /// <summary>
  699. /// Subtitles/audio stream structure
  700. /// </summary>
  701. public struct Stream
  702. {
  703. /// <summary>
  704. /// Name of the stream
  705. /// </summary>
  706. public string name;
  707. /// <summary>
  708. /// Language name of the stream
  709. /// </summary>
  710. public string languageName;
  711. /// <summary>
  712. /// True if the stream is active
  713. /// </summary>
  714. public bool enabled;
  715. /// <summary>
  716. /// True if this is an external file
  717. /// </summary>
  718. public bool isFile;
  719. /// <summary>
  720. /// Constructor of a stream structure
  721. /// </summary>
  722. /// <param name="name">Name of the stream</param>
  723. /// <param name="languageName">Language name of the stream</param>
  724. /// <param name="enabled">True if the stream is active</param>
  725. public Stream(string name, string languageName, bool enabled)
  726. {
  727. this.name = name;
  728. this.languageName = languageName;
  729. this.enabled = enabled;
  730. this.isFile = false;
  731. }
  732. /// <summary>
  733. /// Constructor of a stream structure with external file flag
  734. /// </summary>
  735. /// <param name="name">Name of the stream</param>
  736. /// <param name="languageName">Language name of the stream</param>
  737. /// <param name="enabled">True if the stream is active</param>
  738. /// <param name="isFile">True if this stream is an external file</param>
  739. public Stream(string name, string languageName, bool enabled, bool isFile)
  740. {
  741. this.name = name;
  742. this.languageName = languageName;
  743. this.enabled = enabled;
  744. this.isFile = isFile;
  745. }
  746. }
  747. public class Streams : SortedDictionary<int, Stream>
  748. {
  749. public enum StreamType { EmbeddedOnly, FilesOnly }
  750. public int Size(StreamType type)
  751. {
  752. int cnt = 0;
  753. foreach (KeyValuePair<int, Stream> streamPair in this)
  754. {
  755. if (type == StreamType.EmbeddedOnly && !streamPair.Value.isFile) cnt++;
  756. else if (type == StreamType.FilesOnly && streamPair.Value.isFile) cnt++;
  757. }
  758. return cnt;
  759. }
  760. }
  761. /// <summary>
  762. /// Gets the list of subtitle streams
  763. /// </summary>
  764. public Streams SubtitleStreams
  765. {
  766. get
  767. {
  768. Streams subtitleStreams = new Streams();
  769. if (ffdshowAPIMode == FFDShowAPIMode.DirectShowMode && streamSelect != null)
  770. {
  771. int streamsNb = 0;
  772. streamSelect.Count(out streamsNb);
  773. if (streamsNb == 0) return subtitleStreams;
  774. for (int i = 0; i < streamsNb; i++)
  775. {
  776. AMMediaType mediaType; AMStreamSelectInfoFlags flag; int group, langId;
  777. string streamName; object pppunk, ppobject;
  778. streamSelect.Info(i, out mediaType, out flag, out langId,
  779. out group, out streamName, out pppunk, out ppobject);
  780. if (group == 2)
  781. {
  782. if ((streamName == null || streamName.Equals("")) && subtitleStreams.Count == 0) streamName = "No subtitles";
  783. String langName = "";
  784. String languageName = new String(' ', 256);
  785. Win32.GetLocaleInfo(langId, 2, languageName, 255);
  786. if (!languageName.Equals(new String(' ', 256)))
  787. langName = languageName;
  788. Stream stream = new Stream(streamName, langName,
  789. (flag & AMStreamSelectInfoFlags.Enabled) == AMStreamSelectInfoFlags.Enabled ? true : false, false);
  790. subtitleStreams.Add(i, stream);
  791. }
  792. }
  793. return subtitleStreams;
  794. }
  795. string listString = getCustomParam(FFD_MSG.GET_SUBTITLESTREAMSLIST, 0);
  796. parseStreamsString(listString, subtitleStreams);
  797. return subtitleStreams;
  798. }
  799. }
  800. /// <summary>
  801. /// Gets the list of internal audio streams
  802. /// </summary>
  803. public Streams AudioStreams
  804. {
  805. get
  806. {
  807. Streams audioStreams = new Streams();
  808. if (ffdshowAPIMode == FFDShowAPIMode.DirectShowMode && streamSelect != null)
  809. {
  810. int streamsNb = 0;
  811. streamSelect.Count(out streamsNb);
  812. if (streamsNb == 0) return audioStreams;
  813. for (int i = 0; i < streamsNb; i++)
  814. {
  815. AMMediaType mediaType; AMStreamSelectInfoFlags flag; int group, langId;
  816. string streamName; object pppunk, ppobject;
  817. streamSelect.Info(i, out mediaType, out flag, out langId,
  818. out group, out streamName, out pppunk, out ppobject);
  819. if (group == 1)
  820. {
  821. String languageName = new String(' ', 256);
  822. Win32.GetLocaleInfo(langId, 2, languageName, 255);
  823. Stream stream = new Stream(streamName, languageName,
  824. (flag & AMStreamSelectInfoFlags.Enabled) == AMStreamSelectInfoFlags.Enabled ? true : false);
  825. audioStreams.Add(i, stream);
  826. }
  827. }
  828. return audioStreams;
  829. }
  830. string listString = getCustomParam(FFD_MSG.GET_AUDIOSTREAMSLIST, 0);
  831. parseStreamsString(listString, audioStreams);
  832. return audioStreams;
  833. }
  834. }
  835. /// <summary>
  836. /// Gets or sets the current audio stream
  837. /// </summary>
  838. public int AudioStream
  839. {
  840. get
  841. {
  842. //return SendMessage(FFD_WPRM.GET_CURRENT_AUDIO_STREAM, 0);
  843. Streams audioStreams = AudioStreams;
  844. foreach (KeyValuePair<int, Stream> audioStream in audioStreams)
  845. {
  846. if (audioStream.Value.enabled)
  847. return audioStream.Key;
  848. }
  849. return 0;
  850. }
  851. set
  852. {
  853. if (ffdshowAPIMode == FFDShowAPIMode.InterProcessMode)
  854. SendMessage(FFD_WPRM.SET_AUDIO_STREAM, value);
  855. else if (streamSelect != null)
  856. streamSelect.Enable(value, AMStreamSelectEnableFlags.Enable);
  857. }
  858. }
  859. private void parseStreamsString(string listString, Streams streamsList)
  860. {
  861. string[] list = null;
  862. if (listString != null && listString.Length > 0)
  863. {
  864. list = listString.Split(new string[] { "</enabled></stream><stream><id>" }, StringSplitOptions.None); ;
  865. if (list != null)
  866. {
  867. for (int i = 0; i < list.Length; i++)
  868. {
  869. if (i == 0)
  870. list[i] = list[i].Replace("<stream><id>", "");
  871. if (i == list.Length - 1)
  872. list[i] = list[i].Replace("</enabled></stream>", "");
  873. string[] subElement = list[i].Split(new string[] { "</id><name>" }, StringSplitOptions.None);
  874. if (subElement != null)
  875. {
  876. int streamId = int.Parse(subElement[0]);
  877. string[] subSubElement = subElement[1].Split(new string[] { "</name><language_name>" }, StringSplitOptions.None);
  878. string streamName = subSubElement[0];
  879. string[] subSubSubElement = subSubElement[1].Split(new string[] { "</language_name><enabled>" }, StringSplitOptions.None);
  880. string streamLanguageName = subSubSubElement[0];
  881. string enabled = subSubSubElement[1];
  882. bool isEnabled = false;
  883. if (enabled.Equals("true"))
  884. isEnabled = true;
  885. if (streamLanguageName.IndexOf("(") > 0)
  886. streamLanguageName = streamLanguageName.Substring(0, streamLanguageName.IndexOf("(") - 1);
  887. streamsList[streamId] = new Stream(streamName, streamLanguageName, isEnabled);
  888. }
  889. }
  890. }
  891. }
  892. }
  893. /// <summary>
  894. /// Gets or sets the current internal subtitle stream
  895. /// Gets : the id of the stream is returned. Returns -1 if no stream is selected
  896. /// Sets : the id of the stream must be passed
  897. /// </summary>
  898. public int SubtitleStream
  899. {
  900. get
  901. {
  902. Streams subtitleStreams = SubtitleStreams;
  903. foreach (KeyValuePair<int, Stream> subtitleStream in subtitleStreams)
  904. {
  905. if (subtitleStream.Value.enabled)
  906. return subtitleStream.Key;
  907. }
  908. return -1;
  909. }
  910. set
  911. {
  912. if (ffdshowAPIMode == FFDShowAPIMode.InterProcessMode)
  913. SendMessage(FFD_WPRM.SET_SUBTITLE_STREAM, value);
  914. else if (streamSelect != null)
  915. streamSelect.Enable(value, AMStreamSelectEnableFlags.Enable);
  916. }
  917. }
  918. /// <summary>
  919. /// Set/get substitles delay (in ms)
  920. /// </summary>
  921. public int SubtitlesDelay
  922. {
  923. get
  924. {
  925. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subDelay);
  926. }
  927. set
  928. {
  929. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subDelay, value);
  930. }
  931. }
  932. /// <summary>
  933. /// Set/get subtitles ratio speed (default : 1000/1000)
  934. /// </summary>
  935. public int[] SubtitlesSpeed
  936. {
  937. get
  938. {
  939. int speed1 = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subSpeed);
  940. int speed2 = getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subSpeed2);
  941. int[] values = new int[2] { speed1, speed2 };
  942. return values;
  943. }
  944. set
  945. {
  946. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subSpeed, value[0]);
  947. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subSpeed2, value[1]);
  948. }
  949. }
  950. /// <summary>
  951. /// Set/get the current external subtitles file
  952. /// </summary>
  953. public string CurrentSubtitleFile
  954. {
  955. get
  956. {
  957. if (ffdshowAPIMode == FFDShowAPIMode.InterProcessMode)
  958. return getCustomParam(FFD_MSG.GET_CURRENT_SUBTITLES, 0);//FFDSM_GET_CURRENT_SUBTITLES);
  959. else
  960. {
  961. if (getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subShowEmbedded) > 0) return null;
  962. string customSubtitleFile = getStringParam(FFDShowConstants.FFDShowDataId.IDFF_subTempFilename);
  963. if (customSubtitleFile != null && !customSubtitleFile.Equals("")) return customSubtitleFile;
  964. string fileName = null;
  965. ffdshowDec.getCurrentSubtitlesFile(out fileName);
  966. if (fileName != null && !fileName.Equals("")) return fileName;
  967. return null;
  968. }
  969. }
  970. set
  971. {
  972. setStringParam(FFDShowConstants.FFDShowDataId.IDFF_subTempFilename, value);
  973. //setStringParam(FFDShowConstants.FFDShowDataId.IDFF_subFilename, value);
  974. //setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subAutoFlnm, 0);
  975. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles, 1);
  976. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subShowEmbedded, 0);
  977. }
  978. }
  979. /// <summary>
  980. /// Returns true if the subtitle filter is enabled, false otherwise
  981. /// </summary>
  982. public bool SubtitlesEnabled
  983. {
  984. get
  985. {
  986. return (getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles) == 1) ? true : false;
  987. }
  988. set
  989. {
  990. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isSubtitles, (value == true) ? 1 : 0);
  991. }
  992. }
  993. /// <summary>
  994. /// Retrieves the list of available subtitle files
  995. /// </summary>
  996. public string[] SubtitleFiles
  997. {
  998. get
  999. {
  1000. if (ffdshowAPIMode == FFDShowAPIMode.InterProcessMode)
  1001. {
  1002. string[] list = null;
  1003. string listString = getCustomParam(FFD_MSG.GET_SUBTITLEFILESLIST, 0);//FFDSM_GET_SUBTITLEFILES);
  1004. if (listString != null)
  1005. {
  1006. list = listString.Split(';');
  1007. }
  1008. return list;
  1009. }
  1010. List<string> subtitleFiles = new List<string>();
  1011. if (ffdshowAPIMode == FFDShowAPIMode.DirectShowMode && streamSelect != null)
  1012. {
  1013. int streamsNb = 0;
  1014. streamSelect.Count(out streamsNb);
  1015. if (streamsNb == 0) return subtitleFiles.ToArray();
  1016. for (int i = 0; i < streamsNb; i++)
  1017. {
  1018. AMMediaType mediaType; AMStreamSelectInfoFlags flag; int group, langId;
  1019. string streamName; object pppunk, ppobject;
  1020. streamSelect.Info(i, out mediaType, out flag, out langId,
  1021. out group, out streamName, out pppunk, out ppobject);
  1022. if (group == 4)
  1023. {
  1024. if ((streamName == null || streamName.Equals("")) && subtitleFiles.Count == 0) streamName = "No subtitle file";
  1025. subtitleFiles.Add(streamName);
  1026. }
  1027. }
  1028. }
  1029. return subtitleFiles.ToArray();
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// Horizontal position of the subtitles (percentage value : 0 to 100)
  1034. /// </summary>
  1035. public int SubtitleHorizontalPosition
  1036. {
  1037. get
  1038. {
  1039. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subPosX);
  1040. }
  1041. set
  1042. {
  1043. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subPosX, value);
  1044. }
  1045. }
  1046. /// <summary>
  1047. /// Vertical position of the subtitles (percentage value : 0 to 100)
  1048. /// </summary>
  1049. public int SubtitleVerticalPosition
  1050. {
  1051. get
  1052. {
  1053. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_subPosY);
  1054. }
  1055. set
  1056. {
  1057. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subPosY, value);
  1058. }
  1059. }
  1060. /// <summary>
  1061. /// Set the font size of subtitles on the screen
  1062. /// </summary>
  1063. public int SubtitleFontSize
  1064. {
  1065. get
  1066. {
  1067. /*if (getIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontAutosize) == 1)
  1068. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontSizeA);
  1069. else
  1070. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontSizeP);*/
  1071. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontXscale);
  1072. }
  1073. set
  1074. {
  1075. /*if (getIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontAutosize) == 1)
  1076. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontSizeA, value);
  1077. else
  1078. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontSizeP, value);*/
  1079. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontXscale, value);
  1080. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_fontYscale, value);
  1081. }
  1082. }
  1083. #endregion Subtitles Properties
  1084. #region Other Properties
  1085. /// <summary>
  1086. /// List of chapters. Slow to process : call it once
  1087. /// </summary>
  1088. public Dictionary<int, string> ChaptersList
  1089. {
  1090. get
  1091. {
  1092. Dictionary<int, string> chaptersList = new Dictionary<int, string>();
  1093. string[] list = null;
  1094. string listString = getCustomParam(FFD_MSG.GET_CHAPTERSLIST, 0);
  1095. if (listString != null && listString.Length > 0)
  1096. {
  1097. list = listString.Split(new string[] { "</name></chapter><chapter><time>" }, StringSplitOptions.None); ;
  1098. if (list != null)
  1099. {
  1100. for (int i = 0; i < list.Length; i++)
  1101. {
  1102. if (i == 0)
  1103. list[i] = list[i].Replace("<chapter><time>", "");
  1104. if (i == list.Length - 1)
  1105. list[i] = list[i].Replace("</name></chapter>", "");
  1106. string[] chapterElement = list[i].Split(new string[] { "</time><name>" }, StringSplitOptions.None);
  1107. if (chapterElement != null)
  1108. {
  1109. int chapterTime = int.Parse(chapterElement[0]);
  1110. string chapterName = chapterElement[1];
  1111. chaptersList[chapterTime] = chapterName;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. return chaptersList;
  1117. }
  1118. }
  1119. #endregion Other Properties
  1120. #region Filters Properties
  1121. /// <summary>
  1122. /// Set/get horizontal cropping
  1123. /// </summary>
  1124. public int CropHorizontal
  1125. {
  1126. get
  1127. {
  1128. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationX);
  1129. }
  1130. set
  1131. {
  1132. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationX, value);
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// Get/set horizontal cropping
  1137. /// </summary>
  1138. public int CropVertical
  1139. {
  1140. get
  1141. {
  1142. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationY);
  1143. }
  1144. set
  1145. {
  1146. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_magnificationY, value);
  1147. }
  1148. }
  1149. /// <summary>
  1150. /// Get or set the vertical resize
  1151. /// </summary>
  1152. public int ResizeVertical
  1153. {
  1154. get
  1155. {
  1156. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeDy);
  1157. }
  1158. set
  1159. {
  1160. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeDy, value);
  1161. }
  1162. }
  1163. /// <summary>
  1164. /// Get or set the vertical resize
  1165. /// </summary>
  1166. public bool ResizeModeFitToScreen
  1167. {
  1168. get
  1169. {
  1170. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode) == 5;
  1171. }
  1172. set
  1173. {
  1174. if (value)
  1175. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode, 5);
  1176. else
  1177. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode, 0);
  1178. }
  1179. }
  1180. /// <summary>
  1181. /// Get or set the vertical resize
  1182. /// </summary>
  1183. public bool ResizeModeFreeResize
  1184. {
  1185. get
  1186. {
  1187. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode) == 0;
  1188. }
  1189. set
  1190. {
  1191. if (value)
  1192. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode, 0);
  1193. else
  1194. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeMode, 5);
  1195. }
  1196. }
  1197. /// <summary>
  1198. /// Get or set the keep aspect ratio
  1199. /// </summary>
  1200. public bool ResizeKeepAspectRatio
  1201. {
  1202. get
  1203. {
  1204. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_isAspect) == 1;
  1205. }
  1206. set
  1207. {
  1208. if (value)
  1209. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isAspect, 1);
  1210. else
  1211. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_isAspect, 0);
  1212. }
  1213. }
  1214. /// <summary>
  1215. /// Get or set the horizontal resize
  1216. /// </summary>
  1217. public int ResizeHorizontal
  1218. {
  1219. get
  1220. {
  1221. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeDx);
  1222. }
  1223. set
  1224. {
  1225. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_resizeDx, value);
  1226. }
  1227. }
  1228. /// <summary>
  1229. /// Set/get audio delay
  1230. /// </summary>
  1231. public int AudioDelay
  1232. {
  1233. get
  1234. {
  1235. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_videoDelay);
  1236. }
  1237. set
  1238. {
  1239. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_videoDelay, value);
  1240. }
  1241. }
  1242. #endregion Filters Properties
  1243. #region Picture Properties
  1244. private bool pictureEnabled = false;
  1245. /// <summary>
  1246. /// Gets or sets the picture gamma
  1247. /// </summary>
  1248. public int PictureGama
  1249. {
  1250. get
  1251. {
  1252. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_gammaCorrection);
  1253. }
  1254. set
  1255. {
  1256. if (!pictureEnabled)
  1257. {
  1258. DoPictureProperties = true;
  1259. pictureEnabled = true;
  1260. }
  1261. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_gammaCorrection, value);
  1262. }
  1263. }
  1264. /// <summary>
  1265. /// Gets or sets the picture hue
  1266. /// </summary>
  1267. public int PictureHue
  1268. {
  1269. get
  1270. {
  1271. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_hue);
  1272. }
  1273. set
  1274. {
  1275. if (!pictureEnabled)
  1276. {
  1277. DoPictureProperties = true;
  1278. pictureEnabled = true;
  1279. }
  1280. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_hue, value);
  1281. }
  1282. }
  1283. /// <summary>
  1284. /// Gets or sets the picture saturation
  1285. /// </summary>
  1286. public int PictureSaturation
  1287. {
  1288. get
  1289. {
  1290. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_saturation);
  1291. }
  1292. set
  1293. {
  1294. if (!pictureEnabled)
  1295. {
  1296. DoPictureProperties = true;
  1297. pictureEnabled = true;
  1298. }
  1299. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_saturation, value);
  1300. }
  1301. }
  1302. /// <summary>
  1303. /// Gets or sets the picture contrast
  1304. /// </summary>
  1305. public int PictureContrast
  1306. {
  1307. get
  1308. {
  1309. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_lumGain);
  1310. }
  1311. set
  1312. {
  1313. if (!pictureEnabled)
  1314. {
  1315. DoPictureProperties = true;
  1316. pictureEnabled = true;
  1317. }
  1318. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_lumGain, value);
  1319. }
  1320. }
  1321. /// <summary>
  1322. /// Gets or sets the picture brightness
  1323. /// </summary>
  1324. public int PictureBrightness
  1325. {
  1326. get
  1327. {
  1328. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_lumOffset);
  1329. }
  1330. set
  1331. {
  1332. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_lumOffset, value);
  1333. }
  1334. }
  1335. #endregion Picture Properties
  1336. #region PostProcessing Properties
  1337. /// <summary>
  1338. /// Gets or sets the postprocessing intensity (deblocking strength)
  1339. /// </summary>
  1340. public int PostProcessingIntensity
  1341. {
  1342. get
  1343. {
  1344. return getIntParam(FFDShowConstants.FFDShowDataId.IDFF_deblockStrength);
  1345. }
  1346. set
  1347. {
  1348. setIntParam(FFDShowConstants.FFDShowDataId.IDFF_deblockStrength, value);
  1349. }
  1350. }
  1351. #endregion PostProcessing Properties
  1352. #region Constructors
  1353. /// <summary>
  1354. /// Constructor using a DirectShow graph filter.
  1355. /// Recommanded if you have access to DirectShow graph.
  1356. /// However it cannot be using with the ROT (running object table)
  1357. /// </summary>
  1358. /// <param name="filter">FFDShow filter object</param>
  1359. public FFDShowAPI(object filter)
  1360. {
  1361. ffdshowDec = filter as IffdshowDec;
  1362. ffDecoder = filter as IffDecoder;
  1363. ffdshowDecVideo = filter as IffdshowDecVideo;
  1364. streamSelect = filter as IAMStreamSelect;
  1365. ffdshowBase = filter as IffdshowBase;
  1366. if (ffdshowDec == null || ffDecoder == null || ffdshowDecVideo == null || ffdshowBase == null)
  1367. ffdshowAPIMode = FFDShowAPIMode.InterProcessMode;
  1368. else
  1369. ffdshowAPIMode = FFDShowAPIMode.DirectShowMode;
  1370. }
  1371. /// <summary>
  1372. /// Basic constructor using interprocess communication
  1373. /// </summary>
  1374. public FFDShowAPI()
  1375. {
  1376. initOSD();
  1377. }
  1378. /// <summary>
  1379. /// Constructor with setting of the FFDShow window handle
  1380. /// <param name="FFDShowAPIRemote">Remote API Identifier</param>
  1381. /// </summary>
  1382. public FFDShowAPI(uint FFDShowAPIRemote)
  1383. {
  1384. this.FFDShowAPIRemote = FFDShowAPIRemote;
  1385. initOSD();
  1386. }
  1387. /// <summary>
  1388. /// Constructor where the given file name is searched for between all running FFDShow instances
  1389. /// </summary>
  1390. /// <param name="fileName">Media file name to look FFDShow instance for</param>
  1391. /// <param name="fileNameMode">Filename mode (full path,...)</param>
  1392. public FFDShowAPI(string fileName, FileNameMode fileNameMode)
  1393. {
  1394. this.fileName = fileName;
  1395. this.fileNameMode = fileNameMode;
  1396. initOSD();
  1397. }
  1398. /// <summary>
  1399. /// Constructor where the given file name is searched for between all running FFDShow instances
  1400. /// </summary>
  1401. /// <param name="fileName">Media file name to look FFDShow instance for</param>
  1402. /// <param name="fileNameMode">Filename mode (full path,...)</param>
  1403. /// <param name="FFDShowAPIRemote">Remote API Identifier</param>
  1404. public FFDShowAPI(string fileName, FileNameMode fileNameMode, uint FFDShowAPIRemote)
  1405. {
  1406. this.FFDShowAPIRemote = FFDShowAPIRemote;
  1407. this.fileName = fileName;
  1408. this.fileNameMode = fileNameMode;
  1409. initOSD();
  1410. }
  1411. /// <summary>
  1412. /// Constructor where the given FFDShow instance handle is searched for between all running FFDShow instances
  1413. /// </summary>
  1414. /// <param name="FFDShowInstanceHandle">Handle of FFDShow window to look for</param>
  1415. public FFDShowAPI(int FFDShowInstanceHandle)
  1416. {
  1417. this.initFFDShowInstanceHandle = FFDShowInstanceHandle;
  1418. initOSD();
  1419. }
  1420. /// <summary>
  1421. /// Constructor where the given FFDShow instance handle is searched for between all running FFDShow instances
  1422. /// </summary>
  1423. /// <param name="FFDShowInstanceHandle">Handle of FFDShow window to look for</param>
  1424. /// <param name="FFDShowAPIRemote">Remote API Identifier</param>
  1425. public FFDShowAPI(int FFDShowInstanceHandle, uint FFDShowAPIRemote)
  1426. {
  1427. this.initFFDShowInstanceHandle = FFDShowInstanceHandle;
  1428. this.FFDShowAPIRemote = FFDShowAPIRemote;
  1429. initOSD();
  1430. }
  1431. /// <summary>
  1432. /// FFDShowAPI desctructor
  1433. /// </summary>
  1434. ~FFDShowAPI()
  1435. {
  1436. Dispose();
  1437. }
  1438. /// <summary>
  1439. /// Cleaning
  1440. /// </summary>
  1441. public void Dispose()
  1442. {
  1443. System.GC.SuppressFinalize(this);
  1444. }
  1445. private void initOSD()
  1446. {
  1447. if (osdX != 0 || osdY != 0)
  1448. updateOSD = true;
  1449. }
  1450. #endregion Constructors
  1451. #region Loading
  1452. /// <summary>
  1453. /// Initialization method. Must be called after constructor.
  1454. /// It will look for a running FFDShow instance basing on constructor parameters.
  1455. /// </summary>
  1456. /// <returns>True if FFDShow instance found</returns>
  1457. private bool init()
  1458. {
  1459. if (ffdshowAPIMode == FFDShowAPIMode.DirectShowMode) return true;
  1460. if (fileName == null && initFFDShowInstanceHandle == 0)
  1461. {
  1462. ffDShowInstanceHandle = Win32.FindWindow(strAppName, null);
  1463. if (ffDShowInstanceHandle == 0)
  1464. IsFFDShowActive = false;
  1465. else
  1466. IsFFDShowActive = true;
  1467. return IsFFDShowActive;
  1468. }
  1469. else
  1470. {
  1471. if (initFFDShowInstanceHandle != 0)
  1472. {
  1473. ffDShowInstanceHandle = initFFDShowInstanceHandle;
  1474. if (Win32.IsWindow(ffDShowInstanceHandle) == 1)
  1475. IsFFDShowActive = true;
  1476. else
  1477. IsFFDShowActive = false;
  1478. return IsFFDShowActive;
  1479. }
  1480. else if (ffDShowInstanceHandle != 0)
  1481. {
  1482. if (Win32.IsWindow(ffDShowInstanceHandle) == 1)
  1483. IsFFDShowActive = true;
  1484. else
  1485. IsFFDShowActive = false;
  1486. return IsFFDShowActive;
  1487. }
  1488. else
  1489. {
  1490. List<FFDShowInstance> list = getFFDShowInstances();
  1491. for (int i = 0; i < list.Count; i++)
  1492. {
  1493. int localFFDShowInstanceHandle = list[i].handle;
  1494. string FFDShowFileName = list[i].fileName;
  1495. if (FFDShowFileName == null)
  1496. continue;
  1497. try
  1498. {
  1499. FileInfo fileInfo;
  1500. switch (fileNameMode)
  1501. {
  1502. case FileNameMode.FullPath:
  1503. if (fileName.Equals(FFDShowFileName))
  1504. {
  1505. ffDShowInstanceHandle = localFFDShowInstanceHandle;
  1506. return (IsFFDShowActive = true);
  1507. }
  1508. break;
  1509. case FileNameMode.FileName:
  1510. fileInfo = new FileInfo(FFDShowFileName);
  1511. if (fileName.Equals(fileInfo.Name))
  1512. {
  1513. ffDShowInstanceHandle = localFFDShowInstanceHandle;
  1514. return (IsFFDShowActive = true);
  1515. }
  1516. break;
  1517. case FileNameMode.FileNameWithoutExtension:
  1518. fileInfo = new FileInfo(FFDShowFileName);
  1519. string formattedFileName = fileInfo.Name;
  1520. if (formattedFileName.LastIndexOf('.') != -1)
  1521. formattedFileName = formattedFileName.Substring(0, formattedFileName.LastIndexOf('.'));
  1522. if (fileName.Equals(formattedFileName))
  1523. {
  1524. ffDShowInstanceHandle = localFFDShowInstanceHandle;
  1525. return (IsFFDShowActive = true);
  1526. }
  1527. break;
  1528. }
  1529. }
  1530. catch (ArgumentException) { }
  1531. }
  1532. return (IsFFDShowActive = false);
  1533. }
  1534. }
  1535. }
  1536. /// <summary>
  1537. /// Returns the list of FFDShow instances running
  1538. /// </summary>
  1539. /// <returns>T…

Large files files are truncated, but you can click here to view the full file