Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / video / file_video_capture_device.h
blobf50f04146d37094c6d3033412336858461961233
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.
5 #ifndef MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_
6 #define MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_
8 #include <string>
10 #include "base/files/file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_checker.h"
14 #include "media/capture/video/video_capture_device.h"
16 namespace media {
18 // 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 // only supported file format is YUV4MPEG2 (a.k.a. Y4M), a minimal container
21 // with a series of uncompressed video only frames, see the link
22 // http://wiki.multimedia.cx/index.php?title=YUV4MPEG2 for more information
23 // on the file format. Several restrictions and notes apply, see the
24 // implementation file.
25 // Example videos can be found in http://media.xiph.org/video/derf.
26 class MEDIA_EXPORT FileVideoCaptureDevice : public VideoCaptureDevice {
27 public:
28 static int64 ParseFileAndExtractVideoFormat(
29 base::File* file,
30 media::VideoCaptureFormat* video_format);
31 static base::File OpenFileForRead(const base::FilePath& file_path);
33 // Constructor of the class, with a fully qualified file path as input, which
34 // represents the Y4M video file to stream repeatedly.
35 explicit FileVideoCaptureDevice(const base::FilePath& file_path);
37 // VideoCaptureDevice implementation, class methods.
38 ~FileVideoCaptureDevice() override;
39 void AllocateAndStart(const VideoCaptureParams& params,
40 scoped_ptr<VideoCaptureDevice::Client> client) override;
41 void StopAndDeAllocate() override;
43 private:
44 // Returns size in bytes of an I420 frame, not including possible paddings,
45 // defined by |capture_format_|.
46 int CalculateFrameSize() const;
48 // Called on the |capture_thread_|.
49 void OnAllocateAndStart(const VideoCaptureParams& params,
50 scoped_ptr<Client> client);
51 void OnStopAndDeAllocate();
52 void OnCaptureTask();
54 // |thread_checker_| is used to check that destructor, AllocateAndStart() and
55 // StopAndDeAllocate() are called in the correct thread that owns the object.
56 base::ThreadChecker thread_checker_;
58 // |capture_thread_| is used for internal operations via posting tasks to it.
59 // It is active between OnAllocateAndStart() and OnStopAndDeAllocate().
60 base::Thread capture_thread_;
61 // The following members belong to |capture_thread_|.
62 scoped_ptr<VideoCaptureDevice::Client> client_;
63 const base::FilePath file_path_;
64 base::File file_;
65 scoped_ptr<uint8[]> video_frame_;
66 VideoCaptureFormat capture_format_;
67 int frame_size_;
68 int64 current_byte_index_;
69 int64 first_frame_byte_index_;
70 // Target time for the next frame.
71 base::TimeTicks next_frame_time_;
73 DISALLOW_COPY_AND_ASSIGN(FileVideoCaptureDevice);
76 } // namespace media
78 #endif // MEDIA_VIDEO_CAPTURE_FILE_VIDEO_CAPTURE_DEVICE_H_