chrome: Fix dependencies of common_net target.
[chromium-blink-merge.git] / media / cast / sender / fake_video_encode_accelerator_factory.h
blob73c8feb1112e7c81adc0ff0522f5ac373c1a8363
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.
5 #ifndef MEDIA_CAST_SENDER_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_
6 #define MEDIA_CAST_SENDER_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/shared_memory.h"
12 #include "base/single_thread_task_runner.h"
13 #include "media/cast/cast_config.h"
14 #include "media/video/fake_video_encode_accelerator.h"
16 namespace media {
17 namespace cast {
19 // Used by test code to create fake VideoEncodeAccelerators. The test code
20 // controls when the response callback is invoked.
21 class FakeVideoEncodeAcceleratorFactory {
22 public:
23 explicit FakeVideoEncodeAcceleratorFactory(
24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
25 ~FakeVideoEncodeAcceleratorFactory();
27 int vea_response_count() const {
28 return vea_response_count_;
30 int shm_response_count() const {
31 return shm_response_count_;
34 // These return the instance last responded. It is up to the caller to
35 // determine whether the pointer is still valid, since this factory does not
36 // own these objects anymore.
37 media::FakeVideoEncodeAccelerator* last_response_vea() const {
38 return static_cast<media::FakeVideoEncodeAccelerator*>(last_response_vea_);
40 base::SharedMemory* last_response_shm() const {
41 return last_response_shm_;
44 // Set whether the next created media::FakeVideoEncodeAccelerator will
45 // initialize successfully.
46 void SetInitializationWillSucceed(bool will_init_succeed);
48 // Enable/disable auto-respond mode. Default is disabled.
49 void SetAutoRespond(bool auto_respond);
51 // Creates a media::FakeVideoEncodeAccelerator. If in auto-respond mode,
52 // |callback| is run synchronously (i.e., before this method returns).
53 void CreateVideoEncodeAccelerator(
54 const ReceiveVideoEncodeAcceleratorCallback& callback);
56 // Creates shared memory of the requested |size|. If in auto-respond mode,
57 // |callback| is run synchronously (i.e., before this method returns).
58 void CreateSharedMemory(
59 size_t size,
60 const ReceiveVideoEncodeMemoryCallback& callback);
62 // Runs the |callback| provided to the last call to
63 // CreateVideoEncodeAccelerator() with the new VideoEncodeAccelerator
64 // instance.
65 void RespondWithVideoEncodeAccelerator();
67 // Runs the |callback| provided to the last call to
68 // CreateSharedMemory() with the new base::SharedMemory instance.
69 void RespondWithSharedMemory();
71 private:
72 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
73 bool will_init_succeed_;
74 bool auto_respond_;
75 scoped_ptr<media::VideoEncodeAccelerator> next_response_vea_;
76 ReceiveVideoEncodeAcceleratorCallback vea_response_callback_;
77 scoped_ptr<base::SharedMemory> next_response_shm_;
78 ReceiveVideoEncodeMemoryCallback shm_response_callback_;
79 int vea_response_count_;
80 int shm_response_count_;
81 media::VideoEncodeAccelerator* last_response_vea_;
82 base::SharedMemory* last_response_shm_;
84 DISALLOW_COPY_AND_ASSIGN(FakeVideoEncodeAcceleratorFactory);
87 } // namespace cast
88 } // namespace media
90 #endif // MEDIA_CAST_SENDER_FAKE_VIDEO_ENCODE_ACCELERATOR_FACTORY_H_