Merge pull request #2703 from ace20022/cores_revised
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDCodecs / Video / OpenMax.h
1 #pragma once
2 /*
3  *      Copyright (C) 2010-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
22 #if defined(HAVE_LIBOPENMAX)
23
24 #include "cores/dvdplayer/DVDStreamInfo.h"
25 #include "DVDVideoCodec.h"
26 #include "threads/Event.h"
27
28 #include <queue>
29 #include <semaphore.h>
30 #include <OMX_Core.h>
31
32 ////////////////////////////////////////////////////////////////////////////////////////////
33 // debug spew defines
34 #if 0
35 #define OMX_DEBUG_VERBOSE
36 #define OMX_DEBUG_EVENTHANDLER
37 #define OMX_DEBUG_FILLBUFFERDONE
38 #define OMX_DEBUG_EMPTYBUFFERDONE
39 #endif
40
41 typedef struct omx_codec_capability {
42     // level is OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263PROFILETYPE, 
43     // or OMX_VIDEO_MPEG4PROFILETYPE depending on context.
44     OMX_U32 level;
45     // level is OMX_VIDEO_AVCLEVELTYPE, OMX_VIDEO_H263LEVELTYPE, 
46     // or OMX_VIDEO_MPEG4PROFILETYPE depending on context.
47     OMX_U32 profile;
48 } omx_codec_capability;
49
50 typedef struct omx_demux_packet {
51   OMX_U8 *buff;
52   int size;
53   double dts;
54   double pts;
55 } omx_demux_packet;
56
57 class DllLibOpenMax;
58 class COpenMax
59 {
60 public:
61   COpenMax();
62   virtual ~COpenMax();
63
64 protected:
65   enum OMX_CLIENT_STATE {
66       DEAD,
67       LOADED,
68       LOADED_TO_IDLE,
69       IDLE_TO_EXECUTING,
70       EXECUTING,
71       EXECUTING_TO_IDLE,
72       IDLE_TO_LOADED,
73       RECONFIGURING,
74       ERROR
75   };
76
77   // initialize OpenMax and get decoder component
78   bool Initialize( const CStdString &decoder_name);
79   void Deinitialize();
80
81   // OpenMax Decoder delegate callback routines.
82   static OMX_ERRORTYPE DecoderEventHandlerCallback(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
83     OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData);
84   static OMX_ERRORTYPE DecoderEmptyBufferDoneCallback(
85     OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);
86   static OMX_ERRORTYPE DecoderFillBufferDoneCallback(
87     OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBufferHeader);
88
89   // OpenMax decoder callback routines.
90   virtual OMX_ERRORTYPE DecoderEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
91     OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData);
92   virtual OMX_ERRORTYPE DecoderEmptyBufferDone(
93     OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);
94   virtual OMX_ERRORTYPE DecoderFillBufferDone(
95     OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBufferHeader);
96
97   // OpenMax helper routines
98   OMX_ERRORTYPE WaitForState(OMX_STATETYPE state);
99   OMX_ERRORTYPE SetStateForComponent(OMX_STATETYPE state);
100
101   DllLibOpenMax     *m_dll;
102   bool              m_is_open;
103   OMX_HANDLETYPE    m_omx_decoder;   // openmax decoder component reference
104
105   // OpenMax state tracking
106   OMX_CLIENT_STATE  m_omx_client_state;
107   volatile int      m_omx_decoder_state;
108   sem_t             *m_omx_decoder_state_change;
109   std::vector<omx_codec_capability> m_omx_decoder_capabilities;
110
111 private:
112   COpenMax(const COpenMax& other);
113   COpenMax& operator=(const COpenMax&);
114 };
115
116 #endif