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 * gstmplexibitstream.hh: gstreamer/mplex input bitstream 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 "gstmplexibitstream.hh"
31
32 /*
33 * Class init/exit functions.
34 */
35
GstMplexIBitStream(GstMplexPad * _data,guint buf_size)36 GstMplexIBitStream::GstMplexIBitStream (GstMplexPad * _data, guint buf_size):
37 IBitStream ()
38 {
39 mpad = _data;
40 mplex = GST_MPLEX (GST_PAD_PARENT (mpad->pad));
41 eos = FALSE;
42
43 SetBufSize (buf_size);
44 eobs = false;
45 byteidx = 0;
46 }
47
48 /*
49 * Read data.
50 */
51
52 size_t
ReadStreamBytes(uint8_t * buf,size_t size=BUFFER_SIZE)53 GstMplexIBitStream::ReadStreamBytes (uint8_t * buf, size_t size =
54 BUFFER_SIZE)
55 {
56 gpointer data;
57
58 GST_MPLEX_MUTEX_LOCK (mplex);
59
60 GST_DEBUG_OBJECT (mplex, "needing %d bytes", (guint) size);
61
62 while (gst_adapter_available (mpad->adapter) < size
63 && !mplex->eos && !mpad->eos) {
64 mpad->needed = size;
65 GST_MPLEX_SIGNAL (mplex, mpad);
66 GST_MPLEX_WAIT (mplex, mpad);
67 }
68
69 mpad->needed = 0;
70 size = MIN (size, gst_adapter_available (mpad->adapter));
71 if (size) {
72 data = gst_adapter_take (mpad->adapter, size);
73 memcpy (buf, data, size);
74 g_free (data);
75 }
76
77 GST_MPLEX_MUTEX_UNLOCK (mplex);
78
79 return size;
80 }
81
82 /*
83 * Are we at EOS?
84 */
85
EndOfStream(void)86 bool GstMplexIBitStream::EndOfStream (void)
87 {
88 return eos;
89 }
90
ReadBuffer()91 bool GstMplexIBitStream::ReadBuffer ()
92 {
93 return ReadIntoBuffer (BUFFER_SIZE);
94 }
95