DTS common: refactor to use timecode_c for calculations

This commit is contained in:
Moritz Bunkus 2015-03-26 08:38:04 +01:00
parent 08989fd166
commit ce6c868c23
4 changed files with 38 additions and 28 deletions

View File

@ -296,6 +296,27 @@ header_t::print()
% (hd_type == hd_type_e::master_audio ? "master audio" : "high resolution") % hd_part_size);
}
uint64_t
header_t::get_packet_length_in_core_samples()
const {
// computes the length (in time, not size) of the packet in "samples".
auto samples = static_cast<uint64_t>(num_pcm_sample_blocks) * 32;
if (frametype_e::termination == frametype)
samples -= std::min<uint64_t>(samples, deficit_sample_count);
return samples;
}
timecode_c
header_t::get_packet_length_in_nanoseconds()
const {
// computes the length (in time, not size) of the packet in "samples".
auto samples = get_packet_length_in_core_samples();
return timecode_c::samples(samples, core_sampling_frequency);
}
unsigned int
header_t::get_total_num_audio_channels()
const {

View File

@ -15,6 +15,8 @@
#ifndef MTX_COMMON_DTS_H
#define MTX_COMMON_DTS_H
#include "common/timecode.h"
class bit_reader_c;
namespace mtx { namespace dts {
@ -210,21 +212,8 @@ struct header_t {
std::vector<substream_asset_t> substream_assets;
public:
inline int get_packet_length_in_core_samples() const {
// computes the length (in time, not size) of the packet in "samples".
int r = num_pcm_sample_blocks * 32;
if (frametype_e::termination == frametype)
r -= deficit_sample_count;
return r;
}
inline double get_packet_length_in_nanoseconds() const {
// computes the length (in time, not size) of the packet in "samples".
auto samples = get_packet_length_in_core_samples();
return static_cast<double>(samples) * 1000000000.0 / core_sampling_frequency;
}
uint64_t get_packet_length_in_core_samples() const;
timecode_c get_packet_length_in_nanoseconds() const;
unsigned int get_total_num_audio_channels() const;
void print() const;

View File

@ -108,7 +108,7 @@ dts_packetizer_c::set_headers() {
set_codec_id(MKV_A_DTS);
set_audio_sampling_freq((float)m_first_header.core_sampling_frequency);
set_audio_channels(m_first_header.get_total_num_audio_channels());
set_track_default_duration(m_first_header.get_packet_length_in_nanoseconds());
set_track_default_duration(m_first_header.get_packet_length_in_nanoseconds().to_ns());
generic_packetizer_c::set_headers();
}
@ -133,7 +133,7 @@ dts_packetizer_c::process_available_packets(bool flushing) {
auto samples_in_packet = dtsheader.get_packet_length_in_core_samples();
auto new_timecode = m_timecode_calculator.get_next_timecode(samples_in_packet);
add_packet(std::make_shared<packet_t>(dts_packet, new_timecode.to_ns(), dtsheader.get_packet_length_in_nanoseconds()));
add_packet(std::make_shared<packet_t>(dts_packet, new_timecode.to_ns(), dtsheader.get_packet_length_in_nanoseconds().to_ns()));
}
}

View File

@ -70,8 +70,8 @@ T_220ass_with_comments_at_start:bd1ab3d2901f808a3baf21f21acb033b:passed:20060926
T_221aac_lc_misdetected_as_sbr:6a338e059717d57b89efa683031ee3c6:passed:20061103-174221:0.046026107
T_222stereo_mode:2075d865bab212c0a68c4a09f6bc0d0f-5cb64286f6abf27feb937b2dfbe2a450-e09eccab59f7c67672f3074a0062df96-9dc230a85a399c5e2ef40efe9a3f9011:passed:20061107-092251:1.221005171
T_223ra_cook_keyframes:0ce8fa241c0da02967c64050a7d0abaf:passed:20061228-150947:1.335998563
T_224dts:32c9587a6e8dbe2eb25361571520bc6d-f69b69d420f958a19127696b6895bcc6:passed:20070206-174735:2.808364528
T_225dts_in_wav:bce22003a834ed2958c2672eeb3c216b-3141f3be2355a18cc83f93ee99b9b233:passed:20070206-174726:1.066354749
T_224dts:47835a54a1619207aee2e8f8fc969252-6def59fd2600d177260163ebcf6eaac0:passed:20070206-174735:2.808364528
T_225dts_in_wav:3cb0077865607804c4e7adf5c1ca6166-6d41421cb87b4ecd1c2579cd22d99f5c:passed:20070206-174726:1.066354749
T_226h264:db2d8860284d69eaa9713e9b279d422f:passed:20070208-103558:6.088832141
T_227h264_with_garbage:8f8fcc72b0ff5f65239bf0de24eeb74d:passed:20070208-103656:5.660631896
T_228h264_no_idr_slices:7c6c84deca49aa7e79692c0b85f293ea:passed:20070426-103130:3.516955837
@ -81,12 +81,12 @@ T_231X_ac3_header_removal:6ca341797c5f93e273c8502f4d6f4fba:passed:20070623-11124
T_232h264_changing_sps_pps:689df934c0a7e1f934bb390c1eaf1702:passed:20070815-211934:4.982966207
T_233srt_with_coordinates:0de6cfc206a5889a5bd7afc8ddd9bdb8:passed:20070819-203105:0.279280932
T_234avi_aac_codecid_0x706d:72a44680602467d3a7efcdb4782c2ab2:passed:20080223-174500:1.065188599
T_235wav_fmt_chunk_length:adb5bb6329cd91eb9d24696895ac403a:passed:20080226-134540:0.199256803
T_235wav_fmt_chunk_length:a51ed8caf33d1b37e56074ac946a0438:passed:20080226-134540:0.199256803
T_236ac3_in_mov:243cb2156daf4f96c8c9786d4ba6abea:passed:20080229-103912:0.469764724
T_237ac3_in_wav_iec61937_mode:8ca78db7e874ba5936e3734d604702a7:passed:20080229-152103:0.345607428
T_238ac3_in_wav_acm_mode:01cf7f0cb7f36bcb2b4c5751dafaa202:passed:20080229-152339:0.064912703
T_239aac_with_id3_tags:85e809d53d6ce68ad5e656284d9d8eec:passed:20080309-170151:0.268856001
T_240dts_hd:c284b0e29c3b7040e14b89a7e4790ce1-923f3d925dcfca765567ba2be7cd3e92:passed:20080309-170749:1.508422156
T_240dts_hd:5caa015da487793beb320ba0b9f9e886-bb3a6db9c67634f5e3c3c54a3f9a6df8:passed:20080309-170749:1.508422156
T_241ac3_with_id3_tags:8ca78db7e874ba5936e3734d604702a7:passed:20080309-183547:0.390141882
T_242ogm_with_chapters:de4b664be77259c440cfe93625c90c82:passed:20080420-204932:0.052564939
T_243avi_with_audio_garbage:0ae0d88aa262006d9c64be4ea3c4043b:passed:20080913-185346:0.114602033
@ -145,7 +145,7 @@ T_296video_frames_duration_0:014957444838a0191e878bc77303dcf7:passed:20110709-14
T_297mpeg_transport_streams:80e456901895bd509cc8f2f6ed10d587-71b84bff87ea79be5ba6abedb5fb721f:passed:20110913-112636:10.36149529
T_298ts_language:22cd98453454d64c3bb51de3c4d72b6d:passed:20110915-221140:9.028917562
T_299ts_ghost_entries_in_pmt:a0e5ed55997295f9ef4e9d2b7b9eb0eb:passed:20110917-004553:0.898346704
T_300ts_dts_duplicate_timestamps:d60d97311df29ab0d2829e7692454419:passed:20110918-154508:1.728558428
T_300ts_dts_duplicate_timestamps:a21d66ca88633d6c812b693defea07ba:passed:20110918-154508:1.728558428
T_301ts_pgssub:b68cd888bc9c279fabc9040923feaaae:passed:20110918-154732:1.701870051
T_302pat_pmt_only_once:7f3568ee3b6e236b50ecfd531f98c65f:passed:20110927-222121:0.300545156
T_303mpeg_ts_eac3_pmt_descriptor_tag_0x7a:975846a0109d4faf79d1c971147ae2da:passed:20111008-150823:2.203601363
@ -173,9 +173,9 @@ T_324propedit_chapters:785209f2dc35ad6177bea2ca6e43198f-a9255d40de93e2731aaead0a
T_325propedit_tags:785209f2dc35ad6177bea2ca6e43198f-26ad4ab0491d76d9fb6f57b4a4b35400-2d6bc3c519e65853430cd53e64d46386-52322241c33de4f7b56ede7a4764f72f-2d6bc3c519e65853430cd53e64d46386-52322241c33de4f7b56ede7a4764f72f-ddb1f5475eca068a3e4b6ad8df1dea7e-591a65deb231cb0150a4da224d5f3415-e657d1255b0b7a1a1610bda7460dc318-438f0a8ce757e03b77c084bd593cb196-e657d1255b0b7a1a1610bda7460dc318-438f0a8ce757e03b77c084bd593cb196-6f60e83c7d351a25ad6af4545ce3dff6-5a8f05d63ffe9d53046abf40ec30e42a-e126ac5e6a97297f4ee14cfd648e1e33-d41d8cd98f00b204e9800998ecf8427e:passed:20111203-160727:1.314514241
T_326mpeg_ps_mpeg_audio_layer4:92c7507e54caf041d729c2e9e97c775f:passed:20111207-224511:1.505513342
T_327vp8_frame_type:da02f5873c366315b4594e34a04966e8:passed:20111207-233304:0.089263543
T_328dts_detected_as_ac3:98e9459b6ed0857cd8c9b526eab609b9:passed:20111229-192324:0.090561076
T_328dts_detected_as_ac3:6cadc1ac331dda8e80eae3abfeca1358:passed:20111229-192324:0.090561076
T_329X_timecodes_v2:dadc36ce79c1c4b281f8f1f865746598-049cdc2d9226fac8c61d193d803bfc1f-3720aac3f16b66ec3308ffa7bf913c6e-6469e2522a4b48b7b20bae93f5d9086d-1ff091abfcb0938d6ac7fd0495e899b3-049cdc2d9226fac8c61d193d803bfc1f-d172a9340cbf2802690479e396879d1e-bf76c5886cc7c18cc7e6ee796c3406b4-b3f9d126c31505c22f292a1d2bdffba2-4bd97467fac0ac0b561d68b8b15a79dd:passed:20120105-202451:1.376047868
T_330dts_detection:4315edaa1dc70b81a22c74e2bba08892:passed:20120107-210130:1.935366715
T_330dts_detection:14f0bbcb076116bff389ac58028b9a06:passed:20120107-210130:1.935366715
T_331read_buffer_underflow:fdf4588028552f16052b4100490b091a:passed:20120125-232902:0.322029153
T_332eac3_misdetected_as_avc:5dbc746c19239e50a3d79b33305ee20c:passed:20120131-145550:0.208997135
T_333wavpack_with_correction:7a0c1e500ac9122c6b6c296f25fb3844-e33897409384ca5fd8ed5e497f8c3883+37f802510b43b2ab4bd7d8356a7ac606-ok:passed:20120131-164845:0.221105789
@ -261,7 +261,7 @@ T_412ui_locale_pl_PL:5d790fb95cbc647fe5cec87e7618758a-84c3b74c3d8fe0b661a46c0343
T_413memory_resize_nonfree_smaller:3347c2c5fa6b9c968f20acb9b16d873e:passed:20131102-115507:0.066828215
T_414vc1_no_sequence_headers_before_key_frames:5a61903574b4e5eac70a29cea3192fcb:passed:20131115-164756:0.133015738
T_415create_webm:c1447a8f67f47a0b2d8c21d4208a8f98-5e1abfc5e13a44989a6ff31e51e9eaa9-8ba1b32bd84baef269181ea74cf06f0d-415d91e89e995b02b695e127617d2d8a-AAC@ok-AC3@ok-ALAC@ok-DivX@ok-h.264/AVC@ok-Dirac@ok-DTS@ok-FLV@ok-MP3@ok-MPEG1@ok-MPEG2@ok-PCM@ok-RV4@ok-SSA@ok-PGS@ok-SRT@ok-USF@ok-VC1@ok-WavPack4@ok:passed:20131218-221942:0.832721732
T_416dts_in_mp4:1c845a9e728c4d75d19af048fd0a82e0-6da8fbd8204f787da057c8f78ea05c10:passed:20131218-231435:1.398112245
T_416dts_in_mp4:5bfbf35118604b3ba48356fe3e548a94-6ba6630441824a035ce4950faa960360:passed:20131218-231435:1.398112245
T_417mkvextract_tracks_at_end_of_file:b3bb67d316e20da12926d5c1d628f6e5:passed:20131229-122704:0.04690235
T_418ac3_frame_size_0:b23aa6757e9417e78beae2eefe5174c5:passed:20131230-233047:4.297033387
T_419mov_pcm_sample_size_1_sample_table_empty:a0c597d9f15da1435a072b71123b4166:passed:20140101-221519:0.052961521
@ -302,12 +302,12 @@ T_453mp4_with_hevc:c0c41f1942550b8ae5fac8b93e914185:passed:20141231-125834:0.046
T_454mp4_dash:e2e5f8441f1dcf48256d49faa588b47c-01518029ec5ea87609b3fb388b2bd751:passed:20141231-214733:0.429881173
T_455he_aacv2_ps:2fbfac35fa7785f8e500f1708da4ec4f:passed:20150101-152553:0.075964546
T_456tta:4b92a305f440778a3128685cefd4bd5d-a3f2a14c15e709027c05445ac91b0659:passed:20150103-140714:0.148697252
T_457mpeg_ts_all_pmts_with_crc_errors:0fefd1b95985d5f5deea17d20e05f6e9:passed:20150104-133628:1.586689715
T_457mpeg_ts_all_pmts_with_crc_errors:def2b6534649332dfc1c7a81993abeaf:passed:20150104-133628:1.586689715
T_458pcm_big_endian_in_matroska:c83ea37c1a80696b342859467d863f2a:passed:20150202-193826:0.080955865
T_459append_chapters_same_uid_with_sub_chapters:656362feddd9e89d28df6078361bf9d0:passed:20150202-214722:0.072671062
T_460truehd:33f8c0f013c71529281179cf8669c567-33f8c0f013c71529281179cf8669c567-ab9b806b3de4e93c52e767f925111834-7c94959141b87e30e5e979c5b64fbb12-686246892eb6a9bde07537e5776dc5d6-ab9b806b3de4e93c52e767f925111834:passed:20150210-130114:10.654546371
T_461truehd_from_mpeg_ts:c1ee4dc0746b9a3bea90ab49dd65e6a1-29f5c91656812569fb5e1fdbbbf85c39-c7272bed949872038798042ebbd31a2e:passed:20150212-134650:22.377720277
T_462dtshd_reduce_to_core:c284b0e29c3b7040e14b89a7e4790ce1-1e8b4d2eac574607bbaa54e4b8eee9e0-1e8b4d2eac574607bbaa54e4b8eee9e0:passed:20150212-223839:1.367529862
T_462dtshd_reduce_to_core:5caa015da487793beb320ba0b9f9e886-1ae3abba650cf4cdea255522ee4c3b2f-1ae3abba650cf4cdea255522ee4c3b2f:passed:20150212-223839:1.367529862
T_463a_ms_acm_with_track_tags:7766fe047ed88b8561caa4fba7c40ea6-45aa68321f4c3785d2e38ddbfd7cd850:passed:20150218-142924:0.139369636
T_464mp4_mp3_track_sampling_rate_0:51ec17a6dcfae5d8ac0f5fcf44e31eb6-b2c1dca03505c75c694c0de113a450f6:passed:20150223-190257:0.939161518
T_465propedit_gaps_of_130_bytes:aaee6a36641e36dc3976c9e505b645da:passed:20150223-210006:0.085134008
@ -324,4 +324,4 @@ T_475quicktime_ima4_audio:2aeb5aae29cd929748e8e1a15ca436c5-eae3443c55c6faa56eef4
T_476hevc_append_and_set_default_duration:ef49c29a89868be324876ee88c9ab7e2:passed:20150323-142700:2.506816653
T_477ui_locale_sv_SE:23026ac2ed9767541e89f2261bcf8b60-fdb4e13e302aa9f0ac3a644289890769:passed:20150324-123356:0.061418784
T_478ui_locale_sr_RS:e82297022868c560a80c41513033ef39-2cdbfc8453e871653f2243f91e7a8fcb:passed:20150324-135220:0.061494353
T_479dts_7_1_channels:48b91cc459bbbca2c6ac1068c1111d87-c39dc5ec6980da422a1106c355371b98:passed:20150325-221521:0.561800769
T_479dts_7_1_channels:4f310bdab1c5d09d045dc7cfa6dfd620-22473473f925932cdbed04adc86bab0c:passed:20150325-221521:0.561800769