Adding support for changing resolutions and FEC to video_rtp_play.

BUG=

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2882 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org 2012-10-08 07:02:53 +00:00
parent aca26292ae
commit 7bc3a4172a
2 changed files with 62 additions and 12 deletions

View File

@ -41,16 +41,25 @@ public:
FrameReceiveCallback(std::string outFilename) :
_outFilename(outFilename),
_outFile(NULL),
_timingFile(NULL) {}
_timingFile(NULL),
width_(0),
height_(0) {}
virtual ~FrameReceiveCallback();
WebRtc_Word32 FrameToRender(webrtc::VideoFrame& videoFrame);
private:
static void SplitFilename(std::string filename, std::string* basename,
std::string* ending);
static std::string AppendWidthAndHeight(std::string basename,
unsigned int width,
unsigned int height);
std::string _outFilename;
FILE* _outFile;
FILE* _timingFile;
unsigned int width_;
unsigned int height_;
};
class SharedState

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <sstream>
using namespace webrtc;
@ -55,9 +56,18 @@ FrameReceiveCallback::FrameToRender(VideoFrame& videoFrame)
return -1;
}
}
if (_outFile == NULL)
if (_outFile == NULL || videoFrame.Width() != width_ ||
videoFrame.Height() != height_)
{
_outFile = fopen(_outFilename.c_str(), "wb");
if (_outFile) {
fclose(_outFile);
}
printf("New size: %ux%u\n", videoFrame.Width(), videoFrame.Height());
width_ = videoFrame.Width();
height_ = videoFrame.Height();
std::string filename_with_width_height = AppendWidthAndHeight(
_outFilename, width_, height_);
_outFile = fopen(filename_with_width_height.c_str(), "wb");
if (_outFile == NULL)
{
return -1;
@ -73,6 +83,30 @@ FrameReceiveCallback::FrameToRender(VideoFrame& videoFrame)
return 0;
}
void FrameReceiveCallback::SplitFilename(std::string filename,
std::string* basename,
std::string* ending) {
std::string::size_type idx;
idx = filename.rfind('.');
if(idx != std::string::npos) {
*ending = filename.substr(idx + 1);
*basename = filename.substr(0, idx);
} else {
*basename = filename;
*ending = "";
}
}
std::string FrameReceiveCallback::AppendWidthAndHeight(
std::string filename, unsigned int width, unsigned int height) {
std::string basename;
std::string ending;
SplitFilename(filename, &basename, &ending);
std::stringstream ss;
ss << basename << "." << width << "_" << height << "." << ending;
return ss.str();
}
int RtpPlay(CmdArgs& args)
{
// Make sure this test isn't executed without simulated events.
@ -81,7 +115,7 @@ int RtpPlay(CmdArgs& args)
#endif
// BEGIN Settings
bool protectionEnabled = false;
bool protectionEnabled = true;
VCMVideoProtection protectionMethod = kProtectionNack;
WebRtc_UWord32 rttMS = 0;
float lossRate = 0.0f;
@ -102,6 +136,10 @@ int RtpPlay(CmdArgs& args)
PayloadTypeList payloadTypes;
payloadTypes.push_front(new PayloadCodecTuple(VCM_VP8_PAYLOAD_TYPE, "VP8",
kVideoCodecVP8));
payloadTypes.push_front(new PayloadCodecTuple(VCM_RED_PAYLOAD_TYPE, "RED",
kVideoCodecRED));
payloadTypes.push_front(new PayloadCodecTuple(VCM_ULPFEC_PAYLOAD_TYPE,
"ULPFEC", kVideoCodecULPFEC));
Trace::CreateTrace();
Trace::SetTraceFile((test::OutputPath() + "receiverTestTrace.txt").c_str());
@ -125,14 +163,17 @@ int RtpPlay(CmdArgs& args)
if (payloadType != NULL)
{
VideoCodec codec;
if (VideoCodingModule::Codec(payloadType->codecType, &codec) < 0)
{
return -1;
}
codec.plType = payloadType->payloadType;
if (vcm->RegisterReceiveCodec(&codec, 1) < 0)
{
return -1;
if (payloadType->codecType != kVideoCodecULPFEC &&
payloadType->codecType != kVideoCodecRED) {
if (VideoCodingModule::Codec(payloadType->codecType, &codec) < 0)
{
return -1;
}
codec.plType = payloadType->payloadType;
if (vcm->RegisterReceiveCodec(&codec, 1) < 0)
{
return -1;
}
}
}
}