1 /*****************************************************************************
2 * smooth.h: misc. stuff
3 *****************************************************************************
4 * Copyright (C) 1996-2012 VLC authors and VideoLAN
7 * Author: Frédéric Yhuel <fyhuel _AT_ viotech _DOT_ net>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library 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 GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *****************************************************************************/
25 #define _VLC_SMOOTH_H 1
27 //#define DISABLE_BANDWIDTH_ADAPTATION
36 typedef struct sms_queue_s
42 typedef struct chunk_s
44 int64_t duration; /* chunk duration (seconds / TimeScale) */
45 int64_t start_time; /* PTS (seconds / TimeScale) */
46 int size; /* chunk size in bytes */
47 unsigned sequence; /* unique sequence number */
48 uint64_t offset; /* offset in the media */
49 int read_pos; /* position in the chunk */
50 int type; /* video, audio, or subtitles */
55 typedef struct quality_level_s
62 unsigned SamplingRate;
64 unsigned BitsPerSample;
68 char *CodecPrivateData; /* hex encoded string */
72 typedef struct sms_stream_s
74 vlc_array_t *qlevels; /* list of available Quality Levels */
75 vlc_array_t *chunks; /* list of chunks */
76 uint32_t default_FourCC;
77 unsigned vod_chunks_nb; /* total num of chunks of the VOD stream */
79 unsigned qlevel_nb; /* number of quality levels */
80 unsigned id; /* track id, will be set arbitrarily */
84 unsigned download_qlvl; /* current quality level ID for Download() */
90 char *base_url; /* URL common part for chunks */
91 vlc_thread_t thread; /* SMS chunk download thread */
93 vlc_array_t *sms_streams; /* available streams */
94 vlc_array_t *selected_st; /* selected streams */
95 unsigned i_tracks; /* Total number of tracks in the Manifest */
96 sms_queue_t *bws; /* Measured bandwidths of the N last chunks */
97 uint64_t vod_duration; /* total duration of the VOD media */
102 struct sms_download_s
104 uint64_t lead[3]; /* how much audio/video/text data is available
105 (downloaded), in seconds / TimeScale */
107 unsigned ck_index[3]; /* current chunk for download */
109 uint64_t next_chunk_offset;
110 vlc_array_t *chunks; /* chunks that have been downloaded */
111 vlc_mutex_t lock_wait; /* protect chunk download counter. */
112 vlc_cond_t wait; /* some condition to wait on */
116 struct sms_playback_s
118 uint64_t boffset; /* current byte offset in media */
119 uint64_t toffset; /* current time offset in media */
120 unsigned index; /* current chunk for playback */
124 bool b_cache; /* can cache files */
125 bool b_live; /* live stream? or vod? */
126 bool b_error; /* parsing error */
127 bool b_close; /* set by Close() */
128 bool b_tseek; /* time seeking */
131 #define SMS_GET4BYTES( dst ) do { \
132 dst = U32_AT( slice ); \
136 #define SMS_GET1BYTE( dst ) do { \
141 #define SMS_GET3BYTES( dst ) do { \
142 dst = Get24bBE( slice ); \
146 #define SMS_GET8BYTES( dst ) do { \
147 dst = U64_AT( slice ); \
151 #define SMS_GET4or8BYTES( dst ) \
152 if( (version) == 0 ) \
153 SMS_GET4BYTES( dst ); \
155 SMS_GET8BYTES( dst ); \
157 #define SMS_GETFOURCC( dst ) do { \
158 memcpy( &dst, slice, 4 ); \
162 #define SMS_GET_SELECTED_ST( cat ) \
163 sms_get_stream_by_cat( p_sys->selected_st, cat )
165 #define NO_MORE_CHUNKS ( !p_sys->b_live && \
166 no_more_chunks( p_sys->download.ck_index, p_sys->selected_st ) )
168 sms_queue_t *sms_queue_init( const int );
169 int sms_queue_put( sms_queue_t *, const uint64_t );
170 uint64_t sms_queue_avg( sms_queue_t *);
171 quality_level_t *get_qlevel( sms_stream_t *, const unsigned );
172 void* sms_Thread( void *);
173 quality_level_t * ql_New( void );
174 void ql_Free( quality_level_t *);
175 chunk_t *chunk_New( sms_stream_t* , uint64_t , uint64_t );
176 void chunk_Free( chunk_t *);
177 sms_stream_t * sms_New( void );
178 void sms_Free( sms_stream_t *);
179 uint8_t *decode_string_hex_to_binary( const char * );
180 sms_stream_t * sms_get_stream_by_cat( vlc_array_t *, int );
181 bool no_more_chunks( unsigned[], vlc_array_t *);
182 int index_to_es_cat( int );
183 int es_cat_to_index( int );