| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 16 matching lines...) Expand all Loading... |
| 27 size_t Vp9FrameBufferPool::Vp9FrameBuffer::GetDataSize() const { | 27 size_t Vp9FrameBufferPool::Vp9FrameBuffer::GetDataSize() const { |
| 28 return data_.size(); | 28 return data_.size(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void Vp9FrameBufferPool::Vp9FrameBuffer::SetSize(size_t size) { | 31 void Vp9FrameBufferPool::Vp9FrameBuffer::SetSize(size_t size) { |
| 32 data_.SetSize(size); | 32 data_.SetSize(size); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool Vp9FrameBufferPool::InitializeVpxUsePool( | 35 bool Vp9FrameBufferPool::InitializeVpxUsePool( |
| 36 vpx_codec_ctx* vpx_codec_context) { | 36 vpx_codec_ctx* vpx_codec_context) { |
| 37 DCHECK(vpx_codec_context); | 37 RTC_DCHECK(vpx_codec_context); |
| 38 // Tell libvpx to use this pool. | 38 // Tell libvpx to use this pool. |
| 39 if (vpx_codec_set_frame_buffer_functions( | 39 if (vpx_codec_set_frame_buffer_functions( |
| 40 // In which context to use these callback functions. | 40 // In which context to use these callback functions. |
| 41 vpx_codec_context, | 41 vpx_codec_context, |
| 42 // Called by libvpx when it needs another frame buffer. | 42 // Called by libvpx when it needs another frame buffer. |
| 43 &Vp9FrameBufferPool::VpxGetFrameBuffer, | 43 &Vp9FrameBufferPool::VpxGetFrameBuffer, |
| 44 // Called by libvpx when it no longer uses a frame buffer. | 44 // Called by libvpx when it no longer uses a frame buffer. |
| 45 &Vp9FrameBufferPool::VpxReleaseFrameBuffer, | 45 &Vp9FrameBufferPool::VpxReleaseFrameBuffer, |
| 46 // |this| will be passed as |user_priv| to VpxGetFrameBuffer. | 46 // |this| will be passed as |user_priv| to VpxGetFrameBuffer. |
| 47 this)) { | 47 this)) { |
| 48 // Failed to configure libvpx to use Vp9FrameBufferPool. | 48 // Failed to configure libvpx to use Vp9FrameBufferPool. |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 rtc::scoped_refptr<Vp9FrameBufferPool::Vp9FrameBuffer> | 54 rtc::scoped_refptr<Vp9FrameBufferPool::Vp9FrameBuffer> |
| 55 Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) { | 55 Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) { |
| 56 DCHECK_GT(min_size, 0u); | 56 RTC_DCHECK_GT(min_size, 0u); |
| 57 rtc::scoped_refptr<Vp9FrameBuffer> available_buffer = nullptr; | 57 rtc::scoped_refptr<Vp9FrameBuffer> available_buffer = nullptr; |
| 58 { | 58 { |
| 59 rtc::CritScope cs(&buffers_lock_); | 59 rtc::CritScope cs(&buffers_lock_); |
| 60 // Do we have a buffer we can recycle? | 60 // Do we have a buffer we can recycle? |
| 61 for (const auto& buffer : allocated_buffers_) { | 61 for (const auto& buffer : allocated_buffers_) { |
| 62 if (buffer->HasOneRef()) { | 62 if (buffer->HasOneRef()) { |
| 63 available_buffer = buffer; | 63 available_buffer = buffer; |
| 64 break; | 64 break; |
| 65 } | 65 } |
| 66 } | 66 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 94 | 94 |
| 95 void Vp9FrameBufferPool::ClearPool() { | 95 void Vp9FrameBufferPool::ClearPool() { |
| 96 rtc::CritScope cs(&buffers_lock_); | 96 rtc::CritScope cs(&buffers_lock_); |
| 97 allocated_buffers_.clear(); | 97 allocated_buffers_.clear(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 int32 Vp9FrameBufferPool::VpxGetFrameBuffer(void* user_priv, | 101 int32 Vp9FrameBufferPool::VpxGetFrameBuffer(void* user_priv, |
| 102 size_t min_size, | 102 size_t min_size, |
| 103 vpx_codec_frame_buffer* fb) { | 103 vpx_codec_frame_buffer* fb) { |
| 104 DCHECK(user_priv); | 104 RTC_DCHECK(user_priv); |
| 105 DCHECK(fb); | 105 RTC_DCHECK(fb); |
| 106 Vp9FrameBufferPool* pool = static_cast<Vp9FrameBufferPool*>(user_priv); | 106 Vp9FrameBufferPool* pool = static_cast<Vp9FrameBufferPool*>(user_priv); |
| 107 | 107 |
| 108 rtc::scoped_refptr<Vp9FrameBuffer> buffer = pool->GetFrameBuffer(min_size); | 108 rtc::scoped_refptr<Vp9FrameBuffer> buffer = pool->GetFrameBuffer(min_size); |
| 109 fb->data = buffer->GetData(); | 109 fb->data = buffer->GetData(); |
| 110 fb->size = buffer->GetDataSize(); | 110 fb->size = buffer->GetDataSize(); |
| 111 // Store Vp9FrameBuffer* in |priv| for use in VpxReleaseFrameBuffer. | 111 // Store Vp9FrameBuffer* in |priv| for use in VpxReleaseFrameBuffer. |
| 112 // This also makes vpx_codec_get_frame return images with their |fb_priv| set | 112 // This also makes vpx_codec_get_frame return images with their |fb_priv| set |
| 113 // to |buffer| which is important for external reference counting. | 113 // to |buffer| which is important for external reference counting. |
| 114 // Release from refptr so that the buffer's |ref_count_| remains 1 when | 114 // Release from refptr so that the buffer's |ref_count_| remains 1 when |
| 115 // |buffer| goes out of scope. | 115 // |buffer| goes out of scope. |
| 116 fb->priv = static_cast<void*>(buffer.release()); | 116 fb->priv = static_cast<void*>(buffer.release()); |
| 117 return 0; | 117 return 0; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 int32 Vp9FrameBufferPool::VpxReleaseFrameBuffer(void* user_priv, | 121 int32 Vp9FrameBufferPool::VpxReleaseFrameBuffer(void* user_priv, |
| 122 vpx_codec_frame_buffer* fb) { | 122 vpx_codec_frame_buffer* fb) { |
| 123 DCHECK(user_priv); | 123 RTC_DCHECK(user_priv); |
| 124 DCHECK(fb); | 124 RTC_DCHECK(fb); |
| 125 Vp9FrameBuffer* buffer = static_cast<Vp9FrameBuffer*>(fb->priv); | 125 Vp9FrameBuffer* buffer = static_cast<Vp9FrameBuffer*>(fb->priv); |
| 126 if (buffer != nullptr) { | 126 if (buffer != nullptr) { |
| 127 buffer->Release(); | 127 buffer->Release(); |
| 128 // When libvpx fails to decode and you continue to try to decode (and fail) | 128 // When libvpx fails to decode and you continue to try to decode (and fail) |
| 129 // libvpx can for some reason try to release the same buffer multiple times. | 129 // libvpx can for some reason try to release the same buffer multiple times. |
| 130 // Setting |priv| to null protects against trying to Release multiple times. | 130 // Setting |priv| to null protects against trying to Release multiple times. |
| 131 fb->priv = nullptr; | 131 fb->priv = nullptr; |
| 132 } | 132 } |
| 133 return 0; | 133 return 0; |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace webrtc | 136 } // namespace webrtc |
| OLD | NEW |