PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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