Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: media/cast/sender/h264_vt_encoder.cc

Issue 1094403002: Add power monitoring to the Cast VideoToolbox encoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move PowerObserver implementation directly in the encoder. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cast/sender/h264_vt_encoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cast/sender/h264_vt_encoder.cc
diff --git a/media/cast/sender/h264_vt_encoder.cc b/media/cast/sender/h264_vt_encoder.cc
index 346f96fa1d40473e48483238e961014141867153..b5eabeba2756107701182de4dd0642e52f9db8b6 100644
--- a/media/cast/sender/h264_vt_encoder.cc
+++ b/media/cast/sender/h264_vt_encoder.cc
@@ -13,6 +13,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/synchronization/lock.h"
#include "media/base/mac/corevideo_glue.h"
#include "media/base/mac/video_frame_mac.h"
@@ -333,10 +334,23 @@ H264VideoToolboxEncoder::H264VideoToolboxEncoder(
scoped_refptr<VideoFrameFactoryImpl>(new VideoFrameFactoryImpl(
weak_factory_.GetWeakPtr(), cast_environment_));
}
+
+ // Register for power state changes.
+ auto power_monitor = base::PowerMonitor::Get();
+ if (power_monitor) {
+ power_monitor->AddObserver(this);
+ VLOG(1) << "Registered for power state changes.";
+ } else {
+ DLOG(WARNING) << "No power monitor. Encoder may fail if power state change "
+ "goes undetected.";
+ }
}
H264VideoToolboxEncoder::~H264VideoToolboxEncoder() {
DestroyCompressionSession();
+ auto power_monitor = base::PowerMonitor::Get();
+ if (power_monitor)
+ power_monitor->RemoveObserver(this);
}
void H264VideoToolboxEncoder::ResetCompressionSession() {
@@ -609,6 +623,18 @@ void H264VideoToolboxEncoder::EmitFrames() {
}
}
+void H264VideoToolboxEncoder::OnSuspend() {
+ VLOG(1)
+ << "OnSuspend: Emitting all frames and destroying compression session.";
+ EmitFrames();
+ DestroyCompressionSession();
+}
+
+void H264VideoToolboxEncoder::OnResume() {
+ VLOG(1) << "OnResume: Resetting compression session.";
+ ResetCompressionSession();
miu 2015/04/22 18:18:47 I just realized: You shouldn't call ResetCompressi
jfroy 2015/04/22 18:24:36 Thanks for pointing this out. I'll update the code
+}
+
bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key,
int32_t value) {
base::ScopedCFTypeRef<CFNumberRef> cfvalue(
« no previous file with comments | « media/cast/sender/h264_vt_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698