Esempio n. 1
0
int
dts_reader_c::probe_file(mm_io_c *in,
                         uint64_t size,
                         bool strict_mode) {
  if (size < READ_SIZE)
    return 0;

  try {
    auto chunks         = scan_chunks(*in);
    auto strmdata_chunk = brng::find_if(chunks, [](chunk_t const &chunk) { return chunk.type == chunk_type_e::strmdata; });
    if (strmdata_chunk == chunks.end())
      return 0;

    unsigned char buf[READ_SIZE];
    auto bytes_to_read = std::min<uint64_t>(strmdata_chunk->data_size, READ_SIZE);

    in->setFilePointer(strmdata_chunk->data_start, seek_beginning);
    if (in->read(buf, bytes_to_read) != bytes_to_read)
      return 0;

    bool convert_14_to_16 = false, swap_bytes = false;
    if (!strict_mode && mtx::dts::detect(buf, READ_SIZE, convert_14_to_16, swap_bytes))
      return 1;

    int pos = mtx::dts::find_consecutive_headers(buf, READ_SIZE, 5);
    if ((!strict_mode && (0 <= pos)) || (strict_mode && (0 == pos)))
      return 1;

  } catch (...) {
  }

  return 0;
}
Esempio n. 2
0
dts_reader_c::dts_reader_c(const track_info_c &ti,
                           const mm_io_cptr &in)
  : generic_reader_c(ti, in)
  , m_af_buf(memory_c::alloc(2 * READ_SIZE))
  , m_cur_buf(0)
  , m_dts14_to_16(false)
  , m_swap_bytes(false)
  , m_debug{"dts|dts_reader"}
  , m_codec{codec_c::look_up(codec_c::type_e::A_DTS)}
  , m_chunks{scan_chunks(*in)}
  , m_current_chunk{brng::find_if(m_chunks, [](chunk_t const &chunk) { return chunk.type == chunk_type_e::strmdata; })}
{
  m_buf[0] = reinterpret_cast<unsigned short *>(m_af_buf->get_buffer());
  m_buf[1] = reinterpret_cast<unsigned short *>(m_af_buf->get_buffer() + READ_SIZE);
}
Esempio n. 3
0
void
wav_reader_c::parse_file() {
  int chunk_idx;

  if (m_in->read(&m_wheader.riff, sizeof(m_wheader.riff)) != sizeof(m_wheader.riff))
    throw mtx::input::header_parsing_x();

  scan_chunks();

  if ((chunk_idx = find_chunk("fmt ")) == -1)
    throw mtx::input::header_parsing_x();

  m_in->setFilePointer(m_chunks[chunk_idx].pos, seek_beginning);

  try {
    if (m_in->read(&m_wheader.format, sizeof(m_wheader.format)) != sizeof(m_wheader.format))
      throw false;

    if (static_cast<uint64_t>(m_chunks[chunk_idx].len) >= sizeof(alWAVEFORMATEXTENSIBLE)) {
      alWAVEFORMATEXTENSIBLE format;
      if (m_in->read(&format, sizeof(format)) != sizeof(format))
        throw false;
      memcpy(&m_wheader.common, &format, sizeof(m_wheader.common));

      m_format_tag = get_uint16_le(&m_wheader.common.wFormatTag);
      if (0xfffe == m_format_tag)
        m_format_tag = get_uint32_le(&format.extension.guid.data1);

    } else if (m_in->read(&m_wheader.common, sizeof(m_wheader.common)) != sizeof(m_wheader.common))
      throw false;

    else
      m_format_tag = get_uint16_le(&m_wheader.common.wFormatTag);

  } catch (...) {
    throw mtx::input::header_parsing_x();
  }

  if ((m_cur_data_chunk_idx = find_chunk("data", 0, false)) == -1)
    throw mtx::input::header_parsing_x();

  if (debugging_c::requested("wav_reader|wav_reader_headers"))
    dump_headers();

  m_in->setFilePointer(m_chunks[m_cur_data_chunk_idx].pos + sizeof(struct chunk_struct), seek_beginning);

  m_remaining_bytes_in_current_data_chunk = m_chunks[m_cur_data_chunk_idx].len;
}