예제 #1
0
파일: r_avi.cpp 프로젝트: VRDate/mkvtoolnix
file_status_e
avi_reader_c::read_audio(avi_demuxer_t &demuxer) {
  AVI_set_audio_track(m_avi, demuxer.m_aid);

  while (true) {
    int size = AVI_audio_size(m_avi, AVI_get_audio_position_index(m_avi));

    if (-1 == size)
      return flush_packetizer(demuxer.m_ptzr);

    if (!size) {
      AVI_set_audio_position_index(m_avi, AVI_get_audio_position_index(m_avi) + 1);
      continue;
    }

    auto chunk = memory_c::alloc(size);
    size       = AVI_read_audio_chunk(m_avi, reinterpret_cast<char *>(chunk->get_buffer()));

    if (0 >= size)
      continue;

    PTZR(demuxer.m_ptzr)->add_avi_block_size(size);
    PTZR(demuxer.m_ptzr)->process(new packet_t(chunk));

    m_bytes_processed += size;

    return AVI_get_audio_position_index(m_avi) < AVI_max_audio_chunk(m_avi) ? FILE_STATUS_MOREDATA : flush_packetizer(demuxer.m_ptzr);
  }
}
예제 #2
0
file_status_e
avi_reader_c::read_audio(avi_demuxer_t &demuxer) {
  AVI_set_audio_track(m_avi, demuxer.m_aid);

  while (true) {
    int size = AVI_audio_size(m_avi, AVI_get_audio_position_index(m_avi));

    // -1 indicates the last chunk.
    if (-1 == size)
      return flush_packetizer(demuxer.m_ptzr);

    // Sanity check. Ignore chunks with obvious wrong size information
    // (> 10 MB). Also skip 0-sized blocks. Those are officially
    // skipped.
    if (!size || (size > AVI_MAX_AUDIO_CHUNK_SIZE)) {
      AVI_set_audio_position_index(m_avi, AVI_get_audio_position_index(m_avi) + 1);
      continue;
    }

    auto chunk = memory_c::alloc(size);
    size       = AVI_read_audio_chunk(m_avi, reinterpret_cast<char *>(chunk->get_buffer()));

    if (0 >= size)
      continue;

    PTZR(demuxer.m_ptzr)->process(new packet_t(chunk));

    m_bytes_processed += size;

    return AVI_get_audio_position_index(m_avi) < AVI_max_audio_chunk(m_avi) ? FILE_STATUS_MOREDATA : flush_packetizer(demuxer.m_ptzr);
  }
}
예제 #3
0
파일: r_avi.cpp 프로젝트: VRDate/mkvtoolnix
generic_packetizer_c *
avi_reader_c::create_dts_packetizer(int aid) {
  try {
    AVI_set_audio_track(m_avi, aid);

    long audio_position   = AVI_get_audio_position_index(m_avi);
    unsigned int num_read = 0;
    int dts_position      = -1;
    byte_buffer_c buffer;
    dts_header_t dtsheader;

    while ((-1 == dts_position) && (10 > num_read)) {
      int chunk_size = AVI_read_audio_chunk(m_avi, nullptr);

      if (0 < chunk_size) {
        memory_cptr chunk = memory_c::alloc(chunk_size);
        AVI_read_audio_chunk(m_avi, reinterpret_cast<char *>(chunk->get_buffer()));

        buffer.add(chunk);
        dts_position = find_dts_header(buffer.get_buffer(), buffer.get_size(), &dtsheader);

      } else {
        dts_position = find_dts_header(buffer.get_buffer(), buffer.get_size(), &dtsheader, true);
        break;
      }
    }

    if (-1 == dts_position)
      throw false;

    AVI_set_audio_position_index(m_avi, audio_position);

    return new dts_packetizer_c(this, m_ti, dtsheader);

  } catch (...) {
    mxerror_tid(m_ti.m_fname, aid + 1, Y("Could not find valid DTS headers in this track's first frames.\n"));
    return nullptr;
  }
}