1 /* 2 * Copyright (c) 2012 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_VIDEO_ENGINE_TEST_LIBVIETEST_INCLUDE_VIE_TO_FILE_RENDERER_H_ 12 #define WEBRTC_VIDEO_ENGINE_TEST_LIBVIETEST_INCLUDE_VIE_TO_FILE_RENDERER_H_ 13 14 #include <stdio.h> 15 #include <string.h> 16 17 #include <list> 18 #include <string> 19 20 #include "webrtc/base/constructormagic.h" 21 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 22 #include "webrtc/video_engine/include/vie_render.h" 23 24 namespace webrtc { 25 class CriticalSectionWrapper; 26 class EventWrapper; 27 class ThreadWrapper; 28 }; // namespace webrtc 29 30 namespace test { 31 struct Frame; 32 }; // namespace test 33 34 class ViEToFileRenderer: public webrtc::ExternalRenderer { 35 public: 36 ViEToFileRenderer(); 37 virtual ~ViEToFileRenderer(); 38 39 // Returns false if we fail opening the output filename for writing. 40 bool PrepareForRendering(const std::string& output_path, 41 const std::string& output_filename); 42 43 // Closes the output file. 44 void StopRendering(); 45 46 // Deletes the closed output file from the file system. This is one option 47 // after calling StopRendering, the other being KeepOutputFile. This file 48 // renderer will forget about the file after this call and can be used again. 49 bool DeleteOutputFile(); 50 51 // Renames the closed output file to its previous name with the provided 52 // prefix prepended. This file renderer will forget about the file after this 53 // call and can be used again. 54 bool SaveOutputFile(const std::string& prefix); 55 56 // Implementation of ExternalRenderer: 57 int FrameSizeChange(unsigned int width, unsigned int height, 58 unsigned int number_of_streams) OVERRIDE; 59 60 int DeliverFrame(unsigned char* buffer, 61 int buffer_size, 62 uint32_t time_stamp, 63 int64_t ntp_time_ms, 64 int64_t render_time, 65 void* handle) OVERRIDE; 66 67 bool IsTextureSupported() OVERRIDE; 68 69 const std::string GetFullOutputPath() const; 70 71 private: 72 typedef std::list<test::Frame*> FrameQueue; 73 74 static bool RunRenderThread(void* obj); 75 void ForgetOutputFile(); 76 bool ProcessRenderQueue(); 77 78 FILE* output_file_; 79 std::string output_path_; 80 std::string output_filename_; 81 webrtc::scoped_ptr<webrtc::ThreadWrapper> thread_; 82 webrtc::scoped_ptr<webrtc::CriticalSectionWrapper> frame_queue_cs_; 83 webrtc::scoped_ptr<webrtc::EventWrapper> frame_render_event_; 84 FrameQueue render_queue_; 85 FrameQueue free_frame_queue_; 86 }; 87 88 #endif // WEBRTC_VIDEO_ENGINE_TEST_LIBVIETEST_INCLUDE_VIE_TO_FILE_RENDERER_H_ 89