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

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

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CAPTURE_VIDEO_FILE_VIDEO_CAPTURE_DEVICE_H_
6 #define MEDIA_CAPTURE_VIDEO_FILE_VIDEO_CAPTURE_DEVICE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12
13 #include "base/files/file.h"
14 #include "base/files/memory_mapped_file.h"
15 #include "base/macros.h"
16 #include "base/threading/thread.h"
17 #include "base/threading/thread_checker.h"
18 #include "media/capture/video/video_capture_device.h"
19
20 namespace media {
21
22 class VideoFileParser;
23
24 // Implementation of a VideoCaptureDevice class that reads from a file. Used for
25 // testing the video capture pipeline when no real hardware is available. The
26 // supported file formats are YUV4MPEG2 (a.k.a. Y4M) and MJPEG/JPEG. YUV4MPEG2
27 // is a minimal container with a series of uncompressed video only frames, see
28 // the link http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more
29 // information on the file format. Several restrictions and notes apply, see the
30 // implementation file.
31 // Example Y4M videos can be found in http://media.xiph.org/video/derf.
32 // Example MJPEG videos can be found in media/data/test/bear.mjpeg.
33 // Restrictions: Y4M videos should have .y4m file extension and MJPEG videos
34 // should have .mjpeg file extension.
35 class CAPTURE_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
36 public:
37 // Reads and parses the header of a |file_path|, returning the collected
38 // pixel format in |video_format|. Returns true on file parsed successfully,
39 // or false.
40 // Restrictions: Only trivial Y4M per-frame headers and MJPEG are supported.
41 static bool GetVideoCaptureFormat(const base::FilePath& file_path,
42 media::VideoCaptureFormat* video_format);
43
44 // Constructor of the class, with a fully qualified file path as input, which
45 // represents the Y4M or MJPEG file to stream repeatedly.
46 explicit FileVideoCaptureDevice(const base::FilePath& file_path);
47
48 // VideoCaptureDevice implementation, class methods.
49 ~FileVideoCaptureDevice() override;
50 void AllocateAndStart(
51 const VideoCaptureParams& params,
52 std::unique_ptr<VideoCaptureDevice::Client> client) override;
53 void StopAndDeAllocate() override;
54
55 private:
56 // Opens a given file |file_path| for reading, and stores collected format
57 // information in |video_format|. Returns the parsed file to the
58 // caller, who is responsible for closing it.
59 static std::unique_ptr<VideoFileParser> GetVideoFileParser(
60 const base::FilePath& file_path,
61 media::VideoCaptureFormat* video_format);
62
63 // Called on the |capture_thread_|.
64 void OnAllocateAndStart(const VideoCaptureParams& params,
65 std::unique_ptr<Client> client);
66 void OnStopAndDeAllocate();
67 const uint8_t* GetNextFrame();
68 void OnCaptureTask();
69
70 // |thread_checker_| is used to check that destructor, AllocateAndStart() and
71 // StopAndDeAllocate() are called in the correct thread that owns the object.
72 base::ThreadChecker thread_checker_;
73
74 // |capture_thread_| is used for internal operations via posting tasks to it.
75 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate().
76 base::Thread capture_thread_;
77 // The following members belong to |capture_thread_|.
78 std::unique_ptr<VideoCaptureDevice::Client> client_;
79 const base::FilePath file_path_;
80 std::unique_ptr<VideoFileParser> file_parser_;
81 VideoCaptureFormat capture_format_;
82 // Target time for the next frame.
83 base::TimeTicks next_frame_time_;
84 // The system time when we receive the first frame.
85 base::TimeTicks first_ref_time_;
86
87 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice);
88 };
89
90 } // namespace media
91
92 #endif // MEDIA_CAPTURE_VIDEO_FILE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device_unittest.cc ('k') | media/capture/video/file_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698