• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2  * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2006 Mark Nauwelaerts <manauw@skynet.be>
4  *
5  * gstmpeg2enc.hh: object definition
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef __GST_MPEG2ENC_H__
24 #define __GST_MPEG2ENC_H__
25 
26 #include <gst/gst.h>
27 #include <gst/video/video.h>
28 
29 #include "gstmpeg2encoptions.hh"
30 #include "gstmpeg2encoder.hh"
31 
32 G_BEGIN_DECLS
33 
34 #define GST_TYPE_MPEG2ENC \
35   (gst_mpeg2enc_get_type ())
36 #define GST_MPEG2ENC(obj) \
37   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MPEG2ENC, GstMpeg2enc))
38 #define GST_MPEG2ENC_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MPEG2ENC, GstMpeg2enc))
40 #define GST_IS_MPEG2ENC(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MPEG2ENC))
42 #define GST_IS_MPEG2ENC_CLASS(obj) \
43   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MPEG2ENC))
44 
45 GST_DEBUG_CATEGORY_EXTERN (mpeg2enc_debug);
46 #define GST_CAT_DEFAULT mpeg2enc_debug
47 
48 #define GST_MPEG2ENC_MUTEX_LOCK(m) G_STMT_START {                       \
49   GST_LOG_OBJECT (m, "locking tlock from thread %p", g_thread_self ()); \
50   g_mutex_lock (&m->tlock);                                              \
51   GST_LOG_OBJECT (m, "locked tlock from thread %p", g_thread_self ());  \
52 } G_STMT_END
53 
54 #define GST_MPEG2ENC_MUTEX_UNLOCK(m) G_STMT_START {                       \
55   GST_LOG_OBJECT (m, "unlocking tlock from thread %p", g_thread_self ()); \
56   g_mutex_unlock (&m->tlock);                                              \
57 } G_STMT_END
58 
59 #define GST_MPEG2ENC_WAIT(m) G_STMT_START {                             \
60   GST_LOG_OBJECT (m, "thread %p waiting", g_thread_self ());            \
61   g_cond_wait (&m->cond, &m->tlock);                                      \
62 } G_STMT_END
63 
64 #define GST_MPEG2ENC_SIGNAL(m) G_STMT_START {                           \
65   GST_LOG_OBJECT (m, "signalling from thread %p", g_thread_self ());    \
66   g_cond_signal (&m->cond);                                              \
67 } G_STMT_END
68 
69 typedef struct _GstMpeg2enc {
70   GstVideoEncoder base_video_encoder;
71 
72   /* options wrapper */
73   GstMpeg2EncOptions *options;
74 
75   /* general encoding object (contains rest) */
76   GstMpeg2Encoder *encoder;
77 
78   /* lock for syncing with encoding task */
79   GMutex tlock;
80   /* with TLOCK */
81   /* signals counterpart thread that something changed;
82    * frame ready for task or buffer has been processed */
83   GCond cond;
84   /* seen eos */
85   gboolean eos;
86   /* flowreturn obtained by encoding task */
87   GstFlowReturn srcresult;
88 
89   gboolean started;
90 
91   GstVideoCodecState *input_state;
92   GstVideoCodecFrame *pending_frame;
93 } GstMpeg2enc;
94 
95 typedef struct _GstMpeg2encClass {
96   GstVideoEncoderClass base_video_encoder_class;
97 } GstMpeg2encClass;
98 
99 GType    gst_mpeg2enc_get_type    (void);
100 
101 GST_ELEMENT_REGISTER_DECLARE (mpeg2enc);
102 
103 G_END_DECLS
104 
105 #endif /* __GST_MPEG2ENC_H__ */
106