#ifndef MEDIA_GPU_TEST_VIDEO_FRAME_FILE_WRITER_H_
#define MEDIA_GPU_TEST_VIDEO_FRAME_FILE_WRITER_H_
#include <limits>
#include <memory>
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
#include "media/gpu/test/video_frame_helpers.h"
namespace media {
class VideoFrameMapper;
namespace test {
class VideoFrameFileWriter : public VideoFrameProcessor {
public:
enum class OutputFormat {
kPNG = 0,
kYUV,
};
VideoFrameFileWriter(const VideoFrameFileWriter&) = delete;
VideoFrameFileWriter& operator=(const VideoFrameFileWriter&) = delete;
~VideoFrameFileWriter() override;
static std::unique_ptr<VideoFrameFileWriter> Create(
const base::FilePath& output_folder,
OutputFormat output_format = OutputFormat::kPNG,
size_t output_limit = std::numeric_limits<size_t>::max(),
const base::FilePath::StringType& output_file_prefix =
base::FilePath::StringType());
void ProcessVideoFrame(scoped_refptr<const VideoFrame> video_frame,
size_t frame_index) override;
bool WaitUntilDone() override;
private:
VideoFrameFileWriter(const base::FilePath& output_folder,
OutputFormat output_format,
size_t output_limit,
const base::FilePath::StringType& output_prefix);
bool Initialize();
void CleanUpOnWriterThread();
void ProcessVideoFrameTask(scoped_refptr<const VideoFrame> video_frame,
size_t frame_index);
void WriteVideoFramePNG(scoped_refptr<const VideoFrame> video_frame,
const base::FilePath& filename);
void WriteVideoFrameYUV(scoped_refptr<const VideoFrame> video_frame,
const base::FilePath& filename);
const base::FilePath output_folder_;
const OutputFormat output_format_;
const size_t output_limit_;
const base::FilePath::StringType output_file_prefix_;
std::unique_ptr<VideoFrameMapper> video_frame_mapper_;
size_t num_frames_writing_ GUARDED_BY(frame_writer_lock_);
size_t num_frames_writes_requested_ = 0u;
base::Thread frame_writer_thread_;
mutable base::Lock frame_writer_lock_;
mutable base::ConditionVariable frame_writer_cv_;
SEQUENCE_CHECKER(writer_sequence_checker_);
SEQUENCE_CHECKER(writer_thread_sequence_checker_);
};
}
}
#endif