video_quality_analysis.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
  11. #define RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
  12. #include <stdio.h>
  13. #include <string>
  14. #include <vector>
  15. #include "api/scoped_refptr.h"
  16. #include "api/video/video_frame_buffer.h"
  17. #include "rtc_tools/video_file_reader.h"
  18. namespace webrtc {
  19. namespace test {
  20. struct AnalysisResult {
  21. AnalysisResult() {}
  22. AnalysisResult(int frame_number, double psnr_value, double ssim_value)
  23. : frame_number(frame_number),
  24. psnr_value(psnr_value),
  25. ssim_value(ssim_value) {}
  26. int frame_number;
  27. double psnr_value;
  28. double ssim_value;
  29. };
  30. struct ResultsContainer {
  31. ResultsContainer();
  32. ~ResultsContainer();
  33. std::vector<AnalysisResult> frames;
  34. int max_repeated_frames = 0;
  35. int max_skipped_frames = 0;
  36. int total_skipped_frames = 0;
  37. int decode_errors_ref = 0;
  38. int decode_errors_test = 0;
  39. };
  40. // A function to run the PSNR and SSIM analysis on the test file. The test file
  41. // comprises the frames that were captured during the quality measurement test.
  42. // There may be missing or duplicate frames. Also the frames start at a random
  43. // position in the original video. We also need to provide a map from test frame
  44. // indices to reference frame indices.
  45. std::vector<AnalysisResult> RunAnalysis(
  46. const rtc::scoped_refptr<webrtc::test::Video>& reference_video,
  47. const rtc::scoped_refptr<webrtc::test::Video>& test_video,
  48. const std::vector<size_t>& test_frame_indices);
  49. // Compute PSNR for an I420 buffer (all planes). The max return value (in the
  50. // case where the test and reference frames are exactly the same) will be 48.
  51. double Psnr(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
  52. const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
  53. // Compute SSIM for an I420 buffer (all planes). The max return value (in the
  54. // case where the test and reference frames are exactly the same) will be 1.
  55. double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
  56. const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
  57. // Prints the result from the analysis in Chromium performance
  58. // numbers compatible format to stdout. If the results object contains no frames
  59. // no output will be written.
  60. void PrintAnalysisResults(const std::string& label, ResultsContainer* results);
  61. // Similar to the above, but will print to the specified file handle.
  62. void PrintAnalysisResults(FILE* output,
  63. const std::string& label,
  64. ResultsContainer* results);
  65. struct Cluster {
  66. // Corresponding reference frame index for this cluster.
  67. size_t index;
  68. // The number of sequential frames that mapped to the same reference frame
  69. // index.
  70. int number_of_repeated_frames;
  71. };
  72. // Clusters sequentially repeated frames. For example, the sequence {100, 102,
  73. // 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}.
  74. std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices);
  75. // Get number of max sequentially repeated frames in the test video. This number
  76. // will be one if we only store unique frames in the test video.
  77. int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters);
  78. // Get the longest sequence of skipped reference frames. This corresponds to the
  79. // longest freeze in the test video.
  80. int GetMaxSkippedFrames(const std::vector<Cluster>& clusters);
  81. // Get total number of skipped frames in the test video.
  82. int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters);
  83. } // namespace test
  84. } // namespace webrtc
  85. #endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_