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 3 // found in the LICENSE file. 4 // 5 // This file contains the implementation of GenericV4L2Device used on 6 // platforms, which provide generic V4L2 video codec devices. 7 // Note: ported from Chromium commit head: 9a075af92855 8 // Note: removed all references to 'USE_LIBV4L2'. 9 // Note: removed GL-related functionality. 10 11 #ifndef V4L2_GENERIC_V4L2_DEVICE_H_ 12 #define V4L2_GENERIC_V4L2_DEVICE_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <map> 18 #include <vector> 19 20 #include "base/files/scoped_file.h" 21 #include "base/macros.h" 22 #include "v4l2_device.h" 23 24 namespace media { 25 26 class GenericV4L2Device : public V4L2Device { 27 public: 28 GenericV4L2Device(); 29 30 // V4L2Device implementation. 31 bool Open(Type type, uint32_t v4l2_pixfmt) override; 32 int Ioctl(int request, void* arg) override; 33 bool Poll(bool poll_device, bool* event_pending) override; 34 bool SetDevicePollInterrupt() override; 35 bool ClearDevicePollInterrupt() override; 36 void* Mmap(void* addr, 37 unsigned int len, 38 int prot, 39 int flags, 40 unsigned int offset) override; 41 void Munmap(void* addr, unsigned int len) override; 42 43 std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( 44 int index, 45 size_t num_planes, 46 enum v4l2_buf_type buf_type) override; 47 48 std::vector<uint32_t> PreferredInputFormat(Type type) override; 49 50 std::vector<uint32_t> GetSupportedImageProcessorPixelformats( 51 v4l2_buf_type buf_type) override; 52 53 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( 54 const size_t num_formats, 55 const uint32_t pixelformats[]) override; 56 57 VideoEncodeAccelerator::SupportedProfiles GetSupportedEncodeProfiles() 58 override; 59 60 bool IsImageProcessingSupported() override; 61 62 bool IsJpegDecodingSupported() override; 63 bool IsJpegEncodingSupported() override; 64 65 protected: 66 ~GenericV4L2Device() override; 67 68 bool Initialize() override; 69 70 private: 71 // Vector of video device node paths and corresponding pixelformats supported 72 // by each device node. 73 using Devices = std::vector<std::pair<std::string, std::vector<uint32_t>>>; 74 75 // Open device node for |path| as a device of |type|. 76 bool OpenDevicePath(const std::string& path, Type type); 77 78 // Close the currently open device. 79 void CloseDevice(); 80 81 // Enumerate all V4L2 devices on the system for |type| and store the results 82 // under devices_by_type_[type]. 83 void EnumerateDevicesForType(V4L2Device::Type type); 84 85 // Return device information for all devices of |type| available in the 86 // system. Enumerates and queries devices on first run and caches the results 87 // for subsequent calls. 88 const Devices& GetDevicesForType(V4L2Device::Type type); 89 90 // Return device node path for device of |type| supporting |pixfmt|, or 91 // an empty string if the given combination is not supported by the system. 92 std::string GetDevicePathFor(V4L2Device::Type type, uint32_t pixfmt); 93 94 // Stores information for all devices available on the system 95 // for each device Type. 96 std::map<V4L2Device::Type, Devices> devices_by_type_; 97 98 // The actual device fd. 99 base::ScopedFD device_fd_; 100 101 // eventfd fd to signal device poll thread when its poll() should be 102 // interrupted. 103 base::ScopedFD device_poll_interrupt_fd_; 104 105 DISALLOW_COPY_AND_ASSIGN(GenericV4L2Device); 106 107 // Lazily initialize static data after sandbox is enabled. Return false on 108 // init failure. 109 static bool PostSandboxInitialization(); 110 }; 111 } // namespace media 112 113 #endif // V4L2_GENERIC_V4L2_DEVICE_H_ 114