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