omxvideoenc: drain encoder on ALLOCATION and DRAIN queries
[platform/upstream/gstreamer.git] / omx / gstomxvideodec.h
1 /*
2  * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
3  *   Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation
8  * version 2.1 of the License.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
18  *
19  */
20
21 #ifndef __GST_OMX_VIDEO_DEC_H__
22 #define __GST_OMX_VIDEO_DEC_H__
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29 #include <gst/video/video.h>
30 #include <gst/video/gstvideodecoder.h>
31
32 #include "gstomx.h"
33
34 G_BEGIN_DECLS
35
36 #define GST_TYPE_OMX_VIDEO_DEC \
37   (gst_omx_video_dec_get_type())
38 #define GST_OMX_VIDEO_DEC(obj) \
39   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OMX_VIDEO_DEC,GstOMXVideoDec))
40 #define GST_OMX_VIDEO_DEC_CLASS(klass) \
41   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OMX_VIDEO_DEC,GstOMXVideoDecClass))
42 #define GST_OMX_VIDEO_DEC_GET_CLASS(obj) \
43   (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_OMX_VIDEO_DEC,GstOMXVideoDecClass))
44 #define GST_IS_OMX_VIDEO_DEC(obj) \
45   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OMX_VIDEO_DEC))
46 #define GST_IS_OMX_VIDEO_DEC_CLASS(obj) \
47   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OMX_VIDEO_DEC))
48
49 typedef struct _GstOMXVideoDec GstOMXVideoDec;
50 typedef struct _GstOMXVideoDecClass GstOMXVideoDecClass;
51
52 struct _GstOMXVideoDec
53 {
54   GstVideoDecoder parent;
55
56   /* < protected > */
57   GstOMXComponent *dec;
58   GstOMXPort *dec_in_port, *dec_out_port;
59   
60   GstBufferPool *in_port_pool, *out_port_pool;
61
62   /* < private > */
63   GstVideoCodecState *input_state;
64   GstBuffer *codec_data;
65   /* TRUE if the component is configured and saw
66    * the first buffer */
67   gboolean started;
68    /* TRUE if the ports where disabled after being activated the first time. */
69   gboolean disabled;
70
71   GstClockTime last_upstream_ts;
72
73   /* Draining state */
74   GMutex drain_lock;
75   GCond drain_cond;
76   /* TRUE if EOS buffers shouldn't be forwarded */
77   gboolean draining; /* protected by drain_lock */
78
79   GstFlowReturn downstream_flow_ret;
80   /* Initially FALSE. Switched to TRUE when all requirements
81    * are met to try setting up the decoder with OMX_UseBuffer.
82    * Switched to FALSE if this trial fails so that the decoder
83    * can fallback to OMX_AllocateBuffer. */
84   gboolean use_buffers;
85
86 #if defined (USE_OMX_TARGET_RPI)
87   GstOMXComponent *egl_render;
88   GstOMXPort *egl_in_port, *egl_out_port;
89 #endif
90
91 #if defined (HAVE_GST_GL)
92   gboolean eglimage;
93 #endif
94
95   /* TRUE if decoder is producing dmabuf */
96   gboolean dmabuf;
97   GstOMXBufferAllocation input_allocation;
98
99   /* properties */
100 #ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
101   guint32 internal_entropy_buffers;
102 #endif
103 };
104
105 struct _GstOMXVideoDecClass
106 {
107   GstVideoDecoderClass parent_class;
108
109   GstOMXClassData cdata;
110
111   gboolean (*is_format_change) (GstOMXVideoDec * self, GstOMXPort * port, GstVideoCodecState * state);
112   gboolean (*set_format)       (GstOMXVideoDec * self, GstOMXPort * port, GstVideoCodecState * state);
113 };
114
115 GType gst_omx_video_dec_get_type (void);
116
117 G_END_DECLS
118
119 #endif /* __GST_OMX_VIDEO_DEC_H__ */