OLD | NEW |
---|---|
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 Initialize() override; | |
kcwu
2016/10/07 11:19:04
This method is not expected call by users. I guess
Pawel Osciak
2016/10/11 06:13:45
Done.
| |
28 bool Open(Type type, uint32_t v4l2_pixfmt) override; | |
25 int Ioctl(int request, void* arg) override; | 29 int Ioctl(int request, void* arg) override; |
26 bool Poll(bool poll_device, bool* event_pending) override; | 30 bool Poll(bool poll_device, bool* event_pending) override; |
27 bool SetDevicePollInterrupt() override; | 31 bool SetDevicePollInterrupt() override; |
28 bool ClearDevicePollInterrupt() override; | 32 bool ClearDevicePollInterrupt() override; |
29 void* Mmap(void* addr, | 33 void* Mmap(void* addr, |
30 unsigned int len, | 34 unsigned int len, |
31 int prot, | 35 int prot, |
32 int flags, | 36 int flags, |
33 unsigned int offset) override; | 37 unsigned int offset) override; |
34 void Munmap(void* addr, unsigned int len) override; | 38 void Munmap(void* addr, unsigned int len) override; |
35 bool Initialize() override; | |
36 | 39 |
37 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( | 40 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( |
38 int index, | 41 int index, |
39 size_t num_planes, | 42 size_t num_planes, |
40 enum v4l2_buf_type type) override; | 43 enum v4l2_buf_type buf_type) override; |
41 | 44 |
42 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; | 45 bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; |
43 EGLImageKHR CreateEGLImage( | 46 EGLImageKHR CreateEGLImage( |
44 EGLDisplay egl_display, | 47 EGLDisplay egl_display, |
45 EGLContext egl_context, | 48 EGLContext egl_context, |
46 GLuint texture_id, | 49 GLuint texture_id, |
47 const gfx::Size& size, | 50 const gfx::Size& size, |
48 unsigned int buffer_index, | 51 unsigned int buffer_index, |
49 uint32_t v4l2_pixfmt, | 52 uint32_t v4l2_pixfmt, |
50 const std::vector<base::ScopedFD>& dmabuf_fds) override; | 53 const std::vector<base::ScopedFD>& dmabuf_fds) override; |
51 | 54 |
52 EGLBoolean DestroyEGLImage(EGLDisplay egl_display, | 55 EGLBoolean DestroyEGLImage(EGLDisplay egl_display, |
53 EGLImageKHR egl_image) override; | 56 EGLImageKHR egl_image) override; |
54 GLenum GetTextureTarget() override; | 57 GLenum GetTextureTarget() override; |
55 uint32_t PreferredInputFormat() override; | 58 uint32_t PreferredInputFormat(Type type) override; |
59 | |
60 std::vector<uint32_t> GetSupportedImageProcessorPixelformats( | |
61 v4l2_buf_type buf_type) override; | |
62 | |
63 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( | |
64 const size_t num_formats, | |
65 const uint32_t pixelformats[]) override; | |
66 | |
67 VideoEncodeAccelerator::SupportedProfiles GetSupportedEncodeProfiles() | |
68 override; | |
69 | |
70 bool IsImageProcessingSupported() override; | |
71 | |
72 bool IsJpegDecodingSupported() override; | |
56 | 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| as a device of |type|. | |
82 bool OpenDevicePath(const std::string& path, Type type); | |
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_ |
OLD | NEW |