forked from xbmc/xbmc
/
MMALCodec.h
153 lines (133 loc) · 4.56 KB
/
MMALCodec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#pragma once
/*
* Copyright (C) 2010-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#if defined(HAS_MMAL)
#include <interface/mmal/mmal.h>
#include <interface/mmal/util/mmal_util.h>
#include <interface/mmal/util/mmal_default_components.h>
#include <interface/mmal/util/mmal_util_params.h>
#include <interface/mmal/util/mmal_connection.h>
#include <interface/mmal/mmal_parameters.h>
#include "cores/VideoPlayer/DVDStreamInfo.h"
#include "DVDVideoCodec.h"
#include "threads/Event.h"
#include "xbmc/settings/VideoSettings.h"
#include <queue>
#include <semaphore.h>
#include <memory>
#include <string>
#include "guilib/Geometry.h"
#include "rendering/RenderSystem.h"
#include "cores/VideoPlayer/VideoRenderers/BaseRenderer.h"
#include "cores/VideoPlayer/DVDResource.h"
// a mmal video frame
class CMMALBuffer : public IDVDResourceCounted<CMMALBuffer>
{
public:
virtual ~CMMALBuffer() {}
MMAL_BUFFER_HEADER_T *mmal_buffer;
unsigned int m_width;
unsigned int m_height;
unsigned int m_aligned_width;
unsigned int m_aligned_height;
float m_aspect_ratio;
};
class CMMALVideo;
class CMMALRenderer;
class CMMALPool;
// a mmal video frame
class CMMALVideoBuffer : public CMMALBuffer
{
public:
CMMALVideoBuffer(CMMALVideo *omv);
virtual ~CMMALVideoBuffer();
CMMALVideo *m_omv;
};
class CMMALVideo : public CDVDVideoCodec
{
public:
CMMALVideo(CProcessInfo &processInfo);
virtual ~CMMALVideo();
// Required overrides
virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options);
virtual int Decode(uint8_t *pData, int iSize, double dts, double pts);
virtual void Reset(void);
virtual bool GetPicture(DVDVideoPicture *pDvdVideoPicture);
virtual bool ClearPicture(DVDVideoPicture* pDvdVideoPicture);
virtual unsigned GetAllowedReferences() { return 4; }
virtual void SetDropState(bool bDrop);
virtual const char* GetName(void) { return m_pFormatName ? m_pFormatName:"mmal-xxx"; }
virtual bool GetCodecStats(double &pts, int &droppedPics);
virtual void SetCodecControl(int flags);
virtual void SetSpeed(int iSpeed);
// MMAL decoder callback routines.
void Recycle(MMAL_BUFFER_HEADER_T *buffer);
// MMAL decoder callback routines.
void dec_output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
void dec_control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
void dec_input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
protected:
void QueryCodec(void);
void Prime();
void Dispose(void);
// Video format
unsigned int m_decoded_width;
unsigned int m_decoded_height;
unsigned int m_decoded_aligned_width;
unsigned int m_decoded_aligned_height;
unsigned int m_egl_buffer_count;
bool m_finished;
float m_aspect_ratio;
const char *m_pFormatName;
// mmal output buffers (video frames)
CCriticalSection m_output_mutex;
XbmcThreads::ConditionVariable m_output_cond;
std::queue<CMMALVideoBuffer*> m_output_ready;
// initialize mmal and get decoder component
bool Initialize( const std::string &decoder_name);
void PortSettingsChanged(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
bool SendCodecConfigData();
CDVDStreamInfo m_hints;
float m_fps;
unsigned m_num_decoded;
// Components
MMAL_INTERLACETYPE_T m_interlace_mode;
double m_demuxerPts;
double m_decoderPts;
int m_speed;
int m_codecControlFlags;
bool m_dropState;
bool m_preroll;
bool m_got_eos;
uint32_t m_packet_num;
uint32_t m_packet_num_eos;
CCriticalSection m_sharedSection;
MMAL_COMPONENT_T *m_dec;
MMAL_PORT_T *m_dec_input;
MMAL_PORT_T *m_dec_output;
MMAL_POOL_T *m_dec_input_pool;
CMMALRenderer *m_renderer;
std::shared_ptr<CMMALPool> m_pool;
MMAL_ES_FORMAT_T *m_es_format;
MMAL_FOURCC_T m_codingType;
bool change_dec_output_format();
};
// defined(HAS_MMAL)
#endif