X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fnsv.c;h=b9b3585564c305285017f695be575aeae0bce127;hb=db7fa8f9dbe8d1ba9ae182fff1cef8dddc11db74;hp=dee177e1925f13b63365e66517e49034b9bb0b34;hpb=df61d33b06e2b3cbbe746b2f5a9bea5b370c24ff;p=vlc diff --git a/modules/demux/nsv.c b/modules/demux/nsv.c index dee177e192..b9b3585564 100644 --- a/modules/demux/nsv.c +++ b/modules/demux/nsv.c @@ -1,24 +1,24 @@ /***************************************************************************** * nsv.c: NullSoft Video demuxer. ***************************************************************************** - * Copyright (C) 2004-2007 the VideoLAN team + * Copyright (C) 2004-2007 VLC authors and VideoLAN * $Id$ * * Authors: Laurent Aimar * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -29,7 +29,8 @@ # include "config.h" #endif -#include +#include +#include #include /* TODO: @@ -44,14 +45,14 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_description( _("NullSoft demuxer" ) ); - set_capability( "demux", 10 ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_DEMUX ); - set_callbacks( Open, Close ); - add_shortcut( "nsv" ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("NullSoft demuxer" ) ) + set_capability( "demux", 10 ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_DEMUX ) + set_callbacks( Open, Close ) + add_shortcut( "nsv" ) +vlc_module_end () /***************************************************************************** * Local prototypes @@ -71,6 +72,8 @@ struct demux_sys_t int64_t i_pcr; int64_t i_time; int64_t i_pcr_inc; + + bool b_start_record; }; static int Demux ( demux_t *p_demux ); @@ -101,10 +104,14 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; } + p_sys = malloc( sizeof( demux_sys_t ) ); + if( unlikely(p_sys == NULL) ) + return VLC_ENOMEM; + /* Fill p_demux field */ + p_demux->p_sys = p_sys; p_demux->pf_demux = Demux; p_demux->pf_control = Control; - p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); es_format_Init( &p_sys->fmt_audio, AUDIO_ES, 0 ); p_sys->p_audio = NULL; @@ -115,10 +122,12 @@ static int Open( vlc_object_t *p_this ) es_format_Init( &p_sys->fmt_sub, SPU_ES, 0 ); p_sys->p_sub = NULL; - p_sys->i_pcr = 1; + p_sys->i_pcr = 0; p_sys->i_time = 0; p_sys->i_pcr_inc = 0; + p_sys->b_start_record = false; + return VLC_SUCCESS; } @@ -158,16 +167,19 @@ static int Demux( demux_t *p_demux ) if( !memcmp( p_peek, "NSVf", 4 ) ) { if( ReadNSVf( p_demux ) ) - { return -1; - } } else if( !memcmp( p_peek, "NSVs", 4 ) ) { - if( ReadNSVs( p_demux ) ) + if( p_sys->b_start_record ) { - return -1; + /* Enable recording once synchronized */ + stream_Control( p_demux->s, STREAM_SET_RECORD_STATE, true, "nsv" ); + p_sys->b_start_record = false; } + + if( ReadNSVs( p_demux ) ) + return -1; break; } else if( GetWLE( p_peek ) == 0xbeef ) @@ -184,9 +196,7 @@ static int Demux( demux_t *p_demux ) { msg_Err( p_demux, "invalid signature 0x%x (%4.4s)", GetDWLE( p_peek ), (const char*)p_peek ); if( ReSynch( p_demux ) ) - { return -1; - } } } @@ -197,7 +207,7 @@ static int Demux( demux_t *p_demux ) } /* Set PCR */ - es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_pcr ); + es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr ); /* Read video */ i_size = ( header[0] >> 4 ) | ( header[1] << 4 ) | ( header[2] << 12 ); @@ -245,8 +255,8 @@ static int Demux( demux_t *p_demux ) } /* Skip the first part (it is the language name) */ - p_frame->i_pts = p_sys->i_pcr; - p_frame->i_dts = p_sys->i_pcr + 4000000; /* 4s */ + p_frame->i_pts = VLC_TS_0 + p_sys->i_pcr; + p_frame->i_dts = VLC_TS_0 + p_sys->i_pcr + 4000000; /* 4s */ es_out_Send( p_demux->out, p_sys->p_sub, p_frame ); } @@ -266,7 +276,7 @@ static int Demux( demux_t *p_demux ) /* msg_Dbg( p_demux, "frame video size=%d", i_size ); */ if( i_size > 0 && ( p_frame = stream_Block( p_demux->s, i_size ) ) ) { - p_frame->i_dts = p_sys->i_pcr; + p_frame->i_dts = VLC_TS_0 + p_sys->i_pcr; es_out_Send( p_demux->out, p_sys->p_video, p_frame ); } } @@ -294,7 +304,7 @@ static int Demux( demux_t *p_demux ) if( ( p_frame = stream_Block( p_demux->s, i_size ) ) ) { p_frame->i_dts = - p_frame->i_pts = p_sys->i_pcr; + p_frame->i_pts = VLC_TS_0 + p_sys->i_pcr; es_out_Send( p_demux->out, p_sys->p_audio, p_frame ); } } @@ -315,6 +325,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) { demux_sys_t *p_sys = p_demux->p_sys; double f, *pf; + bool b_bool, *pb_bool; int64_t i64, *pi64; switch( i_query ) @@ -324,7 +335,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) i64 = stream_Size( p_demux->s ); if( i64 > 0 ) { - *pf = (double)stream_Tell( p_demux->s ) / (double)i64; + double current = stream_Tell( p_demux->s ); + *pf = current / (double)i64; } else { @@ -336,11 +348,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) f = (double) va_arg( args, double ); i64 = stream_Size( p_demux->s ); - es_out_Control( p_demux->out, ES_OUT_RESET_PCR ); if( stream_Seek( p_demux->s, (int64_t)(i64 * f) ) || ReSynch( p_demux ) ) - { return VLC_EGENERIC; - } + p_sys->i_time = -1; /* Invalidate time display */ return VLC_SUCCESS; @@ -371,6 +381,20 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) *pf = (double)1000000.0 / (double)p_sys->i_pcr_inc; return VLC_SUCCESS; + case DEMUX_CAN_RECORD: + pb_bool = (bool*)va_arg( args, bool * ); + *pb_bool = true; + return VLC_SUCCESS; + + case DEMUX_SET_RECORD_STATE: + b_bool = (bool)va_arg( args, int ); + + if( !b_bool ) + stream_Control( p_demux->s, STREAM_SET_RECORD_STATE, false ); + p_sys->b_start_record = b_bool; + return VLC_SUCCESS; + + case DEMUX_SET_TIME: default: return VLC_EGENERIC; @@ -382,17 +406,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) *****************************************************************************/ static int ReSynch( demux_t *p_demux ) { - const uint8_t *p_peek; - int i_skip; - int i_peek; - - while( !p_demux->b_die ) + for( ;; ) { - if( ( i_peek = stream_Peek( p_demux->s, &p_peek, 1024 ) ) < 8 ) - { - return VLC_EGENERIC; - } - i_skip = 0; + const uint8_t *p_peek; + int i_peek = stream_Peek( p_demux->s, &p_peek, 1024 ); + if( i_peek < 8 ) + break; + + int i_skip = 0; while( i_skip < i_peek - 4 ) { @@ -409,7 +430,8 @@ static int ReSynch( demux_t *p_demux ) i_skip++; } - stream_Read( p_demux->s, NULL, i_skip ); + if( stream_Read( p_demux->s, NULL, i_skip ) < i_skip ) + break; } return VLC_EGENERIC; } @@ -435,7 +457,7 @@ static int ReadNSVf( demux_t *p_demux ) return stream_Read( p_demux->s, NULL, i_size ) == i_size ? VLC_SUCCESS : VLC_EGENERIC; } /***************************************************************************** - * ReadNSVf: + * ReadNSVs: *****************************************************************************/ static int ReadNSVs( demux_t *p_demux ) { @@ -453,12 +475,22 @@ static int ReadNSVs( demux_t *p_demux ) switch( ( fcc = VLC_FOURCC( header[4], header[5], header[6], header[7] ) ) ) { case VLC_FOURCC( 'V', 'P', '3', ' ' ): + case VLC_FOURCC( 'V', 'P', '3', '0' ): + fcc = VLC_FOURCC( 'V', 'P', '3', '0' ); + break; + case VLC_FOURCC( 'V', 'P', '3', '1' ): fcc = VLC_FOURCC( 'V', 'P', '3', '1' ); break; + + case VLC_FOURCC( 'V', 'P', '5', ' ' ): + case VLC_FOURCC( 'V', 'P', '5', '0' ): + fcc = VLC_FOURCC( 'V', 'P', '5', '0' ); + break; case VLC_FOURCC( 'V', 'P', '6', '0' ): case VLC_FOURCC( 'V', 'P', '6', '1' ): case VLC_FOURCC( 'V', 'P', '6', '2' ): + case VLC_FOURCC( 'V', 'P', '8', '0' ): case VLC_FOURCC( 'H', '2', '6', '4' ): case VLC_FOURCC( 'N', 'O', 'N', 'E' ): break; @@ -496,6 +528,9 @@ static int ReadNSVs( demux_t *p_demux ) case VLC_FOURCC( 'A', 'A', 'C', 'P' ): fcc = VLC_FOURCC( 'm', 'p', '4', 'a' ); break; + case VLC_FOURCC( 'S', 'P', 'X', ' ' ): + fcc = VLC_FOURCC( 's', 'p', 'x', ' ' ); + break; case VLC_FOURCC( 'N', 'O', 'N', 'E' ): break; default: