dts.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/formats/mp4/dts.h"
  5. #include "base/logging.h"
  6. #include "media/base/bit_reader.h"
  7. #include "media/formats/mp4/rcheck.h"
  8. namespace media {
  9. namespace mp4 {
  10. DTS::DTS() = default;
  11. DTS::DTS(const DTS& other) = default;
  12. DTS::~DTS() = default;
  13. bool DTS::Parse(const std::vector<uint8_t>& data, MediaLog* media_log) {
  14. if (data.empty())
  15. return false;
  16. if (data.size() < (32 * 3 + 8 + 2 + 8) / 8)
  17. return false;
  18. // Parse ddts box using reader.
  19. BitReader reader(&data[0], data.size());
  20. // Parse Sample frequency
  21. RCHECK(reader.ReadBits(32, &dts_sampling_frequency_));
  22. // Parse Max Bitrate
  23. RCHECK(reader.ReadBits(32, &max_bitrate_));
  24. // Parse Avg Bitrate
  25. RCHECK(reader.ReadBits(32, &avg_bitrate_));
  26. // Parse PCM Sample Depth
  27. RCHECK(reader.ReadBits(8, &pcm_sample_depth_));
  28. // Parse Frame Duration
  29. uint8_t frame_duration_code = 0;
  30. RCHECK(reader.ReadBits(2, &frame_duration_code));
  31. switch (frame_duration_code) {
  32. case 0:
  33. frame_duration_ = 512;
  34. break;
  35. case 1:
  36. frame_duration_ = 1024;
  37. break;
  38. case 2:
  39. frame_duration_ = 2048;
  40. break;
  41. case 3:
  42. frame_duration_ = 4096;
  43. break;
  44. default:
  45. frame_duration_ = 0;
  46. break;
  47. }
  48. LogDtsParameters();
  49. return true;
  50. }
  51. int DTS::GetFrameDuration() const {
  52. return frame_duration_;
  53. }
  54. uint32_t DTS::GetDtsSamplingFrequency() const {
  55. return dts_sampling_frequency_;
  56. }
  57. uint32_t DTS::GetMaxBitrate() const {
  58. return max_bitrate_;
  59. }
  60. uint32_t DTS::GetAvgBitrate() const {
  61. return avg_bitrate_;
  62. }
  63. uint8_t DTS::GetPcmSampleDepth() const {
  64. return pcm_sample_depth_;
  65. }
  66. void DTS::LogDtsParameters() {
  67. DVLOG(3) << "dts_sampling_freq " << dts_sampling_frequency_ << "max_bitrate "
  68. << max_bitrate_ << "avg_bitrate " << avg_bitrate_
  69. << "pcm_sample_depth " << static_cast<int>(pcm_sample_depth_)
  70. << "frame_duration " << frame_duration_;
  71. }
  72. } // namespace mp4
  73. } // namespace media