summaryrefslogtreecommitdiffstats
path: root/HBDVDReader.cpp
blob: 2027da7e66ecc67e3c86e53b2d24180b883670cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* $Id: HBDVDReader.cpp,v 1.7 2003/08/12 20:10:50 titer Exp $ */

#include "HBCommon.h"
#include "HBDVDReader.h"
#include "HBManager.h"
#include "HBFifo.h"

#include <Application.h>

#include <dvdread/ifo_types.h>
#include <dvdplay/dvdplay.h>
#include <dvdplay/info.h>
#include <dvdplay/state.h>
#include <dvdplay/nav.h>

HBDVDReader::HBDVDReader( HBManager * manager,
                          HBTitleInfo * titleInfo )
    : HBThread( "dvdreader", B_NORMAL_PRIORITY )
{
    fManager   = manager;
    fTitleInfo = titleInfo;
}

void HBDVDReader::DoWork()
{
    /* Open the device */
    dvdplay_ptr vmg;
    vmg = dvdplay_open( fTitleInfo->fDevice, NULL, NULL );
    if( !vmg )
    {
        Log( "HBDVDReader: dvdplay_open() failed" );
        fManager->Error();
        return;
    }
    
    /* Open the title */
    dvdplay_start( vmg, fTitleInfo->fIndex );
    
    /* Read */
    HBBuffer * dvdBuffer;
    int        beginPosition = dvdplay_position( vmg );
    int        endPosition   = dvdplay_title_end( vmg );
    while( dvdplay_position( vmg ) < endPosition )
    {
        dvdBuffer = new HBBuffer( DVD_VIDEO_LB_LEN );
        dvdBuffer->fPosition = (float) ( dvdplay_position( vmg ) - beginPosition ) /
                               (float) ( endPosition - beginPosition ) ;

        if( dvdplay_read( vmg, dvdBuffer->fData, 1 ) < 0 )
        {
            Log( "HBDVDReader: could not dvdplay_read()" );
            delete dvdBuffer;
            fManager->Error();
            break;
        }
        if( !( fTitleInfo->fPSFifo->Push( dvdBuffer ) ) )
        {
            break;
        }
    }
    
    if( dvdplay_position( vmg ) == dvdplay_title_end( vmg ) )
        fManager->Done();
    
    /* Clean up */
    dvdplay_close( vmg );
}