public.rs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /// Check if needed fields are still public.
  2. // This Source Code Form is subject to the terms of the Mozilla Public
  3. // License, v. 2.0. If a copy of the MPL was not distributed with this
  4. // file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. extern crate mp4parse as mp4;
  6. use std::io::{Cursor, Read};
  7. use std::fs::File;
  8. // Taken from https://github.com/GuillaumeGomez/audio-video-metadata/blob/9dff40f565af71d5502e03a2e78ae63df95cfd40/src/metadata.rs#L53
  9. #[test]
  10. fn public_api() {
  11. let mut fd = File::open("tests/minimal.mp4").expect("Unknown file");
  12. let mut buf = Vec::new();
  13. fd.read_to_end(&mut buf).expect("File error");
  14. let mut c = Cursor::new(&buf);
  15. let mut context = mp4::MediaContext::new();
  16. mp4::read_mp4(&mut c, &mut context).expect("read_mp4 failed");
  17. assert_eq!(context.timescale, Some(mp4::MediaTimeScale(1000)));
  18. for track in context.tracks {
  19. match track.data {
  20. Some(mp4::SampleEntry::Video(v)) => {
  21. // track part
  22. assert_eq!(track.duration, Some(mp4::TrackScaledTime(512, 0)));
  23. assert_eq!(track.empty_duration, Some(mp4::MediaScaledTime(0)));
  24. assert_eq!(track.media_time, Some(mp4::TrackScaledTime(0, 0)));
  25. assert_eq!(track.timescale, Some(mp4::TrackTimeScale(12800, 0)));
  26. assert_eq!(v.width, 320);
  27. assert_eq!(v.height, 240);
  28. // track.tkhd part
  29. let tkhd = track.tkhd.unwrap();
  30. assert_eq!(tkhd.disabled, false);
  31. assert_eq!(tkhd.duration, 40);
  32. assert_eq!(tkhd.width, 20971520);
  33. assert_eq!(tkhd.height, 15728640);
  34. // track.data part
  35. assert_eq!(match v.codec_specific {
  36. mp4::VideoCodecSpecific::AVCConfig(v) => {
  37. assert!(v.len() > 0);
  38. "AVC"
  39. }
  40. mp4::VideoCodecSpecific::VPxConfig(vpx) => {
  41. // We don't enter in here, we just check if fields are public.
  42. assert!(vpx.bit_depth > 0);
  43. assert!(vpx.color_space > 0);
  44. assert!(vpx.chroma_subsampling > 0);
  45. assert!(vpx.codec_init.len() > 0);
  46. "VPx"
  47. }
  48. }, "AVC");
  49. }
  50. Some(mp4::SampleEntry::Audio(a)) => {
  51. // track part
  52. assert_eq!(track.duration, Some(mp4::TrackScaledTime(2944, 1)));
  53. assert_eq!(track.empty_duration, Some(mp4::MediaScaledTime(0)));
  54. assert_eq!(track.media_time, Some(mp4::TrackScaledTime(1024, 1)));
  55. assert_eq!(track.timescale, Some(mp4::TrackTimeScale(48000, 1)));
  56. // track.tkhd part
  57. let tkhd = track.tkhd.unwrap();
  58. assert_eq!(tkhd.disabled, false);
  59. assert_eq!(tkhd.duration, 62);
  60. assert_eq!(tkhd.width, 0);
  61. assert_eq!(tkhd.height, 0);
  62. // track.data part
  63. assert_eq!(match a.codec_specific {
  64. mp4::AudioCodecSpecific::ES_Descriptor(v) => {
  65. assert!(v.len() > 0);
  66. "ES"
  67. }
  68. mp4::AudioCodecSpecific::FLACSpecificBox(_flac) => {
  69. // No public fields.
  70. "FLAC"
  71. }
  72. mp4::AudioCodecSpecific::OpusSpecificBox(opus) => {
  73. // We don't enter in here, we just check if fields are public.
  74. assert!(opus.version > 0);
  75. "Opus"
  76. }
  77. }, "ES");
  78. assert!(a.samplesize > 0);
  79. assert!(a.samplerate > 0);
  80. }
  81. Some(mp4::SampleEntry::Unknown) | None => {}
  82. }
  83. }
  84. }