/xbmc/cores/dvdplayer/DVDMessageQueue.h

http://github.com/xbmc/xbmc · C Header · 146 lines · 100 code · 21 blank · 25 comment · 5 complexity · 777f5826f4be3473718f658154a68235 MD5 · raw file

  1. #pragma once
  2. /*
  3. * Copyright (C) 2005-2013 Team XBMC
  4. * http://xbmc.org
  5. *
  6. * This Program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This Program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with XBMC; see the file COPYING. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include "DVDMessage.h"
  22. #include <string>
  23. #include <list>
  24. #include "threads/CriticalSection.h"
  25. #include "threads/Event.h"
  26. struct DVDMessageListItem
  27. {
  28. DVDMessageListItem(CDVDMsg* msg, int prio)
  29. {
  30. message = msg->Acquire();
  31. priority = prio;
  32. }
  33. DVDMessageListItem()
  34. {
  35. message = NULL;
  36. priority = 0;
  37. }
  38. DVDMessageListItem(const DVDMessageListItem& item)
  39. {
  40. if(item.message)
  41. message = item.message->Acquire();
  42. else
  43. message = NULL;
  44. priority = item.priority;
  45. }
  46. ~DVDMessageListItem()
  47. {
  48. if(message)
  49. message->Release();
  50. }
  51. DVDMessageListItem& operator=(const DVDMessageListItem& item)
  52. {
  53. if(message)
  54. message->Release();
  55. if(item.message)
  56. message = item.message->Acquire();
  57. else
  58. message = NULL;
  59. priority = item.priority;
  60. return *this;
  61. }
  62. CDVDMsg* message;
  63. int priority;
  64. };
  65. enum MsgQueueReturnCode
  66. {
  67. MSGQ_OK = 1,
  68. MSGQ_TIMEOUT = 0,
  69. MSGQ_ABORT = -1, // negative for legacy, not an error actually
  70. MSGQ_NOT_INITIALIZED = -2,
  71. MSGQ_INVALID_MSG = -3,
  72. MSGQ_OUT_OF_MEMORY = -4
  73. };
  74. #define MSGQ_IS_ERROR(c) (c < 0)
  75. class CDVDMessageQueue
  76. {
  77. public:
  78. CDVDMessageQueue(const std::string &owner);
  79. virtual ~CDVDMessageQueue();
  80. void Init();
  81. void Flush(CDVDMsg::Message message = CDVDMsg::DEMUXER_PACKET);
  82. void Abort();
  83. void End();
  84. MsgQueueReturnCode Put(CDVDMsg* pMsg, int priority = 0);
  85. /**
  86. * msg, message type from DVDMessage.h
  87. * timeout, timeout in msec
  88. * priority, minimum priority to get, outputs returned packets priority
  89. */
  90. MsgQueueReturnCode Get(CDVDMsg** pMsg, unsigned int iTimeoutInMilliSeconds, int &priority);
  91. MsgQueueReturnCode Get(CDVDMsg** pMsg, unsigned int iTimeoutInMilliSeconds)
  92. {
  93. int priority = 0;
  94. return Get(pMsg, iTimeoutInMilliSeconds, priority);
  95. }
  96. int GetDataSize() const { return m_iDataSize; }
  97. int GetTimeSize() const;
  98. unsigned GetPacketCount(CDVDMsg::Message type);
  99. bool ReceivedAbortRequest() { return m_bAbortRequest; }
  100. void WaitUntilEmpty();
  101. // non messagequeue related functions
  102. bool IsFull() const { return GetLevel() == 100; }
  103. int GetLevel() const;
  104. void SetMaxDataSize(int iMaxDataSize) { m_iMaxDataSize = iMaxDataSize; }
  105. void SetMaxTimeSize(double sec) { m_TimeSize = 1.0 / std::max(1.0, sec); }
  106. int GetMaxDataSize() const { return m_iMaxDataSize; }
  107. double GetMaxTimeSize() const { return m_TimeSize; }
  108. bool IsInited() const { return m_bInitialized; }
  109. bool IsDataBased() const;
  110. private:
  111. CEvent m_hEvent;
  112. mutable CCriticalSection m_section;
  113. bool m_bAbortRequest;
  114. bool m_bInitialized;
  115. bool m_bCaching;
  116. int m_iDataSize;
  117. double m_TimeFront;
  118. double m_TimeBack;
  119. double m_TimeSize;
  120. int m_iMaxDataSize;
  121. bool m_bEmptied;
  122. std::string m_owner;
  123. typedef std::list<DVDMessageListItem> SList;
  124. SList m_list;
  125. };