blob: d3a11bd091d4074c365dd9c70bf39cb34293b87d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
marpan@webrtc.org9d76b4e2012-02-28 23:39:31 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Kjellander0f59a882015-11-18 22:31:24 +010011#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_
12#define WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010014#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander0f59a882015-11-18 22:31:24 +010015#include "webrtc/modules/video_processing/include/video_processing_defines.h"
pbos@webrtc.org6f3d8fc2013-05-27 14:12:16 +000016#include "webrtc/typedefs.h"
Thiago Farina9bfe3da2015-04-10 12:52:13 +020017#include "webrtc/video_frame.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
20
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000021class 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.com470e71d2011-07-07 08:21:25 +000027
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000028 // 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.com6d171c42011-08-15 15:56:23 +000033
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000034 // 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-Sanchez47650702015-05-29 17:21:40 -070038 VideoContentMetrics* ComputeContentMetrics(const VideoFrame& inputFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +000039
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000040 // Release all allocated memory
41 // Output: 0 if OK, negative value upon error
42 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000044 private:
45 // return motion metrics
46 VideoContentMetrics* ContentMetrics();
niklase@google.com470e71d2011-07-07 08:21:25 +000047
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000048 // Normalized temporal difference metric: for motion magnitude
49 typedef int32_t (VPMContentAnalysis::*TemporalDiffMetricFunc)();
50 TemporalDiffMetricFunc TemporalDiffMetric;
51 int32_t TemporalDiffMetric_C();
niklase@google.com470e71d2011-07-07 08:21:25 +000052
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000053 // Motion metric method: call 2 metrics (magnitude and size)
54 int32_t ComputeMotionMetrics();
niklase@google.com470e71d2011-07-07 08:21:25 +000055
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000056 // 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.com31f24de2011-08-17 22:23:28 +000061
andrew@webrtc.orgc8d012f2012-01-13 19:43:09 +000062#if defined(WEBRTC_ARCH_X86_FAMILY)
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000063 int32_t ComputeSpatialMetrics_SSE2();
64 int32_t TemporalDiffMetric_SSE2();
frkoenig@google.com6d171c42011-08-15 15:56:23 +000065#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000066
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000067 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.com470e71d2011-07-07 08:21:25 +000073
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000074 // Content Metrics: Stores the local average of the metrics.
mflodman99ab9442015-12-07 22:54:50 -080075 float motion_magnitude_; // motion class
76 float spatial_pred_err_; // spatial class
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000077 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.com6d171c42011-08-15 15:56:23 +000081
mflodman99ab9442015-12-07 22:54:50 -080082 VideoContentMetrics* content_metrics_;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000083};
niklase@google.com470e71d2011-07-07 08:21:25 +000084
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000085} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000086
Henrik Kjellander0f59a882015-11-18 22:31:24 +010087#endif // WEBRTC_MODULES_VIDEO_PROCESSING_CONTENT_ANALYSIS_H_