]> git.sesse.net Git - vlc/blob - modules/stream_filter/smooth/smooth.h
Smooth Streaming: fix a macro
[vlc] / modules / stream_filter / smooth / smooth.h
1 /*****************************************************************************
2  * smooth.h: misc. stuff
3  *****************************************************************************
4  * Copyright (C) 1996-2012 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Author: Frédéric Yhuel <fyhuel _AT_ viotech _DOT_ net>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef _VLC_SMOOTH_H
25 #define _VLC_SMOOTH_H 1
26
27 //#define DISABLE_BANDWIDTH_ADAPTATION
28
29 typedef struct item_s
30 {
31     uint64_t value;
32     struct item_s *next;
33
34 } item_t;
35
36 typedef struct sms_queue_s
37 {
38     int length;
39     item_t *first;
40 } sms_queue_t;
41
42 typedef struct chunk_s
43 {
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 */
51
52     block_t     *data;
53 } chunk_t;
54
55 typedef struct quality_level_s
56 {
57     int             Index;
58     uint32_t        FourCC;
59     unsigned        Bitrate;
60     unsigned        MaxWidth;
61     unsigned        MaxHeight;
62     unsigned        SamplingRate;
63     unsigned        Channels;
64     unsigned        BitsPerSample;
65     unsigned        AudioTag;
66     unsigned        nBlockAlign;
67     unsigned        id;
68     char            *CodecPrivateData; /* hex encoded string */
69
70 } quality_level_t;
71
72 typedef struct sms_stream_s
73 {
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 */
78     unsigned       timescale;
79     unsigned       qlevel_nb;      /* number of quality levels */
80     unsigned       id;             /* track id, will be set arbitrarily */
81     char           *name;
82     char           *url_template;
83     int            type;
84     unsigned       download_qlvl; /* current quality level ID for Download() */
85
86 } sms_stream_t;
87
88 struct stream_sys_t
89 {
90     char         *base_url;    /* URL common part for chunks */
91     vlc_thread_t thread;       /* SMS chunk download thread */
92
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 */
98     int64_t      time_pos;
99     unsigned     timescale;
100
101     /* Download */
102     struct sms_download_s
103     {
104         uint64_t     lead[3];     /* how much audio/video/text data is available
105                                      (downloaded), in seconds / TimeScale */
106
107         unsigned     ck_index[3]; /* current chunk for download */
108
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 */
113     } download;
114
115     /* Playback */
116     struct sms_playback_s
117     {
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 */
121     } playback;
122
123     /* state */
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 */
129 };
130
131 #define SMS_GET4BYTES( dst ) do { \
132     dst = U32_AT( slice ); \
133     slice += 4; \
134   } while(0)
135
136 #define SMS_GET1BYTE( dst ) do { \
137     dst = *slice; \
138     slice += 1; \
139   } while(0)
140
141 #define SMS_GET3BYTES( dst ) do { \
142     dst = Get24bBE( slice ); \
143     slice += 3; \
144   } while(0)
145
146 #define SMS_GET8BYTES( dst ) do { \
147     dst = U64_AT( slice ); \
148     slice += 8; \
149   } while(0)
150
151 #define SMS_GET4or8BYTES( dst ) \
152     if( (version) == 0 ) \
153         SMS_GET4BYTES( dst ); \
154     else \
155         SMS_GET8BYTES( dst ); \
156
157 #define SMS_GETFOURCC( dst ) do { \
158     memcpy( &dst, slice, 4 ); \
159     slice += 4; \
160   } while(0)
161
162 #define SMS_GET_SELECTED_ST( cat ) \
163     sms_get_stream_by_cat( p_sys->selected_st, cat )
164
165 #define NO_MORE_CHUNKS ( !p_sys->b_live && \
166     no_more_chunks( p_sys->download.ck_index, p_sys->selected_st ) )
167
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 );
184
185 #endif