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

Side by Side Diff: webrtc/test/fake_encoder.h

Issue 2604403003: Make FakeEncoder and FakeH264Encoder thread safe. (Closed)
Patch Set: Rebase. Created 3 years, 11 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
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
(...skipping 29 matching lines...) Expand all
40 EncodedImageCallback* callback) override; 40 EncodedImageCallback* callback) override;
41 int32_t Release() override; 41 int32_t Release() override;
42 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; 42 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
43 int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, 43 int32_t SetRateAllocation(const BitrateAllocation& rate_allocation,
44 uint32_t framerate) override; 44 uint32_t framerate) override;
45 const char* ImplementationName() const override; 45 const char* ImplementationName() const override;
46 46
47 static const char* kImplementationName; 47 static const char* kImplementationName;
48 48
49 protected: 49 protected:
50 rtc::CriticalSection crit_sect_;
50 Clock* const clock_; 51 Clock* const clock_;
51 VideoCodec config_; 52 VideoCodec config_ GUARDED_BY(crit_sect_);
52 EncodedImageCallback* callback_; 53 EncodedImageCallback* callback_ GUARDED_BY(crit_sect_);
53 BitrateAllocation target_bitrate_; 54 BitrateAllocation target_bitrate_ GUARDED_BY(crit_sect_);
54 int max_target_bitrate_kbps_; 55 int max_target_bitrate_kbps_ GUARDED_BY(crit_sect_);
55 int64_t last_encode_time_ms_; 56 int64_t last_encode_time_ms_ GUARDED_BY(crit_sect_);
56 uint8_t encoded_buffer_[100000]; 57 uint8_t encoded_buffer_[100000];
57 }; 58 };
58 59
59 class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback { 60 class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {
60 public: 61 public:
61 explicit FakeH264Encoder(Clock* clock); 62 explicit FakeH264Encoder(Clock* clock);
62 virtual ~FakeH264Encoder() {} 63 virtual ~FakeH264Encoder() {}
63 64
64 int32_t RegisterEncodeCompleteCallback( 65 int32_t RegisterEncodeCompleteCallback(
65 EncodedImageCallback* callback) override; 66 EncodedImageCallback* callback) override;
66 67
67 Result OnEncodedImage(const EncodedImage& encodedImage, 68 Result OnEncodedImage(const EncodedImage& encodedImage,
68 const CodecSpecificInfo* codecSpecificInfo, 69 const CodecSpecificInfo* codecSpecificInfo,
69 const RTPFragmentationHeader* fragments) override; 70 const RTPFragmentationHeader* fragments) override;
70 71
71 private: 72 private:
72 EncodedImageCallback* callback_; 73 rtc::CriticalSection local_crit_sect_;
73 int idr_counter_; 74 EncodedImageCallback* callback_ GUARDED_BY(local_crit_sect_);
75 int idr_counter_ GUARDED_BY(local_crit_sect_);
74 }; 76 };
75 77
76 class DelayedEncoder : public test::FakeEncoder { 78 class DelayedEncoder : public test::FakeEncoder {
77 public: 79 public:
78 DelayedEncoder(Clock* clock, int delay_ms); 80 DelayedEncoder(Clock* clock, int delay_ms);
79 virtual ~DelayedEncoder() {} 81 virtual ~DelayedEncoder() {}
80 82
81 void SetDelay(int delay_ms); 83 void SetDelay(int delay_ms);
82 int32_t Encode(const VideoFrame& input_image, 84 int32_t Encode(const VideoFrame& input_image,
83 const CodecSpecificInfo* codec_specific_info, 85 const CodecSpecificInfo* codec_specific_info,
84 const std::vector<FrameType>* frame_types) override; 86 const std::vector<FrameType>* frame_types) override;
85 87
86 private: 88 private:
87 rtc::CriticalSection lock_; 89 rtc::CriticalSection local_crit_sect_;
88 int delay_ms_ GUARDED_BY(&lock_); 90 int delay_ms_ GUARDED_BY(&local_crit_sect_);
89 }; 91 };
90 92
91 // This class implements a multi-threaded fake encoder by posting 93 // This class implements a multi-threaded fake encoder by posting
92 // FakeH264Encoder::Encode(.) tasks to |queue1_| and |queue2_|, in an 94 // FakeH264Encoder::Encode(.) tasks to |queue1_| and |queue2_|, in an
93 // alternating fashion. 95 // alternating fashion.
94 class MultiThreadedFakeH264Encoder : public test::FakeH264Encoder { 96 class MultithreadedFakeH264Encoder : public test::FakeH264Encoder {
95 public: 97 public:
96 MultiThreadedFakeH264Encoder(Clock* clock); 98 explicit MultithreadedFakeH264Encoder(Clock* clock);
97 virtual ~MultiThreadedFakeH264Encoder() override; 99 virtual ~MultithreadedFakeH264Encoder() override;
98 100
99 int32_t Encode(const VideoFrame& input_image, 101 int32_t Encode(const VideoFrame& input_image,
100 const CodecSpecificInfo* codec_specific_info, 102 const CodecSpecificInfo* codec_specific_info,
101 const std::vector<FrameType>* frame_types) override; 103 const std::vector<FrameType>* frame_types) override;
102 104
103 int32_t EncodeCallback(const VideoFrame& input_image, 105 int32_t EncodeCallback(const VideoFrame& input_image,
104 const CodecSpecificInfo* codec_specific_info, 106 const CodecSpecificInfo* codec_specific_info,
105 const std::vector<FrameType>* frame_types); 107 const std::vector<FrameType>* frame_types);
106 108
107 protected: 109 protected:
108 class EncodeTask; 110 class EncodeTask;
109 111
110 int current_queue_; 112 int current_queue_;
111 rtc::TaskQueue queue1_; 113 rtc::TaskQueue queue1_;
112 rtc::TaskQueue queue2_; 114 rtc::TaskQueue queue2_;
113 }; 115 };
114 116
115 } // namespace test 117 } // namespace test
116 } // namespace webrtc 118 } // namespace webrtc
117 119
118 #endif // WEBRTC_TEST_FAKE_ENCODER_H_ 120 #endif // WEBRTC_TEST_FAKE_ENCODER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698