summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorowenlin <owenlin@chromium.org>2014-10-03 00:17:38 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-03 07:17:59 +0000
commitfd5bdd2688768683e30b27941f181597a849656d (patch)
tree451251c6c39c1429118ad6e991f5b44f121f1e2d
parent91d4e092d3a07e46ad55062dc0883071b3fe47e4 (diff)
downloadchromium_src-fd5bdd2688768683e30b27941f181597a849656d.zip
chromium_src-fd5bdd2688768683e30b27941f181597a849656d.tar.gz
chromium_src-fd5bdd2688768683e30b27941f181597a849656d.tar.bz2
Add still image capture interface for VideoCaptureDevice.
BUG=413086 TEST=Run the media_unittests on peach_pit. Review URL: https://codereview.chromium.org/545053002 Cr-Commit-Position: refs/heads/master@{#298009}
-rw-r--r--media/video/capture/video_capture_device.cc6
-rw-r--r--media/video/capture/video_capture_device.h61
-rw-r--r--media/video/capture/video_capture_device_factory.h7
-rw-r--r--media/video/capture/video_capture_types.cc9
-rw-r--r--media/video/capture/video_capture_types.h17
5 files changed, 100 insertions, 0 deletions
diff --git a/media/video/capture/video_capture_device.cc b/media/video/capture/video_capture_device.cc
index 0688b4b..3b74417 100644
--- a/media/video/capture/video_capture_device.cc
+++ b/media/video/capture/video_capture_device.cc
@@ -79,4 +79,10 @@ int VideoCaptureDevice::GetPowerLineFrequencyForLocation() const {
return kPowerLine60Hz;
}
+bool VideoCaptureDevice::InitializeImageCapture(
+ const ImageCaptureFormat& image_format,
+ scoped_ptr<ImageClient> client) {
+ return false;
+}
+
} // namespace media
diff --git a/media/video/capture/video_capture_device.h b/media/video/capture/video_capture_device.h
index 17af0bc..187145f 100644
--- a/media/video/capture/video_capture_device.h
+++ b/media/video/capture/video_capture_device.h
@@ -231,6 +231,41 @@ class MEDIA_EXPORT VideoCaptureDevice {
// VideoCaptureDevice requests the |message| to be logged.
virtual void OnLog(const std::string& message) {}
+
+ // The video stream has been muted. After this callback, no more
+ // OnIncomingCapturedData() will be called. This may happen when
+ // CaptureImage() has called. After the still image captured, the client
+ // will get notified by OnUnmute() and the video stream will be resumed.
+ virtual void OnMute() {}
+
+ // The video stream has resumed.
+ virtual void OnUnmute() {}
+ };
+
+ // Interface for clients that use VideoCaptureDevice for taking still images.
+ class MEDIA_EXPORT ImageClient {
+ public:
+ virtual ~ImageClient() {}
+
+ // Callback function to notify the client a captured image is available.
+ //
+ // The captured still image is stored at address |data| and is of |length|
+ // bytes. The format of the frame is described by |format|, and is assumed
+ // to be tightly packed. The still image should be rotated |rotation|
+ // degrees clockwise for viewing.
+ //
+ // Note that the content in |data| will not be valid after this callback
+ // returns. Copy the content to use it later.
+ virtual void OnIncomingCapturedData(const uint8* data,
+ size_t length,
+ const ImageCaptureFormat& format,
+ int rotation,
+ base::TimeTicks timestamp) = 0;
+
+ // Callback function to notify the client about a failure of the image
+ // capture. The VideoCaptureDevice must be StopAndDeAllocate()-ed.
+ // |reason| contains a text description of the error.
+ virtual void OnError(const std::string& reason) = 0;
};
virtual ~VideoCaptureDevice();
@@ -258,6 +293,32 @@ class MEDIA_EXPORT VideoCaptureDevice {
// defined, otherwise returns 0.
int GetPowerLineFrequencyForLocation() const;
+ // Initializes the device for still image capture for the given image format.
+ // This call is synchronous and returns true iff the initialization is
+ // successful.
+ //
+ // This function must be called between AllocateAndStart() and
+ // StopAndDeAllocate().
+ virtual bool InitializeImageCapture(const ImageCaptureFormat& image_format,
+ scoped_ptr<ImageClient> client);
+
+ // Releases resources for image capture.
+ //
+ // The ImageClient passed from InitializeImageCapture will be freed. This
+ // method must be called between InitializeImageCapture() and
+ // StopAndDeAllocate().
+ virtual void ReleaseImageCapture() {}
+
+ // Requests one image from the device.
+ //
+ // The image will be returned via the ImageClient::OnIncomingCapturedData()
+ // callback. If the video stream has to be stopped to capture the still image,
+ // the Client::OnMute() and Client::OnUnmute() will be called.
+ //
+ // This function must be called between InitializeImageCapture() and
+ // ReleaseImageCapture().
+ virtual void CaptureImage() {}
+
protected:
static const int kPowerLine50Hz = 50;
static const int kPowerLine60Hz = 60;
diff --git a/media/video/capture/video_capture_device_factory.h b/media/video/capture/video_capture_device_factory.h
index 76c4bdc..f8c2196 100644
--- a/media/video/capture/video_capture_device_factory.h
+++ b/media/video/capture/video_capture_device_factory.h
@@ -38,6 +38,13 @@ class MEDIA_EXPORT VideoCaptureDeviceFactory {
const VideoCaptureDevice::Name& device,
VideoCaptureFormats* supported_formats) = 0;
+ // Gets the supported formats for still image of a particular device attached
+ // to the system. In case format enumeration is not supported, or there was
+ // a problem, the formats array will be empty.
+ virtual void GetDeviceSupportedImageFormats(
+ const VideoCaptureDevice::Name& device,
+ ImageCaptureFormats* supported_formats) {}
+
protected:
// Gets the names of all video capture devices connected to this computer.
// Used by the default implementation of EnumerateDeviceNames().
diff --git a/media/video/capture/video_capture_types.cc b/media/video/capture/video_capture_types.cc
index ce5c354..7201e57 100644
--- a/media/video/capture/video_capture_types.cc
+++ b/media/video/capture/video_capture_types.cc
@@ -69,4 +69,13 @@ std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) {
VideoCaptureParams::VideoCaptureParams()
: resolution_change_policy(RESOLUTION_POLICY_FIXED) {}
+
+ImageCaptureFormat::ImageCaptureFormat() : pixel_format(PIXEL_FORMAT_UNKNOWN) {
+}
+
+ImageCaptureFormat::ImageCaptureFormat(const gfx::Size& frame_size,
+ VideoPixelFormat pixel_format)
+ : frame_size(frame_size), pixel_format(pixel_format) {
+}
+
} // namespace media
diff --git a/media/video/capture/video_capture_types.h b/media/video/capture/video_capture_types.h
index ec57c45..36cc54a 100644
--- a/media/video/capture/video_capture_types.h
+++ b/media/video/capture/video_capture_types.h
@@ -75,8 +75,25 @@ class MEDIA_EXPORT VideoCaptureFormat {
VideoPixelFormat pixel_format;
};
+// Image capture format specification.
+// This class is used by the video capture device to specify the format of a
+// still image captured and returned to a client. A list of these is also
+// provided when client queries supported formats for still image capture.
+class MEDIA_EXPORT ImageCaptureFormat {
+ public:
+ ImageCaptureFormat();
+
+ ImageCaptureFormat(const gfx::Size& frame_size,
+ VideoPixelFormat pixel_format);
+
+ gfx::Size frame_size;
+ VideoPixelFormat pixel_format;
+};
+
typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
+typedef std::vector<ImageCaptureFormat> ImageCaptureFormats;
+
// Parameters for starting video capture.
// This class is used by the client of a video capture device to specify the
// format of frames in which the client would like to have captured frames