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 // This file contains a class that can write audio and/or video to file in 12 // multiple file formats. The unencoded input data is written to file in the 13 // encoded format specified. 14 15 #ifndef WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_ 16 #define WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_ 17 18 #include <list> 19 20 #include "webrtc/base/platform_thread.h" 21 #include "webrtc/common_audio/resampler/include/resampler.h" 22 #include "webrtc/common_types.h" 23 #include "webrtc/engine_configurations.h" 24 #include "webrtc/modules/include/module_common_types.h" 25 #include "webrtc/modules/media_file/media_file.h" 26 #include "webrtc/modules/media_file/media_file_defines.h" 27 #include "webrtc/modules/utility/include/file_recorder.h" 28 #include "webrtc/modules/utility/source/coder.h" 29 #include "webrtc/system_wrappers/include/event_wrapper.h" 30 #include "webrtc/system_wrappers/include/tick_util.h" 31 #include "webrtc/typedefs.h" 32 33 namespace webrtc { 34 // The largest decoded frame size in samples (60ms with 32kHz sample rate). 35 enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60*32}; 36 enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2}; 37 enum { kMaxAudioBufferQueueLength = 100 }; 38 39 class CriticalSectionWrapper; 40 41 class FileRecorderImpl : public FileRecorder 42 { 43 public: 44 FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat); 45 virtual ~FileRecorderImpl(); 46 47 // FileRecorder functions. 48 virtual int32_t RegisterModuleFileCallback(FileCallback* callback); 49 virtual FileFormats RecordingFileFormat() const; 50 virtual int32_t StartRecordingAudioFile( 51 const char* fileName, 52 const CodecInst& codecInst, 53 uint32_t notificationTimeMs) override; 54 virtual int32_t StartRecordingAudioFile( 55 OutStream& destStream, 56 const CodecInst& codecInst, 57 uint32_t notificationTimeMs) override; 58 virtual int32_t StopRecording(); 59 virtual bool IsRecording() const; 60 virtual int32_t codec_info(CodecInst& codecInst) const; 61 virtual int32_t RecordAudioToFile( 62 const AudioFrame& frame, 63 const TickTime* playoutTS = NULL); 64 virtual int32_t StartRecordingVideoFile( 65 const char* fileName, 66 const CodecInst& audioCodecInst, 67 const VideoCodec& videoCodecInst, 68 bool videoOnly = false) override 69 { 70 return -1; 71 } RecordVideoToFile(const VideoFrame & videoFrame)72 virtual int32_t RecordVideoToFile(const VideoFrame& videoFrame) { 73 return -1; 74 } 75 76 protected: 77 int32_t WriteEncodedAudioData(const int8_t* audioBuffer, 78 size_t bufferLength); 79 80 int32_t SetUpAudioEncoder(); 81 82 uint32_t _instanceID; 83 FileFormats _fileFormat; 84 MediaFile* _moduleFile; 85 86 private: 87 CodecInst codec_info_; 88 int8_t _audioBuffer[MAX_AUDIO_BUFFER_IN_BYTES]; 89 AudioCoder _audioEncoder; 90 Resampler _audioResampler; 91 }; 92 } // namespace webrtc 93 #endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_ 94