decklink-device-mode.cpp 1.7 KB

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