Remove avi recorder and corresponding enable_video flags.
R=mflodman@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/42099004
Cr-Commit-Position: refs/heads/master@{#8554}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8554 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/utility/source/file_player_impl.cc b/webrtc/modules/utility/source/file_player_impl.cc
index 5d935fb..1803e8a 100644
--- a/webrtc/modules/utility/source/file_player_impl.cc
+++ b/webrtc/modules/utility/source/file_player_impl.cc
@@ -11,12 +11,6 @@
#include "webrtc/modules/utility/source/file_player_impl.h"
#include "webrtc/system_wrappers/interface/logging.h"
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
- #include "webrtc/modules/utility/source/frame_scaler.h"
- #include "webrtc/modules/utility/source/video_coder.h"
- #include "webrtc/system_wrappers/interface/tick_util.h"
-#endif
-
namespace webrtc {
FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
FileFormats fileFormat)
@@ -31,16 +25,10 @@
case kFileFormatPcm32kHzFile:
// audio formats
return new FilePlayerImpl(instanceID, fileFormat);
- case kFileFormatAviFile:
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
- return new VideoFilePlayerImpl(instanceID, fileFormat);
-#else
+ default:
assert(false);
return NULL;
-#endif
}
- assert(false);
- return NULL;
}
void FilePlayer::DestroyFilePlayer(FilePlayer* player)
@@ -412,258 +400,4 @@
_numberOf10MsInDecoder = 0;
return 0;
}
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-VideoFilePlayerImpl::VideoFilePlayerImpl(uint32_t instanceID,
- FileFormats fileFormat)
- : FilePlayerImpl(instanceID, fileFormat),
- video_decoder_(new VideoCoder()),
- video_codec_info_(),
- _decodedVideoFrames(0),
- _encodedData(*new EncodedVideoData()),
- _frameScaler(*new FrameScaler()),
- _critSec(CriticalSectionWrapper::CreateCriticalSection()),
- _startTime(),
- _accumulatedRenderTimeMs(0),
- _frameLengthMS(0),
- _numberOfFramesRead(0),
- _videoOnly(false) {
- memset(&video_codec_info_, 0, sizeof(video_codec_info_));
-}
-
-VideoFilePlayerImpl::~VideoFilePlayerImpl()
-{
- delete _critSec;
- delete &_frameScaler;
- video_decoder_.reset();
- delete &_encodedData;
-}
-
-int32_t VideoFilePlayerImpl::StartPlayingVideoFile(
- const char* fileName,
- bool loop,
- bool videoOnly)
-{
- CriticalSectionScoped lock( _critSec);
-
- if(_fileModule.StartPlayingVideoFile(fileName, loop, videoOnly,
- _fileFormat) != 0)
- {
- return -1;
- }
-
- _decodedVideoFrames = 0;
- _accumulatedRenderTimeMs = 0;
- _frameLengthMS = 0;
- _numberOfFramesRead = 0;
- _videoOnly = videoOnly;
-
- // Set up video_codec_info_ according to file,
- if(SetUpVideoDecoder() != 0)
- {
- StopPlayingFile();
- return -1;
- }
- if(!videoOnly)
- {
- // Set up _codec according to file,
- if(SetUpAudioDecoder() != 0)
- {
- StopPlayingFile();
- return -1;
- }
- }
- return 0;
-}
-
-int32_t VideoFilePlayerImpl::StopPlayingFile()
-{
- CriticalSectionScoped lock( _critSec);
-
- _decodedVideoFrames = 0;
- video_decoder_.reset(new VideoCoder());
-
- return FilePlayerImpl::StopPlayingFile();
-}
-
-int32_t VideoFilePlayerImpl::GetVideoFromFile(I420VideoFrame& videoFrame,
- uint32_t outWidth,
- uint32_t outHeight)
-{
- CriticalSectionScoped lock( _critSec);
-
- int32_t retVal = GetVideoFromFile(videoFrame);
- if(retVal != 0)
- {
- return retVal;
- }
- if (!videoFrame.IsZeroSize())
- {
- retVal = _frameScaler.ResizeFrameIfNeeded(&videoFrame, outWidth,
- outHeight);
- }
- return retVal;
-}
-
-int32_t VideoFilePlayerImpl::GetVideoFromFile(I420VideoFrame& videoFrame)
-{
- CriticalSectionScoped lock( _critSec);
- // No new video data read from file.
- if(_encodedData.payloadSize == 0)
- {
- videoFrame.ResetSize();
- return -1;
- }
- int32_t retVal = 0;
- if(strncmp(video_codec_info_.plName, "I420", 5) == 0)
- {
- int size_y = video_codec_info_.width * video_codec_info_.height;
- int half_width = (video_codec_info_.width + 1) / 2;
- int half_height = (video_codec_info_.height + 1) / 2;
- int size_uv = half_width * half_height;
-
- // TODO(mikhal): Do we need to align the stride here?
- const uint8_t* buffer_y = _encodedData.payloadData;
- const uint8_t* buffer_u = buffer_y + size_y;
- const uint8_t* buffer_v = buffer_u + size_uv;
- videoFrame.CreateFrame(size_y, buffer_y,
- size_uv, buffer_u,
- size_uv, buffer_v,
- video_codec_info_.width, video_codec_info_.height,
- video_codec_info_.height, half_width, half_width);
- }else
- {
- // Set the timestamp manually since there is no timestamp in the file.
- // Update timestam according to 90 kHz stream.
- _encodedData.timeStamp += (90000 / video_codec_info_.maxFramerate);
- retVal = video_decoder_->Decode(videoFrame, _encodedData);
- }
-
- int64_t renderTimeMs = TickTime::MillisecondTimestamp();
- videoFrame.set_render_time_ms(renderTimeMs);
-
- // Indicate that the current frame in the encoded buffer is old/has
- // already been read.
- _encodedData.payloadSize = 0;
- if( retVal == 0)
- {
- _decodedVideoFrames++;
- }
- return retVal;
-}
-
-int32_t VideoFilePlayerImpl::video_codec_info(
- VideoCodec& videoCodec) const
-{
- if(video_codec_info_.plName[0] == 0)
- {
- return -1;
- }
- memcpy(&videoCodec, &video_codec_info_, sizeof(VideoCodec));
- return 0;
-}
-
-int32_t VideoFilePlayerImpl::TimeUntilNextVideoFrame()
-{
- if(_fileFormat != kFileFormatAviFile)
- {
- return -1;
- }
- if(!_fileModule.IsPlaying())
- {
- return -1;
- }
- if(_encodedData.payloadSize <= 0)
- {
- // Read next frame from file.
- CriticalSectionScoped lock( _critSec);
-
- if(_fileFormat == kFileFormatAviFile)
- {
- // Get next video frame
- size_t encodedBufferLengthInBytes = _encodedData.bufferSize;
- if(_fileModule.PlayoutAVIVideoData(
- reinterpret_cast< int8_t*>(_encodedData.payloadData),
- encodedBufferLengthInBytes) != 0)
- {
- LOG(LS_WARNING) << "Error reading video data.";
- return -1;
- }
- _encodedData.payloadSize = encodedBufferLengthInBytes;
- _encodedData.codec = video_codec_info_.codecType;
- _numberOfFramesRead++;
-
- if(_accumulatedRenderTimeMs == 0)
- {
- _startTime = TickTime::Now();
- // This if-statement should only trigger once.
- _accumulatedRenderTimeMs = 1;
- } else {
- // A full seconds worth of frames have been read.
- if(_numberOfFramesRead % video_codec_info_.maxFramerate == 0)
- {
- // Frame rate is in frames per seconds. Frame length is
- // calculated as an integer division which means it may
- // be rounded down. Compensate for this every second.
- uint32_t rest = 1000%_frameLengthMS;
- _accumulatedRenderTimeMs += rest;
- }
- _accumulatedRenderTimeMs += _frameLengthMS;
- }
- }
- }
-
- int64_t timeToNextFrame;
- if(_videoOnly)
- {
- timeToNextFrame = _accumulatedRenderTimeMs -
- (TickTime::Now() - _startTime).Milliseconds();
-
- } else {
- // Synchronize with the audio stream instead of system clock.
- timeToNextFrame = _accumulatedRenderTimeMs - _decodedLengthInMS;
- }
- if(timeToNextFrame < 0)
- {
- return 0;
-
- } else if(timeToNextFrame > 0x0fffffff)
- {
- // Wraparound or audio stream has gone to far ahead of the video stream.
- return -1;
- }
- return static_cast<int32_t>(timeToNextFrame);
-}
-
-int32_t VideoFilePlayerImpl::SetUpVideoDecoder()
-{
- if (_fileModule.VideoCodecInst(video_codec_info_) != 0)
- {
- LOG(LS_WARNING) << "SetVideoDecoder() failed to retrieve codec info of "
- << "file data.";
- return -1;
- }
-
- int32_t useNumberOfCores = 1;
- if (video_decoder_->SetDecodeCodec(video_codec_info_, useNumberOfCores) !=
- 0) {
- LOG(LS_WARNING) << "SetUpVideoDecoder() codec "
- << video_codec_info_.plName << " not supported.";
- return -1;
- }
-
- _frameLengthMS = 1000/video_codec_info_.maxFramerate;
-
- // Size of unencoded data (I420) should be the largest possible frame size
- // in a file.
- const size_t KReadBufferSize = 3 * video_codec_info_.width *
- video_codec_info_.height / 2;
- _encodedData.VerifyAndAllocate(KReadBufferSize);
- _encodedData.encodedHeight = video_codec_info_.height;
- _encodedData.encodedWidth = video_codec_info_.width;
- _encodedData.payloadType = video_codec_info_.plType;
- _encodedData.timeStamp = 0;
- return 0;
-}
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
} // namespace webrtc
diff --git a/webrtc/modules/utility/source/file_player_impl.h b/webrtc/modules/utility/source/file_player_impl.h
index 3093ce2..f81e710 100644
--- a/webrtc/modules/utility/source/file_player_impl.h
+++ b/webrtc/modules/utility/source/file_player_impl.h
@@ -23,9 +23,6 @@
#include "webrtc/typedefs.h"
namespace webrtc {
-class VideoCoder;
-class FrameScaler;
-
class FilePlayerImpl : public FilePlayer
{
public:
@@ -78,45 +75,5 @@
Resampler _resampler;
float _scaling;
};
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-class VideoFilePlayerImpl: public FilePlayerImpl
-{
-public:
- VideoFilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
- ~VideoFilePlayerImpl();
-
- // FilePlayer functions.
- virtual int32_t TimeUntilNextVideoFrame();
- virtual int32_t StartPlayingVideoFile(const char* fileName,
- bool loop,
- bool videoOnly);
- virtual int32_t StopPlayingFile();
- virtual int32_t video_codec_info(VideoCodec& videoCodec) const;
- virtual int32_t GetVideoFromFile(I420VideoFrame& videoFrame);
- virtual int32_t GetVideoFromFile(I420VideoFrame& videoFrame,
- const uint32_t outWidth,
- const uint32_t outHeight);
-
-private:
- int32_t SetUpVideoDecoder();
-
- rtc::scoped_ptr<VideoCoder> video_decoder_;
- VideoCodec video_codec_info_;
- int32_t _decodedVideoFrames;
-
- EncodedVideoData& _encodedData;
-
- FrameScaler& _frameScaler;
- CriticalSectionWrapper* _critSec;
- TickTime _startTime;
- int64_t _accumulatedRenderTimeMs;
- uint32_t _frameLengthMS;
-
- int32_t _numberOfFramesRead;
- bool _videoOnly;
-};
-#endif //WEBRTC_MODULE_UTILITY_VIDEO
-
} // namespace webrtc
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
diff --git a/webrtc/modules/utility/source/file_recorder_impl.cc b/webrtc/modules/utility/source/file_recorder_impl.cc
index 11f70f6..29eede8 100644
--- a/webrtc/modules/utility/source/file_recorder_impl.cc
+++ b/webrtc/modules/utility/source/file_recorder_impl.cc
@@ -14,36 +14,11 @@
#include "webrtc/modules/utility/source/file_recorder_impl.h"
#include "webrtc/system_wrappers/interface/logging.h"
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
- #include "webrtc/modules/utility/source/frame_scaler.h"
- #include "webrtc/modules/utility/source/video_coder.h"
- #include "webrtc/modules/utility/source/video_frames_queue.h"
- #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
-#endif
-
namespace webrtc {
FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID,
FileFormats fileFormat)
{
- switch(fileFormat)
- {
- case kFileFormatWavFile:
- case kFileFormatCompressedFile:
- case kFileFormatPreencodedFile:
- case kFileFormatPcm16kHzFile:
- case kFileFormatPcm8kHzFile:
- case kFileFormatPcm32kHzFile:
- return new FileRecorderImpl(instanceID, fileFormat);
- case kFileFormatAviFile:
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
- return new AviRecorder(instanceID, fileFormat);
-#else
- assert(false);
- return NULL;
-#endif
- }
- assert(false);
- return NULL;
+ return new FileRecorderImpl(instanceID, fileFormat);
}
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder)
@@ -98,14 +73,9 @@
_amrFormat = amrFormat;
int32_t retVal = 0;
- if(_fileFormat != kFileFormatAviFile)
- {
- // AVI files should be started using StartRecordingVideoFile(..) all
- // other formats should use this API.
- retVal =_moduleFile->StartRecordingAudioFile(fileName, _fileFormat,
- codecInst,
- notificationTimeMs);
- }
+ retVal =_moduleFile->StartRecordingAudioFile(fileName, _fileFormat,
+ codecInst,
+ notificationTimeMs);
if( retVal == 0)
{
@@ -314,410 +284,4 @@
{
return _moduleFile->IncomingAudioData(audioBuffer, bufferLength);
}
-
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-AviRecorder::AviRecorder(uint32_t instanceID, FileFormats fileFormat)
- : FileRecorderImpl(instanceID, fileFormat),
- _videoOnly(false),
- _thread( 0),
- _timeEvent(*EventWrapper::Create()),
- _critSec(CriticalSectionWrapper::CreateCriticalSection()),
- _writtenVideoFramesCounter(0),
- _writtenAudioMS(0),
- _writtenVideoMS(0)
-{
- _videoEncoder = new VideoCoder();
- _frameScaler = new FrameScaler();
- _videoFramesQueue = new VideoFramesQueue();
- _thread = ThreadWrapper::CreateThread(Run, this, kNormalPriority,
- "AviRecorder()");
-}
-
-AviRecorder::~AviRecorder( )
-{
- StopRecording( );
-
- delete _videoEncoder;
- delete _frameScaler;
- delete _videoFramesQueue;
- delete _thread;
- delete &_timeEvent;
- delete _critSec;
-}
-
-int32_t AviRecorder::StartRecordingVideoFile(
- const char* fileName,
- const CodecInst& audioCodecInst,
- const VideoCodec& videoCodecInst,
- ACMAMRPackingFormat amrFormat,
- bool videoOnly)
-{
- _firstAudioFrameReceived = false;
- _videoCodecInst = videoCodecInst;
- _videoOnly = videoOnly;
-
- if(_moduleFile->StartRecordingVideoFile(fileName, _fileFormat,
- audioCodecInst, videoCodecInst,
- videoOnly) != 0)
- {
- return -1;
- }
-
- if(!videoOnly)
- {
- if(FileRecorderImpl::StartRecordingAudioFile(fileName,audioCodecInst, 0,
- amrFormat) !=0)
- {
- StopRecording();
- return -1;
- }
- }
- if( SetUpVideoEncoder() != 0)
- {
- StopRecording();
- return -1;
- }
- if(_videoOnly)
- {
- // Writing to AVI file is non-blocking.
- // Start non-blocking timer if video only. If recording both video and
- // audio let the pushing of audio frames be the timer.
- _timeEvent.StartTimer(true, 1000 / _videoCodecInst.maxFramerate);
- }
- StartThread();
- return 0;
-}
-
-int32_t AviRecorder::StopRecording()
-{
- _timeEvent.StopTimer();
-
- StopThread();
- return FileRecorderImpl::StopRecording();
-}
-
-size_t AviRecorder::CalcI420FrameSize( ) const
-{
- return 3 * _videoCodecInst.width * _videoCodecInst.height / 2;
-}
-
-int32_t AviRecorder::SetUpVideoEncoder()
-{
- // Size of unencoded data (I420) should be the largest possible frame size
- // in a file.
- _videoMaxPayloadSize = CalcI420FrameSize();
- _videoEncodedData.VerifyAndAllocate(_videoMaxPayloadSize);
-
- _videoCodecInst.plType = _videoEncoder->DefaultPayloadType(
- _videoCodecInst.plName);
-
- int32_t useNumberOfCores = 1;
- // Set the max payload size to 16000. This means that the codec will try to
- // create slices that will fit in 16000 kByte packets. However, the
- // Encode() call will still generate one full frame.
- if(_videoEncoder->SetEncodeCodec(_videoCodecInst, useNumberOfCores,
- 16000))
- {
- return -1;
- }
- return 0;
-}
-
-int32_t AviRecorder::RecordVideoToFile(const I420VideoFrame& videoFrame)
-{
- CriticalSectionScoped lock(_critSec);
- if(!IsRecording() || videoFrame.IsZeroSize())
- {
- return -1;
- }
- // The frame is written to file in AviRecorder::Process().
- int32_t retVal = _videoFramesQueue->AddFrame(videoFrame);
- if(retVal != 0)
- {
- StopRecording();
- }
- return retVal;
-}
-
-bool AviRecorder::StartThread()
-{
- unsigned int id;
- if( _thread == 0)
- {
- return false;
- }
-
- return _thread->Start(id);
-}
-
-bool AviRecorder::StopThread()
-{
- _critSec->Enter();
-
- if(_thread)
- {
- ThreadWrapper* thread = _thread;
- _thread = NULL;
-
- _timeEvent.Set();
-
- _critSec->Leave();
-
- if(thread->Stop())
- {
- delete thread;
- } else {
- return false;
- }
- } else {
- _critSec->Leave();
- }
- return true;
-}
-
-bool AviRecorder::Run( ThreadObj threadObj)
-{
- return static_cast<AviRecorder*>( threadObj)->Process();
-}
-
-int32_t AviRecorder::ProcessAudio()
-{
- if (_writtenVideoFramesCounter == 0)
- {
- // Get the most recent frame that is due for writing to file. Since
- // frames are unencoded it's safe to throw away frames if necessary
- // for synchronizing audio and video.
- I420VideoFrame* frameToProcess = _videoFramesQueue->FrameToRecord();
- if(frameToProcess)
- {
- // Syncronize audio to the current frame to process by throwing away
- // audio samples with older timestamp than the video frame.
- size_t numberOfAudioElements =
- _audioFramesToWrite.size();
- for (size_t i = 0; i < numberOfAudioElements; ++i)
- {
- AudioFrameFileInfo* frameInfo = _audioFramesToWrite.front();
- if(TickTime::TicksToMilliseconds(
- frameInfo->_playoutTS.Ticks()) <
- frameToProcess->render_time_ms())
- {
- delete frameInfo;
- _audioFramesToWrite.pop_front();
- } else
- {
- break;
- }
- }
- }
- }
- // Write all audio up to current timestamp.
- int32_t error = 0;
- size_t numberOfAudioElements = _audioFramesToWrite.size();
- for (size_t i = 0; i < numberOfAudioElements; ++i)
- {
- AudioFrameFileInfo* frameInfo = _audioFramesToWrite.front();
- if((TickTime::Now() - frameInfo->_playoutTS).Milliseconds() > 0)
- {
- _moduleFile->IncomingAudioData(frameInfo->_audioData,
- frameInfo->_audioSize);
- _writtenAudioMS += frameInfo->_audioMS;
- delete frameInfo;
- _audioFramesToWrite.pop_front();
- } else {
- break;
- }
- }
- return error;
-}
-
-bool AviRecorder::Process()
-{
- switch(_timeEvent.Wait(500))
- {
- case kEventSignaled:
- if(_thread == NULL)
- {
- return false;
- }
- break;
- case kEventError:
- return false;
- case kEventTimeout:
- // No events triggered. No work to do.
- return true;
- }
- CriticalSectionScoped lock( _critSec);
-
- // Get the most recent frame to write to file (if any). Synchronize it with
- // the audio stream (if any). Synchronization the video based on its render
- // timestamp (i.e. VideoFrame::RenderTimeMS())
- I420VideoFrame* frameToProcess = _videoFramesQueue->FrameToRecord();
- if( frameToProcess == NULL)
- {
- return true;
- }
- int32_t error = 0;
- if(!_videoOnly)
- {
- if(!_firstAudioFrameReceived)
- {
- // Video and audio can only be synchronized if both have been
- // received.
- return true;
- }
- error = ProcessAudio();
-
- while (_writtenAudioMS > _writtenVideoMS)
- {
- error = EncodeAndWriteVideoToFile( *frameToProcess);
- if( error != 0)
- {
- LOG(LS_ERROR) << "AviRecorder::Process() error writing to "
- << "file.";
- break;
- } else {
- uint32_t frameLengthMS = 1000 /
- _videoCodecInst.maxFramerate;
- _writtenVideoFramesCounter++;
- _writtenVideoMS += frameLengthMS;
- // A full seconds worth of frames have been written.
- if(_writtenVideoFramesCounter%_videoCodecInst.maxFramerate == 0)
- {
- // Frame rate is in frames per seconds. Frame length is
- // calculated as an integer division which means it may
- // be rounded down. Compensate for this every second.
- uint32_t rest = 1000 % frameLengthMS;
- _writtenVideoMS += rest;
- }
- }
- }
- } else {
- // Frame rate is in frames per seconds. Frame length is calculated as an
- // integer division which means it may be rounded down. This introduces
- // drift. Once a full frame worth of drift has happened, skip writing
- // one frame. Note that frame rate is in frames per second so the
- // drift is completely compensated for.
- uint32_t frameLengthMS = 1000/_videoCodecInst.maxFramerate;
- uint32_t restMS = 1000 % frameLengthMS;
- uint32_t frameSkip = (_videoCodecInst.maxFramerate *
- frameLengthMS) / restMS;
-
- _writtenVideoFramesCounter++;
- if(_writtenVideoFramesCounter % frameSkip == 0)
- {
- _writtenVideoMS += frameLengthMS;
- return true;
- }
-
- error = EncodeAndWriteVideoToFile( *frameToProcess);
- if(error != 0)
- {
- LOG(LS_ERROR) << "AviRecorder::Process() error writing to file.";
- } else {
- _writtenVideoMS += frameLengthMS;
- }
- }
- return error == 0;
-}
-
-int32_t AviRecorder::EncodeAndWriteVideoToFile(I420VideoFrame& videoFrame)
-{
- if (!IsRecording() || videoFrame.IsZeroSize())
- {
- return -1;
- }
-
- if(_frameScaler->ResizeFrameIfNeeded(&videoFrame, _videoCodecInst.width,
- _videoCodecInst.height) != 0)
- {
- return -1;
- }
-
- _videoEncodedData.payloadSize = 0;
-
- if( STR_CASE_CMP(_videoCodecInst.plName, "I420") == 0)
- {
- size_t length =
- CalcBufferSize(kI420, videoFrame.width(), videoFrame.height());
- _videoEncodedData.VerifyAndAllocate(length);
-
- // I420 is raw data. No encoding needed (each sample is represented by
- // 1 byte so there is no difference depending on endianness).
- int ret_length = ExtractBuffer(videoFrame, length,
- _videoEncodedData.payloadData);
- if (ret_length < 0)
- return -1;
-
- _videoEncodedData.payloadSize = ret_length;
- _videoEncodedData.frameType = kVideoFrameKey;
- }else {
- if( _videoEncoder->Encode(videoFrame, _videoEncodedData) != 0)
- {
- return -1;
- }
- }
-
- if(_videoEncodedData.payloadSize > 0)
- {
- if(_moduleFile->IncomingAVIVideoData(
- (int8_t*)(_videoEncodedData.payloadData),
- _videoEncodedData.payloadSize))
- {
- LOG(LS_ERROR) << "Error writing AVI file.";
- return -1;
- }
- } else {
- LOG(LS_ERROR) << "FileRecorder::RecordVideoToFile() frame dropped by "
- << "encoder, bitrate likely too low.";
- }
- return 0;
-}
-
-// Store audio frame in the _audioFramesToWrite buffer. The writing to file
-// happens in AviRecorder::Process().
-int32_t AviRecorder::WriteEncodedAudioData(
- const int8_t* audioBuffer,
- size_t bufferLength,
- uint16_t millisecondsOfData,
- const TickTime* playoutTS)
-{
- CriticalSectionScoped lock(_critSec);
-
- if (!IsRecording())
- {
- return -1;
- }
- if (bufferLength > MAX_AUDIO_BUFFER_IN_BYTES)
- {
- return -1;
- }
- if (_videoOnly)
- {
- return -1;
- }
- if (_audioFramesToWrite.size() > kMaxAudioBufferQueueLength)
- {
- StopRecording();
- return -1;
- }
- _firstAudioFrameReceived = true;
-
- if(playoutTS)
- {
- _audioFramesToWrite.push_back(new AudioFrameFileInfo(audioBuffer,
- bufferLength,
- millisecondsOfData,
- *playoutTS));
- } else {
- _audioFramesToWrite.push_back(new AudioFrameFileInfo(audioBuffer,
- bufferLength,
- millisecondsOfData,
- TickTime::Now()));
- }
- _timeEvent.Set();
- return 0;
-}
-
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
} // namespace webrtc
diff --git a/webrtc/modules/utility/source/file_recorder_impl.h b/webrtc/modules/utility/source/file_recorder_impl.h
index 5593827..776654b 100644
--- a/webrtc/modules/utility/source/file_recorder_impl.h
+++ b/webrtc/modules/utility/source/file_recorder_impl.h
@@ -30,12 +30,6 @@
#include "webrtc/system_wrappers/interface/tick_util.h"
#include "webrtc/typedefs.h"
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
- #include "webrtc/modules/utility/source/frame_scaler.h"
- #include "webrtc/modules/utility/source/video_coder.h"
- #include "webrtc/modules/utility/source/video_frames_queue.h"
-#endif
-
namespace webrtc {
// The largest decoded frame size in samples (60ms with 32kHz sample rate).
enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60*32};
@@ -104,90 +98,5 @@
AudioCoder _audioEncoder;
Resampler _audioResampler;
};
-
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-class AudioFrameFileInfo
-{
- public:
- AudioFrameFileInfo(const int8_t* audioData,
- const size_t audioSize,
- const uint16_t audioMS,
- const TickTime& playoutTS)
- : _audioData(), _audioSize(audioSize), _audioMS(audioMS),
- _playoutTS(playoutTS)
- {
- if(audioSize > MAX_AUDIO_BUFFER_IN_BYTES)
- {
- assert(false);
- _audioSize = 0;
- return;
- }
- memcpy(_audioData, audioData, audioSize);
- };
- // TODO (hellner): either turn into a struct or provide get/set functions.
- int8_t _audioData[MAX_AUDIO_BUFFER_IN_BYTES];
- size_t _audioSize;
- uint16_t _audioMS;
- TickTime _playoutTS;
-};
-
-class AviRecorder : public FileRecorderImpl
-{
-public:
- AviRecorder(uint32_t instanceID, FileFormats fileFormat);
- virtual ~AviRecorder();
-
- // FileRecorder functions.
- virtual int32_t StartRecordingVideoFile(
- const char* fileName,
- const CodecInst& audioCodecInst,
- const VideoCodec& videoCodecInst,
- ACMAMRPackingFormat amrFormat = AMRFileStorage,
- bool videoOnly = false);
- virtual int32_t StopRecording();
- virtual int32_t RecordVideoToFile(const I420VideoFrame& videoFrame);
-
-protected:
- virtual int32_t WriteEncodedAudioData(
- const int8_t* audioBuffer,
- size_t bufferLength,
- uint16_t millisecondsOfData,
- const TickTime* playoutTS);
-private:
- typedef std::list<AudioFrameFileInfo*> AudioInfoList;
- static bool Run(ThreadObj threadObj);
- bool Process();
-
- bool StartThread();
- bool StopThread();
-
- int32_t EncodeAndWriteVideoToFile(I420VideoFrame& videoFrame);
- int32_t ProcessAudio();
-
- size_t CalcI420FrameSize() const;
- int32_t SetUpVideoEncoder();
-
- VideoCodec _videoCodecInst;
- bool _videoOnly;
-
- AudioInfoList _audioFramesToWrite;
- bool _firstAudioFrameReceived;
-
- VideoFramesQueue* _videoFramesQueue;
-
- FrameScaler* _frameScaler;
- VideoCoder* _videoEncoder;
- size_t _videoMaxPayloadSize;
- EncodedVideoData _videoEncodedData;
-
- ThreadWrapper* _thread;
- EventWrapper& _timeEvent;
- CriticalSectionWrapper* _critSec;
- int64_t _writtenVideoFramesCounter;
- int64_t _writtenAudioMS;
- int64_t _writtenVideoMS;
-};
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
} // namespace webrtc
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_
diff --git a/webrtc/modules/utility/source/frame_scaler.cc b/webrtc/modules/utility/source/frame_scaler.cc
deleted file mode 100644
index 50ccf8a..0000000
--- a/webrtc/modules/utility/source/frame_scaler.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2012 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.
- */
-
-#include "webrtc/modules/utility/source/frame_scaler.h"
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include "webrtc/common_video/libyuv/include/scaler.h"
-
-namespace webrtc {
-
-FrameScaler::FrameScaler()
- : scaler_(new Scaler()),
- scaled_frame_() {}
-
-FrameScaler::~FrameScaler() {}
-
-int FrameScaler::ResizeFrameIfNeeded(I420VideoFrame* video_frame,
- int out_width,
- int out_height) {
- if (video_frame->IsZeroSize()) {
- return -1;
- }
-
- if ((video_frame->width() != out_width) ||
- (video_frame->height() != out_height)) {
- // Set correct scale settings and scale |video_frame| into |scaled_frame_|.
- scaler_->Set(video_frame->width(), video_frame->height(), out_width,
- out_height, kI420, kI420, kScaleBox);
- int ret = scaler_->Scale(*video_frame, &scaled_frame_);
- if (ret < 0) {
- return ret;
- }
-
- scaled_frame_.set_render_time_ms(video_frame->render_time_ms());
- scaled_frame_.set_timestamp(video_frame->timestamp());
- video_frame->SwapFrame(&scaled_frame_);
- }
- return 0;
-}
-
-} // namespace webrtc
-
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
diff --git a/webrtc/modules/utility/source/frame_scaler.h b/webrtc/modules/utility/source/frame_scaler.h
deleted file mode 100644
index 0aaafa4..0000000
--- a/webrtc/modules/utility/source/frame_scaler.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2012 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.
- */
-
-// This file implements a class that can be used for scaling frames.
-
-#ifndef WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_
-#define WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/common_video/interface/i420_video_frame.h"
-#include "webrtc/engine_configurations.h"
-#include "webrtc/modules/interface/module_common_types.h"
-
-namespace webrtc {
-
-class Scaler;
-class VideoFrame;
-
-class FrameScaler {
- public:
- FrameScaler();
- ~FrameScaler();
-
- // Re-sizes |video_frame| so that it has the width |out_width| and height
- // |out_height|.
- int ResizeFrameIfNeeded(I420VideoFrame* video_frame,
- int out_width,
- int out_height);
-
- private:
- rtc::scoped_ptr<Scaler> scaler_;
- I420VideoFrame scaled_frame_;
-};
-
-} // namespace webrtc
-
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
-
-#endif // WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_
diff --git a/webrtc/modules/utility/source/video_coder.cc b/webrtc/modules/utility/source/video_coder.cc
deleted file mode 100644
index 957826c..0000000
--- a/webrtc/modules/utility/source/video_coder.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2012 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.
- */
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include "webrtc/modules/utility/source/video_coder.h"
-#include "webrtc/modules/video_coding/main/source/encoded_frame.h"
-
-namespace webrtc {
-VideoCoder::VideoCoder()
- : _vcm(VideoCodingModule::Create(nullptr)), _decodedVideo(0) {
- _vcm->InitializeSender();
- _vcm->InitializeReceiver();
-
- _vcm->RegisterTransportCallback(this);
- _vcm->RegisterReceiveCallback(this);
-}
-
-VideoCoder::~VideoCoder()
-{
- VideoCodingModule::Destroy(_vcm);
-}
-
-int32_t VideoCoder::SetEncodeCodec(VideoCodec& videoCodecInst,
- uint32_t numberOfCores,
- uint32_t maxPayloadSize)
-{
- if(_vcm->RegisterSendCodec(&videoCodecInst, numberOfCores,
- maxPayloadSize) != VCM_OK)
- {
- return -1;
- }
- return 0;
-}
-
-
-int32_t VideoCoder::SetDecodeCodec(VideoCodec& videoCodecInst,
- int32_t numberOfCores)
-{
- if (videoCodecInst.plType == 0)
- {
- int8_t plType = DefaultPayloadType(videoCodecInst.plName);
- if (plType == -1)
- {
- return -1;
- }
- videoCodecInst.plType = plType;
- }
-
- if(_vcm->RegisterReceiveCodec(&videoCodecInst, numberOfCores) != VCM_OK)
- {
- return -1;
- }
- return 0;
-}
-
-int32_t VideoCoder::Decode(I420VideoFrame& decodedVideo,
- const EncodedVideoData& encodedData)
-{
- decodedVideo.ResetSize();
- if(encodedData.payloadSize <= 0)
- {
- return -1;
- }
-
- _decodedVideo = &decodedVideo;
- return 0;
-}
-
-
-int32_t VideoCoder::Encode(const I420VideoFrame& videoFrame,
- EncodedVideoData& videoEncodedData)
-{
- // The AddVideoFrame(..) call will (indirectly) call SendData(). Store a
- // pointer to videoFrame so that it can be updated.
- _videoEncodedData = &videoEncodedData;
- videoEncodedData.payloadSize = 0;
- if(_vcm->AddVideoFrame(videoFrame) != VCM_OK)
- {
- return -1;
- }
- return 0;
-}
-
-int8_t VideoCoder::DefaultPayloadType(const char* plName)
-{
- VideoCodec tmpCodec;
- int32_t numberOfCodecs = _vcm->NumberOfCodecs();
- for (uint8_t i = 0; i < numberOfCodecs; i++)
- {
- _vcm->Codec(i, &tmpCodec);
- if(strncmp(tmpCodec.plName, plName, kPayloadNameSize) == 0)
- {
- return tmpCodec.plType;
- }
- }
- return -1;
-}
-
-int32_t VideoCoder::FrameToRender(I420VideoFrame& videoFrame)
-{
- return _decodedVideo->CopyFrame(videoFrame);
-}
-
-int32_t VideoCoder::SendData(
- const uint8_t payloadType,
- const EncodedImage& encoded_image,
- const RTPFragmentationHeader& fragmentationHeader,
- const RTPVideoHeader* /*rtpVideoHdr*/)
-{
- // Store the data in _videoEncodedData which is a pointer to videoFrame in
- // Encode(..)
- _videoEncodedData->VerifyAndAllocate(encoded_image._length);
- _videoEncodedData->frameType =
- VCMEncodedFrame::ConvertFrameType(encoded_image._frameType);
- _videoEncodedData->payloadType = payloadType;
- _videoEncodedData->timeStamp = encoded_image._timeStamp;
- _videoEncodedData->fragmentationHeader.CopyFrom(fragmentationHeader);
- memcpy(_videoEncodedData->payloadData, encoded_image._buffer,
- sizeof(uint8_t) * encoded_image._length);
- _videoEncodedData->payloadSize = encoded_image._length;
- return 0;
-}
-} // namespace webrtc
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
diff --git a/webrtc/modules/utility/source/video_coder.h b/webrtc/modules/utility/source/video_coder.h
deleted file mode 100644
index 5695f5e..0000000
--- a/webrtc/modules/utility/source/video_coder.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2012 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_MODULES_UTILITY_SOURCE_VIDEO_CODER_H_
-#define WEBRTC_MODULES_UTILITY_SOURCE_VIDEO_CODER_H_
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include "webrtc/engine_configurations.h"
-#include "webrtc/modules/video_coding/main/interface/video_coding.h"
-
-namespace webrtc {
-class VideoCoder : public VCMPacketizationCallback, public VCMReceiveCallback
-{
-public:
- VideoCoder();
- ~VideoCoder();
-
- int32_t SetEncodeCodec(VideoCodec& videoCodecInst,
- uint32_t numberOfCores,
- uint32_t maxPayloadSize);
-
-
- // Select the codec that should be used for decoding. videoCodecInst.plType
- // will be set to the codec's default payload type.
- int32_t SetDecodeCodec(VideoCodec& videoCodecInst, int32_t numberOfCores);
-
- int32_t Decode(I420VideoFrame& decodedVideo,
- const EncodedVideoData& encodedData);
-
- int32_t Encode(const I420VideoFrame& videoFrame,
- EncodedVideoData& videoEncodedData);
-
- int8_t DefaultPayloadType(const char* plName);
-
-private:
- // VCMReceiveCallback function.
- // Note: called by VideoCodingModule when decoding finished.
- virtual int32_t FrameToRender(I420VideoFrame& videoFrame) OVERRIDE;
-
- // VCMPacketizationCallback function.
- // Note: called by VideoCodingModule when encoding finished.
- virtual int32_t SendData(
- uint8_t /*payloadType*/,
- const EncodedImage& encoded_image,
- const RTPFragmentationHeader& /* fragmentationHeader*/,
- const RTPVideoHeader* rtpTypeHdr) OVERRIDE;
-
- VideoCodingModule* _vcm;
- I420VideoFrame* _decodedVideo;
- EncodedVideoData* _videoEncodedData;
-};
-} // namespace webrtc
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
-#endif // WEBRTC_MODULES_UTILITY_SOURCE_VIDEO_CODER_H_
diff --git a/webrtc/modules/utility/source/video_frames_queue.cc b/webrtc/modules/utility/source/video_frames_queue.cc
deleted file mode 100644
index 9ade8b5..0000000
--- a/webrtc/modules/utility/source/video_frames_queue.cc
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.
- */
-
-#include "webrtc/modules/utility/source/video_frames_queue.h"
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include <assert.h>
-
-#include "webrtc/common_video/interface/texture_video_frame.h"
-#include "webrtc/modules/interface/module_common_types.h"
-#include "webrtc/system_wrappers/interface/logging.h"
-#include "webrtc/system_wrappers/interface/tick_util.h"
-
-namespace webrtc {
-VideoFramesQueue::VideoFramesQueue()
- : _renderDelayMs(10)
-{
-}
-
-VideoFramesQueue::~VideoFramesQueue() {
- for (FrameList::iterator iter = _incomingFrames.begin();
- iter != _incomingFrames.end(); ++iter) {
- delete *iter;
- }
- for (FrameList::iterator iter = _emptyFrames.begin();
- iter != _emptyFrames.end(); ++iter) {
- delete *iter;
- }
-}
-
-int32_t VideoFramesQueue::AddFrame(const I420VideoFrame& newFrame) {
- if (newFrame.native_handle() != NULL) {
- _incomingFrames.push_back(newFrame.CloneFrame());
- return 0;
- }
-
- I420VideoFrame* ptrFrameToAdd = NULL;
- // Try to re-use a VideoFrame. Only allocate new memory if it is necessary.
- if (!_emptyFrames.empty()) {
- ptrFrameToAdd = _emptyFrames.front();
- _emptyFrames.pop_front();
- }
- if (!ptrFrameToAdd) {
- if (_emptyFrames.size() + _incomingFrames.size() >
- KMaxNumberOfFrames) {
- LOG(LS_WARNING) << "Too many frames, limit: " << KMaxNumberOfFrames;
- return -1;
- }
- ptrFrameToAdd = new I420VideoFrame();
- }
- ptrFrameToAdd->CopyFrame(newFrame);
- _incomingFrames.push_back(ptrFrameToAdd);
- return 0;
-}
-
-// Find the most recent frame that has a VideoFrame::RenderTimeMs() that is
-// lower than current time in ms (TickTime::MillisecondTimestamp()).
-// Note _incomingFrames is sorted so that the oldest frame is first.
-// Recycle all frames that are older than the most recent frame.
-I420VideoFrame* VideoFramesQueue::FrameToRecord() {
- I420VideoFrame* ptrRenderFrame = NULL;
- for (FrameList::iterator iter = _incomingFrames.begin();
- iter != _incomingFrames.end(); ++iter) {
- I420VideoFrame* ptrOldestFrameInList = *iter;
- if (ptrOldestFrameInList->render_time_ms() <=
- TickTime::MillisecondTimestamp() + _renderDelayMs) {
- // List is traversed beginning to end. If ptrRenderFrame is not
- // NULL it must be the first, and thus oldest, VideoFrame in the
- // queue. It can be recycled.
- if (ptrRenderFrame) {
- ReturnFrame(ptrRenderFrame);
- _incomingFrames.pop_front();
- }
- ptrRenderFrame = ptrOldestFrameInList;
- } else {
- // All VideoFrames following this one will be even newer. No match
- // will be found.
- break;
- }
- }
- return ptrRenderFrame;
-}
-
-int32_t VideoFramesQueue::ReturnFrame(I420VideoFrame* ptrOldFrame) {
- // No need to reuse texture frames because they do not allocate memory.
- if (ptrOldFrame->native_handle() == NULL) {
- ptrOldFrame->set_timestamp(0);
- ptrOldFrame->set_width(0);
- ptrOldFrame->set_height(0);
- ptrOldFrame->set_render_time_ms(0);
- ptrOldFrame->ResetSize();
- _emptyFrames.push_back(ptrOldFrame);
- } else {
- delete ptrOldFrame;
- }
- return 0;
-}
-
-int32_t VideoFramesQueue::SetRenderDelay(uint32_t renderDelay) {
- _renderDelayMs = renderDelay;
- return 0;
-}
-} // namespace webrtc
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
diff --git a/webrtc/modules/utility/source/video_frames_queue.h b/webrtc/modules/utility/source/video_frames_queue.h
deleted file mode 100644
index afc64d9..0000000
--- a/webrtc/modules/utility/source/video_frames_queue.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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_MODULES_UTILITY_SOURCE_VIDEO_FRAMES_QUEUE_H_
-#define WEBRTC_MODULES_UTILITY_SOURCE_VIDEO_FRAMES_QUEUE_H_
-
-#ifdef WEBRTC_MODULE_UTILITY_VIDEO
-
-#include <list>
-
-#include "webrtc/common_video/interface/i420_video_frame.h"
-#include "webrtc/engine_configurations.h"
-#include "webrtc/typedefs.h"
-
-namespace webrtc {
-
-class VideoFramesQueue {
- public:
- VideoFramesQueue();
- ~VideoFramesQueue();
-
- // Put newFrame (last) in the queue.
- int32_t AddFrame(const I420VideoFrame& newFrame);
-
- // Return the most current frame. I.e. the frame with the highest
- // VideoFrame::RenderTimeMs() that is lower than
- // TickTime::MillisecondTimestamp().
- I420VideoFrame* FrameToRecord();
-
- // Set the render delay estimate to renderDelay ms.
- int32_t SetRenderDelay(uint32_t renderDelay);
-
- protected:
- // Make ptrOldFrame available for re-use. I.e. put it in the empty frames
- // queue.
- int32_t ReturnFrame(I420VideoFrame* ptrOldFrame);
-
- private:
- typedef std::list<I420VideoFrame*> FrameList;
- // Don't allow the buffer to expand beyond KMaxNumberOfFrames VideoFrames.
- // 300 frames correspond to 10 seconds worth of frames at 30 fps.
- enum {KMaxNumberOfFrames = 300};
-
- // List of VideoFrame pointers. The list is sorted in the order of when the
- // VideoFrame was inserted into the list. The first VideoFrame in the list
- // was inserted first.
- FrameList _incomingFrames;
- // A list of frames that are free to be re-used.
- FrameList _emptyFrames;
-
- // Estimated render delay.
- uint32_t _renderDelayMs;
-};
-} // namespace webrtc
-#endif // WEBRTC_MODULE_UTILITY_VIDEO
-#endif // WEBRTC_MODULES_UTILITY_SOURCE_VIDEO_FRAMES_QUEUE_H_