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:
parent
ab2405164a
commit
b08a12d6e8
@ -194,7 +194,8 @@ class VideoCodingModuleImpl : public VideoCodingModule {
|
||||
}
|
||||
|
||||
virtual int StopDebugRecording() OVERRIDE {
|
||||
return sender_->StopDebugRecording();
|
||||
sender_->StopDebugRecording();
|
||||
return VCM_OK;
|
||||
}
|
||||
|
||||
virtual void SuspendBelowMinBitrate() {
|
||||
|
@ -32,6 +32,8 @@ class EncodedFrameObserver;
|
||||
|
||||
namespace vcm {
|
||||
|
||||
class DebugRecorder;
|
||||
|
||||
class VCMProcessTimer {
|
||||
public:
|
||||
VCMProcessTimer(uint32_t periodMs, Clock* clock)
|
||||
@ -96,7 +98,7 @@ class VideoSender {
|
||||
int SetSenderKeyFramePeriod(int periodMs);
|
||||
|
||||
int StartDebugRecording(const char* file_name_utf8);
|
||||
int StopDebugRecording();
|
||||
void StopDebugRecording();
|
||||
|
||||
void SuspendBelowMinBitrate();
|
||||
bool VideoSuspended() const;
|
||||
@ -111,6 +113,8 @@ class VideoSender {
|
||||
int32_t _id;
|
||||
Clock* clock_;
|
||||
|
||||
scoped_ptr<DebugRecorder> recorder_;
|
||||
|
||||
scoped_ptr<CriticalSectionWrapper> process_crit_sect_;
|
||||
CriticalSectionWrapper* _sendCritSect;
|
||||
VCMGenericEncoder* _encoder;
|
||||
@ -118,7 +122,6 @@ class VideoSender {
|
||||
std::vector<FrameType> _nextFrameTypes;
|
||||
media_optimization::MediaOptimization _mediaOpt;
|
||||
VCMSendStatisticsCallback* _sendStatsCallback;
|
||||
FILE* _encoderInputFile;
|
||||
VCMCodecDataBase _codecDataBase;
|
||||
bool frame_dropper_enabled_;
|
||||
VCMProcessTimer _sendStatsTimer;
|
||||
|
@ -21,9 +21,46 @@
|
||||
namespace webrtc {
|
||||
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)
|
||||
: _id(id),
|
||||
clock_(clock),
|
||||
recorder_(new DebugRecorder()),
|
||||
process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||
_sendCritSect(CriticalSectionWrapper::CreateCriticalSection()),
|
||||
_encoder(),
|
||||
@ -31,7 +68,6 @@ VideoSender::VideoSender(const int32_t id, Clock* clock)
|
||||
_nextFrameTypes(1, kVideoFrameDelta),
|
||||
_mediaOpt(id, clock_),
|
||||
_sendStatsCallback(NULL),
|
||||
_encoderInputFile(NULL),
|
||||
_codecDataBase(id),
|
||||
frame_dropper_enabled_(true),
|
||||
_sendStatsTimer(1000, clock_),
|
||||
@ -40,9 +76,6 @@ VideoSender::VideoSender(const int32_t id, Clock* clock)
|
||||
|
||||
VideoSender::~VideoSender() {
|
||||
delete _sendCritSect;
|
||||
if (_encoderInputFile != NULL) {
|
||||
fclose(_encoderInputFile);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t VideoSender::Process() {
|
||||
@ -336,11 +369,7 @@ int32_t VideoSender::AddVideoFrame(const I420VideoFrame& videoFrame,
|
||||
_mediaOpt.UpdateContentData(contentMetrics);
|
||||
int32_t ret =
|
||||
_encoder->Encode(videoFrame, codecSpecificInfo, _nextFrameTypes);
|
||||
if (_encoderInputFile != NULL) {
|
||||
if (PrintI420VideoFrame(videoFrame, _encoderInputFile) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
recorder_->Add(videoFrame);
|
||||
if (ret < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError,
|
||||
webrtc::kTraceVideoCoding,
|
||||
@ -412,20 +441,11 @@ int VideoSender::SetSenderKeyFramePeriod(int periodMs) {
|
||||
}
|
||||
|
||||
int VideoSender::StartDebugRecording(const char* file_name_utf8) {
|
||||
CriticalSectionScoped cs(_sendCritSect);
|
||||
_encoderInputFile = fopen(file_name_utf8, "wb");
|
||||
if (_encoderInputFile == NULL)
|
||||
return VCM_GENERAL_ERROR;
|
||||
return VCM_OK;
|
||||
return recorder_->Start(file_name_utf8);
|
||||
}
|
||||
|
||||
int VideoSender::StopDebugRecording() {
|
||||
CriticalSectionScoped cs(_sendCritSect);
|
||||
if (_encoderInputFile != NULL) {
|
||||
fclose(_encoderInputFile);
|
||||
_encoderInputFile = NULL;
|
||||
}
|
||||
return VCM_OK;
|
||||
void VideoSender::StopDebugRecording() {
|
||||
recorder_->Stop();
|
||||
}
|
||||
|
||||
void VideoSender::SuspendBelowMinBitrate() {
|
||||
|
Loading…
Reference in New Issue
Block a user