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
This commit is contained in:
@ -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 @@ FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
|
||||
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 @@ int32_t FilePlayerImpl::SetUpAudioDecoder()
|
||||
_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
|
||||
|
||||
Reference in New Issue
Block a user