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

Unified Diff: media/capture/video/file_video_capture_device.h

Issue 1291933002: File video capture device supports MJPEG format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address wucheng@ Created 5 years, 4 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: media/capture/video/file_video_capture_device.h
diff --git a/media/capture/video/file_video_capture_device.h b/media/capture/video/file_video_capture_device.h
index f50f04146d37094c6d3033412336858461961233..a026db3cbf3ecca09491bb13f02658a0bb2b70e7 100644
--- a/media/capture/video/file_video_capture_device.h
+++ b/media/capture/video/file_video_capture_device.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/files/file.h"
+#include "base/files/memory_mapped_file.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
@@ -17,21 +18,31 @@ namespace media {
// Implementation of a VideoCaptureDevice class that reads from a file. Used for
// testing the video capture pipeline when no real hardware is available. The
-// only supported file format is YUV4MPEG2 (a.k.a. Y4M), a minimal container
-// with a series of uncompressed video only frames, see the link
-// http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more information
-// on the file format. Several restrictions and notes apply, see the
+// supported file formats are YUV4MPEG2 (a.k.a. Y4M) and MJPEG/JPEG. YUV4MPEG2
+// is a minimal container with a series of uncompressed video only frames, see
+// the link http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more
+// information on the file format. Several restrictions and notes apply, see the
// implementation file.
-// Example videos can be found in http://media.xiph.org/video/derf.
+// Example Y4M videos can be found in http://media.xiph.org/video/derf.
mcasas 2015/08/18 18:28:42 Any example MJPEG files plz?
henryhsu 2015/08/19 01:57:24 media/data/test/bear.mjpeg concatenates many MJPEG
class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
mcasas 2015/08/18 18:28:42 Hmmm, I have the impression that we are mixing two
henryhsu 2015/08/19 01:57:24 SGTM. VideoFileParser still uses MemoryMappedFile.
public:
- static int64 ParseFileAndExtractVideoFormat(
- base::File* file,
- media::VideoCaptureFormat* video_format);
- static base::File OpenFileForRead(const base::FilePath& file_path);
+ // Reads and parses the header of a |mapped_file|, returning the collected
+ // pixel format in |video_format| and storing current frame size in
+ // |frame_size|. Returns the index of the first byte of the first video
+ // frame. If parsing |mapped_file| failed, returns -1.
+ // Restrictions: Only trivial Y4M per-frame headers and MJPEG are supported.
+ static size_t ParseFileAndExtractVideoFormat(
+ const base::MemoryMappedFile* mapped_file,
+ media::VideoCaptureFormat* video_format,
+ int* frame_size);
+
+ // Opens a given file for reading, and returns the memory mapped file to the
+ // caller, who is responsible for closing it.
+ static scoped_ptr<base::MemoryMappedFile>
+ OpenFileForRead(const base::FilePath& file_path);
// Constructor of the class, with a fully qualified file path as input, which
- // represents the Y4M video file to stream repeatedly.
+ // represents the Y4M or MJPEG file to stream repeatedly.
explicit FileVideoCaptureDevice(const base::FilePath& file_path);
// VideoCaptureDevice implementation, class methods.
@@ -41,14 +52,11 @@ class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
void StopAndDeAllocate() override;
private:
- // Returns size in bytes of an I420 frame, not including possible paddings,
- // defined by |capture_format_|.
- int CalculateFrameSize() const;
-
// Called on the |capture_thread_|.
void OnAllocateAndStart(const VideoCaptureParams& params,
scoped_ptr<Client> client);
void OnStopAndDeAllocate();
+ const uint8_t* GetNextFrame();
void OnCaptureTask();
// |thread_checker_| is used to check that destructor, AllocateAndStart() and
@@ -61,12 +69,11 @@ class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
// The following members belong to |capture_thread_|.
scoped_ptr<VideoCaptureDevice::Client> client_;
const base::FilePath file_path_;
- base::File file_;
- scoped_ptr<uint8[]> video_frame_;
+ scoped_ptr<base::MemoryMappedFile> mapped_file_;
mcasas 2015/08/18 18:28:42 A typical Y4M file can be a few Gigabytes long, wo
henryhsu 2015/08/19 01:57:24 MemoryMapedFile doesn't mention the size limitatio
henryhsu 2015/08/19 10:05:11 Y4mFileParser uses original base::File implementat
VideoCaptureFormat capture_format_;
int frame_size_;
- int64 current_byte_index_;
- int64 first_frame_byte_index_;
+ size_t current_byte_index_;
+ size_t first_frame_byte_index_;
// Target time for the next frame.
base::TimeTicks next_frame_time_;
« no previous file with comments | « no previous file | media/capture/video/file_video_capture_device.cc » ('j') | media/capture/video/file_video_capture_device.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698