fake_video_encode_accelerator_factory.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2015 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_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_
  5. #define MEDIA_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include "base/callback.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "base/memory/unsafe_shared_memory_region.h"
  11. #include "base/task/single_thread_task_runner.h"
  12. #include "media/cast/cast_config.h"
  13. #include "media/video/fake_video_encode_accelerator.h"
  14. namespace media {
  15. namespace cast {
  16. // Used by test code to create fake VideoEncodeAccelerators. The test code
  17. // controls when the response callback is invoked.
  18. class FakeVideoEncodeAcceleratorFactory {
  19. public:
  20. explicit FakeVideoEncodeAcceleratorFactory(
  21. const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
  22. FakeVideoEncodeAcceleratorFactory(const FakeVideoEncodeAcceleratorFactory&) =
  23. delete;
  24. FakeVideoEncodeAcceleratorFactory& operator=(
  25. const FakeVideoEncodeAcceleratorFactory&) = delete;
  26. ~FakeVideoEncodeAcceleratorFactory();
  27. int vea_response_count() const { return vea_response_count_; }
  28. // Set whether the next created media::FakeVideoEncodeAccelerator will
  29. // initialize successfully.
  30. void SetInitializationWillSucceed(bool will_init_succeed);
  31. // Enable/disable auto-respond mode. Default is disabled.
  32. void SetAutoRespond(bool auto_respond);
  33. // Creates a media::FakeVideoEncodeAccelerator. If in auto-respond mode,
  34. // |callback| is run synchronously (i.e., before this method returns).
  35. void CreateVideoEncodeAccelerator(
  36. ReceiveVideoEncodeAcceleratorCallback callback);
  37. // Runs the |callback| provided to the last call to
  38. // CreateVideoEncodeAccelerator() with the new VideoEncodeAccelerator
  39. // instance.
  40. void RespondWithVideoEncodeAccelerator();
  41. private:
  42. const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  43. bool will_init_succeed_ = true;
  44. bool auto_respond_ = false;
  45. std::unique_ptr<media::VideoEncodeAccelerator> next_response_vea_;
  46. ReceiveVideoEncodeAcceleratorCallback vea_response_callback_;
  47. int vea_response_count_ = 0;
  48. };
  49. } // namespace cast
  50. } // namespace media
  51. #endif // MEDIA_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_