Exemple #1
0
static void CompareFileToHash(ISVCEncoder* encoder,
    const char* fileName, const char* hashStr,
    int width, int height, float frameRate) {
  std::ifstream file(fileName, std::ios::in | std::ios::binary);
  ASSERT_TRUE(file.is_open());

  int rv = InitWithParam(encoder, width, height, frameRate);
  ASSERT_TRUE(rv == cmResultSuccess);

  // I420: 1(Y) + 1/4(U) + 1/4(V)
  int frameSize = width * height * 3 / 2;

  BufferedData buf;
  buf.SetLength(frameSize);
  ASSERT_TRUE(buf.Length() == frameSize);
  char* data = reinterpret_cast<char*>(buf.data());

  SFrameBSInfo info;
  memset(&info, 0, sizeof(SFrameBSInfo));

  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA_CTX ctx;
  SHA1_Init(&ctx);

  while (file.read(data, frameSize), file.gcount() == frameSize) {
    rv = encoder->EncodeFrame(buf.data(), &info);
    if (rv == videoFrameTypeInvalid) {
      SHA1_Final(digest, &ctx);
      FAIL() << "unable to encode frame";
    }
    if (rv != videoFrameTypeSkip) {
      UpdateHashFromFrame(info, &ctx);
    }
  }

  SHA1_Final(digest, &ctx);
  ASSERT_TRUE(CompareHash(digest, hashStr));
}
Exemple #2
0
 virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
   UpdateHashFromFrame (frameInfo, &ctx_);
 }