v4l2_video_device.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This file defines the V4L2Device interface which is used by the
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// V4L2DecodeAccelerator class to delegate/pass the device specific
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// handling of any of the functionalities.
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DEVICE_H_
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DEVICE_H_
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace content {
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class V4L2Device {
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  V4L2Device();
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~V4L2Device();
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Tries to create and initialize an appropriate V4L2Device object for the
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // current platform and returns a scoped_ptr<V4L2Device> on success else
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // returns NULL.
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static scoped_ptr<V4L2Device> Create();
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Parameters and return value are the same as for the standard ioctl() system
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // call.
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int Ioctl(int request, void* arg) = 0;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This method sleeps until either:
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // - SetDevicePollInterrupt() is called (on another thread),
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // - |poll_device| is true, and there is new data to be read from the device,
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   or an event from the device has arrived; in the latter case
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   |*event_pending| will be set to true.
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns false on error, true otherwise.
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This method should be called from a separate thread.
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Poll(bool poll_device, bool* event_pending) = 0;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // These methods are used to interrupt the thread sleeping on Poll() and force
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // it to return regardless of device state, which is usually when the client
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is no longer interested in what happens with the device (on cleanup,
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // will return immediately, and any subsequent calls to it will also do so
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // until ClearDevicePollInterrupt() is called.
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool SetDevicePollInterrupt() = 0;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool ClearDevicePollInterrupt() = 0;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Wrappers for standard mmap/munmap system calls.
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void* Mmap(void* addr,
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     unsigned int len,
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     int prot,
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     int flags,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     unsigned int offset) = 0;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Munmap(void* addr, unsigned int len) = 0;
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  //  namespace content
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  //  CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DEVICE_H_
57