2011-12-08 07:42:18 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|
|
|
|
|
#define WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2011-12-08 07:42:18 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/scoped_ref_ptr.h"
|
2013-02-13 09:35:12 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2011-12-08 07:42:18 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-09-30 04:14:07 -07:00
|
|
|
class I420Buffer;
|
2011-12-08 07:42:18 +00:00
|
|
|
namespace test {
|
|
|
|
|
|
2016-09-30 04:14:07 -07:00
|
|
|
// Handles reading of I420 frames from video files.
|
2011-12-08 07:42:18 +00:00
|
|
|
class FrameReader {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~FrameReader() {}
|
|
|
|
|
|
|
|
|
|
// Initializes the frame reader, i.e. opens the input file.
|
|
|
|
|
// This must be called before reading of frames has started.
|
|
|
|
|
// Returns false if an error has occurred, in addition to printing to stderr.
|
|
|
|
|
virtual bool Init() = 0;
|
|
|
|
|
|
2016-09-30 04:14:07 -07:00
|
|
|
// Reads a frame from the input file. On success, returns the frame.
|
|
|
|
|
// Returns nullptr if encountering end of file or a read error.
|
|
|
|
|
virtual rtc::scoped_refptr<I420Buffer> ReadFrame() = 0;
|
2011-12-08 07:42:18 +00:00
|
|
|
|
|
|
|
|
// Closes the input file if open. Essentially makes this class impossible
|
|
|
|
|
// to use anymore. Will also be invoked by the destructor.
|
|
|
|
|
virtual void Close() = 0;
|
|
|
|
|
|
|
|
|
|
// Frame length in bytes of a single frame image.
|
2013-02-04 10:07:17 +00:00
|
|
|
virtual size_t FrameLength() = 0;
|
2011-12-08 07:42:18 +00:00
|
|
|
// Total number of frames in the input video source.
|
|
|
|
|
virtual int NumberOfFrames() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-22 01:26:59 -08:00
|
|
|
class YuvFrameReaderImpl : public FrameReader {
|
2011-12-08 07:42:18 +00:00
|
|
|
public:
|
|
|
|
|
// Creates a file handler. The input file is assumed to exist and be readable.
|
|
|
|
|
// Parameters:
|
|
|
|
|
// input_filename The file to read from.
|
2016-09-30 04:14:07 -07:00
|
|
|
// width, height Size of each frame to read.
|
2017-02-22 01:26:59 -08:00
|
|
|
YuvFrameReaderImpl(std::string input_filename, int width, int height);
|
|
|
|
|
~YuvFrameReaderImpl() override;
|
2015-03-04 12:58:35 +00:00
|
|
|
bool Init() override;
|
2016-09-30 04:14:07 -07:00
|
|
|
rtc::scoped_refptr<I420Buffer> ReadFrame() override;
|
2015-03-04 12:58:35 +00:00
|
|
|
void Close() override;
|
|
|
|
|
size_t FrameLength() override;
|
|
|
|
|
int NumberOfFrames() override;
|
2011-12-08 07:42:18 +00:00
|
|
|
|
|
|
|
|
private:
|
2017-02-22 01:26:59 -08:00
|
|
|
const std::string input_filename_;
|
2013-02-04 10:07:17 +00:00
|
|
|
size_t frame_length_in_bytes_;
|
2017-02-22 01:26:59 -08:00
|
|
|
const int width_;
|
|
|
|
|
const int height_;
|
2011-12-08 07:42:18 +00:00
|
|
|
int number_of_frames_;
|
|
|
|
|
FILE* input_file_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|