• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer mplex (mjpegtools) wrapper
2  * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2008 Mark Nauwelaerts <mnauw@users.sourceforge.net>
4  *
5  * gstmplexoutputstream.hh: gstreamer/mplex output stream wrapper
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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <string.h>
28 
29 #include "gstmplex.hh"
30 #include "gstmplexoutputstream.hh"
31 
32 /*
33  * Class init functions.
34  */
35 
GstMplexOutputStream(GstMplex * _element,GstPad * _pad)36 GstMplexOutputStream::GstMplexOutputStream (GstMplex * _element, GstPad * _pad):
37 OutputStream ()
38 {
39   mplex = _element;
40   pad = _pad;
41   size = 0;
42 }
43 
44 /*
45  * Open/close. Basically 'no-op's (close() sets EOS).
46  *
47  * Open (): -1 means failure, 0 means success.
48  */
49 
50 int
Open(void)51 GstMplexOutputStream::Open (void)
52 {
53   return 0;
54 }
55 
56 void
Close(void)57 GstMplexOutputStream::Close (void)
58 {
59   GST_MPLEX_MUTEX_LOCK (mplex);
60   GST_DEBUG_OBJECT (mplex, "closing stream and sending eos");
61   gst_pad_push_event (pad, gst_event_new_eos ());
62   /* notify chain there is no more need to supply buffers */
63   mplex->eos = TRUE;
64   GST_MPLEX_SIGNAL_ALL (mplex);
65   GST_MPLEX_MUTEX_UNLOCK (mplex);
66 }
67 
68 /*
69  * Get size of current segment.
70  */
71 
72 #if GST_MJPEGTOOLS_API >= 10900
73 uint64_t
SegmentSize(void)74 GstMplexOutputStream::SegmentSize (void)
75 #else
76 off_t
77 GstMplexOutputStream::SegmentSize (void)
78 #endif
79 {
80   return size;
81 }
82 
83 /*
84  * Next segment; not really supported.
85  */
86 
87 void
NextSegment(void)88 GstMplexOutputStream::NextSegment (void)
89 {
90   size = 0;
91 
92   GST_WARNING_OBJECT (mplex, "multiple file output is not supported");
93   /* FIXME: no such filesink behaviour to be expected */
94 }
95 
96 /*
97  * Write data.
98  */
99 
100 void
Write(guint8 * data,guint len)101 GstMplexOutputStream::Write (guint8 * data, guint len)
102 {
103   GstBuffer *buf;
104 
105   buf = gst_buffer_new_and_alloc (len);
106   gst_buffer_fill (buf, 0, data, len);
107 
108   size += len;
109   GST_MPLEX_MUTEX_LOCK (mplex);
110   mplex->srcresult = gst_pad_push (pad, buf);
111   GST_MPLEX_MUTEX_UNLOCK (mplex);
112 }
113