int oem3_fill_header(oem3_header_t *header, uint8_t *buffer) { header->checksum = buffer[3]; header->message_id = get_uint32_le(&buffer[4]); header->message_length = get_uint32_le(&buffer[8]); return 0; }
void wav_reader_c::dump_headers() { mxinfo(boost::format("File '%1%' wave_header dump\n" " riff:\n" " id: %2%%3%%4%%5%\n" " len: %6%\n" " wave_id: %7%%8%%9%%10%\n" " common:\n" " wFormatTag: %|11$04x|\n" " wChannels: %12%\n" " dwSamplesPerSec: %13%\n" " dwAvgBytesPerSec: %14%\n" " wBlockAlign: %15%\n" " wBitsPerSample: %16%\n" " actual format_tag: %17%\n") % m_ti.m_fname % char(m_wheader.riff.id[0]) % char(m_wheader.riff.id[1]) % char(m_wheader.riff.id[2]) % char(m_wheader.riff.id[3]) % get_uint32_le(&m_wheader.riff.len) % char(m_wheader.riff.wave_id[0]) % char(m_wheader.riff.wave_id[1]) % char(m_wheader.riff.wave_id[2]) % char(m_wheader.riff.wave_id[3]) % get_uint16_le(&m_wheader.common.wFormatTag) % get_uint16_le(&m_wheader.common.wChannels) % get_uint32_le(&m_wheader.common.dwSamplesPerSec) % get_uint32_le(&m_wheader.common.dwAvgBytesPerSec) % get_uint16_le(&m_wheader.common.wBlockAlign) % get_uint16_le(&m_wheader.common.wBitsPerSample) % m_format_tag); }
int oem3_get_sat(oem3_sat_t *sat, uint8_t buffer[], uint16_t length) { if(length < 32) return -1; sat->week = get_uint32_le(&buffer[ 0]); sat->sec = get_double_le(&buffer[ 4]); sat->sol_status = get_uint32_le(&buffer[12]); sat->obs = get_uint32_le(&buffer[16]); return(0); }
void avi_reader_c::create_video_packetizer() { size_t i; mxverb_tid(4, m_ti.m_fname, 0, "frame sizes:\n"); for (i = 0; i < m_max_video_frames; i++) { m_bytes_to_process += AVI_frame_size(m_avi, i); mxverb(4, boost::format(" %1%: %2%\n") % i % AVI_frame_size(m_avi, i)); } if (m_avi->bitmap_info_header) { m_ti.m_private_data = memory_c::clone(m_avi->bitmap_info_header, get_uint32_le(&m_avi->bitmap_info_header->bi_size)); mxverb(4, boost::format("track extra data size: %1%\n") % (m_ti.m_private_data->get_size() - sizeof(alBITMAPINFOHEADER))); if (sizeof(alBITMAPINFOHEADER) < m_ti.m_private_data->get_size()) mxverb(4, boost::format(" %1%\n") % to_hex(m_ti.m_private_data->get_buffer() + sizeof(alBITMAPINFOHEADER), m_ti.m_private_data->get_size() - sizeof(alBITMAPINFOHEADER))); } const char *codec = AVI_video_compressor(m_avi); if (mpeg4::p2::is_v3_fourcc(codec)) m_divx_type = DIVX_TYPE_V3; else if (mpeg4::p2::is_fourcc(codec)) m_divx_type = DIVX_TYPE_MPEG4; if (map_has_key(m_ti.m_default_durations, 0)) m_fps = 1000000000.0 / m_ti.m_default_durations[0]; else if (map_has_key(m_ti.m_default_durations, -1)) m_fps = 1000000000.0 / m_ti.m_default_durations[-1]; m_ti.m_id = 0; // ID for the video track. if (DIVX_TYPE_MPEG4 == m_divx_type) create_mpeg4_p2_packetizer(); else if (mpeg4::p10::is_avc_fourcc(codec) && !hack_engaged(ENGAGE_ALLOW_AVC_IN_VFW_MODE)) create_mpeg4_p10_packetizer(); else if (mpeg1_2::is_fourcc(get_uint32_le(codec))) create_mpeg1_2_packetizer(); else if (FOURCC('V', 'P', '8', '0') == get_uint32_be(codec)) create_vp8_packetizer(); else create_standard_video_packetizer(); }
file_status_e ivf_reader_c::read(generic_packetizer_c *, bool) { size_t remaining_bytes = m_size - m_in->getFilePointer(); ivf::frame_header_t header; if ((sizeof(ivf::frame_header_t) > remaining_bytes) || (m_in->read(&header, sizeof(ivf::frame_header_t)) != sizeof(ivf::frame_header_t))) return flush_packetizers(); remaining_bytes -= sizeof(ivf::frame_header_t); uint32_t frame_size = get_uint32_le(&header.frame_size); if (remaining_bytes < frame_size) { m_in->setFilePointer(0, seek_end); return flush_packetizers(); } memory_cptr buffer = memory_c::alloc(frame_size); if (m_in->read(buffer->get_buffer(), frame_size) < frame_size) { m_in->setFilePointer(0, seek_end); return flush_packetizers(); } int64_t timestamp = get_uint64_le(&header.timestamp) * 1000000000ull * m_frame_rate_den / m_frame_rate_num; mxverb(3, boost::format("r_ivf.cpp: key %5% header.ts %1% num %2% den %3% res %4%\n") % get_uint64_le(&header.timestamp) % m_frame_rate_num % m_frame_rate_den % timestamp % ivf::is_keyframe(buffer)); PTZR0->process(new packet_t(buffer, timestamp)); return FILE_STATUS_MOREDATA; }
void avi_reader_c::create_mpeg4_p10_packetizer() { try { mpeg4_p10_es_video_packetizer_c *ptzr = new mpeg4_p10_es_video_packetizer_c(this, m_ti); m_vptzr = add_packetizer(ptzr); ptzr->set_video_pixel_dimensions(AVI_video_width(m_avi), AVI_video_height(m_avi)); if (0 != m_fps) ptzr->set_container_default_field_duration(1000000000ll / m_fps / 2); uint32_t extra_data_size = get_uint32_le(&m_avi->bitmap_info_header->bi_size) - sizeof(alBITMAPINFOHEADER); if (0 < extra_data_size) { memory_cptr avc_extra_nalus = mpeg4::p10::avcc_to_nalus(reinterpret_cast<unsigned char *>(m_avi->bitmap_info_header + 1), extra_data_size); if (avc_extra_nalus) ptzr->add_extra_data(avc_extra_nalus); } set_avc_nal_size_size(ptzr); show_packetizer_info(0, ptzr); } catch (...) { mxerror_tid(m_ti.m_fname, 0, Y("Could not extract the decoder specific config data (AVCC) from this AVC/h.264 track.\n")); } }
int oem3_get_pav(oem3_pav_t *pav, uint8_t buffer[], uint16_t length) { if(length < 80) return -1; pav->week = get_uint32_le(&buffer[ 0]); pav->sec = get_double_le(&buffer[ 4]); pav->av_latitude = get_double_le(&buffer[12]); pav->av_longitude = get_double_le(&buffer[20]); pav->av_height = get_double_le(&buffer[28]); pav->std_dev_latitude = get_double_le(&buffer[36]); pav->std_dev_longitude = get_double_le(&buffer[44]); pav->std_dev_height = get_double_le(&buffer[52]); pav->av_time = get_uint32_le(&buffer[60]); pav->samples = get_uint32_le(&buffer[64]); return 0; }
void avi_reader_c::identify_audio() { int i; for (i = 0; i < AVI_audio_tracks(m_avi); i++) { AVI_set_audio_track(m_avi, i); unsigned int audio_format = AVI_audio_format(m_avi); alWAVEFORMATEX *wfe = m_avi->wave_format_ex[i]; if ((0xfffe == audio_format) && (get_uint16_le(&wfe->cb_size) >= (sizeof(alWAVEFORMATEXTENSION)))) { alWAVEFORMATEXTENSIBLE *ext = reinterpret_cast<alWAVEFORMATEXTENSIBLE *>(wfe); audio_format = get_uint32_le(&ext->extension.guid.data1); } std::string type = (0x0001 == audio_format) || (0x0003 == audio_format) ? "PCM" : (0x0050 == audio_format) ? "MP2" : (0x0055 == audio_format) ? "MP3" : (0x2000 == audio_format) ? "AC3" : (0x2001 == audio_format) ? "DTS" : (0x0050 == audio_format) ? "MP2" : (0x00ff == audio_format) || (0x706d == audio_format) ? "AAC" : (0x566f == audio_format) ? "Vorbis" : (boost::format("unsupported (0x%|1$04x|)") % audio_format).str(); id_result_track(i + 1, ID_RESULT_TRACK_AUDIO, type); } }
uint32_t mm_io_c::read_uint32_le() { unsigned char buffer[4]; if (read(buffer, 4) != 4) throw mtx::mm_io::end_of_file_x(); return get_uint32_le(buffer); }
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(); }
void ivf_reader_c::read_headers() { try { ivf::file_header_t header; m_in->read(&header, sizeof(ivf::file_header_t)); m_width = get_uint16_le(&header.width); m_height = get_uint16_le(&header.height); m_frame_rate_num = get_uint32_le(&header.frame_rate_num); m_frame_rate_den = get_uint32_le(&header.frame_rate_den); m_ti.m_id = 0; // ID for this track. } catch (...) { throw mtx::input::open_x(); } show_demuxer_info(); }
/** * This function will test function: * Do_Do_Crypto_AsynchronousHash. * Function used in: Test_Do_Crypto_AsynchronousHash. * * @param [in] Case_p is pointer. * @return void. */ static void ADbg_Do_Crypto_AsynchronousHash(ADbg_Case_t *Case_p) { ErrorCode_e Result = E_SUCCESS; uint32 ObjectLength = 0; void *Object_p = NULL; HashType_e Type; uint32 DataLength = 0; void *Data_p = NULL; uint32 Length = 0; uint8 *Hash_p = NULL; HashCallback_fn Callback; uint32 ParamLength = 0; void *Param_p = NULL; uint8 *Var_p = NULL; Var_p = Case_p->Command_p->Data_p; ObjectLength = get_uint32_le((void **)&Var_p); Object_p = Do_ADbg_GetDataPointer(ObjectLength, (void **)&Var_p); Do_ADbg_GetDataVar(sizeof(HashType_e), &Var_p, &Type); DataLength = get_uint32_le((void **)&Var_p); Data_p = Do_ADbg_GetDataPointer(DataLength, (void **)&Var_p); Do_ADbg_GetDataVar(sizeof(uint32), &Var_p, &Length); Hash_p = (uint8 *) Do_ADbg_GetDataPointer(sizeof(uint8), (void **)&Var_p); Do_ADbg_GetDataVar(sizeof(HashCallback_fn), &Var_p, &Callback); ParamLength = get_uint32_le((void **)&Var_p); Param_p = Do_ADbg_GetDataPointer(ParamLength, (void **)&Var_p); Do_Crypto_AsynchronousHash(Object_p, Type, Data_p, Length, Hash_p, Callback, Param_p); Do_ADbg_Assert(E_SUCCESS == Result, Case_p); BUFFER_FREE(Object_p); BUFFER_FREE(Data_p); BUFFER_FREE(Hash_p); BUFFER_FREE(Param_p); }
generic_packetizer_c * wav_pcm_demuxer_c::create_packetizer() { m_ptzr = new pcm_packetizer_c(m_reader, m_ti, get_uint32_le(&m_wheader->common.dwSamplesPerSec), get_uint16_le(&m_wheader->common.wChannels), get_uint16_le(&m_wheader->common.wBitsPerSample), ieee_float ? pcm_packetizer_c::ieee_float : pcm_packetizer_c::little_endian_integer); show_packetizer_info(0, m_ptzr); return m_ptzr; }
void avi_reader_c::verify_video_track() { alBITMAPINFOHEADER *bih = m_avi->bitmap_info_header; size_t size = get_uint32_le(&bih->bi_size); if (sizeof(alBITMAPINFOHEADER) > size) return; const char *codec = AVI_video_compressor(m_avi); if ((0 == codec[0]) || (0 == AVI_video_width(m_avi)) || (0 == AVI_video_height(m_avi))) return; m_video_track_ok = true; }
/** * This function will test function: * Do_Hash_DeviceShutdown. * Function used in: Test_Do_Hash_DeviceShutdown. * * @param [in] Case_p is pointer. * @return void. */ static void ADbg_Do_Hash_DeviceShutdown(ADbg_Case_t *Case_p) { ErrorCode_e Result = E_SUCCESS; uint32 ObjectLength = 0; void *Object_p = NULL; uint32 HashDeviceLength = 0; void *HashDevice_pp = NULL; uint8 *Var_p = NULL; Var_p = Case_p->Command_p->Data_p; ObjectLength = get_uint32_le((void **)&Var_p); Object_p = Do_ADbg_GetDataPointer(ObjectLength, (void **)&Var_p); HashDeviceLength = get_uint32_le((void **)&Var_p); HashDevice_pp = Do_ADbg_GetDataPointer(HashDeviceLength, (void **)&Var_p); Do_Hash_DeviceShutdown(Object_p, &HashDevice_pp); Do_ADbg_Assert(E_SUCCESS == Result, Case_p); BUFFER_FREE(Object_p); BUFFER_FREE(HashDevice_pp); }
file_status_e tta_reader_c::read(generic_packetizer_c *, bool) { if (seek_points.size() <= pos) return flush_packetizers(); unsigned char *buf = (unsigned char *)safemalloc(seek_points[pos]); int nread = m_in->read(buf, seek_points[pos]); if (0 >= nread) return flush_packetizers(); pos++; memory_cptr mem(new memory_c(buf, nread, true)); if (seek_points.size() <= pos) { double samples_left = (double)get_uint32_le(&header.data_length) - (seek_points.size() - 1) * TTA_FRAME_TIME * get_uint32_le(&header.sample_rate); mxverb(2, boost::format("tta: samples_left %1%\n") % samples_left); PTZR0->process(new packet_t(mem, -1, irnd(samples_left * 1000000000.0l / get_uint32_le(&header.sample_rate)))); } else PTZR0->process(new packet_t(mem)); return seek_points.size() <= pos ? flush_packetizers() : FILE_STATUS_MOREDATA; }
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; }
void wav_reader_c::identify() { if (!m_demuxer) { uint16_t format_tag = get_uint16_le(&m_wheader.common.wFormatTag); id_result_container_unsupported(m_in->get_file_name(), (boost::format("RIFF WAVE (wFormatTag = 0x%|1$04x|)") % format_tag).str()); return; } std::vector<std::string> verbose_info; verbose_info.push_back((boost::format("channels:%1%") % get_uint16_le(&m_wheader.common.wChannels)).str()); verbose_info.push_back((boost::format("sample_rate:%1%") % get_uint32_le(&m_wheader.common.dwSamplesPerSec)).str()); verbose_info.push_back((boost::format("bits_per_sample:%1%") % get_uint16_le(&m_wheader.common.wBitsPerSample)).str()); id_result_container(); id_result_track(0, ID_RESULT_TRACK_AUDIO, m_demuxer->m_codec.get_name(), verbose_info); }
/** * This function will test function: * Do_Crypto_GetHashLength. * Function used in: Test_Do_Crypto_GetHashLength. * * @param [in] Case_p is pointer. * @return void. */ static void ADbg_Do_Crypto_GetHashLength(ADbg_Case_t *Case_p) { uint32 Result = E_SUCCESS; uint32 ExpectedResult = 0xFFFFFFFF; uint32 ObjectLength = 0; void *Object_p = NULL; HashType_e Type; uint8 *Var_p = NULL; Var_p = Case_p->Command_p->Data_p; ObjectLength = get_uint32_le((void **)&Var_p); Object_p = Do_ADbg_GetDataPointer(ObjectLength, (void **)&Var_p); Do_ADbg_GetDataVar(sizeof(HashType_e), &Var_p, &Type); Result = Do_Crypto_GetHashLength(Object_p, Type); Do_ADbg_Assert(ExpectedResult != Result, Case_p); BUFFER_FREE(Object_p); }
void avi_reader_c::identify_audio() { int i; for (i = 0; i < AVI_audio_tracks(m_avi); i++) { AVI_set_audio_track(m_avi, i); auto info = mtx::id::info_c{}; info.add(mtx::id::audio_channels, AVI_audio_channels(m_avi)); info.add(mtx::id::audio_sampling_frequency, AVI_audio_rate(m_avi)); info.add(mtx::id::audio_bits_per_sample, AVI_audio_bits(m_avi)); unsigned int audio_format = AVI_audio_format(m_avi); alWAVEFORMATEX *wfe = m_avi->wave_format_ex[i]; if ((0xfffe == audio_format) && (get_uint16_le(&wfe->cb_size) >= (sizeof(alWAVEFORMATEXTENSION)))) { alWAVEFORMATEXTENSIBLE *ext = reinterpret_cast<alWAVEFORMATEXTENSIBLE *>(wfe); audio_format = get_uint32_le(&ext->extension.guid.data1); } auto codec = codec_c::look_up_audio_format(audio_format); id_result_track(i + 1, ID_RESULT_TRACK_AUDIO, codec.get_name((boost::format("unsupported (0x%|1$04x|)") % audio_format).str()), info.get()); } }
void avi_reader_c::identify_video() { if (!m_video_track_ok) return; std::vector<std::string> extended_info; const char *fourcc_str = AVI_video_compressor(m_avi); std::string type = fourcc_str; if (IS_MPEG4_L2_FOURCC(fourcc_str)) extended_identify_mpeg4_l2(extended_info); else if (mpeg4::p10::is_avc_fourcc(fourcc_str)) extended_info.push_back("packetizer:mpeg4_p10_es_video"); else if (mpeg1_2::is_fourcc(get_uint32_le(fourcc_str))) type = "MPEG-1/2"; else if (type == "VP80") type = "VP8"; id_result_track(0, ID_RESULT_TRACK_VIDEO, type, join(" ", extended_info)); }
void avi_reader_c::add_audio_demuxer(int aid) { for (auto &demuxer : m_audio_demuxers) if (demuxer.m_aid == aid) // Demuxer already added? return; AVI_set_audio_track(m_avi, aid); if (AVI_read_audio_chunk(m_avi, nullptr) < 0) { mxwarn(boost::format(Y("Could not find an index for audio track %1% (avilib error message: %2%). Skipping track.\n")) % (aid + 1) % AVI_strerror()); return; } avi_demuxer_t demuxer; generic_packetizer_c *packetizer = nullptr; alWAVEFORMATEX *wfe = m_avi->wave_format_ex[aid]; uint32_t audio_format = AVI_audio_format(m_avi); demuxer.m_aid = aid; demuxer.m_ptzr = -1; demuxer.m_samples_per_second = AVI_audio_rate(m_avi); demuxer.m_channels = AVI_audio_channels(m_avi); demuxer.m_bits_per_sample = AVI_audio_bits(m_avi); m_ti.m_id = aid + 1; // ID for this audio track. m_ti.m_avi_block_align = get_uint16_le(&wfe->n_block_align); m_ti.m_avi_avg_bytes_per_sec = get_uint32_le(&wfe->n_avg_bytes_per_sec); m_ti.m_avi_samples_per_chunk = get_uint32_le(&m_avi->stream_headers[aid].dw_scale); m_ti.m_avi_sample_scale = get_uint32_le(&m_avi->stream_headers[aid].dw_rate); m_ti.m_avi_samples_per_sec = demuxer.m_samples_per_second; if ((0xfffe == audio_format) && (get_uint16_le(&wfe->cb_size) >= (sizeof(alWAVEFORMATEXTENSION)))) { alWAVEFORMATEXTENSIBLE *ext = reinterpret_cast<alWAVEFORMATEXTENSIBLE *>(wfe); audio_format = get_uint32_le(&ext->extension.guid.data1); } else if (get_uint16_le(&wfe->cb_size) > 0) m_ti.m_private_data = memory_c::clone(wfe + 1, get_uint16_le(&wfe->cb_size)); else m_ti.m_private_data.reset(); switch(audio_format) { case 0x0001: // raw PCM audio case 0x0003: // raw PCM audio (float) packetizer = new pcm_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, demuxer.m_bits_per_sample, 0x0003 == audio_format ? pcm_packetizer_c::ieee_float : pcm_packetizer_c::little_endian_integer); break; case 0x0050: // MP2 case 0x0055: // MP3 packetizer = new mp3_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, false); break; case 0x2000: // AC3 packetizer = new ac3_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, 0); break; case 0x2001: // DTS packetizer = create_dts_packetizer(aid); break; case 0x00ff: case 0x706d: // AAC packetizer = create_aac_packetizer(aid, demuxer); break; case 0x566f: // Vorbis packetizer = create_vorbis_packetizer(aid); break; default: mxerror_tid(m_ti.m_fname, aid + 1, boost::format(Y("Unknown/unsupported audio format 0x%|1$04x| for this audio track.\n")) % audio_format); } show_packetizer_info(aid + 1, packetizer); demuxer.m_ptzr = add_packetizer(packetizer); m_audio_demuxers.push_back(demuxer); int i, maxchunks = AVI_audio_chunks(m_avi); for (i = 0; i < maxchunks; i++) m_bytes_to_process += AVI_audio_size(m_avi, i); }
void avi_reader_c::verify_video_track() { auto size = get_uint32_le(&m_avi->bitmap_info_header->bi_size); m_video_track_ok = (sizeof(alBITMAPINFOHEADER) <= size) && (0 != AVI_video_width(m_avi)) && (0 != AVI_video_height(m_avi)); }
void avi_reader_c::add_audio_demuxer(int aid) { for (auto &demuxer : m_audio_demuxers) if (demuxer.m_aid == aid) // Demuxer already added? return; AVI_set_audio_track(m_avi, aid); if (AVI_read_audio_chunk(m_avi, nullptr) < 0) { mxwarn(boost::format(Y("Could not find an index for audio track %1% (avilib error message: %2%). Skipping track.\n")) % (aid + 1) % AVI_strerror()); return; } avi_demuxer_t demuxer; generic_packetizer_c *packetizer = nullptr; alWAVEFORMATEX *wfe = m_avi->wave_format_ex[aid]; uint32_t audio_format = AVI_audio_format(m_avi); demuxer.m_aid = aid; demuxer.m_ptzr = -1; demuxer.m_samples_per_second = AVI_audio_rate(m_avi); demuxer.m_channels = AVI_audio_channels(m_avi); demuxer.m_bits_per_sample = AVI_audio_bits(m_avi); m_ti.m_id = aid + 1; // ID for this audio track. auto stream_header = &m_avi->stream_headers[aid]; auto dw_scale = static_cast<int64_t>(get_uint32_le(&stream_header->dw_scale)); auto dw_rate = static_cast<int64_t>(get_uint32_le(&stream_header->dw_rate)); auto dw_sample_size = static_cast<int64_t>(get_uint32_le(&stream_header->dw_sample_size)); m_ti.m_avi_audio_data_rate = dw_scale ? dw_rate * dw_sample_size / dw_scale : 0; if ((0xfffe == audio_format) && (get_uint16_le(&wfe->cb_size) >= (sizeof(alWAVEFORMATEXTENSION)))) { alWAVEFORMATEXTENSIBLE *ext = reinterpret_cast<alWAVEFORMATEXTENSIBLE *>(wfe); audio_format = get_uint32_le(&ext->extension.guid.data1); } else if (get_uint16_le(&wfe->cb_size) > 0) m_ti.m_private_data = memory_c::clone(wfe + 1, get_uint16_le(&wfe->cb_size)); else m_ti.m_private_data.reset(); demuxer.m_codec = codec_c::look_up_audio_format(audio_format); if (demuxer.m_codec.is(codec_c::type_e::A_PCM)) packetizer = new pcm_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, demuxer.m_bits_per_sample, 0x0003 == audio_format ? pcm_packetizer_c::ieee_float : pcm_packetizer_c::little_endian_integer); else if (demuxer.m_codec.is(codec_c::type_e::A_MP2) || demuxer.m_codec.is(codec_c::type_e::A_MP3)) packetizer = new mp3_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, false); else if (demuxer.m_codec.is(codec_c::type_e::A_AC3)) packetizer = new ac3_packetizer_c(this, m_ti, demuxer.m_samples_per_second, demuxer.m_channels, 0); else if (demuxer.m_codec.is(codec_c::type_e::A_DTS)) packetizer = create_dts_packetizer(aid); else if (demuxer.m_codec.is(codec_c::type_e::A_AAC)) packetizer = create_aac_packetizer(aid, demuxer); else if (demuxer.m_codec.is(codec_c::type_e::A_VORBIS)) packetizer = create_vorbis_packetizer(aid); else mxerror_tid(m_ti.m_fname, aid + 1, boost::format(Y("Unknown/unsupported audio format 0x%|1$04x| for this audio track.\n")) % audio_format); packetizer->enable_avi_audio_sync(true); show_packetizer_info(aid + 1, packetizer); demuxer.m_ptzr = add_packetizer(packetizer); m_audio_demuxers.push_back(demuxer); int i, maxchunks = AVI_audio_chunks(m_avi); for (i = 0; i < maxchunks; i++) { auto size = AVI_audio_size(m_avi, i); if (size < AVI_MAX_AUDIO_CHUNK_SIZE) m_bytes_to_process += size; } }
wav_pcm_demuxer_c::wav_pcm_demuxer_c(wav_reader_c *reader, wave_header *wheader, bool _float): wav_demuxer_c(reader, wheader), m_bps(0), ieee_float(_float) { m_bps = get_uint16_le(&m_wheader->common.wChannels) * get_uint16_le(&m_wheader->common.wBitsPerSample) * get_uint32_le(&m_wheader->common.dwSamplesPerSec) / 8; m_buffer = memory_c::alloc(m_bps); }
int32_t get_int32_le(uint8_t *buffer) { return((int32_t)get_uint32_le(buffer)); }
void xtr_wavpack4_c::handle_frame(xtr_frame_t &f) { // build the main header binary wv_header[32]; memcpy(wv_header, "wvpk", 4); memcpy(&wv_header[8], m_version, 2); // version wv_header[10] = 0; // track_no wv_header[11] = 0; // index_no wv_header[12] = 0xFF; // total_samples is unknown wv_header[13] = 0xFF; wv_header[14] = 0xFF; wv_header[15] = 0xFF; put_uint32_le(&wv_header[16], m_number_of_samples); // block_index const binary *mybuffer = f.frame->get_buffer(); int data_size = f.frame->get_size(); m_number_of_samples += get_uint32_le(mybuffer); // rest of the header: memcpy(&wv_header[20], mybuffer, 3 * sizeof(uint32_t)); std::vector<uint32_t> flags; // support multi-track files if (2 < m_channels) { uint32_t block_size = get_uint32_le(&mybuffer[12]); put_uint32_le(&wv_header[4], block_size + 24); // ck_size m_out->write(wv_header, 32); flags.push_back(*(uint32_t *)&mybuffer[4]); mybuffer += 16; m_out->write(mybuffer, block_size); mybuffer += block_size; data_size -= block_size + 16; while (0 < data_size) { block_size = get_uint32_le(&mybuffer[8]); memcpy(&wv_header[24], mybuffer, 8); put_uint32_le(&wv_header[4], block_size + 24); m_out->write(wv_header, 32); flags.push_back(*(uint32_t *)mybuffer); mybuffer += 12; m_out->write(mybuffer, block_size); mybuffer += block_size; data_size -= block_size + 12; } } else { put_uint32_le(&wv_header[4], data_size + 12); // ck_size m_out->write(wv_header, 32); m_out->write(&mybuffer[12], data_size - 12); // the rest of the } // support hybrid mode data if (m_corr_out && (f.additions)) { KaxBlockMore *block_more = FindChild<KaxBlockMore>(f.additions); if (!block_more) return; KaxBlockAdditional *block_addition = FindChild<KaxBlockAdditional>(block_more); if (!block_addition) return; data_size = block_addition->GetSize(); mybuffer = block_addition->GetBuffer(); if (2 < m_channels) { size_t flags_index = 0; while (0 < data_size) { uint32_t block_size = get_uint32_le(&mybuffer[4]); put_uint32_le(&wv_header[4], block_size + 24); // ck_size memcpy(&wv_header[24], &flags[flags_index++], 4); // flags memcpy(&wv_header[28], mybuffer, 4); // crc m_corr_out->write(wv_header, 32); mybuffer += 8; m_corr_out->write(mybuffer, block_size); mybuffer += block_size; data_size -= 8 + block_size; } } else { put_uint32_le(&wv_header[4], data_size + 20); // ck_size memcpy(&wv_header[28], mybuffer, 4); // crc m_corr_out->write(wv_header, 32); m_corr_out->write(&mybuffer[4], data_size - 4); } } }
void tta_reader_c::create_packetizer(int64_t) { if (!demuxing_requested('a', 0) || (NPTZR() != 0)) return; add_packetizer(new tta_packetizer_c(this, m_ti, get_uint16_le(&header.channels), get_uint16_le(&header.bits_per_sample), get_uint32_le(&header.sample_rate))); show_packetizer_info(0, PTZR0); }