niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame^] | 11 | #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 14 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame^] | 15 | #include "webrtc/modules/video_processing/include/video_processing_defines.h" |
pbos@webrtc.org | 6f3d8fc | 2013-05-27 14:12:16 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
Thiago Farina | 9bfe3da | 2015-04-10 12:52:13 +0200 | [diff] [blame] | 17 | #include "webrtc/video_frame.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 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(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 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); |
frkoenig@google.com | 6d171c4 | 2011-08-15 15:56:23 +0000 | [diff] [blame] | 33 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 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 |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 38 | VideoContentMetrics* ComputeContentMetrics(const VideoFrame& inputFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 40 | // Release all allocated memory |
| 41 | // Output: 0 if OK, negative value upon error |
| 42 | int32_t Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 44 | private: |
| 45 | // return motion metrics |
| 46 | VideoContentMetrics* ContentMetrics(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 48 | // Normalized temporal difference metric: for motion magnitude |
| 49 | typedef int32_t (VPMContentAnalysis::*TemporalDiffMetricFunc)(); |
| 50 | TemporalDiffMetricFunc TemporalDiffMetric; |
| 51 | int32_t TemporalDiffMetric_C(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 53 | // Motion metric method: call 2 metrics (magnitude and size) |
| 54 | int32_t ComputeMotionMetrics(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 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(); |
frkoenig@google.com | 31f24de | 2011-08-17 22:23:28 +0000 | [diff] [blame] | 61 | |
andrew@webrtc.org | c8d012f | 2012-01-13 19:43:09 +0000 | [diff] [blame] | 62 | #if defined(WEBRTC_ARCH_X86_FAMILY) |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 63 | int32_t ComputeSpatialMetrics_SSE2(); |
| 64 | int32_t TemporalDiffMetric_SSE2(); |
frkoenig@google.com | 6d171c4 | 2011-08-15 15:56:23 +0000 | [diff] [blame] | 65 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 67 | const uint8_t* orig_frame_; |
| 68 | uint8_t* prev_frame_; |
| 69 | int width_; |
| 70 | int height_; |
| 71 | int skip_num_; |
| 72 | int border_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 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_; |
frkoenig@google.com | 6d171c4 | 2011-08-15 15:56:23 +0000 | [diff] [blame] | 81 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 82 | VideoContentMetrics* content_metrics_; |
| 83 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 85 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame^] | 87 | #endif // WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_ |