| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | 5 #ifndef MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| 6 #define MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | 6 #define MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| 7 | 7 |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "base/power_monitor/power_observer.h" |
| 9 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
| 10 #include "media/base/mac/videotoolbox_glue.h" | 11 #include "media/base/mac/videotoolbox_glue.h" |
| 11 #include "media/cast/sender/size_adaptable_video_encoder_base.h" | 12 #include "media/cast/sender/size_adaptable_video_encoder_base.h" |
| 12 #include "media/cast/sender/video_encoder.h" | 13 #include "media/cast/sender/video_encoder.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 namespace cast { | 16 namespace cast { |
| 16 | 17 |
| 17 // VideoToolbox implementation of the media::cast::VideoEncoder interface. | 18 // VideoToolbox implementation of the media::cast::VideoEncoder interface. |
| 18 // VideoToolbox makes no guarantees that it is thread safe, so this object is | 19 // VideoToolbox makes no guarantees that it is thread safe, so this object is |
| 19 // pinned to the thread on which it is constructed. Supports changing frame | 20 // pinned to the thread on which it is constructed. Supports changing frame |
| 20 // sizes directly. | 21 // sizes directly. Implements the base::PowerObserver interface to reset the |
| 21 class H264VideoToolboxEncoder : public VideoEncoder { | 22 // compression session when the host process is suspended. |
| 23 class H264VideoToolboxEncoder : public VideoEncoder, |
| 24 public base::PowerObserver { |
| 22 typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; | 25 typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; |
| 23 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; | 26 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; |
| 24 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; | 27 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; |
| 25 | 28 |
| 26 public: | 29 public: |
| 27 // Returns true if the current platform and system configuration supports | 30 // Returns true if the current platform and system configuration supports |
| 28 // using H264VideoToolboxEncoder with the given |video_config|. | 31 // using H264VideoToolboxEncoder with the given |video_config|. |
| 29 static bool IsSupported(const VideoSenderConfig& video_config); | 32 static bool IsSupported(const VideoSenderConfig& video_config); |
| 30 | 33 |
| 31 H264VideoToolboxEncoder( | 34 H264VideoToolboxEncoder( |
| 32 const scoped_refptr<CastEnvironment>& cast_environment, | 35 const scoped_refptr<CastEnvironment>& cast_environment, |
| 33 const VideoSenderConfig& video_config, | 36 const VideoSenderConfig& video_config, |
| 34 const StatusChangeCallback& status_change_cb); | 37 const StatusChangeCallback& status_change_cb); |
| 35 ~H264VideoToolboxEncoder() override; | 38 ~H264VideoToolboxEncoder() override; |
| 36 | 39 |
| 37 // media::cast::VideoEncoder implementation | 40 // media::cast::VideoEncoder implementation |
| 38 bool EncodeVideoFrame( | 41 bool EncodeVideoFrame( |
| 39 const scoped_refptr<media::VideoFrame>& video_frame, | 42 const scoped_refptr<media::VideoFrame>& video_frame, |
| 40 const base::TimeTicks& reference_time, | 43 const base::TimeTicks& reference_time, |
| 41 const FrameEncodedCallback& frame_encoded_callback) override; | 44 const FrameEncodedCallback& frame_encoded_callback) override; |
| 42 void SetBitRate(int new_bit_rate) override; | 45 void SetBitRate(int new_bit_rate) override; |
| 43 void GenerateKeyFrame() override; | 46 void GenerateKeyFrame() override; |
| 44 void LatestFrameIdToReference(uint32 frame_id) override; | 47 void LatestFrameIdToReference(uint32 frame_id) override; |
| 45 scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override; | 48 scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override; |
| 46 void EmitFrames() override; | 49 void EmitFrames() override; |
| 47 | 50 |
| 51 // base::PowerObserver |
| 52 void OnSuspend() override; |
| 53 void OnResume() override; |
| 54 |
| 48 private: | 55 private: |
| 49 // VideoFrameFactory tied to the VideoToolbox encoder. | 56 // VideoFrameFactory tied to the VideoToolbox encoder. |
| 50 class VideoFrameFactoryImpl; | 57 class VideoFrameFactoryImpl; |
| 51 | 58 |
| 52 // Reset the encoder's compression session by destroying the existing one | 59 // Reset the encoder's compression session by destroying the existing one |
| 53 // using DestroyCompressionSession() and creating a new one. The new session | 60 // using DestroyCompressionSession() and creating a new one. The new session |
| 54 // is configured using ConfigureCompressionSession(). | 61 // is configured using ConfigureCompressionSession(). |
| 55 void ResetCompressionSession(); | 62 void ResetCompressionSession(); |
| 56 | 63 |
| 57 // Configure the current compression session using current encoder settings. | 64 // Configure the current compression session using current encoder settings. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // NOTE: Weak pointers must be invalidated before all other member variables. | 121 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 115 base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_; | 122 base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_; |
| 116 | 123 |
| 117 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); | 124 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); |
| 118 }; | 125 }; |
| 119 | 126 |
| 120 } // namespace cast | 127 } // namespace cast |
| 121 } // namespace media | 128 } // namespace media |
| 122 | 129 |
| 123 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | 130 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| OLD | NEW |