~ubuntu-branches/ubuntu/trusty/dvd95/trusty

« back to all changes in this revision

Viewing changes to src/dvdtools.c

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-11-10 08:33:32 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071110083332-pry0uz9nx4u1s1xz
Tags: 1.3p0-0ubuntu1
* New upstream release.
* debian/control:
  - Move homepage to Homepage field.
  - Comply with DebianMaintainerField.
  - Build-Depend on libmpeg-2-4-dev.
* debian/rules: Check if Makefile exists before cleaning, rather than
  ignoring all errors.
* Fix up .desktop:
  - debian/rules: Use dpatch.
  - debian/control: Build-Depend on dpatch.
  - debian/patches/01_fix_desktop_file.dpatch: Convince dvd95.desktop to
    comply with .desktop file standards.
* Add debian/watch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <gnome.h>
25
25
 
26
26
#define CTEST(x)                /***/
 
27
#define CTEST2(x)               /***/
27
28
 
28
29
#include "dvdinfo.h"
29
30
#include "dvdtools.h"
30
31
#include "message.h"
31
32
#include "globals.h"
32
33
#include "uitools.h"
33
 
 
34
 
static int BadStart = -1;
35
 
static int BadEnd = -1;
 
34
#include "ac.h"
 
35
#include "badsect.h"
36
36
 
37
37
static double FramesPerSec[4] = { -1.0, 25.00, -1.0, 29.97 };
38
 
static char * _AudioFormat[7] = { "ac3", "?", "mpeg1", "mpeg2", "lpcm ", "sdds ", "dts" };
 
38
static char * _AudioFormat[7] = { "ac3", "?", "mpeg1", "mpeg2", "lpcm", "sdds ", "dts" };
39
39
 
40
40
#define MAX_PISTE               100
41
41
static Piste_t  Pistes[MAX_PISTE];
307
307
//!!    if( (audio_attr->channels + 1) == 6 )   return( "dts" );
308
308
        return( _AudioFormat[audio_attr->audio_format] );
309
309
}
310
 
/*------------------------------------------------------------------------------
311
 
        FINDNEXTGOODSECTOR-
312
 
Linux!jef 2006/07/07 20:49:13
313
 
------------------------------------------------------------------------------*/
314
 
 
315
 
static int FindNextGoodSector( dvd_file_t * dvdFile, int noSect, int lim )
316
 
{
317
 
        char buffer[DVD_VIDEO_LB_LEN];
318
 
        int bMax;
319
 
        int next;
320
 
        int res;
321
 
 
322
 
        if( lim < 1000 )        lim = 1000;
323
 
        bMax = noSect + lim;
324
 
 
325
 
        CTEST(fprintf(stderr,"Testing <%d,%d>\n", noSect, bMax ););
326
 
        while( (bMax - noSect) > 1 ) {
327
 
                next = noSect + (( bMax - noSect ) / 2);
328
 
 
329
 
                res = DVDReadBlocks( dvdFile, next, 1, (unsigned char *)buffer );
330
 
                if( res == 1 ) {
331
 
                        CTEST(fprintf(stderr,"sector %d good\n", next ););
332
 
                        bMax = next;
333
 
                }
334
 
                else {
335
 
                        CTEST(fprintf(stderr,"sector %d bad\n", next ););
336
 
                        noSect = next;
337
 
                }
338
 
        }
339
 
        CTEST(fprintf(stderr,"NextGood: %d\n", bMax ););
340
 
        return( bMax );
341
 
}
342
 
 
343
 
/*------------------------------------------------------------------------------
344
 
        MYDVDREADBLOCKS-
 
310
 
 
311
/*------------------------------------------------------------------------------
 
312
        MYDVDREAD1BLOCK-
345
313
Linux!jef 2006/07/06 22:04:04
 
314
        Special for dvd errors handling
346
315
------------------------------------------------------------------------------*/
347
 
 
348
 
ssize_t MyDVDReadBlocks( dvd_file_t * dvdFile, int noSect, size_t nbSect, unsigned char * buffer )
 
316
int MyDVDRead1Block( dvd_file_t * dvdFile, int noSect, void * buffer )
349
317
{
350
318
        ssize_t nbRead;
351
319
 
352
 
        CTEST(fprintf(stderr,"Reading(%d,%ld) (%d,%d)\n", noSect, nbSect, BadStart, BadEnd ););
353
 
        if( (noSect >= BadStart) && (int)(noSect+nbSect) <= BadEnd ) {
354
 
                memset( buffer, 0, DVD_VIDEO_LB_LEN * nbSect );
355
 
                return( nbSect );
356
 
        }
357
 
        nbRead = DVDReadBlocks( dvdFile, noSect, nbSect, buffer );
358
 
        CTEST(fprintf(stderr,"Readed:=%ld\n", nbRead ););
359
 
        if( nbRead < 0 ) {
360
 
                nbRead = 0;
361
 
        }
362
 
        else {
363
 
                BadStart = BadEnd = -1;
364
 
        }
365
 
        noSect += nbRead;
366
 
        nbSect -= nbRead;
367
 
        buffer += ( nbRead * DVD_VIDEO_LB_LEN );
368
 
        if( !nbSect )   return( nbRead );
369
 
        if( IgnoreErrors == -1 ) {
370
 
                int res = MessageBoxYesNo( _("Erreur de lecture ! Ignorer les erreurs ?" ) );
371
 
                if( res == 1 )
372
 
                        IgnoreErrors = 1;
373
 
                else
374
 
                        IgnoreErrors = 0;
375
 
        }
376
 
        if( !IgnoreErrors )     return( -1 );
377
 
        CTEST(fprintf(stderr,"ReadError: nbSect=%ld\n", nbSect ););
378
 
/* En cas d'erreur de  lecture on suppose que c'est un plage complete qui est HS pour eviter
379
 
        de prendre trop de temps avec des lectures unitaires
380
 
*/
381
 
        BadStart = noSect;
382
 
        BadEnd = FindNextGoodSector( dvdFile, noSect, nbSect + 1 );
383
 
 
384
 
        return( nbRead + MyDVDReadBlocks( dvdFile, noSect, nbSect, buffer ) );
385
 
#if 0
386
 
 
387
 
        if( nbSect == 1 ) {
388
 
                memset( buffer, 0, DVD_VIDEO_LB_LEN );
389
 
                return( 1 );
390
 
        }
391
 
        while( nbSect > 0 ) {
392
 
                ssize_t res;
393
 
 
394
 
                res = DVDReadBlocks( dvdFile, noSect, 1, buffer );
395
 
                if( res != 1 ) {
396
 
fprintf(stderr,"ReadError: Sector=%d zeroed\n", noSect );
397
 
                        memset( buffer, 0, DVD_VIDEO_LB_LEN );
398
 
                }
399
 
                else {
400
 
fprintf(stderr,"ReadError: Sector=%d readed\n", noSect );
401
 
                }
402
 
                noSect += 1;
403
 
                nbSect -= 1;
404
 
                buffer += ( 1 * DVD_VIDEO_LB_LEN );
405
 
                nbRead += 1;
406
 
        }
407
 
        return( nbRead );
 
320
        CTEST2(fprintf(stderr,"%s: Reading(%d) at %p\n", __FUNCTION__, noSect, buffer ););
 
321
#if MNG_BADSECTORS
 
322
        if( IsBadSector( noSect ) )     return( 0 );
408
323
#endif
 
324
        nbRead = DVDReadBlocks( dvdFile, noSect, 1, buffer );
 
325
        CTEST2(fprintf(stderr,"%s: Readed:=%ld\n", __FUNCTION__, nbRead ););
 
326
        if( nbRead != 1 ) {
 
327
                DBG('b',fprintf(stderr,"%s: bad sector: %d\n", __FUNCTION__, noSect ););
 
328
                NoteBadSector( noSect );
 
329
                if( IgnoreErrors == -1 ) {
 
330
                        int res = MessageBoxYesNo( _("Erreur de lecture ! Ignorer les erreurs ?" ) );
 
331
                        if( res == 1 )
 
332
                                IgnoreErrors = 1;
 
333
                        else
 
334
                                IgnoreErrors = 0;
 
335
                        GtkFlush();
 
336
                }
 
337
                if( IgnoreErrors )      return( 0 );
 
338
                return( -1 );
 
339
        }
 
340
        return( 1 );
409
341
}
410
342
 
411
343
/*------------------------------------------------------------------------------
426
358
{
427
359
        memset( &Pistes, 0, sizeof(Pistes));
428
360
}
 
361
/*------------------------------------------------------------------------------
 
362
        CREATEDUMMYPACK-
 
363
Linux!jef 2007/08/16 00:41:38
 
364
------------------------------------------------------------------------------*/
 
365
 
 
366
void CreateDummyPack( unsigned char * buffer )
 
367
{
 
368
        int8_t *ptr = (int8_t*)buffer;
 
369
#pragma pack(1)
 
370
        uint8_t dummy_pack [] =
 
371
        {
 
372
            /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */
 
373
            0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8,
 
374
            /* PES header for dummy video packet */
 
375
            0, 0, 1, 0xe0, 0x07, 0xec, 0x81, 0x00, 0x00
 
376
        };
 
377
#pragma pack()
 
378
        tc_memcpy( ptr, dummy_pack, sizeof (dummy_pack));
 
379
        ptr += sizeof (dummy_pack);
 
380
        memset( ptr, 0xff, DVD_VIDEO_LB_LEN - sizeof (dummy_pack));
 
381
}
 
382
 
 
383
/*------------------------------------------------------------------------------
 
384
        CREATEDUMMYNAVPACK-
 
385
Linux!jef 2007/08/16 00:43:54
 
386
------------------------------------------------------------------------------*/
 
387
 
 
388
void CreateDummyNavPack( unsigned char * buffer, unsigned int sector )
 
389
{
 
390
        int8_t *ptr = (int8_t*)buffer;
 
391
        dsi_t dsiPack;
 
392
        pci_t pciPack;
 
393
#pragma pack(1)
 
394
        static uint8_t nav_pack1 [] =
 
395
        {
 
396
            /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */
 
397
            0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8,
 
398
            /* system header length=0x12=18*/
 
399
            0, 0, 1, 0xbb, 0x00, 0x12,
 
400
            /* contents of system header filled in at run time (18 bytes) */
 
401
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
402
            /* PES header for first private stream 2 packet */
 
403
            0, 0, 1, 0xbf, 0x03, 0xd4
 
404
          };
 
405
        static uint8_t nav_pack2 [] =
 
406
        {
 
407
            /* PES header for second private stream 2 packet */
 
408
            0, 0, 1, 0xbf, 0x03, 0xfa
 
409
        };
 
410
#pragma pack()
 
411
        tc_memcpy( ptr, nav_pack1, sizeof (nav_pack1));
 
412
        ptr += sizeof (nav_pack1);
 
413
        memset( ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack1));
 
414
        ptr = (int8_t*)buffer + DVD_VIDEO_LB_LEN/2;
 
415
        tc_memcpy( ptr, nav_pack2, sizeof (nav_pack2));
 
416
        ptr += sizeof (nav_pack2);
 
417
        memset( ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack2));
 
418
 
 
419
        navRead_DSI( &dsiPack, buffer + DSI_START_BYTE);
 
420
        navRead_PCI( &pciPack, buffer+0x2d);
 
421
        dsiPack.dsi_gi.nv_pck_lbn= sector;
 
422
        dsiPack.dsi_gi.vobu_ea = 1;
 
423
 
 
424
        navRead_DSI((dsi_t*)(buffer + DSI_START_BYTE),(unsigned char*)&dsiPack);
 
425
        pciPack.pci_gi.nv_pck_lbn = dsiPack.dsi_gi.nv_pck_lbn;
 
426
        navRead_PCI((pci_t*)(buffer+0x2d),(unsigned char*)&pciPack);
 
427
}
 
428
/*------------------------------------------------------------------------------
 
429
        VERIFNAVPACK-
 
430
Linux!jef 2007/08/22 22:35:53
 
431
------------------------------------------------------------------------------*/
 
432
 
 
433
int VerifNavPack( unsigned char * p )
 
434
{
 
435
        int32_t        bMpeg1 = 0;
 
436
        uint32_t       nHeaderLen;
 
437
        uint32_t       nPacketLen;
 
438
        uint32_t       nStreamID;
 
439
 
 
440
        if (p[3] == 0xBA) { /* program stream pack header */
 
441
                int32_t nStuffingBytes;
 
442
 
 
443
                bMpeg1 = (p[4] & 0x40) == 0;
 
444
 
 
445
                if (bMpeg1) {
 
446
                        p += 12;
 
447
                } else { /* mpeg2 */
 
448
                        nStuffingBytes = p[0xD] & 0x07;
 
449
                        p += 14 + nStuffingBytes;
 
450
                }
 
451
        }
 
452
 
 
453
        if (p[3] == 0xbb) { /* program stream system header */
 
454
                nHeaderLen = (p[4] << 8) | p[5];
 
455
                p += 6 + nHeaderLen;
 
456
        }
 
457
 
 
458
/* we should now have a PES packet here */
 
459
        if (p[0] || p[1] || (p[2] != 1)) {
 
460
                fprintf(stderr, "%s: demux error! %02x %02x %02x (should be 0x000001) \n",__FUNCTION__,p[0],p[1],p[2]);
 
461
                return( 0 );
 
462
        }
 
463
 
 
464
        nPacketLen = p[4] << 8 | p[5];
 
465
        nStreamID  = p[3];
 
466
 
 
467
        nHeaderLen = 6;
 
468
        p += nHeaderLen;
 
469
 
 
470
        if (nStreamID == 0xbf) { /* Private stream 2 */
 
471
//              if(p[0] == 0x00)        navRead_PCI(nav_pci, p+1);
 
472
                p += nPacketLen;
 
473
        /* We should now have a DSI packet. */
 
474
                if(p[6] == 0x01) {
 
475
                        nPacketLen = p[4] << 8 | p[5];
 
476
                        p += 6;
 
477
//                      navRead_DSI(nav_dsi, p+1);
 
478
                }
 
479
                return( 1 );
 
480
        }
 
481
        fprintf(stderr,"%s: bad streamid 0x%x\n", __FUNCTION__, nStreamID );
 
482
        return( 0 );
 
483
}
 
484