/*****************************************************************************
- * rawdv.c : raw dv input module for vlc
+ * rawdv.c : raw DV input module for vlc
*****************************************************************************
- * Copyright (C) 2001-2003 VideoLAN
- * $Id: rawdv.c,v 1.14 2004/01/25 20:05:28 hartman Exp $
+ * Copyright (C) 2001-2007 VLC authors and VideoLAN
+ * $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Paul Corke <paul dot corke at datatote dot co dot uk>
*
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111, 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.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+
+#include "rawdv.h"
/*****************************************************************************
* Module descriptor
*****************************************************************************/
+#define HURRYUP_TEXT N_( "Hurry up" )
+#define HURRYUP_LONGTEXT N_( "The demuxer will advance timestamps if the " \
+ "input can't keep up with the rate." )
+
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
-vlc_module_begin();
- set_description( _("raw dv demuxer") );
- set_capability( "demux", 2 );
- set_callbacks( Open, Close );
- add_shortcut( "rawdv" );
-vlc_module_end();
+vlc_module_begin ()
+ set_shortname( "DV" )
+ set_description( N_("DV (Digital Video) demuxer") )
+ set_capability( "demux", 3 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
+ add_bool( "rawdv-hurry-up", false, HURRYUP_TEXT, HURRYUP_LONGTEXT, false )
+ set_callbacks( Open, Close )
+ add_shortcut( "rawdv" )
+vlc_module_end ()
/*****************************************************************************
*****************************************************************************/
-
-/*****************************************************************************
- * Constants
- *****************************************************************************/
-#define DV_PAL_FRAME_SIZE 144000
-#define DV_NTSC_FRAME_SIZE 122000
-
/*****************************************************************************
* Definitions of structures used by this plugin
*****************************************************************************/
es_out_id_t *p_es_audio;
es_format_t fmt_audio;
+ int i_dsf;
double f_rate;
int i_bitrate;
/* program clock reference (in units of 90kHz) */
mtime_t i_pcr;
+ bool b_hurry_up;
};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int Demux ( input_thread_t * );
+static int Demux( demux_t * );
+static int Control( demux_t *, int i_query, va_list args );
/*****************************************************************************
- * Open: initializes raw dv demux structures
+ * Open: initializes raw DV demux structures
*****************************************************************************/
static int Open( vlc_object_t * p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- demux_sys_t *p_sys;
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys;
- byte_t *p_peek, *p_peek_backup;
+ const uint8_t *p_peek, *p_peek_backup;
- uint32_t i_dword;
- dv_header_t dv_header;
- dv_id_t dv_id;
- char *psz_ext;
+ uint32_t i_dword;
+ dv_header_t dv_header;
+ dv_id_t dv_id;
- /* It isn't easy to recognize a raw dv stream. The chances that we'll
- * mistake a stream from another type for a raw dv stream are too high, so
+ /* It isn't easy to recognize a raw DV stream. The chances that we'll
+ * mistake a stream from another type for a raw DV stream are too high, so
* we'll rely on the file extension to trigger this demux. Alternatively,
* it is possible to force this demux. */
- /* Check for dv file extension */
- psz_ext = strrchr ( p_input->psz_name, '.' );
- if( ( !psz_ext || strcasecmp( psz_ext, ".dv") )&&
- ( !p_input->psz_demux || strcmp(p_input->psz_demux, "rawdv") ) )
- {
+ /* Check for DV file extension */
+ if( !demux_IsPathExtension( p_demux, ".dv" ) && !p_demux->b_force )
return VLC_EGENERIC;
- }
- if( stream_Peek( p_input->s, &p_peek, DV_PAL_FRAME_SIZE ) < DV_NTSC_FRAME_SIZE )
+ if( stream_Peek( p_demux->s, &p_peek, DV_PAL_FRAME_SIZE ) <
+ DV_NTSC_FRAME_SIZE )
{
/* Stream too short ... */
- msg_Err( p_input, "cannot peek()" );
+ msg_Err( p_demux, "cannot peek()" );
return VLC_EGENERIC;
}
p_peek_backup = p_peek;
if( dv_id.sct != 0 )
{
- msg_Warn( p_input, "not a raw dv stream header" );
+ msg_Warn( p_demux, "not a raw DV stream header" );
return VLC_EGENERIC;
}
i_dword <<= 1;
if( i_dword >> (32 - 1) ) /* incorrect bit */
{
- msg_Warn( p_input, "incorrect bit" );
+ msg_Warn( p_demux, "incorrect bit" );
return VLC_EGENERIC;
}
p_peek += 72; /* skip rest of DIF block */
+ p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+ if( !p_sys )
+ return VLC_ENOMEM;
- /* Set p_input field */
- p_input->pf_demux = Demux;
- p_input->pf_demux_control = demux_vaControlDefault;
- p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
+ p_sys->b_hurry_up = var_CreateGetBool( p_demux, "rawdv-hurry-up" );
+ msg_Dbg( p_demux, "Realtime DV Source: %s", (p_sys->b_hurry_up)?"Yes":"No" );
- p_sys->frame_size = dv_header.dsf ? 12 * 150 * 80 : 10 * 150 * 80;
+ p_sys->i_dsf = dv_header.dsf;
+ p_sys->frame_size = dv_header.dsf ? DV_PAL_FRAME_SIZE
+ : DV_NTSC_FRAME_SIZE;
p_sys->f_rate = dv_header.dsf ? 25 : 29.97;
p_sys->i_pcr = 0;
p_sys->i_bitrate = 0;
- es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_FOURCC( 'd','v','s','d' ) );
+ es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_CODEC_DV );
p_sys->fmt_video.video.i_width = 720;
p_sys->fmt_video.video.i_height= dv_header.dsf ? 576 : 480;;
+ p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video );
+
/* Audio stuff */
-#if 0
p_peek = p_peek_backup + 80*6+80*16*3 + 3; /* beginning of AAUX pack */
-
- if( *p_peek != 0x50 || *p_peek != 0x51 )
+ if( *p_peek == 0x50 )
{
- msg_Err( p_input, "AAUX should begin with 0x50" );
- }
-#endif
-
- es_format_Init( &p_sys->fmt_audio, AUDIO_ES, VLC_FOURCC( 'd','v','a','u' ) );
- p_sys->fmt_audio.audio.i_channels = 2;
- p_sys->fmt_audio.audio.i_rate = 44100; /* FIXME */
- p_sys->fmt_audio.audio.i_bitspersample = 16;
- p_sys->fmt_audio.audio.i_blockalign = p_sys->frame_size; /* ??? */
- p_sys->fmt_audio.i_bitrate = p_sys->f_rate * p_sys->frame_size; /* ??? */
-
- /* necessary because input_SplitBuffer() will only get
- * INPUT_DEFAULT_BUFSIZE bytes at a time. */
- p_input->i_bufsize = p_sys->frame_size;
-
- vlc_mutex_lock( &p_input->stream.stream_lock );
- if( input_InitStream( p_input, 0 ) == -1)
- {
- vlc_mutex_unlock( &p_input->stream.stream_lock );
- msg_Err( p_input, "cannot init stream" );
- free( p_sys );
- return VLC_EGENERIC;
+ dv_get_audio_format( &p_sys->fmt_audio, &p_peek[1] );
+ p_sys->p_es_audio = es_out_Add( p_demux->out, &p_sys->fmt_audio );
}
- p_input->stream.i_mux_rate = p_sys->frame_size * p_sys->f_rate;
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- p_sys->p_es_video = es_out_Add( p_input->p_es_out, &p_sys->fmt_video );
- p_sys->p_es_audio = es_out_Add( p_input->p_es_out, &p_sys->fmt_audio );
+ p_demux->pf_demux = Demux;
+ p_demux->pf_control = Control;
return VLC_SUCCESS;
}
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- demux_sys_t *p_sys = p_input->p_demux_data;
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys = p_demux->p_sys;
+ var_Destroy( p_demux, "rawdv-hurry-up");
free( p_sys );
}
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
-static int Demux( input_thread_t * p_input )
+static int Demux( demux_t *p_demux )
{
- demux_sys_t *p_sys = p_input->p_demux_data;
- block_t *p_block;
- vlc_bool_t b_audio, b_video;
-
+ demux_sys_t *p_sys = p_demux->p_sys;
+ block_t *p_block;
+ bool b_audio = false;
- if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
+ if( p_sys->b_hurry_up )
{
- off_t i_pos = stream_Tell( p_input->s );
-
- msg_Warn( p_input, "synchro reinit" );
-
- /* If the user tried to seek in the stream, we need to make sure
- * the new position is at a DIF block boundary. */
- if( i_pos % p_sys->frame_size > 0 )
- {
- i_pos += p_sys->frame_size - i_pos % p_sys->frame_size;
-
- if( stream_Seek( p_input->s, i_pos ) )
- {
- msg_Warn( p_input, "cannot resynch after seek (EOF?)" );
- return -1;
- }
- }
+ /* 3 frames */
+ p_sys->i_pcr = mdate() + (p_sys->i_dsf ? 120000 : 90000);
}
/* Call the pace control */
- input_ClockManageRef( p_input, p_input->stream.p_selected_program,
- p_sys->i_pcr );
-
- if( ( p_block = stream_Block( p_input->s, p_sys->frame_size ) ) == NULL )
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
+ p_block = stream_Block( p_demux->s, p_sys->frame_size );
+ if( p_block == NULL )
{
/* EOF */
return 0;
}
- es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE,
- p_sys->p_es_audio, &b_audio );
- es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE,
- p_sys->p_es_video, &b_video );
+ if( p_sys->p_es_audio )
+ {
+ es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
+ p_sys->p_es_audio, &b_audio );
+ }
p_block->i_dts =
- p_block->i_pts = input_ClockGetTS( p_input,
- p_input->stream.p_selected_program,
- p_sys->i_pcr );
- if( b_audio && b_video )
- {
- block_t *p_dup = block_Duplicate( p_block );
+ p_block->i_pts = VLC_TS_0 + p_sys->i_pcr;
- es_out_Send( p_input->p_es_out, p_sys->p_es_video, p_block );
- if( p_dup )
- {
- es_out_Send( p_input->p_es_out, p_sys->p_es_video, p_dup );
- }
- }
- else if( b_audio )
- {
- es_out_Send( p_input->p_es_out, p_sys->p_es_audio, p_block );
- }
- else if( b_video )
+ if( b_audio )
{
- es_out_Send( p_input->p_es_out, p_sys->p_es_video, p_block );
+ block_t *p_audio_block = dv_extract_audio( p_block );
+ if( p_audio_block )
+ es_out_Send( p_demux->out, p_sys->p_es_audio, p_audio_block );
}
- else
+
+ es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
+
+ if( !p_sys->b_hurry_up )
{
- block_Release( p_block );
+ p_sys->i_pcr += ( INT64_C(1000000) / p_sys->f_rate );
}
- p_sys->i_pcr += ( 90000 / p_sys->f_rate );
-
return 1;
}
+/*****************************************************************************
+ * Control:
+ *****************************************************************************/
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ /* XXX: DEMUX_SET_TIME is precise here */
+ return demux_vaControlHelper( p_demux->s,
+ 0, -1,
+ p_sys->frame_size * p_sys->f_rate * 8,
+ p_sys->frame_size, i_query, args );
+}
+