shithub: openh264

Download patch

ref: f13b5c34659715c52cfee6c932de8b8d9236f020
parent: 5aa42e8976d1a3e1fc9c1020b2b921f2c630b79b
author: Martin Storsjö <[email protected]>
date: Mon Mar 3 05:59:16 EST 2014

Add a test with sliced encoding

This serves as a simple test of the thread library.

--- a/test/BaseEncoderTest.cpp
+++ b/test/BaseEncoderTest.cpp
@@ -6,16 +6,37 @@
 #include "BaseEncoderTest.h"
 
 static int InitWithParam(ISVCEncoder* encoder, int width,
-    int height, float frameRate) {
-  SEncParamBase param;
-  memset (&param, 0, sizeof(SEncParamBase));
+    int height, float frameRate, bool slices) {
+  if (!slices) {
+    SEncParamBase param;
+    memset (&param, 0, sizeof(SEncParamBase));
 
-  param.fMaxFrameRate = frameRate;
-  param.iPicWidth = width;
-  param.iPicHeight = height;
-  param.iTargetBitrate = 5000000;
-  param.iInputCsp = videoFormatI420;
-  return encoder->Initialize(&param);
+    param.fMaxFrameRate = frameRate;
+    param.iPicWidth = width;
+    param.iPicHeight = height;
+    param.iTargetBitrate = 5000000;
+    param.iInputCsp = videoFormatI420;
+
+    return encoder->Initialize(&param);
+  } else {
+    SEncParamExt param;
+    encoder->GetDefaultParams(&param);
+
+    param.fMaxFrameRate = frameRate;
+    param.iPicWidth = width;
+    param.iPicHeight = height;
+    param.iTargetBitrate = 5000000;
+    param.iInputCsp = videoFormatI420;
+
+    param.sSpatialLayers[0].iVideoWidth = width;
+    param.sSpatialLayers[0].iVideoHeight = height;
+    param.sSpatialLayers[0].fFrameRate = frameRate;
+    param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
+
+    param.sSpatialLayers[0].sSliceCfg.uiSliceMode = 3; // One slice per MB row
+
+    return encoder->InitializeExt(&param);
+  }
 }
 
 BaseEncoderTest::BaseEncoderTest() : encoder_(NULL) {}
@@ -34,8 +55,8 @@
 }
 
 void BaseEncoderTest::EncodeStream(InputStream* in, int width, int height,
-    float frameRate, Callback* cbk) {
-  int rv = InitWithParam(encoder_, width, height, frameRate);
+    float frameRate, bool slices, Callback* cbk) {
+  int rv = InitWithParam(encoder_, width, height, frameRate, slices);
   ASSERT_TRUE(rv == cmResultSuccess);
 
   // I420: 1(Y) + 1/4(U) + 1/4(V)
@@ -68,8 +89,8 @@
 }
 
 void BaseEncoderTest::EncodeFile(const char* fileName, int width, int height,
-    float frameRate, Callback* cbk) {
+    float frameRate, bool slices, Callback* cbk) {
   FileInputStream fileStream;
   ASSERT_TRUE(fileStream.Open(fileName));
-  EncodeStream(&fileStream, width, height, frameRate, cbk);
+  EncodeStream(&fileStream, width, height, frameRate, slices, cbk);
 }
--- a/test/BaseEncoderTest.h
+++ b/test/BaseEncoderTest.h
@@ -14,8 +14,8 @@
   BaseEncoderTest();
   void SetUp();
   void TearDown();
-  void EncodeFile(const char* fileName, int width, int height, float frameRate, Callback* cbk);
-  void EncodeStream(InputStream* in, int width, int height, float frameRate, Callback* cbk);
+  void EncodeFile(const char* fileName, int width, int height, float frameRate, bool slices, Callback* cbk);
+  void EncodeStream(InputStream* in, int width, int height, float frameRate, bool slices, Callback* cbk);
 
  private:
   ISVCEncoder* encoder_;
--- a/test/decode_encode_test.cpp
+++ b/test/decode_encode_test.cpp
@@ -95,7 +95,7 @@
   DecodeEncodeFileParam p = GetParam();
 
   ASSERT_TRUE(Open(p.fileName));
-  EncodeStream(this, p.width, p.height, p.frameRate, this);
+  EncodeStream(this, p.width, p.height, p.frameRate, false, this);
   unsigned char digest[SHA_DIGEST_LENGTH];
   SHA1Result(&ctx_, digest);
   if (!HasFatalFailure()) {
--- a/test/encoder_test.cpp
+++ b/test/encoder_test.cpp
@@ -31,6 +31,7 @@
   int width;
   int height;
   float frameRate;
+  bool slices;
 };
 
 class EncoderOutputTest : public ::testing::WithParamInterface<EncodeFileParam>,
@@ -53,7 +54,7 @@
 
 TEST_P(EncoderOutputTest, CompareOutput) {
   EncodeFileParam p = GetParam();
-  EncodeFile(p.fileName, p.width, p.height, p.frameRate, this);
+  EncodeFile(p.fileName, p.width, p.height, p.frameRate, p.slices, this);
 
   unsigned char digest[SHA_DIGEST_LENGTH];
   SHA1Result(&ctx_, digest);
@@ -65,15 +66,19 @@
 static const EncodeFileParam kFileParamArray[] = {
   {
       "res/CiscoVT2people_320x192_12fps.yuv",
-      "06441376891cbc237a36e59b62131cd94ff9cb19", 320, 192, 12.0f
+      "06441376891cbc237a36e59b62131cd94ff9cb19", 320, 192, 12.0f, false
   },
   {
       "res/CiscoVT2people_160x96_6fps.yuv",
-      "4f3759fc44125b27a179ebff158dbba9e431bd0b", 160, 96, 6.0f
+      "4f3759fc44125b27a179ebff158dbba9e431bd0b", 160, 96, 6.0f, false
   },
   {
       "res/Static_152_100.yuv",
-      "af5c6a41b567ce1b2cb6fd427f4379473d3b829f", 152, 100, 6.0f
+      "af5c6a41b567ce1b2cb6fd427f4379473d3b829f", 152, 100, 6.0f, false
+  },
+  {
+      "res/CiscoVT2people_320x192_12fps.yuv",
+      "be0079b022b18fdce04570db24e4327ca26a0ecb", 320, 192, 12.0f, true
   },
 };