1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67

media / cast / test / fake_video_encode_accelerator_factory.h [blame]

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_
#define MEDIA_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_

#include <stddef.h>

#include <memory>

#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/task/single_thread_task_runner.h"
#include "media/cast/cast_config.h"
#include "media/video/fake_video_encode_accelerator.h"

namespace media {
namespace cast {

// Used by test code to create fake VideoEncodeAccelerators.  The test code
// controls when the response callback is invoked.
class FakeVideoEncodeAcceleratorFactory {
 public:
  explicit FakeVideoEncodeAcceleratorFactory(
      const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);

  FakeVideoEncodeAcceleratorFactory(const FakeVideoEncodeAcceleratorFactory&) =
      delete;
  FakeVideoEncodeAcceleratorFactory& operator=(
      const FakeVideoEncodeAcceleratorFactory&) = delete;

  ~FakeVideoEncodeAcceleratorFactory();

  int vea_response_count() const { return vea_response_count_; }

  // Set whether the next created media::FakeVideoEncodeAccelerator will
  // initialize successfully.
  void SetInitializationWillSucceed(bool will_init_succeed);

  // Enable/disable auto-respond mode.  Default is disabled.
  void SetAutoRespond(bool auto_respond);

  // Creates a media::FakeVideoEncodeAccelerator.  If in auto-respond mode,
  // |callback| is run synchronously (i.e., before this method returns).
  void CreateVideoEncodeAccelerator(
      ReceiveVideoEncodeAcceleratorCallback callback);

  // Runs the |callback| provided to the last call to
  // CreateVideoEncodeAccelerator() with the new VideoEncodeAccelerator
  // instance.
  void RespondWithVideoEncodeAccelerator();

 private:
  const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  bool will_init_succeed_ = true;
  bool auto_respond_ = false;
  std::unique_ptr<media::VideoEncodeAccelerator> next_response_vea_;
  ReceiveVideoEncodeAcceleratorCallback vea_response_callback_;
  int vea_response_count_ = 0;
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_TEST_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_