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

Side by Side Diff: content/browser/renderer_host/media/video_capture_device_client.h

Issue 2361173002: Move classses VideoCaptureDeviceClient and VideoCaptureBufferPool to media/capture/video (Closed)
Patch Set: mcasas@ comments 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
(Empty)
1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/common/content_export.h"
17 #include "media/capture/video/video_capture_device.h"
18
19 namespace content {
20 class VideoCaptureBufferPool;
21 class VideoFrameReceiver;
22 class VideoCaptureJpegDecoder;
23
24 using VideoCaptureJpegDecoderFactoryCB =
25 base::Callback<std::unique_ptr<VideoCaptureJpegDecoder>()>;
26
27 // Implementation of media::VideoCaptureDevice::Client that uses a buffer pool
28 // to provide buffers and converts incoming data to the I420 format for
29 // consumption by a given VideoFrameReceiver.
30 //
31 // Methods of this class may be called from any thread, and in practice will
32 // often be called on some auxiliary thread depending on the platform and the
33 // device type; including, for example, the DirectShow thread on Windows, the
34 // v4l2_thread on Linux, and the UI thread for tab capture.
35 // The owner is responsible for making sure that the instance outlives these
36 // calls.
37 //
38 // It has an internal ref counted TextureWrapHelper class used to wrap incoming
39 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and
40 // manages the necessary entities to interact with the GPU process, notably an
41 // offscreen Context to avoid janking the UI thread.
42 class CONTENT_EXPORT VideoCaptureDeviceClient
43 : public media::VideoCaptureDevice::Client,
44 public base::SupportsWeakPtr<VideoCaptureDeviceClient> {
45 public:
46 VideoCaptureDeviceClient(
47 std::unique_ptr<VideoFrameReceiver> receiver,
48 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool,
49 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory);
50 ~VideoCaptureDeviceClient() override;
51
52 // VideoCaptureDevice::Client implementation.
53 void OnIncomingCapturedData(const uint8_t* data,
54 int length,
55 const media::VideoCaptureFormat& frame_format,
56 int rotation,
57 base::TimeTicks reference_time,
58 base::TimeDelta timestamp) override;
59 std::unique_ptr<Buffer> ReserveOutputBuffer(
60 const gfx::Size& dimensions,
61 media::VideoPixelFormat format,
62 media::VideoPixelStorage storage) override;
63 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
64 const media::VideoCaptureFormat& frame_format,
65 base::TimeTicks reference_time,
66 base::TimeDelta timestamp) override;
67 void OnIncomingCapturedVideoFrame(
68 std::unique_ptr<Buffer> buffer,
69 const scoped_refptr<media::VideoFrame>& frame) override;
70 std::unique_ptr<Buffer> ResurrectLastOutputBuffer(
71 const gfx::Size& dimensions,
72 media::VideoPixelFormat format,
73 media::VideoPixelStorage storage) override;
74 void OnError(const tracked_objects::Location& from_here,
75 const std::string& reason) override;
76 void OnLog(const std::string& message) override;
77 double GetBufferPoolUtilization() const override;
78
79 private:
80 // Reserve output buffer into which I420 contents can be copied directly.
81 // The dimensions of the frame is described by |dimensions|, and requested
82 // output buffer format is specified by |storage|. The reserved output buffer
83 // is returned; and the pointer to Y plane is stored at [y_plane_data], U
84 // plane is stored at [u_plane_data], V plane is stored at [v_plane_data].
85 // Returns an nullptr if allocation fails.
86 //
87 // When requested |storage| is PIXEL_STORAGE_CPU, a single shared memory
88 // chunk is reserved; whereas for PIXEL_STORAGE_GPUMEMORYBUFFER, three
89 // GpuMemoryBuffers in R_8 format representing I420 planes are reserved. The
90 // output buffers stay reserved and mapped for use until the Buffer objects
91 // are destroyed or returned.
92 std::unique_ptr<Buffer> ReserveI420OutputBuffer(
93 const gfx::Size& dimensions,
94 media::VideoPixelStorage storage,
95 uint8_t** y_plane_data,
96 uint8_t** u_plane_data,
97 uint8_t** v_plane_data);
98
99 // The receiver to which we post events.
100 const std::unique_ptr<VideoFrameReceiver> receiver_;
101
102 const VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_;
103 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_;
104
105 // Whether |external_jpeg_decoder_| has been initialized.
106 bool external_jpeg_decoder_initialized_;
107
108 // The pool of shared-memory buffers used for capturing.
109 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
110
111 #if DCHECK_IS_ON()
112 // Counter used to track the number of times consecutive capture buffers are
113 // dropped.
114 int dropped_frame_counter_ = 0;
115
116 static const int kMaxDroppedFrames = 150;
117 #endif // DCHECK_IS_ON()
118
119 // Indication to the Client to copy-transform the incoming data into
120 // GpuMemoryBuffers.
121 const bool use_gpu_memory_buffers_;
122
123 media::VideoPixelFormat last_captured_pixel_format_;
124
125 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient);
126 };
127
128
129 } // namespace content
130
131 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698