| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#ifdef HAVE_CONFIG_H |
|---|
| 28 |
# include "config.h" |
|---|
| 29 |
#endif |
|---|
| 30 |
|
|---|
| 31 |
#include <vlc_common.h> |
|---|
| 32 |
#include <vlc_plugin.h> |
|---|
| 33 |
#include <vlc_demux.h> |
|---|
| 34 |
#include <vlc_codec.h> |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
static int Open ( vlc_object_t * ); |
|---|
| 40 |
static void Close ( vlc_object_t * ); |
|---|
| 41 |
|
|---|
| 42 |
vlc_module_begin(); |
|---|
| 43 |
set_category( CAT_INPUT ); |
|---|
| 44 |
set_subcategory( SUBCAT_INPUT_DEMUX ); |
|---|
| 45 |
set_description( N_("Raw DTS demuxer") ); |
|---|
| 46 |
set_capability( "demux", 155 ); |
|---|
| 47 |
set_callbacks( Open, Close ); |
|---|
| 48 |
add_shortcut( "dts" ); |
|---|
| 49 |
vlc_module_end(); |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
static int Demux ( demux_t * ); |
|---|
| 55 |
static int Control( demux_t *, int, va_list ); |
|---|
| 56 |
|
|---|
| 57 |
struct demux_sys_t |
|---|
| 58 |
{ |
|---|
| 59 |
bool b_start; |
|---|
| 60 |
es_out_id_t *p_es; |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
decoder_t *p_packetizer; |
|---|
| 64 |
|
|---|
| 65 |
mtime_t i_pts; |
|---|
| 66 |
mtime_t i_time_offset; |
|---|
| 67 |
|
|---|
| 68 |
int i_mux_rate; |
|---|
| 69 |
}; |
|---|
| 70 |
|
|---|
| 71 |
static int CheckSync( const uint8_t *p_peek ); |
|---|
| 72 |
|
|---|
| 73 |
#define DTS_PACKET_SIZE 16384 |
|---|
| 74 |
#define DTS_PROBE_SIZE (DTS_PACKET_SIZE * 4) |
|---|
| 75 |
#define DTS_MAX_HEADER_SIZE 11 |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
static int Open( vlc_object_t * p_this ) |
|---|
| 81 |
{ |
|---|
| 82 |
demux_t *p_demux = (demux_t*)p_this; |
|---|
| 83 |
demux_sys_t *p_sys; |
|---|
| 84 |
const uint8_t *p_peek; |
|---|
| 85 |
int i_peek = 0; |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
if( stream_Peek( p_demux->s, &p_peek, 20 ) == 20 && |
|---|
| 89 |
!memcmp( p_peek, "RIFF", 4 ) && !memcmp( &p_peek[8], "WAVE", 4 ) ) |
|---|
| 90 |
{ |
|---|
| 91 |
|
|---|
| 92 |
i_peek = 12 + 8; |
|---|
| 93 |
while( memcmp( p_peek + i_peek - 8, "fmt ", 4 ) ) |
|---|
| 94 |
{ |
|---|
| 95 |
uint32_t i_len = GetDWLE( p_peek + i_peek - 4 ); |
|---|
| 96 |
if( i_len > DTS_PROBE_SIZE || i_peek + i_len > DTS_PROBE_SIZE ) |
|---|
| 97 |
return VLC_EGENERIC; |
|---|
| 98 |
|
|---|
| 99 |
i_peek += i_len + 8; |
|---|
| 100 |
if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) |
|---|
| 101 |
return VLC_EGENERIC; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
uint32_t i_len = GetDWLE( p_peek + i_peek - 4 ); |
|---|
| 106 |
if( i_len > DTS_PROBE_SIZE ) |
|---|
| 107 |
return VLC_EGENERIC; |
|---|
| 108 |
|
|---|
| 109 |
i_peek += i_len + 8; |
|---|
| 110 |
if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) |
|---|
| 111 |
return VLC_EGENERIC; |
|---|
| 112 |
if( GetWLE( p_peek + i_peek - i_len - 8 ) != |
|---|
| 113 |
1 ) |
|---|
| 114 |
return VLC_EGENERIC; |
|---|
| 115 |
if( GetWLE( p_peek + i_peek - i_len - 6 ) != 2 ) |
|---|
| 116 |
return VLC_EGENERIC; |
|---|
| 117 |
if( GetDWLE( p_peek + i_peek - i_len - 4 ) != |
|---|
| 118 |
44100 ) |
|---|
| 119 |
return VLC_EGENERIC; |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
while( memcmp( p_peek + i_peek - 8, "data", 4 ) ) |
|---|
| 123 |
{ |
|---|
| 124 |
uint32_t i_len = GetDWLE( p_peek + i_peek - 4 ); |
|---|
| 125 |
if( i_len > DTS_PROBE_SIZE || i_peek + i_len > DTS_PROBE_SIZE ) |
|---|
| 126 |
return VLC_EGENERIC; |
|---|
| 127 |
|
|---|
| 128 |
i_peek += i_len + 8; |
|---|
| 129 |
if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) |
|---|
| 130 |
return VLC_EGENERIC; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
int i_size = stream_Peek( p_demux->s, &p_peek, DTS_PROBE_SIZE ); |
|---|
| 136 |
i_size -= DTS_MAX_HEADER_SIZE; |
|---|
| 137 |
|
|---|
| 138 |
while( i_peek < i_size ) |
|---|
| 139 |
{ |
|---|
| 140 |
if( CheckSync( p_peek + i_peek ) != VLC_SUCCESS ) |
|---|
| 141 |
|
|---|
| 142 |
i_peek += 2; |
|---|
| 143 |
else |
|---|
| 144 |
break; |
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
CHECK_PEEK( p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ); |
|---|
| 150 |
|
|---|
| 151 |
if( CheckSync( p_peek + i_peek ) != VLC_SUCCESS ) |
|---|
| 152 |
{ |
|---|
| 153 |
if( !p_demux->b_force ) |
|---|
| 154 |
return VLC_EGENERIC; |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
msg_Err( p_demux, "this doesn't look like a DTS audio stream, " |
|---|
| 158 |
"continuing anyway" ); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys; |
|---|
| 162 |
p_sys->i_mux_rate = 0; |
|---|
| 163 |
p_sys->i_pts = 0; |
|---|
| 164 |
p_sys->i_time_offset = 0; |
|---|
| 165 |
|
|---|
| 166 |
INIT_APACKETIZER( p_sys->p_packetizer, 'd','t','s',' ' ); |
|---|
| 167 |
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "DTS" ); |
|---|
| 168 |
|
|---|
| 169 |
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); |
|---|
| 170 |
|
|---|
| 171 |
return VLC_SUCCESS; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
static void Close( vlc_object_t *p_this ) |
|---|
| 178 |
{ |
|---|
| 179 |
demux_t *p_demux = (demux_t*)p_this; |
|---|
| 180 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 181 |
|
|---|
| 182 |
DESTROY_PACKETIZER( p_sys->p_packetizer ); |
|---|
| 183 |
|
|---|
| 184 |
free( p_sys ); |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
static int Demux( demux_t *p_demux ) |
|---|
| 193 |
{ |
|---|
| 194 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 195 |
block_t *p_block_in, *p_block_out; |
|---|
| 196 |
|
|---|
| 197 |
if( !( p_block_in = stream_Block( p_demux->s, DTS_PACKET_SIZE ) ) ) |
|---|
| 198 |
{ |
|---|
| 199 |
return 0; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
if( p_sys->b_start ) |
|---|
| 203 |
p_block_in->i_pts = p_block_in->i_dts = 1; |
|---|
| 204 |
else |
|---|
| 205 |
p_block_in->i_pts = p_block_in->i_dts = 0; |
|---|
| 206 |
|
|---|
| 207 |
while( (p_block_out = p_sys->p_packetizer->pf_packetize( |
|---|
| 208 |
p_sys->p_packetizer, &p_block_in )) ) |
|---|
| 209 |
{ |
|---|
| 210 |
p_sys->b_start = false; |
|---|
| 211 |
|
|---|
| 212 |
while( p_block_out ) |
|---|
| 213 |
{ |
|---|
| 214 |
block_t *p_next = p_block_out->p_next; |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
if( p_block_out->i_length ) |
|---|
| 218 |
{ |
|---|
| 219 |
p_sys->i_mux_rate = |
|---|
| 220 |
p_block_out->i_buffer * INT64_C(1000000) / p_block_out->i_length; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
p_block_out->i_pts += p_sys->i_time_offset; |
|---|
| 225 |
p_block_out->i_dts += p_sys->i_time_offset; |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); |
|---|
| 229 |
|
|---|
| 230 |
es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); |
|---|
| 231 |
|
|---|
| 232 |
p_block_out = p_next; |
|---|
| 233 |
} |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
return 1; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| 243 |
{ |
|---|
| 244 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 245 |
bool *pb_bool; |
|---|
| 246 |
int64_t *pi64; |
|---|
| 247 |
int i_ret; |
|---|
| 248 |
|
|---|
| 249 |
switch( i_query ) |
|---|
| 250 |
{ |
|---|
| 251 |
case DEMUX_HAS_UNSUPPORTED_META: |
|---|
| 252 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 253 |
*pb_bool = true; |
|---|
| 254 |
return VLC_SUCCESS; |
|---|
| 255 |
|
|---|
| 256 |
case DEMUX_GET_TIME: |
|---|
| 257 |
pi64 = (int64_t*)va_arg( args, int64_t * ); |
|---|
| 258 |
*pi64 = p_sys->i_pts + p_sys->i_time_offset; |
|---|
| 259 |
return VLC_SUCCESS; |
|---|
| 260 |
|
|---|
| 261 |
case DEMUX_SET_TIME: |
|---|
| 262 |
default: |
|---|
| 263 |
i_ret = demux_vaControlHelper( p_demux->s, |
|---|
| 264 |
0, -1, |
|---|
| 265 |
8*p_sys->i_mux_rate, 1, i_query, args ); |
|---|
| 266 |
if( !i_ret && p_sys->i_mux_rate > 0 && |
|---|
| 267 |
( i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME ) ) |
|---|
| 268 |
{ |
|---|
| 269 |
|
|---|
| 270 |
const int64_t i_time = INT64_C(1000000) * stream_Tell(p_demux->s) / |
|---|
| 271 |
p_sys->i_mux_rate; |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
if( i_time >= 0 ) |
|---|
| 275 |
p_sys->i_time_offset = i_time - p_sys->i_pts; |
|---|
| 276 |
} |
|---|
| 277 |
return i_ret; |
|---|
| 278 |
} |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
static int CheckSync( const uint8_t *p_peek ) |
|---|
| 285 |
{ |
|---|
| 286 |
|
|---|
| 287 |
if( p_peek[0] == 0xff && p_peek[1] == 0x1f && |
|---|
| 288 |
p_peek[2] == 0x00 && p_peek[3] == 0xe8 && |
|---|
| 289 |
(p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 ) |
|---|
| 290 |
{ |
|---|
| 291 |
return VLC_SUCCESS; |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
else if( p_peek[0] == 0x1f && p_peek[1] == 0xff && |
|---|
| 295 |
p_peek[2] == 0xe8 && p_peek[3] == 0x00 && |
|---|
| 296 |
p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0) |
|---|
| 297 |
{ |
|---|
| 298 |
return VLC_SUCCESS; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe && |
|---|
| 302 |
p_peek[2] == 0x80 && p_peek[3] == 0x01 ) |
|---|
| 303 |
{ |
|---|
| 304 |
return VLC_SUCCESS; |
|---|
| 305 |
} |
|---|
| 306 |
|
|---|
| 307 |
else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f && |
|---|
| 308 |
p_peek[2] == 0x01 && p_peek[3] == 0x80 ) |
|---|
| 309 |
{ |
|---|
| 310 |
return VLC_SUCCESS; |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
return VLC_EGENERIC; |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|