scoped_buffer_pool_reservation.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_CAPTURE_VIDEO_SCOPED_BUFFER_POOL_RESERVATION_H_
  5. #define MEDIA_CAPTURE_VIDEO_SCOPED_BUFFER_POOL_RESERVATION_H_
  6. #include "media/capture/capture_export.h"
  7. #include "media/capture/video/video_capture_buffer_pool.h"
  8. #include "media/capture/video/video_capture_device_client.h"
  9. namespace media {
  10. template <typename ReleaseTraits>
  11. class CAPTURE_EXPORT ScopedBufferPoolReservation
  12. : public VideoCaptureDevice::Client::Buffer::ScopedAccessPermission {
  13. public:
  14. ScopedBufferPoolReservation(scoped_refptr<VideoCaptureBufferPool> buffer_pool,
  15. int buffer_id)
  16. : buffer_pool_(std::move(buffer_pool)), buffer_id_(buffer_id) {}
  17. ~ScopedBufferPoolReservation() {
  18. ReleaseTraits::Release(buffer_pool_, buffer_id_);
  19. }
  20. private:
  21. const scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
  22. const int buffer_id_;
  23. };
  24. class CAPTURE_EXPORT ProducerReleaseTraits {
  25. public:
  26. static void Release(const scoped_refptr<VideoCaptureBufferPool>& buffer_pool,
  27. int buffer_id) {
  28. buffer_pool->RelinquishProducerReservation(buffer_id);
  29. }
  30. };
  31. class CAPTURE_EXPORT ConsumerReleaseTraits {
  32. public:
  33. static void Release(const scoped_refptr<VideoCaptureBufferPool>& buffer_pool,
  34. int buffer_id) {
  35. buffer_pool->RelinquishConsumerHold(buffer_id, 1 /* num_clients */);
  36. }
  37. };
  38. } // namespace media
  39. #endif // MEDIA_CAPTURE_VIDEO_SCOPED_BUFFER_POOL_RESERVATION_H_