| 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 "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 14 #include "media/cast/cast_config.h" | 13 #include "media/cast/cast_config.h" |
| 15 #include "media/cast/cast_environment.h" | 14 #include "media/cast/cast_environment.h" |
| 16 #include "media/cast/constants.h" | 15 #include "media/cast/constants.h" |
| 17 #include "media/cast/sender/video_encoder.h" | 16 #include "media/cast/sender/video_encoder.h" |
| 18 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 19 | 18 |
| 20 namespace media { | 19 namespace media { |
| 21 namespace cast { | 20 namespace cast { |
| 22 | 21 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 | 33 |
| 35 ~SizeAdaptableVideoEncoderBase() override; | 34 ~SizeAdaptableVideoEncoderBase() override; |
| 36 | 35 |
| 37 // VideoEncoder implementation. | 36 // VideoEncoder implementation. |
| 38 bool EncodeVideoFrame( | 37 bool EncodeVideoFrame( |
| 39 const scoped_refptr<media::VideoFrame>& video_frame, | 38 const scoped_refptr<media::VideoFrame>& video_frame, |
| 40 const base::TimeTicks& reference_time, | 39 const base::TimeTicks& reference_time, |
| 41 const FrameEncodedCallback& frame_encoded_callback) final; | 40 const FrameEncodedCallback& frame_encoded_callback) final; |
| 42 void SetBitRate(int new_bit_rate) final; | 41 void SetBitRate(int new_bit_rate) final; |
| 43 void GenerateKeyFrame() final; | 42 void GenerateKeyFrame() final; |
| 44 scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() final; | 43 std::unique_ptr<VideoFrameFactory> CreateVideoFrameFactory() final; |
| 45 void EmitFrames() final; | 44 void EmitFrames() final; |
| 46 | 45 |
| 47 protected: | 46 protected: |
| 48 // Accessors for subclasses. | 47 // Accessors for subclasses. |
| 49 CastEnvironment* cast_environment() const { | 48 CastEnvironment* cast_environment() const { |
| 50 return cast_environment_.get(); | 49 return cast_environment_.get(); |
| 51 } | 50 } |
| 52 const VideoSenderConfig& video_config() const { | 51 const VideoSenderConfig& video_config() const { |
| 53 return video_config_; | 52 return video_config_; |
| 54 } | 53 } |
| 55 const gfx::Size& frame_size() const { | 54 const gfx::Size& frame_size() const { |
| 56 return frame_size_; | 55 return frame_size_; |
| 57 } | 56 } |
| 58 uint32_t last_frame_id() const { return last_frame_id_; } | 57 uint32_t last_frame_id() const { return last_frame_id_; } |
| 59 | 58 |
| 60 // Returns a callback that calls OnEncoderStatusChange(). The callback is | 59 // Returns a callback that calls OnEncoderStatusChange(). The callback is |
| 61 // canceled by invalidating its bound weak pointer just before a replacement | 60 // canceled by invalidating its bound weak pointer just before a replacement |
| 62 // encoder is instantiated. In this scheme, OnEncoderStatusChange() can only | 61 // encoder is instantiated. In this scheme, OnEncoderStatusChange() can only |
| 63 // be called by the most-recent encoder. | 62 // be called by the most-recent encoder. |
| 64 StatusChangeCallback CreateEncoderStatusChangeCallback(); | 63 StatusChangeCallback CreateEncoderStatusChangeCallback(); |
| 65 | 64 |
| 66 // Overridden by subclasses to create a new encoder instance that handles | 65 // Overridden by subclasses to create a new encoder instance that handles |
| 67 // frames of the size specified by |frame_size()|. | 66 // frames of the size specified by |frame_size()|. |
| 68 virtual scoped_ptr<VideoEncoder> CreateEncoder() = 0; | 67 virtual std::unique_ptr<VideoEncoder> CreateEncoder() = 0; |
| 69 | 68 |
| 70 // Overridden by subclasses to perform additional steps when | 69 // Overridden by subclasses to perform additional steps when |
| 71 // |replacement_encoder| becomes the active encoder. | 70 // |replacement_encoder| becomes the active encoder. |
| 72 virtual void OnEncoderReplaced(VideoEncoder* replacement_encoder); | 71 virtual void OnEncoderReplaced(VideoEncoder* replacement_encoder); |
| 73 | 72 |
| 74 // Overridden by subclasses to perform additional steps before/after the | 73 // Overridden by subclasses to perform additional steps before/after the |
| 75 // current encoder is destroyed. | 74 // current encoder is destroyed. |
| 76 virtual void DestroyEncoder(); | 75 virtual void DestroyEncoder(); |
| 77 | 76 |
| 78 private: | 77 private: |
| 79 // Create and initialize a replacement video encoder, if this not already | 78 // Create and initialize a replacement video encoder, if this not already |
| 80 // in-progress. The replacement will call back to OnEncoderStatusChange() | 79 // in-progress. The replacement will call back to OnEncoderStatusChange() |
| 81 // with success/fail status. | 80 // with success/fail status. |
| 82 void TrySpawningReplacementEncoder(const gfx::Size& size_needed); | 81 void TrySpawningReplacementEncoder(const gfx::Size& size_needed); |
| 83 | 82 |
| 84 // Called when a status change is received from an encoder. | 83 // Called when a status change is received from an encoder. |
| 85 void OnEncoderStatusChange(OperationalStatus status); | 84 void OnEncoderStatusChange(OperationalStatus status); |
| 86 | 85 |
| 87 // Called by the |encoder_| with the next EncodedFrame. | 86 // Called by the |encoder_| with the next EncodedFrame. |
| 88 void OnEncodedVideoFrame(const FrameEncodedCallback& frame_encoded_callback, | 87 void OnEncodedVideoFrame(const FrameEncodedCallback& frame_encoded_callback, |
| 89 scoped_ptr<SenderEncodedFrame> encoded_frame); | 88 std::unique_ptr<SenderEncodedFrame> encoded_frame); |
| 90 | 89 |
| 91 const scoped_refptr<CastEnvironment> cast_environment_; | 90 const scoped_refptr<CastEnvironment> cast_environment_; |
| 92 | 91 |
| 93 // This is not const since |video_config_.starting_bitrate| is modified by | 92 // This is not const since |video_config_.starting_bitrate| is modified by |
| 94 // SetBitRate(), for when a replacement encoder is spawned. | 93 // SetBitRate(), for when a replacement encoder is spawned. |
| 95 VideoSenderConfig video_config_; | 94 VideoSenderConfig video_config_; |
| 96 | 95 |
| 97 // Run whenever the underlying encoder reports a status change. | 96 // Run whenever the underlying encoder reports a status change. |
| 98 const StatusChangeCallback status_change_cb_; | 97 const StatusChangeCallback status_change_cb_; |
| 99 | 98 |
| 100 // The underlying platform video encoder and the frame size it expects. | 99 // The underlying platform video encoder and the frame size it expects. |
| 101 scoped_ptr<VideoEncoder> encoder_; | 100 std::unique_ptr<VideoEncoder> encoder_; |
| 102 gfx::Size frame_size_; | 101 gfx::Size frame_size_; |
| 103 | 102 |
| 104 // The number of frames in |encoder_|'s pipeline. If this is set to | 103 // The number of frames in |encoder_|'s pipeline. If this is set to |
| 105 // kEncoderIsInitializing, |encoder_| is not yet ready to accept frames. | 104 // kEncoderIsInitializing, |encoder_| is not yet ready to accept frames. |
| 106 enum { kEncoderIsInitializing = -1 }; | 105 enum { kEncoderIsInitializing = -1 }; |
| 107 int frames_in_encoder_; | 106 int frames_in_encoder_; |
| 108 | 107 |
| 109 // The ID of the last frame that was emitted from |encoder_|. | 108 // The ID of the last frame that was emitted from |encoder_|. |
| 110 uint32_t last_frame_id_; | 109 uint32_t last_frame_id_; |
| 111 | 110 |
| 112 // NOTE: Weak pointers must be invalidated before all other member variables. | 111 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 113 base::WeakPtrFactory<SizeAdaptableVideoEncoderBase> weak_factory_; | 112 base::WeakPtrFactory<SizeAdaptableVideoEncoderBase> weak_factory_; |
| 114 | 113 |
| 115 DISALLOW_COPY_AND_ASSIGN(SizeAdaptableVideoEncoderBase); | 114 DISALLOW_COPY_AND_ASSIGN(SizeAdaptableVideoEncoderBase); |
| 116 }; | 115 }; |
| 117 | 116 |
| 118 } // namespace cast | 117 } // namespace cast |
| 119 } // namespace media | 118 } // namespace media |
| 120 | 119 |
| 121 #endif // MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ | 120 #endif // MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_ |
| OLD | NEW |