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

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

Issue 2607203002: [Mojo Video Capture] Retire buffers when Android Chromium goes to the background (Closed)
Patch Set: mcasas comments Created 3 years, 10 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
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 #include <vector>
12 13
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/thread_collision_warner.h"
16 #include "media/capture/capture_export.h" 18 #include "media/capture/capture_export.h"
17 #include "media/capture/video/video_capture_device.h" 19 #include "media/capture/video/video_capture_device.h"
18 20
19 namespace media { 21 namespace media {
20 class VideoCaptureBufferPool; 22 class VideoCaptureBufferPool;
21 class VideoFrameReceiver; 23 class VideoFrameReceiver;
22 class VideoCaptureJpegDecoder; 24 class VideoCaptureJpegDecoder;
23 25
24 using VideoCaptureJpegDecoderFactoryCB = 26 using VideoCaptureJpegDecoderFactoryCB =
25 base::Callback<std::unique_ptr<VideoCaptureJpegDecoder>()>; 27 base::Callback<std::unique_ptr<VideoCaptureJpegDecoder>()>;
26 28
27 // Implementation of media::VideoCaptureDevice::Client that uses a buffer pool 29 // Implementation of media::VideoCaptureDevice::Client that uses a buffer pool
28 // to provide buffers and converts incoming data to the I420 format for 30 // to provide buffers and converts incoming data to the I420 format for
29 // consumption by a given VideoFrameReceiver. 31 // consumption by a given VideoFrameReceiver.
30 // 32 //
31 // Methods of this class may be called from any thread, and in practice will 33 // 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 34 // 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 35 // device type; including, for example, the DirectShow thread on Windows, the
34 // v4l2_thread on Linux, and the UI thread for tab capture. 36 // v4l2_thread on Linux, and the UI thread for tab capture.
35 // The owner is responsible for making sure that the instance outlives these 37 // The owner is responsible for making sure that the instance outlives these
36 // calls. 38 // 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 CAPTURE_EXPORT VideoCaptureDeviceClient 39 class CAPTURE_EXPORT VideoCaptureDeviceClient
43 : public media::VideoCaptureDevice::Client, 40 : public media::VideoCaptureDevice::Client,
44 public base::SupportsWeakPtr<VideoCaptureDeviceClient> { 41 public base::SupportsWeakPtr<VideoCaptureDeviceClient> {
45 public: 42 public:
46 VideoCaptureDeviceClient( 43 VideoCaptureDeviceClient(
47 std::unique_ptr<VideoFrameReceiver> receiver, 44 std::unique_ptr<VideoFrameReceiver> receiver,
48 scoped_refptr<VideoCaptureBufferPool> buffer_pool, 45 scoped_refptr<VideoCaptureBufferPool> buffer_pool,
49 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory); 46 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory);
50 ~VideoCaptureDeviceClient() override; 47 ~VideoCaptureDeviceClient() override;
51 48
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // A branch of OnIncomingCapturedData for Y16 frame_format.pixel_format. 93 // A branch of OnIncomingCapturedData for Y16 frame_format.pixel_format.
97 void OnIncomingCapturedY16Data(const uint8_t* data, 94 void OnIncomingCapturedY16Data(const uint8_t* data,
98 int length, 95 int length,
99 const VideoCaptureFormat& frame_format, 96 const VideoCaptureFormat& frame_format,
100 base::TimeTicks reference_time, 97 base::TimeTicks reference_time,
101 base::TimeDelta timestamp, 98 base::TimeDelta timestamp,
102 int frame_feedback_id); 99 int frame_feedback_id);
103 100
104 // The receiver to which we post events. 101 // The receiver to which we post events.
105 const std::unique_ptr<VideoFrameReceiver> receiver_; 102 const std::unique_ptr<VideoFrameReceiver> receiver_;
103 std::vector<int> buffer_ids_known_by_receiver_;
106 104
107 const VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; 105 const VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_;
108 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_; 106 std::unique_ptr<VideoCaptureJpegDecoder> external_jpeg_decoder_;
109 107
110 // Whether |external_jpeg_decoder_| has been initialized. 108 // Whether |external_jpeg_decoder_| has been initialized.
111 bool external_jpeg_decoder_initialized_; 109 bool external_jpeg_decoder_initialized_;
112 110
113 // The pool of shared-memory buffers used for capturing. 111 // The pool of shared-memory buffers used for capturing.
114 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 112 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
115 113
116 #if DCHECK_IS_ON() 114 #if DCHECK_IS_ON()
117 // Counter used to track the number of times consecutive capture buffers are 115 // Counter used to track the number of times consecutive capture buffers are
118 // dropped. 116 // dropped.
119 int dropped_frame_counter_ = 0; 117 int dropped_frame_counter_ = 0;
120 118
121 static const int kMaxDroppedFrames = 150; 119 static const int kMaxDroppedFrames = 150;
122 #endif // DCHECK_IS_ON() 120 #endif // DCHECK_IS_ON()
123 121
124 media::VideoPixelFormat last_captured_pixel_format_; 122 media::VideoPixelFormat last_captured_pixel_format_;
125 123
124 // Thread collision warner to ensure that producer-facing API is not called
125 // concurrently. Producers are allowed to call from multiple threads, but not
126 // concurrently.
127 DFAKE_MUTEX(call_from_producer_);
128
126 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient); 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient);
127 }; 130 };
128 131
129 } // namespace media 132 } // namespace media
130 133
131 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_ 134 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698