decklink-device-mode.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. BMDDisplayModeFlags DeckLinkDeviceMode::GetDisplayModeFlags(void) const
  35. {
  36. if (mode != nullptr)
  37. return mode->GetFlags();
  38. return (BMDDisplayModeFlags)0;
  39. }
  40. long long DeckLinkDeviceMode::GetId(void) const
  41. {
  42. return id;
  43. }
  44. const std::string &DeckLinkDeviceMode::GetName(void) const
  45. {
  46. return name;
  47. }
  48. bool DeckLinkDeviceMode::IsEqualFrameRate(int64_t num, int64_t den)
  49. {
  50. bool equal = false;
  51. if (mode) {
  52. BMDTimeValue frameDuration;
  53. BMDTimeScale timeScale;
  54. if (SUCCEEDED(mode->GetFrameRate(&frameDuration, &timeScale)))
  55. equal = timeScale * den == frameDuration * num;
  56. }
  57. return equal;
  58. }
  59. void DeckLinkDeviceMode::SetMode(IDeckLinkDisplayMode *mode_)
  60. {
  61. mode = mode_;
  62. }