Isolate debug recording from video sender into a thread safe small class.

R=marpan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/6649004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5353 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andresp@webrtc.org 2014-01-08 12:38:22 +00:00
parent ab2405164a
commit b08a12d6e8
3 changed files with 48 additions and 24 deletions

View File

@ -194,7 +194,8 @@ class VideoCodingModuleImpl : public VideoCodingModule {
} }
virtual int StopDebugRecording() OVERRIDE { virtual int StopDebugRecording() OVERRIDE {
return sender_->StopDebugRecording(); sender_->StopDebugRecording();
return VCM_OK;
} }
virtual void SuspendBelowMinBitrate() { virtual void SuspendBelowMinBitrate() {

View File

@ -32,6 +32,8 @@ class EncodedFrameObserver;
namespace vcm { namespace vcm {
class DebugRecorder;
class VCMProcessTimer { class VCMProcessTimer {
public: public:
VCMProcessTimer(uint32_t periodMs, Clock* clock) VCMProcessTimer(uint32_t periodMs, Clock* clock)
@ -96,7 +98,7 @@ class VideoSender {
int SetSenderKeyFramePeriod(int periodMs); int SetSenderKeyFramePeriod(int periodMs);
int StartDebugRecording(const char* file_name_utf8); int StartDebugRecording(const char* file_name_utf8);
int StopDebugRecording(); void StopDebugRecording();
void SuspendBelowMinBitrate(); void SuspendBelowMinBitrate();
bool VideoSuspended() const; bool VideoSuspended() const;
@ -111,6 +113,8 @@ class VideoSender {
int32_t _id; int32_t _id;
Clock* clock_; Clock* clock_;
scoped_ptr<DebugRecorder> recorder_;
scoped_ptr<CriticalSectionWrapper> process_crit_sect_; scoped_ptr<CriticalSectionWrapper> process_crit_sect_;
CriticalSectionWrapper* _sendCritSect; CriticalSectionWrapper* _sendCritSect;
VCMGenericEncoder* _encoder; VCMGenericEncoder* _encoder;
@ -118,7 +122,6 @@ class VideoSender {
std::vector<FrameType> _nextFrameTypes; std::vector<FrameType> _nextFrameTypes;
media_optimization::MediaOptimization _mediaOpt; media_optimization::MediaOptimization _mediaOpt;
VCMSendStatisticsCallback* _sendStatsCallback; VCMSendStatisticsCallback* _sendStatsCallback;
FILE* _encoderInputFile;
VCMCodecDataBase _codecDataBase; VCMCodecDataBase _codecDataBase;
bool frame_dropper_enabled_; bool frame_dropper_enabled_;
VCMProcessTimer _sendStatsTimer; VCMProcessTimer _sendStatsTimer;

View File

@ -21,9 +21,46 @@
namespace webrtc { namespace webrtc {
namespace vcm { namespace vcm {
class DebugRecorder {
public:
DebugRecorder()
: cs_(CriticalSectionWrapper::CreateCriticalSection()), file_(NULL) {}
~DebugRecorder() { Stop(); }
int Start(const char* file_name_utf8) {
CriticalSectionScoped cs(cs_.get());
if (file_)
fclose(file_);
file_ = fopen(file_name_utf8, "wb");
if (!file_)
return VCM_GENERAL_ERROR;
return VCM_OK;
}
void Stop() {
CriticalSectionScoped cs(cs_.get());
if (file_) {
fclose(file_);
file_ = NULL;
}
}
void Add(const I420VideoFrame& frame) {
CriticalSectionScoped cs(cs_.get());
if (file_)
PrintI420VideoFrame(frame, file_);
}
private:
scoped_ptr<CriticalSectionWrapper> cs_;
FILE* file_ GUARDED_BY(cs_);
};
VideoSender::VideoSender(const int32_t id, Clock* clock) VideoSender::VideoSender(const int32_t id, Clock* clock)
: _id(id), : _id(id),
clock_(clock), clock_(clock),
recorder_(new DebugRecorder()),
process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
_sendCritSect(CriticalSectionWrapper::CreateCriticalSection()), _sendCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_encoder(), _encoder(),
@ -31,7 +68,6 @@ VideoSender::VideoSender(const int32_t id, Clock* clock)
_nextFrameTypes(1, kVideoFrameDelta), _nextFrameTypes(1, kVideoFrameDelta),
_mediaOpt(id, clock_), _mediaOpt(id, clock_),
_sendStatsCallback(NULL), _sendStatsCallback(NULL),
_encoderInputFile(NULL),
_codecDataBase(id), _codecDataBase(id),
frame_dropper_enabled_(true), frame_dropper_enabled_(true),
_sendStatsTimer(1000, clock_), _sendStatsTimer(1000, clock_),
@ -40,9 +76,6 @@ VideoSender::VideoSender(const int32_t id, Clock* clock)
VideoSender::~VideoSender() { VideoSender::~VideoSender() {
delete _sendCritSect; delete _sendCritSect;
if (_encoderInputFile != NULL) {
fclose(_encoderInputFile);
}
} }
int32_t VideoSender::Process() { int32_t VideoSender::Process() {
@ -336,11 +369,7 @@ int32_t VideoSender::AddVideoFrame(const I420VideoFrame& videoFrame,
_mediaOpt.UpdateContentData(contentMetrics); _mediaOpt.UpdateContentData(contentMetrics);
int32_t ret = int32_t ret =
_encoder->Encode(videoFrame, codecSpecificInfo, _nextFrameTypes); _encoder->Encode(videoFrame, codecSpecificInfo, _nextFrameTypes);
if (_encoderInputFile != NULL) { recorder_->Add(videoFrame);
if (PrintI420VideoFrame(videoFrame, _encoderInputFile) < 0) {
return -1;
}
}
if (ret < 0) { if (ret < 0) {
WEBRTC_TRACE(webrtc::kTraceError, WEBRTC_TRACE(webrtc::kTraceError,
webrtc::kTraceVideoCoding, webrtc::kTraceVideoCoding,
@ -412,20 +441,11 @@ int VideoSender::SetSenderKeyFramePeriod(int periodMs) {
} }
int VideoSender::StartDebugRecording(const char* file_name_utf8) { int VideoSender::StartDebugRecording(const char* file_name_utf8) {
CriticalSectionScoped cs(_sendCritSect); return recorder_->Start(file_name_utf8);
_encoderInputFile = fopen(file_name_utf8, "wb");
if (_encoderInputFile == NULL)
return VCM_GENERAL_ERROR;
return VCM_OK;
} }
int VideoSender::StopDebugRecording() { void VideoSender::StopDebugRecording() {
CriticalSectionScoped cs(_sendCritSect); recorder_->Stop();
if (_encoderInputFile != NULL) {
fclose(_encoderInputFile);
_encoderInputFile = NULL;
}
return VCM_OK;
} }
void VideoSender::SuspendBelowMinBitrate() { void VideoSender::SuspendBelowMinBitrate() {