Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/modules/video_processing/main/source/frame_preprocessor.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 4.0 KB
Line 
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#include "webrtc/modules/video_processing/main/source/frame_preprocessor.h"
12#include "webrtc/system_wrappers/interface/trace.h"
13
14namespace webrtc {
15
16VPMFramePreprocessor::VPMFramePreprocessor()
17    : id_(0),
18      content_metrics_(NULL),
19      max_frame_rate_(0),
20      resampled_frame_(),
21      enable_ca_(false),
22      frame_cnt_(0) {
23  spatial_resampler_ = new VPMSimpleSpatialResampler();
24  ca_ = new VPMContentAnalysis(true);
25  vd_ = new VPMVideoDecimator();
26}
27
28VPMFramePreprocessor::~VPMFramePreprocessor() {
29  Reset();
30  delete spatial_resampler_;
31  delete ca_;
32  delete vd_;
33}
34
35int32_t VPMFramePreprocessor::ChangeUniqueId(const int32_t id) {
36  id_ = id;
37  return VPM_OK;
38}
39
40void  VPMFramePreprocessor::Reset() {
41  ca_->Release();
42  vd_->Reset();
43  content_metrics_ = NULL;
44  spatial_resampler_->Reset();
45  enable_ca_ = false;
46  frame_cnt_ = 0;
47}
48
49
50void  VPMFramePreprocessor::EnableTemporalDecimation(bool enable) {
51  vd_->EnableTemporalDecimation(enable);
52}
53
54void VPMFramePreprocessor::EnableContentAnalysis(bool enable) {
55  enable_ca_ = enable;
56}
57
58void  VPMFramePreprocessor::SetInputFrameResampleMode(
59    VideoFrameResampling resampling_mode) {
60  spatial_resampler_->SetInputFrameResampleMode(resampling_mode);
61}
62
63int32_t VPMFramePreprocessor::SetMaxFramerate(uint32_t max_frame_rate) {
64  if (max_frame_rate == 0) return VPM_PARAMETER_ERROR;
65
66  // Max allowed frame_rate.
67  max_frame_rate_ = max_frame_rate;
68  return vd_->SetMaxFramerate(max_frame_rate);
69}
70
71int32_t VPMFramePreprocessor::SetTargetResolution(
72    uint32_t width, uint32_t height, uint32_t frame_rate) {
73  if ( (width == 0) || (height == 0) || (frame_rate == 0)) {
74    return VPM_PARAMETER_ERROR;
75  }
76  int32_t ret_val = 0;
77  ret_val = spatial_resampler_->SetTargetFrameSize(width, height);
78
79  if (ret_val < 0) return ret_val;
80
81  ret_val = vd_->SetTargetframe_rate(frame_rate);
82  if (ret_val < 0) return ret_val;
83
84  return VPM_OK;
85}
86
87void VPMFramePreprocessor::UpdateIncomingframe_rate() {
88  vd_->UpdateIncomingframe_rate();
89}
90
91uint32_t VPMFramePreprocessor::Decimatedframe_rate() {
92  return vd_->Decimatedframe_rate();
93}
94
95
96uint32_t VPMFramePreprocessor::DecimatedWidth() const {
97  return spatial_resampler_->TargetWidth();
98}
99
100
101uint32_t VPMFramePreprocessor::DecimatedHeight() const {
102  return spatial_resampler_->TargetHeight();
103}
104
105
106int32_t VPMFramePreprocessor::PreprocessFrame(const I420VideoFrame& frame,
107    I420VideoFrame** processed_frame) {
108  if (frame.IsZeroSize()) {
109    return VPM_PARAMETER_ERROR;
110  }
111
112  vd_->UpdateIncomingframe_rate();
113
114  if (vd_->DropFrame()) {
115    WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, id_,
116                 "Drop frame due to frame rate");
117    return 1;  // drop 1 frame
118  }
119
120  // Resizing incoming frame if needed. Otherwise, remains NULL.
121  // We are not allowed to resample the input frame (must make a copy of it).
122  *processed_frame = NULL;
123  if (spatial_resampler_->ApplyResample(frame.width(), frame.height()))  {
124    int32_t ret = spatial_resampler_->ResampleFrame(frame, &resampled_frame_);
125    if (ret != VPM_OK) return ret;
126    *processed_frame = &resampled_frame_;
127  }
128
129  // Perform content analysis on the frame to be encoded.
130  if (enable_ca_) {
131    // Compute new metrics every |kSkipFramesCA| frames, starting with
132    // the first frame.
133    if (frame_cnt_ % kSkipFrameCA == 0) {
134      if (*processed_frame == NULL)  {
135        content_metrics_ = ca_->ComputeContentMetrics(frame);
136      } else {
137        content_metrics_ = ca_->ComputeContentMetrics(resampled_frame_);
138      }
139    }
140    ++frame_cnt_;
141  }
142  return VPM_OK;
143}
144
145VideoContentMetrics* VPMFramePreprocessor::ContentMetrics() const {
146  return content_metrics_;
147}
148
149}  // namespace
Note: See TracBrowser for help on using the repository browser.