| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ | 5 #ifndef MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ |
| 6 #define MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ | 6 #define MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // Creates and owns a VideoEncoder instance. The owned instance is an | 24 // Creates and owns a VideoEncoder instance. The owned instance is an |
| 25 // implementation that does not support changing frame sizes, and so | 25 // implementation that does not support changing frame sizes, and so |
| 26 // SizeAdaptableVideoEncoderBase acts as a proxy to automatically detect when | 26 // SizeAdaptableVideoEncoderBase acts as a proxy to automatically detect when |
| 27 // the owned instance should be replaced with one that can handle the new frame | 27 // the owned instance should be replaced with one that can handle the new frame |
| 28 // size. | 28 // size. |
| 29 class SizeAdaptableVideoEncoderBase : public VideoEncoder { | 29 class SizeAdaptableVideoEncoderBase : public VideoEncoder { |
| 30 public: | 30 public: |
| 31 SizeAdaptableVideoEncoderBase( | 31 SizeAdaptableVideoEncoderBase( |
| 32 const scoped_refptr<CastEnvironment>& cast_environment, | 32 const scoped_refptr<CastEnvironment>& cast_environment, |
| 33 const FrameSenderConfig& video_config, | 33 const VideoSenderConfig& video_config, |
| 34 const StatusChangeCallback& status_change_cb); | 34 const StatusChangeCallback& status_change_cb); |
| 35 | 35 |
| 36 ~SizeAdaptableVideoEncoderBase() override; | 36 ~SizeAdaptableVideoEncoderBase() override; |
| 37 | 37 |
| 38 // VideoEncoder implementation. | 38 // VideoEncoder implementation. |
| 39 bool EncodeVideoFrame( | 39 bool EncodeVideoFrame( |
| 40 const scoped_refptr<media::VideoFrame>& video_frame, | 40 const scoped_refptr<media::VideoFrame>& video_frame, |
| 41 const base::TimeTicks& reference_time, | 41 const base::TimeTicks& reference_time, |
| 42 const FrameEncodedCallback& frame_encoded_callback) final; | 42 const FrameEncodedCallback& frame_encoded_callback) final; |
| 43 void SetBitRate(int new_bit_rate) final; | 43 void SetBitRate(int new_bit_rate) final; |
| 44 void GenerateKeyFrame() final; | 44 void GenerateKeyFrame() final; |
| 45 std::unique_ptr<VideoFrameFactory> CreateVideoFrameFactory() final; | 45 std::unique_ptr<VideoFrameFactory> CreateVideoFrameFactory() final; |
| 46 void EmitFrames() final; | 46 void EmitFrames() final; |
| 47 | 47 |
| 48 protected: | 48 protected: |
| 49 // Accessors for subclasses. | 49 // Accessors for subclasses. |
| 50 CastEnvironment* cast_environment() const { | 50 CastEnvironment* cast_environment() const { |
| 51 return cast_environment_.get(); | 51 return cast_environment_.get(); |
| 52 } | 52 } |
| 53 const FrameSenderConfig& video_config() const { return video_config_; } | 53 const VideoSenderConfig& video_config() const { |
| 54 return video_config_; |
| 55 } |
| 54 const gfx::Size& frame_size() const { | 56 const gfx::Size& frame_size() const { |
| 55 return frame_size_; | 57 return frame_size_; |
| 56 } | 58 } |
| 57 FrameId next_frame_id() const { return next_frame_id_; } | 59 FrameId next_frame_id() const { return next_frame_id_; } |
| 58 | 60 |
| 59 // Returns a callback that calls OnEncoderStatusChange(). The callback is | 61 // Returns a callback that calls OnEncoderStatusChange(). The callback is |
| 60 // canceled by invalidating its bound weak pointer just before a replacement | 62 // canceled by invalidating its bound weak pointer just before a replacement |
| 61 // encoder is instantiated. In this scheme, OnEncoderStatusChange() can only | 63 // encoder is instantiated. In this scheme, OnEncoderStatusChange() can only |
| 62 // be called by the most-recent encoder. | 64 // be called by the most-recent encoder. |
| 63 StatusChangeCallback CreateEncoderStatusChangeCallback(); | 65 StatusChangeCallback CreateEncoderStatusChangeCallback(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 void OnEncoderStatusChange(OperationalStatus status); | 86 void OnEncoderStatusChange(OperationalStatus status); |
| 85 | 87 |
| 86 // Called by the |encoder_| with the next EncodedFrame. | 88 // Called by the |encoder_| with the next EncodedFrame. |
| 87 void OnEncodedVideoFrame(const FrameEncodedCallback& frame_encoded_callback, | 89 void OnEncodedVideoFrame(const FrameEncodedCallback& frame_encoded_callback, |
| 88 std::unique_ptr<SenderEncodedFrame> encoded_frame); | 90 std::unique_ptr<SenderEncodedFrame> encoded_frame); |
| 89 | 91 |
| 90 const scoped_refptr<CastEnvironment> cast_environment_; | 92 const scoped_refptr<CastEnvironment> cast_environment_; |
| 91 | 93 |
| 92 // This is not const since |video_config_.starting_bitrate| is modified by | 94 // This is not const since |video_config_.starting_bitrate| is modified by |
| 93 // SetBitRate(), for when a replacement encoder is spawned. | 95 // SetBitRate(), for when a replacement encoder is spawned. |
| 94 FrameSenderConfig video_config_; | 96 VideoSenderConfig video_config_; |
| 95 | 97 |
| 96 // Run whenever the underlying encoder reports a status change. | 98 // Run whenever the underlying encoder reports a status change. |
| 97 const StatusChangeCallback status_change_cb_; | 99 const StatusChangeCallback status_change_cb_; |
| 98 | 100 |
| 99 // The underlying platform video encoder and the frame size it expects. | 101 // The underlying platform video encoder and the frame size it expects. |
| 100 std::unique_ptr<VideoEncoder> encoder_; | 102 std::unique_ptr<VideoEncoder> encoder_; |
| 101 gfx::Size frame_size_; | 103 gfx::Size frame_size_; |
| 102 | 104 |
| 103 // The number of frames in |encoder_|'s pipeline. If this is set to | 105 // The number of frames in |encoder_|'s pipeline. If this is set to |
| 104 // kEncoderIsInitializing, |encoder_| is not yet ready to accept frames. | 106 // kEncoderIsInitializing, |encoder_| is not yet ready to accept frames. |
| 105 enum { kEncoderIsInitializing = -1 }; | 107 enum { kEncoderIsInitializing = -1 }; |
| 106 int frames_in_encoder_; | 108 int frames_in_encoder_; |
| 107 | 109 |
| 108 // The ID for the next frame to be emitted. | 110 // The ID for the next frame to be emitted. |
| 109 FrameId next_frame_id_; | 111 FrameId next_frame_id_; |
| 110 | 112 |
| 111 // NOTE: Weak pointers must be invalidated before all other member variables. | 113 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 112 base::WeakPtrFactory<SizeAdaptableVideoEncoderBase> weak_factory_; | 114 base::WeakPtrFactory<SizeAdaptableVideoEncoderBase> weak_factory_; |
| 113 | 115 |
| 114 DISALLOW_COPY_AND_ASSIGN(SizeAdaptableVideoEncoderBase); | 116 DISALLOW_COPY_AND_ASSIGN(SizeAdaptableVideoEncoderBase); |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 } // namespace cast | 119 } // namespace cast |
| 118 } // namespace media | 120 } // namespace media |
| 119 | 121 |
| 120 #endif // MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ | 122 #endif // MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ |
| OLD | NEW |