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_CONTENT_ANALYSIS_H_
12 #define WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_
13 
14 #include "webrtc/modules/include/module_common_types.h"
15 #include "webrtc/modules/video_processing/include/video_processing_defines.h"
16 #include "webrtc/typedefs.h"
17 #include "webrtc/video_frame.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 VideoFrame& inputFrame);
39 
40   // Release all allocated memory
41   // Output: 0 if OK, negative value upon error
42   int32_t Release();
43 
44  private:
45   // return motion metrics
46   VideoContentMetrics* ContentMetrics();
47 
48   // Normalized temporal difference metric: for motion magnitude
49   typedef int32_t (VPMContentAnalysis::*TemporalDiffMetricFunc)();
50   TemporalDiffMetricFunc TemporalDiffMetric;
51   int32_t TemporalDiffMetric_C();
52 
53   // Motion metric method: call 2 metrics (magnitude and size)
54   int32_t ComputeMotionMetrics();
55 
56   // Spatial metric method: computes the 3 frame-average spatial
57   //  prediction errors (1x2,2x1,2x2)
58   typedef int32_t (VPMContentAnalysis::*ComputeSpatialMetricsFunc)();
59   ComputeSpatialMetricsFunc ComputeSpatialMetrics;
60   int32_t ComputeSpatialMetrics_C();
61 
62 #if defined(WEBRTC_ARCH_X86_FAMILY)
63   int32_t ComputeSpatialMetrics_SSE2();
64   int32_t TemporalDiffMetric_SSE2();
65 #endif
66 
67   const uint8_t* orig_frame_;
68   uint8_t* prev_frame_;
69   int width_;
70   int height_;
71   int skip_num_;
72   int border_;
73 
74   // Content Metrics: Stores the local average of the metrics.
75   float motion_magnitude_;    // motion class
76   float spatial_pred_err_;    // spatial class
77   float spatial_pred_err_h_;  // spatial class
78   float spatial_pred_err_v_;  // spatial class
79   bool first_frame_;
80   bool ca_Init_;
81 
82   VideoContentMetrics* content_metrics_;
83 };
84 
85 }  // namespace webrtc
86 
87 #endif  // WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_
88