video_frame_pool.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_BASE_VIDEO_FRAME_POOL_H_
  5. #define MEDIA_BASE_VIDEO_FRAME_POOL_H_
  6. #include <stddef.h>
  7. #include "media/base/media_export.h"
  8. #include "media/base/video_frame.h"
  9. namespace base {
  10. class TickClock;
  11. }
  12. namespace media {
  13. // Simple VideoFrame pool used to avoid unnecessarily allocating and destroying
  14. // VideoFrame objects. The pool manages the memory for the VideoFrame
  15. // returned by CreateFrame(). When one of these VideoFrames is destroyed,
  16. // the memory is returned to the pool for use by a subsequent CreateFrame()
  17. // call. The memory in the pool is retained for the life of the
  18. // VideoFramePool object. If the parameters passed to CreateFrame() change
  19. // during the life of this object, then the memory used by frames with the old
  20. // parameter values will be purged from the pool.
  21. class MEDIA_EXPORT VideoFramePool {
  22. public:
  23. VideoFramePool();
  24. VideoFramePool(const VideoFramePool&) = delete;
  25. VideoFramePool& operator=(const VideoFramePool&) = delete;
  26. ~VideoFramePool();
  27. // Returns a frame from the pool that matches the specified
  28. // parameters or creates a new frame if no suitable frame exists in
  29. // the pool. The pool is drained if no matching frame is found.
  30. // The buffer for the new frame will be zero initialized. Reused frames will
  31. // not be zero initialized.
  32. scoped_refptr<VideoFrame> CreateFrame(VideoPixelFormat format,
  33. const gfx::Size& coded_size,
  34. const gfx::Rect& visible_rect,
  35. const gfx::Size& natural_size,
  36. base::TimeDelta timestamp);
  37. protected:
  38. friend class VideoFramePoolTest;
  39. // Returns the number of frames in the pool for testing purposes.
  40. size_t GetPoolSizeForTesting() const;
  41. // Allows injection of a base::SimpleTestClock for testing.
  42. void SetTickClockForTesting(const base::TickClock* tick_clock);
  43. private:
  44. class PoolImpl;
  45. scoped_refptr<PoolImpl> pool_;
  46. };
  47. } // namespace media
  48. #endif // MEDIA_BASE_VIDEO_FRAME_POOL_H_