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

Side by Side Diff: media/capture/video/video_capture_device_client.h

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fixes for failing bots Created 4 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_ 5 #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_
6 #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_ 6 #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "media/capture/capture_export.h" 16 #include "media/capture/capture_export.h"
17 #include "media/capture/video/video_capture_device.h" 17 #include "media/capture/video/video_capture_device.h"
18 #include "media/capture/video/video_frame_receiver.h"
18 19
19 namespace media { 20 namespace media {
20 class VideoCaptureBufferPool; 21 class VideoCaptureBufferPool;
21 class VideoFrameReceiver;
22 class VideoCaptureJpegDecoder; 22 class VideoCaptureJpegDecoder;
23 23
24 using VideoCaptureJpegDecoderFactoryCB = 24 using VideoCaptureJpegDecoderFactoryCB =
25 base::Callback<std::unique_ptr<VideoCaptureJpegDecoder>()>; 25 base::Callback<std::unique_ptr<VideoCaptureJpegDecoder>()>;
26 26
27 // Implementation of media::VideoCaptureDevice::Client that uses a buffer pool 27 // Implementation of media::VideoCaptureDevice::Client that uses a buffer pool
28 // to provide buffers and converts incoming data to the I420 format for 28 // to provide buffers and converts incoming data to the I420 format for
29 // consumption by a given VideoFrameReceiver. 29 // consumption by a given VideoFrameReceiver.
30 // 30 //
31 // Methods of this class may be called from any thread, and in practice will 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 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 33 // device type; including, for example, the DirectShow thread on Windows, the
34 // v4l2_thread on Linux, and the UI thread for tab capture. 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 35 // The owner is responsible for making sure that the instance outlives these
36 // calls. 36 // calls.
37 // 37 //
38 // It has an internal ref counted TextureWrapHelper class used to wrap incoming 38 // It has an internal ref counted TextureWrapHelper class used to wrap incoming
39 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and 39 // GpuMemoryBuffers into Texture backed VideoFrames. This class creates and
40 // manages the necessary entities to interact with the GPU process, notably an 40 // manages the necessary entities to interact with the GPU process, notably an
41 // offscreen Context to avoid janking the UI thread. 41 // offscreen Context to avoid janking the UI thread.
42 class CAPTURE_EXPORT VideoCaptureDeviceClient 42 class CAPTURE_EXPORT VideoCaptureDeviceClient
43 : public media::VideoCaptureDevice::Client, 43 : public VideoCaptureDevice::Client,
44 public FrameReceiverObserver,
44 public base::SupportsWeakPtr<VideoCaptureDeviceClient> { 45 public base::SupportsWeakPtr<VideoCaptureDeviceClient> {
45 public: 46 public:
46 VideoCaptureDeviceClient( 47 VideoCaptureDeviceClient(
47 std::unique_ptr<VideoFrameReceiver> receiver, 48 std::unique_ptr<VideoFrameReceiver> receiver,
48 scoped_refptr<VideoCaptureBufferPool> buffer_pool, 49 scoped_refptr<VideoCaptureBufferPool> buffer_pool,
49 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory); 50 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory,
51 scoped_refptr<base::SingleThreadTaskRunner>
52 utilization_reporting_task_runner);
50 ~VideoCaptureDeviceClient() override; 53 ~VideoCaptureDeviceClient() override;
51 54
55 void SetConsumerLoadObserver(ConsumerLoadObserver* load_observer);
56
52 // VideoCaptureDevice::Client implementation. 57 // VideoCaptureDevice::Client implementation.
53 void OnIncomingCapturedData(const uint8_t* data, 58 void OnIncomingCapturedData(const uint8_t* data,
54 int length, 59 int length,
55 const media::VideoCaptureFormat& frame_format, 60 const media::VideoCaptureFormat& frame_format,
56 int rotation, 61 int rotation,
57 base::TimeTicks reference_time, 62 base::TimeTicks reference_time,
58 base::TimeDelta timestamp) override; 63 base::TimeDelta timestamp,
64 int frame_id = 0) override;
59 std::unique_ptr<Buffer> ReserveOutputBuffer( 65 std::unique_ptr<Buffer> ReserveOutputBuffer(
60 const gfx::Size& dimensions, 66 const gfx::Size& dimensions,
61 media::VideoPixelFormat format, 67 media::VideoPixelFormat format,
62 media::VideoPixelStorage storage) override; 68 media::VideoPixelStorage storage) override;
63 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, 69 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
64 const media::VideoCaptureFormat& frame_format, 70 const VideoCaptureFormat& format,
65 base::TimeTicks reference_time, 71 base::TimeTicks reference_time,
66 base::TimeDelta timestamp) override; 72 base::TimeDelta timestamp,
67 void OnIncomingCapturedVideoFrame( 73 int frame_id) override;
68 std::unique_ptr<Buffer> buffer, 74 void OnIncomingCapturedVideoFrame(std::unique_ptr<Buffer> buffer,
69 scoped_refptr<media::VideoFrame> frame) override; 75 scoped_refptr<media::VideoFrame> frame,
76 int frame_id) override;
70 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( 77 std::unique_ptr<Buffer> ResurrectLastOutputBuffer(
71 const gfx::Size& dimensions, 78 const gfx::Size& dimensions,
72 media::VideoPixelFormat format, 79 media::VideoPixelFormat format,
73 media::VideoPixelStorage storage) override; 80 media::VideoPixelStorage storage) override;
74 void OnError(const tracked_objects::Location& from_here, 81 void OnError(const tracked_objects::Location& from_here,
75 const std::string& reason) override; 82 const std::string& reason) override;
76 void OnLog(const std::string& message) override; 83 void OnLog(const std::string& message) override;
77 double GetBufferPoolUtilization() const override; 84 double GetBufferPoolUtilization() const override;
78 85
86 // FrameReceiverObserver implementation.
87 void OnReceiverReportingUtilization(int buffer_id,
88 double utilization) override;
89
79 private: 90 private:
80 // Reserve output buffer into which I420 contents can be copied directly. 91 // Reserve output buffer into which I420 contents can be copied directly.
81 // The dimensions of the frame is described by |dimensions|, and requested 92 // The dimensions of the frame is described by |dimensions|, and requested
82 // output buffer format is specified by |storage|. The reserved output buffer 93 // 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 94 // 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]. 95 // plane is stored at [u_plane_data], V plane is stored at [v_plane_data].
85 // Returns an nullptr if allocation fails. 96 // Returns an nullptr if allocation fails.
86 // 97 //
87 // When requested |storage| is PIXEL_STORAGE_CPU, a single shared memory 98 // When requested |storage| is PIXEL_STORAGE_CPU, a single shared memory
88 // chunk is reserved. The output buffers stay reserved and mapped for use 99 // chunk is reserved. The output buffers stay reserved and mapped for use
89 // until the Buffer objects are destroyed or returned. 100 // until the Buffer objects are destroyed or returned.
90 std::unique_ptr<Buffer> ReserveI420OutputBuffer( 101 std::unique_ptr<Buffer> ReserveI420OutputBuffer(
91 const gfx::Size& dimensions, 102 const gfx::Size& dimensions,
92 media::VideoPixelStorage storage, 103 media::VideoPixelStorage storage,
93 uint8_t** y_plane_data, 104 uint8_t** y_plane_data,
94 uint8_t** u_plane_data, 105 uint8_t** u_plane_data,
95 uint8_t** v_plane_data); 106 uint8_t** v_plane_data);
96 107
97 // A branch of OnIncomingCapturedData for Y16 frame_format.pixel_format. 108 // A branch of OnIncomingCapturedData for Y16 frame_format.pixel_format.
98 void OnIncomingCapturedY16Data(const uint8_t* data, 109 void OnIncomingCapturedY16Data(const uint8_t* data,
99 int length, 110 int length,
100 const VideoCaptureFormat& frame_format, 111 const VideoCaptureFormat& frame_format,
101 base::TimeTicks reference_time, 112 base::TimeTicks reference_time,
102 base::TimeDelta timestamp); 113 base::TimeDelta timestamp,
114 int frame_id);
115
116 void EraseEntryFromBufferIdToFrameIdMap(int buffer_id_to_drop);
117 void AddEntryToBufferIdToFrameIdMap(int buffer_id, int frame_id);
103 118
104 // The receiver to which we post events. 119 // The receiver to which we post events.
105 const std::unique_ptr<VideoFrameReceiver> receiver_; 120 const std::unique_ptr<VideoFrameReceiver> receiver_;
106 121
107 const VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; 122 const VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_;
108 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_; 123 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_;
109 124
110 // Whether |external_jpeg_decoder_| has been initialized. 125 // Whether |external_jpeg_decoder_| has been initialized.
111 bool external_jpeg_decoder_initialized_; 126 bool external_jpeg_decoder_initialized_;
112 127
113 // The pool of shared-memory buffers used for capturing. 128 // The pool of shared-memory buffers used for capturing.
114 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 129 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
115 130
131 ConsumerLoadObserver* optional_load_observer_;
132 // Read and write access to |buffer_id_to_frame_id_map_| is sequentialized to
133 // |utilization_reporting_task_runner_|, since the corresponding calls may
134 // arrive from different threads.
135 const scoped_refptr<base::SingleThreadTaskRunner>
136 utilization_reporting_task_runner_;
137 std::map<int, int> buffer_id_to_frame_id_map_;
miu 2016/12/01 05:25:18 Instead of this map, can you tag the frame feedbac
chfremer 2016/12/02 01:28:29 Excellent suggestions. This greatly simplifies thi
138
116 #if DCHECK_IS_ON() 139 #if DCHECK_IS_ON()
117 // Counter used to track the number of times consecutive capture buffers are 140 // Counter used to track the number of times consecutive capture buffers are
118 // dropped. 141 // dropped.
119 int dropped_frame_counter_ = 0; 142 int dropped_frame_counter_ = 0;
120 143
121 static const int kMaxDroppedFrames = 150; 144 static const int kMaxDroppedFrames = 150;
122 #endif // DCHECK_IS_ON() 145 #endif // DCHECK_IS_ON()
123 146
124 media::VideoPixelFormat last_captured_pixel_format_; 147 media::VideoPixelFormat last_captured_pixel_format_;
125 148
126 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); 149 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient);
127 }; 150 };
128 151
129 } // namespace media 152 } // namespace media
130 153
131 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_ 154 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698