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 11 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_SOURCE_CONTENT_ANALYSIS_H 12 #define WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_SOURCE_CONTENT_ANALYSIS_H 13 14 #include "webrtc/common_video/interface/i420_video_frame.h" 15 #include "webrtc/modules/interface/module_common_types.h" 16 #include "webrtc/modules/video_processing/main/interface/video_processing_defines.h" 17 #include "webrtc/typedefs.h" 18 19 namespace webrtc { 20 21 class VPMContentAnalysis { 22 public: 23 // When |runtime_cpu_detection| is true, runtime selection of an optimized 24 // code path is allowed. 25 explicit VPMContentAnalysis(bool runtime_cpu_detection); 26 ~VPMContentAnalysis(); 27 28 // Initialize ContentAnalysis - should be called prior to 29 // extractContentFeature 30 // Inputs: width, height 31 // Return value: 0 if OK, negative value upon error 32 int32_t Initialize(int width, int height); 33 34 // Extract content Feature - main function of ContentAnalysis 35 // Input: new frame 36 // Return value: pointer to structure containing content Analysis 37 // metrics or NULL value upon error 38 VideoContentMetrics* ComputeContentMetrics(const I420VideoFrame& 39 inputFrame); 40 41 // Release all allocated memory 42 // Output: 0 if OK, negative value upon error 43 int32_t Release(); 44 45 private: 46 // return motion metrics 47 VideoContentMetrics* ContentMetrics(); 48 49 // Normalized temporal difference metric: for motion magnitude 50 typedef int32_t (VPMContentAnalysis::*TemporalDiffMetricFunc)(); 51 TemporalDiffMetricFunc TemporalDiffMetric; 52 int32_t TemporalDiffMetric_C(); 53 54 // Motion metric method: call 2 metrics (magnitude and size) 55 int32_t ComputeMotionMetrics(); 56 57 // Spatial metric method: computes the 3 frame-average spatial 58 // prediction errors (1x2,2x1,2x2) 59 typedef int32_t (VPMContentAnalysis::*ComputeSpatialMetricsFunc)(); 60 ComputeSpatialMetricsFunc ComputeSpatialMetrics; 61 int32_t ComputeSpatialMetrics_C(); 62 63 #if defined(WEBRTC_ARCH_X86_FAMILY) 64 int32_t ComputeSpatialMetrics_SSE2(); 65 int32_t TemporalDiffMetric_SSE2(); 66 #endif 67 68 const uint8_t* orig_frame_; 69 uint8_t* prev_frame_; 70 int width_; 71 int height_; 72 int skip_num_; 73 int border_; 74 75 // Content Metrics: Stores the local average of the metrics. 76 float motion_magnitude_; // motion class 77 float spatial_pred_err_; // spatial class 78 float spatial_pred_err_h_; // spatial class 79 float spatial_pred_err_v_; // spatial class 80 bool first_frame_; 81 bool ca_Init_; 82 83 VideoContentMetrics* content_metrics_; 84 }; 85 86 } // namespace webrtc 87 88 #endif // WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_SOURCE_CONTENT_ANALYSIS_H 89