1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2016 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
35 struct vlc_demux_chained_t
53 static void *vlc_demux_chained_Thread(void *data
)
55 vlc_demux_chained_t
*dc
= data
;
56 demux_t
*demux
= demux_New(VLC_OBJECT(dc
->fifo
), dc
->name
, dc
->fifo
,
60 vlc_stream_Delete(dc
->fifo
);
64 /* Stream FIFO cannot apply DVB filters.
65 * Get all programs and let the E/S output sort them out. */
66 demux_Control(demux
, DEMUX_SET_GROUP_ALL
);
69 vlc_tick_t next_update
= 0;
72 if (demux_TestAndClearFlags(demux
, UINT_MAX
) || vlc_tick_now() >= next_update
)
78 if (demux_Control(demux
, DEMUX_GET_POSITION
, &newpos
))
80 if (demux_Control(demux
, DEMUX_GET_LENGTH
, &newlen
))
82 if (demux_Control(demux
, DEMUX_GET_TIME
, &newtime
))
85 vlc_mutex_lock(&dc
->lock
);
86 dc
->stats
.position
= newpos
;
87 dc
->stats
.length
= newlen
;
88 dc
->stats
.time
= newtime
;
89 vlc_mutex_unlock(&dc
->lock
);
91 next_update
= vlc_tick_now() + VLC_TICK_FROM_MS(250);
93 while (demux_Demux(demux
) > 0);
99 vlc_demux_chained_t
*vlc_demux_chained_New(vlc_object_t
*parent
,
100 const char *name
, es_out_t
*out
)
102 vlc_demux_chained_t
*dc
= malloc(sizeof (*dc
) + strlen(name
) + 1);
103 if (unlikely(dc
== NULL
))
106 dc
->fifo
= vlc_stream_fifo_New(parent
);
107 if (dc
->fifo
== NULL
)
113 dc
->stats
.position
= 0.;
114 dc
->stats
.length
= 0;
117 strcpy(dc
->name
, name
);
119 vlc_mutex_init(&dc
->lock
);
121 if (vlc_clone(&dc
->thread
, vlc_demux_chained_Thread
, dc
,
122 VLC_THREAD_PRIORITY_INPUT
))
124 vlc_stream_Delete(dc
->fifo
);
125 vlc_stream_fifo_Close(dc
->fifo
);
126 vlc_mutex_destroy(&dc
->lock
);
133 void vlc_demux_chained_Send(vlc_demux_chained_t
*dc
, block_t
*block
)
135 vlc_stream_fifo_Queue(dc
->fifo
, block
);
138 int vlc_demux_chained_ControlVa(vlc_demux_chained_t
*dc
, int query
, va_list ap
)
142 case DEMUX_GET_POSITION
:
143 vlc_mutex_lock(&dc
->lock
);
144 *va_arg(ap
, double *) = dc
->stats
.position
;
145 vlc_mutex_unlock(&dc
->lock
);
147 case DEMUX_GET_LENGTH
:
148 vlc_mutex_lock(&dc
->lock
);
149 *va_arg(ap
, vlc_tick_t
*) = dc
->stats
.length
;
150 vlc_mutex_unlock(&dc
->lock
);
153 vlc_mutex_lock(&dc
->lock
);
154 *va_arg(ap
, vlc_tick_t
*) = dc
->stats
.time
;
155 vlc_mutex_unlock(&dc
->lock
);
163 void vlc_demux_chained_Delete(vlc_demux_chained_t
*dc
)
165 vlc_stream_fifo_Close(dc
->fifo
);
166 vlc_join(dc
->thread
, NULL
);
167 vlc_mutex_destroy(&dc
->lock
);