| OLD | NEW |
| 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> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 BufferData(); | 102 BufferData(); |
| 103 ~BufferData(); | 103 ~BufferData(); |
| 104 int32_t bitstream_buffer_id; | 104 int32_t bitstream_buffer_id; |
| 105 uint32_t timestamp; // in 90KHz | 105 uint32_t timestamp; // in 90KHz |
| 106 size_t size; // buffer size | 106 size_t size; // buffer size |
| 107 gfx::Rect visible_rect; | 107 gfx::Rect visible_rect; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); | 110 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); |
| 111 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); | 111 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); |
| 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, GetVDAErrorCounterForTesting); |
| 112 | 113 |
| 113 RTCVideoDecoder(webrtc::VideoCodecType type, | 114 RTCVideoDecoder(webrtc::VideoCodecType type, |
| 114 media::GpuVideoAcceleratorFactories* factories); | 115 media::GpuVideoAcceleratorFactories* factories); |
| 115 | 116 |
| 116 // Requests a buffer to be decoded by VDA. | 117 // Requests a buffer to be decoded by VDA. |
| 117 void RequestBufferDecode(); | 118 void RequestBufferDecode(); |
| 118 | 119 |
| 119 bool CanMoreDecodeWorkBeDone(); | 120 bool CanMoreDecodeWorkBeDone(); |
| 120 | 121 |
| 121 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. | 122 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. |
| 122 // This handles the wraparound. | 123 // This handles the wraparound. |
| 123 bool IsBufferAfterReset(int32_t id_buffer, int32_t id_reset); | 124 bool IsBufferAfterReset(int32_t id_buffer, int32_t id_reset); |
| 124 | 125 |
| 125 // Returns true if bitstream buffer |id_buffer| is the first buffer after | 126 // Returns true if bitstream buffer |id_buffer| is the first buffer after |
| 126 // |id_reset|. | 127 // |id_reset|. |
| 127 bool IsFirstBufferAfterReset(int32_t id_buffer, int32_t id_reset); | 128 bool IsFirstBufferAfterReset(int32_t id_buffer, int32_t id_reset); |
| 128 | 129 |
| 130 int GetVDAErrorCounterForTesting() { return vda_error_counter_; } |
| 131 |
| 129 // Saves a WebRTC buffer in |decode_buffers_| for decode. | 132 // Saves a WebRTC buffer in |decode_buffers_| for decode. |
| 130 void SaveToDecodeBuffers_Locked(const webrtc::EncodedImage& input_image, | 133 void SaveToDecodeBuffers_Locked(const webrtc::EncodedImage& input_image, |
| 131 scoped_ptr<base::SharedMemory> shm_buffer, | 134 scoped_ptr<base::SharedMemory> shm_buffer, |
| 132 const BufferData& buffer_data); | 135 const BufferData& buffer_data); |
| 133 | 136 |
| 134 // Saves a WebRTC buffer in |pending_buffers_| waiting for SHM available. | 137 // Saves a WebRTC buffer in |pending_buffers_| waiting for SHM available. |
| 135 // Returns true on success. | 138 // Returns true on success. |
| 136 bool SaveToPendingBuffers_Locked(const webrtc::EncodedImage& input_image, | 139 bool SaveToPendingBuffers_Locked(const webrtc::EncodedImage& input_image, |
| 137 const BufferData& buffer_data); | 140 const BufferData& buffer_data); |
| 138 | 141 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 | 153 |
| 151 // Static method is to allow it to run even after RVD is deleted. | 154 // Static method is to allow it to run even after RVD is deleted. |
| 152 static void ReleaseMailbox(base::WeakPtr<RTCVideoDecoder> decoder, | 155 static void ReleaseMailbox(base::WeakPtr<RTCVideoDecoder> decoder, |
| 153 media::GpuVideoAcceleratorFactories* factories, | 156 media::GpuVideoAcceleratorFactories* factories, |
| 154 int64_t picture_buffer_id, | 157 int64_t picture_buffer_id, |
| 155 uint32_t texture_id, | 158 uint32_t texture_id, |
| 156 const gpu::SyncToken& release_sync_token); | 159 const gpu::SyncToken& release_sync_token); |
| 157 // Tells VDA that a picture buffer can be recycled. | 160 // Tells VDA that a picture buffer can be recycled. |
| 158 void ReusePictureBuffer(int64_t picture_buffer_id); | 161 void ReusePictureBuffer(int64_t picture_buffer_id); |
| 159 | 162 |
| 160 // Create |vda_| on |vda_loop_proxy_|. | 163 // Creates |vda_| on |vda_loop_proxy_|. |
| 161 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); | 164 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); |
| 162 | 165 |
| 163 void DestroyTextures(); | 166 void DestroyTextures(); |
| 164 void DestroyVDA(); | 167 void DestroyVDA(); |
| 165 | 168 |
| 166 // Gets a shared-memory segment of at least |min_size| bytes from | 169 // Gets a shared-memory segment of at least |min_size| bytes from |
| 167 // |available_shm_segments_|. Returns NULL if there is no buffer or the | 170 // |available_shm_segments_|. Returns NULL if there is no buffer or the |
| 168 // buffer is not big enough. | 171 // buffer is not big enough. |
| 169 scoped_ptr<base::SharedMemory> GetSHM_Locked(size_t min_size); | 172 scoped_ptr<base::SharedMemory> GetSHM_Locked(size_t min_size); |
| 170 | 173 |
| 171 // Returns a shared-memory segment to the available pool. | 174 // Returns a shared-memory segment to the available pool. |
| 172 void PutSHM_Locked(scoped_ptr<base::SharedMemory> shm_buffer); | 175 void PutSHM_Locked(scoped_ptr<base::SharedMemory> shm_buffer); |
| 173 | 176 |
| 174 // Allocates |count| shared memory buffers of |size| bytes. | 177 // Allocates |count| shared memory buffers of |size| bytes. |
| 175 void CreateSHM(size_t count, size_t size); | 178 void CreateSHM(size_t count, size_t size); |
| 176 | 179 |
| 177 // Stores the buffer metadata to |input_buffer_data_|. | 180 // Stores the buffer metadata to |input_buffer_data_|. |
| 178 void RecordBufferData(const BufferData& buffer_data); | 181 void RecordBufferData(const BufferData& buffer_data); |
| 179 // Gets the buffer metadata from |input_buffer_data_|. | 182 // Gets the buffer metadata from |input_buffer_data_|. |
| 180 void GetBufferData(int32_t bitstream_buffer_id, | 183 void GetBufferData(int32_t bitstream_buffer_id, |
| 181 uint32_t* timestamp, | 184 uint32_t* timestamp, |
| 182 gfx::Rect* visible_rect); | 185 gfx::Rect* visible_rect); |
| 183 | 186 |
| 184 // Records the result of InitDecode to UMA and returns |status|. | 187 // Records the result of InitDecode to UMA and returns |status|. |
| 185 int32_t RecordInitDecodeUMA(int32_t status); | 188 int32_t RecordInitDecodeUMA(int32_t status); |
| 186 | 189 |
| 187 // Assert the contract that this class is operated on the right thread. | 190 // Asserts the contract that this class is operated on the right thread. |
| 188 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; | 191 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; |
| 189 | 192 |
| 190 // Query factories_ whether |profile| is supported and return true is so, | 193 // Queries factories_ whether |profile| is supported and return true is so, |
| 191 // false otherwise. If true, also set resolution limits for |profile| | 194 // false otherwise. If true, also set resolution limits for |profile| |
| 192 // in min/max_resolution_. | 195 // in min/max_resolution_. |
| 193 bool IsProfileSupported(media::VideoCodecProfile profile); | 196 bool IsProfileSupported(media::VideoCodecProfile profile); |
| 194 | 197 |
| 195 // Clear the pending_buffers_ queue, freeing memory. | 198 // Clears the pending_buffers_ queue, freeing memory. |
| 196 void ClearPendingBuffers(); | 199 void ClearPendingBuffers(); |
| 197 | 200 |
| 201 // Resets |vda_error_counter_| after a successfull run of decode. |
| 202 void TryResetVDAErrorCounter_Locked(); |
| 203 |
| 198 enum State { | 204 enum State { |
| 199 UNINITIALIZED, // The decoder has not initialized. | 205 UNINITIALIZED, // The decoder has not initialized. |
| 200 INITIALIZED, // The decoder has initialized. | 206 INITIALIZED, // The decoder has initialized. |
| 201 RESETTING, // The decoder is being reset. | 207 RESETTING, // The decoder is being reset. |
| 202 DECODE_ERROR, // Decoding error happened. | 208 DECODE_ERROR, // Decoding error happened. |
| 203 }; | 209 }; |
| 204 | 210 |
| 205 static const int32_t ID_LAST; // maximum bitstream buffer id | 211 static const int32_t ID_LAST; // maximum bitstream buffer id |
| 206 static const int32_t ID_HALF; // half of the maximum bitstream buffer id | 212 static const int32_t ID_HALF; // half of the maximum bitstream buffer id |
| 207 static const int32_t ID_INVALID; // indicates Reset or Release never occurred | 213 static const int32_t ID_INVALID; // indicates Reset or Release never occurred |
| 208 | 214 |
| 209 // The hardware video decoder. | 215 // The hardware video decoder. |
| 210 scoped_ptr<media::VideoDecodeAccelerator> vda_; | 216 scoped_ptr<media::VideoDecodeAccelerator> vda_; |
| 211 | 217 |
| 212 media::VideoCodecProfile vda_codec_profile_; | 218 media::VideoCodecProfile vda_codec_profile_; |
| 213 | 219 |
| 214 // Number of times that |vda_| notified of an error. | 220 // Number of times that |vda_| notified of an error. |
| 215 uint32_t num_vda_errors_; | 221 uint32_t vda_error_counter_; |
| 216 | 222 |
| 217 // The video codec type, as reported by WebRTC. | 223 // The video codec type, as reported by WebRTC. |
| 218 const webrtc::VideoCodecType video_codec_type_; | 224 const webrtc::VideoCodecType video_codec_type_; |
| 219 | 225 |
| 220 // The size of the incoming video frames. | 226 // The size of the incoming video frames. |
| 221 gfx::Size frame_size_; | 227 gfx::Size frame_size_; |
| 222 | 228 |
| 223 media::GpuVideoAcceleratorFactories* const factories_; | 229 media::GpuVideoAcceleratorFactories* const factories_; |
| 224 | 230 |
| 225 // The texture target used for decoded pictures. | 231 // The texture target used for decoded pictures. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 240 // to us via ReusePictureBuffer. | 246 // to us via ReusePictureBuffer. |
| 241 typedef std::map<int32_t /* picture_buffer_id */, uint32_t /* texture_id */> | 247 typedef std::map<int32_t /* picture_buffer_id */, uint32_t /* texture_id */> |
| 242 PictureBufferTextureMap; | 248 PictureBufferTextureMap; |
| 243 PictureBufferTextureMap picture_buffers_at_display_; | 249 PictureBufferTextureMap picture_buffers_at_display_; |
| 244 | 250 |
| 245 // The id that will be given to the next picture buffer. | 251 // The id that will be given to the next picture buffer. |
| 246 int32_t next_picture_buffer_id_; | 252 int32_t next_picture_buffer_id_; |
| 247 | 253 |
| 248 // Protects |state_|, |decode_complete_callback_| , |num_shm_buffers_|, | 254 // Protects |state_|, |decode_complete_callback_| , |num_shm_buffers_|, |
| 249 // |available_shm_segments_|, |pending_buffers_|, |decode_buffers_|, | 255 // |available_shm_segments_|, |pending_buffers_|, |decode_buffers_|, |
| 250 // |next_bitstream_buffer_id_| and |reset_bitstream_buffer_id_|. | 256 // |next_bitstream_buffer_id_|, |reset_bitstream_buffer_id_| and |
| 257 // |vda_error_counter_|. |
| 251 base::Lock lock_; | 258 base::Lock lock_; |
| 252 | 259 |
| 253 // The state of RTCVideoDecoder. Guarded by |lock_|. | 260 // The state of RTCVideoDecoder. Guarded by |lock_|. |
| 254 State state_; | 261 State state_; |
| 255 | 262 |
| 256 // Guarded by |lock_|. | 263 // Guarded by |lock_|. |
| 257 webrtc::DecodedImageCallback* decode_complete_callback_; | 264 webrtc::DecodedImageCallback* decode_complete_callback_; |
| 258 | 265 |
| 259 // Total number of allocated SHM buffers. Guarded by |lock_|. | 266 // Total number of allocated SHM buffers. Guarded by |lock_|. |
| 260 size_t num_shm_buffers_; | 267 size_t num_shm_buffers_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 287 // Must be destroyed, or invalidated, on |vda_loop_proxy_| | 294 // Must be destroyed, or invalidated, on |vda_loop_proxy_| |
| 288 // NOTE: Weak pointers must be invalidated before all other member variables. | 295 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 289 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; | 296 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; |
| 290 | 297 |
| 291 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); | 298 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); |
| 292 }; | 299 }; |
| 293 | 300 |
| 294 } // namespace content | 301 } // namespace content |
| 295 | 302 |
| 296 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ | 303 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| OLD | NEW |