void xtr_wav_c::create_file(xtr_base_c *master, KaxTrackEntry &track) { init_content_decoder(track); int channels = kt_get_a_channels(track); int sfreq = (int)kt_get_a_sfreq(track); int bps = kt_get_a_bps(track); if (-1 == bps) mxerror(boost::format(Y("Track %1% with the CodecID '%2%' is missing the \"bits per second (bps)\" element and cannot be extracted.\n")) % m_tid % m_codec_id); xtr_base_c::create_file(master, track); memcpy(&m_wh.riff.id, "RIFF", 4); memcpy(&m_wh.riff.wave_id, "WAVE", 4); memcpy(&m_wh.format.id, "fmt ", 4); memcpy(&m_wh.data.id, "data", 4); put_uint32_le(&m_wh.format.len, 16); put_uint16_le(&m_wh.common.wFormatTag, 1); put_uint16_le(&m_wh.common.wChannels, channels); put_uint32_le(&m_wh.common.dwSamplesPerSec, sfreq); put_uint32_le(&m_wh.common.dwAvgBytesPerSec, channels * sfreq * bps / 8); put_uint16_le(&m_wh.common.wBlockAlign, 4); put_uint16_le(&m_wh.common.wBitsPerSample, bps); m_out->write(&m_wh, sizeof(wave_header)); }
void xtr_ivf_c::handle_frame(memory_cptr &frame, KaxBlockAdditions *, int64_t timecode, int64_t, int64_t, int64_t, bool, bool, bool) { m_content_decoder.reverse(frame, CONTENT_ENCODING_SCOPE_BLOCK); uint64_t frame_number = timecode * m_frame_rate_num / m_frame_rate_den / 1000000000ull; mxverb(2, boost::format("timecode %1% num %2% den %3% frame_number %4% calculated back %5%\n") % timecode % m_frame_rate_num % m_frame_rate_den % frame_number % (frame_number * 1000000000ull * m_frame_rate_den / m_frame_rate_num)); ivf::frame_header_t frame_header; put_uint32_le(&frame_header.frame_size, frame->get_size()); put_uint32_le(&frame_header.timestamp, frame_number); m_out->write(&frame_header, sizeof(frame_header)); m_out->write(frame->get_buffer(), frame->get_size()); ++m_frame_count; }
void xtr_wav_c::finish_file() { m_out->setFilePointer(0); put_uint32_le(&m_wh.riff.len, m_bytes_written + 36); put_uint32_le(&m_wh.data.len, m_bytes_written); m_out->write(&m_wh, sizeof(wave_header)); }
void xtr_tta_c::finish_file() { m_out.reset(); mm_io_cptr in; try { in = mm_file_io_c::open(m_temp_file_name); } catch (mtx::mm_io::exception &ex) { mxerror(boost::format(Y("The temporary file '%1%' could not be opened for reading: %2%.\n")) % m_temp_file_name % ex); } try { m_out = mm_write_buffer_io_c::open(m_file_name, 5 * 1024 * 1024); } catch (mtx::mm_io::exception &ex) { mxerror(boost::format(Y("The file '%1%' could not be opened for writing: %2%.\n")) % m_file_name % ex); } tta_file_header_t tta_header; memcpy(tta_header.signature, "TTA1", 4); if (3 != m_bps) put_uint16_le(&tta_header.audio_format, 1); else put_uint16_le(&tta_header.audio_format, 3); put_uint16_le(&tta_header.channels, m_channels); put_uint16_le(&tta_header.bits_per_sample, m_bps); put_uint32_le(&tta_header.sample_rate, m_sfreq); if (0 >= m_previous_duration) m_previous_duration = (int64_t)(TTA_FRAME_TIME * m_sfreq) * 1000000000ll; put_uint32_le(&tta_header.data_length, (uint32_t)(m_sfreq * (TTA_FRAME_TIME * (m_frame_sizes.size() - 1) + (double)m_previous_duration / 1000000000.0l))); put_uint32_le(&tta_header.crc, 0xffffffff ^ mtx::checksum::calculate_as_uint(mtx::checksum::algorithm_e::crc32_ieee_le, &tta_header, sizeof(tta_file_header_t) - 4, 0xffffffff)); m_out->write(&tta_header, sizeof(tta_file_header_t)); unsigned char *buffer = (unsigned char *)safemalloc(m_frame_sizes.size() * 4); size_t k; for (k = 0; m_frame_sizes.size() > k; ++k) put_uint32_le(buffer + 4 * k, m_frame_sizes[k]); m_out->write(buffer, m_frame_sizes.size() * 4); m_out->write_uint32_le(0xffffffff ^ mtx::checksum::calculate_as_uint(mtx::checksum::algorithm_e::crc32_ieee_le, buffer, m_frame_sizes.size() * 4, 0xffffffff)); safefree(buffer); mxinfo(boost::format(Y("\nThe temporary TTA file for track ID %1% is being copied into the final TTA file. This may take some time.\n")) % m_tid); buffer = (unsigned char *)safemalloc(128000); int nread; do { nread = in->read(buffer, 128000); m_out->write(buffer, nread); } while (nread == 128000); m_out.reset(); unlink(m_temp_file_name.c_str()); }
void xtr_oggopus_c::header_packets_unlaced(std::vector<memory_cptr> &header_packets) { auto signature = std::string{"OpusTags"}; auto version = std::string{"unknown encoder; extracted from Matroska with "} + (!hack_engaged(ENGAGE_NO_VARIABLE_DATA) ? get_version_info("mkvextract") : std::string{"mkvextract"}); auto ver_len = version.length(); auto mem = memory_c::alloc(8 + 4 + ver_len + 4); auto buffer = reinterpret_cast<char *>(mem->get_buffer()); signature.copy(buffer, 8); put_uint32_le(buffer + 8, ver_len); version.copy(buffer + 8 + 4, ver_len); put_uint32_le(buffer + mem->get_size() - 4, 0); header_packets.push_back(mem); }
ErrorCode_e Do_System_RebootImpl(uint16 Session, const uint32 Mode) { ErrorCode_e ReturnValue = E_GENERAL_FATAL_ERROR; uint8 *Data_p = NULL; CommandData_t CmmData = {0}; CmmData.CommandNr = COMMAND_SYSTEM_REBOOT; CmmData.ApplicationNr = GROUP_SYSTEM; CmmData.SessionNr = Session; CmmData.Type = COMMAND_TYPE; CmmData.Payload.Size = sizeof(uint32); CmmData.Payload.Data_p = (uint8 *)malloc(CmmData.Payload.Size); ASSERT(NULL != CmmData.Payload.Data_p); Data_p = CmmData.Payload.Data_p; put_uint32_le((void **)&Data_p, Mode); ReturnValue = Do_CES_RegisterRepeatCommand(&CmmData); VERIFY(E_SUCCESS == ReturnValue, ReturnValue); ReturnValue = E_SUCCESS; return ReturnValue; ErrorExit: B_(printf("system_applications_functions.c : Do_System_RebootImpl (%d) ......ReturnValue:(%d)\n\n", __LINE__, ReturnValue);)
int mm_io_c::write_uint32_le(uint32_t value) { uint32_t buffer; put_uint32_le(&buffer, value); return write(&buffer, sizeof(uint32_t)); }
void xtr_ivf_c::finish_file() { put_uint32_le(&m_file_header.frame_count, m_frame_count); m_out->setFilePointer(0, seek_beginning); m_out->write(&m_file_header, sizeof(m_file_header)); }
void mpeg4_p2_video_packetizer_c::extract_size(const unsigned char *buffer, int size) { if (m_size_extracted) return; if (0 != m_connected_to) { m_size_extracted = true; return; } uint32_t xtr_width, xtr_height; if (mpeg4::p2::extract_size(buffer, size, xtr_width, xtr_height)) { m_size_extracted = true; if (!m_reader->m_appending && ((xtr_width != static_cast<uint32_t>(m_hvideo_pixel_width)) || (xtr_height != static_cast<uint32_t>(m_hvideo_pixel_height)))) { set_video_pixel_width(xtr_width); set_video_pixel_height(xtr_height); if (!m_output_is_native && m_ti.m_private_data && (sizeof(alBITMAPINFOHEADER) <= m_ti.m_private_data->get_size())) { auto bih = reinterpret_cast<alBITMAPINFOHEADER *>(m_ti.m_private_data->get_buffer()); put_uint32_le(&bih->bi_width, xtr_width); put_uint32_le(&bih->bi_height, xtr_height); set_codec_private(m_ti.m_private_data); } m_hvideo_display_width = -1; m_hvideo_display_height = -1; generic_packetizer_c::set_headers(); rerender_track_headers(); mxinfo_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("The extracted values for video width and height from the MPEG4 layer 2 video data bitstream differ from what the values " "in the source container. The ones from the video data bitstream (%1%x%2%) will be used.\n")) % xtr_width % xtr_height); } } else if (50 <= m_frames_output) m_aspect_ratio_extracted = true; }
/***************************************************************************//** * @brief Reads bits from OTP memory. * * Reads all requested Length bits from OTP. * * @param[in] Session Command session. * @param[in] OTP_id NOT used. * @param[in] Start NOT used. * @param[in] Length Number of bits to read. * * @return E_INVALID_INPUT_PARAMETERS if input parameters are invalid. * E_ALLOCATE_FAILED if memory allocation failed. * E_READING_OTP_FAILED if reading from OTP failed. * E_SUCCESS if reading was successful. * *******************************************************************************/ ErrorCode_e Do_OTP_ReadBitsImpl(uint16 Session, const uint32 OTP_id, const uint32 Start, const uint32 Length) { ErrorCode_e ReturnValue = E_GENERAL_FATAL_ERROR; CommandData_t CmmData = {0}; void *Data_p = NULL; IDENTIFIER_NOT_USED(OTP_id); CmmData.CommandNr = COMMAND_OTP_READBITS; CmmData.ApplicationNr = GROUP_OTP; CmmData.SessionNr = Session; CmmData.Type = COMMAND_TYPE; VERIFY((Start & START_BIT_MASK) == Start, E_INVALID_INPUT_PARAMETERS); CmmData.Payload.Size = sizeof(uint32) + sizeof(uint32); CmmData.Payload.Data_p = (uint8 *)malloc(CmmData.Payload.Size); ASSERT(NULL != CmmData.Payload.Data_p); Data_p = CmmData.Payload.Data_p; put_uint32_le((void **)&Data_p, Start); put_uint32_le((void **)&Data_p, Length); C_(printf("otp_applications_functions.c (%d): Do_OTP_ReadBitsImpl: OTP_AREA_SIZE = %d \n", __LINE__, OTP_AREA_SIZE);)
void xtr_wav_c::create_file(xtr_base_c *master, KaxTrackEntry &track) { init_content_decoder(track); auto channels = kt_get_a_channels(track); auto sfreq = static_cast<int>(kt_get_a_sfreq(track)); auto bps = kt_get_a_bps(track); auto block_align = bps * channels / boost::math::gcd(8, bps); if (-1 == bps) mxerror(boost::format(Y("Track %1% with the CodecID '%2%' is missing the \"bits per second (bps)\" element and cannot be extracted.\n")) % m_tid % m_codec_id); xtr_base_c::create_file(master, track); memcpy(&m_wh.riff.id, "RIFF", 4); memcpy(&m_wh.riff.wave_id, "WAVE", 4); memcpy(&m_wh.format.id, "fmt ", 4); memcpy(&m_wh.data.id, "data", 4); put_uint32_le(&m_wh.format.len, 16); put_uint16_le(&m_wh.common.wFormatTag, 1); put_uint16_le(&m_wh.common.wChannels, channels); put_uint32_le(&m_wh.common.dwSamplesPerSec, sfreq); put_uint32_le(&m_wh.common.dwAvgBytesPerSec, channels * sfreq * bps / 8); put_uint16_le(&m_wh.common.wBlockAlign, block_align); put_uint16_le(&m_wh.common.wBitsPerSample, bps); m_out->write(&m_wh, sizeof(wave_header)); if (m_codec_id == MKV_A_PCM_BE) m_byte_swapper = [bps](unsigned char const *src, unsigned char *dst, std::size_t num_bytes) { mtx::bytes::swap_buffer(src, dst, num_bytes, bps / 8); }; }
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); } } }