decklink-device-mode.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "decklink-device-mode.hpp"
  2. DeckLinkDeviceMode::DeckLinkDeviceMode(IDeckLinkDisplayMode *mode, long long id)
  3. : id(id), mode(mode)
  4. {
  5. if (mode == nullptr)
  6. return;
  7. mode->AddRef();
  8. decklink_string_t decklinkStringName;
  9. if (mode->GetName(&decklinkStringName) == S_OK)
  10. DeckLinkStringToStdString(decklinkStringName, name);
  11. }
  12. DeckLinkDeviceMode::DeckLinkDeviceMode(const std::string &name, long long id)
  13. : id(id), mode(nullptr), name(name)
  14. {
  15. }
  16. DeckLinkDeviceMode::~DeckLinkDeviceMode(void) {}
  17. BMDDisplayMode DeckLinkDeviceMode::GetDisplayMode(void) const
  18. {
  19. if (mode != nullptr)
  20. return mode->GetDisplayMode();
  21. return bmdModeUnknown;
  22. }
  23. int DeckLinkDeviceMode::GetWidth()
  24. {
  25. if (mode != nullptr)
  26. return mode->GetWidth();
  27. return 0;
  28. }
  29. int DeckLinkDeviceMode::GetHeight()
  30. {
  31. if (mode != nullptr)
  32. return mode->GetHeight();
  33. return 0;
  34. }
  35. BMDDisplayModeFlags DeckLinkDeviceMode::GetDisplayModeFlags(void) const
  36. {
  37. if (mode != nullptr)
  38. return mode->GetFlags();
  39. return (BMDDisplayModeFlags)0;
  40. }
  41. long long DeckLinkDeviceMode::GetId(void) const
  42. {
  43. return id;
  44. }
  45. const std::string &DeckLinkDeviceMode::GetName(void) const
  46. {
  47. return name;
  48. }
  49. bool DeckLinkDeviceMode::IsEqualFrameRate(int64_t num, int64_t den)
  50. {
  51. bool equal = false;
  52. if (mode) {
  53. BMDTimeValue frameDuration;
  54. BMDTimeScale timeScale;
  55. if (SUCCEEDED(mode->GetFrameRate(&frameDuration, &timeScale)))
  56. equal = timeScale * den == frameDuration * num;
  57. }
  58. return equal;
  59. }
  60. void DeckLinkDeviceMode::SetMode(IDeckLinkDisplayMode *mode_)
  61. {
  62. mode = mode_;
  63. }