Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: media/video/capture/fake_video_capture_device.h

Issue 91343002: Added supported formats caching to VideoCaptureManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased FakeVCD. Reconnected VCManager unittest for all platforms. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implementation of a fake VideoCaptureDevice class. Used for testing other 5 // Implementation of a fake VideoCaptureDevice class. Used for testing other
6 // video capture classes when no real hardware is available. 6 // video capture classes when no real hardware is available.
7 7
8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ 8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ 9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "media/video/capture/video_capture_device.h" 16 #include "media/video/capture/video_capture_device.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { 20 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
21 public: 21 public:
22 static VideoCaptureDevice* Create(const Name& device_name); 22 static VideoCaptureDevice* Create(const Name& device_name);
23 virtual ~FakeVideoCaptureDevice(); 23 virtual ~FakeVideoCaptureDevice();
24 // Used for testing. This will make sure the next call to Create will 24 // Used for testing. This will make sure the next call to Create will
25 // return NULL; 25 // return NULL;
26 static void SetFailNextCreate(); 26 static void SetFailNextCreate();
27 static void SetNumberOfFakeDevices(size_t number_of_devices); 27 static void SetNumberOfFakeDevices(size_t number_of_devices);
28 static int NumberOfFakeDevices();
28 29
29 static void GetDeviceNames(Names* device_names); 30 static void GetDeviceNames(Names* device_names);
30 static void GetDeviceSupportedFormats(const Name& device, 31 static void GetDeviceSupportedFormats(const Name& device,
31 VideoCaptureCapabilities* formats); 32 VideoCaptureFormats* supported_formats);
32 33
33 // VideoCaptureDevice implementation. 34 // VideoCaptureDevice implementation.
34 virtual void AllocateAndStart(const VideoCaptureParams& params, 35 virtual void AllocateAndStart(const VideoCaptureParams& params,
35 scoped_ptr<VideoCaptureDevice::Client> client) 36 scoped_ptr<VideoCaptureDevice::Client> client)
36 OVERRIDE; 37 OVERRIDE;
37 virtual void StopAndDeAllocate() OVERRIDE; 38 virtual void StopAndDeAllocate() OVERRIDE;
38 39
39 private: 40 private:
40 // Flag indicating the internal state. 41 // Flag indicating the internal state.
41 enum InternalState { 42 enum InternalState {
42 kIdle, 43 kIdle,
43 kCapturing, 44 kCapturing,
44 kError 45 kError
45 }; 46 };
46 FakeVideoCaptureDevice(); 47 FakeVideoCaptureDevice();
47 48
48 // Called on the capture_thread_. 49 // Called on the capture_thread_.
49 void OnCaptureTask(); 50 void OnCaptureTask();
50
51 // EXPERIMENTAL, similar to allocate, but changes resolution and calls
52 // client->OnFrameInfoChanged(VideoCaptureCapability&)
53 void Reallocate(); 51 void Reallocate();
54 void PopulateFormatRoster(); 52 void PopulateFormatRoster();
55 53
56 scoped_ptr<VideoCaptureDevice::Client> client_; 54 scoped_ptr<VideoCaptureDevice::Client> client_;
57 InternalState state_; 55 InternalState state_;
58 base::Thread capture_thread_; 56 base::Thread capture_thread_;
59 scoped_ptr<uint8[]> fake_frame_; 57 scoped_ptr<uint8[]> fake_frame_;
60 int frame_count_; 58 int frame_count_;
61 VideoCaptureFormat capture_format_; 59 VideoCaptureFormat capture_format_;
62 60
63 // When the device is configured as mutating video captures, this vector 61 // When the device is configured as mutating video captures, this vector
64 // holds the available ones which are used in sequence, restarting at the end. 62 // holds the available ones which are used in sequence, restarting at the end.
65 std::vector<VideoCaptureFormat> format_roster_; 63 std::vector<VideoCaptureFormat> format_roster_;
66 int format_roster_index_; 64 int format_roster_index_;
67 65
66 static int number_of_fake_devices_;
68 static bool fail_next_create_; 67 static bool fail_next_create_;
69 // |number_of_devices_| is atomic since tests can call SetNumberOfFakeDevices 68 // |number_of_devices_| is atomic since tests can call SetNumberOfFakeDevices
70 // on the IO thread to set |number_of_devices_|. The variable can be 69 // on the IO thread to set |number_of_devices_|. The variable can be
71 // read from a separate thread. 70 // read from a separate thread.
72 // TODO(perkj): Make tests independent of global state. crbug/323913 71 // TODO(perkj): Make tests independent of global state. crbug/323913
73 static base::subtle::Atomic32 number_of_devices_; 72 static base::subtle::Atomic32 number_of_devices_;
74 73
75 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); 74 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
76 }; 75 };
77 76
78 } // namespace media 77 } // namespace media
79 78
80 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ 79 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698