| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/power_monitor/power_observer.h" | 12 #include "base/power_monitor/power_observer.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "media/base/mac/videotoolbox_glue.h" | |
| 15 #include "media/base/mac/videotoolbox_helpers.h" | 14 #include "media/base/mac/videotoolbox_helpers.h" |
| 16 #include "media/cast/sender/size_adaptable_video_encoder_base.h" | 15 #include "media/cast/sender/size_adaptable_video_encoder_base.h" |
| 17 #include "media/cast/sender/video_encoder.h" | 16 #include "media/cast/sender/video_encoder.h" |
| 18 | 17 |
| 19 namespace media { | 18 namespace media { |
| 20 namespace cast { | 19 namespace cast { |
| 21 | 20 |
| 22 // VideoToolbox implementation of the media::cast::VideoEncoder interface. | 21 // VideoToolbox implementation of the media::cast::VideoEncoder interface. |
| 23 // VideoToolbox makes no guarantees that it is thread safe, so this object is | 22 // VideoToolbox makes no guarantees that it is thread safe, so this object is |
| 24 // pinned to the thread on which it is constructed. Supports changing frame | 23 // pinned to the thread on which it is constructed. Supports changing frame |
| 25 // sizes directly. Implements the base::PowerObserver interface to reset the | 24 // sizes directly. Implements the base::PowerObserver interface to reset the |
| 26 // compression session when the host process is suspended. | 25 // compression session when the host process is suspended. |
| 27 class H264VideoToolboxEncoder : public VideoEncoder, | 26 class H264VideoToolboxEncoder : public VideoEncoder, |
| 28 public base::PowerObserver { | 27 public base::PowerObserver { |
| 29 typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; | |
| 30 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; | |
| 31 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; | |
| 32 | |
| 33 public: | 28 public: |
| 34 // Returns true if the current platform and system configuration supports | 29 // Returns true if the current platform and system configuration supports |
| 35 // using H264VideoToolboxEncoder with the given |video_config|. | 30 // using H264VideoToolboxEncoder with the given |video_config|. |
| 36 static bool IsSupported(const FrameSenderConfig& video_config); | 31 static bool IsSupported(const FrameSenderConfig& video_config); |
| 37 | 32 |
| 38 H264VideoToolboxEncoder( | 33 H264VideoToolboxEncoder( |
| 39 const scoped_refptr<CastEnvironment>& cast_environment, | 34 const scoped_refptr<CastEnvironment>& cast_environment, |
| 40 const FrameSenderConfig& video_config, | 35 const FrameSenderConfig& video_config, |
| 41 const StatusChangeCallback& status_change_cb); | 36 const StatusChangeCallback& status_change_cb); |
| 42 ~H264VideoToolboxEncoder() final; | 37 ~H264VideoToolboxEncoder() final; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // Compression session callback function to handle compressed frames. | 74 // Compression session callback function to handle compressed frames. |
| 80 static void CompressionCallback(void* encoder_opaque, | 75 static void CompressionCallback(void* encoder_opaque, |
| 81 void* request_opaque, | 76 void* request_opaque, |
| 82 OSStatus status, | 77 OSStatus status, |
| 83 VTEncodeInfoFlags info, | 78 VTEncodeInfoFlags info, |
| 84 CMSampleBufferRef sbuf); | 79 CMSampleBufferRef sbuf); |
| 85 | 80 |
| 86 // The cast environment (contains worker threads & more). | 81 // The cast environment (contains worker threads & more). |
| 87 const scoped_refptr<CastEnvironment> cast_environment_; | 82 const scoped_refptr<CastEnvironment> cast_environment_; |
| 88 | 83 |
| 89 // VideoToolboxGlue provides access to VideoToolbox at runtime. | |
| 90 const VideoToolboxGlue* const videotoolbox_glue_; | |
| 91 | |
| 92 // VideoSenderConfig copy so we can create compression sessions on demand. | 84 // VideoSenderConfig copy so we can create compression sessions on demand. |
| 93 // This is needed to recover from backgrounding and other events that can | 85 // This is needed to recover from backgrounding and other events that can |
| 94 // invalidate compression sessions. | 86 // invalidate compression sessions. |
| 95 const FrameSenderConfig video_config_; | 87 const FrameSenderConfig video_config_; |
| 96 | 88 |
| 97 // Frame size of the current compression session. Can be changed by submitting | 89 // Frame size of the current compression session. Can be changed by submitting |
| 98 // a frame of a different size, which will cause a compression session reset. | 90 // a frame of a different size, which will cause a compression session reset. |
| 99 gfx::Size frame_size_; | 91 gfx::Size frame_size_; |
| 100 | 92 |
| 101 // Callback used to report initialization status and runtime errors. | 93 // Callback used to report initialization status and runtime errors. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 122 // NOTE: Weak pointers must be invalidated before all other member variables. | 114 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 123 base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_; | 115 base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_; |
| 124 | 116 |
| 125 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); | 117 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); |
| 126 }; | 118 }; |
| 127 | 119 |
| 128 } // namespace cast | 120 } // namespace cast |
| 129 } // namespace media | 121 } // namespace media |
| 130 | 122 |
| 131 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | 123 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| OLD | NEW |