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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_ 5 #ifndef MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_
6 #define MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_ 6 #define MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/memory_mapped_file.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "media/capture/video/video_capture_device.h" 15 #include "media/capture/video/video_capture_device.h"
15 16
16 namespace media { 17 namespace media {
17 18
18 // Implementation of a VideoCaptureDevice class that reads from a file. Used for 19 // Implementation of a VideoCaptureDevice class that reads from a file. Used for
19 // testing the video capture pipeline when no real hardware is available. The 20 // testing the video capture pipeline when no real hardware is available. The
20 // only supported file format is YUV4MPEG2 (a.k.a. Y4M), a minimal container 21 // supported file formats are YUV4MPEG2 (a.k.a. Y4M) and MJPEG/JPEG. YUV4MPEG2
21 // with a series of uncompressed video only frames, see the link 22 // is a minimal container with a series of uncompressed video only frames, see
22 // http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more information 23 // the link http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more
23 // on the file format. Several restrictions and notes apply, see the 24 // information on the file format. Several restrictions and notes apply, see the
24 // implementation file. 25 // implementation file.
25 // Example videos can be found in http://media.xiph.org/video/derf. 26 // 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
26 class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice { 27 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.
27 public: 28 public:
28 static int64 ParseFileAndExtractVideoFormat( 29 // Reads and parses the header of a |mapped_file|, returning the collected
29 base::File* file, 30 // pixel format in |video_format| and storing current frame size in
30 media::VideoCaptureFormat* video_format); 31 // |frame_size|. Returns the index of the first byte of the first video
31 static base::File OpenFileForRead(const base::FilePath& file_path); 32 // frame. If parsing |mapped_file| failed, returns -1.
33 // Restrictions: Only trivial Y4M per-frame headers and MJPEG are supported.
34 static size_t ParseFileAndExtractVideoFormat(
35 const base::MemoryMappedFile* mapped_file,
36 media::VideoCaptureFormat* video_format,
37 int* frame_size);
38
39 // Opens a given file for reading, and returns the memory mapped file to the
40 // caller, who is responsible for closing it.
41 static scoped_ptr<base::MemoryMappedFile>
42 OpenFileForRead(const base::FilePath& file_path);
32 43
33 // Constructor of the class, with a fully qualified file path as input, which 44 // Constructor of the class, with a fully qualified file path as input, which
34 // represents the Y4M video file to stream repeatedly. 45 // represents the Y4M or MJPEG file to stream repeatedly.
35 explicit FileVideoCaptureDevice(const base::FilePath& file_path); 46 explicit FileVideoCaptureDevice(const base::FilePath& file_path);
36 47
37 // VideoCaptureDevice implementation, class methods. 48 // VideoCaptureDevice implementation, class methods.
38 ~FileVideoCaptureDevice() override; 49 ~FileVideoCaptureDevice() override;
39 void AllocateAndStart(const VideoCaptureParams& params, 50 void AllocateAndStart(const VideoCaptureParams& params,
40 scoped_ptr<VideoCaptureDevice::Client> client) override; 51 scoped_ptr<VideoCaptureDevice::Client> client) override;
41 void StopAndDeAllocate() override; 52 void StopAndDeAllocate() override;
42 53
43 private: 54 private:
44 // Returns size in bytes of an I420 frame, not including possible paddings,
45 // defined by |capture_format_|.
46 int CalculateFrameSize() const;
47
48 // Called on the |capture_thread_|. 55 // Called on the |capture_thread_|.
49 void OnAllocateAndStart(const VideoCaptureParams& params, 56 void OnAllocateAndStart(const VideoCaptureParams& params,
50 scoped_ptr<Client> client); 57 scoped_ptr<Client> client);
51 void OnStopAndDeAllocate(); 58 void OnStopAndDeAllocate();
59 const uint8_t* GetNextFrame();
52 void OnCaptureTask(); 60 void OnCaptureTask();
53 61
54 // |thread_checker_| is used to check that destructor, AllocateAndStart() and 62 // |thread_checker_| is used to check that destructor, AllocateAndStart() and
55 // StopAndDeAllocate() are called in the correct thread that owns the object. 63 // StopAndDeAllocate() are called in the correct thread that owns the object.
56 base::ThreadChecker thread_checker_; 64 base::ThreadChecker thread_checker_;
57 65
58 // |capture_thread_| is used for internal operations via posting tasks to it. 66 // |capture_thread_| is used for internal operations via posting tasks to it.
59 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate(). 67 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate().
60 base::Thread capture_thread_; 68 base::Thread capture_thread_;
61 // The following members belong to |capture_thread_|. 69 // The following members belong to |capture_thread_|.
62 scoped_ptr<VideoCaptureDevice::Client> client_; 70 scoped_ptr<VideoCaptureDevice::Client> client_;
63 const base::FilePath file_path_; 71 const base::FilePath file_path_;
64 base::File file_; 72 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
65 scoped_ptr<uint8[]> video_frame_;
66 VideoCaptureFormat capture_format_; 73 VideoCaptureFormat capture_format_;
67 int frame_size_; 74 int frame_size_;
68 int64 current_byte_index_; 75 size_t current_byte_index_;
69 int64 first_frame_byte_index_; 76 size_t first_frame_byte_index_;
70 // Target time for the next frame. 77 // Target time for the next frame.
71 base::TimeTicks next_frame_time_; 78 base::TimeTicks next_frame_time_;
72 79
73 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice); 80 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice);
74 }; 81 };
75 82
76 } // namespace media 83 } // namespace media
77 84
78 #endif // MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_ 85 #endif // MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW
« 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