Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1139)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h

Issue 2830793005: Reuse allocated encoders in SimulcastEncoderAdapter. (Closed)
Patch Set: holmer comments 1: use stack instead of vector. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 * 9 *
10 */ 10 */
11 11
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_
14 14
15 #include <memory> 15 #include <memory>
16 #include <stack>
16 #include <string> 17 #include <string>
18 #include <utility>
17 #include <vector> 19 #include <vector>
18 20
21 #include "webrtc/base/criticalsection.h"
22 #include "webrtc/base/sequenced_task_checker.h"
19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 23 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
20 24
21 namespace webrtc { 25 namespace webrtc {
22 26
23 class SimulcastRateAllocator; 27 class SimulcastRateAllocator;
24 28
29 // TODO(brandtr): Remove this class and replace its use with a
30 // WebRtcVideoEncoderFactory.
25 class VideoEncoderFactory { 31 class VideoEncoderFactory {
26 public: 32 public:
27 virtual VideoEncoder* Create() = 0; 33 virtual VideoEncoder* Create() = 0;
28 virtual void Destroy(VideoEncoder* encoder) = 0; 34 virtual void Destroy(VideoEncoder* encoder) = 0;
29 virtual ~VideoEncoderFactory() {} 35 virtual ~VideoEncoderFactory() {}
30 }; 36 };
31 37
32 // SimulcastEncoderAdapter implements simulcast support by creating multiple 38 // SimulcastEncoderAdapter implements simulcast support by creating multiple
33 // webrtc::VideoEncoder instances with the given VideoEncoderFactory. 39 // webrtc::VideoEncoder instances with the given VideoEncoderFactory.
34 // All the public interfaces are expected to be called from the same thread, 40 // The object is created and destroyed on the worker thread, but all public
35 // e.g the encoder thread. 41 // interfaces should be called from the encoder task queue.
36 class SimulcastEncoderAdapter : public VP8Encoder { 42 class SimulcastEncoderAdapter : public VP8Encoder {
37 public: 43 public:
38 explicit SimulcastEncoderAdapter(VideoEncoderFactory* factory); 44 explicit SimulcastEncoderAdapter(VideoEncoderFactory* factory);
39 virtual ~SimulcastEncoderAdapter(); 45 virtual ~SimulcastEncoderAdapter();
40 46
41 // Implements VideoEncoder 47 // Implements VideoEncoder.
42 int Release() override; 48 int Release() override;
43 int InitEncode(const VideoCodec* inst, 49 int InitEncode(const VideoCodec* inst,
44 int number_of_cores, 50 int number_of_cores,
45 size_t max_payload_size) override; 51 size_t max_payload_size) override;
46 int Encode(const VideoFrame& input_image, 52 int Encode(const VideoFrame& input_image,
47 const CodecSpecificInfo* codec_specific_info, 53 const CodecSpecificInfo* codec_specific_info,
48 const std::vector<FrameType>* frame_types) override; 54 const std::vector<FrameType>* frame_types) override;
49 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; 55 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
50 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; 56 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
51 int SetRateAllocation(const BitrateAllocation& bitrate, 57 int SetRateAllocation(const BitrateAllocation& bitrate,
52 uint32_t new_framerate) override; 58 uint32_t new_framerate) override;
53 59
54 // Eventual handler for the contained encoders' EncodedImageCallbacks, but 60 // Eventual handler for the contained encoders' EncodedImageCallbacks, but
55 // called from an internal helper that also knows the correct stream 61 // called from an internal helper that also knows the correct stream
56 // index. 62 // index.
57 EncodedImageCallback::Result OnEncodedImage( 63 EncodedImageCallback::Result OnEncodedImage(
58 size_t stream_idx, 64 size_t stream_idx,
59 const EncodedImage& encoded_image, 65 const EncodedImage& encoded_image,
60 const CodecSpecificInfo* codec_specific_info, 66 const CodecSpecificInfo* codec_specific_info,
61 const RTPFragmentationHeader* fragmentation); 67 const RTPFragmentationHeader* fragmentation);
62 68
63 VideoEncoder::ScalingSettings GetScalingSettings() const override; 69 VideoEncoder::ScalingSettings GetScalingSettings() const override;
64 70
65 bool SupportsNativeHandle() const override; 71 bool SupportsNativeHandle() const override;
66 const char* ImplementationName() const override; 72 const char* ImplementationName() const override;
67 73
68 private: 74 private:
69 struct StreamInfo { 75 struct StreamInfo {
70 StreamInfo()
71 : encoder(NULL),
72 callback(NULL),
73 width(0),
74 height(0),
75 key_frame_request(false),
76 send_stream(true) {}
77 StreamInfo(VideoEncoder* encoder, 76 StreamInfo(VideoEncoder* encoder,
78 EncodedImageCallback* callback, 77 std::unique_ptr<EncodedImageCallback> callback,
79 uint16_t width, 78 uint16_t width,
80 uint16_t height, 79 uint16_t height,
81 bool send_stream) 80 bool send_stream)
82 : encoder(encoder), 81 : encoder(encoder),
83 callback(callback), 82 callback(std::move(callback)),
84 width(width), 83 width(width),
85 height(height), 84 height(height),
86 key_frame_request(false), 85 key_frame_request(false),
87 send_stream(send_stream) {} 86 send_stream(send_stream) {}
88 // Deleted by SimulcastEncoderAdapter::Release(). 87 // Deleted by SimulcastEncoderAdapter::DestroyStoredEncoders().
89 VideoEncoder* encoder; 88 VideoEncoder* encoder;
90 EncodedImageCallback* callback; 89 std::unique_ptr<EncodedImageCallback> callback;
91 uint16_t width; 90 uint16_t width;
92 uint16_t height; 91 uint16_t height;
93 bool key_frame_request; 92 bool key_frame_request;
94 bool send_stream; 93 bool send_stream;
95 }; 94 };
96 95
97 // Populate the codec settings for each stream. 96 // Populate the codec settings for each simulcast stream.
98 void PopulateStreamCodec(const webrtc::VideoCodec* inst, 97 static void PopulateStreamCodec(const webrtc::VideoCodec& inst,
99 int stream_index, 98 int stream_index,
100 uint32_t start_bitrate_kbps, 99 uint32_t start_bitrate_kbps,
101 bool highest_resolution_stream, 100 bool highest_resolution_stream,
102 webrtc::VideoCodec* stream_codec); 101 webrtc::VideoCodec* stream_codec);
103 102
104 bool Initialized() const; 103 bool Initialized() const;
105 104
106 std::unique_ptr<VideoEncoderFactory> factory_; 105 void DestroyStoredEncoders();
106
107 #if RTC_DCHECK_IS_ON
108 // Used for protecting |inited_| in debug builds. This is necessary for the
109 // DHECK in the destructor, as the object is created/destroyed on a different
110 // thread that it is being operated on.
111 rtc::CriticalSection inited_crit_;
112 #endif
sprang_webrtc 2017/05/11 11:53:36 Maybe you can use an atomic instead?
brandtr 2017/05/15 10:12:01 Would be nice to not have this lock here at all. I
sprang_webrtc 2017/05/15 12:03:39 rtc::AtomicOps::AcquireLoad and rtc::AtomicOps::Re
113
114 bool inited_;
115 const std::unique_ptr<VideoEncoderFactory> factory_;
107 VideoCodec codec_; 116 VideoCodec codec_;
108 std::vector<StreamInfo> streaminfos_; 117 std::vector<StreamInfo> streaminfos_;
109 EncodedImageCallback* encoded_complete_callback_; 118 EncodedImageCallback* encoded_complete_callback_;
110 std::string implementation_name_; 119 std::string implementation_name_;
120
121 // Used for checking the single-threaded access of the encoder interface.
122 rtc::SequencedTaskChecker encoder_queue_;
123
124 // Store encoders in between calls to Release and InitEncode, so they don't
125 // have to be recreated. Remaining encoders are destroyed by the destructor.
126 std::stack<VideoEncoder*> stored_encoders_;
111 }; 127 };
112 128
113 } // namespace webrtc 129 } // namespace webrtc
114 130
115 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ 131 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/BUILD.gn ('k') | webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698