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

Side by Side Diff: media/gpu/generic_v4l2_device.h

Issue 2398883002: Add support for multiple V4L2 video devices of the same type. (Closed)
Patch Set: comments addressed Created 4 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file contains the implementation of GenericV4L2Device used on 5 // This file contains the implementation of GenericV4L2Device used on
6 // platforms, which provide generic V4L2 video codec devices. 6 // platforms, which provide generic V4L2 video codec devices.
7 7
8 #ifndef MEDIA_GPU_GENERIC_V4L2_DEVICE_H_ 8 #ifndef MEDIA_GPU_GENERIC_V4L2_DEVICE_H_
9 #define MEDIA_GPU_GENERIC_V4L2_DEVICE_H_ 9 #define MEDIA_GPU_GENERIC_V4L2_DEVICE_H_
10 10
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include <map>
15
14 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "media/gpu/v4l2_device.h" 18 #include "media/gpu/v4l2_device.h"
17 19
18 namespace media { 20 namespace media {
19 21
20 class GenericV4L2Device : public V4L2Device { 22 class GenericV4L2Device : public V4L2Device {
21 public: 23 public:
22 explicit GenericV4L2Device(Type type); 24 GenericV4L2Device();
23 25
24 // V4L2Device implementation. 26 // V4L2Device implementation.
27 bool Open(Type type, uint32_t v4l2_pixfmt) override;
25 int Ioctl(int request, void* arg) override; 28 int Ioctl(int request, void* arg) override;
26 bool Poll(bool poll_device, bool* event_pending) override; 29 bool Poll(bool poll_device, bool* event_pending) override;
27 bool SetDevicePollInterrupt() override; 30 bool SetDevicePollInterrupt() override;
28 bool ClearDevicePollInterrupt() override; 31 bool ClearDevicePollInterrupt() override;
29 void* Mmap(void* addr, 32 void* Mmap(void* addr,
30 unsigned int len, 33 unsigned int len,
31 int prot, 34 int prot,
32 int flags, 35 int flags,
33 unsigned int offset) override; 36 unsigned int offset) override;
34 void Munmap(void* addr, unsigned int len) override; 37 void Munmap(void* addr, unsigned int len) override;
35 bool Initialize() override;
36 38
37 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( 39 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer(
38 int index, 40 int index,
39 size_t num_planes, 41 size_t num_planes,
40 enum v4l2_buf_type type) override; 42 enum v4l2_buf_type buf_type) override;
41 43
42 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; 44 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override;
43 EGLImageKHR CreateEGLImage( 45 EGLImageKHR CreateEGLImage(
44 EGLDisplay egl_display, 46 EGLDisplay egl_display,
45 EGLContext egl_context, 47 EGLContext egl_context,
46 GLuint texture_id, 48 GLuint texture_id,
47 const gfx::Size& size, 49 const gfx::Size& size,
48 unsigned int buffer_index, 50 unsigned int buffer_index,
49 uint32_t v4l2_pixfmt, 51 uint32_t v4l2_pixfmt,
50 const std::vector<base::ScopedFD>& dmabuf_fds) override; 52 const std::vector<base::ScopedFD>& dmabuf_fds) override;
51 53
52 EGLBoolean DestroyEGLImage(EGLDisplay egl_display, 54 EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
53 EGLImageKHR egl_image) override; 55 EGLImageKHR egl_image) override;
54 GLenum GetTextureTarget() override; 56 GLenum GetTextureTarget() override;
55 uint32_t PreferredInputFormat() override; 57 uint32_t PreferredInputFormat(Type type) override;
58
59 std::vector<uint32_t> GetSupportedImageProcessorPixelformats(
60 v4l2_buf_type buf_type) override;
61
62 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
63 const size_t num_formats,
64 const uint32_t pixelformats[]) override;
65
66 VideoEncodeAccelerator::SupportedProfiles GetSupportedEncodeProfiles()
67 override;
68
69 bool IsImageProcessingSupported() override;
70
71 bool IsJpegDecodingSupported() override;
56 72
57 private: 73 private:
74 // Vector of video device node paths and corresponding pixelformats supported
75 // by each device node.
76 using Devices = std::vector<std::pair<std::string, std::vector<uint32_t>>>;
77
58 ~GenericV4L2Device() override; 78 ~GenericV4L2Device() override;
59 79
80 bool Initialize() override;
81
82 // Open device node for |path| as a device of |type|.
83 bool OpenDevicePath(const std::string& path, Type type);
84
85 // Close the currently open device.
86 void CloseDevice();
87
88 // Enumerate all V4L2 devices on the system for |type| and store the results
89 // under devices_by_type_[type].
90 void EnumerateDevicesForType(V4L2Device::Type type);
91
92 // Return device information for all devices of |type| available in the
93 // system. Enumerates and queries devices on first run and caches the results
94 // for subsequent calls.
95 const Devices& GetDevicesForType(V4L2Device::Type type);
96
97 // Return device node path for device of |type| supporting |pixfmt|, or
98 // an empty string if the given combination is not supported by the system.
99 std::string GetDevicePathFor(V4L2Device::Type type, uint32_t pixfmt);
100
101 // Stores information for all devices available on the system
102 // for each device Type.
103 std::map<V4L2Device::Type, Devices> devices_by_type_;
104
60 // The actual device fd. 105 // The actual device fd.
61 base::ScopedFD device_fd_; 106 base::ScopedFD device_fd_;
62 107
63 // eventfd fd to signal device poll thread when its poll() should be 108 // eventfd fd to signal device poll thread when its poll() should be
64 // interrupted. 109 // interrupted.
65 base::ScopedFD device_poll_interrupt_fd_; 110 base::ScopedFD device_poll_interrupt_fd_;
66 111
67 #if USE_LIBV4L2 112 #if USE_LIBV4L2
68 // Use libv4l2 when operating |device_fd_|. 113 // Use libv4l2 when operating |device_fd_|.
69 bool use_libv4l2_; 114 bool use_libv4l2_;
70 #endif 115 #endif
71 116
72 DISALLOW_COPY_AND_ASSIGN(GenericV4L2Device); 117 DISALLOW_COPY_AND_ASSIGN(GenericV4L2Device);
73 118
74 // Lazily initialize static data after sandbox is enabled. Return false on 119 // Lazily initialize static data after sandbox is enabled. Return false on
75 // init failure. 120 // init failure.
76 static bool PostSandboxInitialization(); 121 static bool PostSandboxInitialization();
77 }; 122 };
78 } // namespace media 123 } // namespace media
79 124
80 #endif // MEDIA_GPU_GENERIC_V4L2_DEVICE_H_ 125 #endif // MEDIA_GPU_GENERIC_V4L2_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698