1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_ 12 #define WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_ 13 14 #include <cstdio> 15 #include <string> 16 17 #include "typedefs.h" 18 19 namespace webrtc { 20 namespace test { 21 22 // Handles writing of video files. 23 class FrameWriter { 24 public: ~FrameWriter()25 virtual ~FrameWriter() {} 26 27 // Initializes the file handler, i.e. opens the input and output files etc. 28 // This must be called before reading or writing frames has started. 29 // Returns false if an error has occurred, in addition to printing to stderr. 30 virtual bool Init() = 0; 31 32 // Writes a frame of the configured frame length to the output file. 33 // Returns true if the write was successful, false otherwise. 34 virtual bool WriteFrame(WebRtc_UWord8* frame_buffer) = 0; 35 36 // Closes the output file if open. Essentially makes this class impossible 37 // to use anymore. Will also be invoked by the destructor. 38 virtual void Close() = 0; 39 40 // Frame length in bytes of a single frame image. 41 virtual int FrameLength() = 0; 42 }; 43 44 class FrameWriterImpl : public FrameWriter { 45 public: 46 // Creates a file handler. The input file is assumed to exist and be readable 47 // and the output file must be writable. 48 // Parameters: 49 // output_filename The file to write. Will be overwritten if already 50 // existing. 51 // frame_length_in_bytes The size of each frame. 52 // For YUV: 3*width*height/2 53 FrameWriterImpl(std::string output_filename, int frame_length_in_bytes); 54 virtual ~FrameWriterImpl(); 55 bool Init(); 56 bool WriteFrame(WebRtc_UWord8* frame_buffer); 57 void Close(); FrameLength()58 int FrameLength() { return frame_length_in_bytes_; } 59 60 private: 61 std::string output_filename_; 62 int frame_length_in_bytes_; 63 int number_of_frames_; 64 FILE* output_file_; 65 }; 66 67 } // namespace test 68 } // namespace webrtc 69 70 #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_ 71