Bug 881935 - Part 3: Video conduit unit test for max-fs. r=derf

This commit is contained in:
Shian-Yow Wu 2013-10-13 09:44:53 +08:00
parent 7fc5baaade
commit eebd948927
3 changed files with 166 additions and 0 deletions

View File

@ -220,6 +220,14 @@ public:
const std::vector<VideoCodecConfig* >& recvCodecConfigList) = 0;
/**
* These methods allow unit tests to double-check that the
* max-fs and max-fr related settings are as expected.
*/
virtual unsigned short SendingWidth() = 0;
virtual unsigned short SendingHeight() = 0;
/**
* These methods allow unit tests to double-check that the
* rtcp-fb settings are as expected.

View File

@ -152,6 +152,13 @@ public:
virtual int DeliverFrame(unsigned char*,int, uint32_t , int64_t);
unsigned short SendingWidth() {
return mSendingWidth;
}
unsigned short SendingHeight() {
return mSendingHeight;
}
WebrtcVideoConduit():
mVideoEngine(nullptr),

View File

@ -7,6 +7,7 @@
#include <fstream>
#include <unistd.h>
#include <vector>
#include <math.h>
using namespace std;
@ -709,6 +710,152 @@ class TransportConduitTest : public ::testing::Test
}
void DumpMaxFs(int orig_width, int orig_height, int max_fs,
int new_width, int new_height)
{
cerr << "Applying max_fs=" << max_fs << " to input resolution " <<
orig_width << "x" << orig_height << endl;
cerr << "New resolution: " << new_width << "x" << new_height << endl;
cerr << endl;
}
// Calculate new resolution for sending video by applying max-fs constraint.
void GetVideoResolutionWithMaxFs(int orig_width, int orig_height, int max_fs,
int *new_width, int *new_height)
{
int err = 0;
// Get pointer to VideoSessionConduit.
mVideoSession = mozilla::VideoSessionConduit::Create();
if( !mVideoSession )
ASSERT_NE(mVideoSession, (void*)NULL);
// Configure send codecs on the conduit.
mozilla::VideoCodecConfig cinst1(120, "VP8", 0, max_fs, 0);
err = mVideoSession->ConfigureSendMediaCodec(&cinst1);
ASSERT_EQ(mozilla::kMediaConduitNoError, err);
// Send one frame.
MOZ_ASSERT(!(orig_width & 1));
MOZ_ASSERT(!(orig_height & 1));
int len = ((orig_width * orig_height) * 3 / 2);
uint8_t* frame = (uint8_t*) PR_MALLOC(len);
memset(frame, COLOR, len);
mVideoSession->SendVideoFrame((unsigned char*)frame,
len,
orig_width,
orig_height,
mozilla::kVideoI420,
0);
PR_Free(frame);
// Get the new resolution as adjusted by the max-fs constraint.
*new_width = mVideoSession->SendingWidth();
*new_height = mVideoSession->SendingHeight();
}
void TestVideoConduitMaxFs()
{
int orig_width, orig_height, width, height, max_fs;
// No limitation.
cerr << "Test no max-fs limition" << endl;
orig_width = 640;
orig_height = 480;
max_fs = 0;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 640);
ASSERT_EQ(height, 480);
// VGA to QVGA.
cerr << "Test resizing from VGA to QVGA" << endl;
orig_width = 640;
orig_height = 480;
max_fs = 300;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 320);
ASSERT_EQ(height, 240);
// Extreme input resolution.
cerr << "Test extreme input resolution" << endl;
orig_width = 3072;
orig_height = 100;
max_fs = 300;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 768);
ASSERT_EQ(height, 26);
// Small max-fs.
cerr << "Test small max-fs (case 1)" << endl;
orig_width = 8;
orig_height = 32;
max_fs = 1;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 4);
ASSERT_EQ(height, 16);
// Small max-fs.
cerr << "Test small max-fs (case 2)" << endl;
orig_width = 4;
orig_height = 50;
max_fs = 1;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 2);
ASSERT_EQ(height, 16);
// Small max-fs.
cerr << "Test small max-fs (case 3)" << endl;
orig_width = 872;
orig_height = 136;
max_fs = 3;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 48);
ASSERT_EQ(height, 8);
// Small max-fs.
cerr << "Test small max-fs (case 4)" << endl;
orig_width = 160;
orig_height = 8;
max_fs = 5;
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs, &width, &height);
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ASSERT_EQ(width, 80);
ASSERT_EQ(height, 4);
// Random values.
for (int i = 0; i < 30; i++) {
max_fs = rand() % 1000;
orig_width = ((rand() % 2000) & ~1) + 2;
orig_height = ((rand() % 2000) & ~1) + 2;
// Potential crash on small resolution, see bug 919979.
if (orig_width * orig_height <= 20) {
cerr << "Temporarily skip resolution " << orig_width << "x" <<
orig_height << endl;
continue;
}
GetVideoResolutionWithMaxFs(orig_width, orig_height, max_fs,
&width, &height);
if (max_fs > 0 &&
ceil(width / 16.) * ceil(height / 16.) > max_fs) {
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ADD_FAILURE();
}
if ((width & 1) || (height & 1)) {
DumpMaxFs(orig_width, orig_height, max_fs, width, height);
ADD_FAILURE();
}
}
}
private:
//Audio Conduit Test Objects
mozilla::RefPtr<mozilla::AudioSessionConduit> mAudioSession;
@ -744,6 +891,10 @@ TEST_F(TransportConduitTest, TestVideoConduitCodecAPI) {
TestVideoConduitCodecAPI();
}
TEST_F(TransportConduitTest, TestVideoConduitMaxFs) {
TestVideoConduitMaxFs();
}
} // end namespace
int main(int argc, char **argv)