summaryrefslogtreecommitdiffstats
path: root/remoting/codec
diff options
context:
space:
mode:
authoraconverse <aconverse@chromium.org>2015-05-15 19:05:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-16 02:05:52 +0000
commit8a3333697857a0125e5bb68a10e7ea2f83f35d3e (patch)
treeafe373edef767dbe063cc6fa18d8f8b7b4d75440 /remoting/codec
parent01e014cd8dfcb5a68736a4a426661a8585365b92 (diff)
downloadchromium_src-8a3333697857a0125e5bb68a10e7ea2f83f35d3e.zip
chromium_src-8a3333697857a0125e5bb68a10e7ea2f83f35d3e.tar.gz
chromium_src-8a3333697857a0125e5bb68a10e7ea2f83f35d3e.tar.bz2
Enable Cyclic Refresh for VP9.
Cyclic refresh allows the encoder to update already coded sections of the image at a higher quality. BUG=134202 Review URL: https://codereview.chromium.org/1092813003 Cr-Commit-Position: refs/heads/master@{#330265}
Diffstat (limited to 'remoting/codec')
-rw-r--r--remoting/codec/video_encoder_vpx.cc43
-rw-r--r--remoting/codec/video_encoder_vpx.h6
2 files changed, 46 insertions, 3 deletions
diff --git a/remoting/codec/video_encoder_vpx.cc b/remoting/codec/video_encoder_vpx.cc
index 724fbec..c74f0d8 100644
--- a/remoting/codec/video_encoder_vpx.cc
+++ b/remoting/codec/video_encoder_vpx.cc
@@ -39,6 +39,10 @@ const int kMacroBlockSize = 16;
const int kVp9I420ProfileNumber = 0;
const int kVp9I444ProfileNumber = 1;
+// Magic encoder constants for adaptive quantization strategy.
+const int kVp9AqModeNone = 0;
+const int kVp9AqModeCyclicRefresh = 3;
+
void SetCommonCodecParameters(vpx_codec_enc_cfg_t* config,
const webrtc::DesktopSize& size) {
// Use millisecond granularity time base.
@@ -137,6 +141,11 @@ void SetVp9CodecOptions(vpx_codec_ctx_t* codec, bool lossless_encode) {
ret = vpx_codec_control(
codec, VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN);
DCHECK_EQ(VPX_CODEC_OK, ret) << "Failed to set screen content mode";
+
+ // Set cyclic refresh (aka "top-off") only for lossy encoding.
+ int aq_mode = lossless_encode ? kVp9AqModeNone : kVp9AqModeCyclicRefresh;
+ ret = vpx_codec_control(codec, VP9E_SET_AQ_MODE, aq_mode);
+ DCHECK_EQ(VPX_CODEC_OK, ret) << "Failed to set aq mode";
}
void FreeImageIfMismatched(bool use_i444,
@@ -273,7 +282,7 @@ scoped_ptr<VideoPacket> VideoEncoderVpx::Encode(
PrepareImage(frame, &updated_region);
// Update active map based on updated region.
- PrepareActiveMap(updated_region);
+ SetActiveMapFromRegion(updated_region);
// Apply active map to the encoder.
vpx_active_map_t act_map;
@@ -293,6 +302,14 @@ scoped_ptr<VideoPacket> VideoEncoderVpx::Encode(
<< "Details: " << vpx_codec_error(codec_.get()) << "\n"
<< vpx_codec_error_detail(codec_.get());
+ if (use_vp9_ && !lossless_encode_) {
+ ret = vpx_codec_control(codec_.get(), VP9E_GET_ACTIVEMAP, &act_map);
+ DCHECK_EQ(ret, VPX_CODEC_OK)
+ << "Failed to fetch active map: "
+ << vpx_codec_err_to_string(ret) << "\n";
+ UpdateRegionFromActiveMap(&updated_region);
+ }
+
// Read the encoded data.
vpx_codec_iter_t iter = NULL;
bool got_data = false;
@@ -485,7 +502,7 @@ void VideoEncoderVpx::PrepareImage(const webrtc::DesktopFrame& frame,
}
}
-void VideoEncoderVpx::PrepareActiveMap(
+void VideoEncoderVpx::SetActiveMapFromRegion(
const webrtc::DesktopRegion& updated_region) {
// Clear active map first.
memset(active_map_.get(), 0, active_map_width_ * active_map_height_);
@@ -510,4 +527,26 @@ void VideoEncoderVpx::PrepareActiveMap(
}
}
+void VideoEncoderVpx::UpdateRegionFromActiveMap(
+ webrtc::DesktopRegion* updated_region) {
+ const uint8* map = active_map_.get();
+ for (int y = 0; y < active_map_height_; ++y) {
+ for (int x0 = 0; x0 < active_map_width_;) {
+ int x1 = x0;
+ for (; x1 < active_map_width_; ++x1) {
+ if (map[y * active_map_width_ + x1] == 0)
+ break;
+ }
+ if (x1 > x0) {
+ updated_region->AddRect(webrtc::DesktopRect::MakeLTRB(
+ kMacroBlockSize * x0, kMacroBlockSize * y, kMacroBlockSize * x1,
+ kMacroBlockSize * (y + 1)));
+ }
+ x0 = x1 + 1;
+ }
+ }
+ updated_region->IntersectWith(
+ webrtc::DesktopRect::MakeWH(image_->w, image_->h));
+}
+
} // namespace remoting
diff --git a/remoting/codec/video_encoder_vpx.h b/remoting/codec/video_encoder_vpx.h
index a7433a1..d8d39eb 100644
--- a/remoting/codec/video_encoder_vpx.h
+++ b/remoting/codec/video_encoder_vpx.h
@@ -47,7 +47,11 @@ class VideoEncoderVpx : public VideoEncoder {
// Updates the active map according to |updated_region|. Active map is then
// given to the encoder to speed up encoding.
- void PrepareActiveMap(const webrtc::DesktopRegion& updated_region);
+ void SetActiveMapFromRegion(const webrtc::DesktopRegion& updated_region);
+
+ // Adds areas changed in the most recent frame to |updated_region|. This
+ // includes both content changes and areas enhanced by cyclic refresh.
+ void UpdateRegionFromActiveMap(webrtc::DesktopRegion* updated_region);
// True if the encoder is for VP9, false for VP8.
const bool use_vp9_;