コード例 #1
0
ファイル: dvd_reader.c プロジェクト: zoominla/mplayer-ww
/* This is using a single input and starting from 'dvd_file->lb_start' offset.
 *
 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
 * into the buffer located at 'data' and if 'encrypted' is set
 * descramble the data if it's encrypted.  Returning either an
 * negative error or the number of blocks read. */
static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
                             size_t block_count, unsigned char *data,
                             int encrypted )
{
  return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset,
                           block_count, data, encrypted );
}
コード例 #2
0
ファイル: dvd_reader.c プロジェクト: zoominla/mplayer-ww
int DVDISOVolumeInfo( dvd_reader_t *dvd,
                      char *volid, unsigned int volid_size,
                      unsigned char *volsetid, unsigned int volsetid_size )
{
  unsigned char *buffer, *buffer_base;
  int ret;

  /* Check arguments. */
  if( dvd == NULL )
    return 0;

  if( dvd->dev == NULL ) {
    /* No block access, so no ISO... */
    return -1;
  }

  buffer_base = malloc( DVD_VIDEO_LB_LEN + 2048 );
  buffer = (unsigned char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);

  if( buffer_base == NULL ) {
    fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
             "allocate memory for file read!\n" );
    return -1;
  }

  ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
  if( ret != 1 ) {
    fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
             "read ISO9660 Primary Volume Descriptor!\n" );
    free( buffer_base );
    return -1;
  }

  if( (volid != NULL) && (volid_size > 0) ) {
    unsigned int n;
    for(n = 0; n < 32; n++) {
      if(buffer[40+n] == 0x20) {
        break;
      }
    }

    if(volid_size > n+1) {
      volid_size = n+1;
    }

    memcpy(volid, &buffer[40], volid_size-1);
    volid[volid_size-1] = '\0';
  }

  if( (volsetid != NULL) && (volsetid_size > 0) ) {
    if(volsetid_size > 128) {
      volsetid_size = 128;
    }
    memcpy(volsetid, &buffer[190], volsetid_size);
  }
  free( buffer_base );
  return 0;
}
コード例 #3
0
ファイル: dvd_udf.c プロジェクト: DragonStalker/mythtv
/* It's required to either fail or deliver all the blocks asked for. */
static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number,
                         size_t block_count, unsigned char *data,
                         int encrypted )
{
  int ret;
  size_t count = block_count;

  while(count > 0) {

    ret = UDFReadBlocksRaw(device, lb_number, count, data, encrypted);

    if(ret <= 0) {
      /* One of the reads failed or nothing more to read, too bad.
       * We won't even bother returning the reads that went ok. */
      return ret;
    }

    count -= (size_t)ret;
    lb_number += (uint32_t)ret;
  }

  return block_count;
}
コード例 #4
0
ファイル: dvd_reader.c プロジェクト: batman52/dingux-code
int DVDISOVolumeInfo( dvd_reader_t *dvd,
                      char *volid, unsigned int volid_size,
                      unsigned char *volsetid, unsigned int volsetid_size )
{
  unsigned char *buffer; /* must be aligned to 2048 for raw/O_DIRECT */
  unsigned char *buffer_start; 
  int ret;

  /* Check arguments. */
  if( dvd == NULL ) {
    errno = EINVAL;
    return -1;
  }
  
  if( dvd->dev == NULL ) {
    /* No block access, so no ISO... */
    errno = EINVAL;
    return -1;
  }
  
  buffer_start = malloc( 2 * DVD_VIDEO_LB_LEN );
  if( buffer_start == NULL ) {
    return -1;
  }

  buffer = DVD_ALIGN(buffer_start);
  
  ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
  if( ret != 1 ) {
    if(dvd->verbose >= 1) {
      fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
               "read ISO9660 Primary Volume Descriptor!\n" );
    }
    free(buffer_start);
    return -1;
  }
  
  if( (volid != NULL) && (volid_size > 0) ) {
    unsigned int n;
    for(n = 0; n < 32; n++) {
      if(buffer[40+n] == 0x20) {
        break;
      }
    }
    
    if(volid_size > n+1) {
      volid_size = n+1;
    }

    memcpy(volid, &buffer[40], volid_size-1);
    volid[volid_size-1] = '\0';
  }
  
  if( (volsetid != NULL) && (volsetid_size > 0) ) {
    if(volsetid_size > 128) {
      volsetid_size = 128;
    }
    memcpy(volsetid, &buffer[190], volsetid_size);
  }
  free(buffer_start);

  return 0;
}
コード例 #5
0
ファイル: dvdstream.cpp プロジェクト: JGunning/OpenAOL-TV
//virtual
int DVDStream::safe_read(void *data, uint size)
{
    uint32_t lb = size / DVD_VIDEO_LB_LEN;
    if (lb < 1)
    {
        LOG(VB_GENERAL, LOG_ERR, "DVDStream::safe_read too small");
        return -1;
    }

    if (!m_reader)
        return -1;

    int ret = 0;

    // Are any blocks in the range encrypted?
    list_t::const_iterator it = qBinaryFind(m_list, BlockRange(m_pos, lb, -1));
    uint32_t b = it == m_list.end() ? lb : m_pos < it->Start() ? it->Start() - m_pos : 0;
    if (b)
    {
        // Read the beginning unencrypted blocks
        ret = UDFReadBlocksRaw(m_reader, m_pos, b, (unsigned char*)data, DVDINPUT_NOFLAGS);
        if (ret == -1)
        {
            LOG(VB_GENERAL, LOG_ERR, "DVDStream::safe_read DVDReadBlocks error");
            return -1;
        }

        m_pos += ret;
        lb -= ret;
        if (it == m_list.end())
            return ret * DVD_VIDEO_LB_LEN;

        data = (unsigned char*)data + ret * DVD_VIDEO_LB_LEN;
    }

    b = it->End() - m_pos;
    if (b > lb)
        b = lb;

    // Request new key if change in title
    int flags = DVDINPUT_READ_DECRYPT;
    if (it->Title() != m_title)
    {
        m_title = it->Title();
        flags |= DVDCSS_SEEK_KEY;
    }

    // Read the encrypted blocks
    int ret2 = UDFReadBlocksRaw(m_reader, m_pos + m_start, b, (unsigned char*)data, flags);
    if (ret2 == -1)
    {
        LOG(VB_GENERAL, LOG_ERR, "DVDStream::safe_read DVDReadBlocks error");
        m_title = -1;
        return -1;
    }

    m_pos += ret2;
    ret += ret2;
    lb -= ret2;
    data = (unsigned char*)data + ret2 * DVD_VIDEO_LB_LEN;

    if (lb > 0 && m_start == 0)
    {
        // Read the last unencrypted blocks
        ret2 = UDFReadBlocksRaw(m_reader, m_pos, lb, (unsigned char*)data, DVDINPUT_NOFLAGS);
        if (ret2 == -1)
        {
            LOG(VB_GENERAL, LOG_ERR, "DVDStream::safe_read DVDReadBlocks error");
            return -1;
        }

        m_pos += ret2;
        ret += ret2;;
    }

    return ret * DVD_VIDEO_LB_LEN;
}