bool truehd_reader_c::find_valid_headers(mm_io_c &in, int64_t probe_range, int num_headers) { try { memory_cptr buf(memory_c::alloc(probe_range)); in.setFilePointer(0, seek_beginning); skip_id3v2_tag(in); int num_read = in.read(buf->get_buffer(), probe_range); truehd_parser_c parser; parser.add_data(buf->get_buffer(), num_read); int num_sync_frames = 0; while (parser.frame_available()) { truehd_frame_cptr frame = parser.get_next_frame(); if (frame->is_sync()) ++num_sync_frames; } return num_sync_frames >= num_headers; } catch (...) { return false; } }
void ac3_reader_c::read_headers() { try { int tag_size_start = skip_id3v2_tag(*m_in); int tag_size_end = id3_tag_present_at_end(*m_in); if (0 > tag_size_start) tag_size_start = 0; if (0 < tag_size_end) m_size -= tag_size_end; size_t init_read_len = std::min(m_size - tag_size_start, static_cast<uint64_t>(AC3_READ_SIZE)); if (m_in->read(m_chunk->get_buffer(), init_read_len) != init_read_len) throw mtx::input::header_parsing_x(); m_in->setFilePointer(tag_size_start, seek_beginning); ac3::parser_c parser; parser.add_bytes(m_chunk->get_buffer(), init_read_len); if (!parser.frame_available()) throw mtx::input::header_parsing_x(); m_ac3header = parser.get_frame(); } catch (mtx::mm_io::exception &) { throw mtx::input::open_x(); } m_ti.m_id = 0; // ID for this track. show_demuxer_info(); }
int truehd_reader_c::probe_file(mm_io_c *in, uint64_t /* size */) { try { in->setFilePointer(0, seek_beginning); skip_id3v2_tag(*in); return find_valid_headers(*in, TRUEHD_READ_SIZE, 2) ? 1 : 0; } catch (...) { return 0; } }
void truehd_reader_c::read_headers() { try { int tag_size_start = skip_id3v2_tag(*m_in); int tag_size_end = id3_tag_present_at_end(*m_in); if (0 > tag_size_start) tag_size_start = 0; if (0 < tag_size_end) m_size -= tag_size_end; size_t init_read_len = std::min(m_size - tag_size_start, static_cast<uint64_t>(TRUEHD_READ_SIZE)); if (m_in->read(m_chunk->get_buffer(), init_read_len) != init_read_len) throw mtx::input::header_parsing_x(); m_in->setFilePointer(tag_size_start, seek_beginning); truehd_parser_c parser; parser.add_data(m_chunk->get_buffer(), init_read_len); auto found_truehd = false; auto found_ac3 = false; while (parser.frame_available() && (!found_truehd || !found_ac3)) { auto frame = parser.get_next_frame(); if (frame->is_ac3()) { if (!found_ac3) { found_ac3 = true; m_ac3_header = frame->m_ac3_header; } continue; } if (!frame->is_sync()) continue; m_header = frame; found_truehd = true; } m_ti.m_id = 0; // ID for this track. show_demuxer_info(); } catch (mtx::mm_io::exception &) { throw mtx::input::open_x(); } }
void aac_reader_c::read_headers() { try { int tag_size_start = skip_id3v2_tag(*m_in); int tag_size_end = id3_tag_present_at_end(*m_in); if (0 > tag_size_start) tag_size_start = 0; if (0 < tag_size_end) m_size -= tag_size_end; size_t init_read_len = std::min(m_size - tag_size_start, static_cast<uint64_t>(INITCHUNKSIZE)); if (m_in->read(m_chunk, init_read_len) != init_read_len) throw mtx::input::header_parsing_x(); m_in->setFilePointer(tag_size_start, seek_beginning); if (find_aac_header(*m_chunk, init_read_len, &m_aacheader, m_emphasis_present) < 0) throw mtx::input::header_parsing_x(); guess_adts_version(); m_ti.m_id = 0; // ID for this track. int detected_profile = m_aacheader.profile; if (24000 >= m_aacheader.sample_rate) m_aacheader.profile = AAC_PROFILE_SBR; if ( (map_has_key(m_ti.m_all_aac_is_sbr, 0) && m_ti.m_all_aac_is_sbr[ 0]) || (map_has_key(m_ti.m_all_aac_is_sbr, -1) && m_ti.m_all_aac_is_sbr[-1])) m_aacheader.profile = AAC_PROFILE_SBR; if ( (map_has_key(m_ti.m_all_aac_is_sbr, 0) && !m_ti.m_all_aac_is_sbr[ 0]) || (map_has_key(m_ti.m_all_aac_is_sbr, -1) && !m_ti.m_all_aac_is_sbr[-1])) m_aacheader.profile = detected_profile; if ( map_has_key(m_ti.m_all_aac_is_sbr, 0) || map_has_key(m_ti.m_all_aac_is_sbr, -1)) m_sbr_status_set = true; } catch (...) { throw mtx::input::open_x(); } show_demuxer_info(); }
int ac3_reader_c::probe_file(mm_io_c *in, uint64_t, int64_t probe_size, int num_headers, bool require_zero_offset) { try { in->setFilePointer(0, seek_beginning); skip_id3v2_tag(*in); int offset = find_valid_headers(*in, probe_size, num_headers); return (require_zero_offset && (0 == offset)) || (!require_zero_offset && (0 <= offset)); } catch (...) { return 0; } }
void tta_reader_c::read_headers() { if (g_identifying) return; try { int tag_size = skip_id3v2_tag(*m_in); if (0 > tag_size) mxerror_fn(m_ti.m_fname, boost::format(Y("tta_reader: tag_size < 0 in the c'tor. %1%\n")) % BUGMSG); m_size -= tag_size; if (m_in->read(&header, sizeof(tta_file_header_t)) != sizeof(tta_file_header_t)) mxerror_fn(m_ti.m_fname, Y("The file header is too short.\n")); uint64_t seek_sum = m_in->getFilePointer() + 4 - tag_size; m_size -= id3_tag_present_at_end(*m_in); uint32_t seek_point; do { seek_point = m_in->read_uint32_le(); seek_sum += seek_point + 4; seek_points.push_back(seek_point); } while (seek_sum < m_size); mxverb(2, boost::format("tta: ch %1% bps %2% sr %3% dl %4% seek_sum %5% size %6% num %7%\n") % get_uint16_le(&header.channels) % get_uint16_le(&header.bits_per_sample) % get_uint32_le(&header.sample_rate) % get_uint32_le(&header.data_length) % seek_sum % m_size % seek_points.size()); if (seek_sum != m_size) mxerror_fn(m_ti.m_fname, Y("The seek table in this TTA file seems to be broken.\n")); m_in->skip(4); pos = 0; m_ti.m_id = 0; // ID for this track. } catch (...) { throw mtx::input::open_x(); } show_demuxer_info(); }
int tta_reader_c::probe_file(mm_io_c *in, uint64_t size) { unsigned char buf[4]; if (26 > size) return 0; try { in->setFilePointer(0, seek_beginning); int tag_size = skip_id3v2_tag(*in); if (-1 == tag_size) return 0; if (in->read(buf, 4) != 4) return 0; in->setFilePointer(0, seek_beginning); } catch (...) { return 0; } if (!strncmp((char *)buf, "TTA1", 4)) return 1; return 0; }
int ac3_reader_c::find_valid_headers(mm_io_c &in, int64_t probe_range, int num_headers) { try { memory_cptr buf(memory_c::alloc(probe_range)); in.setFilePointer(0, seek_beginning); skip_id3v2_tag(in); ac3::parser_c parser; int num_read = in.read(buf->get_buffer(), probe_range); int pos = parser.find_consecutive_frames(buf->get_buffer(), num_read, num_headers); in.setFilePointer(0, seek_beginning); return pos; } catch (...) { return -1; } }