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

Side by Side Diff: content/renderer/media/rtc_video_decoder.h

Issue 1547073003: Switch to standard integer types in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
7 7
8 #include <stddef.h>
9 #include <stdint.h>
10
8 #include <deque> 11 #include <deque>
9 #include <list> 12 #include <list>
10 #include <map> 13 #include <map>
11 #include <set> 14 #include <set>
12 #include <utility> 15 #include <utility>
13 16
14 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
17 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
18 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
19 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
20 #include "media/base/bitstream_buffer.h" 23 #include "media/base/bitstream_buffer.h"
21 #include "media/base/video_decoder.h" 24 #include "media/base/video_decoder.h"
22 #include "media/video/picture.h" 25 #include "media/video/picture.h"
23 #include "media/video/video_decode_accelerator.h" 26 #include "media/video/video_decode_accelerator.h"
24 #include "third_party/webrtc/modules/video_coding/include/video_codec_interface. h" 27 #include "third_party/webrtc/modules/video_coding/include/video_codec_interface. h"
25 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 int32_t RegisterDecodeCompleteCallback( 77 int32_t RegisterDecodeCompleteCallback(
75 webrtc::DecodedImageCallback* callback) override; 78 webrtc::DecodedImageCallback* callback) override;
76 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while 79 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while
77 // this runs. 80 // this runs.
78 int32_t Release() override; 81 int32_t Release() override;
79 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while 82 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while
80 // this runs. 83 // this runs.
81 int32_t Reset() override; 84 int32_t Reset() override;
82 85
83 // VideoDecodeAccelerator::Client implementation. 86 // VideoDecodeAccelerator::Client implementation.
84 void ProvidePictureBuffers(uint32 count, 87 void ProvidePictureBuffers(uint32_t count,
85 const gfx::Size& size, 88 const gfx::Size& size,
86 uint32 texture_target) override; 89 uint32_t texture_target) override;
87 void DismissPictureBuffer(int32 id) override; 90 void DismissPictureBuffer(int32_t id) override;
88 void PictureReady(const media::Picture& picture) override; 91 void PictureReady(const media::Picture& picture) override;
89 void NotifyEndOfBitstreamBuffer(int32 id) override; 92 void NotifyEndOfBitstreamBuffer(int32_t id) override;
90 void NotifyFlushDone() override; 93 void NotifyFlushDone() override;
91 void NotifyResetDone() override; 94 void NotifyResetDone() override;
92 void NotifyError(media::VideoDecodeAccelerator::Error error) override; 95 void NotifyError(media::VideoDecodeAccelerator::Error error) override;
93 96
94 private: 97 private:
95 // Metadata of a bitstream buffer. 98 // Metadata of a bitstream buffer.
96 struct BufferData { 99 struct BufferData {
97 BufferData(int32 bitstream_buffer_id, 100 BufferData(int32_t bitstream_buffer_id,
98 uint32_t timestamp, 101 uint32_t timestamp,
99 size_t size, 102 size_t size,
100 const gfx::Rect& visible_rect); 103 const gfx::Rect& visible_rect);
101 BufferData(); 104 BufferData();
102 ~BufferData(); 105 ~BufferData();
103 int32 bitstream_buffer_id; 106 int32_t bitstream_buffer_id;
104 uint32_t timestamp; // in 90KHz 107 uint32_t timestamp; // in 90KHz
105 size_t size; // buffer size 108 size_t size; // buffer size
106 gfx::Rect visible_rect; 109 gfx::Rect visible_rect;
107 }; 110 };
108 111
109 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset);
110 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); 113 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset);
111 114
112 RTCVideoDecoder(webrtc::VideoCodecType type, 115 RTCVideoDecoder(webrtc::VideoCodecType type,
113 media::GpuVideoAcceleratorFactories* factories); 116 media::GpuVideoAcceleratorFactories* factories);
114 117
115 // Requests a buffer to be decoded by VDA. 118 // Requests a buffer to be decoded by VDA.
116 void RequestBufferDecode(); 119 void RequestBufferDecode();
117 120
118 bool CanMoreDecodeWorkBeDone(); 121 bool CanMoreDecodeWorkBeDone();
119 122
120 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. 123 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|.
121 // This handles the wraparound. 124 // This handles the wraparound.
122 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); 125 bool IsBufferAfterReset(int32_t id_buffer, int32_t id_reset);
123 126
124 // Returns true if bitstream buffer |id_buffer| is the first buffer after 127 // Returns true if bitstream buffer |id_buffer| is the first buffer after
125 // |id_reset|. 128 // |id_reset|.
126 bool IsFirstBufferAfterReset(int32 id_buffer, int32 id_reset); 129 bool IsFirstBufferAfterReset(int32_t id_buffer, int32_t id_reset);
127 130
128 // Saves a WebRTC buffer in |decode_buffers_| for decode. 131 // Saves a WebRTC buffer in |decode_buffers_| for decode.
129 void SaveToDecodeBuffers_Locked(const webrtc::EncodedImage& input_image, 132 void SaveToDecodeBuffers_Locked(const webrtc::EncodedImage& input_image,
130 scoped_ptr<base::SharedMemory> shm_buffer, 133 scoped_ptr<base::SharedMemory> shm_buffer,
131 const BufferData& buffer_data); 134 const BufferData& buffer_data);
132 135
133 // Saves a WebRTC buffer in |pending_buffers_| waiting for SHM available. 136 // Saves a WebRTC buffer in |pending_buffers_| waiting for SHM available.
134 // Returns true on success. 137 // Returns true on success.
135 bool SaveToPendingBuffers_Locked(const webrtc::EncodedImage& input_image, 138 bool SaveToPendingBuffers_Locked(const webrtc::EncodedImage& input_image,
136 const BufferData& buffer_data); 139 const BufferData& buffer_data);
137 140
138 // Gets SHM and moves pending buffers to decode buffers. 141 // Gets SHM and moves pending buffers to decode buffers.
139 void MovePendingBuffersToDecodeBuffers(); 142 void MovePendingBuffersToDecodeBuffers();
140 143
141 scoped_refptr<media::VideoFrame> CreateVideoFrame( 144 scoped_refptr<media::VideoFrame> CreateVideoFrame(
142 const media::Picture& picture, 145 const media::Picture& picture,
143 const media::PictureBuffer& pb, 146 const media::PictureBuffer& pb,
144 uint32_t timestamp, 147 uint32_t timestamp,
145 const gfx::Rect& visible_rect); 148 const gfx::Rect& visible_rect);
146 149
147 // Resets VDA. 150 // Resets VDA.
148 void ResetInternal(); 151 void ResetInternal();
149 152
150 // Static method is to allow it to run even after RVD is deleted. 153 // Static method is to allow it to run even after RVD is deleted.
151 static void ReleaseMailbox(base::WeakPtr<RTCVideoDecoder> decoder, 154 static void ReleaseMailbox(base::WeakPtr<RTCVideoDecoder> decoder,
152 media::GpuVideoAcceleratorFactories* factories, 155 media::GpuVideoAcceleratorFactories* factories,
153 int64 picture_buffer_id, 156 int64_t picture_buffer_id,
154 uint32 texture_id, 157 uint32_t texture_id,
155 const gpu::SyncToken& release_sync_token); 158 const gpu::SyncToken& release_sync_token);
156 // Tells VDA that a picture buffer can be recycled. 159 // Tells VDA that a picture buffer can be recycled.
157 void ReusePictureBuffer(int64 picture_buffer_id); 160 void ReusePictureBuffer(int64_t picture_buffer_id);
158 161
159 // Create |vda_| on |vda_loop_proxy_|. 162 // Create |vda_| on |vda_loop_proxy_|.
160 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); 163 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter);
161 164
162 void DestroyTextures(); 165 void DestroyTextures();
163 void DestroyVDA(); 166 void DestroyVDA();
164 167
165 // Gets a shared-memory segment of at least |min_size| bytes from 168 // Gets a shared-memory segment of at least |min_size| bytes from
166 // |available_shm_segments_|. Returns NULL if there is no buffer or the 169 // |available_shm_segments_|. Returns NULL if there is no buffer or the
167 // buffer is not big enough. 170 // buffer is not big enough.
168 scoped_ptr<base::SharedMemory> GetSHM_Locked(size_t min_size); 171 scoped_ptr<base::SharedMemory> GetSHM_Locked(size_t min_size);
169 172
170 // Returns a shared-memory segment to the available pool. 173 // Returns a shared-memory segment to the available pool.
171 void PutSHM_Locked(scoped_ptr<base::SharedMemory> shm_buffer); 174 void PutSHM_Locked(scoped_ptr<base::SharedMemory> shm_buffer);
172 175
173 // Allocates |count| shared memory buffers of |size| bytes. 176 // Allocates |count| shared memory buffers of |size| bytes.
174 void CreateSHM(size_t count, size_t size); 177 void CreateSHM(size_t count, size_t size);
175 178
176 // Stores the buffer metadata to |input_buffer_data_|. 179 // Stores the buffer metadata to |input_buffer_data_|.
177 void RecordBufferData(const BufferData& buffer_data); 180 void RecordBufferData(const BufferData& buffer_data);
178 // Gets the buffer metadata from |input_buffer_data_|. 181 // Gets the buffer metadata from |input_buffer_data_|.
179 void GetBufferData(int32 bitstream_buffer_id, 182 void GetBufferData(int32_t bitstream_buffer_id,
180 uint32_t* timestamp, 183 uint32_t* timestamp,
181 gfx::Rect* visible_rect); 184 gfx::Rect* visible_rect);
182 185
183 // Records the result of InitDecode to UMA and returns |status|. 186 // Records the result of InitDecode to UMA and returns |status|.
184 int32_t RecordInitDecodeUMA(int32_t status); 187 int32_t RecordInitDecodeUMA(int32_t status);
185 188
186 // Assert the contract that this class is operated on the right thread. 189 // Assert the contract that this class is operated on the right thread.
187 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; 190 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const;
188 191
189 // Query factories_ whether |profile| is supported and return true is so, 192 // Query factories_ whether |profile| is supported and return true is so,
190 // false otherwise. If true, also set resolution limits for |profile| 193 // false otherwise. If true, also set resolution limits for |profile|
191 // in min/max_resolution_. 194 // in min/max_resolution_.
192 bool IsProfileSupported(media::VideoCodecProfile profile); 195 bool IsProfileSupported(media::VideoCodecProfile profile);
193 196
194 // Clear the pending_buffers_ queue, freeing memory. 197 // Clear the pending_buffers_ queue, freeing memory.
195 void ClearPendingBuffers(); 198 void ClearPendingBuffers();
196 199
197 enum State { 200 enum State {
198 UNINITIALIZED, // The decoder has not initialized. 201 UNINITIALIZED, // The decoder has not initialized.
199 INITIALIZED, // The decoder has initialized. 202 INITIALIZED, // The decoder has initialized.
200 RESETTING, // The decoder is being reset. 203 RESETTING, // The decoder is being reset.
201 DECODE_ERROR, // Decoding error happened. 204 DECODE_ERROR, // Decoding error happened.
202 }; 205 };
203 206
204 static const int32 ID_LAST; // maximum bitstream buffer id 207 static const int32_t ID_LAST; // maximum bitstream buffer id
205 static const int32 ID_HALF; // half of the maximum bitstream buffer id 208 static const int32_t ID_HALF; // half of the maximum bitstream buffer id
206 static const int32 ID_INVALID; // indicates Reset or Release never occurred 209 static const int32_t ID_INVALID; // indicates Reset or Release never occurred
207 210
208 // The hardware video decoder. 211 // The hardware video decoder.
209 scoped_ptr<media::VideoDecodeAccelerator> vda_; 212 scoped_ptr<media::VideoDecodeAccelerator> vda_;
210 213
211 // The video codec type, as reported by WebRTC. 214 // The video codec type, as reported by WebRTC.
212 const webrtc::VideoCodecType video_codec_type_; 215 const webrtc::VideoCodecType video_codec_type_;
213 216
214 // The size of the incoming video frames. 217 // The size of the incoming video frames.
215 gfx::Size frame_size_; 218 gfx::Size frame_size_;
216 219
217 media::GpuVideoAcceleratorFactories* const factories_; 220 media::GpuVideoAcceleratorFactories* const factories_;
218 221
219 // The texture target used for decoded pictures. 222 // The texture target used for decoded pictures.
220 uint32 decoder_texture_target_; 223 uint32_t decoder_texture_target_;
221 224
222 // Metadata of the buffers that have been sent for decode. 225 // Metadata of the buffers that have been sent for decode.
223 std::list<BufferData> input_buffer_data_; 226 std::list<BufferData> input_buffer_data_;
224 227
225 // A map from bitstream buffer IDs to bitstream buffers that are being 228 // A map from bitstream buffer IDs to bitstream buffers that are being
226 // processed by VDA. The map owns SHM buffers. 229 // processed by VDA. The map owns SHM buffers.
227 std::map<int32, base::SharedMemory*> bitstream_buffers_in_decoder_; 230 std::map<int32_t, base::SharedMemory*> bitstream_buffers_in_decoder_;
228 231
229 // A map from picture buffer IDs to texture-backed picture buffers. 232 // A map from picture buffer IDs to texture-backed picture buffers.
230 std::map<int32, media::PictureBuffer> assigned_picture_buffers_; 233 std::map<int32_t, media::PictureBuffer> assigned_picture_buffers_;
231 234
232 // PictureBuffers given to us by VDA via PictureReady, which we sent forward 235 // PictureBuffers given to us by VDA via PictureReady, which we sent forward
233 // as VideoFrames to be rendered via read_cb_, and which will be returned 236 // as VideoFrames to be rendered via read_cb_, and which will be returned
234 // to us via ReusePictureBuffer. 237 // to us via ReusePictureBuffer.
235 typedef std::map<int32 /* picture_buffer_id */, uint32 /* texture_id */> 238 typedef std::map<int32_t /* picture_buffer_id */, uint32_t /* texture_id */>
236 PictureBufferTextureMap; 239 PictureBufferTextureMap;
237 PictureBufferTextureMap picture_buffers_at_display_; 240 PictureBufferTextureMap picture_buffers_at_display_;
238 241
239 // The id that will be given to the next picture buffer. 242 // The id that will be given to the next picture buffer.
240 int32 next_picture_buffer_id_; 243 int32_t next_picture_buffer_id_;
241 244
242 // Protects |state_|, |decode_complete_callback_| , |num_shm_buffers_|, 245 // Protects |state_|, |decode_complete_callback_| , |num_shm_buffers_|,
243 // |available_shm_segments_|, |pending_buffers_|, |decode_buffers_|, 246 // |available_shm_segments_|, |pending_buffers_|, |decode_buffers_|,
244 // |next_bitstream_buffer_id_| and |reset_bitstream_buffer_id_|. 247 // |next_bitstream_buffer_id_| and |reset_bitstream_buffer_id_|.
245 base::Lock lock_; 248 base::Lock lock_;
246 249
247 // The state of RTCVideoDecoder. Guarded by |lock_|. 250 // The state of RTCVideoDecoder. Guarded by |lock_|.
248 State state_; 251 State state_;
249 252
250 // Guarded by |lock_|. 253 // Guarded by |lock_|.
(...skipping 10 matching lines...) Expand all
261 264
262 // A queue storing WebRTC encoding images (and their metadata) that are 265 // A queue storing WebRTC encoding images (and their metadata) that are
263 // waiting for the shared memory. Guarded by |lock_|. 266 // waiting for the shared memory. Guarded by |lock_|.
264 std::deque<std::pair<webrtc::EncodedImage, BufferData>> pending_buffers_; 267 std::deque<std::pair<webrtc::EncodedImage, BufferData>> pending_buffers_;
265 268
266 // A queue storing buffers (and their metadata) that will be sent to VDA for 269 // A queue storing buffers (and their metadata) that will be sent to VDA for
267 // decode. The queue owns SHM buffers. Guarded by |lock_|. 270 // decode. The queue owns SHM buffers. Guarded by |lock_|.
268 std::deque<std::pair<base::SharedMemory*, BufferData>> decode_buffers_; 271 std::deque<std::pair<base::SharedMemory*, BufferData>> decode_buffers_;
269 272
270 // The id that will be given to the next bitstream buffer. Guarded by |lock_|. 273 // The id that will be given to the next bitstream buffer. Guarded by |lock_|.
271 int32 next_bitstream_buffer_id_; 274 int32_t next_bitstream_buffer_id_;
272 275
273 // A buffer that has an id less than this should be dropped because Reset or 276 // A buffer that has an id less than this should be dropped because Reset or
274 // Release has been called. Guarded by |lock_|. 277 // Release has been called. Guarded by |lock_|.
275 int32 reset_bitstream_buffer_id_; 278 int32_t reset_bitstream_buffer_id_;
276 279
277 // Minimum and maximum supported resolutions for the current profile/VDA. 280 // Minimum and maximum supported resolutions for the current profile/VDA.
278 gfx::Size min_resolution_; 281 gfx::Size min_resolution_;
279 gfx::Size max_resolution_; 282 gfx::Size max_resolution_;
280 283
281 // Must be destroyed, or invalidated, on |vda_loop_proxy_| 284 // Must be destroyed, or invalidated, on |vda_loop_proxy_|
282 // NOTE: Weak pointers must be invalidated before all other member variables. 285 // NOTE: Weak pointers must be invalidated before all other member variables.
283 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; 286 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_;
284 287
285 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); 288 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder);
286 }; 289 };
287 290
288 } // namespace content 291 } // namespace content
289 292
290 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 293 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler_unittest.cc ('k') | content/renderer/media/rtc_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698