- if ( i_len % CDIO_CD_FRAMESIZE_RAW ) /* this should not happen */
- {
- msg_Err( p_input, "must read full sectors" );
- }
-
- return i_read;
-}
-
-/*****************************************************************************
- * CDDASetProgram: Does nothing since a CDDA is mono_program
- *****************************************************************************/
-static int CDDASetProgram( input_thread_t * p_input,
- pgrm_descriptor_t * p_program)
-{
- cdda_data_t * p_cdda= (cdda_data_t *) p_input->p_access_data;
- dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
- return 0;
-}
-
-/*****************************************************************************
- * CDDASetArea: initialize input data for title x.
- * It should be called for each user navigation request.
- ****************************************************************************/
-static int CDDASetArea( input_thread_t * p_input, input_area_t * p_area )
-{
- cdda_data_t *p_cdda = (cdda_data_t*) p_input->p_access_data;
- vlc_value_t val;
-
- dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "");
-
- /* we can't use the interface slider until initilization is complete */
- p_input->stream.b_seekable = 0;
-
- if( p_area != p_input->stream.p_selected_area )
- {
- /* Change the default area */
- p_input->stream.p_selected_area = p_area;
-
- /* Change the current track */
- p_cdda->i_track = p_area->i_id - 1;
- p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track];
-
- /* Update the navigation variables without triggering a callback */
- val.i_int = p_area->i_id;
- var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
- }
-
- p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track];
-
- p_input->stream.p_selected_area->i_tell =
- (off_t)p_cdda->i_sector * (off_t)CDIO_CD_FRAMESIZE_RAW
- - p_input->stream.p_selected_area->i_start;
-
- /* warn interface that something has changed */
- p_input->stream.b_seekable = 1;
- p_input->stream.b_changed = 1;
-
- return 0;
-}
-
-/****************************************************************************
- * CDDASeek
- ****************************************************************************/
-static void CDDASeek( input_thread_t * p_input, off_t i_off )
-{
- cdda_data_t * p_cdda;
-
- p_cdda = (cdda_data_t *) p_input->p_access_data;
-
- p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track]
- + i_off / (off_t)CDIO_CD_FRAMESIZE_RAW;
-
- vlc_mutex_lock( &p_input->stream.stream_lock );
- p_input->stream.p_selected_area->i_tell =
- (off_t)p_cdda->i_sector * (off_t)CDIO_CD_FRAMESIZE_RAW
- - p_input->stream.p_selected_area->i_start;
-
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
- "sector %ud, offset: %lld, i_tell: %lld", p_cdda->i_sector, i_off,
- p_input->stream.p_selected_area->i_tell );
-
-}
-
-/*****************************************************************************
- * Demux: local prototypes
- *****************************************************************************/
-struct demux_sys_t
-{
- es_out_id_t *p_es;
- mtime_t i_pts;
-};
-
-static int Demux ( input_thread_t * p_input );
-
-/****************************************************************************
- * DemuxOpen:
- ****************************************************************************/
-static int DemuxOpen ( vlc_object_t * p_this)
-{
- input_thread_t *p_input = (input_thread_t *)p_this;
- demux_sys_t *p_sys;
-
- es_format_t fmt;
-
- if( p_input->stream.i_method != INPUT_METHOD_CDDA )
- {
- return VLC_EGENERIC;
- }
-
- p_input->pf_demux = Demux;
- p_input->pf_rewind = NULL;
- p_input->pf_demux_control = demux_vaControlDefault;
- p_input->p_demux_data = p_sys = malloc( sizeof( es_descriptor_t ) );
- p_sys->i_pts = 0;
-
- 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;
- }
- p_input->stream.i_mux_rate = 4 * 44100 / 50;
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'a', 'r', 'a', 'w' ) );
- fmt.audio.i_channels = 2;
- fmt.audio.i_rate = 44100;
- fmt.audio.i_bitspersample = 16;
- fmt.audio.i_blockalign = 4;
- fmt.i_bitrate = 4 * 44100 * 8;
-
- p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt );
-
- return VLC_SUCCESS;
-}
-
-/****************************************************************************
- * DemuxClose:
- ****************************************************************************/
-static void DemuxClose( vlc_object_t * p_this)
-{
- input_thread_t *p_input = (input_thread_t*)p_this;
- demux_sys_t *p_sys = (demux_sys_t*)p_input->p_demux_data;
-
- free( p_sys );
- return;
-}
-
-/****************************************************************************
- * Demux:
- ****************************************************************************/
-static int Demux( input_thread_t * p_input )
-{
- demux_sys_t *p_sys = (demux_sys_t*)p_input->p_demux_data;
- block_t *p_block;
-
-
- input_ClockManageRef( p_input,
- p_input->stream.p_selected_program,
- p_sys->i_pts );
-
- if( ( p_block = stream_Block( p_input->s, CDIO_CD_FRAMESIZE_RAW ) ) == NULL )
- {
- /* eof */
- return 0;
- }
- p_block->i_dts =
- p_block->i_pts = input_ClockGetTS( p_input,
- p_input->stream.p_selected_program,
- p_sys->i_pts );
- p_block->i_length = (mtime_t)90000 * (mtime_t)p_block->i_buffer/44100/4;
-
- p_sys->i_pts += p_block->i_length;
-
- es_out_Send( p_input->p_es_out, p_sys->p_es, p_block );
-
- return 1;
-}
-
-/*****************************************************************************
- * OpenIntf: initialize dummy interface
- *****************************************************************************/
-int E_(OpenIntf) ( vlc_object_t *p_this )
-{
- intf_thread_t *p_intf = (intf_thread_t *)p_this;
-
- /* Allocate instance and initialize some members */
- p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
- if( p_intf->p_sys == NULL )
- {
- return( 1 );
- };
-
- p_intf->pf_run = RunIntf;
-
- var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
-
- return( 0 );
-}
-
-/*****************************************************************************
- * CloseIntf: destroy dummy interface
- *****************************************************************************/
-void E_(CloseIntf) ( vlc_object_t *p_this )
-{
- intf_thread_t *p_intf = (intf_thread_t *)p_this;
-
- /* Destroy structure */
- free( p_intf->p_sys );
-}
-
-
-/*****************************************************************************
- * RunIntf: main loop
- *****************************************************************************/
-static void RunIntf( intf_thread_t *p_intf )
-{
- vlc_object_t * p_vout = NULL;
- cdda_data_t * p_cdda;
- input_thread_t * p_input;
-
- /* What you add to the last input number entry. It accumulates all of
- the 10_ADD keypresses */
- int number_addend = 0;
-
- if( InitThread( p_intf ) < 0 )
- {
- msg_Err( p_intf, "can't initialize intf" );
- return;
- }
-
- p_input = p_intf->p_sys->p_input;
- p_cdda = p_intf->p_sys->p_cdda =
- (cdda_data_t *) p_input->p_access_data;
-
- dbg_print( INPUT_DBG_CALL, "intf initialized" );
-
- /* Main loop */
- while( !p_intf->b_die )
- {
- vlc_mutex_lock( &p_intf->change_lock );
-
- /*
- * keyboard event
- */
- if( p_vout && p_intf->p_sys->b_key_pressed )
- {
- vlc_value_t val;
- int i, i_action = -1;
- struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
-
- p_intf->p_sys->b_key_pressed = VLC_FALSE;
-
- /* Find action triggered by hotkey (if any) */
- var_Get( p_intf->p_vlc, "key-pressed", &val );
-
- dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
-
- for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
- {
- if( p_hotkeys[i].i_key == val.i_int )
- {
- i_action = p_hotkeys[i].i_action;
- }
- }
-
- if( i_action != -1) {
- switch (i_action) {
-
- case ACTIONID_NAV_LEFT:
- dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT (%d)",
- number_addend );
- do {
- if ( CDDAPlay( p_input, p_cdda->i_track-1 ) ) {
- p_cdda->i_track--;
- } else {
- break;
- }
- } while (number_addend-- > 0);
- break;
-
- case ACTIONID_NAV_RIGHT:
- dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT (%d)",
- number_addend );
- do {
- if ( CDDAPlay( p_input, p_cdda->i_track+1 ) ) {
- p_cdda->i_track++;
- } else {
- break;
- }
- } while (number_addend-- > 0);
- break;
-
- case ACTIONID_NAV_UP:
- dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP" );
- do {
- ;
- } while (number_addend-- > 0);
- break;
-
- case ACTIONID_NAV_DOWN:
- dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN" );
- break;
-
- case ACTIONID_NAV_ACTIVATE:
- {
- dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
- if ( CDDAPlay( p_input, number_addend ) ) {
- p_cdda->i_track = number_addend;
- } else {
- break;
- }
- break;
- }
- }
- number_addend = 0;
- } else {
- unsigned int digit_entered=0;
-
- switch (val.i_int) {
- case '9':
- digit_entered++;
- case '8':
- digit_entered++;
- case '7':
- digit_entered++;
- case '6':
- digit_entered++;
- case '5':
- digit_entered++;
- case '4':
- digit_entered++;
- case '3':
- digit_entered++;
- case '2':
- digit_entered++;
- case '1':
- digit_entered++;
- case '0':
- {
- number_addend *= 10;
- number_addend += digit_entered;
- dbg_print( INPUT_DBG_EVENT,
- "Added %d. Number is now: %d\n",
- digit_entered, number_addend);
- break;
- }
- }
- }
- }
-
-
- vlc_mutex_unlock( &p_intf->change_lock );
-
- if( p_vout == NULL )
- {
- p_vout = vlc_object_find( p_intf->p_sys->p_input,
- VLC_OBJECT_VOUT, FIND_ANYWHERE );
- if( p_vout )
- {
- var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
- }
- }
-
-
- /* Wait a bit */
- msleep( INTF_IDLE_SLEEP );
- }
-
- if( p_vout )
- {
- var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
- vlc_object_release( p_vout );
- }
-
- vlc_object_release( p_intf->p_sys->p_input );
-}
-
-/*****************************************************************************
- * InitThread:
- *****************************************************************************/
-static int InitThread( intf_thread_t * p_intf )
-{
- /* We might need some locking here */
- if( !p_intf->b_die )
- {
- input_thread_t * p_input;
-
- p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
-
- /* Maybe the input just died */
- if( p_input == NULL )
- {
- return VLC_EGENERIC;
- }
-
- vlc_mutex_lock( &p_intf->change_lock );
-
- p_intf->p_sys->p_input = p_input;
-
- p_intf->p_sys->b_move = VLC_FALSE;
- p_intf->p_sys->b_click = VLC_FALSE;
- p_intf->p_sys->b_key_pressed = VLC_FALSE;
-
- vlc_mutex_unlock( &p_intf->change_lock );
-
- return VLC_SUCCESS;
- }
- else
- {
- return VLC_EGENERIC;
- }
-}
-
-/*****************************************************************************
- * KeyEvent: callback for keyboard events
- *****************************************************************************/
-static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
- intf_thread_t *p_intf = (intf_thread_t *)p_data;
- vlc_mutex_lock( &p_intf->change_lock );