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

Side by Side Diff: webrtc/test/testsupport/frame_reader.h

Issue 2362683002: New helper function test::ReadI420Buffer, refactor FrameReader to use it. (Closed)
Patch Set: Created 4 years, 2 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 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ 11 #ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
12 #define WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ 12 #define WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
13 13
14 #include <stdio.h> 14 #include <stdio.h>
15 15
16 #include <string> 16 #include <string>
17 17
18 #include "webrtc/base/scoped_ref_ptr.h"
18 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
19 20
20 namespace webrtc { 21 namespace webrtc {
22 class I420Buffer;
23
21 namespace test { 24 namespace test {
22 25
23 // Handles reading of frames from video files. 26 // Handles reading of frames from video files.
24 class FrameReader { 27 class FrameReader {
25 public: 28 public:
26 virtual ~FrameReader() {} 29 virtual ~FrameReader() {}
27 30
28 // Initializes the frame reader, i.e. opens the input file. 31 // Initializes the frame reader, i.e. opens the input file.
29 // This must be called before reading of frames has started. 32 // This must be called before reading of frames has started.
30 // Returns false if an error has occurred, in addition to printing to stderr. 33 // Returns false if an error has occurred, in addition to printing to stderr.
31 virtual bool Init() = 0; 34 virtual bool Init() = 0;
32 35
33 // Reads a frame into the supplied buffer, which must contain enough space 36 // Reads a frame into the supplied buffer, which must contain enough space
kjellander_webrtc 2016/09/22 11:29:37 This comment also is a bit odd now, a I420Buffer s
nisse-webrtc 2016/09/22 11:48:15 Rewriting the comment.
34 // for the frame size. 37 // for the frame size.
35 // Returns true if there are more frames to read, false if we've already 38 // Returns true if there are more frames to read, false if we've already
36 // read the last frame (in the previous call). 39 // read the last frame (in the previous call).
37 virtual bool ReadFrame(uint8_t* source_buffer) = 0; 40 virtual rtc::scoped_refptr<I420Buffer> ReadFrame() = 0;
38 41
39 // Closes the input file if open. Essentially makes this class impossible 42 // Closes the input file if open. Essentially makes this class impossible
40 // to use anymore. Will also be invoked by the destructor. 43 // to use anymore. Will also be invoked by the destructor.
41 virtual void Close() = 0; 44 virtual void Close() = 0;
42 45
43 // Frame length in bytes of a single frame image. 46 // Frame length in bytes of a single frame image.
44 virtual size_t FrameLength() = 0; 47 virtual size_t FrameLength() = 0;
45 // Total number of frames in the input video source. 48 // Total number of frames in the input video source.
46 virtual int NumberOfFrames() = 0; 49 virtual int NumberOfFrames() = 0;
47 }; 50 };
48 51
49 class FrameReaderImpl : public FrameReader { 52 class FrameReaderImpl : public FrameReader {
50 public: 53 public:
51 // Creates a file handler. The input file is assumed to exist and be readable. 54 // Creates a file handler. The input file is assumed to exist and be readable.
52 // Parameters: 55 // Parameters:
53 // input_filename The file to read from. 56 // input_filename The file to read from.
54 // frame_length_in_bytes The size of each frame. 57 // frame_length_in_bytes The size of each frame.
kjellander_webrtc 2016/09/22 11:29:37 Update/remove this documentation
nisse-webrtc 2016/09/22 11:48:15 Done.
55 // For YUV this is 3 * width * height / 2 58 // For YUV this is 3 * width * height / 2
56 FrameReaderImpl(std::string input_filename, size_t frame_length_in_bytes); 59 FrameReaderImpl(std::string input_filename, int width, int height);
57 ~FrameReaderImpl() override; 60 ~FrameReaderImpl() override;
58 bool Init() override; 61 bool Init() override;
59 bool ReadFrame(uint8_t* source_buffer) override; 62 rtc::scoped_refptr<I420Buffer> ReadFrame() override;
60 void Close() override; 63 void Close() override;
61 size_t FrameLength() override; 64 size_t FrameLength() override;
62 int NumberOfFrames() override; 65 int NumberOfFrames() override;
63 66
64 private: 67 private:
65 std::string input_filename_; 68 std::string input_filename_;
66 size_t frame_length_in_bytes_; 69 size_t frame_length_in_bytes_;
70 int width_;
71 int height_;
67 int number_of_frames_; 72 int number_of_frames_;
68 FILE* input_file_; 73 FILE* input_file_;
69 }; 74 };
70 75
71 } // namespace test 76 } // namespace test
72 } // namespace webrtc 77 } // namespace webrtc
73 78
74 #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ 79 #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698