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

Unified Diff: content/common/gpu/media/v4l2_jpeg_decode_accelerator.h

Issue 1125263005: MJPEG acceleration for V4L2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/v4l2_jpeg_decode_accelerator.h
diff --git a/content/common/gpu/media/v4l2_image_processor.h b/content/common/gpu/media/v4l2_jpeg_decode_accelerator.h
similarity index 57%
copy from content/common/gpu/media/v4l2_image_processor.h
copy to content/common/gpu/media/v4l2_jpeg_decode_accelerator.h
index f396b0b3a7800fca88cacca490a0e31629e87dc2..6f03df553e06b5abb1727f2cd5bd3929167f12f3 100644
--- a/content/common/gpu/media/v4l2_image_processor.h
+++ b/content/common/gpu/media/v4l2_jpeg_decode_accelerator.h
@@ -1,9 +1,9 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_IMAGE_PROCESSOR_H_
-#define CONTENT_COMMON_GPU_MEDIA_V4L2_IMAGE_PROCESSOR_H_
+#ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_
+#define CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_
#include <queue>
#include <vector>
@@ -14,32 +14,22 @@
#include "base/threading/thread.h"
#include "content/common/content_export.h"
#include "content/common/gpu/media/v4l2_device.h"
+#include "media/base/bitstream_buffer.h"
#include "media/base/video_frame.h"
+#include "media/video/jpeg_decode_accelerator.h"
namespace content {
-// Handles image processing accelerators that expose a V4L2 memory-to-memory
-// interface. The threading model of this class is the same as for other V4L2
-// hardware accelerators (see V4L2VideoDecodeAccelerator) for more details.
-class CONTENT_EXPORT V4L2ImageProcessor {
+class CONTENT_EXPORT V4L2JpegDecodeAccelerator
+ : public media::JpegDecodeAccelerator {
public:
- explicit V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device);
- virtual ~V4L2ImageProcessor();
-
- // Initializes the processor to convert from |input_format| to |output_format|
- // and/or scale from |input_visible_size| to |output_visible_size|.
- // Request the output buffers to be of at least |output_allocated_size|.
- // Provided |error_cb| will be called if an error occurs.
- // Return true if the requested configuration is supported.
- bool Initialize(media::VideoFrame::Format input_format,
- media::VideoFrame::Format output_format,
- gfx::Size input_visible_size,
- gfx::Size output_visible_size,
- gfx::Size output_allocated_size,
- const base::Closure& error_cb);
-
- // Returns allocated size required by the processor to be fed with.
- gfx::Size input_allocated_size() { return input_allocated_size_; }
+ V4L2JpegDecodeAccelerator(
+ const scoped_refptr<V4L2Device>& device,
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy);
+ ~V4L2JpegDecodeAccelerator() override;
+
+ // Note: Initialize() and Destroy() are synchronous.
+ bool Initialize(Client* client) override;
// Callback to be used to return a processed image to the client. The client
// should drop references to |frame| once it's done with it.
@@ -49,18 +39,22 @@ class CONTENT_EXPORT V4L2ImageProcessor {
// Called by client to process |frame|. The resulting processed frame will
// be returned via |cb|. The processor will drop all its references to |frame|
// after it finishes accessing it.
- void Process(const scoped_refptr<media::VideoFrame>& frame,
- const FrameReadyCB& cb);
+// void Process(const scoped_refptr<media::VideoFrame>& frame,
+// const FrameReadyCB& cb);
+
+ void Decode(const media::BitstreamBuffer& bitstream_buffer,
+ const scoped_refptr<media::VideoFrame>& video_frame);
kcwu 2015/05/26 10:47:23 override;
henryhsu 2015/06/05 03:28:56 Done.
// Stop all processing and clean up.
- void Destroy();
+ void Destroy() override;
private:
// Record for input buffers.
struct InputRecord {
InputRecord();
~InputRecord();
- scoped_refptr<media::VideoFrame> frame;
+ void* address; // mmap() address.
+ size_t length; // mmap() length.
bool at_device;
};
@@ -68,9 +62,9 @@ class CONTENT_EXPORT V4L2ImageProcessor {
struct OutputRecord {
OutputRecord();
~OutputRecord();
+ void* address; // mmap() address.
+ size_t length; // mmap() length.
bool at_device;
- bool at_client;
- std::vector<int> fds;
};
// Job record. Jobs are processed in a FIFO order. This is separate from
@@ -80,10 +74,11 @@ class CONTENT_EXPORT V4L2ImageProcessor {
// may not have one available (and don't need one to submit input to the
// device).
struct JobRecord {
- JobRecord();
+ JobRecord(media::BitstreamBuffer bitstream_buffer,
+ scoped_refptr<media::VideoFrame> video_frame);
~JobRecord();
+ media::BitstreamBuffer bitstream_buffer;
scoped_refptr<media::VideoFrame> frame;
- FrameReadyCB ready_cb;
};
enum {
@@ -92,21 +87,20 @@ class CONTENT_EXPORT V4L2ImageProcessor {
kOutputBufferCount = 2,
};
- void ReuseOutputBuffer(int index);
-
void Enqueue();
void Dequeue();
bool EnqueueInputRecord();
bool EnqueueOutputRecord();
+ bool CheckBufferAttributes();
bool CreateInputBuffers();
bool CreateOutputBuffers();
void DestroyInputBuffers();
void DestroyOutputBuffers();
- void NotifyError();
+ void NotifyError(int32_t bitstream_buffer_id, Error error);
void DestroyTask();
- void ProcessTask(scoped_ptr<JobRecord> job_record);
+ void DecodeTask(scoped_ptr<JobRecord> job_record);
void ServiceDeviceTask();
// Attempt to start/stop device_poll_thread_.
@@ -116,27 +110,23 @@ class CONTENT_EXPORT V4L2ImageProcessor {
// Ran on device_poll_thread_ to wait for device events.
void DevicePollTask(bool poll_device);
- // Size and format-related members remain constant after initialization.
- // The visible/allocated sizes of the input frame.
- gfx::Size input_visible_size_;
- gfx::Size input_allocated_size_;
-
- // The visible/allocated sizes of the destination frame.
- gfx::Size output_visible_size_;
- gfx::Size output_allocated_size_;
-
- media::VideoFrame::Format input_format_;
media::VideoFrame::Format output_format_;
- uint32 input_format_fourcc_;
- uint32 output_format_fourcc_;
-
- size_t input_planes_count_;
- size_t output_planes_count_;
+ // Record current image size for checking image size is changed or not.
+ gfx::Size image_coded_size_;
// Our original calling message loop for the child thread.
- const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_;
+ scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_;
+
+ // GPU IO message loop.
+ scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
- // V4L2 device in use.
+ // To expose client callbacks from JpegDecodeAccelerator.
+ // NOTE: all calls to these objects *MUST* be executed on
+ // |child_message_loop_proxy_|.
+ scoped_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_;
+ base::WeakPtr<Client> client_;
+
+ // The V4L2Device this class is operating upon.
scoped_refptr<V4L2Device> device_;
// Thread to communicate with the device on.
@@ -171,11 +161,18 @@ class CONTENT_EXPORT V4L2ImageProcessor {
base::Closure error_cb_;
// Weak factory for producing weak pointers on the device_thread_
- base::WeakPtrFactory<V4L2ImageProcessor> device_weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor);
+ base::WeakPtrFactory<V4L2JpegDecodeAccelerator> device_weak_factory_;
+ // WeakPtr<> pointing to |this| for use in posting tasks from the decoder
+ // thread back to the ChildThread. Because the decoder thread is a member of
+ // this class, any task running on the decoder thread is guaranteed that this
+ // object is still alive. As a result, tasks posted from ChildThread to
+ // decoder thread should use base::Unretained(this), and tasks posted from
+ // the decoder thread to the ChildThread should use |device_weak_|.
+ base::WeakPtr<V4L2JpegDecodeAccelerator> device_weak_;
+
+ DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator);
};
-} // namespace content
+}
kcwu 2015/05/26 10:47:23 } // namespace content
henryhsu 2015/06/05 03:28:56 Done.
-#endif // CONTENT_COMMON_GPU_MEDIA_V4L2_IMAGE_PROCESSOR_H_
+#endif // CONTENT_COMMON_GPU_MEDIA_V4L2_JPEG_DECODE_ACCELERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698