+/*****************************************************************************
+ * CDDARead: Handler for audio control reads the CD-DA.
+ *****************************************************************************/
+static ssize_t
+CDDARead( access_t * p_access, uint8_t *p_buffer, size_t i_len )
+{
+ cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
+
+ dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
+ "called lsn: %d pos: %lld, size: %lld",
+ p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
+
+ /* Check end of file */
+ if( p_access->info.b_eof )
+ return 0;
+
+ {
+ lsn_t i_lsn = get_audio_position(p_access);
+ if( CDIO_INVALID_LSN == i_lsn )
+ {
+ dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
+ memset( p_buffer, 0, i_len );
+ return i_len;
+ }
+
+ p_cdda->i_lsn = i_lsn;
+ p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
+ }
+
+ dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
+
+ /* Check end of track */
+ while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
+ p_cdda->i_track) )
+ {
+ if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
+ {
+ dbg_print( (INPUT_DBG_LSN), "EOF");
+ p_access->info.b_eof = true;
+ return 0;
+ }
+ p_access->info.i_update |= INPUT_UPDATE_TITLE;
+ p_access->info.i_title++;
+ p_cdda->i_track++;
+
+ if( p_cdda-> b_nav_mode )
+ {
+ char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
+ input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
+ free( psz_title );
+ }
+ else
+ {
+ p_access->info.i_size =
+ p_cdda->p_title[p_access->info.i_title]->i_size;
+ p_access->info.i_pos = 0;
+ p_access->info.i_update |= INPUT_UPDATE_SIZE;
+ }
+ }
+ memset( p_buffer, 0, i_len );
+ return i_len;
+}
+
+/*! Pause CD playing via audio control */
+static bool cdda_audio_pause( CdIo_t *p_cdio )
+{
+ bool b_ok = true;
+#if LIBCDIO_VERSION_NUM >= 73
+ cdio_subchannel_t sub;
+
+ if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
+ {
+ if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
+ {
+ b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
+ }
+ }
+ else
+ b_ok = false;
+#endif
+ return b_ok;
+}
+
+#if LIBCDIO_VERSION_NUM >= 73
+/*! play CD using audio controls */
+static driver_return_code_t
+cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
+{
+ msf_t start_msf;
+ msf_t last_msf;
+ cdio_lsn_to_msf( start_lsn, &start_msf );
+ cdio_lsn_to_msf( end_lsn, &last_msf );
+ cdda_audio_pause( p_cdio );
+ return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
+}
+#endif
+