1 /* $Id: reader.c,v 1.21 2005/11/25 15:05:25 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
21 /***********************************************************************
23 **********************************************************************/
24 static void ReaderFunc( void * );
25 static hb_fifo_t
* GetFifoForId( hb_job_t
* job
, int id
);
27 /***********************************************************************
29 ***********************************************************************
31 **********************************************************************/
32 hb_thread_t
* hb_reader_init( hb_job_t
* job
)
36 r
= calloc( sizeof( hb_reader_t
), 1 );
39 r
->title
= job
->title
;
42 return hb_thread_init( "reader", ReaderFunc
, r
,
46 /***********************************************************************
48 ***********************************************************************
50 **********************************************************************/
51 static void ReaderFunc( void * _r
)
59 if( !( r
->dvd
= hb_dvd_init( r
->title
->dvd
) ) )
61 if ( !(r
->stream
= hb_stream_open(r
->title
->dvd
) ) )
69 if( !hb_dvd_start( r
->dvd
, r
->title
->index
, r
->job
->chapter_start
) )
71 hb_dvd_close( &r
->dvd
);
78 // At this point r->audios[0] gives us the index of the selected audio track for output track 0
79 // we cannot effectively demux multiple PID's into the seperate output tracks unfortunately
80 // so we'll just specifiy things here for a single track.
81 hb_stream_set_selected_audio_pid_index(r
->stream
, r
->job
->audios
[0]);
84 list
= hb_list_init();
85 r
->ps
= hb_buffer_init( HB_DVD_READ_BUFFER_SIZE
);
87 while( !*r
->die
&& !r
->job
->done
)
90 chapter
= hb_dvd_chapter( r
->dvd
);
96 hb_log( "reader: end of the title reached" );
99 if( chapter
> r
->job
->chapter_end
)
101 hb_log( "reader: end of chapter %d reached (%d)",
102 r
->job
->chapter_end
, chapter
);
108 if( !hb_dvd_read( r
->dvd
, r
->ps
) )
115 if ( !hb_stream_read( r
->stream
, r
->ps
) )
121 hb_demux_ps( r
->ps
, list
);
123 while( ( buf
= hb_list_item( list
, 0 ) ) )
125 hb_list_rem( list
, buf
);
126 fifo
= GetFifoForId( r
->job
, buf
->id
);
129 while( !*r
->die
&& !r
->job
->done
&&
130 hb_fifo_is_full( fifo
) )
134 hb_fifo_push( fifo
, buf
);
138 hb_buffer_close( &buf
);
143 hb_list_empty( &list
);
144 hb_buffer_close( &r
->ps
);
147 hb_dvd_stop( r
->dvd
);
148 hb_dvd_close( &r
->dvd
);
152 hb_stream_close(&r
->stream
);
158 hb_log( "reader: done" );
161 /***********************************************************************
163 ***********************************************************************
165 **********************************************************************/
166 static hb_fifo_t
* GetFifoForId( hb_job_t
* job
, int id
)
168 hb_title_t
* title
= job
->title
;
170 hb_subtitle_t
* subtitle
;
175 return job
->fifo_mpeg2
;
178 if (job
->subtitle_scan
) {
180 * Count the occurances of the subtitles, don't actually return any to encode.
182 for (i
=0; i
< hb_list_count(title
->list_subtitle
); i
++) {
183 subtitle
= hb_list_item( title
->list_subtitle
, i
);
184 if (id
== subtitle
->id
) {
192 if( ( subtitle
= hb_list_item( title
->list_subtitle
, 0 ) ) &&
195 return subtitle
->fifo_in
;
198 for( i
= 0; i
< hb_list_count( title
->list_audio
); i
++ )
200 audio
= hb_list_item( title
->list_audio
, i
);
201 if( id
== audio
->id
)
203 return audio
->fifo_in
;