X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fnsv.c;h=34890534b03af6705d308532c2d7077e39162f9c;hb=452ceeacf515b84f1e135e842214ff3fd65394b3;hp=577472018f9fca111e89a4a40bbb29af2ed2109b;hpb=fe087a38282e93addb25fa9598393e40ea233b09;p=vlc diff --git a/modules/demux/nsv.c b/modules/demux/nsv.c index 577472018f..34890534b0 100644 --- a/modules/demux/nsv.c +++ b/modules/demux/nsv.c @@ -1,7 +1,7 @@ /***************************************************************************** * nsv.c: NullSoft Video demuxer. ***************************************************************************** - * Copyright (C) 2004 the VideoLAN team + * Copyright (C) 2004-2007 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -18,16 +18,20 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include /* TODO: * - implement NSVf parsing (to get meta data) @@ -41,14 +45,14 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_description( _("NullSoft demuxer" ) ); - set_capability( "demux2", 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 @@ -68,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 ); @@ -86,17 +92,16 @@ static int Open( vlc_object_t *p_this ) demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; - uint8_t *p_peek; + const uint8_t *p_peek; - if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) return VLC_EGENERIC; + if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) + return VLC_EGENERIC; - if( strncmp( p_peek, "NSVf", 4 ) && strncmp( p_peek, "NSVs", 4 )) + if( memcmp( p_peek, "NSVf", 4 ) && memcmp( p_peek, "NSVs", 4 ) ) { /* In case we had force this demuxer we try to resynch */ - if( strcmp( p_demux->psz_demux, "nsv" ) || ReSynch( p_demux ) ) - { + if( !p_demux->b_force || ReSynch( p_demux ) ) return VLC_EGENERIC; - } } /* Fill p_demux field */ @@ -117,6 +122,8 @@ static int Open( vlc_object_t *p_this ) p_sys->i_time = 0; p_sys->i_pcr_inc = 0; + p_sys->b_start_record = false; + return VLC_SUCCESS; } @@ -140,7 +147,7 @@ static int Demux( demux_t *p_demux ) demux_sys_t *p_sys = p_demux->p_sys; uint8_t header[5]; - uint8_t *p_peek; + const uint8_t *p_peek; int i_size; block_t *p_frame; @@ -153,19 +160,22 @@ static int Demux( demux_t *p_demux ) return 0; } - if( !strncmp( p_peek, "NSVf", 4 ) ) + if( !memcmp( p_peek, "NSVf", 4 ) ) { if( ReadNSVf( p_demux ) ) - { return -1; - } } - else if( !strncmp( p_peek, "NSVs", 4 ) ) + 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 ) @@ -180,11 +190,9 @@ static int Demux( demux_t *p_demux ) } else { - msg_Err( p_demux, "invalid signature 0x%x (%4.4s)", *(uint32_t*)p_peek, (char*)p_peek ); + msg_Err( p_demux, "invalid signature 0x%x (%4.4s)", GetDWLE( p_peek ), (const char*)p_peek ); if( ReSynch( p_demux ) ) - { return -1; - } } } @@ -313,6 +321,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 ) @@ -334,11 +343,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; @@ -369,6 +376,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; @@ -380,11 +401,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) *****************************************************************************/ static int ReSynch( demux_t *p_demux ) { - uint8_t *p_peek; + const uint8_t *p_peek; int i_skip; int i_peek; - while( !p_demux->b_die ) + while( vlc_object_alive (p_demux) ) { if( ( i_peek = stream_Peek( p_demux->s, &p_peek, 1024 ) ) < 8 ) { @@ -394,7 +415,8 @@ static int ReSynch( demux_t *p_demux ) while( i_skip < i_peek - 4 ) { - if( !strncmp( p_peek, "NSVf", 4 ) || !strncmp( p_peek, "NSVs", 4 ) ) + if( !memcmp( p_peek, "NSVf", 4 ) + || !memcmp( p_peek, "NSVs", 4 ) ) { if( i_skip > 0 ) { @@ -417,7 +439,7 @@ static int ReSynch( demux_t *p_demux ) static int ReadNSVf( demux_t *p_demux ) { /* demux_sys_t *p_sys = p_demux->p_sys; */ - uint8_t *p; + const uint8_t *p; int i_size; msg_Dbg( p_demux, "new NSVf chunk" ); @@ -446,7 +468,6 @@ static int ReadNSVs( demux_t *p_demux ) return VLC_EGENERIC; } - msg_Dbg( p_demux, "new NSVs chunk" ); /* Video */ switch( ( fcc = VLC_FOURCC( header[4], header[5], header[6], header[7] ) ) ) { @@ -454,10 +475,14 @@ static int ReadNSVs( demux_t *p_demux ) case VLC_FOURCC( 'V', 'P', '3', '1' ): fcc = VLC_FOURCC( 'V', 'P', '3', '1' ); 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( 'H', '2', '6', '4' ): case VLC_FOURCC( 'N', 'O', 'N', 'E' ): break; default: - msg_Warn( p_demux, "unknown codec" ); + msg_Warn( p_demux, "unknown codec %4.4s", (char *)&fcc ); break; } if( fcc != VLC_FOURCC( 'N', 'O', 'N', 'E' ) && fcc != p_sys->fmt_video.i_codec ) @@ -493,7 +518,7 @@ static int ReadNSVs( demux_t *p_demux ) case VLC_FOURCC( 'N', 'O', 'N', 'E' ): break; default: - msg_Warn( p_demux, "unknown codec" ); + msg_Warn( p_demux, "unknown codec %4.4s", (char *)&fcc ); break; } @@ -543,7 +568,7 @@ static int ReadNSVs( demux_t *p_demux ) msg_Dbg( p_demux, "invalid fps (0x00)" ); p_sys->i_pcr_inc = 40000; } - msg_Dbg( p_demux, " - fps=%.3f", 1000000.0 / (double)p_sys->i_pcr_inc ); + //msg_Dbg( p_demux, " - fps=%.3f", 1000000.0 / (double)p_sys->i_pcr_inc ); return VLC_SUCCESS; }