gui: macos: use float for rate
[vlc.git] / src / input / demux_chained.c
blob30fb6fd935114ec2c3f79b1de7fab8fecec6e45f
1 /*****************************************************************************
2 * demux_chained.c
3 *****************************************************************************
4 * Copyright (C) 1999-2016 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7 * RĂ©mi Denis-Courmont
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <limits.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
33 #include "demux.h"
35 struct vlc_demux_chained_t
37 stream_t *fifo;
39 vlc_thread_t thread;
40 vlc_mutex_t lock;
42 struct
44 double position;
45 vlc_tick_t length;
46 vlc_tick_t time;
47 } stats;
49 es_out_t *out;
50 char name[];
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,
57 dc->out);
58 if (demux == NULL)
60 vlc_stream_Delete(dc->fifo);
61 return NULL;
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);
68 /* Main loop */
69 vlc_tick_t next_update = 0;
72 if (demux_TestAndClearFlags(demux, UINT_MAX) || vlc_tick_now() >= next_update)
74 double newpos;
75 vlc_tick_t newlen;
76 vlc_tick_t newtime;
78 if (demux_Control(demux, DEMUX_GET_POSITION, &newpos))
79 newpos = 0.;
80 if (demux_Control(demux, DEMUX_GET_LENGTH, &newlen))
81 newlen = 0;
82 if (demux_Control(demux, DEMUX_GET_TIME, &newtime))
83 newtime = 0;
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);
95 demux_Delete(demux);
96 return NULL;
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))
104 return NULL;
106 dc->fifo = vlc_stream_fifo_New(parent);
107 if (dc->fifo == NULL)
109 free(dc);
110 return NULL;
113 dc->stats.position = 0.;
114 dc->stats.length = 0;
115 dc->stats.time = 0;
116 dc->out = out;
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);
127 free(dc);
128 dc = NULL;
130 return dc;
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)
140 switch (query)
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);
146 break;
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);
151 break;
152 case DEMUX_GET_TIME:
153 vlc_mutex_lock(&dc->lock);
154 *va_arg(ap, vlc_tick_t *) = dc->stats.time;
155 vlc_mutex_unlock(&dc->lock);
156 break;
157 default:
158 return VLC_EGENERIC;
160 return VLC_SUCCESS;
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);
168 free(dc);