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 337bc9febe8749e98a3812a0dc4380ceae75c29450Johann res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_, init_flags_); 347ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 357ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 367ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if CONFIG_VP9_ENCODER 377ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if (CodecInterface() == &vpx_codec_vp9_cx_algo) { 387ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Default to 1 tile column for VP9. 397ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const int log2_tile_columns = 0; 407ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian res = vpx_codec_control_(&encoder_, VP9E_SET_TILE_COLUMNS, 417ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian log2_tile_columns); 427ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 437ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } else 447ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 457ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian { 467ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#if CONFIG_VP8_ENCODER 477ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian ASSERT_EQ(&vpx_codec_vp8_cx_algo, CodecInterface()) 487ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian << "Unknown Codec Interface"; 497ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian#endif 507ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 517ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 527ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian} 537ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 541b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { 557bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (video->img()) { 561b362b15af34006e6a11974088a46d42b903418eJohann EncodeFrameInternal(*video, frame_flags); 577bc9febe8749e98a3812a0dc4380ceae75c29450Johann } else { 581b362b15af34006e6a11974088a46d42b903418eJohann Flush(); 597bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 601b362b15af34006e6a11974088a46d42b903418eJohann 611b362b15af34006e6a11974088a46d42b903418eJohann // Handle twopass stats 621b362b15af34006e6a11974088a46d42b903418eJohann CxDataIterator iter = GetCxData(); 631b362b15af34006e6a11974088a46d42b903418eJohann 641b362b15af34006e6a11974088a46d42b903418eJohann while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { 657bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (pkt->kind != VPX_CODEC_STATS_PKT) continue; 661b362b15af34006e6a11974088a46d42b903418eJohann 671b362b15af34006e6a11974088a46d42b903418eJohann stats_->Append(*pkt); 681b362b15af34006e6a11974088a46d42b903418eJohann } 691b362b15af34006e6a11974088a46d42b903418eJohann} 701b362b15af34006e6a11974088a46d42b903418eJohann 711b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::EncodeFrameInternal(const VideoSource &video, 721b362b15af34006e6a11974088a46d42b903418eJohann const unsigned long frame_flags) { 731b362b15af34006e6a11974088a46d42b903418eJohann vpx_codec_err_t res; 741b362b15af34006e6a11974088a46d42b903418eJohann const vpx_image_t *img = video.img(); 751b362b15af34006e6a11974088a46d42b903418eJohann 761b362b15af34006e6a11974088a46d42b903418eJohann // Handle frame resizing 771b362b15af34006e6a11974088a46d42b903418eJohann if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) { 781b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_w = img->d_w; 791b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_h = img->d_h; 801b362b15af34006e6a11974088a46d42b903418eJohann res = vpx_codec_enc_config_set(&encoder_, &cfg_); 811b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 821b362b15af34006e6a11974088a46d42b903418eJohann } 831b362b15af34006e6a11974088a46d42b903418eJohann 841b362b15af34006e6a11974088a46d42b903418eJohann // Encode the frame 857bc9febe8749e98a3812a0dc4380ceae75c29450Johann API_REGISTER_STATE_CHECK(res = vpx_codec_encode(&encoder_, img, video.pts(), 867bc9febe8749e98a3812a0dc4380ceae75c29450Johann video.duration(), frame_flags, 877bc9febe8749e98a3812a0dc4380ceae75c29450Johann deadline_)); 881b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 891b362b15af34006e6a11974088a46d42b903418eJohann} 901b362b15af34006e6a11974088a46d42b903418eJohann 911b362b15af34006e6a11974088a46d42b903418eJohannvoid Encoder::Flush() { 927bc9febe8749e98a3812a0dc4380ceae75c29450Johann const vpx_codec_err_t res = 937bc9febe8749e98a3812a0dc4380ceae75c29450Johann vpx_codec_encode(&encoder_, NULL, 0, 0, 0, deadline_); 94ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian if (!encoder_.priv) 95ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_ERROR, res) << EncoderError(); 96ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian else 97ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); 981b362b15af34006e6a11974088a46d42b903418eJohann} 991b362b15af34006e6a11974088a46d42b903418eJohann 100ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangvoid EncoderTest::InitializeConfig() { 101ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const vpx_codec_err_t res = codec_->DefaultEncoderConfig(&cfg_, 0); 1027ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian dec_cfg_ = vpx_codec_dec_cfg_t(); 103ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_EQ(VPX_CODEC_OK, res); 104ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 105ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 1061b362b15af34006e6a11974088a46d42b903418eJohannvoid EncoderTest::SetMode(TestMode mode) { 1071b362b15af34006e6a11974088a46d42b903418eJohann switch (mode) { 1087bc9febe8749e98a3812a0dc4380ceae75c29450Johann case kRealTime: deadline_ = VPX_DL_REALTIME; break; 1091b362b15af34006e6a11974088a46d42b903418eJohann 1101b362b15af34006e6a11974088a46d42b903418eJohann case kOnePassGood: 1117bc9febe8749e98a3812a0dc4380ceae75c29450Johann case kTwoPassGood: deadline_ = VPX_DL_GOOD_QUALITY; break; 1121b362b15af34006e6a11974088a46d42b903418eJohann 1131b362b15af34006e6a11974088a46d42b903418eJohann case kOnePassBest: 1147bc9febe8749e98a3812a0dc4380ceae75c29450Johann case kTwoPassBest: deadline_ = VPX_DL_BEST_QUALITY; break; 1151b362b15af34006e6a11974088a46d42b903418eJohann 1167bc9febe8749e98a3812a0dc4380ceae75c29450Johann default: ASSERT_TRUE(false) << "Unexpected mode " << mode; 1171b362b15af34006e6a11974088a46d42b903418eJohann } 1181b362b15af34006e6a11974088a46d42b903418eJohann 1197bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (mode == kTwoPassGood || mode == kTwoPassBest) { 1201b362b15af34006e6a11974088a46d42b903418eJohann passes_ = 2; 1217bc9febe8749e98a3812a0dc4380ceae75c29450Johann } else { 1221b362b15af34006e6a11974088a46d42b903418eJohann passes_ = 1; 1237bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1241b362b15af34006e6a11974088a46d42b903418eJohann} 1251b362b15af34006e6a11974088a46d42b903418eJohann// The function should return "true" most of the time, therefore no early 1261b362b15af34006e6a11974088a46d42b903418eJohann// break-out is implemented within the match checking process. 1277bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic bool compare_img(const vpx_image_t *img1, const vpx_image_t *img2) { 1287bc9febe8749e98a3812a0dc4380ceae75c29450Johann bool match = (img1->fmt == img2->fmt) && (img1->cs == img2->cs) && 1297bc9febe8749e98a3812a0dc4380ceae75c29450Johann (img1->d_w == img2->d_w) && (img1->d_h == img2->d_h); 1307bc9febe8749e98a3812a0dc4380ceae75c29450Johann 1317bc9febe8749e98a3812a0dc4380ceae75c29450Johann const unsigned int width_y = img1->d_w; 1321b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int height_y = img1->d_h; 1331b362b15af34006e6a11974088a46d42b903418eJohann unsigned int i; 1347bc9febe8749e98a3812a0dc4380ceae75c29450Johann for (i = 0; i < height_y; ++i) { 1351184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y], 1361184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y], 1377bc9febe8749e98a3812a0dc4380ceae75c29450Johann width_y) == 0) && 1387bc9febe8749e98a3812a0dc4380ceae75c29450Johann match; 1397bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1407bc9febe8749e98a3812a0dc4380ceae75c29450Johann const unsigned int width_uv = (img1->d_w + 1) >> 1; 1411b362b15af34006e6a11974088a46d42b903418eJohann const unsigned int height_uv = (img1->d_h + 1) >> 1; 1427bc9febe8749e98a3812a0dc4380ceae75c29450Johann for (i = 0; i < height_uv; ++i) { 1431184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U], 1441184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U], 1457bc9febe8749e98a3812a0dc4380ceae75c29450Johann width_uv) == 0) && 1467bc9febe8749e98a3812a0dc4380ceae75c29450Johann match; 1477bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1487bc9febe8749e98a3812a0dc4380ceae75c29450Johann for (i = 0; i < height_uv; ++i) { 1491184aebb761cbeac9124c37189a80a1a58f04b6bhkuang match = (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V], 1501184aebb761cbeac9124c37189a80a1a58f04b6bhkuang img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V], 1517bc9febe8749e98a3812a0dc4380ceae75c29450Johann width_uv) == 0) && 1527bc9febe8749e98a3812a0dc4380ceae75c29450Johann match; 1537bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1541b362b15af34006e6a11974088a46d42b903418eJohann return match; 1551b362b15af34006e6a11974088a46d42b903418eJohann} 1561b362b15af34006e6a11974088a46d42b903418eJohann 1577bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid EncoderTest::MismatchHook(const vpx_image_t * /*img1*/, 1587bc9febe8749e98a3812a0dc4380ceae75c29450Johann const vpx_image_t * /*img2*/) { 159ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_TRUE(0) << "Encode/Decode mismatch found"; 160ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 161ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 1621b362b15af34006e6a11974088a46d42b903418eJohannvoid EncoderTest::RunLoop(VideoSource *video) { 1637ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t(); 1641b362b15af34006e6a11974088a46d42b903418eJohann 1651b362b15af34006e6a11974088a46d42b903418eJohann stats_.Reset(); 1661b362b15af34006e6a11974088a46d42b903418eJohann 167ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ASSERT_TRUE(passes_ == 1 || passes_ == 2); 1681b362b15af34006e6a11974088a46d42b903418eJohann for (unsigned int pass = 0; pass < passes_; pass++) { 1691b362b15af34006e6a11974088a46d42b903418eJohann last_pts_ = 0; 1701b362b15af34006e6a11974088a46d42b903418eJohann 1717bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (passes_ == 1) { 1721b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_ONE_PASS; 1737bc9febe8749e98a3812a0dc4380ceae75c29450Johann } else if (pass == 0) { 1741b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_FIRST_PASS; 1757bc9febe8749e98a3812a0dc4380ceae75c29450Johann } else { 1761b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_pass = VPX_RC_LAST_PASS; 1777bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1781b362b15af34006e6a11974088a46d42b903418eJohann 1791b362b15af34006e6a11974088a46d42b903418eJohann BeginPassHook(pass); 1807bc9febe8749e98a3812a0dc4380ceae75c29450Johann testing::internal::scoped_ptr<Encoder> encoder( 1817bc9febe8749e98a3812a0dc4380ceae75c29450Johann codec_->CreateEncoder(cfg_, deadline_, init_flags_, &stats_)); 1827bc9febe8749e98a3812a0dc4380ceae75c29450Johann ASSERT_TRUE(encoder.get() != NULL); 1837ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 1847bc9febe8749e98a3812a0dc4380ceae75c29450Johann ASSERT_NO_FATAL_FAILURE(video->Begin()); 1857ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian encoder->InitEncoder(video); 186c927526be9a7b72fb5edb3f29c4e8ceabe0ec98aJohann ASSERT_FALSE(::testing::Test::HasFatalFailure()); 1877ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 1887ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian unsigned long dec_init_flags = 0; // NOLINT 1897ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Use fragment decoder if encoder outputs partitions. 1907ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // NOTE: fragment decoder and partition encoder are only supported by VP8. 1917bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) { 1927ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian dec_init_flags |= VPX_CODEC_USE_INPUT_FRAGMENTS; 1937bc9febe8749e98a3812a0dc4380ceae75c29450Johann } 1947bc9febe8749e98a3812a0dc4380ceae75c29450Johann testing::internal::scoped_ptr<Decoder> decoder( 1957bc9febe8749e98a3812a0dc4380ceae75c29450Johann codec_->CreateDecoder(dec_cfg, dec_init_flags)); 1961b362b15af34006e6a11974088a46d42b903418eJohann bool again; 1977ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian for (again = true; again; video->Next()) { 1981184aebb761cbeac9124c37189a80a1a58f04b6bhkuang again = (video->img() != NULL); 1991b362b15af34006e6a11974088a46d42b903418eJohann 2001b362b15af34006e6a11974088a46d42b903418eJohann PreEncodeFrameHook(video); 2017bc9febe8749e98a3812a0dc4380ceae75c29450Johann PreEncodeFrameHook(video, encoder.get()); 202ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang encoder->EncodeFrame(video, frame_flags_); 2031b362b15af34006e6a11974088a46d42b903418eJohann 204ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang CxDataIterator iter = encoder->GetCxData(); 2051b362b15af34006e6a11974088a46d42b903418eJohann 206ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bool has_cxdata = false; 207ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bool has_dxdata = false; 2081b362b15af34006e6a11974088a46d42b903418eJohann while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { 209ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang pkt = MutateEncoderOutputHook(pkt); 2101b362b15af34006e6a11974088a46d42b903418eJohann again = true; 2111b362b15af34006e6a11974088a46d42b903418eJohann switch (pkt->kind) { 2121b362b15af34006e6a11974088a46d42b903418eJohann case VPX_CODEC_CX_FRAME_PKT: 2131b362b15af34006e6a11974088a46d42b903418eJohann has_cxdata = true; 2147bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (decoder.get() != NULL && DoDecode()) { 215ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang vpx_codec_err_t res_dec = decoder->DecodeFrame( 2167bc9febe8749e98a3812a0dc4380ceae75c29450Johann (const uint8_t *)pkt->data.frame.buf, pkt->data.frame.sz); 217ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian 2187bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (!HandleDecodeResult(res_dec, *video, decoder.get())) break; 219ba6c59e9d7d7013b3906b6f4230b663422681848Vignesh Venkatasubramanian 220ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang has_dxdata = true; 221ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 2221b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_GE(pkt->data.frame.pts, last_pts_); 2231b362b15af34006e6a11974088a46d42b903418eJohann last_pts_ = pkt->data.frame.pts; 2241b362b15af34006e6a11974088a46d42b903418eJohann FramePktHook(pkt); 2251b362b15af34006e6a11974088a46d42b903418eJohann break; 2261b362b15af34006e6a11974088a46d42b903418eJohann 2277bc9febe8749e98a3812a0dc4380ceae75c29450Johann case VPX_CODEC_PSNR_PKT: PSNRPktHook(pkt); break; 2281b362b15af34006e6a11974088a46d42b903418eJohann 2298b92989c89bec8632aa47dc58dc162f199d62edcJames Zern case VPX_CODEC_STATS_PKT: StatsPktHook(pkt); break; 2308b92989c89bec8632aa47dc58dc162f199d62edcJames Zern 2317bc9febe8749e98a3812a0dc4380ceae75c29450Johann default: break; 2321b362b15af34006e6a11974088a46d42b903418eJohann } 2331b362b15af34006e6a11974088a46d42b903418eJohann } 2341b362b15af34006e6a11974088a46d42b903418eJohann 2357ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian // Flush the decoder when there are no more fragments. 2367ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian if ((init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) && has_dxdata) { 2377ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0); 2387bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (!HandleDecodeResult(res_dec, *video, decoder.get())) break; 2397ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian } 2407ce0a1d1337c01056ba24006efab21f00e179e04Vignesh Venkatasubramanian 241ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (has_dxdata && has_cxdata) { 242ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const vpx_image_t *img_enc = encoder->GetPreviewFrame(); 243ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang DxDataIterator dec_iter = decoder->GetDxData(); 2441b362b15af34006e6a11974088a46d42b903418eJohann const vpx_image_t *img_dec = dec_iter.Next(); 245ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (img_enc && img_dec) { 2461b362b15af34006e6a11974088a46d42b903418eJohann const bool res = compare_img(img_enc, img_dec); 247ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (!res) { // Mismatch 248ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MismatchHook(img_enc, img_dec); 249ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 2501b362b15af34006e6a11974088a46d42b903418eJohann } 2517bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (img_dec) DecompressedFrameHook(*img_dec, video->pts()); 2521b362b15af34006e6a11974088a46d42b903418eJohann } 2537bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (!Continue()) break; 2541b362b15af34006e6a11974088a46d42b903418eJohann } 2551b362b15af34006e6a11974088a46d42b903418eJohann 2561b362b15af34006e6a11974088a46d42b903418eJohann EndPassHook(); 2571b362b15af34006e6a11974088a46d42b903418eJohann 2587bc9febe8749e98a3812a0dc4380ceae75c29450Johann if (!Continue()) break; 2591b362b15af34006e6a11974088a46d42b903418eJohann } 2601b362b15af34006e6a11974088a46d42b903418eJohann} 261ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 2621b362b15af34006e6a11974088a46d42b903418eJohann} // namespace libvpx_test 263