| 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 47e6c8fba7d55ab970b3da21812aa6e73cdeba04..fae7c0d40c9ba4773caf3fb323d4a47ae46317c0 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"
|
| @@ -300,6 +301,38 @@ class H264VideoToolboxEncoder::VideoFrameFactoryImpl::Proxy
|
| DISALLOW_COPY_AND_ASSIGN(Proxy);
|
| };
|
|
|
| +H264VideoToolboxEncoder::PowerObserver::PowerObserver(
|
| + H264VideoToolboxEncoder* encoder)
|
| + : encoder_(encoder) {
|
| + DCHECK(encoder_);
|
| + auto power_monitor = base::PowerMonitor::Get();
|
| + if (!power_monitor) {
|
| + DLOG(WARNING) << "No power monitor. Encoder may fail if power state change "
|
| + "goes undetected.";
|
| + return;
|
| + }
|
| + power_monitor->AddObserver(this);
|
| + VLOG(1) << "Registered for power state changes.";
|
| +}
|
| +
|
| +H264VideoToolboxEncoder::PowerObserver::~PowerObserver() {
|
| + auto power_monitor = base::PowerMonitor::Get();
|
| + if (power_monitor)
|
| + power_monitor->RemoveObserver(this);
|
| +}
|
| +
|
| +void H264VideoToolboxEncoder::PowerObserver::OnSuspend() {
|
| + VLOG(1)
|
| + << "OnSuspend: Emitting all frames and destroying compression session.";
|
| + encoder_->EmitFrames();
|
| + encoder_->DestroyCompressionSession();
|
| +}
|
| +
|
| +void H264VideoToolboxEncoder::PowerObserver::OnResume() {
|
| + VLOG(1) << "OnResume: Resetting compression session.";
|
| + encoder_->ResetCompressionSession();
|
| +}
|
| +
|
| // static
|
| bool H264VideoToolboxEncoder::IsSupported(
|
| const VideoSenderConfig& video_config) {
|
| @@ -314,6 +347,7 @@ H264VideoToolboxEncoder::H264VideoToolboxEncoder(
|
| videotoolbox_glue_(VideoToolboxGlue::Get()),
|
| video_config_(video_config),
|
| status_change_cb_(status_change_cb),
|
| + power_observer_(this),
|
| last_frame_id_(kStartFrameId),
|
| encode_next_frame_as_keyframe_(false),
|
| weak_factory_(this) {
|
|
|