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

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: 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.
26 class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice { 27 class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
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
kcwu 2015/08/14 09:01:37 remove this line?
henryhsu 2015/08/14 11:22:26 Done. Thanks.
35 static int64_t ParseFileAndExtractVideoFormat(
36 const base::MemoryMappedFile* mapped_file,
37 media::VideoCaptureFormat* video_format,
38 int* frame_size);
39
40 // Opens a given file for reading, and returns the memory mapped file to the
41 // caller, who is responsible for closing it.
42 static scoped_ptr<base::MemoryMappedFile>
43 OpenFileForRead(const base::FilePath& file_path);
32 44
33 // Constructor of the class, with a fully qualified file path as input, which 45 // Constructor of the class, with a fully qualified file path as input, which
34 // represents the Y4M video file to stream repeatedly. 46 // represents the Y4M/MJPEG file to stream repeatedly.
35 explicit FileVideoCaptureDevice(const base::FilePath& file_path); 47 explicit FileVideoCaptureDevice(const base::FilePath& file_path);
36 48
37 // VideoCaptureDevice implementation, class methods. 49 // VideoCaptureDevice implementation, class methods.
38 ~FileVideoCaptureDevice() override; 50 ~FileVideoCaptureDevice() override;
39 void AllocateAndStart(const VideoCaptureParams& params, 51 void AllocateAndStart(const VideoCaptureParams& params,
40 scoped_ptr<VideoCaptureDevice::Client> client) override; 52 scoped_ptr<VideoCaptureDevice::Client> client) override;
41 void StopAndDeAllocate() override; 53 void StopAndDeAllocate() override;
42 54
43 private: 55 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_|. 56 // Called on the |capture_thread_|.
49 void OnAllocateAndStart(const VideoCaptureParams& params, 57 void OnAllocateAndStart(const VideoCaptureParams& params,
50 scoped_ptr<Client> client); 58 scoped_ptr<Client> client);
51 void OnStopAndDeAllocate(); 59 void OnStopAndDeAllocate();
60 const uint8_t* GetNextFrame();
52 void OnCaptureTask(); 61 void OnCaptureTask();
53 62
54 // |thread_checker_| is used to check that destructor, AllocateAndStart() and 63 // |thread_checker_| is used to check that destructor, AllocateAndStart() and
55 // StopAndDeAllocate() are called in the correct thread that owns the object. 64 // StopAndDeAllocate() are called in the correct thread that owns the object.
56 base::ThreadChecker thread_checker_; 65 base::ThreadChecker thread_checker_;
57 66
58 // |capture_thread_| is used for internal operations via posting tasks to it. 67 // |capture_thread_| is used for internal operations via posting tasks to it.
59 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate(). 68 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate().
60 base::Thread capture_thread_; 69 base::Thread capture_thread_;
61 // The following members belong to |capture_thread_|. 70 // The following members belong to |capture_thread_|.
62 scoped_ptr<VideoCaptureDevice::Client> client_; 71 scoped_ptr<VideoCaptureDevice::Client> client_;
63 const base::FilePath file_path_; 72 const base::FilePath file_path_;
64 base::File file_; 73 scoped_ptr<base::MemoryMappedFile> mapped_file_;
65 scoped_ptr<uint8[]> video_frame_;
66 VideoCaptureFormat capture_format_; 74 VideoCaptureFormat capture_format_;
67 int frame_size_; 75 int frame_size_;
68 int64 current_byte_index_; 76 int64_t current_byte_index_;
69 int64 first_frame_byte_index_; 77 int64_t first_frame_byte_index_;
70 // Target time for the next frame. 78 // Target time for the next frame.
71 base::TimeTicks next_frame_time_; 79 base::TimeTicks next_frame_time_;
72 80
73 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice); 81 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice);
74 }; 82 };
75 83
76 } // namespace media 84 } // namespace media
77 85
78 #endif // MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_ 86 #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