encode_test_driver.cc revision c927526be9a7b72fb5edb3f29c4e8ceabe0ec98a
11b362b15af34006e6a11974088a46d42b903418eJohann/* 21b362b15af34006e6a11974088a46d42b903418eJohann * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 31b362b15af34006e6a11974088a46d42b903418eJohann * 41b362b15af34006e6a11974088a46d42b903418eJohann * Use of this source code is governed by a BSD-style license 51b362b15af34006e6a11974088a46d42b903418eJohann * that can be found in the LICENSE file in the root of the source 61b362b15af34006e6a11974088a46d42b903418eJohann * tree. An additional intellectual property rights grant can be found 71b362b15af34006e6a11974088a46d42b903418eJohann * in the file PATENTS. All contributing project authors may 81b362b15af34006e6a11974088a46d42b903418eJohann * be found in the AUTHORS file in the root of the source tree. 91b362b15af34006e6a11974088a46d42b903418eJohann */ 10ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 117ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#include <string> 127ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 137ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#include "third_party/googletest/src/include/gtest/gtest.h" 147ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 151184aebb761cbeac9124c37189a80a1a58f04b6bhkuang#include "./vpx_config.h" 16ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/codec_factory.h" 171b362b15af34006e6a11974088a46d42b903418eJohann#include "test/decode_test_driver.h" 187ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#include "test/encode_test_driver.h" 19ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/register_state_check.h" 201b362b15af34006e6a11974088a46d42b903418eJohann#include "test/video_source.h" 211b362b15af34006e6a11974088a46d42b903418eJohann 221b362b15af34006e6a11974088a46d42b903418eJohannnamespace libvpx_test { 237ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanianvoid Encoder::InitEncoder(VideoSource *video) { 247ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian vpx_codec_err_t res; 257ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const vpx_image_t *img = video->img(); 267ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 277ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (video->img() && !encoder_.priv) { 287ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian cfg_.g_w = img->d_w; 297ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian cfg_.g_h = img->d_h; 307ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian cfg_.g_timebase = video->timebase(); 317ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian cfg_.rc_twopass_stats_in = stats_->buf(); 327ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 337ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_, 347ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian init_flags_); 357ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 367ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 377ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if CONFIG_VP9_ENCODER 387ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (CodecInterface() == &vpx_codec_vp9_cx_algo) { 397ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Default to 1 tile column for VP9. 407ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const int log2_tile_columns = 0; 417ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian res = vpx_codec_control_(&encoder_, VP9E_SET_TILE_COLUMNS, 427ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian log2_tile_columns); 437ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 447ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } else 457ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 467ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if CONFIG_VP10_ENCODER 477ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (CodecInterface() == &vpx_codec_vp10_cx_algo) { 487ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Default to 1 tile column for VP10. 497ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const int log2_tile_columns = 0; 507ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian res = vpx_codec_control_(&encoder_, VP9E_SET_TILE_COLUMNS, 517ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian log2_tile_columns); 527ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 537ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } else 547ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 557ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian { 567ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if CONFIG_VP8_ENCODER 577ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(&vpx_codec_vp8_cx_algo, CodecInterface()) 587ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian << "Unknown Codec Interface"; 597ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 607ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 617ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 627ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian} 637ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 641b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { 651b362b15af34006e6a11974088a46d42b903418eJohann if (video->img()) 661b362b15af34006e6a11974088a46d42b903418eJohann EncodeFrameInternal(*video, frame_flags); 671b362b15af34006e6a11974088a46d42b903418eJohann else 681b362b15af34006e6a11974088a46d42b903418eJohann Flush(); 691b362b15af34006e6a11974088a46d42b903418eJohann 701b362b15af34006e6a11974088a46d42b903418eJohann // Handle twopass stats 711b362b15af34006e6a11974088a46d42b903418eJohann CxDataIterator iter = GetCxData(); 721b362b15af34006e6a11974088a46d42b903418eJohann 731b362b15af34006e6a11974088a46d42b903418eJohann while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { 741b362b15af34006e6a11974088a46d42b903418eJohann if (pkt->kind != VPX_CODEC_STATS_PKT) 751b362b15af34006e6a11974088a46d42b903418eJohann continue; 761b362b15af34006e6a11974088a46d42b903418eJohann 771b362b15af34006e6a11974088a46d42b903418eJohann stats_->Append(*pkt); 781b362b15af34006e6a11974088a46d42b903418eJohann } 791b362b15af34006e6a11974088a46d42b903418eJohann} 801b362b15af34006e6a11974088a46d42b903418eJohann 811b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::EncodeFrameInternal(const VideoSource &video, 821b362b15af34006e6a11974088a46d42b903418eJohann const unsigned long frame_flags) { 831b362b15af34006e6a11974088a46d42b903418eJohann vpx_codec_err_t res; 841b362b15af34006e6a11974088a46d42b903418eJohann const vpx_image_t *img = video.img(); 851b362b15af34006e6a11974088a46d42b903418eJohann 861b362b15af34006e6a11974088a46d42b903418eJohann // Handle frame resizing 871b362b15af34006e6a11974088a46d42b903418eJohann if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) { 881b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_w = img->d_w; 891b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_h = img->d_h; 901b362b15af34006e6a11974088a46d42b903418eJohann res = vpx_codec_enc_config_set(&encoder_, &cfg_); 911b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 921b362b15af34006e6a11974088a46d42b903418eJohann } 931b362b15af34006e6a11974088a46d42b903418eJohann 941b362b15af34006e6a11974088a46d42b903418eJohann // Encode the frame 95ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian API_REGISTER_STATE_CHECK( 967ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian res = vpx_codec_encode(&encoder_, img, video.pts(), video.duration(), 97ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang frame_flags, deadline_)); 981b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 991b362b15af34006e6a11974088a46d42b903418eJohann} 1001b362b15af34006e6a11974088a46d42b903418eJohann 1011b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::Flush() { 1021b362b15af34006e6a11974088a46d42b903418eJohann const vpx_codec_err_t res = vpx_codec_encode(&encoder_, NULL, 0, 0, 0, 1031b362b15af34006e6a11974088a46d42b903418eJohann deadline_); 104ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian if (!encoder_.priv) 105ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_ERROR, res) << EncoderError(); 106ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian else 107ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 1081b362b15af34006e6a11974088a46d42b903418eJohann} 1091b362b15af34006e6a11974088a46d42b903418eJohann 110ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangvoid EncoderTest::InitializeConfig() { 111ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const vpx_codec_err_t res = codec_->DefaultEncoderConfig(&cfg_, 0); 1127ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian dec_cfg_ = vpx_codec_dec_cfg_t(); 113ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_EQ(VPX_CODEC_OK, res); 114ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 115ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 1161b362b15af34006e6a11974088a46d42b903418eJohannvoid EncoderTest::SetMode(TestMode mode) { 1171b362b15af34006e6a11974088a46d42b903418eJohann switch (mode) { 1181b362b15af34006e6a11974088a46d42b903418eJohann case kRealTime: 1191b362b15af34006e6a11974088a46d42b903418eJohann deadline_ = VPX_DL_REALTIME; 1201b362b15af34006e6a11974088a46d42b903418eJohann break; 1211b362b15af34006e6a11974088a46d42b903418eJohann 1221b362b15af34006e6a11974088a46d42b903418eJohann case kOnePassGood: 1231b362b15af34006e6a11974088a46d42b903418eJohann case kTwoPassGood: 1241b362b15af34006e6a11974088a46d42b903418eJohann deadline_ = VPX_DL_GOOD_QUALITY; 1251b362b15af34006e6a11974088a46d42b903418eJohann break; 1261b362b15af34006e6a11974088a46d42b903418eJohann 1271b362b15af34006e6a11974088a46d42b903418eJohann case kOnePassBest: 1281b362b15af34006e6a11974088a46d42b903418eJohann case kTwoPassBest: 1291b362b15af34006e6a11974088a46d42b903418eJohann deadline_ = VPX_DL_BEST_QUALITY; 1301b362b15af34006e6a11974088a46d42b903418eJohann break; 1311b362b15af34006e6a11974088a46d42b903418eJohann 1321b362b15af34006e6a11974088a46d42b903418eJohann default: 1331b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_TRUE(false) << "Unexpected mode " << mode; 1341b362b15af34006e6a11974088a46d42b903418eJohann } 1351b362b15af34006e6a11974088a46d42b903418eJohann 1361b362b15af34006e6a11974088a46d42b903418eJohann if (mode == kTwoPassGood || mode == kTwoPassBest) 1371b362b15af34006e6a11974088a46d42b903418eJohann passes_ = 2; 1381b362b15af34006e6a11974088a46d42b903418eJohann else 1391b362b15af34006e6a11974088a46d42b903418eJohann passes_ = 1; 1401b362b15af34006e6a11974088a46d42b903418eJohann} 1411b362b15af34006e6a11974088a46d42b903418eJohann// The function should return "true" most of the time, therefore no early 1421b362b15af34006e6a11974088a46d42b903418eJohann// break-out is implemented within the match checking process. 1431b362b15af34006e6a11974088a46d42b903418eJohannstatic bool compare_img(const vpx_image_t *img1, 1441b362b15af34006e6a11974088a46d42b903418eJohann const vpx_image_t *img2) { 1451b362b15af34006e6a11974088a46d42b903418eJohann bool match = (img1->fmt == img2->fmt) && 1467ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian (img1->cs == img2->cs) && 1471b362b15af34006e6a11974088a46d42b903418eJohann (img1->d_w == img2->d_w) && 1481b362b15af34006e6a11974088a46d42b903418eJohann (img1->d_h == img2->d_h); 1491b362b15af34006e6a11974088a46d42b903418eJohann 1501b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int width_y = img1->d_w; 1511b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int height_y = img1->d_h; 1521b362b15af34006e6a11974088a46d42b903418eJohann unsigned int i; 1531b362b15af34006e6a11974088a46d42b903418eJohann for (i = 0; i < height_y; ++i) 1541184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y], 1551184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y], 1561184aebb761cbeac9124c37189a80a1a58f04b6bhkuang width_y) == 0) && match; 1571b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int width_uv = (img1->d_w + 1) >> 1; 1581b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int height_uv = (img1->d_h + 1) >> 1; 1591b362b15af34006e6a11974088a46d42b903418eJohann for (i = 0; i < height_uv; ++i) 1601184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U], 1611184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U], 1621184aebb761cbeac9124c37189a80a1a58f04b6bhkuang width_uv) == 0) && match; 1631b362b15af34006e6a11974088a46d42b903418eJohann for (i = 0; i < height_uv; ++i) 1641184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V], 1651184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V], 1661184aebb761cbeac9124c37189a80a1a58f04b6bhkuang width_uv) == 0) && match; 1671b362b15af34006e6a11974088a46d42b903418eJohann return match; 1681b362b15af34006e6a11974088a46d42b903418eJohann} 1691b362b15af34006e6a11974088a46d42b903418eJohann 1707ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanianvoid EncoderTest::MismatchHook(const vpx_image_t* /*img1*/, 1717ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const vpx_image_t* /*img2*/) { 172ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_TRUE(0) << "Encode/Decode mismatch found"; 173ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 174ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 1751b362b15af34006e6a11974088a46d42b903418eJohannvoid EncoderTest::RunLoop(VideoSource *video) { 1767ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t(); 1771b362b15af34006e6a11974088a46d42b903418eJohann 1781b362b15af34006e6a11974088a46d42b903418eJohann stats_.Reset(); 1791b362b15af34006e6a11974088a46d42b903418eJohann 180ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_TRUE(passes_ == 1 || passes_ == 2); 1811b362b15af34006e6a11974088a46d42b903418eJohann for (unsigned int pass = 0; pass < passes_; pass++) { 1821b362b15af34006e6a11974088a46d42b903418eJohann last_pts_ = 0; 1831b362b15af34006e6a11974088a46d42b903418eJohann 1841b362b15af34006e6a11974088a46d42b903418eJohann if (passes_ == 1) 1851b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_ONE_PASS; 1861b362b15af34006e6a11974088a46d42b903418eJohann else if (pass == 0) 1871b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_FIRST_PASS; 1881b362b15af34006e6a11974088a46d42b903418eJohann else 1891b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_LAST_PASS; 1901b362b15af34006e6a11974088a46d42b903418eJohann 1911b362b15af34006e6a11974088a46d42b903418eJohann BeginPassHook(pass); 192ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang Encoder* const encoder = codec_->CreateEncoder(cfg_, deadline_, init_flags_, 193ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang &stats_); 194ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_TRUE(encoder != NULL); 1957ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 1967ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian video->Begin(); 1977ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian encoder->InitEncoder(video); 198c927526be9a7b72fb5edb3f29c4e8ceabe0ec98aJohann ASSERT_FALSE(::testing::Test::HasFatalFailure()); 1997ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 2007ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian unsigned long dec_init_flags = 0; // NOLINT 2017ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Use fragment decoder if encoder outputs partitions. 2027ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // NOTE: fragment decoder and partition encoder are only supported by VP8. 2037ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) 2047ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian dec_init_flags |= VPX_CODEC_USE_INPUT_FRAGMENTS; 2057ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian Decoder* const decoder = codec_->CreateDecoder(dec_cfg, dec_init_flags, 0); 2061b362b15af34006e6a11974088a46d42b903418eJohann bool again; 2077ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian for (again = true; again; video->Next()) { 2081184aebb761cbeac9124c37189a80a1a58f04b6bhkuang again = (video->img() != NULL); 2091b362b15af34006e6a11974088a46d42b903418eJohann 2101b362b15af34006e6a11974088a46d42b903418eJohann PreEncodeFrameHook(video); 211ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PreEncodeFrameHook(video, encoder); 212ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang encoder->EncodeFrame(video, frame_flags_); 2131b362b15af34006e6a11974088a46d42b903418eJohann 214ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang CxDataIterator iter = encoder->GetCxData(); 2151b362b15af34006e6a11974088a46d42b903418eJohann 216ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bool has_cxdata = false; 217ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bool has_dxdata = false; 2181b362b15af34006e6a11974088a46d42b903418eJohann while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { 219ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang pkt = MutateEncoderOutputHook(pkt); 2201b362b15af34006e6a11974088a46d42b903418eJohann again = true; 2211b362b15af34006e6a11974088a46d42b903418eJohann switch (pkt->kind) { 2221b362b15af34006e6a11974088a46d42b903418eJohann case VPX_CODEC_CX_FRAME_PKT: 2231b362b15af34006e6a11974088a46d42b903418eJohann has_cxdata = true; 224ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (decoder && DoDecode()) { 225ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang vpx_codec_err_t res_dec = decoder->DecodeFrame( 226ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang (const uint8_t*)pkt->data.frame.buf, pkt->data.frame.sz); 227ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian 228ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian if (!HandleDecodeResult(res_dec, *video, decoder)) 229ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian break; 230ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian 231ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang has_dxdata = true; 232ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 2331b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_GE(pkt->data.frame.pts, last_pts_); 2341b362b15af34006e6a11974088a46d42b903418eJohann last_pts_ = pkt->data.frame.pts; 2351b362b15af34006e6a11974088a46d42b903418eJohann FramePktHook(pkt); 2361b362b15af34006e6a11974088a46d42b903418eJohann break; 2371b362b15af34006e6a11974088a46d42b903418eJohann 2381b362b15af34006e6a11974088a46d42b903418eJohann case VPX_CODEC_PSNR_PKT: 2391b362b15af34006e6a11974088a46d42b903418eJohann PSNRPktHook(pkt); 2401b362b15af34006e6a11974088a46d42b903418eJohann break; 2411b362b15af34006e6a11974088a46d42b903418eJohann 2421b362b15af34006e6a11974088a46d42b903418eJohann default: 2431b362b15af34006e6a11974088a46d42b903418eJohann break; 2441b362b15af34006e6a11974088a46d42b903418eJohann } 2451b362b15af34006e6a11974088a46d42b903418eJohann } 2461b362b15af34006e6a11974088a46d42b903418eJohann 2477ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Flush the decoder when there are no more fragments. 2487ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if ((init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) && has_dxdata) { 2497ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0); 2507ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (!HandleDecodeResult(res_dec, *video, decoder)) 2517ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian break; 2527ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 2537ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 254ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (has_dxdata && has_cxdata) { 255ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const vpx_image_t *img_enc = encoder->GetPreviewFrame(); 256ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang DxDataIterator dec_iter = decoder->GetDxData(); 2571b362b15af34006e6a11974088a46d42b903418eJohann const vpx_image_t *img_dec = dec_iter.Next(); 258ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (img_enc && img_dec) { 2591b362b15af34006e6a11974088a46d42b903418eJohann const bool res = compare_img(img_enc, img_dec); 260ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (!res) { // Mismatch 261ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MismatchHook(img_enc, img_dec); 262ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 2631b362b15af34006e6a11974088a46d42b903418eJohann } 264ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (img_dec) 265ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang DecompressedFrameHook(*img_dec, video->pts()); 2661b362b15af34006e6a11974088a46d42b903418eJohann } 2671b362b15af34006e6a11974088a46d42b903418eJohann if (!Continue()) 2681b362b15af34006e6a11974088a46d42b903418eJohann break; 2691b362b15af34006e6a11974088a46d42b903418eJohann } 2701b362b15af34006e6a11974088a46d42b903418eJohann 2711b362b15af34006e6a11974088a46d42b903418eJohann EndPassHook(); 2721b362b15af34006e6a11974088a46d42b903418eJohann 273ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (decoder) 274ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang delete decoder; 275ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang delete encoder; 276ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 2771b362b15af34006e6a11974088a46d42b903418eJohann if (!Continue()) 2781b362b15af34006e6a11974088a46d42b903418eJohann break; 2791b362b15af34006e6a11974088a46d42b903418eJohann } 2801b362b15af34006e6a11974088a46d42b903418eJohann} 281ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 2821b362b15af34006e6a11974088a46d42b903418eJohann} // namespace libvpx_test 283