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

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: Fixes for image processor. 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 explicit GenericV4L2Device(Type type);
23 25
26 bool Initialize() override;
kcwu 2016/10/06 10:39:59 Why put line 26 and 28 before line 30?
Pawel Osciak 2016/10/07 08:30:23 Ah right, good point.
27
28 bool Open(uint32_t v4l2_pixfmt) override;
29
24 // V4L2Device implementation. 30 // V4L2Device implementation.
25 int Ioctl(int request, void* arg) override; 31 int Ioctl(int request, void* arg) override;
26 bool Poll(bool poll_device, bool* event_pending) override; 32 bool Poll(bool poll_device, bool* event_pending) override;
27 bool SetDevicePollInterrupt() override; 33 bool SetDevicePollInterrupt() override;
28 bool ClearDevicePollInterrupt() override; 34 bool ClearDevicePollInterrupt() override;
29 void* Mmap(void* addr, 35 void* Mmap(void* addr,
30 unsigned int len, 36 unsigned int len,
31 int prot, 37 int prot,
32 int flags, 38 int flags,
33 unsigned int offset) override; 39 unsigned int offset) override;
34 void Munmap(void* addr, unsigned int len) override; 40 void Munmap(void* addr, unsigned int len) override;
35 bool Initialize() override;
36 41
37 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( 42 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer(
38 int index, 43 int index,
39 size_t num_planes, 44 size_t num_planes,
40 enum v4l2_buf_type type) override; 45 enum v4l2_buf_type type) override;
41 46
42 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; 47 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override;
43 EGLImageKHR CreateEGLImage( 48 EGLImageKHR CreateEGLImage(
44 EGLDisplay egl_display, 49 EGLDisplay egl_display,
45 EGLContext egl_context, 50 EGLContext egl_context,
46 GLuint texture_id, 51 GLuint texture_id,
47 const gfx::Size& size, 52 const gfx::Size& size,
48 unsigned int buffer_index, 53 unsigned int buffer_index,
49 uint32_t v4l2_pixfmt, 54 uint32_t v4l2_pixfmt,
50 const std::vector<base::ScopedFD>& dmabuf_fds) override; 55 const std::vector<base::ScopedFD>& dmabuf_fds) override;
51 56
52 EGLBoolean DestroyEGLImage(EGLDisplay egl_display, 57 EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
53 EGLImageKHR egl_image) override; 58 EGLImageKHR egl_image) override;
54 GLenum GetTextureTarget() override; 59 GLenum GetTextureTarget() override;
55 uint32_t PreferredInputFormat() override; 60 uint32_t PreferredInputFormat() override;
56 61
62 std::vector<uint32_t> GetSupportedImageProcessorPixelformats(
63 v4l2_buf_type buf_type) override;
64
65 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
66 const size_t num_formats,
67 const uint32_t pixelformats[]) override;
68
69 VideoEncodeAccelerator::SupportedProfiles GetSupportedEncodeProfiles()
70 override;
71
72 bool IsJpegDecodingSupported() override;
73
57 private: 74 private:
75 // Vector of video device node paths and corresponding pixelformats supported
76 // by each device node.
77 using Devices = std::vector<std::pair<std::string, std::vector<uint32_t>>>;
78
58 ~GenericV4L2Device() override; 79 ~GenericV4L2Device() override;
59 80
81 // Open device node for |path|.
82 bool OpenDevicePath(const std::string& path);
83
84 // Close the currently open device.
85 void CloseDevice();
86
87 // Enumerate all V4L2 devices on the system for |type| and store the results
88 // under devices_by_type_[type].
89 void EnumerateDevicesForType(V4L2Device::Type type);
90
91 // Return device information for all devices of |type| available in the
92 // system. Enumerates and queries devices on first run and caches the results
93 // for subsequent calls.
94 const Devices& GetDevicesForType(V4L2Device::Type type);
95
96 // Return device node path for device of |type| supporting |pixfmt|, or
97 // an empty string if the given combination is not supported by the system.
98 std::string GetDevicePathFor(V4L2Device::Type type, uint32_t pixfmt);
99
100 // Stores information for all devices available on the system
101 // for each device Type.
102 std::map<V4L2Device::Type, Devices> devices_by_type_;
103
60 // The actual device fd. 104 // The actual device fd.
61 base::ScopedFD device_fd_; 105 base::ScopedFD device_fd_;
62 106
63 // eventfd fd to signal device poll thread when its poll() should be 107 // eventfd fd to signal device poll thread when its poll() should be
64 // interrupted. 108 // interrupted.
65 base::ScopedFD device_poll_interrupt_fd_; 109 base::ScopedFD device_poll_interrupt_fd_;
66 110
67 #if USE_LIBV4L2 111 #if USE_LIBV4L2
68 // Use libv4l2 when operating |device_fd_|. 112 // Use libv4l2 when operating |device_fd_|.
69 bool use_libv4l2_; 113 bool use_libv4l2_;
70 #endif 114 #endif
71 115
72 DISALLOW_COPY_AND_ASSIGN(GenericV4L2Device); 116 DISALLOW_COPY_AND_ASSIGN(GenericV4L2Device);
73 117
74 // Lazily initialize static data after sandbox is enabled. Return false on 118 // Lazily initialize static data after sandbox is enabled. Return false on
75 // init failure. 119 // init failure.
76 static bool PostSandboxInitialization(); 120 static bool PostSandboxInitialization();
77 }; 121 };
78 } // namespace media 122 } // namespace media
79 123
80 #endif // MEDIA_GPU_GENERIC_V4L2_DEVICE_H_ 124 #endif // MEDIA_GPU_GENERIC_V4L2_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698