Compare commits

..

385 Commits

Author SHA1 Message Date
hui su
be407e001b Adjust optimize_b RD parameters
Coding gain
lowres 0.51%
midres 0.36%

Change-Id: I1e9f2f9341bad12d9023f97c73d0e991ae5ec7f0
2016-05-06 09:56:59 -07:00
hui su
5af706210b Enable optimize_b for intra blocks
Coding gain
lowres 0.13%
midres 0.36%

Change-Id: Ia65d2d7513685dfcffbe3939fea473fb6d7036b9
2016-05-06 09:55:45 -07:00
Geza Lore
6d9bec4366 Configure tiles in tests when using row-tile.
With row-tile enabled, the encoder test driver needs to configure the
decoder in order to decode all tiles correctly.

Change-Id: I8b00a766cf5e41255625846f92fd71915c614ec1
2016-05-03 14:42:17 -07:00
Debargha Mukherjee
7a2934550b Merge "Quantization Profiles Strictly on Entropy Context" into nextgen 2016-05-02 19:15:13 +00:00
Brandon Young
43195061b7 Quantization Profiles Strictly on Entropy Context
Allow for 3 quant profiles from entropy context

Refactored dq_offset bands to allow for re-optimization based on number
of quantization profiles

Change-Id: Ib8d7e8854ad4e0bf8745038df28833d91efcfbea
2016-05-01 12:25:57 -07:00
Sarah Parker
b8bf8085be Merge "Search parameter space around gm parameters" into nextgen 2016-04-26 22:08:20 +00:00
Sarah Parker
31257e5406 Merge "Make feature based motion estimation the default" into nextgen 2016-04-22 01:21:09 +00:00
Sarah Parker
ba6423c564 Make feature based motion estimation the default
Optical flow parameters still need to be tweaked and is much slower
so feature based should be the default for now.

Change-Id: Id6cafb5a245e329f728e9c66c89c0ed1018c347c
2016-04-21 11:50:05 -07:00
Sarah Parker
70266ab130 Increase precision for gm parameters
Change-Id: I151ca8ec9b0c8a920745f4b1665d369a258f6ccb
2016-04-21 11:48:13 -07:00
Sarah Parker
7fa7f4c14a Fix comipler warnings in opticalflow.c
Change-Id: I4561c2676d8a7793ade47e1995e026ba9d521fdd
2016-04-20 17:27:13 -07:00
Debargha Mukherjee
3e3f40acb9 Fix for libwebm upgrade
To allow runborgs to run on the nextgen branch

Change-Id: Icbd425c5e65dd4bcb061a3a1ed4dbe0393dc2c5d
2016-04-19 10:27:42 -07:00
Sarah Parker
de085787ec Search parameter space around gm parameters
For each global motion parameter, search some step
size to the left and right to try and minimize warp
mse and correct for error.

Change-Id: I1f0b464b0924d56b15460e509f89736af9b7e78f
2016-04-13 17:56:25 -07:00
Brandon Young
50619bacfd Fix error with cumbins to allow multiple profiles
Change-Id: I23aadc8f7551771197b55465a3264250b40838ff
2016-04-08 13:16:34 -07:00
Debargha Mukherjee
72ee991598 Adds function to return superblock entropy context
For use with switchable quant profiles.

Change-Id: I2a4aa93204f086094457860d1646707d71f33f5e
2016-03-15 14:27:45 -07:00
Debargha Mukherjee
a399281daa Merge "Framework to incorporate switchable dequant levels" into nextgen 2016-03-14 16:34:04 +00:00
Debargha Mukherjee
b8a7d1fe02 Framework to incorporate switchable dequant levels
Changed experiment to allow switchable QUANT_PROFILES

Change-Id: I8e5e76239a4103273e9ef759d46400104ef55599
2016-03-11 23:07:26 -08:00
Geza Lore
d8739359a1 Make vpxenc --test-decode work with --enable-row-tile
Change-Id: I352c8ccdaa5faa4fd345f0cb0f7e614af669f0bc
2016-02-29 14:14:16 +00:00
Debargha Mukherjee
f90038c3a1 Remove key_frame_tile config option
Change-Id: I8ae22e9f706727ee258dc24780644b99087c8d23
2016-02-23 13:07:09 -08:00
Debargha Mukherjee
fb6bf251d4 Merge key_frame_tile experiment with row_tile
Since they are used together no need to keep them separate.

Change-Id: Ia7b4bec06ca6924fffd806f772638224292fddb2
2016-02-23 09:57:25 -08:00
Yunqing Wang
efb93f518f Merge "Implement a tile copying method in large-scale tile coding" into nextgen 2016-02-05 23:10:08 +00:00
Yunqing Wang
6e4dff92a4 Implement a tile copying method in large-scale tile coding
A tile copy mode is introduced, while allows a tile to use
another tile's coded data directly at bitstream level. This
largely reduces the bit rate in this use case. Our tests
showed that 10% - 20% bit rate reduction was achieved.

Change-Id: Icf5ae00320e27193b15ce95297720f8b6f5e7fd9
2016-02-01 11:08:30 -08:00
Sarah Parker
36cbc27587 Merge "Optical flow for computing global motion params" into nextgen 2016-01-25 22:06:32 +00:00
Yunqing Wang
990e30b8a7 Merge "Make set_reference control API work in VP9" into nextgen 2016-01-25 19:27:42 +00:00
Yunqing Wang
bcdc6befd2 Make set_reference control API work in VP9
1. Made VP8_SET_REFERENCE vpx_codec_control API work in VP9 based
on Ryan Overbeck's patch. (Thanks.)
2. Added vp9cx_set_ref example, which demonstrated how to set
VP8_SET_REFERENCE vpx_codec_control in encoder and decoder. If
we only set_reference in the encoder, the encoder/decoder
mismatch would be observed.
3. Also updated test/cx_set_ref.sh.

Change-Id: I433a6220616947ca8c73e65a5fb3694751ea84b6
2016-01-25 10:37:15 -08:00
Sarah Parker
a7aab42915 Optical flow for computing global motion params
Addressing comments, fixing style issues

Change-Id: I91b72ab5cdf80d68476858f442616ab3af41e709
2016-01-22 11:29:33 -08:00
Debargha Mukherjee
b765dc8e39 Merge "Changes to CONFIG_NEW_QUANT experiment." into nextgen 2016-01-22 00:15:05 +00:00
Brandon Young
9c9beb1c40 Changes to CONFIG_NEW_QUANT experiment.
Added dq_off_index attribute to mbmi to allow for switching between
dequantization modes.
Reduced number of different dequantization modes from 5 to 3.
Changed dequant_val_nuq to be allow for 3 dequant levels instead of 1.
Fixed lint errors

Change-Id: I7aee3548011aa4eee18adb09d835051c3108d2ee
2016-01-19 15:59:50 -08:00
Debargha Mukherjee
c20adb59b2 Merge "Rework wedge experiment to improve speed." into nextgen 2016-01-14 16:13:38 +00:00
Brandon Young
839ab586f6 Merge "Simplify new_quant experiment" into nextgen 2016-01-14 00:51:56 +00:00
Debargha Mukherjee
f93bdebcf9 Rework wedge experiment to improve speed.
Implements wedge mask generation by pre-computing arrays.
Improves encode speed by 15-20%.

Also consolidates the mask generation code for inter-inter
and inter-intra.

Change-Id: If1d4ae2babb2c05bd50cc30affce22785fd59f95
2016-01-12 15:23:54 -08:00
Yunqing Wang
15a90668a5 Adaptively determine the number of bytes used for tile-data size transmission
In large-scale tile coding, when the number of tiles is large and the tile
size is small, using a fixed number of bytes in the tile header to store
tile-data size information as done in current VP9 codec would bring high
overhead for each tile. This patch implemented 2 ways to lower that overhead
and adaptively determine the number of bytes needed for tile-data size
transmission.

The test on a test clip having the tile size of 64x64 showed that the number
of bytes used for storing tile-data size was reduced from 4 to 1, which
substantially improved the compression ratio in large-scale tile coding.

Change-Id: Ia02fc43eda67fa252fbc2554321957790f53f6fd
2016-01-11 12:46:04 -08:00
Brandon Young
604b909e06 Simplify new_quant experiment
Changes number of non-uniform bins from 5 to 3.
Changed all references to 'KNOTES' to 'KNOTS'.

Change-Id: If39d7cef00dbe07307035e44cb29194d0783b475
2015-12-17 12:25:27 -08:00
Debargha Mukherjee
e6790e30c5 Replace DST1 with DST2 for ext-tx experiment
A small gain (0.1 - 0.2%) with this experiment on derflr/hevcmr.

The DST2 can be implemened very efficiently using sign flipping
of odd indexed inputs, followed by DCT, followed by reversal of
the output. This is how it is implemented in this patch.
SIMD optimization is pending.

Change-Id: Ic2fc211ce0e6b7c6702974d76d6573f55cc4da0e
2015-12-14 13:54:41 -08:00
Debargha Mukherjee
d7eb423a72 Merge "SSSE3 optimisations of high bit depth masked variance functions" into nextgen 2015-12-08 21:54:03 +00:00
Peter de Rivaz
087a93eae5 Fix to avoid overflow in highbd_masked_variance64.
Change-Id: I98731c5f50c4821c604f53480f43110a75205d25
2015-12-08 11:12:35 -08:00
Julia Robson
711600e5f1 SSSE3 optimisations of high bit depth masked variance functions
Includes tests which compare output of new SSSE3 functions with
their C equivalents, and fixes to the C code to ensure these tests
pass.

Change-Id: Iec3980cce95a8ee6bf9421fa4793130e92c162e3
2015-12-04 11:59:30 -08:00
Julia Robson
997595e8a6 Code refactoring to remove duplication in masked sub pixel var fns
Change-Id: Idcc93ff94ed2c68367225b6bebfcae0b7952f074
2015-12-03 17:57:35 +00:00
Yunqing Wang
9227a372d3 Merge "Reduce the memset call in tile decoding" into nextgen 2015-12-02 00:24:06 +00:00
Julia Robson
ea167a5855 Adding SSSE3 accelerations of masked SAD functions
Includes tests of masked SAD function optimisations against C
versions

Change-Id: I42f198767a113b58ae9456841f4ec71075591720
2015-12-01 09:55:24 -08:00
Julia Robson
8e4d779137 SSSE3 optimisations of masked variance function (8bit ONLY)
Includes test which compares output of new SSSE3 functions with their
C equivalents

Change-Id: I4488cd7672cdb57efff93c0b3b8bff07f07ec544
2015-12-01 12:07:22 +00:00
Julia Robson
ef01ea152d Changes so other expts work with 128x128 coding unit size expt
Changes ensure wedge_partition, interintra and palette expts all
work alongside the ext_coding_unit_size experiment.

Change-Id: I18f17acb29071f6fc6784e815661c73cc21144d6
2015-11-26 17:43:00 +00:00
Yunqing Wang
7099feaeed Reduce the memset call in tile decoding
When the error resilient mode is on, the decoder resets mode info structure
to zero once per frame. This makes decoder about 10x slower if we decode
a single tile at a time. This patch resolves the issue by only memset mode
info of those decoded tiles. Currently, to decode a frame, tile decoding is
less than 2x slower than frame decoding.

Change-Id: Ia3fd88d91a4e74e7bbbc6547d87c24d085a1533e
2015-11-25 15:28:03 -08:00
Julia Robson
d52cc33891 Changes to allow 128x128 to work with copy_mode
Change-Id: I1fff46e7733e5e1d15c012d6a204536243c6e090
2015-11-24 10:15:10 -08:00
Peter de Rivaz
d79850e60c Bug fix for high bitdepth using flipped transforms.
Fixes mismatch and performance drop.

Change-Id: Ib99711eb3b78257a8105073e2b6d7031459357bb
2015-11-23 12:04:55 -08:00
Geza Lore
85ab9d56cc Flip the result of the inv transform for FLIPADST.
This is a port of 4f5108090a6047d5d4d9ce1df302da23b2ef4bc5

This commit also fixes a bug where FLIPADST transforms when combined
with a DST (that is FLIPADST_DST and DST_FLIPADST) did not actually did
a flipped transform but a straight ADST instead. This was due to the C
implementation that it fell back on not implementing flipping.  This is
now fixed as well and FLIPADST_DST and DST_FLIPADST does what it is
supposed to do.

There are 3 functions in the SR_MODE experiment that should be updated,
but given that the build of SR_MODE is broken at the upstream tip of
nextgen, I could not test these, so I have put in assertions and FIXME
notes at the problematic places.

Change-Id: I5b8175b85f944f2369b183a26256e08d97f4bdef
2015-11-17 14:31:28 -08:00
Debargha Mukherjee
f1f3a8ab14 Increase extension for ext-coding-unti-size expt
Change-Id: Ifc7fe5df6831cb7190b9b6e84125de13b9e0146f
2015-11-16 16:57:50 -08:00
Debargha Mukherjee
484c8858f0 Remove last4-ref config option
Change-Id: I12ab2f8b039e328210ae8eadc663f751e19c0c09
2015-11-13 16:22:28 -08:00
Debargha Mukherjee
0c29af2767 Merge last4_ref with multi-ref experiment
Change-Id: I9778670ff6d02fb021099b17f292edadf87603e6
2015-11-13 14:54:38 -08:00
Debargha Mukherjee
ec6d31781d Merge "Remove dst1 config option and merge with ext-tx" into nextgen 2015-11-13 21:01:21 +00:00
Debargha Mukherjee
3a45a1edfd Remove dst1 config option and merge with ext-tx
Change-Id: I0152ed352ae2a0a725a508b5c209ef2c1dc2302d
2015-11-13 11:24:38 -08:00
Julia Robson
3d9133b2a5 SSE2 optim of vp9_subtract_block for 128x128 units
Extending the SSE2 implementation of vp9_subtract_block to work
with the 128x128 coding unit experiment

Change-Id: Ib3cc16bf5801ef2c7eecc19d3cc07a8c50631580
2015-11-13 11:12:56 -08:00
Debargha Mukherjee
3436acb347 Merge "Adding encoder support for 128x128 coding units" into nextgen 2015-11-13 18:52:09 +00:00
Debargha Mukherjee
a542190830 Merge "Eliminate copying for FLIPADST in fwd transforms." into nextgen 2015-11-13 18:23:49 +00:00
Geza Lore
177ad11981 Eliminate copying for FLIPADST in fwd transforms.
This is a port of 01bb4a318dc0f9069264b7fd5641bc3014f47f32

This commit also fixes a bug where FLIPADST transforms when combined
with a DST (that is FLIPADST_DST and DST_FLIPADST) did not actually did
a flipped transform but a straight ADST instead. This was due to the C
implementation that it fell back on not implementing flipping.  This is
now fixed as well and FLIPADST_DST and DST_FLIPADST does what it is
supposed to do.

Change-Id: I89c67ca1d5e06808a1567c51e7d6bec4998182bd
2015-11-13 09:34:26 -08:00
Debargha Mukherjee
59de0c0bc7 Adding encoder support for 128x128 coding units
Changes to allow the encoder to make use of 128x128 coding units.

Change-Id: I340bd38f9d9750cb6346d83885efb00443852910
2015-11-13 09:21:22 -08:00
Debargha Mukherjee
9d9962aec9 Some fixes on context size for the 128x128 expt
Change-Id: I56f050502e3a750ce74b196d033b780218df2c1f
2015-11-13 07:06:19 -08:00
Johann Koenig
a0c13e6757 Merge "Cherry pick the rest of 661802, the important part" into nextgen 2015-11-13 00:47:05 +00:00
Julia Robson
d90a3265f0 Changes to use defined constants rather than hard-coded numbers
Also fixes a valgrind error when optimizations are disabled.
Done in preparation for the work on the extended coding unit size
experiment.

Change-Id: Ib074c5a02c94ebed7dd61ff0465d26fa89834545
2015-11-12 15:42:32 -08:00
Johann
a877c6e9a6 Cherry pick the rest of 661802, the important part
Change-Id: I85f1d2c07b89c874ea6c30df32dda9ecaa8d2c3f
2015-11-12 15:41:24 -08:00
Debargha Mukherjee
bd7a34d5a3 Merge "Fixing issue with calculation of block_idx" into nextgen 2015-11-12 23:39:35 +00:00
Johann
26272dd366 Cherry pick 661802 to fix 64bit arm build
Remove default cortex-a8 tuning.

Probably not even the dominant platform the library is being built for.
Add --cpu= option description to help. The option already exists.

Don't allow passing just --cpu as a no-op.

BUG=826

Change-Id: Iaa3f4f693ec78b18927b159b480daafeba0549c0
2015-11-12 14:51:53 -08:00
Julia Robson
598a11d04a Fixing issue with calculation of block_idx
For tall rectangular blocks, the block_idx of the lower transform
block was being mis-calculated.

Does not affect results the way this function is being used now.

Change-Id: I470464d19be0bf0f42003d0cc29793bc42db8f52
2015-11-12 08:21:53 -08:00
Julia Robson
84a5403bab Added decoder support for 128x128 coding units
Change-Id: Icf3c6b64caaf8a86cd27231aa27baf5fd99c0fde
2015-11-02 16:03:30 +00:00
Julia Robson
2a1f8c74aa Changes to use defined constants rather than hard-coded numbers
These changes have been made in preparation for the work on the
extended coding unit size experiment.

Change-Id: I83f289812426bb9aba6c4a5fedd2b0e0a4fe17cb
2015-11-02 16:02:55 +00:00
Sarah Parker
42abac9374 Fixed final style issues
WIP.

Change-Id: Iafcbcfdc2139e77eb2c6849a52a9dc94ea498d66
2015-10-27 18:39:54 -07:00
Debargha Mukherjee
9ef4023569 Remove some unused variables
Change-Id: I3ab263b4c42cc3bfd598a1fc280fbaffba2d4461
2015-10-15 12:50:15 -07:00
Julia Robson
dff4e683fd Added extended coding unit size experiment
Change-Id: I45e2efe22c8e2f23e3305d00906bc08229a85c17
2015-10-07 16:54:10 +01:00
Debargha Mukherjee
9fc51184b7 Merge "Speed up of wedge search" into nextgen 2015-10-06 00:33:50 +00:00
Debargha Mukherjee
597204298a Speed up of wedge search
Speeds up wedge search by pre-calculating single predictions
before computing the wedge combination.

About 20% speed up achieved.

Change-Id: I72f76568559d1899c8ac0afaa133d433ba388e6d
2015-10-04 23:43:25 -07:00
Debargha Mukherjee
ff6a66a0b2 Merge "tx64 prob tweaks." into nextgen 2015-10-03 17:59:54 +00:00
Debargha Mukherjee
b80a04bd63 tx64 prob tweaks.
A little improvement in results on hevchd

Change-Id: Ib71a57c4bec34bf688e1d53dbf73eb4525e7805b
2015-10-02 11:44:02 -07:00
Debargha Mukherjee
ff9aa146cb Reimplementatio of dst1 for speed
Encoder with --enable-ext-tx --enable-dst1 is now 4 times faster.

Change-Id: Ia750ad3516698ce94da4ceb566b1c51539537a95
2015-10-02 11:06:55 -07:00
Debargha Mukherjee
4f371ac4f2 Merge "64x64 idct fix." into nextgen 2015-09-25 23:36:42 +00:00
Zoe Liu
90dede3f5b Merge "Merged LAST2 and LAST3 to one experiment MULTI_REF" into nextgen 2015-09-25 16:47:28 +00:00
Debargha Mukherjee
5a25d567d7 64x64 idct fix.
Change-Id: If0e0cd7cbe71e9586657f5e8ffa87dcdebc686ba
2015-09-25 05:54:23 -07:00
Debargha Mukherjee
1e2cbf515e Merge "tx64x64 experiment fix for high-bitdepth" into nextgen 2015-09-25 03:22:54 +00:00
Zoe Liu
e8e58402f0 Merged LAST2 and LAST3 to one experiment MULTI_REF
Change-Id: I220be17af317520dccb62fa6b19da5c7ce10652d
2015-09-24 17:08:15 -07:00
Zoe Liu
a9900eb2b1 Merge "Added another reference frame LAST4_FRAME" into nextgen 2015-09-24 15:58:22 +00:00
Debargha Mukherjee
cdcebfba29 tx64x64 experiment fix for high-bitdepth
Change-Id: Ia8d769b43bad0f9ad0684ecf6925e580339c7397
2015-09-24 05:45:03 -07:00
Zoe Liu
829dbf7a79 Added another reference frame LAST4_FRAME
Under the experiment of CONFIG_LAST4_REF. On derflr testset, using
highbitdepth (HBD), in average PSNR,

(1) LAST2+LAST3+LAST4 obtained +0.361% against LAST2+LAST3;
(2) LAST2+LAST3+LAST4 obtained +1.567% against baesline.

Change-Id: Ic8b14272de6a569df2b54418fa72b505e1ed3aad
2015-09-23 17:10:44 -07:00
hui su
71d0af90f8 Adjust rd calculation in choose_tx_size_from_rd
Change-Id: I3649f28196a87663b116b9fe6446b1fbe6eeab4a
2015-09-23 14:37:45 -07:00
Zoe Liu
411c490bc3 Improved LAST3's single ref prob context design a little
On derflr testset, using 12-bit HightBitDepth mode, this CL obtained a
small gain of +0.031% by turning on LAST2+LAST3.

Change-Id: Ib6c9d595e56269634bf29d684eabcd806fc08cc9
2015-09-21 15:03:43 -07:00
Zoe Liu
9144967ca8 Fixed a couple of bugs for LAST3
Change-Id: I63126a844c255df4a447aac7f630ba54cc7d7d7a
2015-09-21 11:50:35 -07:00
Zoe Liu
c0889b9a8c Added a 3rd reference frame LAST3_FRAME
Under experiment CONFIG_LAST3_REF, which can only be turned on when
the experiment of CONFIG_MULTI_REF is on, i.e. LAST3_FRAME can only
be used when LAST2_FRAME is used. CONFIG_LAST3_REF would most likely
be combined with CONFIG_MULTI_REF once the performance improvement
is further confirmed.

On the testset of derflr, using Average PSNR metrics, with HighBitDepth
(HBD) on:

(1) LAST2 HBD obtained +0.579% against base HBD;
(2) LAST2 + LAST3 HBD obtained +0.591% against LAST2 HBD;
(3) LAST2 + LAST3 HBD obtained +1.173% against base HBD.

Change-Id: I1aa2b2e2d2c9834e5f8e61bf2d8818c7b1516669
2015-09-18 15:25:46 -07:00
Debargha Mukherjee
b6d5b0838b ext-tx extension to intra blocks
derflr: improves to 1.692%

Change-Id: Idf583216b40ed02526b9b39031eaf2fb72fed11d
2015-09-17 14:21:24 -07:00
Debargha Mukherjee
c104998b61 Merge "Redo DST1 in the ext-tx experiment" into nextgen 2015-09-16 18:38:03 +00:00
Debargha Mukherjee
4dbaf9a5ab Redo DST1 in the ext-tx experiment
Moved from nextgenv2 branch to test with other experiments.

derflr: +1.629%

Change-Id: Ie7c720053ed8b628177679c4351bb31b54716a71
2015-09-16 09:46:13 -07:00
Zoe Liu
9b0635fc75 Fixed a bug on the number of MAX_MODES in baseline
All the numbers of MAX_MODES have been changed assuming
CONFIG_MULTI_REF. Now correct numbers have been put in for both with and
without the enabling of the experiment MULTI_REF.

Change-Id: I70ffe2f1a89fa572d612dd3d311d3af19fe3a632
2015-09-15 14:12:12 -07:00
Zoe Liu
f48a159430 Added more LAST2 modes for INTERINTRA
Turning on all the other experiments, compared the RD performance
between with and without the use of LAST2_FRAME, on derflr testset,
on Average PSNR:

8-bit: +0.653% (All positive except one,
max: mobile_cif: 2.019%; min: paris_cif: -0.081%)
12-bit HBD: +0.735% (All positive,
max: bridge_far_cif: 2.416%; min: bowing_cif: 0.132%)

Change-Id: Ia0a375667e228c8ba3d2e223abff608206f2f545
2015-09-15 11:57:18 -07:00
Zoe Liu
ec8864a8bf Added MACRO for reference frame encoding
This CL introduces a few macros plus code cleaning on the encoding of
the reference frames. Coding performance remains unchanged.

For the encoding of either the compound reference or the single reference
case, since each bit has different contexts, the tree structure may not
be applied to treat the combined bits as one symbol. It is possible we may
explore the sharing of the same context for all the bits to introduce
the use of tree structure for the next step.

Change-Id: I6916ae53c66be1a0b23e6273811c0139515484df
2015-09-11 14:57:31 -07:00
Zoe Liu
897192be43 Added one more reference frame LAST2_FRAME
Under the experiment CONFIG_MULTI_REF. Current version shows
LAST2 vs base in nextgen on the testset of derflr:

(1) 8-bit: Average PSNR +0.53%
(worst: students_cif: -0.247%; best: mobile_cif: 1.902%)
(2) 12-bit HBD: Average PSNR +0.63%
(worst: pamphlet_cif: -0.213%, best: mobile_cif: 2.101%)

More tuning on the reference frame context design and default
probs are being conducted. This version does not guarantee to
work with other experiments in nextgen. A separate CL will address
the working with all other experiments.

Change-Id: I7f40d2522517afc26ca389c995bad56989587f65
2015-09-09 14:27:05 -07:00
Shunyao Li
2de18d1fd2 Super resolution mode (+CONFIG_SR_MODE)
CONFIG_SR_MODE=1, enable SR mode
USE_POST_F=1, enable SR post filter
SR_USE_MULTI_F=1, enable SR post filter family
Not compatible with other experiments yet

Change-Id: I116f1d898cc2ff7dd114d7379664304907afe0ec
2015-08-31 15:29:39 -07:00
Shunyao Li
c7d886d96a Add transform size rate for intra skip mode in rdopt
Change-Id: I81fedd99cd39c12b66b93b786cb43234c867b84b
2015-08-31 11:28:27 -07:00
Debargha Mukherjee
9c685602d0 Make tests work with new configurations
Disables some test vector tests when Vp8/Vp9 decoders are disabled
in configuration. Also moves some macros to the vpx level in
line with recent refactoring on the master branch.

Change-Id: Iaac8008992110398ae096c36b9726f723164c207
2015-08-27 14:05:59 -07:00
Debargha Mukherjee
4525961d80 Some tweaks to probabilities for ext-tx with dst1
derflr: up to 1.429% from a little less than 1.3% when
--enable-dst1 is also enabled with --enable-ext-tx.

Change-Id: I301229f2239b18acb96accc4fc44b64fa6927ace
2015-08-12 14:31:31 -07:00
hui su
d5eaca7fee code cleanup in encode_block_intra
Change-Id: I376b7e9b243178d79141a96e0aeafcbc15758e97
2015-07-30 15:28:51 -07:00
Cheng Chen
cc4d523d9f Resolve bug of DST1 in ext_tx experiment.
Change-Id: I828569e3596f9b9e8487aec7c4056e66cf1fc1f2
2015-07-28 10:58:14 -07:00
Debargha Mukherjee
23690fc5d1 Adds support for DST1 transforms for inter blocks
Adds an additional transform in the ext_tx experiment that
is a 2d DST1-DST1 combination.

To enable use --enable-ext-tx --enable-dst1.

This needs to be later extended to combine DST1 with DCT
or ADST.

Change-Id: I6d29f1b778ef8294bcfb6a512a78fc5eda20723b
2015-07-24 16:23:09 -07:00
Shunyao Li
188087202c Speed up of supertx
Limited the prediction extension to 8 pixels at each edge
Fixed a bug in the combination of wedge prediction and supertx

~10% speed up in decoder
derflr:     -0.004
derflr+hbd: +0.002
hevcmr:     +0.015

Change-Id: I777518896894a612c9704d3de0e7902bf498b0ea
2015-07-24 11:19:19 -07:00
Debargha Mukherjee
4b57a8b356 Add extended transforms for 32x32 and 64x64
Framework for alternate transforms for inter 32x32 and larger based
on dwt-dct hybrid is implemented.
Further experiments are to be condcuted with different
variations of hybrid dct/dwt or plain dwt, as well as super-resolution
mode.

Change-Id: I9a2bf49ba317e7668002cf1499211d7da6fa14ad
2015-07-23 18:01:22 -07:00
Yunqing Wang
7959dd012c Nextgen branch cleanup: remove elevate_newmv_thresh feature
Code cleanup.

Change-Id: Idf00d5359e5f3d943ee39b4a00f8d40325c0f8b3
2015-07-14 14:28:56 -07:00
Yunqing Wang
527f88316c Nextgen branch cleanup: remove real-time speed features
Removed inter_mode_mask and max_intra_bsize.

Change-Id: I835d31f95af64a524b2fdb685d1d09a6b0ad5c9f
2015-07-14 14:26:17 -07:00
Yunqing Wang
6c2035744a Merge "Nextgen branch cleanup: add back some SVC functions" into nextgen 2015-07-08 23:26:35 +00:00
Yunqing Wang
da013eed3f Nextgen branch cleanup: add back some SVC functions
Several SVC functions were added back to ensure Borg test build.

Change-Id: I2cff676407fa74e2255606094ff12bd840287b6d
2015-07-08 14:13:57 -07:00
Zoe Liu
08effeaad5 A small code cleanup for the encoder workflow.
Change-Id: I543a69ad5a34cd9a0671b57131cafc541d595d9a
2015-07-08 12:12:47 -07:00
Alex Converse
7932eb014e Merge "intrabc: Allow odd pel displacement for non-444" into nextgen 2015-07-08 04:06:24 +00:00
Shunyao Li
e8885d4a50 Merge "Optimize bilateral filter to improve speed" into nextgen 2015-07-07 20:17:13 +00:00
Yunqing Wang
ca42973ea2 Nextgen branch cleanup: remove svc code
Spatial/temporal svc code was removed.

Change-Id: Ie25c7a58ee5feb662d4de526406d8cd834d19977
2015-07-06 21:19:05 -07:00
Yunqing Wang
020293588d Nextgen branch cleanup: remove unused functions
Removed unused real-time functions.

Change-Id: I0cbcee67fb8f495f87c6330e04ed6d56ed8e2625
2015-07-06 12:07:33 -07:00
Yunqing Wang
cc6dc0b7d9 Nextgen branch cleanup: remove nonrd code
Code cleanup.

Change-Id: I4d8d7fa2fc61a58b819c9a18bf25cda53e3fd88c
2015-07-06 10:03:23 -07:00
Alex Converse
5241acf6e2 intrabc: Allow odd pel displacement for non-444
intrabc:
screen_content: -0.618 derflr: +0.015

intrabc+tx_skip+palette:
screen_content: -0.124 derflr: -0.048

Change-Id: Iabea4be19dce2f6fdab8f639e585a424c90c81b4
2015-06-30 10:11:46 -07:00
Shunyao Li
dac589d6d4 Optimize bilateral filter to improve speed
Optimization of bilateral filter:
1) Pre-calculate the bilateral filters at all the
levels at the initialization.
2) Convert 1D matrix to 2D matrix, avoid too many
multiplications in the bilateral filter loop.
3) Fix a bug in "loop_bilateral_filter_highbd".
The right-shifted range index can be larger than 255.

Change-Id: I42f6177e896706948e2403bd9edce46e3eb5cbf8
2015-06-29 14:48:59 -07:00
Alex Converse
a4f4ed60cf Merge "intrabc: displacement vector prediction" into nextgen 2015-06-25 20:55:21 +00:00
Alex Converse
93cd5cf3f4 intrabc: displacement vector prediction
Predict displacement vector with the same logic as NEARESTMV. If no
neighbors are available fall back to the current one block left or up
prediction.

vp9+intrabc+tx_skip+palette: -0.489
vp9+intrabc: -0.771

Change-Id: If67d08b54f1a3b847cf7ab8c7b800c55baa1a86b
2015-06-24 10:02:50 -07:00
Peter de Rivaz
fbfeb03f02 Fix for copy-mode with segmentation
Change-Id: Icfc97826e494b856aa80fbefe4811dff99f3a0b4
2015-06-24 09:25:23 +01:00
Debargha Mukherjee
567e4c754f Merge "Removing some compiler warnings" into nextgen 2015-06-23 19:13:09 +00:00
Peter de Rivaz
269f6e2cb1 Added support for extended partitions with copy_mode
Change-Id: I815374bd89e3faf2bac1b4155dbbe7366f0a1d29
2015-06-23 11:09:34 -07:00
hui su
ffcd76e328 Merge "Fix a bug induced by qctx-tprobs experiment" into nextgen 2015-06-23 17:54:35 +00:00
hui su
2f1325049a Merge "Bug fix in tx-skip" into nextgen 2015-06-23 17:42:41 +00:00
hui su
591b03a915 Fix a bug induced by qctx-tprobs experiment
Change-Id: I8d31b8e6037464c36b514fddccd5d7edee024a47
2015-06-23 10:20:27 -07:00
Debargha Mukherjee
3a18fc6784 Removing some compiler warnings
Change-Id: I572594a9c00ba5a2b8000d3b4c86ec5757aa586c
2015-06-22 15:26:25 -07:00
Peter de Rivaz
bad321d9e4 Added palette support to extended partitions
Change-Id: Ide11bd3fcc9fb26b27ae39cdf216a2c32b853348
2015-06-22 20:34:26 +01:00
Julia Robson
84d0da63d0 Palette high bit depth functionality
Changes to allow high bit depth and palette to be enabled at the
same time by using a 16 bit (instead of 8bit) palette when high
bit depth is enabled and modifying related functions accordingly.

Change-Id: I97d30b4d9338d3a51db02c94bc568eba60a8905d
2015-06-22 18:53:34 +01:00
hui su
c96afa256f Merge "Add q-index as context for initial token probs" into nextgen 2015-06-22 17:44:26 +00:00
Debargha Mukherjee
1c96a0bb09 Merge "Fix for supertx decode with segments" into nextgen 2015-06-22 17:28:31 +00:00
Debargha Mukherjee
adc9ed5a87 Merge "Fix supertx HORZ and VERT partitioning." into nextgen 2015-06-22 17:11:39 +00:00
hui su
315351e9de Bug fix in tx-skip
This patch avoids using tx_size larger than 16x16 in lossless mode.
Big block quantization (32x32 or larger) is not lossless.

Change-Id: I69cd84d4f3fd06d641048d6096da1bfde18ad24e
2015-06-22 09:54:42 -07:00
hui su
5963fd35dd Add q-index as context for initial token probs
There are 4 entropy tables to select for initial entropy table,
depending on the frame base q-index. The entropy tables are
trained with derf, yt, and stdhd sets. About 0.2% gain on
the following test sets:

derflr       0.227%
yt           0.277%
stdhd        0.233%
hevclr       0.221%
hevcmr       0.155%
hevchr       0.182%

Change-Id: I3fde846c47fc020e80c814897690b4cda1da569c

Change-Id: I460408372586c823974f945ed9fd8dcb0360fbaf
2015-06-21 13:09:57 -07:00
Peter de Rivaz
3b09cc1945 Fix for supertx decode with segments
Change-Id: I5e07b0b9fafd2578ecfacf20fb70b07fd6977d98
2015-06-18 18:16:07 +00:00
Peter de Rivaz
bdbae2520a Fix supertx HORZ and VERT partitioning.
Change-Id: I9a44d70dc2514baf679025335badc2744eeb4b88
2015-06-17 22:02:58 -07:00
Peter de Rivaz
100fff09b6 Added ext_partitions to supertx
Change-Id: I0e2a0253e5a8dcdb5b765836a3301299409e9d0a
2015-06-17 20:28:32 +00:00
Peter de Rivaz
3a3fb8d100 Fix seg fault in count_segs_sb with ext_partitions
Change-Id: I609f429006e7d2b849fe0a509f5d9f5123ecf0ec
2015-06-17 08:25:58 +00:00
Pieter Kapsenberg
d0e9499f94 Fixing skip simplifcation with SuperTX experiment
Combination of MISC_ENTROPY and SUPERTX resulted in compilation error

Change-Id: Ibcf28216712d93f00f38f3786fce8fcdca3f835e
2015-06-15 16:50:10 -07:00
hui su
0809dc09cb Merge "Fix tx-skip warnings on Windows" into nextgen 2015-06-15 19:41:24 +00:00
Alex Converse
a046bece1e Merge changes I9d80152b,I4e13da4b into nextgen
* changes:
  intrabc: Add a frame level flag
  intrabc: Remove NEWDV from the intra mode tree.
2015-06-15 16:57:05 +00:00
Debargha Mukherjee
ec8b957efe Merge "Added tests for high bit depth quantize functions" into nextgen 2015-06-12 20:59:16 +00:00
Debargha Mukherjee
dcb3d7f398 Bug fix in highbd psnr computation with postproc
Change-Id: I6944a5fc38d6a89e1bb739938c6ecae7ec731b8d
2015-06-12 11:57:40 -07:00
Peter de Rivaz
3bf31c4c98 Allow extended partition support to encode
Change-Id: I75246e2ee35a1b7c1ad46669c464e582e3a9961c
2015-06-11 11:52:45 -07:00
Debargha Mukherjee
e0617385d6 Merge "Add extended partition support to decode" into nextgen 2015-06-11 18:47:29 +00:00
hui su
c80386a5ab Fix tx-skip warnings on Windows
Change-Id: I2a515abe20e6989de233fc8ae2c31d8ee462add2
2015-06-11 11:20:16 -07:00
hui su
0c8bcb43a0 Merge "Fix palette build on windows" into nextgen 2015-06-11 17:56:26 +00:00
hui su
5d132c799e Fix palette build on windows
Change-Id: I2a90e235ab5bdf95eb83f684e46ef844553ba629
2015-06-11 10:44:05 -07:00
Peter de Rivaz
31d17053f3 Add extended partition support to decode
Change-Id: I65f7aed37d65dbba76999d2b9585129c48e70b11
2015-06-11 09:37:00 -07:00
Peter de Rivaz
999fabc183 Added extended partition experiment
Change-Id: Ife89c95f04212e9dceb4c4e663280a85b5718c13
2015-06-11 09:37:00 -07:00
Debargha Mukherjee
db90b74c1a Merge "Fix copy mode bug: searches made outside of the current tile" into nextgen 2015-06-11 16:30:23 +00:00
Jack Haughton
286983b8c6 Fix copy mode bug: searches made outside of the current tile
Change-Id: Ib3cf4bf4da0a575053493609956e133d1ce028a1
2015-06-11 09:23:32 +01:00
Debargha Mukherjee
ee5f9c7181 Merge "Fix to loopfilter tests" into nextgen 2015-06-11 05:30:50 +00:00
Debargha Mukherjee
278de7b73a Merge "Fix cost array overrun bug in search_bilateral_level()" into nextgen 2015-06-11 05:28:43 +00:00
Alex Converse
c3e884f5be intrabc: Add a frame level flag
For the combination of this and removing NEWDV from the tree:
derflr: -0.101 screen_content: +0.053

The bulk of the decline in screen content effecincy is from the liquify
clip. These should be recoverable by further entropy tweaks.

Change-Id: I9d80152b8492e60a0367c31797fb6932fb09bba9
2015-06-09 11:23:23 -07:00
Debargha Mukherjee
36eec6a9b1 Merge "Fix masked_variance overflow for non-highbitdepth" into nextgen 2015-06-09 17:07:13 +00:00
Jack Haughton
fa4b1ca714 Fix cost array overrun bug in search_bilateral_level()
Change-Id: I9b7b727cb45328040a82477a2ce8eb3d15feec77
2015-06-09 14:21:55 +01:00
Julia Robson
ece7479208 Fix to loopfilter tests
Ensuring the random numbers used by the loopfilter tests
are in a valid range

Change-Id: If8130145c413dbe7e29180046eca3e4f7d941706
2015-06-09 13:09:09 +01:00
Debargha Mukherjee
b433dd4443 Adds wavelet transforms + hybrid dct/dwt variants
The wavelets implemented are 2/6, 5/3 and 9/7 each with
a lifting based scheme for even block sizes. The 9/7
one is a double implementation currently.

This is to start experiments with:
1. Replacing large transforms (32x32 and 64x64) with wavelets
or wavelet-dct hybrids that can hopefully localize errors better
spatially. (Will also need alternate entropy coder)
2. Super-resolution modes where the higher sub-bands may be
selectively skipped from being conveyed, while a smart
reconstruction recovers the lost frequencies.

The current patch includes two types of 32x32 and 64x64
transforms: one where only wavelets are used, and another
where a single level wavelet decomposition is followed
by a lower resolution dct on the low-low band.

Change-Id: I2d6755c4e6c8ec9386a04633dacbe0de3b0043ec
2015-06-08 23:30:38 -07:00
Jack Haughton
2799fad98c Fix masked_variance overflow for non-highbitdepth
Change-Id: I668b034111ccc877c70cf65035a9c748fe00aeba
2015-06-08 12:09:48 -07:00
Debargha Mukherjee
5a69abc66b Merge "Windows build fix" into nextgen 2015-06-05 17:40:06 +00:00
Debargha Mukherjee
ad2cf9b444 Windows build fix
Change-Id: I663e0d61c4115a5297baeb25f39743e1eea95fbf
2015-06-05 10:24:24 -07:00
hui su
507857786d Fix lossless mode in tx-skip experiment
Change-Id: I205fa8614a9079ce7e6ca87d7b08fe3602bbd376
2015-06-04 15:13:37 -07:00
Julia Robson
33199783ea Added tests for high bit depth quantize functions
This was originally part of change-id:Idef18f90b111a0d0c9546543d3347e551908fd78
but the rest of that patch has previously been incorporated into nextgen
without these tests.

Change-Id: I6ac491ed1cfc153e0ed3cb999c76feac9d5e74e3
2015-06-04 16:00:39 +01:00
Debargha Mukherjee
b8a793458a Fix lossless mode with new_quant experiment
Change-Id: Ia0b00746e3f7aacf8d9488db3522ab72d9dc22fd
2015-06-04 02:45:54 -07:00
Alex Converse
1f537e3818 intrabc: Remove NEWDV from the intra mode tree.
Change-Id: I4e13da4bf70386f6f70ea733fb9adeb41682c735
2015-06-03 13:26:03 -07:00
Alex Converse
f35fb46c48 intrabc: Fix mismatch introduced by 85a7485.
Change-Id: I1ea51ebbd1e3cb60a13a30e3252253493c28baec
2015-06-03 13:07:49 -07:00
Alex Converse
783d18d22a Merge "intrabc: Include NEWDV in mode_2_counter" into nextgen 2015-06-03 16:09:36 +00:00
Debargha Mukherjee
d6ff3b3b22 Merge "Implied skip is 0 for intra blocks" into nextgen 2015-06-02 21:10:18 +00:00
Alex Converse
7944249b80 Merge "intrabc: Add odd-pel support for 444." into nextgen 2015-06-02 19:03:15 +00:00
Alex Converse
8cbed23cdf intrabc: Include NEWDV in mode_2_counter
This fixes a failure to decode as VP9 with frame level signalling
patched in and removed to implictly force it off.

This is primarily a correctness fix, but there were small coding gains.
0.074% smaller on derlf
0.180% smaller on screen_content

Change-Id: I4cc264bf4d9016201924be198a0c5b8374020fd9
2015-06-02 11:01:00 -07:00
Pieter Kapsenberg
ec1e91847c Implied skip is 0 for intra blocks
Skip flag is removed from the bitstream for all blocks coded in intra
mode. Very minor coding gain in derf and stdhd sets (0.048 and 0.1)

Change-Id: I79f03300f16d6fa84ce54405cafecab8a021cd7d
2015-06-01 18:27:34 -07:00
Jingning Han
b71176b477 Fix the upper limit of row/column tile index
If the decoder is configured to decode a tile indexed above the
upper limit, the internal codec will clip the index to the upper
limits.

Change-Id: Icbc1bb7b14069ac009e0a2042dd66a46d6f76679
2015-05-29 09:12:05 -07:00
Jingning Han
f5660af165 Allow vpxdec to produce target tile reconstruction
This commit allows the vpxdec to produce the target tile
reconstruction as its output. When the provided tile index is -1,
the entire corresponding row/column tiles will be reconstructed.
If the tile index is over the upper limit, the decoder will decode
left-most/bottom tile.

Change-Id: I4c18bdb32099f736f99b8842f7f177a32b3fee09
2015-05-28 23:20:24 -07:00
Jingning Han
89747d09cc Enable selective key frame tile decoding
This commit allows the decoder to decode selective tiles according
to decoder configuration settings. To decode a single tile out of
the provided key frame bit-stream (test_kf.webm), set compiler
configuration:

--enable-experimental --enable-row-tile --enable-key-frame-tile

use the command:

vpxdec -o test_dec.y4m test_kf.webm --tile-row=1 --tile-column=2

where the tile's row and column indexes are 1 and 2, respectively.

To decode all row tiles inside a provided column index, use:
--tile-row=-1 --tile-column=2

To decode all column tiles inside a provided row index, use:
--tile-row=2 --tile-column=-1

Change-Id: Ib73c266414dcee7eaab5d741b90d0058970dae56
2015-05-28 16:10:13 -07:00
Alex Converse
85a7485137 intrabc: Add odd-pel support for 444.
Odd pel still needs more testing on 4:2:0.

0.2% smaller on the PNG set. 4095 better, 1324 worse.

Change-Id: Idf2f108a96462c7696e63d533605e4a926a8b203
2015-05-28 15:44:15 -07:00
Debargha Mukherjee
fe79548bc8 Merge "Intrabc high bit depth functionality" into nextgen 2015-05-28 22:40:38 +00:00
Debargha Mukherjee
8f82bc172c Merge "Turn on global rotation-zoom warping prediction" into nextgen 2015-05-28 22:07:29 +00:00
Julia Robson
153d824207 Intrabc high bit depth functionality
Fixing compile errors when intrabc and vp9_highbitdepth are both enabled.
Error arose because intrabc uses vp9_setup_scale_factors_for_frame()
which takes an additional argument (use_highbitdepth) when
vp9_highbitdepth is enabled.

Change-Id: I6a15b09dcea0d35525f4c25efb6848804ae5cfab
2015-05-28 12:05:37 +01:00
Alex Converse
f80879d452 Merge "palette: don't repeat calc_dist for j = 0" into nextgen 2015-05-28 01:55:05 +00:00
Jingning Han
30fb5831da Merge "Fix a memory overflow issue in large scale tile use case" into nextgen 2015-05-28 01:53:56 +00:00
Jingning Han
d8d30cfb9b Merge "Configure selective tile decoding" into nextgen 2015-05-28 01:53:38 +00:00
Alex Converse
3df4a571a4 palette: don't repeat calc_dist for j = 0
Change-Id: I043c3b9696dbfa76436763ef871600cb54ade212
2015-05-27 11:45:00 -07:00
Debargha Mukherjee
5930a90cc9 Turn on global rotation-zoom warping prediction
With this patch, the ZEROMV mode is overloaded to represent
a single global dominant motion using one of three models:
1. True zero translation motion (as before)
2. A translation motion different from 0
3. A Rotation-zoom affine model where the predictor is warped
The actual model used is indicated at the frame level for
each reference frame.
A metric that computes the ratio of the error with a global
non-zero model to the error for zero motion, is used to
determine on the encoder side whether to use one of the two
non-zero models or not.

Change-Id: I1f3d235b8860e543191237024a89041ff3aad689
2015-05-27 11:33:33 -07:00
Jingning Han
ceda343d0b Fix a memory overflow issue in large scale tile use case
Increase the tok_count array size defined in VP9_COMP to avoid
out of boundary memory access.

Change-Id: Ib277c1102cb5f8355b1d69991532a94e24a2242e
2015-05-27 11:18:06 -07:00
hui su
c4f04808eb Merge "Fixed a bug in palette expt for 444 video format" into nextgen 2015-05-27 18:14:16 +00:00
hui su
f3f2645f24 Fixed a bug in palette expt for 444 video format
The bug was that palette color map was not correctly recorded.

Change-Id: I237494d1d6449c53c5d24eed8c25dcf2f8d21e66
2015-05-27 10:53:17 -07:00
Jingning Han
3b6901730f Merge "Make the tile coding syntax support large scale tile decoding" into nextgen 2015-05-27 16:40:49 +00:00
Jingning Han
f00bf10de0 Configure selective tile decoding
Add decoder control to extract single tile from key frame.

Change-Id: Id018bf267d748bfd96a6261055de4194f632190c
2015-05-27 09:22:34 -07:00
Alex Converse
57fefc1d73 Merge "intrabc: Fix probs of illegal modes." into nextgen 2015-05-27 01:03:02 +00:00
Jingning Han
f7a39d7f08 Make the tile coding syntax support large scale tile decoding
This commit makes the bit-stream syntax support fast selective tile
decoding in a large scale tile array. It reduces the computational
complexity of computing the target tile offset in the bit-stream
from quadratic to linear scale, while maintaining relatively small
stack space requirement (in the order of 1024 bytes instead of 1M
bytes). The overhead cost due to tile separation remains identical.

Change-Id: Id60c6915733d33a627f49e167c57d2534e70aa96
2015-05-26 12:54:00 -07:00
Alex Converse
1748a59f83 intrabc: Fix probs of illegal modes.
ibc: derflr -0.069 screen_content -0.085
ibc+tx+pal: derflr +0.017 screen_content -0.029

Change-Id: I79c0ca0a5c38c53afd209286dbcd78873e070098
2015-05-26 12:51:53 -07:00
Jingning Han
7099fd12bd Fix assertion conditions for tile coding
Allow up to 1024 row/col tiles instead of 4 for row tile and 64 for
column tile.

Change-Id: I1702254e241401821f3aaab1645f6df6dbc48b8d
2015-05-26 16:38:15 +00:00
Debargha Mukherjee
a14e3616b3 Merge "Loop_postfilter high bit depth functionality" into nextgen 2015-05-25 08:04:04 +00:00
Zoe Liu
98f6f54d93 Merge "Refined the mv ref candidate selection" into nextgen 2015-05-23 00:00:15 +00:00
Zoe Liu
e84c1d24bc Refined the mv ref candidate selection
Now this is an on-going work on the re-work on the motion vector
references for all Inter coding modes. Currently implementation on
sub8x8 and BLOCK_8X8 is done. More work will be added along the way.

Essetial ideas include:

(1) Added new nearestmv algorithm through adaptive median search, out of
the four nearest neighbors: TOP, LEFT, TOPLEFT, and TOPRIGHT;

(2) Added new sheme for sub8x8 to obtain the mv ref candidates,
specially, mv ref candidates are obtained depending on the sub8x8 mode
of the current block as well as the sub8x8 mode of the neighboring
block;

(3) Added top right corner mv ref candidate whenever it is available;
The adding of the top right mv ref has showed potential in helping such
video clips as bridge_far_cif.

Change-Id: I573c04cd346ed7010f4ad87a6eaa6bab6e2caf9c
2015-05-22 16:06:45 -07:00
Julia Robson
650e12dd63 Loop_postfilter high bit depth functionality
Adding a high bit depth version of the function loop_bilateral_filter()
and ensuring the appropriate version of this function is called when
vp9_highbitdepth is enabled.

Change-Id: I7a78029c733a9a79b3b2f39af0de0824239ad5a3
2015-05-22 10:34:44 -07:00
hui su
8806e25215 Code cleanup in tx-skip expt
No effect on performance

Change-Id: I493da0d4d8fb3a7d95f07574b800cb6c85705229
2015-05-22 10:20:58 -07:00
Pieter Kapsenberg
70ddd92d9a Removing skip inferrence with all 0 TX
If a non-skipped block has all transform blocks with only 0 data, then
decoder infers skip flag. This affects the loopfilter. No real encoder
would do this though, so it is pointless. Also, it causes headaches in
HW implmentations as the loop filter cannot proceed until all TX blocks
in the block have been checked. There could be up to 768 of them in
64x64 4:4:4 with 4x4 transform.

Change-Id: I45a021d1f27ca7feefed2242605777e70ce7cabd
2015-05-21 23:03:16 +00:00
Jingning Han
c238d6cd72 Merge "Enable arbitrary tile size support" into nextgen 2015-05-21 22:56:59 +00:00
Alex Converse
feb3a14e44 Merge "intrabc: Cleanup." into nextgen 2015-05-21 22:27:56 +00:00
Alex Converse
afea20e94c Merge "intrabc: Fix costing for tx_skip." into nextgen 2015-05-21 22:27:47 +00:00
Alex Converse
57f6a6d225 Merge "intrabc: Don't double account for skip" into nextgen 2015-05-21 22:27:40 +00:00
Jingning Han
bae6229884 Merge "Make internal codec support arbitrary tile size" into nextgen 2015-05-21 22:24:28 +00:00
Jingning Han
73ca749ddb Merge "Refactor internal tile_info variables to support 1024 tiles" into nextgen 2015-05-21 22:24:05 +00:00
Jingning Han
ad5ede6e36 Merge "Support up to 64 row tile coding" into nextgen 2015-05-21 22:23:42 +00:00
Jingning Han
c604b9a86c Enable arbitrary tile size support
This commit allows the encoder to process tile coding per 64x64
block. The supported upper limit of tile resolution is the minimum
of frame size and 4096 in each dimension. To turn on, set
--experiment --row-tile
and compile.

It overwrite the old --tile-columns and --tile-rows configurations.
These two parameters now tell the encoder the width and height of
tile in the unit of 64x64 block. For example,
--tile-columns=1 --tile-rows=1
will make a tile contains a single 64x64 block.

Change-Id: Id515749a05cfeb9e9d008291b76bdfb720de0948
2015-05-21 14:57:05 -07:00
Jingning Han
a0d950345b Merge "Support up to 1024 row/column tiles in bit-stream syntax" into nextgen 2015-05-21 19:50:12 +00:00
Jingning Han
a3a3fee09f Merge "Set row and col tile number upper limit as 1024" into nextgen 2015-05-21 19:49:59 +00:00
Alex Converse
1110f09385 intrabc: Cleanup.
Change-Id: I71ad705e579a62563af8282846dbda522c3c971e
2015-05-21 12:00:05 -07:00
Alex Converse
32bec3f0ec intrabc: Fix costing for tx_skip.
ibc+tx+pal: derflr: -0.033 screen_content: -0.145

Change-Id: I446ef1c890eb9afa12454e53b24dc0ef6a80b02b
2015-05-21 12:00:05 -07:00
Alex Converse
5e6ab9935e intrabc: Don't double account for skip
ibc: derflr +0.007 screen_content -0.025
ibc+tx+pal: derflr -0.208 screen_content +0.003

Change-Id: I5e46e84fd545f3810ae7a5d13dc3618e1b077f76
2015-05-21 12:00:05 -07:00
Jingning Han
98339250c1 Make internal codec support arbitrary tile size
This commit allows the internal codec handle arbitrary tile size
in the unit of 64x64 pixel blocks.

Change-Id: I3ad24de392064645bebab887c94e1db957794916
2015-05-21 09:20:31 -07:00
Debargha Mukherjee
d43544137b Rename NEAR_FORNEW to NEW2
Change-Id: I2928b0d28dcbf9c6b705d3ebf20550aeec9b99b3
2015-05-20 17:31:20 -07:00
Jingning Han
225097a7ed Refactor internal tile_info variables to support 1024 tiles
Move the 2D tile info arrays as global variables. This resolves
the local function stack overflow issue due to excessively large
tile info variables. This allows the internal operation to support
up to 1024 row and column tiles.

Change-Id: I6644cc929e5d3a778a5c03a712ebfc0b8729f576
2015-05-20 10:19:01 -07:00
Jingning Han
8e3099aa2b Support up to 64 row tile coding
This commit allows the codec to use up to row tiles (optionally
in combination with up to 64 column tiles per row tile). The
minimum tile size is set to be 256x256 pixel block.

Change-Id: I811ca93f0c5eba41e190f6c7c0f064d1083f530f
2015-05-19 17:27:05 -07:00
Jingning Han
97adfb32bd Support up to 1024 row/column tiles in bit-stream syntax
Add syntax support to allow up to 1024 row/column tiles
respectively.

Change-Id: I84278589364b658d6c4dd05f0771795f732ad68f
2015-05-19 17:20:36 -07:00
Jingning Han
46afda0908 Set row and col tile number upper limit as 1024
Increase the supported row and col tile numbers from 4 and 64,
respectively to 1024 both.

Change-Id: Ic07435ff6783940a466a549a69a11ab3faf3247a
2015-05-19 17:20:36 -07:00
Jingning Han
f5445e124c Rename variables in tile info decoding
The max and min tile number reference should be used to support
both row and column tiles. This commit renames the previous col
prefix to avoid confusion.

Change-Id: I487bea43701af946b79023597a9a9a0516480380
2015-05-19 17:20:36 -07:00
Zoe Liu
2bbddcf0a5 Removed the unused modes newmvref and compound-modes
Change-Id: Ia51913d48a09a7ea7502e8c49ee0159492e58b96
2015-05-19 16:20:37 -07:00
Zoe Liu
6437c3cb6d Combined two experiments of NEWMVREF and COMPOUND_MODES to NEW_INTER
Runborgs results on derflr show consistent results between NEW_INTER
and the previous combination of NEWMVREF and COMPOUND_MODES.

Change-Id: Ieba239c4faa7f93bc5c05ad656a7a3b818b4fbfc
2015-05-19 14:04:22 -07:00
Julia Robson
0a1c529b26 Merge "Fix mismatch in handling of 8x4/4x8 blocks with supertx" into nextgen 2015-05-19 16:06:26 +00:00
Pieter Kapsenberg
418956690e Removing unnecessary syntax remaping for mc filter type
Change-Id: Iba067eb2bcf519dc5776976c3ab0a694ff3feb12
2015-05-18 13:56:56 -07:00
Julia Robson
8718262437 Fix mismatch in handling of 8x4/4x8 blocks with supertx
Test VP9/EndToEndTestLarge.EndtoEndPSNRTest/1 (422 stream) failed when
supertx enabled. This was because 4x8 and 8x4 blocks were not being
split into 4x4s during tokenization in the encoder. This patch
uses vp9_foreach_transformed_block() to fix this.

Change-Id: I1f1cb27474eb9e04347067f5c4aff1942bbea8d9
2015-05-18 11:59:51 +01:00
hui su
10834f4373 Merge "Fix a bug in tx-skip experiment" into nextgen 2015-05-18 04:31:27 +00:00
Debargha Mukherjee
e82fffd416 Row tile fix
Fixes mismatch with intrabc experiment.

Change-Id: I1d83a8aa5584fb35396351f7fae7f9365598d00f
2015-05-15 08:01:21 -07:00
Debargha Mukherjee
520e861e03 Merge "Global motion enhancements" into nextgen 2015-05-15 05:48:26 +00:00
Debargha Mukherjee
fb093a337f Global motion enhancements
Adds warping functions. Also includes some refactoring.

Change-Id: I909830650f29046edf108ddaddceb1a5e7c6c61c
2015-05-14 16:33:01 -07:00
Zoe Liu
987d44f5d0 Added a new experiment "NEW_INTER"
Down the road this experiment will combine and replace both NEWMVREF
and COMPOUND_MODES.

Change-Id: I383291f94f3e80e5cbbabab45e31c4b48669f2e5
2015-05-14 14:39:45 -07:00
hui su
4fcb86251d Fix a bug in tx-skip experiment
Fix potential mismatch.

Change-Id: I51f9241c73d70c0c38fd7e2c15f4381350b60388
2015-05-12 09:38:14 -07:00
Julia Robson
b4d8b235dd Changed tokenize to correct tx_size for 440 input
Change-Id: I41995cfa03038ec45b5f0d6c68195cfa36d58ec8
2015-05-12 09:34:04 -07:00
Zoe Liu
60b71edf2b Merge "Removed unused macro for INTERINTRA" into nextgen 2015-05-12 00:25:01 +00:00
Zoe Liu
d29384192c Removed unused macro for INTERINTRA
Change-Id: Ibdf4da969c17d4b1dff14a777ccb405763a62b75
2015-05-11 13:01:25 -07:00
Jingning Han
7a2f9bbda4 Add row tile coding support in bit-stream
Fix the row tile boundary detection issues. This allows to use
more resources for parallel encoding/decoding when avaiable.

Change-Id: Ifda9f66d1d7c2567dd4e0a572a99a83f179b55f9
2015-05-11 12:30:03 -07:00
Zoe Liu
9e0466d0fd Cleaned mv search code and added a few fixes on the experiments
Besides code cleaning, this patch contains 3 fixes:
(1) Fixed the COMPOUND_MODES for the NEW_NEWMV mode;
(2) Fixed the joint search when the NEAR_FORNEWMV mode (in NEWMVREF)
is being evaluated;
(3) Fixed the WEDGE_PARTITION when the NEAR_FORNEWMV mode (in NEWMVREF)
is being evaluated.
(4) Adjusted the entropy probability value for NEAR_FORNEW mode.

On derflr turning on all 14 experiments (except for global-motion), the
average gain w.r.t. PSNR is +0.07%:
Maximum on bridge_far_cif: +1.02%
Minimum on hallmonitor_cif: -0.16%

Change-Id: I4c9c6ee24a981af7e655a629580641d9f9745f91
2015-05-10 23:38:44 -07:00
hui su
bada9f0b87 Merge "Optimize entropy coding of non-transform tokens" into nextgen 2015-05-08 18:18:49 +00:00
Alex Converse
d28a10870f Merge "Try non-traditional intra prediction even when spatial isn't good." into nextgen 2015-05-08 01:27:13 +00:00
hui su
00c793ee5f Optimize entropy coding of non-transform tokens
Use separate token probabilities and counters for non-transform
blocks (pixel domain) . Initial probabilities are trained with screen_content
clips. On screen_content, it improves coding performance by about
2% (from +16.4% to +18.45%).

The initial probabilities are not optimized for natural videos. So it should
not be used for natural videos. Set FOR_SCREEN_CONTENT as 0/1 to specify
whether or not to enable this patch.

Change-Id: Ifa361c94bb62aa4b783cbfa50de08c3fecae0984
2015-05-07 07:58:19 -07:00
Debargha Mukherjee
e6889b28e9 Merge "Fix a bug in copy_mode experiment" into nextgen 2015-05-07 05:10:01 +00:00
Debargha Mukherjee
5e7bc81128 Merge "Global motion continued" into nextgen 2015-05-07 05:09:34 +00:00
Yaowu Xu
d1f04fb5b2 Fix a bug in copy_mode experiment
Change-Id: I1cf7d51ba99e5b6f5cf7e0d1a5d86ce4f19046e5
2015-05-06 17:03:32 -07:00
Peter de Rivaz
d6153aa447 Added highbitdepth sse2 acceleration for quantize and block error
This is a partial cherry-pick of db7192e

Change-Id: Idef18f90b111a0d0c9546543d3347e551908fd78
2015-05-06 15:14:01 -07:00
Debargha Mukherjee
caae13d54f Global motion continued
Implements a first version of global motion where the
existing ZEROMV mode is converted to a translation only
global motion mode.
A lot of the code for supporting a rotation-zoom affine
model is also incorporated.
WIP.

Change-Id: Ia1288a8dfe82f89484d4e291780288388e56d91b
2015-05-06 14:59:38 -07:00
Alex Converse
47cd96fb49 Try non-traditional intra prediction even when spatial isn't good.
Change-Id: I3a9b94d52cc0e962d91827a9b7ca8b65e82130ca
2015-05-06 10:23:22 -07:00
Peter de Rivaz
16add99f0d Corrected optimization of 8x8 DCT code
The 8x8 DCT uses a fast version whenever possible.
There was a mistake in the checking code which
meant sometimes the fast version was used when it
was not safe to do so.

Change-Id: I154c84c9e2d836764768a11082947ca30f4b5ab7
2015-05-06 10:10:19 -07:00
Peter de Rivaz
6aed50370c Added tests for high bitdepth variance sse2 functions
Change-Id: I72735e2e07464a0f7e44968fb14a195c84a58992
2015-05-06 10:10:19 -07:00
Peter de Rivaz
ecf677ede6 Fixed idct16x16_10 highbitdepth transform
In the case when there are only non-zero coefficients
in the first 4x4 block a special routine is called.
The highbitdepth optimized version of this routine
examined the wrong positions when deciding whether
to call an assembler or C inverse transform.

Change-Id: I62da663ca11775dadb66e402e42f4a1cb1927893
2015-05-06 10:10:18 -07:00
Deb Mukherjee
963393321c Iadst transforms to use internal low precision
Change-Id: I266777d40c300bc53b45b205144520b85b0d6e58
2015-05-06 10:10:18 -07:00
Peter de Rivaz
2dad1a7c8e Added high bitdepth sse2 transform functions
Change-Id: If359f0e9a71bca9c2ba685a87a355873536bb282
2015-05-06 10:10:18 -07:00
Peter de Rivaz
2189a51891 Added sse2 acceleration for highbitdepth variance
This is a combination of:
  4a19fa6 Added sse2 acceleration for highbitdepth variance
  c6f5d3b Fix high bit depth assembly function bugs

Change-Id: I446bdf3a405e4e9d2aa633d6281d66ea0cdfd79f
2015-05-06 10:04:08 -07:00
Peter de Rivaz
41973e0e3e Refactored idct routines and headers
This change is made in preparation for a
subsequent patch which adds acceleration
for the highbitdepth transform functions.

The highbitdepth transform functions attempt
to use 16/32bit sse instructions where possible,
but fallback to using the C implementations if
potential overflow is detected.  For this reason
the dct routines are made global so they can be
called from the acceleration functions in the
subsequent patch.

Change-Id: Ia921f191bf6936ccba4f13e8461624b120c1f665
2015-05-06 09:59:20 -07:00
Peter de Rivaz
0e82cba628 Added highbitdepth sse2 SAD acceleration and tests
Change-Id: I9f09e404e3136951e5cc15bf40b915c1fe10b620
2015-05-06 09:00:53 -07:00
Yaowu Xu
846396ddda Enable build with vs20013
Change-Id: I0592b9e92c3ca45e0a81d9ce49a9f2381bec3e39
2015-05-04 14:08:52 -07:00
Zoe Liu
9b083e8271 Changed nearmv for one of the sub8x8 partitions
It is a minor change, but the essential idea is to use the mv of the
top right block as the nearmv for the bottom left partition in the
sub8x8 block. The change is under the experiment of NEWMVREF.

When all 13 experiments are on (except for INTRABC), the gain is +0.05%:
Worse on bowing_cif: -0.17%
Best on foreman_cif: +0.42%; and bridge_far_cif: +0.40%
The total 13 experiments achieved a gain of +6.97% against base.

Change-Id: I3a51d9e28b34b0943fe16a984d62bfb38304ebca
2015-04-30 22:59:32 -07:00
Alex Converse
9b638cded6 tx_skip: Avoid undefined shift behavior.
vp9_quantize_rect did illegal shifts but didn't use the results.
The shift |a << b| is unfortunately undefined if |a < 0|, but the
more verbose |a * (1 << b)| generates the same machine code.

Change-Id: I7ceac66fa20a700630cf8ed008949146b161dab4
2015-04-30 12:56:27 -07:00
Alex Converse
aaa50de4ca Fix integer overflows in TX skipping
Change-Id: Ic1fc0f1271065180cffcbd2906e8faac6d07d08d
2015-04-30 11:42:31 -07:00
Debargha Mukherjee
4e3cf9bdfd Merge "Consolidate common count updates" into nextgen 2015-04-29 22:08:26 +00:00
Debargha Mukherjee
735360f70e Consolidate common count updates
Cleanup - does not have any change in RD performance.

Change-Id: Iaca9c7378b294bd8c780958f5e33e697690eebfa
2015-04-29 14:12:03 -07:00
Yaowu Xu
dfa47eb64b Merge "Add a necessary include file" into nextgen 2015-04-28 23:48:50 +00:00
Yaowu Xu
9d5035ce38 Add a necessary include file
The include is necessary for --enable-coefficient-range-checking

Change-Id: I5cf7b2fca0ddd610815398b1e77f17df42f9785c
2015-04-28 15:44:16 -07:00
Yaowu Xu
5652851391 Merge changes I33c72799,I3ee8974a,I38a42ed1,Iaad3dc3c into nextgen
* changes:
  usage.dox: fix doxygen warnings in 1.8.x
  Fix doxygen warning with usage.dox
  Remove obsolete doxygen tags
  Fix comments for doxygen
2015-04-28 21:16:10 +00:00
Alex Converse
8d9c600d44 Merge "palette: Add missing consts" into nextgen 2015-04-28 19:51:16 +00:00
James Zern
368f7c806a usage.dox: fix doxygen warnings in 1.8.x
use \li to denote list items with \if.

fixes the following likely visible in <1.8.3:
usage.dox: warning: Invalid list item found
usage.dox: warning: End of list marker found without any preceding list items

Change-Id: I33c72799edf9f8866596ac8f79247050b8c75681
2015-04-28 12:07:56 -07:00
Yaowu Xu
4674152287 Fix doxygen warning with usage.dox
Change-Id: I3ee8974a66f186fb0eb15b1078a3c7b9cbf5ec80
2015-04-28 12:07:56 -07:00
Yaowu Xu
856e549027 Remove obsolete doxygen tags
Change-Id: I38a42ed1d0be4fbfce6c9f3f5d021055107933d7
2015-04-28 12:07:56 -07:00
Alex Converse
cb437f800f Merge "Refactor 4:4:4 palette selection." into nextgen 2015-04-28 19:07:41 +00:00
Yaowu Xu
b1f93f56a1 Fix comments for doxygen
Change-Id: Iaad3dc3cdd25275939b475706eb7d136a5a10174
2015-04-28 12:06:56 -07:00
Alex Converse
7ae0b65f32 palette: Add missing consts
Change-Id: I83a2e57dc5dbc328c7bfea421ffbaeb83b7ca3bd
2015-04-28 11:35:17 -07:00
Alex Converse
d0cb4e75bc Refactor 4:4:4 palette selection.
Move 444 palette selection out of vp9_rd_pick_intra_mode_sb and into
a subfunction.

Change-Id: Ib323b740318626e2a68cd3d106dbd27c8f4652a6
2015-04-28 11:21:04 -07:00
hui su
1f7b49f7cd Use uniform quantization settings for non-transform blocks
Do not treat first element (dc) differently.

on screen_content
tx-skip only: +16.4% (was +15.45%)

no significant impact on natrual videos

Change-Id: I79415a9e948ebbb4a69109311c10126d8a0b96ab
2015-04-28 07:54:16 -07:00
hui su
761cd0b010 Fix bugs in palette and intrabc expt
palette expt: correctly update color buffer
intrabc expt: update zcoeff_blk so that residue coding will not
              be mistakenly skipped

Change-Id: I870f5b742c2ac394f4c871aa65e6591e293d8ef6
2015-04-27 15:27:11 -07:00
Alex Converse
98d4f09a7a Replace vp9_get_bit_depth with vp9_ceil_log2.
The current name is confusing with regard to high bit depth buffers.

Change-Id: Ieacd55ec22c81bd2f013f2e3d73a095affc93689
2015-04-23 10:26:57 -07:00
Debargha Mukherjee
96213ac5e7 Merge "Some minor improvements in bilateral filter expt." into nextgen 2015-04-23 01:14:45 +00:00
Debargha Mukherjee
425a45a45c Some minor improvements in bilateral filter expt.
Changes include:

* Uses double for RD cost computation to guard against overflow
for large resolution frames.
* Use previous frame's filter level to code the level better.
* Change precision of the filter parameters.
* Allow spatial variance for x and y to be different

Change-Id: I1669f65eb0ab1e8519962954c92d59e04f1277b7
derflr: +0.556% (a little up from before)
2015-04-22 18:09:42 -07:00
hui su
9e0750c2d2 Modify scan order for non-transform coding blocks
Use raster scan order for non-transform blocks

+15.45% (+2.1%) on screen_content
no significant change on natural videos

Change-Id: I0e264cb69e8624540639302d131f7de9c31c3ba7
2015-04-21 14:23:52 -07:00
hui su
33207fb170 Remove unused variable in new-quant expt
remove dequant_val_nuq in macroblock_plane

Change-Id: I4b4070ae2d01c2403c781433030204d6e95c3750
2015-04-20 11:14:51 -07:00
Alex Converse
90b3838fca Merge "Don't use old uv scores for NEWDV and cleanup mbmi saving." into nextgen 2015-04-17 12:47:23 -07:00
hui su
ebd3666940 Merge "Add high bit depth support for tx-skip expt" into nextgen 2015-04-17 11:37:39 -07:00
Alex Converse
e45e18593b Don't use old uv scores for NEWDV and cleanup mbmi saving.
Change-Id: Ic0fae1b348ad7659e4a41db29d075ae5eb6cdc82
2015-04-17 10:54:33 -07:00
Debargha Mukherjee
fb001c2e2f Merge "Simplify bilateral filter search for speed" into nextgen 2015-04-16 18:58:03 -07:00
Debargha Mukherjee
017baf9f4b Simplify bilateral filter search for speed
Adds an internal buffer in the encoder to store the deblocked
result to help speed up the search for the best bilateral filter.

Very small change in performance but a lot faster:
derflr: +0.518%

Change-Id: I5d37e016088e559c16317789cfb1c2f49334b2b9
2015-04-16 15:33:34 -07:00
hui su
8c00c7a9cd Fix palette expt asan failure
Account for 422 video format.

Change-Id: Ic5af661720fc5fa7142210d907dd25e1e79ff653
2015-04-16 15:08:06 -07:00
hui su
b69152db79 Add high bit depth support for tx-skip expt
+0.3% on 10-bit
+0.3% on 12-bit

With other high bit compatible experiments on 12-bit
+12.44% (+0.17) over 8-bit baseline

Change-Id: I40b4c382fa54ba4640d08d9d01950ea8c1200bc9
2015-04-16 14:54:39 -07:00
hui su
871c51b30a Fix a bug in tx_skip expt
tx_skip is not enabled for sub8x8 blocks.

Change-Id: I3797238735f85fb2bd07b50ca2845611b198bff6
2015-04-14 11:25:55 -07:00
hui su
294159d41e Merge "refactoring in tx_skip experiment" into nextgen 2015-04-14 08:12:08 -07:00
hui su
261a9bac5a refactoring in tx_skip experiment
simplify code logic

Change-Id: Ifafc712f3f85abafadb429a04e295cf8cbb185d2
2015-04-13 17:14:05 -07:00
Debargha Mukherjee
febb434356 Merge "High bit-depth support for wedge partition expt" into nextgen 2015-04-13 10:09:51 -07:00
Debargha Mukherjee
343c092e2e High bit-depth support for wedge partition expt
Change-Id: Idbd27e66d4f4a7953f888137d5752856215a6760
2015-04-13 09:28:15 -07:00
hui su
359bf925ce Fix a mismatch bug
In the tx_skip experiment, dpcm is not used for 64x64 blocks.

Change-Id: Iafbed3b5e411954b80e898f10def3757f2cf44c1
2015-04-11 09:38:49 -07:00
Debargha Mukherjee
8fa0b12cf7 Merge "An experiment introducing a bilateral loop filter" into nextgen 2015-04-10 16:46:16 -07:00
Debargha Mukherjee
fe4b6ac652 An experiment introducing a bilateral loop filter
Adds a framework to incorporate a parameterized loop
postfilter in the coding loop after the application of the
standard deblocking loop filter.

The first version uses a straight bilateral filter
where the parameters conveyed are just spatial and
intensity gaussian variances.

Results on derflr:
+0.523% (only with this experiment)
+6.714% (with all expts other than intrabc)

Change-Id: I20d47285b4d25b8c6386ff8af2a75ff88ac2b69b
2015-04-10 16:05:00 -07:00
hui su
bfc27bb614 tx-skip experiment: improve entropy coding of coeff tokens
This patch allows the prediction residues of tx-skipped blocks
to use probs that are different from regular transfrom
coefficients for token entropy coding. Prediction residues are
assumed as in band 6.

The initial value of probs is obtained with stats from limited
tests. The statistic model for constrained token nodes has not
been optimized. The probs for token extra bits have not been
optimized. These can be future work.

Certain coding improvment is observed:
derflr with all experiments:                +6.26%  (+0.10%)
screen_content with palette:               +22.48%  (+1.28%)

Change-Id: I1c0d78178ee9f3655febb6f30cdaef8ee9f8e3cc
2015-04-10 11:33:42 -07:00
Debargha Mukherjee
b19df73ce8 Preparation for end to end test turn on
Change-Id: Ibc53bf50c8164b413749aaa8baa08e2f6e928e1b
2015-04-03 16:44:40 -07:00
Alex Converse
16e5e713fa Add an intra block copy mode (NEWDV).
Change-Id: I82b261c54ac9db33706bb057613dcbe66fc71387
2015-04-03 11:59:57 -07:00
Zoe Liu
e1cae5eebf Clean the COMPOUND_MODES mv initialization for sub8x8
Change-Id: I04f4ad41c002c761d55093432d6c437c25e5bddd
2015-04-02 16:30:48 -07:00
Zoe Liu
2ae3d4f266 Add a new PREDICTION mode using NEARMV as ref mv
This experiment, referred as NEWMVREF, also merged with NEWMVREF_SUB8X8
and the latter one has been removed. Runborgs results show that:

(1) Turning on this experiment only, compared against the base:
derflf: Average PSNR 0.40%; Overall PSNR 0.40%; SSIM 0.35%
(2) Turning on all the experiments including this feature, compared against
that without this feature, on the highbitdepth case using 12-bit:
derflf: Average PSNR 0.33%; Overall PSNR 0.32%; SSIM 0.30%.

Now for highbitdepth using 12-bit, compared against base:
derflf: Average PSNR 11.12%; Overall PSNR 11.07%; SSIM 20.27%.

Change-Id: Ie61dbfd5a19b8652920d2c602201a25a018a87a6
2015-04-02 14:37:22 -07:00
hui su
9eada94a3e palette experiment: remove run-length coding
Change-Id: I1e52475d0179cf019841d09a53b3b7fc53c79336
2015-03-31 11:09:30 -07:00
hui su
65d39f9fae Merge "Palette experiment: encode color indices based on context" into nextgen 2015-03-26 18:34:43 -07:00
hui su
a3af20f56e Merge "Palette experiment: adaptly update probs" into nextgen 2015-03-26 18:34:28 -07:00
hui su
6ad18db24f Palette experiment: encode color indices based on context
The basic idea is to use a pixel’s neighboring colors as
context to predict its own color. Up to 4 neighbors are
considered here: left, left-above, above, right-above.
To reduce the number of contexts,  the combination of any
4 (or less) colors are mapped to a reduced number of
patterns. For example, 1111, 2222, 3333, … , can be mapped
to the same pattern: AAAA. SImilarly, 1122, 1133, 2233, …,
can be mapped to the pattern AABB. In this way, the total
number of color contexts is reduced to 16.

This almost doubles the gain of palette coding on screen
content videos.

on screen_content
--enable-palette                                  +14.2%
--enable-palette --enable-tx-skip                 +21.2%

on derflr
--enable-palette                                  +0.12%
with all other experiments                        +6.16%

Change-Id: I560306dae216f2ac11a9214968c2ad2319fa1718
2015-03-26 15:48:08 -07:00
Debargha Mukherjee
3d965883f4 Merge "Add palette coding mode for inter frames" into nextgen 2015-03-26 11:59:36 -07:00
hui su
e18b104462 Palette experiment: adaptly update probs
Also make changes to transmit palette-enabled flag using
neighbor blocks as context.

on screen_content
--enable-palette                            +7.35%

on derflr
with all other experiments                  +6.05%

Change-Id: Id6c2f726d21913d54a3f86ecfea474a4044c27f6
2015-03-25 09:12:57 -07:00
Zoe Liu
2a5648dca5 Cleaned the code in handle_inter_mode
borgs show consistent results as before this patch

Change-Id: I3d21623cb03ea169a031328e9dde9c26ba1bd016
2015-03-23 15:33:25 -07:00
hui su
070d635657 Add palette coding mode for inter frames
on screen_content
--enable-palette                                    +6.74%

on derflr
with all other experiments                          +6.02%
(--enable-supertx --enable-copy-mode
 --enable-ext-tx --enable-filterintra
 --enable-tx64x64 --enable-tx-skip
 --enable-interintra --enable-wedge-partition
 --enable-compound-modes --enable-new-quant
 --enable-palette)

Change-Id: Ib85049b4c3fcf52bf95efbc9d6aecf53d53ca1a3
2015-03-23 08:41:51 -07:00
Deb Mukherjee
73dcd41b72 Merge "Make interintra experiment work with highbitdepth" into nextgen 2015-03-22 22:48:56 -07:00
Deb Mukherjee
c082df2359 Make interintra experiment work with highbitdepth
Also includes some adjustments to the algorithm.
All stats look good.

Change-Id: I824ef8ecf25b34f3feb358623d14fe375c3e4eb7
2015-03-21 07:35:40 -07:00
Deb Mukherjee
8c5ac79e66 Some build fixes with highbitdepth and new quant
Highbitdepth performance about the same as 8-bit.

Change-Id: If737962d8588dd190083edae4383b731f9d22873
2015-03-21 06:53:58 -07:00
Deb Mukherjee
c8ed36432e Non-uniform quantization experiment
This framework allows lower quantization bins to be shrunk down or
expanded to match closer the source distribution (assuming a generalized
gaussian-like central peaky model for the coefficients) in an
entropy-constrained sense. Specifically, the width of the bins 0-4 are
modified as a factor of the nominal quantization step size and from 5
onwards all bins become the same as the nominal quantization step size.
Further, different bin width profiles as well as reconstruction values
can be used based on the coefficient band as well as the quantization step
size divided into 5 ranges.

A small gain currently on derflr of about 0.16% is observed with the
same paraemters for all q values.
Optimizing the parameters based on qstep value is left as a TODO for now.

Results on derflr with all expts on is +6.08% (up from 5.88%).

Experiments are in progress to tune the parameters for different
coefficient bands and quantization step ranges.

Change-Id: I88429d8cb0777021bfbb689ef69b764eafb3a1de
2015-03-17 21:42:55 -07:00
Alex Converse
9a92891ac4 interintra: wedge: Get the correct wedge params.
Fixes an asan issue.

Change-Id: I671ffc382c77c2b38673e0b148f54e7bce2ce9c2
2015-03-17 10:49:22 -07:00
Alex Converse
7ca745a2df palette: Fix an illegal read
Change-Id: I71649f0a85d98b96efd08c8a9e3ee7372fd7d327
2015-03-16 17:13:15 -07:00
Deb Mukherjee
961fe77e70 Merge "Misc changes to support high-bitdepth with supertx" into nextgen 2015-03-12 17:42:20 -07:00
Deb Mukherjee
35d38646ec Misc changes to support high-bitdepth with supertx
Change-Id: I0331646d1c55deb6e4631e64bd6b092fb892a43e
2015-03-12 16:52:25 -07:00
Zoe Liu
0337ae5218 Fixed a bug & a build warning for newmvref-sub8x8
Change-Id: I799fc3fb4c1201da14c97bf66e06dec655f6a620
2015-03-12 11:31:33 -07:00
hui su
7621c779e5 Add palette coding mode for UV
For 444 videos, a single palette of 3-d colors is
generated for YUV. For 420 videos, there may be two
palettes, one for Y, and the other for UV.

Also fixed a bug when palette and tx-skip are both on.

on derflr
--enable-palette                    +0.00%
with all experiments                +5.87% (was +5.93%)

on screen_content
--enable-palette                    +6.00%
--enable-palette --enable-tx_skip   +15.3%

on screen_content 444 version
--enable-palette                    +6.76%
--enable-palette --enable-tx_skip   +19.5%

Change-Id: I7287090aecc90eebcd4335d132a8c2c3895dfdd4
2015-03-10 13:38:19 -07:00
Debargha Mukherjee
ee2f0bdfcd Merge "Global motion work continued" into nextgen 2015-03-10 11:27:04 -07:00
Spencer Egart
faaaf85fc3 Global motion work continued
Interface change for the global Mv functions.

Change-Id: Ie4722faa638ac557f99743f7b33ff46c3d29e9a1
2015-03-10 10:47:12 -07:00
Deb Mukherjee
d835821fa1 Merge "Make filterintra experiment work with highbitdepth" into nextgen 2015-03-10 10:42:58 -07:00
Deb Mukherjee
78bcc48756 Make filterintra experiment work with highbitdepth
All stats look fine.
derflr: +0.912 with respect to 10-bit internal baseline
               (Was +0.747% w.r.t. 8 bit)
        +5.545 with respect to 8-bit baseline

Change-Id: I3c14fd17718a640ea2f6bd39534e0b5cbe04fb66
2015-03-10 07:59:59 -07:00
Alex Converse
efe2b3cbc6 Fix tx_skip debug build.
Change-Id: I20a3e4e34f10485aa5e6723cd33b0311bdbf1320
2015-03-09 14:57:13 -07:00
Yaowu Xu
41eb20d1e9 Add encoder control for setting color space
This commit adds encoder side control for vp9 to set color space info
in the output compressed bitstream.

It also amends the "vp9_encoder_params_get_to_decoder" test to verify
the correct color space information is passed from the encoder end to
decoder end.

Change-Id: Ibf5fba2edcb2a8dc37557f6fae5c7816efa52650
(cherry picked from commit e94b415c3479129944a69fafbeacf550fb9237b7)
2015-03-06 16:42:09 -08:00
Yaowu Xu
63537df4c0 Enable decoder to pass through color space info
This commit added a field to vpx_image_t for indicating color space,
the field is also added to YUV_BUFFER_CONFIG. This allows the color
space information pass through the decoder from input stream to the
output buffer.

The commit also updates compare_img() function with added verification
of matching color space to ensure the color space information to be
correctly passed from encode to decoder in compressed vp9 streams.

Change-Id: I412776ec83defd8a09d76759aeb057b8fa690371
(cherry picked from commit 6b223fcb588c865ae6f5abfd3d9de3ba2ae0540f)
2015-03-06 15:57:12 -08:00
Yaowu Xu
b7913deb7e Added plumbing for setting color space
Change-Id: If64052cc6e404abc8a64a889f42930d14fad21d3
(cherry picked from commit ce52b0f8d347224cd526dc1ba55597a2aa79c341)
2015-03-06 14:51:49 -08:00
James Zern
cd152849ea vp9_highbd_tm_predictor_16x16: fix win64
by saving xmm8; cglobal's xmm reg arg is 0-based

Change-Id: Ic8426ec9ac59ab4478716aa812452a6406794dcb
(cherry picked from commit 923cc0bf51a24d05c6aa68f80e09d485a54431f6)
2015-03-06 13:29:00 -08:00
Yaowu Xu
6fcaa06911 Correct the miscalculation in uv dimensions
The calculation of required extension used in HBD case was wrong due
to rounding for UV when y dimension is odd. This commit replace the
computation with correct version.

This fixes a crash caused by writting beyond buffer boundary.

Change-Id: Ic7c9afeb7388cd1341ec4974a611dacfb74ac6b6
(cherry picked from commit 4bca73b609bfe9a5cb86fc25b69c6128d9041504)
2015-03-06 09:47:57 -08:00
Yaowu Xu
7b4ff46175 Prevent VP8 encoding crash
This commit changes the value of highbitdepth flag to avoid conflict
with vp8 refresh_last_frame flag.

Change-Id: Idcff2cf44f0a200bd935b326f785c0cf32d7228a
(cherry picked from commit dd27307cac5ac7f346888d219877041563eea0a2)
2015-03-06 09:47:56 -08:00
Zoe Liu
cf004a0845 Merge "Fixed the build for newmvref-sub8x8" into nextgen 2015-03-06 08:54:11 -08:00
Zoe Liu
6c7b4ed355 Fixed the build for newmvref-sub8x8
Change-Id: Ie042001e69d80b1fc52368f29617ad2e51a5e250
2015-03-06 00:01:30 -08:00
Zoe Liu
756a18663c Merge "Cleaned code further for newmvref-sub8x8 and compound-modes" into nextgen 2015-03-05 15:41:28 -08:00
Zoe Liu
1192f99976 Cleaned code further for newmvref-sub8x8 and compound-modes
Change-Id: I9f869c37566aaf81910d1d6ab1b2ac0d2a2f0a23
2015-03-05 15:40:36 -08:00
Zoe Liu
e222d46658 Merge "Changed mv ref to nearestmv always for sub8x8" into nextgen 2015-03-05 11:57:21 -08:00
Zoe Liu
b359952c2c Changed mv ref to nearestmv always for sub8x8
For all sub8x8 partition, the mv ref has changed to its own nearest_mv
instead of the nearest_mv of the super 8x8 block:

--enable-newmvref-sub8x8: ~0.1% gain for derflr

Besides the above new experiment, code has been cleaned largely for the
sub8x8 motion search, such that the mv ref can be fairly easily changed to
use other options, e.g., the next step's global motion effort.

Change-Id: I8e3f4aaa8553ba8c445369692e079db5ce282593
2015-03-05 11:09:58 -08:00
Zoe Liu
a9040ea40c Corrected comment in mode_2_counter for compound
Change-Id: I5459550e62cff79182fa0ac5a24edb56cb64d608
2015-03-04 10:16:25 -08:00
Zoe Liu
30720adf6e Fixed the build for denoiser in new compound mode
Change-Id: Ifb824ce87db9c00c8c87f52d9b8718669fb39d05
2015-03-04 09:29:05 -08:00
Deb Mukherjee
4c1049d7a8 Some fixes to quantization and compiler warnings
The bugs affected only the tx64x64 experiment. This patch fixes
them.

Also fixes some compiler warnings

Change-Id: I4cf1e24a4f1fa59831bf29750cf6daa8373e8e8f
2015-03-03 14:07:17 -08:00
Deb Mukherjee
9909903229 Adds translation model to global motion estimation
Change-Id: Ie1791ab7cfdd3f7a1b03404627246c923f1bd51f
2015-02-25 09:57:33 -08:00
hui su
caccf06acd Palette-based coding experiment
Added palette coding option for Y channel only, key frame only.
Palette colors are obtained with k-means clustering algorithm.
Run-length coding is used to compress the color indices.

On screen_content:
--enable-palette                            + 5.75%
--enable-palette --enable-tx_skip           +15.04% (was 13.3%)

On derflr:
--enable-palette                            - 0.03%
with all the other expriments               + 5.95% (was 5.98%)

Change-Id: I6d1cf45c889be764d14083170fdf14a424bd31b5
2015-02-23 09:23:50 -08:00
Zoe Liu
7d8840a082 Removed redundant src_mi in mv ref candidates
Change-Id: I4eb144e7c9d2c8568388ae58001cc7b7498967e4
2015-02-19 09:44:05 -08:00
Spencer Egart
d8983f0dd7 Global Motion block-based
Uses block-based motion fields with ransac to find transformation between
frames.

Change-Id: I6293fbb690cdad854a1140fb6af76b326abfe964
2015-02-18 11:52:39 -08:00
Spencer Egart
edffe3f956 Global motion experiment
Added a function to compute a motion field for a pair of buffers, for use in
finding an affine transform or homography.

Change-Id: Id5169cc811a61037e877dfd57fccaca89d93936f
2015-02-10 11:15:39 -08:00
Deb Mukherjee
2aef964519 Merge "Adds code for corner detection and ransac" into nextgen 2015-02-10 08:18:03 -08:00
Deb Mukherjee
1fc70e47cd Adds code for corner detection and ransac
This code is to start experiments with global motion models.

The corner detection can be either fast_9 or Harris.
Corner matching is currently based on normalized correlation.
Three flavors of ransac are used to estimate either a
homography (8-param), or an affine model (6-param) or a
rotation-zoom only affine model (4-param).

The highest level API for the library is in vp9_global_motion.h,
where there are two functions - one for computing a single model
and another for computing multiple models up to a maximum number
provided or until a desired inlier probability is achieved.

Change-Id: I3f9788ec2dc0635cbc65f5c66c6ea8853cfcf2dd
2015-02-10 00:48:56 -08:00
Zoe Liu
48da7bf004 Cleaned up the COMPOUND_MODES code in sub8x8
Change-Id: I571ff39799c3257b5c6db82660364ce412c7f6e2
2015-02-09 11:58:54 -08:00
hui su
2118f66a91 Enable tx_skip for inter blocks
Enable tx_skip for inter blocks whose q-index is smaller than 64.

tx_skip experiment alone:
derflr: +0.233% (was +0.038%)

all experiments:
derflr: +5.98% (was +5.94%)

Change-Id: I35245a476ff7039fec8468a92a6aa63feaf74831
2015-02-08 17:57:51 -08:00
hui su
1ae3989558 Fix a bug in filterintra experiment
All expts together: +5.946% (up about 0.3%)

Change-Id: If686e5e97209b4cc4a8115f920e1f4f35ded5a1d
2015-01-31 00:43:06 -08:00
Yue Chen
2ed2f29d21 Fix a bug in COPY_MODE + EXT_TX experiment
Remove the duplicated step counting the overhead for ext_tx, because
it has been counted in super_block_yrd().

Change-Id: I50bc01d8166572bc0847305565cf33c14ee516e6
2015-01-27 12:02:54 -08:00
Jingning Han
50cab76f12 Removal of legacy zbin_extra / zbin_oq_value.
Change-Id: I07f77a63aa98087626e45c4e87aa5dcafc0b0b07
(cherry picked from commit d0f237702745c4bfc0297d24f9465f960fb988ed)
2015-01-21 20:37:19 -08:00
Deb Mukherjee
7a993f850e Adds inter-intra combination with wedge partitions
Also fixes some build issues with certain experimental combinations.

Results on derflr with all experiments on: +5.516%

Change-Id: I9b492f3d3556bd1f057005571dc9bee63167dd95
2015-01-21 15:45:22 -08:00
Deb Mukherjee
760219d0fd Some build fixes
Related zbin boost removal.

Change-Id: I0f34d31038c29d5cb78bc5d110159df01e41e328
2015-01-21 13:37:24 -08:00
Paul Wilkins
dfed541f21 Remove mode dependent zbin boost.
Initial patch to remove get_zbin_mode_boost() and
cpi->zbin_mode_boost.

For now sets a dummy value of 0 for zbin extra pending
a further clean up patch.

Change-Id: I64a1e1eca2d39baa8ffb0871b515a0be05c9a6af
(cherry picked from commit 60e9b731cf8945403dbcf149a0f6dc745e5cabe1)
2015-01-21 11:05:55 -08:00
Spencer Egart
347c31b48f Created COMPOUND_MODES experiment.
COMPOUND_MODES experiment encodes separate MV modes for each frame in a compound
reference prediction.  Added modes NEAREST_NEARESTMV, ZERO_ZEROMV,
NEW_NEWMV, NEAREST_NEARMV, NEAR_NEARESTMV, NEW_NEARESTMV, NEAR_NEWMV,
NEW_NEARMV, and NEAREST_NEWMV.

Also enhances the wedge-partition expt to work better with compound
modes.

Results:
derflr +0.227
All experiments on: derflr +5.218

Change-Id: I719e8a34826bf1f1fe3988dac5733a845a89ef2b
2015-01-16 14:48:56 -08:00
Deb Mukherjee
db5dd49996 Adds wedge-partitions for compound prediction
Results with this experiment only: +0.642% on derflr.
With other experiments: +4.733%

Change-Id: Ieb2022f8e49ac38a7e7129e261a6bf69ae9666b9
2015-01-15 15:59:33 -08:00
punksu
5f0093bb98 Merge "dpcm intra prediction for tx_skip" into nextgen 2015-01-15 11:53:06 -08:00
punksu
571fdbb05f dpcm intra prediction for tx_skip
Implements vertical, horizontal, and tm dpcm intra prediction for
blocks in tx_skip mode. Typical coding gain on screen content video
is 2%~5%.

Change-Id: Idd5bd84ac59daa586ec0cd724680cef695981651
2015-01-14 14:54:09 -08:00
Zoe Liu
a56ff2d323 Fixed a bug in the experiment EXT_TX.
Change-Id: I1adf0e916f9414e6dfe1d07cefc0693bc63b7e97
2015-01-14 14:27:51 -08:00
hui su
f60b844974 Merge "Turn on tx_skip for inter modes" into nextgen 2015-01-14 08:57:41 -08:00
Deb Mukherjee
3960e92c8b Merge "Some fixes in interintra expt" into nextgen 2015-01-13 12:34:24 -08:00
hui su
2c68b07d7d Turn on tx_skip for inter modes
Fixed the mismatch issue in lossless case

Change-Id: Ia2fd98865b4687e664fdc75f62b402e8289a1968
2015-01-13 11:28:08 -08:00
Deb Mukherjee
cb165354e7 Some fixes in interintra expt
Removes some redundant information when supertx and interintra
both are used.

Change-Id: I40b0fddbc1ba54607c6e8068bde128c21c14d997
2015-01-13 00:52:25 -08:00
Zoe Liu
919692d6c5 Cleaned up the code a little for the CONFIG_EXT_TX experiment on the
16x16 and 8x8 transform sizes, both for the regular case and the high
bit depth (CONFIG_VP9_HIGHBITDEPTH) case.

Change-Id: I34a9d3c73c3687f967105194ce4def48c3ec435c
2015-01-12 12:11:37 -08:00
Deb Mukherjee
b43beffc3c Merge "Adds an inter-intra combination mode" into nextgen 2015-01-12 09:22:21 -08:00
Deb Mukherjee
2dba1221b4 Adds an inter-intra combination mode
A smooth weighting scheme is used to put more weight
on the intra predictor samples near the left/top boundaries
and decaying it to favor the inter predictor samples more as
we move away from these boundaries in the direction of
prediction.

Results:
derflr: +0.609% with only this experiment
derflr: +3.901% with all experiments

Change-Id: Ic9dbe599ad6162fb05900059cbd6fc88b203a09c
2015-01-12 00:28:01 -08:00
Zoe Liu
b342c8405b Merge "Fixed a bug in the CONFIG_EXT_TX experiment for the forward 16x16 transform size when CONFIG_VP9_HIGHBITDEPTH is enabled." into nextgen 2015-01-09 13:32:53 -08:00
Deb Mukherjee
f61bcfbafa Merge "Segment id fix in tx-skip/supertx experiment" into nextgen 2015-01-09 10:37:59 -08:00
punksu
9100fe3944 Merge "Fix conflict b/w tx_skip and copy_mode in lossless mode" into nextgen 2015-01-08 17:06:41 -08:00
Zoe Liu
d7d5c75c69 Fixed a bug in the CONFIG_EXT_TX experiment for the forward 16x16
transform size when CONFIG_VP9_HIGHBITDEPTH is enabled.

Change-Id: I475f64eac2c31094a47bc0d557968940cad01c86
2015-01-08 09:03:53 -08:00
Deb Mukherjee
28258c5fe2 Segment id fix in tx-skip/supertx experiment
Change-Id: Ice9e833ad7f60e943acc011260dc3121ad3b136f
2015-01-08 02:05:11 -08:00
Deb Mukherjee
9a19ef0add Turn off tx-skip for intermodes temporarily
Will be re-enabled when a mismatch issue is resolved.

Change-Id: I303d80effa69eeb0ebf1921bbb4eaeeb34497e4b
2015-01-06 18:14:00 -08:00
punksu
42dfd9a728 Fix conflict b/w tx_skip and copy_mode in lossless mode
Change-Id: Idb12344adda99dddde8d2cd010ffffe6425aca62
2015-01-06 20:51:46 +08:00
Yue Chen
695c4bc321 Fix mismatch in SUPERTX experiment
Disable SUPERTX mode when lossless mode is enabled because the largest
lossless transform size is 4X4.

Change-Id: I4167959a282728d62354119ced99ca29febabfd1
2014-12-28 02:27:16 -08:00
punksu
b0ef621f84 Merge "Allow large tx_size in lossless coding with transform skipping" into nextgen 2014-12-27 20:52:36 -08:00
Deb Mukherjee
2b959d4ee8 Fix frame-parallel modes
This fix is already incorporated in master.

Change-Id: I7b0c048ebef4d92f041cc8727bc276843f17d50d
2014-12-27 01:55:27 -08:00
Deb Mukherjee
9aa76fdb69 Adds a copy mode experiment
Experiment to copy motion and mode from block neighbors.

Results:
--------
--enable-experimental --enable-copy-mode:
derflr: +0.727%

With other expts:
--enable-experimental --enable-copy-mode --enable-supertx
--enable-ext-tx --enable-filterintra --enable-tx-skip --enable-tx64x64
derflr: +3.43%

Change-Id: Iae74b9a855a1a690bf76131b42d247bbc54dec17
2014-12-24 17:52:55 -08:00
punksu
8a41d18bd0 Allow large tx_size in lossless coding with transform skipping
In lossless coding, tx_size can be larger than 4x4 when transform
skipping is activated. Compared to regular vp9 lossless coding,
performance improvement for derf is about 5%; gain is larger
for screen content videos.

Change-Id: Ib20ece7e117f29fb91543612757302a2400110b4
2014-12-22 22:56:52 +08:00
Debargha Mukherjee
2f7de8c887 Bug fix in rdopt
Change-Id: Ieab80902755456e97583636f13d1417269b332b5
2014-12-18 02:43:27 -08:00
Deb Mukherjee
7ec9792f96 Adds forward prob updates for supertx expt
Also refactors the supertx prob models, and includes other
cleanups.

Change-Id: I74de6c01d872ae09bf6d43a31f53d43283b6b226
2014-12-15 21:55:58 -08:00
hui su
5de9280ae9 tx_skip mode for lossy coding
This patch improves the non-transform coding mode. At this
point, the coding gain on screen content videos is about
12% for lossless, an 15% for lossy case.

1. Encode tx_skip flags with context. Y tx_skip flag context is
whether the prediction mode is inter or intra. UV flag context
is Y flag.

2. Transform skipping is less helpful when the Q-index is high.
So it is enabled only when the Q-index is smaller than a
threshold. Currently the threshold is set as 255 for intra blocks,
and 0 for inter blocks.

3. The shift of the prediction residue, when copying them to the
coeff buffer, is set as 3 when the Q-index is larger than a
threshold (currently set as 0), and 2 otherwise.

Change-Id: I372973c7518cf385f6e542b22d0f803016e693b0
2014-12-15 10:46:41 -08:00
Deb Mukherjee
625c0961ff Adds supertx experiment adopted from playground
Reimplements the supertx experiment from the playground branch.
Makes it work with other experiments.

Results:
With --enable-superttx
derflr: +0.958

With --enable-supertx --enable-ext-tx
derflr: +2.25%

With --enable-supertx --enable-ext-tx --enable-filterintra
derflr: +2.73%

Change-Id: I5012418ef2556bf2758146d90c4e2fb8a14610c7
2014-12-11 16:06:23 -08:00
Deb Mukherjee
1fdc274900 Extends ext_tx expt to include all hybrid variants
Extends the ext-tx experiment to include all 9 DST/DCT
variants.

Results with ext_tx experiment:
derflr: +1.338 derflr (improved from 1.12)

Change-Id: I24b5564f96bce6ccaa13d88ca6cb9d0c57000597
2014-11-21 07:21:38 -08:00
Deb Mukherjee
c82de3bede Extending ext_tx expt to include dst variants
Extends the ext-tx experiment to include regular and flipped
DST variants. A total of 9 transforms are thus possible for
each inter block with transform size <= 16x16.

In this patch currently only the four ADST_ADST variants
(flipped or non-flipped in both dimensions) are enabled
for inter blocks.

The gain with the ext-tx experiment grows to +1.12 on derflr.
Further experiments are underway.

Change-Id: Ia2ed19a334face6135b064748f727fdc9db278ec
2014-11-20 14:25:40 -08:00
hui su
d97fd3eef6 Non transform coding experiment
Non-transform option is enabled in both intra and inter modes.
In lossless case, the average coding gain on screen content
clips is 11.3% in my test.

Change-Id: I2e8de515fb39e74c61bb86ce0f682d5f79e15188
2014-11-19 21:20:21 -08:00
Deb Mukherjee
e2a8e90874 Misc cleanups on ext_tx expt.
Change-Id: I599d9fb00a2accdf24def65df52bef56d014a0b6
2014-11-16 00:03:18 -08:00
Deb Mukherjee
52e4dfe1b1 Merge "Adds missing EXT_TX checks" into nextgen 2014-11-13 20:13:40 -08:00
Deb Mukherjee
f62d19752d Adds missing EXT_TX checks
Change-Id: Ia0ca39c9041f17da0b7f522e55868498f31de848
2014-11-13 15:59:50 -08:00
Spencer Egart
83e50d6412 Refactoring in nonrd_ methods in vp9_encodeframe
Refactored some of the more repetitive code in the nonrd methods in
vp9_encodeframe.c.

Change-Id: Ib71dcd14f74fb6e5fd123b3ffea8f253aaa04b1a
2014-11-13 13:00:15 -08:00
hui su
cf7dc66e34 Fix lossless mismatch in EXT_TX
In lossless mode, transform should not be altered.

Change-Id: I216d1700963b4d1c35e059cd7ff7b0cefaf46133
2014-11-13 05:07:37 -08:00
Spencer Egart
1c562aebd8 Migrate EXT_TX from playground to nextgen.
Change-Id: I1cb0584104323fb3781e66bb65d44ebbe853c9c8
2014-11-11 07:55:49 -08:00
Spencer Egart
e55808d9a7 Migrated FILTERINTRA from playground to nextgen
derf +0.385
derflr +0.411
with --enable-tx64x64, derflr +0.433

Added fix for integration with TX64X64

Change-Id: Ie24825de06021d007ba215ac7f6de40638c57e12
2014-11-10 10:13:32 -08:00
Deb Mukherjee
613ea21ae7 Tx64x64 bug fixes
Change-Id: Iac595a3ae8f1466d8485c3627219b4b623efc8ad
2014-11-05 20:19:43 -08:00
Deb Mukherjee
a137e3c3ba Fixes in 64x64 transform
Extends quantizer range and some other fixes.

Change-Id: Ia9adf7848e772783365d6501efd07585bff80c15
stdhd: +0.166%, turns positive a little
derf: -0.036% (very few blocks use the 64x64 mode)
2014-11-03 17:00:43 -08:00
Deb Mukherjee
8bdf4cebb9 Merge "Adding a 64x64 transform mode" into nextgen 2014-10-30 00:51:35 -07:00
Deb Mukherjee
0c7a94f49b Adding a 64x64 transform mode
Preliminary 64x64 transform implementation.
Includes all code changes.
All mismatches resolved.

Coding results for derf and stdhd are within noise. stdhd is slightly
higher, derf is slightly lower.

To be further refined.

Change-Id: I091c183f62b156d23ed6f648202eb96c82e69b4b
2014-10-30 00:45:57 -07:00
1233 changed files with 271958 additions and 279591 deletions

View File

@ -1,109 +0,0 @@
---
Language: Cpp
# BasedOnStyle: Google
# Generated with clang-format 5.0.0
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

13
.gitignore vendored
View File

@ -30,35 +30,28 @@
/examples/decode_with_partial_drops /examples/decode_with_partial_drops
/examples/example_xma /examples/example_xma
/examples/postproc /examples/postproc
/examples/resize_util
/examples/set_maps /examples/set_maps
/examples/simple_decoder /examples/simple_decoder
/examples/simple_encoder /examples/simple_encoder
/examples/twopass_encoder /examples/twopass_encoder
/examples/vp8_multi_resolution_encoder /examples/vp8_multi_resolution_encoder
/examples/vp8cx_set_ref /examples/vp8cx_set_ref
/examples/vp9cx_set_ref /examples/vp9_spatial_scalable_encoder
/examples/vp9_lossless_encoder /examples/vpx_temporal_scalable_patterns
/examples/vp9_spatial_svc_encoder
/examples/vpx_temporal_svc_encoder
/ivfdec /ivfdec
/ivfdec.dox /ivfdec.dox
/ivfenc /ivfenc
/ivfenc.dox /ivfenc.dox
/libvpx.so* /libvpx.so*
/libvpx.ver /libvpx.ver
/obj_int_extract
/samples.dox /samples.dox
/test_intra_pred_speed
/test_libvpx /test_libvpx
/tools.dox
/tools/*.dox
/tools/tiny_ssim
/vp8_api1_migration.dox /vp8_api1_migration.dox
/vp[89x]_rtcd.h /vp[89x]_rtcd.h
/vpx.pc /vpx.pc
/vpx_config.c /vpx_config.c
/vpx_config.h /vpx_config.h
/vpx_dsp_rtcd.h
/vpx_scale_rtcd.h /vpx_scale_rtcd.h
/vpx_version.h /vpx_version.h
/vpxdec /vpxdec

View File

@ -1,42 +1,18 @@
Adrian Grange <agrange@google.com> Adrian Grange <agrange@google.com>
Aex Converse <aconverse@google.com>
Aex Converse <aconverse@google.com> <alex.converse@gmail.com>
Alexis Ballier <aballier@gentoo.org> <alexis.ballier@gmail.com> Alexis Ballier <aballier@gentoo.org> <alexis.ballier@gmail.com>
Alpha Lam <hclam@google.com> <hclam@chromium.org>
Chris Cunningham <chcunningham@chromium.org>
Daniele Castagna <dcastagna@chromium.org> <dcastagna@google.com>
Deb Mukherjee <debargha@google.com>
Erik Niemeyer <erik.a.niemeyer@intel.com> <erik.a.niemeyer@gmail.com>
Guillaume Martres <gmartres@google.com> <smarter3@gmail.com>
Hangyu Kuang <hkuang@google.com> Hangyu Kuang <hkuang@google.com>
Hui Su <huisu@google.com>
Jacky Chen <jackychen@google.com>
Jim Bankoski <jimbankoski@google.com> Jim Bankoski <jimbankoski@google.com>
John Koleszar <jkoleszar@google.com>
Johann Koenig <johannkoenig@google.com> Johann Koenig <johannkoenig@google.com>
Johann Koenig <johannkoenig@google.com> <johann.koenig@duck.com> Johann Koenig <johannkoenig@google.com> <johann.koenig@duck.com>
Johann Koenig <johannkoenig@google.com> <johann.koenig@gmail.com> Johann Koenig <johannkoenig@google.com> <johannkoenig@dhcp-172-19-7-52.mtv.corp.google.com>
Johann Koenig <johannkoenig@google.com> <johannkoenig@chromium.org>
John Koleszar <jkoleszar@google.com>
Joshua Litt <joshualitt@google.com> <joshualitt@chromium.org>
Marco Paniconi <marpan@google.com>
Marco Paniconi <marpan@google.com> <marpan@chromium.org>
Pascal Massimino <pascal.massimino@gmail.com> Pascal Massimino <pascal.massimino@gmail.com>
Paul Wilkins <paulwilkins@google.com> Sami Pietilä <samipietila@google.com>
Peter Boström <pbos@chromium.org> <pbos@google.com> Tero Rintaluoma <teror@google.com> <tero.rintaluoma@on2.com>
Peter de Rivaz <peter.derivaz@gmail.com> Timothy B. Terriberry <tterribe@xiph.org> Tim Terriberry <tterriberry@mozilla.com>
Peter de Rivaz <peter.derivaz@gmail.com> <peter.derivaz@argondesign.com> Tom Finegan <tomfinegan@google.com>
Ralph Giles <giles@xiph.org> <giles@entropywave.com> Ralph Giles <giles@xiph.org> <giles@entropywave.com>
Ralph Giles <giles@xiph.org> <giles@mozilla.com> Ralph Giles <giles@xiph.org> <giles@mozilla.com>
Ronald S. Bultje <rsbultje@gmail.com> <rbultje@google.com> Alpha Lam <hclam@google.com> <hclam@chromium.org>
Sami Pietilä <samipietila@google.com> Deb Mukherjee <debargha@google.com>
Shiyou Yin <yinshiyou-hf@loongson.cn>
Tamar Levy <tamar.levy@intel.com>
Tamar Levy <tamar.levy@intel.com> <levytamar82@gmail.com>
Tero Rintaluoma <teror@google.com> <tero.rintaluoma@on2.com>
Timothy B. Terriberry <tterribe@xiph.org> <tterriberry@mozilla.com>
Tom Finegan <tomfinegan@google.com>
Tom Finegan <tomfinegan@google.com> <tomfinegan@chromium.org>
Urvang Joshi <urvang@google.com> <urvang@chromium.org>
Yaowu Xu <yaowu@google.com> <adam@xuyaowu.com>
Yaowu Xu <yaowu@google.com> <yaowu@xuyaowu.com> Yaowu Xu <yaowu@google.com> <yaowu@xuyaowu.com>
Yaowu Xu <yaowu@google.com> <Yaowu Xu>

76
AUTHORS
View File

@ -4,12 +4,9 @@
Aaron Watry <awatry@gmail.com> Aaron Watry <awatry@gmail.com>
Abo Talib Mahfoodh <ab.mahfoodh@gmail.com> Abo Talib Mahfoodh <ab.mahfoodh@gmail.com>
Adrian Grange <agrange@google.com> Adrian Grange <agrange@google.com>
Aex Converse <aconverse@google.com>
Ahmad Sharif <asharif@google.com> Ahmad Sharif <asharif@google.com>
Aleksey Vasenev <margtu-fivt@ya.ru>
Alexander Potapenko <glider@google.com>
Alexander Voronov <avoronov@graphics.cs.msu.ru> Alexander Voronov <avoronov@graphics.cs.msu.ru>
Alexandra Hájková <alexandra.khirnova@gmail.com> Alex Converse <alex.converse@gmail.com>
Alexis Ballier <aballier@gentoo.org> Alexis Ballier <aballier@gentoo.org>
Alok Ahuja <waveletcoeff@gmail.com> Alok Ahuja <waveletcoeff@gmail.com>
Alpha Lam <hclam@google.com> Alpha Lam <hclam@google.com>
@ -17,80 +14,44 @@ A.Mahfoodh <ab.mahfoodh@gmail.com>
Ami Fischman <fischman@chromium.org> Ami Fischman <fischman@chromium.org>
Andoni Morales Alastruey <ylatuya@gmail.com> Andoni Morales Alastruey <ylatuya@gmail.com>
Andres Mejia <mcitadel@gmail.com> Andres Mejia <mcitadel@gmail.com>
Andrew Lewis <andrewlewis@google.com>
Andrew Russell <anrussell@google.com>
Angie Chiang <angiebird@google.com>
Aron Rosenberg <arosenberg@logitech.com> Aron Rosenberg <arosenberg@logitech.com>
Attila Nagy <attilanagy@google.com> Attila Nagy <attilanagy@google.com>
Brion Vibber <bvibber@wikimedia.org>
changjun.yang <changjun.yang@intel.com> changjun.yang <changjun.yang@intel.com>
Charles 'Buck' Krasic <ckrasic@google.com>
Cheng Chen <chengchen@google.com>
chm <chm@rock-chips.com> chm <chm@rock-chips.com>
Chris Cunningham <chcunningham@chromium.org>
Christian Duvivier <cduvivier@google.com> Christian Duvivier <cduvivier@google.com>
Daniele Castagna <dcastagna@chromium.org>
Daniel Kang <ddkang@google.com> Daniel Kang <ddkang@google.com>
Deb Mukherjee <debargha@google.com> Deb Mukherjee <debargha@google.com>
Deepa K G <deepa.kg@ittiam.com>
Dim Temp <dimtemp0@gmail.com>
Dmitry Kovalev <dkovalev@google.com> Dmitry Kovalev <dkovalev@google.com>
Dragan Mrdjan <dmrdjan@mips.com> Dragan Mrdjan <dmrdjan@mips.com>
Ed Baker <edward.baker@intel.com> Erik Niemeyer <erik.a.niemeyer@gmail.com>
Ehsan Akhgari <ehsan.akhgari@gmail.com>
Erik Niemeyer <erik.a.niemeyer@intel.com>
Fabio Pedretti <fabio.ped@libero.it> Fabio Pedretti <fabio.ped@libero.it>
Frank Galligan <fgalligan@google.com> Frank Galligan <fgalligan@google.com>
Fredrik Söderquist <fs@opera.com> Fredrik Söderquist <fs@opera.com>
Fritz Koenig <frkoenig@google.com> Fritz Koenig <frkoenig@google.com>
Gabriel Marin <gmx@chromium.org>
Gaute Strokkenes <gaute.strokkenes@broadcom.com> Gaute Strokkenes <gaute.strokkenes@broadcom.com>
Geza Lore <gezalore@gmail.com>
Ghislain MARY <ghislainmary2@gmail.com>
Giuseppe Scrivano <gscrivano@gnu.org> Giuseppe Scrivano <gscrivano@gnu.org>
Gordana Cmiljanovic <gordana.cmiljanovic@imgtec.com>
Gregor Jasny <gjasny@gmail.com>
Guillaume Martres <gmartres@google.com> Guillaume Martres <gmartres@google.com>
Guillermo Ballester Valor <gbvalor@gmail.com> Guillermo Ballester Valor <gbvalor@gmail.com>
Hangyu Kuang <hkuang@google.com> Hangyu Kuang <hkuang@google.com>
Hanno Böck <hanno@hboeck.de>
Han Shen <shenhan@google.com>
Henrik Lundin <hlundin@google.com> Henrik Lundin <hlundin@google.com>
Hui Su <huisu@google.com> Hui Su <huisu@google.com>
Ivan Krasin <krasin@chromium.org>
Ivan Maltz <ivanmaltz@google.com> Ivan Maltz <ivanmaltz@google.com>
Jacek Caban <cjacek@gmail.com>
Jacky Chen <jackychen@google.com>
James Berry <jamesberry@google.com> James Berry <jamesberry@google.com>
James Yu <james.yu@linaro.org>
James Zern <jzern@google.com> James Zern <jzern@google.com>
Jan Gerber <j@mailb.org>
Jan Kratochvil <jan.kratochvil@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com>
Janne Salonen <jsalonen@google.com> Janne Salonen <jsalonen@google.com>
Jean-Yves Avenard <jyavenard@mozilla.com>
Jeff Faust <jfaust@google.com> Jeff Faust <jfaust@google.com>
Jeff Muizelaar <jmuizelaar@mozilla.com> Jeff Muizelaar <jmuizelaar@mozilla.com>
Jeff Petkau <jpet@chromium.org> Jeff Petkau <jpet@chromium.org>
Jerome Jiang <jianj@google.com>
Jia Jia <jia.jia@linaro.org>
Jian Zhou <zhoujian@google.com>
Jim Bankoski <jimbankoski@google.com> Jim Bankoski <jimbankoski@google.com>
Jingning Han <jingning@google.com> Jingning Han <jingning@google.com>
Joey Parrish <joeyparrish@google.com>
Johann Koenig <johannkoenig@google.com> Johann Koenig <johannkoenig@google.com>
John Koleszar <jkoleszar@google.com> John Koleszar <jkoleszar@google.com>
Johnny Klonaris <google@jawknee.com>
John Stark <jhnstrk@gmail.com>
Joshua Bleecher Snyder <josh@treelinelabs.com> Joshua Bleecher Snyder <josh@treelinelabs.com>
Joshua Litt <joshualitt@google.com> Joshua Litt <joshualitt@google.com>
Julia Robson <juliamrobson@gmail.com>
Justin Clift <justin@salasaga.org> Justin Clift <justin@salasaga.org>
Justin Lebar <justin.lebar@gmail.com> Justin Lebar <justin.lebar@gmail.com>
Kaustubh Raste <kaustubh.raste@imgtec.com>
KO Myung-Hun <komh@chollian.net> KO Myung-Hun <komh@chollian.net>
Kyle Siefring <kylesiefring@gmail.com>
Lawrence Velázquez <larryv@macports.org>
Linfeng Zhang <linfengz@google.com>
Lou Quillio <louquillio@google.com> Lou Quillio <louquillio@google.com>
Luca Barbato <lu_zero@gentoo.org> Luca Barbato <lu_zero@gentoo.org>
Makoto Kato <makoto.kt@gmail.com> Makoto Kato <makoto.kt@gmail.com>
@ -104,67 +65,36 @@ Michael Kohler <michaelkohler@live.com>
Mike Frysinger <vapier@chromium.org> Mike Frysinger <vapier@chromium.org>
Mike Hommey <mhommey@mozilla.com> Mike Hommey <mhommey@mozilla.com>
Mikhal Shemer <mikhal@google.com> Mikhal Shemer <mikhal@google.com>
Min Chen <chenm003@gmail.com>
Minghai Shang <minghai@google.com>
Min Ye <yeemmi@google.com>
Moriyoshi Koizumi <mozo@mozo.jp>
Morton Jonuschat <yabawock@gmail.com> Morton Jonuschat <yabawock@gmail.com>
Nathan E. Egge <negge@mozilla.com>
Nico Weber <thakis@chromium.org>
Parag Salasakar <img.mips1@gmail.com> Parag Salasakar <img.mips1@gmail.com>
Pascal Massimino <pascal.massimino@gmail.com> Pascal Massimino <pascal.massimino@gmail.com>
Patrik Westin <patrik.westin@gmail.com> Patrik Westin <patrik.westin@gmail.com>
Paul Wilkins <paulwilkins@google.com> Paul Wilkins <paulwilkins@google.com>
Pavol Rusnak <stick@gk2.sk> Pavol Rusnak <stick@gk2.sk>
Paweł Hajdan <phajdan@google.com> Paweł Hajdan <phajdan@google.com>
Pengchong Jin <pengchong@google.com>
Peter Boström <pbos@chromium.org>
Peter Collingbourne <pcc@chromium.org>
Peter de Rivaz <peter.derivaz@gmail.com>
Philip Jägenstedt <philipj@opera.com> Philip Jägenstedt <philipj@opera.com>
Priit Laes <plaes@plaes.org> Priit Laes <plaes@plaes.org>
Rafael Ávila de Espíndola <rafael.espindola@gmail.com> Rafael Ávila de Espíndola <rafael.espindola@gmail.com>
Rafaël Carré <funman@videolan.org> Rafaël Carré <funman@videolan.org>
Rafael de Lucena Valle <rafaeldelucena@gmail.com>
Rahul Chaudhry <rahulchaudhry@google.com>
Ralph Giles <giles@xiph.org> Ralph Giles <giles@xiph.org>
Ranjit Kumar Tulabandu <ranjit.tulabandu@ittiam.com>
Rob Bradford <rob@linux.intel.com> Rob Bradford <rob@linux.intel.com>
Ronald S. Bultje <rsbultje@gmail.com> Ronald S. Bultje <rbultje@google.com>
Rui Ueyama <ruiu@google.com>
Sami Pietilä <samipietila@google.com> Sami Pietilä <samipietila@google.com>
Sarah Parker <sarahparker@google.com>
Sasi Inguva <isasi@google.com>
Scott Graham <scottmg@chromium.org> Scott Graham <scottmg@chromium.org>
Scott LaVarnway <slavarnway@google.com> Scott LaVarnway <slavarnway@google.com>
Sean McGovern <gseanmcg@gmail.com>
Sergey Kolomenkin <kolomenkin@gmail.com>
Sergey Ulanov <sergeyu@chromium.org>
Shimon Doodkin <helpmepro1@gmail.com> Shimon Doodkin <helpmepro1@gmail.com>
Shiyou Yin <yinshiyou-hf@loongson.cn>
Shunyao Li <shunyaoli@google.com>
Stefan Holmer <holmer@google.com> Stefan Holmer <holmer@google.com>
Suman Sunkara <sunkaras@google.com> Suman Sunkara <sunkaras@google.com>
Sylvestre Ledru <sylvestre@mozilla.com>
Taekhyun Kim <takim@nvidia.com> Taekhyun Kim <takim@nvidia.com>
Takanori MATSUURA <t.matsuu@gmail.com> Takanori MATSUURA <t.matsuu@gmail.com>
Tamar Levy <tamar.levy@intel.com> Tamar Levy <tamar.levy@intel.com>
Tao Bai <michaelbai@chromium.org>
Tero Rintaluoma <teror@google.com> Tero Rintaluoma <teror@google.com>
Thijs Vermeir <thijsvermeir@gmail.com> Thijs Vermeir <thijsvermeir@gmail.com>
Tim Kopp <tkopp@google.com>
Timothy B. Terriberry <tterribe@xiph.org> Timothy B. Terriberry <tterribe@xiph.org>
Tom Finegan <tomfinegan@google.com> Tom Finegan <tomfinegan@google.com>
Tristan Matthews <le.businessman@gmail.com>
Urvang Joshi <urvang@google.com>
Vignesh Venkatasubramanian <vigneshv@google.com> Vignesh Venkatasubramanian <vigneshv@google.com>
Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Yaowu Xu <yaowu@google.com> Yaowu Xu <yaowu@google.com>
Yi Luo <luoyi@google.com>
Yongzhe Wang <yongzhe@google.com>
Yunqing Wang <yunqingwang@google.com> Yunqing Wang <yunqingwang@google.com>
Yury Gitman <yuryg@google.com>
Zoe Liu <zoeliu@google.com>
Google Inc. Google Inc.
The Mozilla Foundation The Mozilla Foundation
The Xiph.Org Foundation The Xiph.Org Foundation

111
CHANGELOG
View File

@ -1,114 +1,3 @@
2017-01-04 v1.7.0 "Mandarin Duck"
This release focused on high bit depth performance (10/12 bit) and vp9
encoding improvements.
- Upgrading:
This release is ABI incompatible due to new vp9 encoder features.
Frame parallel decoding for vp9 has been removed.
- Enhancements:
vp9 encoding supports additional threads with --row-mt. This can be greater
than the number of tiles.
Two new vp9 encoder options have been added:
--corpus-complexity
--tune-content=film
Additional tooling for respecting the vp9 "level" profiles has been added.
- Bug fixes:
A variety of fuzzing issues.
vp8 threading fix for ARM.
Codec control VP9_SET_SKIP_LOOP_FILTER fixed.
Reject invalid multi resolution configurations.
2017-01-09 v1.6.1 "Long Tailed Duck"
This release improves upon the VP9 encoder and speeds up the encoding and
decoding processes.
- Upgrading:
This release is ABI compatible with 1.6.0.
- Enhancements:
Faster VP9 encoding and decoding.
High bit depth builds now provide similar speed for 8 bit encode and decode
for x86 targets. Other platforms and higher bit depth improvements are in
progress.
- Bug Fixes:
A variety of fuzzing issues.
2016-07-20 v1.6.0 "Khaki Campbell Duck"
This release improves upon the VP9 encoder and speeds up the encoding and
decoding processes.
- Upgrading:
This release is ABI incompatible with 1.5.0 due to a new 'color_range' enum
in vpx_image and some minor changes to the VP8_COMP structure.
The default key frame interval for VP9 has changed from 128 to 9999.
- Enhancement:
A core focus has been performance for low end Intel processors. SSSE3
instructions such as 'pshufb' have been avoided and instructions have been
reordered to better accommodate the more constrained pipelines.
As a result, devices based on Celeron processors have seen substantial
decoding improvements. From Indian Runner Duck to Javan Whistling Duck,
decoding speed improved between 10 and 30%. Between Javan Whistling Duck
and Khaki Campbell Duck, it improved another 10 to 15%.
While Celeron benefited most, Core-i5 also improved 5% and 10% between the
respective releases.
Realtime performance for WebRTC for both speed and quality has received a
lot of attention.
- Bug Fixes:
A number of fuzzing issues, found variously by Mozilla, Chromium and others,
have been fixed and we strongly recommend updating.
2015-11-09 v1.5.0 "Javan Whistling Duck"
This release improves upon the VP9 encoder and speeds up the encoding and
decoding processes.
- Upgrading:
This release is ABI incompatible with 1.4.0. It drops deprecated VP8
controls and adds a variety of VP9 controls for testing.
The vpxenc utility now prefers VP9 by default.
- Enhancements:
Faster VP9 encoding and decoding
Smaller library size by combining functions used by VP8 and VP9
- Bug Fixes:
A variety of fuzzing issues
2015-04-03 v1.4.0 "Indian Runner Duck"
This release includes significant improvements to the VP9 codec.
- Upgrading:
This release is ABI incompatible with 1.3.0. It drops the compatibility
layer, requiring VPX_IMG_FMT_* instead of IMG_FMT_*, and adds several codec
controls for VP9.
- Enhancements:
Faster VP9 encoding and decoding
Multithreaded VP9 decoding (tile and frame-based)
Multithreaded VP9 encoding - on by default
YUV 4:2:2 and 4:4:4 support in VP9
10 and 12bit support in VP9
64bit ARM support by replacing ARM assembly with intrinsics
- Bug Fixes:
Fixes a VP9 bitstream issue in Profile 1. This only affected non-YUV 4:2:0
files.
- Known Issues:
Frame Parallel decoding fails for segmented and non-420 files.
2013-11-15 v1.3.0 "Forest" 2013-11-15 v1.3.0 "Forest"
This release introduces the VP9 codec in a backward-compatible way. This release introduces the VP9 codec in a backward-compatible way.
All existing users of VP8 can continue to use the library without All existing users of VP8 can continue to use the library without

View File

@ -17,7 +17,7 @@ or agree to the institution of patent litigation or any other patent
enforcement activity against any entity (including a cross-claim or enforcement activity against any entity (including a cross-claim or
counterclaim in a lawsuit) alleging that any of these implementations of WebM counterclaim in a lawsuit) alleging that any of these implementations of WebM
or any code incorporated within any of these implementations of WebM or any code incorporated within any of these implementations of WebM
constitute direct or contributory patent infringement, or inducement of constitutes direct or contributory patent infringement, or inducement of
patent infringement, then any patent rights granted to you under this License patent infringement, then any patent rights granted to you under this License
for these implementations of WebM shall terminate as of the date such for these implementations of WebM shall terminate as of the date such
litigation is filed. litigation is filed.

95
README
View File

@ -1,4 +1,4 @@
README - 24 January 2018 README - 30 May 2014
Welcome to the WebM VP8/VP9 Codec SDK! Welcome to the WebM VP8/VP9 Codec SDK!
@ -9,26 +9,22 @@ COMPILING THE APPLICATIONS/LIBRARIES:
1. Prerequisites 1. Prerequisites
* All x86 targets require the Yasm[1] assembler be installed[2]. * All x86 targets require the Yasm[1] assembler be installed.
* All Windows builds require that Cygwin[3] be installed. * All Windows builds require that Cygwin[2] be installed.
* Building the documentation requires Doxygen[4]. If you do not * Building the documentation requires Doxygen[3]. If you do not
have this package, the install-docs option will be disabled. have this package, the install-docs option will be disabled.
* Downloading the data for the unit tests requires curl[5] and sha1sum. * Downloading the data for the unit tests requires curl[4] and sha1sum.
sha1sum is provided via the GNU coreutils, installed by default on sha1sum is provided via the GNU coreutils, installed by default on
many *nix platforms, as well as MinGW and Cygwin. If coreutils is not many *nix platforms, as well as MinGW and Cygwin. If coreutils is not
available, a compatible version of sha1sum can be built from available, a compatible version of sha1sum can be built from
source[6]. These requirements are optional if not running the unit source[5]. These requirements are optional if not running the unit
tests. tests.
[1]: http://www.tortall.net/projects/yasm [1]: http://www.tortall.net/projects/yasm
[2]: For Visual Studio the base yasm binary (not vsyasm) should be in the [2]: http://www.cygwin.com
PATH for Visual Studio. For VS2017 it is sufficient to rename [3]: http://www.doxygen.org
yasm-<version>-<arch>.exe to yasm.exe and place it in: [4]: http://curl.haxx.se
Program Files (x86)/Microsoft Visual Studio/2017/<level>/Common7/Tools/ [5]: http://www.microbrew.org/tools/md5sha1sum/
[3]: http://www.cygwin.com
[4]: http://www.doxygen.org
[5]: http://curl.haxx.se
[6]: http://www.microbrew.org/tools/md5sha1sum/
2. Out-of-tree builds 2. Out-of-tree builds
Out of tree builds are a supported method of building the application. For Out of tree builds are a supported method of building the application. For
@ -45,24 +41,21 @@ COMPILING THE APPLICATIONS/LIBRARIES:
used to get a list of supported options: used to get a list of supported options:
$ ../libvpx/configure --help $ ../libvpx/configure --help
4. Compiler analyzers 4. Cross development
Compilers have added sanitizers which instrument binaries with information
about address calculation, memory usage, threading, undefined behavior, and
other common errors. To simplify building libvpx with some of these features
use tools/set_analyzer_env.sh before running configure. It will set the
compiler and necessary flags for building as well as environment variables
read by the analyzer when testing the binaries.
$ source ../libvpx/tools/set_analyzer_env.sh address
5. Cross development
For cross development, the most notable option is the --target option. The For cross development, the most notable option is the --target option. The
most up-to-date list of supported targets can be found at the bottom of the most up-to-date list of supported targets can be found at the bottom of the
--help output of the configure script. As of this writing, the list of --help output of the configure script. As of this writing, the list of
available targets is: available targets is:
arm64-android-gcc armv5te-android-gcc
armv5te-linux-rvct
armv5te-linux-gcc
armv5te-none-rvct
armv6-darwin-gcc
armv6-linux-rvct
armv6-linux-gcc
armv6-none-rvct
arm64-darwin-gcc arm64-darwin-gcc
arm64-linux-gcc
armv7-android-gcc armv7-android-gcc
armv7-darwin-gcc armv7-darwin-gcc
armv7-linux-rvct armv7-linux-rvct
@ -70,14 +63,15 @@ COMPILING THE APPLICATIONS/LIBRARIES:
armv7-none-rvct armv7-none-rvct
armv7-win32-vs11 armv7-win32-vs11
armv7-win32-vs12 armv7-win32-vs12
armv7-win32-vs14
armv7-win32-vs15
armv7s-darwin-gcc armv7s-darwin-gcc
armv8-linux-gcc
mips32-linux-gcc mips32-linux-gcc
mips64-linux-gcc mips64-linux-gcc
ppc32-darwin8-gcc
ppc32-darwin9-gcc
ppc32-linux-gcc
ppc64-darwin8-gcc
ppc64-darwin9-gcc
ppc64-linux-gcc ppc64-linux-gcc
ppc64le-linux-gcc
sparc-solaris-gcc sparc-solaris-gcc
x86-android-gcc x86-android-gcc
x86-darwin8-gcc x86-darwin8-gcc
@ -88,39 +82,39 @@ COMPILING THE APPLICATIONS/LIBRARIES:
x86-darwin11-gcc x86-darwin11-gcc
x86-darwin12-gcc x86-darwin12-gcc
x86-darwin13-gcc x86-darwin13-gcc
x86-darwin14-gcc
x86-darwin15-gcc
x86-darwin16-gcc
x86-iphonesimulator-gcc x86-iphonesimulator-gcc
x86-linux-gcc x86-linux-gcc
x86-linux-icc x86-linux-icc
x86-os2-gcc x86-os2-gcc
x86-solaris-gcc x86-solaris-gcc
x86-win32-gcc x86-win32-gcc
x86-win32-vs7
x86-win32-vs8
x86-win32-vs9
x86-win32-vs10 x86-win32-vs10
x86-win32-vs11 x86-win32-vs11
x86-win32-vs12 x86-win32-vs12
x86-win32-vs14
x86-win32-vs15
x86_64-android-gcc
x86_64-darwin9-gcc x86_64-darwin9-gcc
x86_64-darwin10-gcc x86_64-darwin10-gcc
x86_64-darwin11-gcc x86_64-darwin11-gcc
x86_64-darwin12-gcc x86_64-darwin12-gcc
x86_64-darwin13-gcc x86_64-darwin13-gcc
x86_64-darwin14-gcc
x86_64-darwin15-gcc
x86_64-darwin16-gcc
x86_64-iphonesimulator-gcc x86_64-iphonesimulator-gcc
x86_64-linux-gcc x86_64-linux-gcc
x86_64-linux-icc x86_64-linux-icc
x86_64-solaris-gcc x86_64-solaris-gcc
x86_64-win64-gcc x86_64-win64-gcc
x86_64-win64-vs8
x86_64-win64-vs9
x86_64-win64-vs10 x86_64-win64-vs10
x86_64-win64-vs11 x86_64-win64-vs11
x86_64-win64-vs12 x86_64-win64-vs12
x86_64-win64-vs14 universal-darwin8-gcc
x86_64-win64-vs15 universal-darwin9-gcc
universal-darwin10-gcc
universal-darwin11-gcc
universal-darwin12-gcc
universal-darwin13-gcc
generic-gnu generic-gnu
The generic-gnu target, in conjunction with the CROSS environment variable, The generic-gnu target, in conjunction with the CROSS environment variable,
@ -136,7 +130,7 @@ COMPILING THE APPLICATIONS/LIBRARIES:
environment variables: CC, AR, LD, AS, STRIP, NM. Additional flags can be environment variables: CC, AR, LD, AS, STRIP, NM. Additional flags can be
passed to these executables with CFLAGS, LDFLAGS, and ASFLAGS. passed to these executables with CFLAGS, LDFLAGS, and ASFLAGS.
6. Configuration errors 5. Configuration errors
If the configuration step fails, the first step is to look in the error log. If the configuration step fails, the first step is to look in the error log.
This defaults to config.log. This should give a good indication of what went This defaults to config.log. This should give a good indication of what went
wrong. If not, contact us for support. wrong. If not, contact us for support.
@ -149,22 +143,7 @@ VP8/VP9 TEST VECTORS:
$ ./configure --enable-unit-tests $ ./configure --enable-unit-tests
$ LIBVPX_TEST_DATA_PATH=../libvpx-test-data make testdata $ LIBVPX_TEST_DATA_PATH=../libvpx-test-data make testdata
CODE STYLE:
The coding style used by this project is enforced with clang-format using the
configuration contained in the .clang-format file in the root of the
repository.
Before pushing changes for review you can format your code with:
# Apply clang-format to modified .c, .h and .cc files
$ clang-format -i --style=file \
$(git diff --name-only --diff-filter=ACMR '*.[hc]' '*.cc')
Check the .clang-format file for the version used to generate it if there is
any difference between your local formatting and the review system.
See also: http://clang.llvm.org/docs/ClangFormat.html
SUPPORT SUPPORT
This library is an open source project supported by its community. Please This library is an open source project supported by its community. Please
email webm-discuss@webmproject.org for help. please email webm-discuss@webmproject.org for help.

131
args.c
View File

@ -8,13 +8,15 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include "args.h" #include "args.h"
#include "vpx/vpx_integer.h" #ifdef _MSC_VER
#include "vpx_ports/msvc.h" #define snprintf _snprintf
#endif
#if defined(__GNUC__) && __GNUC__ #if defined(__GNUC__) && __GNUC__
extern void die(const char *fmt, ...) __attribute__((noreturn)); extern void die(const char *fmt, ...) __attribute__((noreturn));
@ -22,36 +24,42 @@ extern void die(const char *fmt, ...) __attribute__((noreturn));
extern void die(const char *fmt, ...); extern void die(const char *fmt, ...);
#endif #endif
struct arg arg_init(char **argv) { struct arg arg_init(char **argv) {
struct arg a; struct arg a;
a.argv = argv; a.argv = argv;
a.argv_step = 1; a.argv_step = 1;
a.name = NULL; a.name = NULL;
a.val = NULL; a.val = NULL;
a.def = NULL; a.def = NULL;
return a; return a;
} }
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) { int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
struct arg arg; struct arg arg;
if (!argv[0] || argv[0][0] != '-') return 0; if (!argv[0] || argv[0][0] != '-')
return 0;
arg = arg_init(argv); arg = arg_init(argv);
if (def->short_name && strlen(arg.argv[0]) == strlen(def->short_name) + 1 && if (def->short_name
!strcmp(arg.argv[0] + 1, def->short_name)) { && strlen(arg.argv[0]) == strlen(def->short_name) + 1
&& !strcmp(arg.argv[0] + 1, def->short_name)) {
arg.name = arg.argv[0] + 1; arg.name = arg.argv[0] + 1;
arg.val = def->has_val ? arg.argv[1] : NULL; arg.val = def->has_val ? arg.argv[1] : NULL;
arg.argv_step = def->has_val ? 2 : 1; arg.argv_step = def->has_val ? 2 : 1;
} else if (def->long_name) { } else if (def->long_name) {
const size_t name_len = strlen(def->long_name); const size_t name_len = strlen(def->long_name);
if (strlen(arg.argv[0]) >= name_len + 2 && arg.argv[0][1] == '-' && if (strlen(arg.argv[0]) >= name_len + 2
!strncmp(arg.argv[0] + 2, def->long_name, name_len) && && arg.argv[0][1] == '-'
(arg.argv[0][name_len + 2] == '=' || && !strncmp(arg.argv[0] + 2, def->long_name, name_len)
arg.argv[0][name_len + 2] == '\0')) { && (arg.argv[0][name_len + 2] == '='
|| arg.argv[0][name_len + 2] == '\0')) {
arg.name = arg.argv[0] + 2; arg.name = arg.argv[0] + 2;
arg.val = arg.name[name_len] == '=' ? arg.name + name_len + 1 : NULL; arg.val = arg.name[name_len] == '=' ? arg.name + name_len + 1 : NULL;
arg.argv_step = 1; arg.argv_step = 1;
@ -64,7 +72,8 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
if (arg.name && arg.val && !def->has_val) if (arg.name && arg.val && !def->has_val)
die("Error: option %s requires no argument.\n", arg.name); die("Error: option %s requires no argument.\n", arg.name);
if (arg.name && (arg.val || !def->has_val)) { if (arg.name
&& (arg.val || !def->has_val)) {
arg.def = def; arg.def = def;
*arg_ = arg; *arg_ = arg;
return 1; return 1;
@ -73,12 +82,15 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
return 0; return 0;
} }
const char *arg_next(struct arg *arg) { const char *arg_next(struct arg *arg) {
if (arg->argv[0]) arg->argv += arg->argv_step; if (arg->argv[0])
arg->argv += arg->argv_step;
return *arg->argv; return *arg->argv;
} }
char **argv_dup(int argc, const char **argv) { char **argv_dup(int argc, const char **argv) {
char **new_argv = malloc((argc + 1) * sizeof(*argv)); char **new_argv = malloc((argc + 1) * sizeof(*argv));
@ -87,8 +99,9 @@ char **argv_dup(int argc, const char **argv) {
return new_argv; return new_argv;
} }
void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
char option_text[40] = { 0 }; char option_text[40] = {0};
for (; *defs; defs++) { for (; *defs; defs++) {
const struct arg_def *def = *defs; const struct arg_def *def = *defs;
@ -98,12 +111,15 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
if (def->short_name && def->long_name) { if (def->short_name && def->long_name) {
char *comma = def->has_val ? "," : ", "; char *comma = def->has_val ? "," : ", ";
snprintf(option_text, 37, "-%s%s%s --%s%6s", def->short_name, short_val, snprintf(option_text, 37, "-%s%s%s --%s%6s",
comma, def->long_name, long_val); def->short_name, short_val, comma,
def->long_name, long_val);
} else if (def->short_name) } else if (def->short_name)
snprintf(option_text, 37, "-%s%s", def->short_name, short_val); snprintf(option_text, 37, "-%s%s",
def->short_name, short_val);
else if (def->long_name) else if (def->long_name)
snprintf(option_text, 37, " --%s%s", def->long_name, long_val); snprintf(option_text, 37, " --%s%s",
def->long_name, long_val);
fprintf(fp, " %-37s\t%s\n", option_text, def->desc); fprintf(fp, " %-37s\t%s\n", option_text, def->desc);
@ -113,103 +129,110 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
fprintf(fp, " %-37s\t ", ""); fprintf(fp, " %-37s\t ", "");
for (listptr = def->enums; listptr->name; listptr++) for (listptr = def->enums; listptr->name; listptr++)
fprintf(fp, "%s%s", listptr->name, listptr[1].name ? ", " : "\n"); fprintf(fp, "%s%s", listptr->name,
listptr[1].name ? ", " : "\n");
} }
} }
} }
unsigned int arg_parse_uint(const struct arg *arg) {
uint32_t rawval;
char *endptr;
rawval = (uint32_t)strtoul(arg->val, &endptr, 10); unsigned int arg_parse_uint(const struct arg *arg) {
long int rawval;
char *endptr;
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval <= UINT_MAX) return rawval; if (rawval >= 0 && rawval <= UINT_MAX)
return rawval;
die("Option %s: Value %ld out of range for unsigned int\n", arg->name, die("Option %s: Value %ld out of range for unsigned int\n",
rawval); arg->name, rawval);
} }
die("Option %s: Invalid character '%c'\n", arg->name, *endptr); die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
return 0; return 0;
} }
int arg_parse_int(const struct arg *arg) { int arg_parse_int(const struct arg *arg) {
int32_t rawval; long int rawval;
char *endptr; char *endptr;
rawval = (int32_t)strtol(arg->val, &endptr, 10); rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX) return (int)rawval; if (rawval >= INT_MIN && rawval <= INT_MAX)
return rawval;
die("Option %s: Value %ld out of range for signed int\n", arg->name, die("Option %s: Value %ld out of range for signed int\n",
rawval); arg->name, rawval);
} }
die("Option %s: Invalid character '%c'\n", arg->name, *endptr); die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
return 0; return 0;
} }
struct vpx_rational { struct vpx_rational {
int num; /**< fraction numerator */ int num; /**< fraction numerator */
int den; /**< fraction denominator */ int den; /**< fraction denominator */
}; };
struct vpx_rational arg_parse_rational(const struct arg *arg) { struct vpx_rational arg_parse_rational(const struct arg *arg) {
long int rawval; long int rawval;
char *endptr; char *endptr;
struct vpx_rational rat; struct vpx_rational rat;
/* parse numerator */ /* parse numerator */
rawval = strtol(arg->val, &endptr, 10); rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '/') { if (arg->val[0] != '\0' && endptr[0] == '/') {
if (rawval >= INT_MIN && rawval <= INT_MAX) if (rawval >= INT_MIN && rawval <= INT_MAX)
rat.num = (int)rawval; rat.num = rawval;
else else die("Option %s: Value %ld out of range for signed int\n",
die("Option %s: Value %ld out of range for signed int\n", arg->name, arg->name, rawval);
rawval); } else die("Option %s: Expected / at '%c'\n", arg->name, *endptr);
} else
die("Option %s: Expected / at '%c'\n", arg->name, *endptr);
/* parse denominator */ /* parse denominator */
rawval = strtol(endptr + 1, &endptr, 10); rawval = strtol(endptr + 1, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX) if (rawval >= INT_MIN && rawval <= INT_MAX)
rat.den = (int)rawval; rat.den = rawval;
else else die("Option %s: Value %ld out of range for signed int\n",
die("Option %s: Value %ld out of range for signed int\n", arg->name, arg->name, rawval);
rawval); } else die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
} else
die("Option %s: Invalid character '%c'\n", arg->name, *endptr);
return rat; return rat;
} }
int arg_parse_enum(const struct arg *arg) { int arg_parse_enum(const struct arg *arg) {
const struct arg_enum_list *listptr; const struct arg_enum_list *listptr;
long int rawval; long int rawval;
char *endptr; char *endptr;
/* First see if the value can be parsed as a raw value */ /* First see if the value can be parsed as a raw value */
rawval = strtol(arg->val, &endptr, 10); rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
/* Got a raw value, make sure it's valid */ /* Got a raw value, make sure it's valid */
for (listptr = arg->def->enums; listptr->name; listptr++) for (listptr = arg->def->enums; listptr->name; listptr++)
if (listptr->val == rawval) return (int)rawval; if (listptr->val == rawval)
return rawval;
} }
/* Next see if it can be parsed as a string */ /* Next see if it can be parsed as a string */
for (listptr = arg->def->enums; listptr->name; listptr++) for (listptr = arg->def->enums; listptr->name; listptr++)
if (!strcmp(arg->val, listptr->name)) return listptr->val; if (!strcmp(arg->val, listptr->name))
return listptr->val;
die("Option %s: Invalid value '%s'\n", arg->name, arg->val); die("Option %s: Invalid value '%s'\n", arg->name, arg->val);
return 0; return 0;
} }
int arg_parse_enum_or_int(const struct arg *arg) { int arg_parse_enum_or_int(const struct arg *arg) {
if (arg->def->enums) return arg_parse_enum(arg); if (arg->def->enums)
return arg_parse_enum(arg);
return arg_parse_int(arg); return arg_parse_int(arg);
} }

27
args.h
View File

@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef ARGS_H_ #ifndef ARGS_H_
#define ARGS_H_ #define ARGS_H_
#include <stdio.h> #include <stdio.h>
@ -17,33 +18,29 @@ extern "C" {
#endif #endif
struct arg { struct arg {
char **argv; char **argv;
const char *name; const char *name;
const char *val; const char *val;
unsigned int argv_step; unsigned int argv_step;
const struct arg_def *def; const struct arg_def *def;
}; };
struct arg_enum_list { struct arg_enum_list {
const char *name; const char *name;
int val; int val;
}; };
#define ARG_ENUM_LIST_END \ #define ARG_ENUM_LIST_END {0}
{ 0 }
typedef struct arg_def { typedef struct arg_def {
const char *short_name; const char *short_name;
const char *long_name; const char *long_name;
int has_val; int has_val;
const char *desc; const char *desc;
const struct arg_enum_list *enums; const struct arg_enum_list *enums;
} arg_def_t; } arg_def_t;
#define ARG_DEF(s, l, v, d) \ #define ARG_DEF(s,l,v,d) {s,l,v,d, NULL}
{ s, l, v, d, NULL } #define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e}
#define ARG_DEF_ENUM(s, l, v, d, e) \ #define ARG_DEF_LIST_END {0}
{ s, l, v, d, e }
#define ARG_DEF_LIST_END \
{ 0 }
struct arg arg_init(char **argv); struct arg arg_init(char **argv);
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); int arg_match(struct arg *arg_, const struct arg_def *def, char **argv);

2
build/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*-vs8/*.rules -crlf
*-msvs/*.rules -crlf

1
build/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
x86*-win32-vs*

View File

@ -0,0 +1,18 @@
REM Copyright (c) 2013 The WebM project authors. All Rights Reserved.
REM
REM Use of this source code is governed by a BSD-style license
REM that can be found in the LICENSE file in the root of the source
REM tree. An additional intellectual property rights grant can be found
REM in the file PATENTS. All contributing project authors may
REM be found in the AUTHORS file in the root of the source tree.
echo on
REM Arguments:
REM %1 - Relative path to the directory containing the vp8 and vpx_scale
REM source directories.
REM %2 - Path to obj_int_extract.exe.
cl /I. /I%1 /nologo /c /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP "%~1/vp8/encoder/vp8_asm_enc_offsets.c"
%2\obj_int_extract.exe rvds "vp8_asm_enc_offsets.obj" > "vp8_asm_enc_offsets.asm"
cl /I. /I%1 /nologo /c /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP "%~1/vpx_scale/vpx_scale_asm_offsets.c"
%2\obj_int_extract.exe rvds "vpx_scale_asm_offsets.obj" > "vpx_scale_asm_offsets.asm"

View File

@ -29,6 +29,11 @@
# include $(CLEAR_VARS) # include $(CLEAR_VARS)
# include jni/libvpx/build/make/Android.mk # include jni/libvpx/build/make/Android.mk
# #
# There are currently two TARGET_ARCH_ABI targets for ARM.
# armeabi and armeabi-v7a. armeabi-v7a is selected by creating an
# Application.mk in the jni directory that contains:
# APP_ABI := armeabi-v7a
#
# By default libvpx will detect at runtime the existance of NEON extension. # By default libvpx will detect at runtime the existance of NEON extension.
# For this we import the 'cpufeatures' module from the NDK sources. # For this we import the 'cpufeatures' module from the NDK sources.
# libvpx can also be configured without this runtime detection method. # libvpx can also be configured without this runtime detection method.
@ -37,49 +42,31 @@
# --disable-neon-asm # --disable-neon-asm
# will remove any NEON dependency. # will remove any NEON dependency.
# To change to building armeabi, run ./libvpx/configure again, but with
# --target=arm5te-android-gcc and modify the Application.mk file to
# set APP_ABI := armeabi
# #
# Running ndk-build will build libvpx and include it in your project. # Running ndk-build will build libvpx and include it in your project.
# #
# Alternatively, building the examples and unit tests can be accomplished in the
# following way:
#
# Create a standalone toolchain from the NDK:
# https://developer.android.com/ndk/guides/standalone_toolchain.html
#
# For example - to test on arm64 devices with clang:
# $NDK/build/tools/make_standalone_toolchain.py \
# --arch arm64 --install-dir=/tmp/my-android-toolchain
# export PATH=/tmp/my-android-toolchain/bin:$PATH
# CROSS=aarch64-linux-android- CC=clang CXX=clang++ /path/to/libvpx/configure \
# --target=arm64-android-gcc
#
# Push the resulting binaries to a device and run them:
# adb push test_libvpx /data/tmp/test_libvpx
# adb shell /data/tmp/test_libvpx --gtest_filter=\*Sixtap\*
#
# Make sure to push the test data as well and set LIBVPX_TEST_DATA
CONFIG_DIR := $(LOCAL_PATH)/ CONFIG_DIR := $(LOCAL_PATH)/
LIBVPX_PATH := $(LOCAL_PATH)/libvpx LIBVPX_PATH := $(LOCAL_PATH)/libvpx
ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL) ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
ifneq ($(V),1)
qexec := @
endif
# Use the makefiles generated by upstream configure to determine which files to # Use the makefiles generated by upstream configure to determine which files to
# build. Also set any architecture-specific flags. # build. Also set any architecture-specific flags.
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
include $(CONFIG_DIR)libs-armv7-android-gcc.mk include $(CONFIG_DIR)libs-armv7-android-gcc.mk
LOCAL_ARM_MODE := arm LOCAL_ARM_MODE := arm
else ifeq ($(TARGET_ARCH_ABI),armeabi)
include $(CONFIG_DIR)libs-armv5te-android-gcc.mk
LOCAL_ARM_MODE := arm
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a) else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
include $(CONFIG_DIR)libs-arm64-android-gcc.mk include $(CONFIG_DIR)libs-armv8-android-gcc.mk
LOCAL_ARM_MODE := arm LOCAL_ARM_MODE := arm
else ifeq ($(TARGET_ARCH_ABI),x86) else ifeq ($(TARGET_ARCH_ABI),x86)
include $(CONFIG_DIR)libs-x86-android-gcc.mk include $(CONFIG_DIR)libs-x86-android-gcc.mk
else ifeq ($(TARGET_ARCH_ABI),x86_64)
include $(CONFIG_DIR)libs-x86_64-android-gcc.mk
else ifeq ($(TARGET_ARCH_ABI),mips) else ifeq ($(TARGET_ARCH_ABI),mips)
include $(CONFIG_DIR)libs-mips-android-gcc.mk include $(CONFIG_DIR)libs-mips-android-gcc.mk
else else
@ -104,10 +91,53 @@ LOCAL_CFLAGS := -O3
# like x86inc.asm and x86_abi_support.asm # like x86inc.asm and x86_abi_support.asm
LOCAL_ASMFLAGS := -I$(LIBVPX_PATH) LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
.PRECIOUS: %.asm.S # -----------------------------------------------------------------------------
$(ASM_CNV_PATH)/libvpx/%.asm.S: $(LIBVPX_PATH)/%.asm # Template : asm_offsets_template
$(qexec)mkdir -p $(dir $@) # Arguments : 1: assembly offsets file to be created
$(qexec)$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@ # 2: c file to base assembly offsets on
# Returns : None
# Usage : $(eval $(call asm_offsets_template,<asmfile>, <srcfile>
# Rationale : Create offsets at compile time using for structures that are
# defined in c, but used in assembly functions.
# -----------------------------------------------------------------------------
define asm_offsets_template
_SRC:=$(2)
_OBJ:=$(ASM_CNV_PATH)/$$(notdir $(2)).S
_FLAGS = $$($$(my)CFLAGS) \
$$(call get-src-file-target-cflags,$(2)) \
$$(call host-c-includes,$$(LOCAL_C_INCLUDES) $$(CONFIG_DIR)) \
$$(LOCAL_CFLAGS) \
$$(NDK_APP_CFLAGS) \
$$(call host-c-includes,$$($(my)C_INCLUDES)) \
-DINLINE_ASM \
-S \
_TEXT = "Compile $$(call get-src-file-text,$(2))"
_CC = $$(TARGET_CC)
$$(eval $$(call ev-build-file))
$(1) : $$(_OBJ) $(2)
@mkdir -p $$(dir $$@)
@grep $(OFFSET_PATTERN) $$< | tr -d '\#' | $(CONFIG_DIR)$(ASM_CONVERSION) > $$@
endef
# Use ads2gas script to convert from RVCT format to GAS format. This
# puts the processed file under $(ASM_CNV_PATH). Local clean rule
# to handle removing these
ifeq ($(CONFIG_VP8_ENCODER), yes)
ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm
endif
ifeq ($(HAVE_NEON_ASM), yes)
ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm
endif
.PRECIOUS: %.asm.s
$(ASM_CNV_PATH)/libvpx/%.asm.s: $(LIBVPX_PATH)/%.asm $(ASM_CNV_OFFSETS_DEPEND)
@mkdir -p $(dir $@)
@$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
# For building *_rtcd.h, which have rules in libs.mk # For building *_rtcd.h, which have rules in libs.mk
TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN))) TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
@ -135,7 +165,7 @@ endif
# Pull out assembly files, splitting NEON from the rest. This is # Pull out assembly files, splitting NEON from the rest. This is
# done to specify that the NEON assembly files use NEON assembler flags. # done to specify that the NEON assembly files use NEON assembler flags.
# x86 assembly matches %.asm, arm matches %.asm.S # x86 assembly matches %.asm, arm matches %.asm.s
# x86: # x86:
@ -143,86 +173,75 @@ CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file)) LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
# arm: # arm:
CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.S, $(CODEC_SRCS_UNIQUE)) CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
CODEC_SRCS_ASM_ARM = $(foreach v, \ CODEC_SRCS_ASM_ARM = $(foreach v, \
$(CODEC_SRCS_ASM_ARM_ALL), \ $(CODEC_SRCS_ASM_ARM_ALL), \
$(if $(findstring neon,$(v)),,$(v))) $(if $(findstring neon,$(v)),,$(v)))
CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.S, \ CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
$(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \ $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
$(CODEC_SRCS_ASM_ARM)) $(CODEC_SRCS_ASM_ARM))
LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS) LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
ASM_INCLUDES := vpx_dsp/arm/idct_neon.asm.S
CODEC_SRCS_ASM_NEON = $(foreach v, \ CODEC_SRCS_ASM_NEON = $(foreach v, \
$(CODEC_SRCS_ASM_ARM_ALL),\ $(CODEC_SRCS_ASM_ARM_ALL),\
$(if $(findstring neon,$(v)),$(v),)) $(if $(findstring neon,$(v)),$(v),))
CODEC_SRCS_ASM_NEON := $(filter-out $(addprefix %, $(ASM_INCLUDES)), \ CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
$(CODEC_SRCS_ASM_NEON)) $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.S, \
$(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \
$(CODEC_SRCS_ASM_NEON)) $(CODEC_SRCS_ASM_NEON))
LOCAL_SRC_FILES += $(patsubst %.S, \ LOCAL_SRC_FILES += $(patsubst %.s, \
%.S.neon, \ %.s.neon, \
$(CODEC_SRCS_ASM_NEON_ADS2GAS)) $(CODEC_SRCS_ASM_NEON_ADS2GAS))
NEON_ASM_TARGETS = $(patsubst %.S, \
$(ASM_CNV_PATH)/libvpx/%.S, \
$(CODEC_SRCS_ASM_NEON))
# add a dependency to the full path to the ads2gas output to ensure the
# includes are converted first.
ifneq ($(strip $(NEON_ASM_TARGETS)),)
$(NEON_ASM_TARGETS): $(addprefix $(ASM_CNV_PATH)/libvpx/, $(ASM_INCLUDES))
endif
endif endif
LOCAL_CFLAGS += \ LOCAL_CFLAGS += \
-DHAVE_CONFIG_H=vpx_config.h \ -DHAVE_CONFIG_H=vpx_config.h \
-I$(LIBVPX_PATH) \ -I$(LIBVPX_PATH) \
-I$(ASM_CNV_PATH) \ -I$(ASM_CNV_PATH)
-I$(ASM_CNV_PATH)/libvpx
LOCAL_MODULE := libvpx LOCAL_MODULE := libvpx
LOCAL_LDLIBS := -llog
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes) ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
LOCAL_STATIC_LIBRARIES := cpufeatures LOCAL_STATIC_LIBRARIES := cpufeatures
endif endif
# Add a dependency to force generation of the RTCD files. # Add a dependency to force generation of the RTCD files.
define rtcd_dep_template
rtcd_dep_template_SRCS := $(addprefix $(LOCAL_PATH)/, $(LOCAL_SRC_FILES))
rtcd_dep_template_SRCS := $$(rtcd_dep_template_SRCS:.neon=)
ifeq ($(CONFIG_VP8), yes) ifeq ($(CONFIG_VP8), yes)
$$(rtcd_dep_template_SRCS): vp8_rtcd.h $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp8_rtcd.h
endif endif
ifeq ($(CONFIG_VP9), yes) ifeq ($(CONFIG_VP9), yes)
$$(rtcd_dep_template_SRCS): vp9_rtcd.h $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp9_rtcd.h
endif endif
$$(rtcd_dep_template_SRCS): vpx_scale_rtcd.h $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_scale_rtcd.h
$$(rtcd_dep_template_SRCS): vpx_dsp_rtcd.h
rtcd_dep_template_CONFIG_ASM_ABIS := x86 x86_64 armeabi-v7a ifeq ($(TARGET_ARCH_ABI),x86)
ifneq ($$(findstring $(TARGET_ARCH_ABI),$$(rtcd_dep_template_CONFIG_ASM_ABIS)),) $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_config.asm
$$(rtcd_dep_template_SRCS): vpx_config.asm
endif endif
endef
$(eval $(call rtcd_dep_template))
.PHONY: clean .PHONY: clean
clean: clean:
@echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]" @echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
$(qexec)$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS) @$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
$(qexec)$(RM) -r $(ASM_CNV_PATH) @$(RM) $(patsubst %.asm, %.*, $(ASM_CNV_OFFSETS_DEPEND))
$(qexec)$(RM) $(CLEAN-OBJS) @$(RM) -r $(ASM_CNV_PATH)
@$(RM) $(CLEAN-OBJS)
ifeq ($(ENABLE_SHARED),1) include $(BUILD_SHARED_LIBRARY)
LOCAL_CFLAGS += -fPIC
include $(BUILD_SHARED_LIBRARY) ifeq ($(HAVE_NEON), yes)
else $(eval $(call asm_offsets_template,\
include $(BUILD_STATIC_LIBRARY) $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm, \
$(LIBVPX_PATH)/vpx_scale/vpx_scale_asm_offsets.c))
endif
ifeq ($(CONFIG_VP8_ENCODER), yes)
$(eval $(call asm_offsets_template,\
$(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm, \
$(LIBVPX_PATH)/vp8/encoder/vp8_asm_enc_offsets.c))
endif endif
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes) ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
$(call import-module,android/cpufeatures) $(call import-module,cpufeatures)
endif endif

View File

@ -22,11 +22,9 @@ clean:: .DEFAULT
exampletest: .DEFAULT exampletest: .DEFAULT
install:: .DEFAULT install:: .DEFAULT
test:: .DEFAULT test:: .DEFAULT
test-no-data-check:: .DEFAULT
testdata:: .DEFAULT testdata:: .DEFAULT
utiltest: .DEFAULT utiltest: .DEFAULT
exampletest-no-data-check utiltest-no-data-check: .DEFAULT
test_%: .DEFAULT ;
# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be # Note: md5sum is not installed on OS X, but openssl is. Openssl may not be
# installed on cygwin, so we need to autodetect here. # installed on cygwin, so we need to autodetect here.
@ -58,10 +56,13 @@ dist:
fi fi
endif endif
# Since we invoke make recursively for multiple targets we need to include the
# .mk file for the correct target, but only when $(target) is non-empty.
ifneq ($(target),) ifneq ($(target),)
include $(target)-$(TOOLCHAIN).mk # Normally, we want to build the filename from the target and the toolchain.
# This disambiguates from the $(target).mk file that exists in the source tree.
# However, the toolchain is part of the target in universal builds, so we
# don't want to include TOOLCHAIN in that case. FAT_ARCHS is used to test
# if we're in the universal case.
include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk
endif endif
BUILD_ROOT?=. BUILD_ROOT?=.
VPATH=$(SRC_PATH_BARE) VPATH=$(SRC_PATH_BARE)
@ -90,7 +91,7 @@ all:
.PHONY: clean .PHONY: clean
clean:: clean::
rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.S.o=.asm.S) rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s)
rm -f $(CLEAN-OBJS) rm -f $(CLEAN-OBJS)
.PHONY: clean .PHONY: clean
@ -115,36 +116,28 @@ test::
testdata:: testdata::
.PHONY: utiltest .PHONY: utiltest
utiltest: utiltest:
.PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check
test-no-data-check::
exampletest-no-data-check utiltest-no-data-check:
# Force to realign stack always on OS/2 # Add compiler flags for intrinsic files
ifeq ($(TOOLCHAIN), x86-os2-gcc) ifeq ($(TOOLCHAIN), x86-os2-gcc)
CFLAGS += -mstackrealign STACKREALIGN=-mstackrealign
else
STACKREALIGN=
endif endif
# x86[_64]
$(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx $(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx
$(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx $(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx
$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 $(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 $(STACKREALIGN)
$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2 $(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2 $(STACKREALIGN)
$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3 $(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3 $(STACKREALIGN)
$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3 $(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3 $(STACKREALIGN)
$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3 $(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3 $(STACKREALIGN)
$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3 $(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3 $(STACKREALIGN)
$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1 $(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1 $(STACKREALIGN)
$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1 $(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1 $(STACKREALIGN)
$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx $(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx $(STACKREALIGN)
$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx $(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx $(STACKREALIGN)
$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2 $(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2 $(STACKREALIGN)
$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 $(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 $(STACKREALIGN)
$(BUILD_PFX)%_avx512.c.d: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl
$(BUILD_PFX)%_avx512.c.o: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl
# POWER
$(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx
$(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx
$(BUILD_PFX)%.c.d: %.c $(BUILD_PFX)%.c.d: %.c
$(if $(quiet),@echo " [DEP] $@") $(if $(quiet),@echo " [DEP] $@")
@ -153,7 +146,6 @@ $(BUILD_PFX)%.c.d: %.c
$(BUILD_PFX)%.c.o: %.c $(BUILD_PFX)%.c.o: %.c
$(if $(quiet),@echo " [CC] $@") $(if $(quiet),@echo " [CC] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $< $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
$(BUILD_PFX)%.cc.d: %.cc $(BUILD_PFX)%.cc.d: %.cc
@ -163,7 +155,6 @@ $(BUILD_PFX)%.cc.d: %.cc
$(BUILD_PFX)%.cc.o: %.cc $(BUILD_PFX)%.cc.o: %.cc
$(if $(quiet),@echo " [CXX] $@") $(if $(quiet),@echo " [CXX] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(BUILD_PFX)%.cpp.d: %.cpp $(BUILD_PFX)%.cpp.d: %.cpp
@ -173,7 +164,6 @@ $(BUILD_PFX)%.cpp.d: %.cpp
$(BUILD_PFX)%.cpp.o: %.cpp $(BUILD_PFX)%.cpp.o: %.cpp
$(if $(quiet),@echo " [CXX] $@") $(if $(quiet),@echo " [CXX] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(BUILD_PFX)%.asm.d: %.asm $(BUILD_PFX)%.asm.d: %.asm
@ -184,29 +174,26 @@ $(BUILD_PFX)%.asm.d: %.asm
$(BUILD_PFX)%.asm.o: %.asm $(BUILD_PFX)%.asm.o: %.asm
$(if $(quiet),@echo " [AS] $@") $(if $(quiet),@echo " [AS] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(AS) $(ASFLAGS) -o $@ $< $(qexec)$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_PFX)%.S.d: %.S $(BUILD_PFX)%.s.d: %.s
$(if $(quiet),@echo " [DEP] $@") $(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@) $(qexec)mkdir -p $(dir $@)
$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
--build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
$(BUILD_PFX)%.S.o: %.S $(BUILD_PFX)%.s.o: %.s
$(if $(quiet),@echo " [AS] $@") $(if $(quiet),@echo " [AS] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(AS) $(ASFLAGS) -o $@ $< $(qexec)$(AS) $(ASFLAGS) -o $@ $<
.PRECIOUS: %.c.S .PRECIOUS: %.c.S
%.c.S: CFLAGS += -DINLINE_ASM %.c.S: CFLAGS += -DINLINE_ASM
$(BUILD_PFX)%.c.S: %.c $(BUILD_PFX)%.c.S: %.c
$(if $(quiet),@echo " [GEN] $@") $(if $(quiet),@echo " [GEN] $@")
$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
$(qexec)$(CC) -S $(CFLAGS) -o $@ $< $(qexec)$(CC) -S $(CFLAGS) -o $@ $<
.PRECIOUS: %.asm.S .PRECIOUS: %.asm.s
$(BUILD_PFX)%.asm.S: %.asm $(BUILD_PFX)%.asm.s: %.asm
$(if $(quiet),@echo " [ASM CONVERSION] $@") $(if $(quiet),@echo " [ASM CONVERSION] $@")
$(qexec)mkdir -p $(dir $@) $(qexec)mkdir -p $(dir $@)
$(qexec)$(ASM_CONVERSION) <$< >$@ $(qexec)$(ASM_CONVERSION) <$< >$@
@ -229,6 +216,14 @@ else
$(qexec)cp $< $@ $(qexec)cp $< $@
endif endif
#
# Rule to extract assembly constants from C sources
#
obj_int_extract: build/make/obj_int_extract.c
$(if $(quiet),@echo " [HOSTCC] $@")
$(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $<
CLEAN-OBJS += obj_int_extract
# #
# Utility functions # Utility functions
# #
@ -290,7 +285,7 @@ define archive_template
# for creating them. # for creating them.
$(1): $(1):
$(if $(quiet),@echo " [AR] $$@") $(if $(quiet),@echo " [AR] $$@")
$(qexec)$$(AR) $$(ARFLAGS) $$@ $$^ $(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
endef endef
define so_template define so_template
@ -320,15 +315,18 @@ $(1):
$$(filter %.o,$$^) $$(extralibs) $$(filter %.o,$$^) $$(extralibs)
endef endef
define dll_template
# Not using a pattern rule here because we don't want to generate empty
# archives when they are listed as a dependency in files not responsible define lipo_lib_template
# for creating them. $(1): $(addsuffix /$(1),$(FAT_ARCHS))
$(1): $(if $(quiet),@echo " [LIPO] $$@")
$(if $(quiet),@echo " [LD] $$@") $(qexec)libtool -static -o $$@ $$?
$(qexec)$$(LD) -Zdll $$(LDFLAGS) \ endef
-o $$@ \
$$(filter %.o,$$^) $$(extralibs) $$(EXPORTS_FILE) define lipo_bin_template
$(1): $(addsuffix /$(1),$(FAT_ARCHS))
$(if $(quiet),@echo " [LIPO] $$@")
$(qexec)lipo -output $$@ -create $$?
endef endef
@ -342,11 +340,9 @@ endif
skip_deps := $(filter %clean,$(MAKECMDGOALS)) skip_deps := $(filter %clean,$(MAKECMDGOALS))
skip_deps += $(findstring testdata,$(MAKECMDGOALS)) skip_deps += $(findstring testdata,$(MAKECMDGOALS))
ifeq ($(strip $(skip_deps)),) ifeq ($(strip $(skip_deps)),)
ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes) # Older versions of make don't like -include directives with no arguments
# Older versions of make don't like -include directives with no arguments ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),) -include $(filter %.d,$(OBJS-yes:.o=.d))
-include $(filter %.d,$(OBJS-yes:.o=.d))
endif
endif endif
endif endif
@ -387,9 +383,8 @@ LIBS=$(call enabled,LIBS)
.libs: $(LIBS) .libs: $(LIBS)
@touch $@ @touch $@
$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib)))) $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
$(foreach lib,$(filter %so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib)))) $(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib)))) $(foreach lib,$(filter %$(VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib))))
$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dll,$(LIBS)),$(eval $(call dll_template,$(lib))))
INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS) INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
ifeq ($(MAKECMDGOALS),dist) ifeq ($(MAKECMDGOALS),dist)
@ -425,10 +420,15 @@ ifneq ($(call enabled,DIST-SRCS),)
DIST-SRCS-yes += build/make/gen_asm_deps.sh DIST-SRCS-yes += build/make/gen_asm_deps.sh
DIST-SRCS-yes += build/make/Makefile DIST-SRCS-yes += build/make/Makefile
DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh
DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_proj.sh
DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh
DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh
DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh
DIST-SRCS-$(CONFIG_MSVS) += build/x86-msvs/obj_int_extract.bat
DIST-SRCS-$(CONFIG_MSVS) += build/arm-msvs/obj_int_extract.bat
DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
# Include obj_int_extract if we use offsets from *_asm_*_offsets
DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64) += build/make/obj_int_extract.c
DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl
DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas_apple.pl DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas_apple.pl
DIST-SRCS-$(ARCH_ARM) += build/make/ads2armasm_ms.pl DIST-SRCS-$(ARCH_ARM) += build/make/ads2armasm_ms.pl
@ -455,5 +455,3 @@ all: $(BUILD_TARGETS)
install:: $(INSTALL_TARGETS) install:: $(INSTALL_TARGETS)
dist: $(INSTALL_TARGETS) dist: $(INSTALL_TARGETS)
test:: test::
.SUFFIXES: # Delete default suffix rules

View File

@ -23,11 +23,9 @@ use lib $FindBin::Bin;
use thumb; use thumb;
my $thumb = 0; my $thumb = 0;
my $elf = 1;
foreach my $arg (@ARGV) { foreach my $arg (@ARGV) {
$thumb = 1 if ($arg eq "-thumb"); $thumb = 1 if ($arg eq "-thumb");
$elf = 0 if ($arg eq "-noelf");
} }
print "@ This file was created from a .asm file\n"; print "@ This file was created from a .asm file\n";
@ -140,13 +138,17 @@ while (<STDIN>)
s/DCD(.*)/.long $1/; s/DCD(.*)/.long $1/;
s/DCB(.*)/.byte $1/; s/DCB(.*)/.byte $1/;
# RN to .req
if (s/RN\s+([Rr]\d+|lr)/.req $1/)
{
print;
print "$comment_sub$comment\n" if defined $comment;
next;
}
# Make function visible to linker, and make additional symbol with # Make function visible to linker, and make additional symbol with
# prepended underscore # prepended underscore
if ($elf) { s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/;
s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/;
} else {
s/EXPORT\s+\|([\$\w]*)\|/.global $1/;
}
s/IMPORT\s+\|([\$\w]*)\|/.global $1/; s/IMPORT\s+\|([\$\w]*)\|/.global $1/;
s/EXPORT\s+([\$\w]*)/.global $1/; s/EXPORT\s+([\$\w]*)/.global $1/;
@ -187,16 +189,11 @@ while (<STDIN>)
# eabi_attributes numerical equivalents can be found in the # eabi_attributes numerical equivalents can be found in the
# "ARM IHI 0045C" document. # "ARM IHI 0045C" document.
if ($elf) { # REQUIRE8 Stack is required to be 8-byte aligned
# REQUIRE8 Stack is required to be 8-byte aligned s/\sREQUIRE8/.eabi_attribute 24, 1 \@Tag_ABI_align_needed/g;
s/\sREQUIRE8/.eabi_attribute 24, 1 \@Tag_ABI_align_needed/g;
# PRESERVE8 Stack 8-byte align is preserved # PRESERVE8 Stack 8-byte align is preserved
s/\sPRESERVE8/.eabi_attribute 25, 1 \@Tag_ABI_align_preserved/g; s/\sPRESERVE8/.eabi_attribute 25, 1 \@Tag_ABI_align_preserved/g;
} else {
s/\sREQUIRE8//;
s/\sPRESERVE8//;
}
# Use PROC and ENDP to give the symbols a .size directive. # Use PROC and ENDP to give the symbols a .size directive.
# This makes them show up properly in debugging tools like gdb and valgrind. # This makes them show up properly in debugging tools like gdb and valgrind.
@ -213,7 +210,7 @@ while (<STDIN>)
my $proc; my $proc;
s/\bENDP\b/@ $&/; s/\bENDP\b/@ $&/;
$proc = pop(@proc_stack); $proc = pop(@proc_stack);
$_ = "\t.size $proc, .-$proc".$_ if ($proc and $elf); $_ = "\t.size $proc, .-$proc".$_ if ($proc);
} }
# EQU directive # EQU directive
@ -236,4 +233,4 @@ while (<STDIN>)
} }
# Mark that this object doesn't need an executable stack. # Mark that this object doesn't need an executable stack.
printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n") if $elf; printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n");

View File

@ -18,6 +18,12 @@
# Usage: cat inputfile | perl ads2gas_apple.pl > outputfile # Usage: cat inputfile | perl ads2gas_apple.pl > outputfile
# #
my $chromium = 0;
foreach my $arg (@ARGV) {
$chromium = 1 if ($arg eq "-chromium");
}
print "@ This file was created from a .asm file\n"; print "@ This file was created from a .asm file\n";
print "@ using the ads2gas_apple.pl script.\n\n"; print "@ using the ads2gas_apple.pl script.\n\n";
print "\t.set WIDE_REFERENCE, 0\n"; print "\t.set WIDE_REFERENCE, 0\n";
@ -120,6 +126,18 @@ while (<STDIN>)
s/DCD(.*)/.long $1/; s/DCD(.*)/.long $1/;
s/DCB(.*)/.byte $1/; s/DCB(.*)/.byte $1/;
# Build a hash of all the register - alias pairs.
if (s/(.*)RN(.*)/$1 .req $2/g)
{
$register_aliases{trim($1)} = trim($2);
next;
}
while (($key, $value) = each(%register_aliases))
{
s/\b$key\b/$value/g;
}
# Make function visible to linker, and make additional symbol with # Make function visible to linker, and make additional symbol with
# prepended underscore # prepended underscore
s/EXPORT\s+\|([\$\w]*)\|/.globl _$1\n\t.globl $1/; s/EXPORT\s+\|([\$\w]*)\|/.globl _$1\n\t.globl $1/;
@ -200,5 +218,18 @@ while (<STDIN>)
s/\bMEND\b/.endm/; # No need to tell it where to stop assembling s/\bMEND\b/.endm/; # No need to tell it where to stop assembling
next if /^\s*END\s*$/; next if /^\s*END\s*$/;
# Clang used by Chromium differs slightly from clang in XCode in what it
# will accept in the assembly.
if ($chromium) {
s/qsubaddx/qsax/i;
s/qaddsubx/qasx/i;
s/ldrneb/ldrbne/i;
s/ldrneh/ldrhne/i;
s/(vqshrun\.s16 .*, \#)0$/${1}8/i;
# http://llvm.org/bugs/show_bug.cgi?id=16022
s/\.include/#include/;
}
print; print;
} }

File diff suppressed because it is too large Load Diff

528
build/make/gen_msvs_proj.sh Executable file
View File

@ -0,0 +1,528 @@
#!/bin/bash
##
## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
##
## Use of this source code is governed by a BSD-style license
## that can be found in the LICENSE file in the root of the source
## tree. An additional intellectual property rights grant can be found
## in the file PATENTS. All contributing project authors may
## be found in the AUTHORS file in the root of the source tree.
##
self=$0
self_basename=${self##*/}
self_dirname=$(dirname "$0")
. "$self_dirname/msvs_common.sh"|| exit 127
show_help() {
cat <<EOF
Usage: ${self_basename} --name=projname [options] file1 [file2 ...]
This script generates a Visual Studio project file from a list of source
code files.
Options:
--help Print this message
--exe Generate a project for building an Application
--lib Generate a project for creating a static library
--dll Generate a project for creating a dll
--static-crt Use the static C runtime (/MT)
--target=isa-os-cc Target specifier (required)
--out=filename Write output to a file [stdout]
--name=project_name Name of the project (required)
--proj-guid=GUID GUID to use for the project
--module-def=filename File containing export definitions (for DLLs)
--ver=version Version (7,8,9) of visual studio to generate for
--src-path-bare=dir Path to root of source tree
-Ipath/to/include Additional include directories
-DFLAG[=value] Preprocessor macros to define
-Lpath/to/lib Additional library search paths
-llibname Library to link against
EOF
exit 1
}
generate_filter() {
local var=$1
local name=$2
local pats=$3
local file_list_sz
local i
local f
local saveIFS="$IFS"
local pack
echo "generating filter '$name' from ${#file_list[@]} files" >&2
IFS=*
open_tag Filter \
Name=$name \
Filter=$pats \
UniqueIdentifier=`generate_uuid` \
file_list_sz=${#file_list[@]}
for i in ${!file_list[@]}; do
f=${file_list[i]}
for pat in ${pats//;/$IFS}; do
if [ "${f##*.}" == "$pat" ]; then
unset file_list[i]
objf=$(echo ${f%.*}.obj \
| sed -e "s,$src_path_bare,," \
-e 's/^[\./]\+//g' -e 's,[:/ ],_,g')
open_tag File RelativePath="$f"
if [ "$pat" == "asm" ] && $asm_use_custom_step; then
for plat in "${platforms[@]}"; do
for cfg in Debug Release; do
open_tag FileConfiguration \
Name="${cfg}|${plat}" \
tag Tool \
Name="VCCustomBuildTool" \
Description="Assembling \$(InputFileName)" \
CommandLine="$(eval echo \$asm_${cfg}_cmdline) -o \$(IntDir)\\$objf" \
Outputs="\$(IntDir)\\$objf" \
close_tag FileConfiguration
done
done
fi
if [ "$pat" == "c" ] || \
[ "$pat" == "cc" ] || [ "$pat" == "cpp" ]; then
for plat in "${platforms[@]}"; do
for cfg in Debug Release; do
open_tag FileConfiguration \
Name="${cfg}|${plat}" \
tag Tool \
Name="VCCLCompilerTool" \
ObjectFile="\$(IntDir)\\$objf" \
close_tag FileConfiguration
done
done
fi
close_tag File
break
fi
done
done
close_tag Filter
IFS="$saveIFS"
}
# Process command line
unset target
for opt in "$@"; do
optval="${opt#*=}"
case "$opt" in
--help|-h) show_help
;;
--target=*) target="${optval}"
;;
--out=*) outfile="$optval"
;;
--name=*) name="${optval}"
;;
--proj-guid=*) guid="${optval}"
;;
--module-def=*) link_opts="${link_opts} ModuleDefinitionFile=${optval}"
;;
--exe) proj_kind="exe"
;;
--dll) proj_kind="dll"
;;
--lib) proj_kind="lib"
;;
--src-path-bare=*)
src_path_bare=$(fix_path "$optval")
src_path_bare=${src_path_bare%/}
;;
--static-crt) use_static_runtime=true
;;
--ver=*)
vs_ver="$optval"
case "$optval" in
[789])
;;
*) die Unrecognized Visual Studio Version in $opt
;;
esac
;;
-I*)
opt=${opt##-I}
opt=$(fix_path "$opt")
opt="${opt%/}"
incs="${incs}${incs:+;}&quot;${opt}&quot;"
yasmincs="${yasmincs} -I&quot;${opt}&quot;"
;;
-D*) defines="${defines}${defines:+;}${opt##-D}"
;;
-L*) # fudge . to $(OutDir)
if [ "${opt##-L}" == "." ]; then
libdirs="${libdirs}${libdirs:+;}&quot;\$(OutDir)&quot;"
else
# Also try directories for this platform/configuration
opt=${opt##-L}
opt=$(fix_path "$opt")
libdirs="${libdirs}${libdirs:+;}&quot;${opt}&quot;"
libdirs="${libdirs}${libdirs:+;}&quot;${opt}/\$(PlatformName)/\$(ConfigurationName)&quot;"
libdirs="${libdirs}${libdirs:+;}&quot;${opt}/\$(PlatformName)&quot;"
fi
;;
-l*) libs="${libs}${libs:+ }${opt##-l}.lib"
;;
-*) die_unknown $opt
;;
*)
# The paths in file_list are fixed outside of the loop.
file_list[${#file_list[@]}]="$opt"
case "$opt" in
*.asm) uses_asm=true
;;
esac
;;
esac
done
# Make one call to fix_path for file_list to improve performance.
fix_file_list
outfile=${outfile:-/dev/stdout}
guid=${guid:-`generate_uuid`}
asm_use_custom_step=false
uses_asm=${uses_asm:-false}
case "${vs_ver:-8}" in
7) vs_ver_id="7.10"
asm_use_custom_step=$uses_asm
warn_64bit='Detect64BitPortabilityProblems=true'
;;
8) vs_ver_id="8.00"
asm_use_custom_step=$uses_asm
warn_64bit='Detect64BitPortabilityProblems=true'
;;
9) vs_ver_id="9.00"
asm_use_custom_step=$uses_asm
warn_64bit='Detect64BitPortabilityProblems=false'
;;
esac
[ -n "$name" ] || die "Project name (--name) must be specified!"
[ -n "$target" ] || die "Target (--target) must be specified!"
if ${use_static_runtime:-false}; then
release_runtime=0
debug_runtime=1
lib_sfx=mt
else
release_runtime=2
debug_runtime=3
lib_sfx=md
fi
# Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
# it to ${lib_sfx}d.lib. This precludes linking to release libs from a
# debug exe, so this may need to be refactored later.
for lib in ${libs}; do
if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
lib=${lib%.lib}d.lib
fi
debug_libs="${debug_libs}${debug_libs:+ }${lib}"
done
# List Keyword for this target
case "$target" in
x86*) keyword="ManagedCProj"
;;
*) die "Unsupported target $target!"
esac
# List of all platforms supported for this target
case "$target" in
x86_64*)
platforms[0]="x64"
asm_Debug_cmdline="yasm -Xvc -g cv8 -f win64 ${yasmincs} &quot;\$(InputPath)&quot;"
asm_Release_cmdline="yasm -Xvc -f win64 ${yasmincs} &quot;\$(InputPath)&quot;"
;;
x86*)
platforms[0]="Win32"
asm_Debug_cmdline="yasm -Xvc -g cv8 -f win32 ${yasmincs} &quot;\$(InputPath)&quot;"
asm_Release_cmdline="yasm -Xvc -f win32 ${yasmincs} &quot;\$(InputPath)&quot;"
;;
*) die "Unsupported target $target!"
;;
esac
generate_vcproj() {
case "$proj_kind" in
exe) vs_ConfigurationType=1
;;
dll) vs_ConfigurationType=2
;;
*) vs_ConfigurationType=4
;;
esac
echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
open_tag VisualStudioProject \
ProjectType="Visual C++" \
Version="${vs_ver_id}" \
Name="${name}" \
ProjectGUID="{${guid}}" \
RootNamespace="${name}" \
Keyword="${keyword}" \
open_tag Platforms
for plat in "${platforms[@]}"; do
tag Platform Name="$plat"
done
close_tag Platforms
open_tag Configurations
for plat in "${platforms[@]}"; do
plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
open_tag Configuration \
Name="Debug|$plat" \
OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
ConfigurationType="$vs_ConfigurationType" \
CharacterSet="1" \
case "$target" in
x86*)
case "$name" in
obj_int_extract)
tag Tool \
Name="VCCLCompilerTool" \
Optimization="0" \
AdditionalIncludeDirectories="$incs" \
PreprocessorDefinitions="WIN32;DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
RuntimeLibrary="$debug_runtime" \
WarningLevel="3" \
DebugInformationFormat="1" \
$warn_64bit \
;;
vpx)
tag Tool \
Name="VCPreBuildEventTool" \
CommandLine="call obj_int_extract.bat &quot;$src_path_bare&quot; $plat_no_ws\\\$(ConfigurationName)" \
tag Tool \
Name="VCCLCompilerTool" \
Optimization="0" \
AdditionalIncludeDirectories="$incs" \
PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
RuntimeLibrary="$debug_runtime" \
UsePrecompiledHeader="0" \
WarningLevel="3" \
DebugInformationFormat="2" \
$warn_64bit \
$uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="true"
;;
*)
tag Tool \
Name="VCCLCompilerTool" \
Optimization="0" \
AdditionalIncludeDirectories="$incs" \
PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
RuntimeLibrary="$debug_runtime" \
UsePrecompiledHeader="0" \
WarningLevel="3" \
DebugInformationFormat="2" \
$warn_64bit \
$uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="true"
;;
esac
;;
esac
case "$proj_kind" in
exe)
case "$target" in
x86*)
case "$name" in
obj_int_extract)
tag Tool \
Name="VCLinkerTool" \
GenerateDebugInformation="true" \
;;
*)
tag Tool \
Name="VCLinkerTool" \
AdditionalDependencies="$debug_libs \$(NoInherit)" \
AdditionalLibraryDirectories="$libdirs" \
GenerateDebugInformation="true" \
ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \
;;
esac
;;
esac
;;
lib)
case "$target" in
x86*)
tag Tool \
Name="VCLibrarianTool" \
OutputFile="\$(OutDir)/${name}${lib_sfx}d.lib" \
;;
esac
;;
dll)
tag Tool \
Name="VCLinkerTool" \
AdditionalDependencies="\$(NoInherit)" \
LinkIncremental="2" \
GenerateDebugInformation="true" \
AssemblyDebug="1" \
TargetMachine="1" \
$link_opts \
;;
esac
close_tag Configuration
open_tag Configuration \
Name="Release|$plat" \
OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
ConfigurationType="$vs_ConfigurationType" \
CharacterSet="1" \
WholeProgramOptimization="0" \
case "$target" in
x86*)
case "$name" in
obj_int_extract)
tag Tool \
Name="VCCLCompilerTool" \
Optimization="2" \
FavorSizeorSpeed="1" \
AdditionalIncludeDirectories="$incs" \
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
RuntimeLibrary="$release_runtime" \
UsePrecompiledHeader="0" \
WarningLevel="3" \
DebugInformationFormat="0" \
$warn_64bit \
;;
vpx)
tag Tool \
Name="VCPreBuildEventTool" \
CommandLine="call obj_int_extract.bat &quot;$src_path_bare&quot; $plat_no_ws\\\$(ConfigurationName)" \
tag Tool \
Name="VCCLCompilerTool" \
Optimization="2" \
FavorSizeorSpeed="1" \
AdditionalIncludeDirectories="$incs" \
PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
RuntimeLibrary="$release_runtime" \
UsePrecompiledHeader="0" \
WarningLevel="3" \
DebugInformationFormat="0" \
$warn_64bit \
$uses_asm && tag Tool Name="YASM" IncludePaths="$incs"
;;
*)
tag Tool \
Name="VCCLCompilerTool" \
AdditionalIncludeDirectories="$incs" \
Optimization="2" \
FavorSizeorSpeed="1" \
PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
RuntimeLibrary="$release_runtime" \
UsePrecompiledHeader="0" \
WarningLevel="3" \
DebugInformationFormat="0" \
$warn_64bit \
$uses_asm && tag Tool Name="YASM" IncludePaths="$incs"
;;
esac
;;
esac
case "$proj_kind" in
exe)
case "$target" in
x86*)
case "$name" in
obj_int_extract)
tag Tool \
Name="VCLinkerTool" \
GenerateDebugInformation="true" \
;;
*)
tag Tool \
Name="VCLinkerTool" \
AdditionalDependencies="$libs \$(NoInherit)" \
AdditionalLibraryDirectories="$libdirs" \
;;
esac
;;
esac
;;
lib)
case "$target" in
x86*)
tag Tool \
Name="VCLibrarianTool" \
OutputFile="\$(OutDir)/${name}${lib_sfx}.lib" \
;;
esac
;;
dll) # note differences to debug version: LinkIncremental, AssemblyDebug
tag Tool \
Name="VCLinkerTool" \
AdditionalDependencies="\$(NoInherit)" \
LinkIncremental="1" \
GenerateDebugInformation="true" \
TargetMachine="1" \
$link_opts \
;;
esac
close_tag Configuration
done
close_tag Configurations
open_tag Files
generate_filter srcs "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx"
generate_filter hdrs "Header Files" "h;hm;inl;inc;xsd"
generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
generate_filter resrcs "Build Files" "mk"
close_tag Files
tag Globals
close_tag VisualStudioProject
# This must be done from within the {} subshell
echo "Ignored files list (${#file_list[@]} items) is:" >&2
for f in "${file_list[@]}"; do
echo " $f" >&2
done
}
generate_vcproj |
sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}
exit
<!--
TODO: Add any files not captured by filters.
<File
RelativePath=".\ReadMe.txt"
>
</File>
-->

View File

@ -19,13 +19,13 @@ show_help() {
cat <<EOF cat <<EOF
Usage: ${self_basename} [options] file1 [file2 ...] Usage: ${self_basename} [options] file1 [file2 ...]
This script generates a Visual Studio solution file from a list of project This script generates a Visual Studio 2005 solution file from a list of project
files. files.
Options: Options:
--help Print this message --help Print this message
--out=outfile Redirect output to a file --out=outfile Redirect output to a file
--ver=version Version (7,8,9,10,11,12,14,15) of visual studio to generate for --ver=version Version (7,8,9,10,11) of visual studio to generate for
--target=isa-os-cc Target specifier --target=isa-os-cc Target specifier
EOF EOF
exit 1 exit 1
@ -55,11 +55,16 @@ indent_pop() {
parse_project() { parse_project() {
local file=$1 local file=$1
local name=`grep RootNamespace "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'` if [ "$sfx" = "vcproj" ]; then
local guid=`grep ProjectGuid "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'` local name=`grep Name "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'`
local guid=`grep ProjectGUID "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'`
else
local name=`grep RootNamespace "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
local guid=`grep ProjectGuid "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
fi
# save the project GUID to a varaible, normalizing to the basename of the # save the project GUID to a varaible, normalizing to the basename of the
# vcxproj file without the extension # vcproj file without the extension
local var local var
var=${file##*/} var=${file##*/}
var=${var%%.${sfx}} var=${var%%.${sfx}}
@ -67,8 +72,13 @@ parse_project() {
eval "${var}_name=$name" eval "${var}_name=$name"
eval "${var}_guid=$guid" eval "${var}_guid=$guid"
cur_config_list=`grep -B1 'Label="Configuration"' $file | if [ "$sfx" = "vcproj" ]; then
grep Condition | cut -d\' -f4` cur_config_list=`grep -A1 '<Configuration' $file |
grep Name | cut -d\" -f2`
else
cur_config_list=`grep -B1 'Label="Configuration"' $file |
grep Condition | cut -d\' -f4`
fi
new_config_list=$(for i in $config_list $cur_config_list; do new_config_list=$(for i in $config_list $cur_config_list; do
echo $i echo $i
done | sort | uniq) done | sort | uniq)
@ -93,6 +103,25 @@ process_project() {
eval "${var}_guid=$guid" eval "${var}_guid=$guid"
echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\"" echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\""
indent_push
eval "local deps=\"\${${var}_deps}\""
if [ -n "$deps" ] && [ "$sfx" = "vcproj" ]; then
echo "${indent}ProjectSection(ProjectDependencies) = postProject"
indent_push
for dep in $deps; do
eval "local dep_guid=\${${dep}_guid}"
[ -z "${dep_guid}" ] && die "Unknown GUID for $dep (dependency of $var)"
echo "${indent}$dep_guid = $dep_guid"
done
indent_pop
echo "${indent}EndProjectSection"
fi
indent_pop
echo "EndProject" echo "EndProject"
} }
@ -162,7 +191,11 @@ process_makefile() {
IFS=$'\r'$'\n' IFS=$'\r'$'\n'
local TAB=$'\t' local TAB=$'\t'
cat <<EOF cat <<EOF
ifeq (\$(CONFIG_VS_VERSION),7)
MSBUILD_TOOL := devenv.com
else
MSBUILD_TOOL := msbuild.exe MSBUILD_TOOL := msbuild.exe
endif
found_devenv := \$(shell which \$(MSBUILD_TOOL) >/dev/null 2>&1 && echo yes) found_devenv := \$(shell which \$(MSBUILD_TOOL) >/dev/null 2>&1 && echo yes)
.nodevenv.once: .nodevenv.once:
${TAB}@echo " * \$(MSBUILD_TOOL) not found in path." ${TAB}@echo " * \$(MSBUILD_TOOL) not found in path."
@ -171,7 +204,7 @@ ${TAB}@echo " * You will have to build all configurations manually using the"
${TAB}@echo " * Visual Studio IDE. To allow make to build them automatically," ${TAB}@echo " * Visual Studio IDE. To allow make to build them automatically,"
${TAB}@echo " * add the Common7/IDE directory of your Visual Studio" ${TAB}@echo " * add the Common7/IDE directory of your Visual Studio"
${TAB}@echo " * installation to your path, eg:" ${TAB}@echo " * installation to your path, eg:"
${TAB}@echo " * C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE" ${TAB}@echo " * C:\Program Files\Microsoft Visual Studio 8\Common7\IDE"
${TAB}@echo " * " ${TAB}@echo " * "
${TAB}@touch \$@ ${TAB}@touch \$@
CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once) CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once)
@ -188,9 +221,16 @@ clean::
${TAB}rm -rf "$platform"/"$config" ${TAB}rm -rf "$platform"/"$config"
.PHONY: $nows_sln_config .PHONY: $nows_sln_config
ifneq (\$(found_devenv),) ifneq (\$(found_devenv),)
ifeq (\$(CONFIG_VS_VERSION),7)
$nows_sln_config: $outfile
${TAB}\$(MSBUILD_TOOL) $outfile -build "$config"
else
$nows_sln_config: $outfile $nows_sln_config: $outfile
${TAB}\$(MSBUILD_TOOL) $outfile -m -t:Build \\ ${TAB}\$(MSBUILD_TOOL) $outfile -m -t:Build \\
${TAB}${TAB}-p:Configuration="$config" -p:Platform="$platform" ${TAB}${TAB}-p:Configuration="$config" -p:Platform="$platform"
endif
else else
$nows_sln_config: $outfile .nodevenv.once $nows_sln_config: $outfile .nodevenv.once
${TAB}@echo " * Skipping build of $sln_config (\$(MSBUILD_TOOL) not in path)." ${TAB}@echo " * Skipping build of $sln_config (\$(MSBUILD_TOOL) not in path)."
@ -215,12 +255,23 @@ for opt in "$@"; do
;; ;;
--ver=*) vs_ver="$optval" --ver=*) vs_ver="$optval"
case $optval in case $optval in
10|11|12|14|15) [789]|10|11|12)
;; ;;
*) die Unrecognized Visual Studio Version in $opt *) die Unrecognized Visual Studio Version in $opt
;; ;;
esac esac
;; ;;
--ver=*) vs_ver="$optval"
case $optval in
7) sln_vers="8.00"
sln_vers_str="Visual Studio .NET 2003"
;;
[89])
;;
*) die "Unrecognized Visual Studio Version '$optval' in $opt"
;;
esac
;;
--target=*) target="${optval}" --target=*) target="${optval}"
;; ;;
-*) die_unknown $opt -*) die_unknown $opt
@ -230,7 +281,16 @@ for opt in "$@"; do
done done
outfile=${outfile:-/dev/stdout} outfile=${outfile:-/dev/stdout}
mkoutfile=${mkoutfile:-/dev/stdout} mkoutfile=${mkoutfile:-/dev/stdout}
case "${vs_ver:-10}" in case "${vs_ver:-8}" in
7) sln_vers="8.00"
sln_vers_str="Visual Studio .NET 2003"
;;
8) sln_vers="9.00"
sln_vers_str="Visual Studio 2005"
;;
9) sln_vers="10.00"
sln_vers_str="Visual Studio 2008"
;;
10) sln_vers="11.00" 10) sln_vers="11.00"
sln_vers_str="Visual Studio 2010" sln_vers_str="Visual Studio 2010"
;; ;;
@ -240,14 +300,15 @@ case "${vs_ver:-10}" in
12) sln_vers="12.00" 12) sln_vers="12.00"
sln_vers_str="Visual Studio 2013" sln_vers_str="Visual Studio 2013"
;; ;;
14) sln_vers="12.00" esac
sln_vers_str="Visual Studio 2015" case "${vs_ver:-8}" in
[789])
sfx=vcproj
;; ;;
15) sln_vers="12.00" 10|11|12)
sln_vers_str="Visual Studio 2017" sfx=vcxproj
;; ;;
esac esac
sfx=vcxproj
for f in "${file_list[@]}"; do for f in "${file_list[@]}"; do
parse_project $f parse_project $f

View File

@ -34,7 +34,7 @@ Options:
--name=project_name Name of the project (required) --name=project_name Name of the project (required)
--proj-guid=GUID GUID to use for the project --proj-guid=GUID GUID to use for the project
--module-def=filename File containing export definitions (for DLLs) --module-def=filename File containing export definitions (for DLLs)
--ver=version Version (10,11,12,14,15) of visual studio to generate for --ver=version Version (10,11,12) of visual studio to generate for
--src-path-bare=dir Path to root of source tree --src-path-bare=dir Path to root of source tree
-Ipath/to/include Additional include directories -Ipath/to/include Additional include directories
-DFLAG[=value] Preprocessor macros to define -DFLAG[=value] Preprocessor macros to define
@ -82,7 +82,7 @@ generate_filter() {
| sed -e "s,$src_path_bare,," \ | sed -e "s,$src_path_bare,," \
-e 's/^[\./]\+//g' -e 's,[:/ ],_,g') -e 's/^[\./]\+//g' -e 's,[:/ ],_,g')
if ([ "$pat" == "asm" ] || [ "$pat" == "s" ] || [ "$pat" == "S" ]) && $asm_use_custom_step; then if ([ "$pat" == "asm" ] || [ "$pat" == "s" ]) && $asm_use_custom_step; then
# Avoid object file name collisions, i.e. vpx_config.c and # Avoid object file name collisions, i.e. vpx_config.c and
# vpx_config.asm produce the same object file without # vpx_config.asm produce the same object file without
# this additional suffix. # this additional suffix.
@ -168,7 +168,7 @@ for opt in "$@"; do
--ver=*) --ver=*)
vs_ver="$optval" vs_ver="$optval"
case "$optval" in case "$optval" in
10|11|12|14|15) 10|11|12)
;; ;;
*) die Unrecognized Visual Studio Version in $opt *) die Unrecognized Visual Studio Version in $opt
;; ;;
@ -203,7 +203,7 @@ for opt in "$@"; do
# The paths in file_list are fixed outside of the loop. # The paths in file_list are fixed outside of the loop.
file_list[${#file_list[@]}]="$opt" file_list[${#file_list[@]}]="$opt"
case "$opt" in case "$opt" in
*.asm|*.[Ss]) uses_asm=true *.asm|*.s) uses_asm=true
;; ;;
esac esac
;; ;;
@ -211,14 +211,14 @@ for opt in "$@"; do
done done
# Make one call to fix_path for file_list to improve performance. # Make one call to fix_path for file_list to improve performance.
fix_file_list file_list fix_file_list
outfile=${outfile:-/dev/stdout} outfile=${outfile:-/dev/stdout}
guid=${guid:-`generate_uuid`} guid=${guid:-`generate_uuid`}
asm_use_custom_step=false asm_use_custom_step=false
uses_asm=${uses_asm:-false} uses_asm=${uses_asm:-false}
case "${vs_ver:-11}" in case "${vs_ver:-11}" in
10|11|12|14|15) 10|11|12)
asm_use_custom_step=$uses_asm asm_use_custom_step=$uses_asm
;; ;;
esac esac
@ -262,9 +262,15 @@ case "$target" in
asm_Release_cmdline="yasm -Xvc -f win32 ${yasmincs} &quot;%(FullPath)&quot;" asm_Release_cmdline="yasm -Xvc -f win32 ${yasmincs} &quot;%(FullPath)&quot;"
;; ;;
arm*) arm*)
platforms[0]="ARM" asm_Debug_cmdline="armasm -nologo &quot;%(FullPath)&quot;"
asm_Debug_cmdline="armasm -nologo -oldit &quot;%(FullPath)&quot;" asm_Release_cmdline="armasm -nologo &quot;%(FullPath)&quot;"
asm_Release_cmdline="armasm -nologo -oldit &quot;%(FullPath)&quot;" if [ "$name" = "obj_int_extract" ]; then
# We don't want to build this tool for the target architecture,
# but for an architecture we can run locally during the build.
platforms[0]="Win32"
else
platforms[0]="ARM"
fi
;; ;;
*) die "Unsupported target $target!" *) die "Unsupported target $target!"
;; ;;
@ -344,12 +350,6 @@ generate_vcxproj() {
# has to enable AppContainerApplication as well. # has to enable AppContainerApplication as well.
tag_content PlatformToolset v120 tag_content PlatformToolset v120
fi fi
if [ "$vs_ver" = "14" ]; then
tag_content PlatformToolset v140
fi
if [ "$vs_ver" = "15" ]; then
tag_content PlatformToolset v141
fi
tag_content CharacterSet Unicode tag_content CharacterSet Unicode
if [ "$config" = "Release" ]; then if [ "$config" = "Release" ]; then
tag_content WholeProgramOptimization true tag_content WholeProgramOptimization true
@ -400,13 +400,23 @@ generate_vcxproj() {
if [ "$hostplat" == "ARM" ]; then if [ "$hostplat" == "ARM" ]; then
hostplat=Win32 hostplat=Win32
fi fi
open_tag PreBuildEvent
tag_content Command "call obj_int_extract.bat &quot;$src_path_bare&quot; $hostplat\\\$(Configuration)"
close_tag PreBuildEvent
fi fi
open_tag ClCompile open_tag ClCompile
if [ "$config" = "Debug" ]; then if [ "$config" = "Debug" ]; then
opt=Disabled opt=Disabled
runtime=$debug_runtime runtime=$debug_runtime
curlibs=$debug_libs curlibs=$debug_libs
debug=_DEBUG case "$name" in
obj_int_extract)
debug=DEBUG
;;
*)
debug=_DEBUG
;;
esac
else else
opt=MaxSpeed opt=MaxSpeed
runtime=$release_runtime runtime=$release_runtime
@ -414,7 +424,14 @@ generate_vcxproj() {
tag_content FavorSizeOrSpeed Speed tag_content FavorSizeOrSpeed Speed
debug=NDEBUG debug=NDEBUG
fi fi
extradefines=";$defines" case "$name" in
obj_int_extract)
extradefines=";_CONSOLE"
;;
*)
extradefines=";$defines"
;;
esac
tag_content Optimization $opt tag_content Optimization $opt
tag_content AdditionalIncludeDirectories "$incs;%(AdditionalIncludeDirectories)" tag_content AdditionalIncludeDirectories "$incs;%(AdditionalIncludeDirectories)"
tag_content PreprocessorDefinitions "WIN32;$debug;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE$extradefines;%(PreprocessorDefinitions)" tag_content PreprocessorDefinitions "WIN32;$debug;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE$extradefines;%(PreprocessorDefinitions)"
@ -434,6 +451,10 @@ generate_vcxproj() {
case "$proj_kind" in case "$proj_kind" in
exe) exe)
open_tag Link open_tag Link
if [ "$name" != "obj_int_extract" ]; then
tag_content AdditionalDependencies "$curlibs;%(AdditionalDependencies)"
tag_content AdditionalLibraryDirectories "$libdirs;%(AdditionalLibraryDirectories)"
fi
tag_content GenerateDebugInformation true tag_content GenerateDebugInformation true
# Console is the default normally, but if # Console is the default normally, but if
# AppContainerApplication is set, we need to override it. # AppContainerApplication is set, we need to override it.
@ -455,7 +476,7 @@ generate_vcxproj() {
done done
open_tag ItemGroup open_tag ItemGroup
generate_filter "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx;s;S" generate_filter "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx;s"
close_tag ItemGroup close_tag ItemGroup
open_tag ItemGroup open_tag ItemGroup
generate_filter "Header Files" "h;hm;inl;inc;xsd" generate_filter "Header Files" "h;hm;inl;inc;xsd"

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>VPX</string>
<key>CFBundleIdentifier</key>
<string>org.webmproject.VPX</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>VPX</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>MinimumOSVersion</key>
<string>${IOS_VERSION_MIN}</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>VPXFullVersion</key>
<string>${FULLVERSION}</string>
</dict>
</plist>

View File

@ -18,50 +18,34 @@ set -e
devnull='> /dev/null 2>&1' devnull='> /dev/null 2>&1'
BUILD_ROOT="_iosbuild" BUILD_ROOT="_iosbuild"
CONFIGURE_ARGS="--disable-docs
--disable-examples
--disable-libyuv
--disable-unit-tests"
DIST_DIR="_dist" DIST_DIR="_dist"
FRAMEWORK_DIR="VPX.framework" FRAMEWORK_DIR="VPX.framework"
FRAMEWORK_LIB="VPX.framework/VPX"
HEADER_DIR="${FRAMEWORK_DIR}/Headers/vpx" HEADER_DIR="${FRAMEWORK_DIR}/Headers/vpx"
SCRIPT_DIR=$(dirname "$0") MAKE_JOBS=1
LIBVPX_SOURCE_DIR=$(cd ${SCRIPT_DIR}/../..; pwd) LIBVPX_SOURCE_DIR=$(dirname "$0" | sed -e s,/build/make,,)
LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
ORIG_PWD="$(pwd)" ORIG_PWD="$(pwd)"
ARM_TARGETS="arm64-darwin-gcc TARGETS="arm64-darwin-gcc
armv7-darwin-gcc armv6-darwin-gcc
armv7s-darwin-gcc" armv7-darwin-gcc
SIM_TARGETS="x86-iphonesimulator-gcc armv7s-darwin-gcc
x86_64-iphonesimulator-gcc" x86-iphonesimulator-gcc
OSX_TARGETS="x86-darwin16-gcc x86_64-iphonesimulator-gcc"
x86_64-darwin16-gcc"
TARGETS="${ARM_TARGETS} ${SIM_TARGETS}"
# Configures for the target specified by $1, and invokes make with the dist # Configures for the target specified by $1, and invokes make with the dist
# target using $DIST_DIR as the distribution output directory. # target using $DIST_DIR as the distribution output directory.
build_target() { build_target() {
local target="$1" local target="$1"
local old_pwd="$(pwd)" local old_pwd="$(pwd)"
local target_specific_flags=""
vlog "***Building target: ${target}***" vlog "***Building target: ${target}***"
case "${target}" in
x86-*)
target_specific_flags="--enable-pic"
vlog "Enabled PIC for ${target}"
;;
esac
mkdir "${target}" mkdir "${target}"
cd "${target}" cd "${target}"
eval "${LIBVPX_SOURCE_DIR}/configure" --target="${target}" \ eval "../../${LIBVPX_SOURCE_DIR}/configure" --target="${target}" \
${CONFIGURE_ARGS} ${EXTRA_CONFIGURE_ARGS} ${target_specific_flags} \ --disable-docs ${EXTRA_CONFIGURE_ARGS} ${devnull}
${devnull}
export DIST_DIR export DIST_DIR
eval make dist ${devnull} eval make -j ${MAKE_JOBS} dist ${devnull}
cd "${old_pwd}" cd "${old_pwd}"
vlog "***Done building target: ${target}***" vlog "***Done building target: ${target}***"
@ -74,6 +58,9 @@ target_to_preproc_symbol() {
arm64-*) arm64-*)
echo "__aarch64__" echo "__aarch64__"
;; ;;
armv6-*)
echo "__ARM_ARCH_6__"
;;
armv7-*) armv7-*)
echo "__ARM_ARCH_7A__" echo "__ARM_ARCH_7A__"
;; ;;
@ -138,44 +125,6 @@ create_vpx_framework_config_shim() {
printf "#endif // ${include_guard}" >> "${config_file}" printf "#endif // ${include_guard}" >> "${config_file}"
} }
# Verifies that $FRAMEWORK_LIB fat library contains requested builds.
verify_framework_targets() {
local requested_cpus=""
local cpu=""
# Extract CPU from full target name.
for target; do
cpu="${target%%-*}"
if [ "${cpu}" = "x86" ]; then
# lipo -info outputs i386 for libvpx x86 targets.
cpu="i386"
fi
requested_cpus="${requested_cpus}${cpu} "
done
# Get target CPUs present in framework library.
local targets_built=$(${LIPO} -info ${FRAMEWORK_LIB})
# $LIPO -info outputs a string like the following:
# Architectures in the fat file: $FRAMEWORK_LIB <architectures>
# Capture only the architecture strings.
targets_built=${targets_built##*: }
# Sort CPU strings to make the next step a simple string compare.
local actual=$(echo ${targets_built} | tr " " "\n" | sort | tr "\n" " ")
local requested=$(echo ${requested_cpus} | tr " " "\n" | sort | tr "\n" " ")
vlog "Requested ${FRAMEWORK_LIB} CPUs: ${requested}"
vlog "Actual ${FRAMEWORK_LIB} CPUs: ${actual}"
if [ "${requested}" != "${actual}" ]; then
elog "Actual ${FRAMEWORK_LIB} targets do not match requested target list."
elog " Requested target CPUs: ${requested}"
elog " Actual target CPUs: ${actual}"
return 1
fi
}
# Configures and builds each target specified by $1, and then builds # Configures and builds each target specified by $1, and then builds
# VPX.framework. # VPX.framework.
build_framework() { build_framework() {
@ -196,12 +145,7 @@ build_framework() {
for target in ${targets}; do for target in ${targets}; do
build_target "${target}" build_target "${target}"
target_dist_dir="${BUILD_ROOT}/${target}/${DIST_DIR}" target_dist_dir="${BUILD_ROOT}/${target}/${DIST_DIR}"
if [ "${ENABLE_SHARED}" = "yes" ]; then lib_list="${lib_list} ${target_dist_dir}/lib/libvpx.a"
local suffix="dylib"
else
local suffix="a"
fi
lib_list="${lib_list} ${target_dist_dir}/lib/libvpx.${suffix}"
done done
cd "${ORIG_PWD}" cd "${ORIG_PWD}"
@ -220,75 +164,37 @@ build_framework() {
# Copy in vpx_version.h. # Copy in vpx_version.h.
cp -p "${BUILD_ROOT}/${target}/vpx_version.h" "${HEADER_DIR}" cp -p "${BUILD_ROOT}/${target}/vpx_version.h" "${HEADER_DIR}"
if [ "${ENABLE_SHARED}" = "yes" ]; then vlog "Created fat library ${FRAMEWORK_DIR}/VPX containing:"
# Adjust the dylib's name so dynamic linking in apps works as expected.
install_name_tool -id '@rpath/VPX.framework/VPX' ${FRAMEWORK_DIR}/VPX
# Copy in Info.plist.
cat "${SCRIPT_DIR}/ios-Info.plist" \
| sed "s/\${FULLVERSION}/${FULLVERSION}/g" \
| sed "s/\${VERSION}/${VERSION}/g" \
| sed "s/\${IOS_VERSION_MIN}/${IOS_VERSION_MIN}/g" \
> "${FRAMEWORK_DIR}/Info.plist"
fi
# Confirm VPX.framework/VPX contains the targets requested.
verify_framework_targets ${targets}
vlog "Created fat library ${FRAMEWORK_LIB} containing:"
for lib in ${lib_list}; do for lib in ${lib_list}; do
vlog " $(echo ${lib} | awk -F / '{print $2, $NF}')" vlog " $(echo ${lib} | awk -F / '{print $2, $NF}')"
done done
# TODO(tomfinegan): Verify that expected targets are included within
# VPX.framework/VPX via lipo -info.
} }
# Trap function. Cleans up the subtree used to build all targets contained in # Trap function. Cleans up the subtree used to build all targets contained in
# $TARGETS. # $TARGETS.
cleanup() { cleanup() {
local readonly res=$?
cd "${ORIG_PWD}" cd "${ORIG_PWD}"
if [ $res -ne 0 ]; then
elog "build exited with error ($res)"
fi
if [ "${PRESERVE_BUILD_OUTPUT}" != "yes" ]; then if [ "${PRESERVE_BUILD_OUTPUT}" != "yes" ]; then
rm -rf "${BUILD_ROOT}" rm -rf "${BUILD_ROOT}"
fi fi
} }
print_list() {
local indent="$1"
shift
local list="$@"
for entry in ${list}; do
echo "${indent}${entry}"
done
}
iosbuild_usage() { iosbuild_usage() {
cat << EOF cat << EOF
Usage: ${0##*/} [arguments] Usage: ${0##*/} [arguments]
--help: Display this message and exit. --help: Display this message and exit.
--enable-shared: Build a dynamic framework for use on iOS 8 or later. --jobs: Number of make jobs.
--extra-configure-args <args>: Extra args to pass when configuring libvpx.
--macosx: Uses darwin16 targets instead of iphonesimulator targets for x86
and x86_64. Allows linking to framework when builds target MacOSX
instead of iOS.
--preserve-build-output: Do not delete the build directory. --preserve-build-output: Do not delete the build directory.
--show-build-output: Show output from each library build. --show-build-output: Show output from each library build.
--targets <targets>: Override default target list. Defaults:
$(print_list " " ${TARGETS})
--test-link: Confirms all targets can be linked. Functionally identical to
passing --enable-examples via --extra-configure-args.
--verbose: Output information about the environment and each stage of the --verbose: Output information about the environment and each stage of the
build. build.
EOF EOF
} }
elog() {
echo "${0##*/} failed because: $@" 1>&2
}
vlog() { vlog() {
if [ "${VERBOSE}" = "yes" ]; then if [ "${VERBOSE}" = "yes" ]; then
echo "$@" echo "$@"
@ -308,8 +214,9 @@ while [ -n "$1" ]; do
iosbuild_usage iosbuild_usage
exit exit
;; ;;
--enable-shared) --jobs)
ENABLE_SHARED=yes MAKE_JOBS="$2"
shift
;; ;;
--preserve-build-output) --preserve-build-output)
PRESERVE_BUILD_OUTPUT=yes PRESERVE_BUILD_OUTPUT=yes
@ -317,16 +224,6 @@ while [ -n "$1" ]; do
--show-build-output) --show-build-output)
devnull= devnull=
;; ;;
--test-link)
EXTRA_CONFIGURE_ARGS="${EXTRA_CONFIGURE_ARGS} --enable-examples"
;;
--targets)
TARGETS="$2"
shift
;;
--macosx)
TARGETS="${ARM_TARGETS} ${OSX_TARGETS}"
;;
--verbose) --verbose)
VERBOSE=yes VERBOSE=yes
;; ;;
@ -338,46 +235,20 @@ while [ -n "$1" ]; do
shift shift
done done
if [ "${ENABLE_SHARED}" = "yes" ]; then
CONFIGURE_ARGS="--enable-shared ${CONFIGURE_ARGS}"
fi
FULLVERSION=$("${SCRIPT_DIR}"/version.sh --bare "${LIBVPX_SOURCE_DIR}")
VERSION=$(echo "${FULLVERSION}" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+).*$/\1/')
if [ "$ENABLE_SHARED" = "yes" ]; then
IOS_VERSION_OPTIONS="--enable-shared"
IOS_VERSION_MIN="8.0"
else
IOS_VERSION_OPTIONS=""
IOS_VERSION_MIN="6.0"
fi
if [ "${VERBOSE}" = "yes" ]; then if [ "${VERBOSE}" = "yes" ]; then
cat << EOF cat << EOF
BUILD_ROOT=${BUILD_ROOT} BUILD_ROOT=${BUILD_ROOT}
DIST_DIR=${DIST_DIR} DIST_DIR=${DIST_DIR}
CONFIGURE_ARGS=${CONFIGURE_ARGS}
EXTRA_CONFIGURE_ARGS=${EXTRA_CONFIGURE_ARGS} EXTRA_CONFIGURE_ARGS=${EXTRA_CONFIGURE_ARGS}
FRAMEWORK_DIR=${FRAMEWORK_DIR} FRAMEWORK_DIR=${FRAMEWORK_DIR}
FRAMEWORK_LIB=${FRAMEWORK_LIB}
HEADER_DIR=${HEADER_DIR} HEADER_DIR=${HEADER_DIR}
MAKE_JOBS=${MAKE_JOBS}
PRESERVE_BUILD_OUTPUT=${PRESERVE_BUILD_OUTPUT}
LIBVPX_SOURCE_DIR=${LIBVPX_SOURCE_DIR} LIBVPX_SOURCE_DIR=${LIBVPX_SOURCE_DIR}
LIPO=${LIPO} LIPO=${LIPO}
MAKEFLAGS=${MAKEFLAGS}
ORIG_PWD=${ORIG_PWD} ORIG_PWD=${ORIG_PWD}
PRESERVE_BUILD_OUTPUT=${PRESERVE_BUILD_OUTPUT} TARGETS="${TARGETS}"
TARGETS="$(print_list "" ${TARGETS})"
ENABLE_SHARED=${ENABLE_SHARED}
OSX_TARGETS="${OSX_TARGETS}"
SIM_TARGETS="${SIM_TARGETS}"
SCRIPT_DIR="${SCRIPT_DIR}"
FULLVERSION="${FULLVERSION}"
VERSION="${VERSION}"
IOS_VERSION_MIN="${IOS_VERSION_MIN}"
EOF EOF
fi fi
build_framework "${TARGETS}" build_framework "${TARGETS}"
echo "Successfully built '${FRAMEWORK_DIR}' for:"
print_list "" ${TARGETS}

View File

@ -39,21 +39,11 @@ fix_path() {
} }
# Corrects the paths in file_list in one pass for efficiency. # Corrects the paths in file_list in one pass for efficiency.
# $1 is the name of the array to be modified.
fix_file_list() { fix_file_list() {
if [ "${FIXPATH}" = "echo_path" ] ; then # TODO(jzern): this could be more generic and take the array as a param.
# When used with echo_path, fix_file_list is a no-op. Avoid warning about files=$(fix_path "${file_list[@]}")
# unsupported 'declare -n' when it is not important.
return 0
elif [ "${BASH_VERSINFO}" -lt 4 ] ; then
echo "Cygwin path conversion has failed. Please use a version of bash"
echo "which supports nameref (-n), introduced in bash 4.3"
return 1
fi
declare -n array_ref=$1
files=$(fix_path "${array_ref[@]}")
local IFS=$'\n' local IFS=$'\n'
array_ref=($files) file_list=($files)
} }
generate_uuid() { generate_uuid() {

View File

@ -0,0 +1,857 @@
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vpx_config.h"
#include "vpx/vpx_integer.h"
typedef enum {
OUTPUT_FMT_PLAIN,
OUTPUT_FMT_RVDS,
OUTPUT_FMT_GAS,
OUTPUT_FMT_C_HEADER,
} output_fmt_t;
int log_msg(const char *fmt, ...) {
int res;
va_list ap;
va_start(ap, fmt);
res = vfprintf(stderr, fmt, ap);
va_end(ap);
return res;
}
#if defined(__GNUC__) && __GNUC__
#if defined(FORCE_PARSE_ELF)
#if defined(__MACH__)
#undef __MACH__
#endif
#if !defined(__ELF__)
#define __ELF__
#endif
#endif
#if defined(__MACH__)
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) {
switch (mode) {
case OUTPUT_FMT_RVDS:
printf("%-40s EQU %5d\n", name, val);
return 0;
case OUTPUT_FMT_GAS:
printf(".set %-40s, %5d\n", name, val);
return 0;
case OUTPUT_FMT_C_HEADER:
printf("#define %-40s %5d\n", name, val);
return 0;
default:
log_msg("Unsupported mode: %d", mode);
return 1;
}
}
int parse_macho(uint8_t *base_buf, size_t sz, output_fmt_t mode) {
int i, j;
struct mach_header header;
uint8_t *buf = base_buf;
int base_data_section = 0;
int bits = 0;
/* We can read in mach_header for 32 and 64 bit architectures
* because it's identical to mach_header_64 except for the last
* element (uint32_t reserved), which we don't use. Then, when
* we know which architecture we're looking at, increment buf
* appropriately.
*/
memcpy(&header, buf, sizeof(struct mach_header));
if (header.magic == MH_MAGIC) {
if (header.cputype == CPU_TYPE_ARM
|| header.cputype == CPU_TYPE_X86) {
bits = 32;
buf += sizeof(struct mach_header);
} else {
log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_[ARM|X86].\n");
goto bail;
}
} else if (header.magic == MH_MAGIC_64) {
if (header.cputype == CPU_TYPE_X86_64) {
bits = 64;
buf += sizeof(struct mach_header_64);
} else {
log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_X86_64.\n");
goto bail;
}
} else {
log_msg("Bad magic number for object file. 0x%x or 0x%x expected, 0x%x found.\n",
MH_MAGIC, MH_MAGIC_64, header.magic);
goto bail;
}
if (header.filetype != MH_OBJECT) {
log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n");
goto bail;
}
for (i = 0; i < header.ncmds; i++) {
struct load_command lc;
memcpy(&lc, buf, sizeof(struct load_command));
if (lc.cmd == LC_SEGMENT) {
uint8_t *seg_buf = buf;
struct section s;
struct segment_command seg_c;
memcpy(&seg_c, seg_buf, sizeof(struct segment_command));
seg_buf += sizeof(struct segment_command);
/* Although each section is given it's own offset, nlist.n_value
* references the offset of the first section. This isn't
* apparent without debug information because the offset of the
* data section is the same as the first section. However, with
* debug sections mixed in, the offset of the debug section
* increases but n_value still references the first section.
*/
if (seg_c.nsects < 1) {
log_msg("Not enough sections\n");
goto bail;
}
memcpy(&s, seg_buf, sizeof(struct section));
base_data_section = s.offset;
} else if (lc.cmd == LC_SEGMENT_64) {
uint8_t *seg_buf = buf;
struct section_64 s;
struct segment_command_64 seg_c;
memcpy(&seg_c, seg_buf, sizeof(struct segment_command_64));
seg_buf += sizeof(struct segment_command_64);
/* Explanation in LG_SEGMENT */
if (seg_c.nsects < 1) {
log_msg("Not enough sections\n");
goto bail;
}
memcpy(&s, seg_buf, sizeof(struct section_64));
base_data_section = s.offset;
} else if (lc.cmd == LC_SYMTAB) {
if (base_data_section != 0) {
struct symtab_command sc;
uint8_t *sym_buf = base_buf;
uint8_t *str_buf = base_buf;
memcpy(&sc, buf, sizeof(struct symtab_command));
if (sc.cmdsize != sizeof(struct symtab_command)) {
log_msg("Can't find symbol table!\n");
goto bail;
}
sym_buf += sc.symoff;
str_buf += sc.stroff;
for (j = 0; j < sc.nsyms; j++) {
/* Location of string is cacluated each time from the
* start of the string buffer. On darwin the symbols
* are prefixed by "_", so we bump the pointer by 1.
* The target value is defined as an int in *_asm_*_offsets.c,
* which is 4 bytes on all targets we currently use.
*/
if (bits == 32) {
struct nlist nl;
int val;
memcpy(&nl, sym_buf, sizeof(struct nlist));
sym_buf += sizeof(struct nlist);
memcpy(&val, base_buf + base_data_section + nl.n_value,
sizeof(val));
print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
} else { /* if (bits == 64) */
struct nlist_64 nl;
int val;
memcpy(&nl, sym_buf, sizeof(struct nlist_64));
sym_buf += sizeof(struct nlist_64);
memcpy(&val, base_buf + base_data_section + nl.n_value,
sizeof(val));
print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
}
}
}
}
buf += lc.cmdsize;
}
return 0;
bail:
return 1;
}
#elif defined(__ELF__)
#include "elf.h"
#define COPY_STRUCT(dst, buf, ofst, sz) do {\
if(ofst + sizeof((*(dst))) > sz) goto bail;\
memcpy(dst, buf+ofst, sizeof((*(dst))));\
} while(0)
#define ENDIAN_ASSIGN(val, memb) do {\
if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\
(val) = (memb);\
} while(0)
#define ENDIAN_ASSIGN_IN_PLACE(memb) do {\
ENDIAN_ASSIGN(memb, memb);\
} while(0)
typedef struct {
uint8_t *buf; /* Buffer containing ELF data */
size_t sz; /* Buffer size */
int le_data; /* Data is little-endian */
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
int bits; /* 32 or 64 */
Elf32_Ehdr hdr32;
Elf64_Ehdr hdr64;
} elf_obj_t;
int parse_elf_header(elf_obj_t *elf) {
int res;
/* Verify ELF Magic numbers */
COPY_STRUCT(&elf->e_ident, elf->buf, 0, elf->sz);
res = elf->e_ident[EI_MAG0] == ELFMAG0;
res &= elf->e_ident[EI_MAG1] == ELFMAG1;
res &= elf->e_ident[EI_MAG2] == ELFMAG2;
res &= elf->e_ident[EI_MAG3] == ELFMAG3;
res &= elf->e_ident[EI_CLASS] == ELFCLASS32
|| elf->e_ident[EI_CLASS] == ELFCLASS64;
res &= elf->e_ident[EI_DATA] == ELFDATA2LSB;
if (!res) goto bail;
elf->le_data = elf->e_ident[EI_DATA] == ELFDATA2LSB;
/* Read in relevant values */
if (elf->e_ident[EI_CLASS] == ELFCLASS32) {
elf->bits = 32;
COPY_STRUCT(&elf->hdr32, elf->buf, 0, elf->sz);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_type);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_machine);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_version);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_entry);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phoff);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shoff);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_flags);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_ehsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phentsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phnum);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shentsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shnum);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shstrndx);
} else { /* if (elf->e_ident[EI_CLASS] == ELFCLASS64) */
elf->bits = 64;
COPY_STRUCT(&elf->hdr64, elf->buf, 0, elf->sz);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_type);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_machine);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_version);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_entry);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phoff);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shoff);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_flags);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_ehsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phentsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phnum);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shentsize);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shnum);
ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shstrndx);
}
return 0;
bail:
log_msg("Failed to parse ELF file header");
return 1;
}
int parse_elf_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr32, Elf64_Shdr *hdr64) {
if (hdr32) {
if (idx >= elf->hdr32.e_shnum)
goto bail;
COPY_STRUCT(hdr32, elf->buf, elf->hdr32.e_shoff + idx * elf->hdr32.e_shentsize,
elf->sz);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_name);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_type);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_flags);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addr);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_offset);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_size);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_link);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_info);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addralign);
ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_entsize);
} else { /* if (hdr64) */
if (idx >= elf->hdr64.e_shnum)
goto bail;
COPY_STRUCT(hdr64, elf->buf, elf->hdr64.e_shoff + idx * elf->hdr64.e_shentsize,
elf->sz);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_name);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_type);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_flags);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addr);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_offset);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_size);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_link);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_info);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addralign);
ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_entsize);
}
return 0;
bail:
return 1;
}
const char *parse_elf_string_table(elf_obj_t *elf, int s_idx, int idx) {
if (elf->bits == 32) {
Elf32_Shdr shdr;
if (parse_elf_section(elf, s_idx, &shdr, NULL)) {
log_msg("Failed to parse ELF string table: section %d, index %d\n",
s_idx, idx);
return "";
}
return (char *)(elf->buf + shdr.sh_offset + idx);
} else { /* if (elf->bits == 64) */
Elf64_Shdr shdr;
if (parse_elf_section(elf, s_idx, NULL, &shdr)) {
log_msg("Failed to parse ELF string table: section %d, index %d\n",
s_idx, idx);
return "";
}
return (char *)(elf->buf + shdr.sh_offset + idx);
}
}
int parse_elf_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym32, Elf64_Sym *sym64) {
if (sym32) {
COPY_STRUCT(sym32, elf->buf, ofst, elf->sz);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_name);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_value);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_size);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_info);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_other);
ENDIAN_ASSIGN_IN_PLACE(sym32->st_shndx);
} else { /* if (sym64) */
COPY_STRUCT(sym64, elf->buf, ofst, elf->sz);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_name);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_value);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_size);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_info);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_other);
ENDIAN_ASSIGN_IN_PLACE(sym64->st_shndx);
}
return 0;
bail:
return 1;
}
int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) {
elf_obj_t elf;
unsigned int ofst;
int i;
Elf32_Off strtab_off32;
Elf64_Off strtab_off64; /* save String Table offset for later use */
memset(&elf, 0, sizeof(elf));
elf.buf = buf;
elf.sz = sz;
/* Parse Header */
if (parse_elf_header(&elf))
goto bail;
if (elf.bits == 32) {
Elf32_Shdr shdr;
for (i = 0; i < elf.hdr32.e_shnum; i++) {
parse_elf_section(&elf, i, &shdr, NULL);
if (shdr.sh_type == SHT_STRTAB) {
char strtsb_name[128];
strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
if (!(strcmp(strtsb_name, ".shstrtab"))) {
/* log_msg("found section: %s\n", strtsb_name); */
strtab_off32 = shdr.sh_offset;
break;
}
}
}
} else { /* if (elf.bits == 64) */
Elf64_Shdr shdr;
for (i = 0; i < elf.hdr64.e_shnum; i++) {
parse_elf_section(&elf, i, NULL, &shdr);
if (shdr.sh_type == SHT_STRTAB) {
char strtsb_name[128];
strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
if (!(strcmp(strtsb_name, ".shstrtab"))) {
/* log_msg("found section: %s\n", strtsb_name); */
strtab_off64 = shdr.sh_offset;
break;
}
}
}
}
/* Parse all Symbol Tables */
if (elf.bits == 32) {
Elf32_Shdr shdr;
for (i = 0; i < elf.hdr32.e_shnum; i++) {
parse_elf_section(&elf, i, &shdr, NULL);
if (shdr.sh_type == SHT_SYMTAB) {
for (ofst = shdr.sh_offset;
ofst < shdr.sh_offset + shdr.sh_size;
ofst += shdr.sh_entsize) {
Elf32_Sym sym;
parse_elf_symbol(&elf, ofst, &sym, NULL);
/* For all OBJECTS (data objects), extract the value from the
* proper data segment.
*/
/* if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
log_msg("found data object %s\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name));
*/
if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT
&& sym.st_size == 4) {
Elf32_Shdr dhdr;
int val = 0;
char section_name[128];
parse_elf_section(&elf, sym.st_shndx, &dhdr, NULL);
/* For explanition - refer to _MSC_VER version of code */
strcpy(section_name, (char *)(elf.buf + strtab_off32 + dhdr.sh_name));
/* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
if (strcmp(section_name, ".bss")) {
if (sizeof(val) != sym.st_size) {
/* The target value is declared as an int in
* *_asm_*_offsets.c, which is 4 bytes on all
* targets we currently use. Complain loudly if
* this is not true.
*/
log_msg("Symbol size is wrong\n");
goto bail;
}
memcpy(&val,
elf.buf + dhdr.sh_offset + sym.st_value,
sym.st_size);
}
if (!elf.le_data) {
log_msg("Big Endian data not supported yet!\n");
goto bail;
}
switch (mode) {
case OUTPUT_FMT_RVDS:
printf("%-40s EQU %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
case OUTPUT_FMT_GAS:
printf(".equ %-40s, %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
case OUTPUT_FMT_C_HEADER:
printf("#define %-40s %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
default:
printf("%s = %d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
}
}
}
}
}
} else { /* if (elf.bits == 64) */
Elf64_Shdr shdr;
for (i = 0; i < elf.hdr64.e_shnum; i++) {
parse_elf_section(&elf, i, NULL, &shdr);
if (shdr.sh_type == SHT_SYMTAB) {
for (ofst = shdr.sh_offset;
ofst < shdr.sh_offset + shdr.sh_size;
ofst += shdr.sh_entsize) {
Elf64_Sym sym;
parse_elf_symbol(&elf, ofst, NULL, &sym);
/* For all OBJECTS (data objects), extract the value from the
* proper data segment.
*/
/* if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
log_msg("found data object %s\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name));
*/
if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT
&& sym.st_size == 4) {
Elf64_Shdr dhdr;
int val = 0;
char section_name[128];
parse_elf_section(&elf, sym.st_shndx, NULL, &dhdr);
/* For explanition - refer to _MSC_VER version of code */
strcpy(section_name, (char *)(elf.buf + strtab_off64 + dhdr.sh_name));
/* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
if ((strcmp(section_name, ".bss"))) {
if (sizeof(val) != sym.st_size) {
/* The target value is declared as an int in
* *_asm_*_offsets.c, which is 4 bytes on all
* targets we currently use. Complain loudly if
* this is not true.
*/
log_msg("Symbol size is wrong\n");
goto bail;
}
memcpy(&val,
elf.buf + dhdr.sh_offset + sym.st_value,
sym.st_size);
}
if (!elf.le_data) {
log_msg("Big Endian data not supported yet!\n");
goto bail;
}
switch (mode) {
case OUTPUT_FMT_RVDS:
printf("%-40s EQU %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
case OUTPUT_FMT_GAS:
printf(".equ %-40s, %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
default:
printf("%s = %d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
}
}
}
}
}
}
if (mode == OUTPUT_FMT_RVDS)
printf(" END\n");
return 0;
bail:
log_msg("Parse error: File does not appear to be valid ELF32 or ELF64\n");
return 1;
}
#endif
#endif /* defined(__GNUC__) && __GNUC__ */
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
/* See "Microsoft Portable Executable and Common Object File Format Specification"
for reference.
*/
#define get_le32(x) ((*(x)) | (*(x+1)) << 8 |(*(x+2)) << 16 | (*(x+3)) << 24 )
#define get_le16(x) ((*(x)) | (*(x+1)) << 8)
int parse_coff(uint8_t *buf, size_t sz) {
unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr;
unsigned int sectionrawdata_ptr;
unsigned int i;
uint8_t *ptr;
uint32_t symoffset;
char **sectionlist; // this array holds all section names in their correct order.
// it is used to check if the symbol is in .bss or .rdata section.
nsections = get_le16(buf + 2);
symtab_ptr = get_le32(buf + 8);
symtab_sz = get_le32(buf + 12);
strtab_ptr = symtab_ptr + symtab_sz * 18;
if (nsections > 96) {
log_msg("Too many sections\n");
return 1;
}
sectionlist = malloc(nsections * sizeof(sectionlist));
if (sectionlist == NULL) {
log_msg("Allocating first level of section list failed\n");
return 1;
}
// log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections);
/*
The size of optional header is always zero for an obj file. So, the section header
follows the file header immediately.
*/
ptr = buf + 20; // section header
for (i = 0; i < nsections; i++) {
char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
strncpy(sectionname, ptr, 8);
// log_msg("COFF: Parsing section %s\n",sectionname);
sectionlist[i] = malloc(strlen(sectionname) + 1);
if (sectionlist[i] == NULL) {
log_msg("Allocating storage for %s failed\n", sectionname);
goto bail;
}
strcpy(sectionlist[i], sectionname);
// check if it's .rdata and is not a COMDAT section.
if (!strcmp(sectionname, ".rdata") &&
(get_le32(ptr + 36) & 0x1000) == 0) {
sectionrawdata_ptr = get_le32(ptr + 20);
}
ptr += 40;
}
// log_msg("COFF: Symbol table at offset %u\n", symtab_ptr);
// log_msg("COFF: raw data pointer ofset for section .rdata is %u\n", sectionrawdata_ptr);
/* The compiler puts the data with non-zero offset in .rdata section, but puts the data with
zero offset in .bss section. So, if the data in in .bss section, set offset=0.
Note from Wiki: In an object module compiled from C, the bss section contains
the local variables (but not functions) that were declared with the static keyword,
except for those with non-zero initial values. (In C, static variables are initialized
to zero by default.) It also contains the non-local (both extern and static) variables
that are also initialized to zero (either explicitly or by default).
*/
// move to symbol table
/* COFF symbol table:
offset field
0 Name(*)
8 Value
12 SectionNumber
14 Type
16 StorageClass
17 NumberOfAuxSymbols
*/
ptr = buf + symtab_ptr;
for (i = 0; i < symtab_sz; i++) {
int16_t section = get_le16(ptr + 12); // section number
if (section > 0 && ptr[16] == 2) {
// if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) {
if (get_le32(ptr)) {
char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
strncpy(name, ptr, 8);
// log_msg("COFF: Parsing symbol %s\n",name);
/* The 64bit Windows compiler doesn't prefix with an _.
* Check what's there, and bump if necessary
*/
if (name[0] == '_')
printf("%-40s EQU ", name + 1);
else
printf("%-40s EQU ", name);
} else {
// log_msg("COFF: Parsing symbol %s\n",
// buf + strtab_ptr + get_le32(ptr+4));
if ((buf + strtab_ptr + get_le32(ptr + 4))[0] == '_')
printf("%-40s EQU ",
buf + strtab_ptr + get_le32(ptr + 4) + 1);
else
printf("%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4));
}
if (!(strcmp(sectionlist[section - 1], ".bss"))) {
symoffset = 0;
} else {
symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8));
}
// log_msg(" Section: %d\n",section);
// log_msg(" Class: %d\n",ptr[16]);
// log_msg(" Address: %u\n",get_le32(ptr+8));
// log_msg(" Offset: %u\n", symoffset);
printf("%5d\n", symoffset);
}
ptr += 18;
}
printf(" END\n");
for (i = 0; i < nsections; i++) {
free(sectionlist[i]);
}
free(sectionlist);
return 0;
bail:
for (i = 0; i < nsections; i++) {
free(sectionlist[i]);
}
free(sectionlist);
return 1;
}
#endif /* defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) */
int main(int argc, char **argv) {
output_fmt_t mode = OUTPUT_FMT_PLAIN;
const char *f;
uint8_t *file_buf;
int res;
FILE *fp;
long int file_size;
if (argc < 2 || argc > 3) {
fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]);
fprintf(stderr, " <obj file>\tobject file to parse\n");
fprintf(stderr, "Output Formats:\n");
fprintf(stderr, " gas - compatible with GNU assembler\n");
fprintf(stderr, " rvds - compatible with armasm\n");
fprintf(stderr, " cheader - c/c++ header file\n");
goto bail;
}
f = argv[2];
if (!strcmp(argv[1], "rvds"))
mode = OUTPUT_FMT_RVDS;
else if (!strcmp(argv[1], "gas"))
mode = OUTPUT_FMT_GAS;
else if (!strcmp(argv[1], "cheader"))
mode = OUTPUT_FMT_C_HEADER;
else
f = argv[1];
fp = fopen(f, "rb");
if (!fp) {
perror("Unable to open file");
goto bail;
}
if (fseek(fp, 0, SEEK_END)) {
perror("stat");
goto bail;
}
file_size = ftell(fp);
file_buf = malloc(file_size);
if (!file_buf) {
perror("malloc");
goto bail;
}
rewind(fp);
if (fread(file_buf, sizeof(char), file_size, fp) != file_size) {
perror("read");
goto bail;
}
if (fclose(fp)) {
perror("close");
goto bail;
}
#if defined(__GNUC__) && __GNUC__
#if defined(__MACH__)
res = parse_macho(file_buf, file_size, mode);
#elif defined(__ELF__)
res = parse_elf(file_buf, file_size, mode);
#endif
#endif
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
res = parse_coff(file_buf, file_size);
#endif
free(file_buf);
if (!res)
return EXIT_SUCCESS;
bail:
return EXIT_FAILURE;
}

View File

@ -1,13 +1,4 @@
#!/usr/bin/env perl #!/usr/bin/env perl
##
## Copyright (c) 2017 The WebM project authors. All Rights Reserved.
##
## Use of this source code is governed by a BSD-style license
## that can be found in the LICENSE file in the root of the source
## tree. An additional intellectual property rights grant can be found
## in the file PATENTS. All contributing project authors may
## be found in the AUTHORS file in the root of the source tree.
##
no strict 'refs'; no strict 'refs';
use warnings; use warnings;
@ -209,7 +200,6 @@ sub filter {
sub common_top() { sub common_top() {
my $include_guard = uc($opts{sym})."_H_"; my $include_guard = uc($opts{sym})."_H_";
print <<EOF; print <<EOF;
// This file is generated. Do not edit.
#ifndef ${include_guard} #ifndef ${include_guard}
#define ${include_guard} #define ${include_guard}
@ -329,46 +319,15 @@ EOF
print <<EOF; print <<EOF;
#if HAVE_DSPR2 #if HAVE_DSPR2
void vpx_dsputil_static_init();
#if CONFIG_VP8 #if CONFIG_VP8
void dsputil_static_init(); void dsputil_static_init();
#endif
vpx_dsputil_static_init();
#if CONFIG_VP8
dsputil_static_init(); dsputil_static_init();
#endif #endif
#if CONFIG_VP9
void vp9_dsputil_static_init();
vp9_dsputil_static_init();
#endif #endif
}
#endif #endif
EOF
common_bottom;
}
sub ppc() {
determine_indirection("c", @ALL_ARCHS);
# Assign the helper variable for each enabled extension
foreach my $opt (@ALL_ARCHS) {
my $opt_uc = uc $opt;
eval "\$have_${opt}=\"flags & HAS_${opt_uc}\"";
}
common_top;
print <<EOF;
#include "vpx_config.h"
#ifdef RTCD_C
#include "vpx_ports/ppc.h"
static void setup_rtcd_internal(void)
{
int flags = ppc_simd_caps();
(void)flags;
EOF
set_function_pointers("c", @ALL_ARCHS);
print <<EOF;
} }
#endif #endif
EOF EOF
@ -401,10 +360,10 @@ EOF
&require("c"); &require("c");
if ($opts{arch} eq 'x86') { if ($opts{arch} eq 'x86') {
@ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2 avx512/); @ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2/);
x86; x86;
} elsif ($opts{arch} eq 'x86_64') { } elsif ($opts{arch} eq 'x86_64') {
@ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2 avx512/); @ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2/);
@REQUIRES = filter(keys %required ? keys %required : qw/mmx sse sse2/); @REQUIRES = filter(keys %required ? keys %required : qw/mmx sse sse2/);
&require(@REQUIRES); &require(@REQUIRES);
x86; x86;
@ -417,26 +376,23 @@ if ($opts{arch} eq 'x86') {
@ALL_ARCHS = filter("$opts{arch}", qw/dspr2/); @ALL_ARCHS = filter("$opts{arch}", qw/dspr2/);
last; last;
} }
if (/HAVE_MSA=yes/) {
@ALL_ARCHS = filter("$opts{arch}", qw/msa/);
last;
}
if (/HAVE_MMI=yes/) {
@ALL_ARCHS = filter("$opts{arch}", qw/mmi/);
last;
}
} }
close CONFIG_FILE; close CONFIG_FILE;
mips; mips;
} elsif ($opts{arch} =~ /armv7\w?/) { } elsif ($opts{arch} eq 'armv5te') {
@ALL_ARCHS = filter(qw/neon_asm neon/); @ALL_ARCHS = filter(qw/edsp/);
arm;
} elsif ($opts{arch} eq 'armv6') {
@ALL_ARCHS = filter(qw/edsp media/);
arm;
} elsif ($opts{arch} eq 'armv7') {
@ALL_ARCHS = filter(qw/edsp media neon_asm neon/);
@REQUIRES = filter(keys %required ? keys %required : qw/media/);
&require(@REQUIRES);
arm; arm;
} elsif ($opts{arch} eq 'armv8' || $opts{arch} eq 'arm64' ) { } elsif ($opts{arch} eq 'armv8' || $opts{arch} eq 'arm64' ) {
@ALL_ARCHS = filter(qw/neon/); @ALL_ARCHS = filter(qw/neon/);
arm; arm;
} elsif ($opts{arch} =~ /^ppc/ ) {
@ALL_ARCHS = filter(qw/vsx/);
ppc;
} else { } else {
unoptimized; unoptimized;
} }

View File

@ -54,6 +54,13 @@ sub FixThumbInstructions($$)
# "addne r0, r0, r2". # "addne r0, r0, r2".
s/^(\s*)((ldr|str)(ne)?[bhd]?)(\s+)(\w+),(\s*\w+,)?\s*\[(\w+)\],\s*(\w+)/$1$2$5$6,$7 [$8]\n$1add$4$5$8, $8, $9/g; s/^(\s*)((ldr|str)(ne)?[bhd]?)(\s+)(\w+),(\s*\w+,)?\s*\[(\w+)\],\s*(\w+)/$1$2$5$6,$7 [$8]\n$1add$4$5$8, $8, $9/g;
# Convert a conditional addition to the pc register into a series of
# instructions. This converts "addlt pc, pc, r3, lsl #2" into
# "itttt lt", "movlt.n r12, pc", "addlt.w r12, #12",
# "addlt.w r12, r12, r3, lsl #2", "movlt.n pc, r12".
# This assumes that r12 is free at this point.
s/^(\s*)addlt(\s+)pc,\s*pc,\s*(\w+),\s*lsl\s*#(\d+)/$1itttt$2lt\n$1movlt.n$2r12, pc\n$1addlt.w$2r12, #12\n$1addlt.w$2r12, r12, $3, lsl #($4-$branch_shift_offset)\n$1movlt.n$2pc, r12/g;
# Convert "mov pc, lr" into "bx lr", since the former only works # Convert "mov pc, lr" into "bx lr", since the former only works
# for switching from arm to thumb (and only in armv7), but not # for switching from arm to thumb (and only in armv7), but not
# from thumb to arm. # from thumb to arm.

View File

@ -24,9 +24,8 @@ out_file=${2}
id=${3:-VERSION_STRING} id=${3:-VERSION_STRING}
git_version_id="" git_version_id=""
if [ -e "${source_path}/.git" ]; then if [ -d "${source_path}/.git" ]; then
# Source Path is a git working copy. Check for local modifications. # Source Path is a git working copy. Check for local modifications.
# Note that git submodules may have a file as .git, not a directory.
export GIT_DIR="${source_path}/.git" export GIT_DIR="${source_path}/.git"
git_version_id=`git describe --match=v[0-9]* 2>/dev/null` git_version_id=`git describe --match=v[0-9]* 2>/dev/null`
fi fi
@ -60,7 +59,6 @@ if [ ${bare} ]; then
echo "${changelog_version}${git_version_id}" > $$.tmp echo "${changelog_version}${git_version_id}" > $$.tmp
else else
cat<<EOF>$$.tmp cat<<EOF>$$.tmp
// This file is generated. Do not edit.
#define VERSION_MAJOR $major_version #define VERSION_MAJOR $major_version
#define VERSION_MINOR $minor_version #define VERSION_MINOR $minor_version
#define VERSION_PATCH $patch_version #define VERSION_PATCH $patch_version

View File

@ -0,0 +1,15 @@
REM Copyright (c) 2011 The WebM project authors. All Rights Reserved.
REM
REM Use of this source code is governed by a BSD-style license
REM that can be found in the LICENSE file in the root of the source
REM tree. An additional intellectual property rights grant can be found
REM in the file PATENTS. All contributing project authors may
REM be found in the AUTHORS file in the root of the source tree.
echo on
REM Arguments:
REM %1 - Relative path to the directory containing the vp8 source directory.
REM %2 - Path to obj_int_extract.exe.
cl /I. /I%1 /nologo /c "%~1/vp8/encoder/vp8_asm_enc_offsets.c"
%2\obj_int_extract.exe rvds "vp8_asm_enc_offsets.obj" > "vp8_asm_enc_offsets.asm"

View File

@ -1,4 +0,0 @@
# This file is used by git cl to get repository specific information.
GERRIT_HOST: True
CODE_REVIEW_SERVER: chromium-review.googlesource.com
GERRIT_SQUASH_UPLOADS: False

327
configure vendored
View File

@ -22,7 +22,6 @@ show_help(){
Advanced options: Advanced options:
${toggle_libs} libraries ${toggle_libs} libraries
${toggle_examples} examples ${toggle_examples} examples
${toggle_tools} tools
${toggle_docs} documentation ${toggle_docs} documentation
${toggle_unit_tests} unit tests ${toggle_unit_tests} unit tests
${toggle_decode_perf_tests} build decoder perf tests with unit tests ${toggle_decode_perf_tests} build decoder perf tests with unit tests
@ -32,16 +31,15 @@ Advanced options:
--size-limit=WxH max size to allow in the decoder --size-limit=WxH max size to allow in the decoder
--as={yasm|nasm|auto} use specified assembler [auto, yasm preferred] --as={yasm|nasm|auto} use specified assembler [auto, yasm preferred]
--sdk-path=PATH path to root of sdk (android builds only) --sdk-path=PATH path to root of sdk (android builds only)
${toggle_fast_unaligned} don't use unaligned accesses, even when
supported by hardware [auto]
${toggle_codec_srcs} in/exclude codec library source code ${toggle_codec_srcs} in/exclude codec library source code
${toggle_debug_libs} in/exclude debug version of libraries ${toggle_debug_libs} in/exclude debug version of libraries
${toggle_static_msvcrt} use static MSVCRT (VS builds only) ${toggle_static_msvcrt} use static MSVCRT (VS builds only)
${toggle_vp9_highbitdepth} use VP9 high bit depth (10/12) profiles
${toggle_better_hw_compatibility}
enable encoder to produce streams with better
hardware decoder compatibility
${toggle_vp8} VP8 codec support ${toggle_vp8} VP8 codec support
${toggle_vp9} VP9 codec support ${toggle_vp9} VP9 codec support
${toggle_internal_stats} output of encoder internal stats for debug, if supported (encoders) ${toggle_internal_stats} output of encoder internal stats for debug, if supported (encoders)
${toggle_mem_tracker} track memory usage
${toggle_postproc} postprocessing ${toggle_postproc} postprocessing
${toggle_vp9_postproc} vp9 specific postprocessing ${toggle_vp9_postproc} vp9 specific postprocessing
${toggle_multithread} multithreaded encoding and decoding ${toggle_multithread} multithreaded encoding and decoding
@ -59,8 +57,6 @@ Advanced options:
${toggle_postproc_visualizer} macro block / block level visualizers ${toggle_postproc_visualizer} macro block / block level visualizers
${toggle_multi_res_encoding} enable multiple-resolution encoding ${toggle_multi_res_encoding} enable multiple-resolution encoding
${toggle_temporal_denoising} enable temporal denoising and disable the spatial denoiser ${toggle_temporal_denoising} enable temporal denoising and disable the spatial denoiser
${toggle_vp9_temporal_denoising}
enable vp9 temporal denoising
${toggle_webm_io} enable input from and output to WebM container ${toggle_webm_io} enable input from and output to WebM container
${toggle_libyuv} enable libyuv ${toggle_libyuv} enable libyuv
@ -98,26 +94,31 @@ EOF
# all_platforms is a list of all supported target platforms. Maintain # all_platforms is a list of all supported target platforms. Maintain
# alphabetically by architecture, generic-gnu last. # alphabetically by architecture, generic-gnu last.
all_platforms="${all_platforms} arm64-android-gcc" all_platforms="${all_platforms} armv5te-android-gcc"
all_platforms="${all_platforms} armv5te-linux-rvct"
all_platforms="${all_platforms} armv5te-linux-gcc"
all_platforms="${all_platforms} armv5te-none-rvct"
all_platforms="${all_platforms} armv6-darwin-gcc"
all_platforms="${all_platforms} armv6-linux-rvct"
all_platforms="${all_platforms} armv6-linux-gcc"
all_platforms="${all_platforms} armv6-none-rvct"
all_platforms="${all_platforms} arm64-darwin-gcc" all_platforms="${all_platforms} arm64-darwin-gcc"
all_platforms="${all_platforms} arm64-linux-gcc"
all_platforms="${all_platforms} arm64-win64-gcc"
all_platforms="${all_platforms} armv7-android-gcc" #neon Cortex-A8 all_platforms="${all_platforms} armv7-android-gcc" #neon Cortex-A8
all_platforms="${all_platforms} armv7-darwin-gcc" #neon Cortex-A8 all_platforms="${all_platforms} armv7-darwin-gcc" #neon Cortex-A8
all_platforms="${all_platforms} armv7-linux-rvct" #neon Cortex-A8 all_platforms="${all_platforms} armv7-linux-rvct" #neon Cortex-A8
all_platforms="${all_platforms} armv7-linux-gcc" #neon Cortex-A8 all_platforms="${all_platforms} armv7-linux-gcc" #neon Cortex-A8
all_platforms="${all_platforms} armv7-none-rvct" #neon Cortex-A8 all_platforms="${all_platforms} armv7-none-rvct" #neon Cortex-A8
all_platforms="${all_platforms} armv7-win32-gcc"
all_platforms="${all_platforms} armv7-win32-vs11" all_platforms="${all_platforms} armv7-win32-vs11"
all_platforms="${all_platforms} armv7-win32-vs12" all_platforms="${all_platforms} armv7-win32-vs12"
all_platforms="${all_platforms} armv7-win32-vs14"
all_platforms="${all_platforms} armv7-win32-vs15"
all_platforms="${all_platforms} armv7s-darwin-gcc" all_platforms="${all_platforms} armv7s-darwin-gcc"
all_platforms="${all_platforms} armv8-linux-gcc"
all_platforms="${all_platforms} mips32-linux-gcc" all_platforms="${all_platforms} mips32-linux-gcc"
all_platforms="${all_platforms} mips64-linux-gcc" all_platforms="${all_platforms} mips64-linux-gcc"
all_platforms="${all_platforms} ppc32-darwin8-gcc"
all_platforms="${all_platforms} ppc32-darwin9-gcc"
all_platforms="${all_platforms} ppc32-linux-gcc"
all_platforms="${all_platforms} ppc64-darwin8-gcc"
all_platforms="${all_platforms} ppc64-darwin9-gcc"
all_platforms="${all_platforms} ppc64-linux-gcc" all_platforms="${all_platforms} ppc64-linux-gcc"
all_platforms="${all_platforms} ppc64le-linux-gcc"
all_platforms="${all_platforms} sparc-solaris-gcc" all_platforms="${all_platforms} sparc-solaris-gcc"
all_platforms="${all_platforms} x86-android-gcc" all_platforms="${all_platforms} x86-android-gcc"
all_platforms="${all_platforms} x86-darwin8-gcc" all_platforms="${all_platforms} x86-darwin8-gcc"
@ -128,60 +129,55 @@ all_platforms="${all_platforms} x86-darwin10-gcc"
all_platforms="${all_platforms} x86-darwin11-gcc" all_platforms="${all_platforms} x86-darwin11-gcc"
all_platforms="${all_platforms} x86-darwin12-gcc" all_platforms="${all_platforms} x86-darwin12-gcc"
all_platforms="${all_platforms} x86-darwin13-gcc" all_platforms="${all_platforms} x86-darwin13-gcc"
all_platforms="${all_platforms} x86-darwin14-gcc"
all_platforms="${all_platforms} x86-darwin15-gcc"
all_platforms="${all_platforms} x86-darwin16-gcc"
all_platforms="${all_platforms} x86-darwin17-gcc"
all_platforms="${all_platforms} x86-iphonesimulator-gcc" all_platforms="${all_platforms} x86-iphonesimulator-gcc"
all_platforms="${all_platforms} x86-linux-gcc" all_platforms="${all_platforms} x86-linux-gcc"
all_platforms="${all_platforms} x86-linux-icc" all_platforms="${all_platforms} x86-linux-icc"
all_platforms="${all_platforms} x86-os2-gcc" all_platforms="${all_platforms} x86-os2-gcc"
all_platforms="${all_platforms} x86-solaris-gcc" all_platforms="${all_platforms} x86-solaris-gcc"
all_platforms="${all_platforms} x86-win32-gcc" all_platforms="${all_platforms} x86-win32-gcc"
all_platforms="${all_platforms} x86-win32-vs7"
all_platforms="${all_platforms} x86-win32-vs8"
all_platforms="${all_platforms} x86-win32-vs9"
all_platforms="${all_platforms} x86-win32-vs10" all_platforms="${all_platforms} x86-win32-vs10"
all_platforms="${all_platforms} x86-win32-vs11" all_platforms="${all_platforms} x86-win32-vs11"
all_platforms="${all_platforms} x86-win32-vs12" all_platforms="${all_platforms} x86-win32-vs12"
all_platforms="${all_platforms} x86-win32-vs14"
all_platforms="${all_platforms} x86-win32-vs15"
all_platforms="${all_platforms} x86_64-android-gcc"
all_platforms="${all_platforms} x86_64-darwin9-gcc" all_platforms="${all_platforms} x86_64-darwin9-gcc"
all_platforms="${all_platforms} x86_64-darwin10-gcc" all_platforms="${all_platforms} x86_64-darwin10-gcc"
all_platforms="${all_platforms} x86_64-darwin11-gcc" all_platforms="${all_platforms} x86_64-darwin11-gcc"
all_platforms="${all_platforms} x86_64-darwin12-gcc" all_platforms="${all_platforms} x86_64-darwin12-gcc"
all_platforms="${all_platforms} x86_64-darwin13-gcc" all_platforms="${all_platforms} x86_64-darwin13-gcc"
all_platforms="${all_platforms} x86_64-darwin14-gcc"
all_platforms="${all_platforms} x86_64-darwin15-gcc"
all_platforms="${all_platforms} x86_64-darwin16-gcc"
all_platforms="${all_platforms} x86_64-darwin17-gcc"
all_platforms="${all_platforms} x86_64-iphonesimulator-gcc" all_platforms="${all_platforms} x86_64-iphonesimulator-gcc"
all_platforms="${all_platforms} x86_64-linux-gcc" all_platforms="${all_platforms} x86_64-linux-gcc"
all_platforms="${all_platforms} x86_64-linux-icc" all_platforms="${all_platforms} x86_64-linux-icc"
all_platforms="${all_platforms} x86_64-solaris-gcc" all_platforms="${all_platforms} x86_64-solaris-gcc"
all_platforms="${all_platforms} x86_64-win64-gcc" all_platforms="${all_platforms} x86_64-win64-gcc"
all_platforms="${all_platforms} x86_64-win64-vs8"
all_platforms="${all_platforms} x86_64-win64-vs9"
all_platforms="${all_platforms} x86_64-win64-vs10" all_platforms="${all_platforms} x86_64-win64-vs10"
all_platforms="${all_platforms} x86_64-win64-vs11" all_platforms="${all_platforms} x86_64-win64-vs11"
all_platforms="${all_platforms} x86_64-win64-vs12" all_platforms="${all_platforms} x86_64-win64-vs12"
all_platforms="${all_platforms} x86_64-win64-vs14" all_platforms="${all_platforms} universal-darwin8-gcc"
all_platforms="${all_platforms} x86_64-win64-vs15" all_platforms="${all_platforms} universal-darwin9-gcc"
all_platforms="${all_platforms} universal-darwin10-gcc"
all_platforms="${all_platforms} universal-darwin11-gcc"
all_platforms="${all_platforms} universal-darwin12-gcc"
all_platforms="${all_platforms} universal-darwin13-gcc"
all_platforms="${all_platforms} generic-gnu" all_platforms="${all_platforms} generic-gnu"
# all_targets is a list of all targets that can be configured # all_targets is a list of all targets that can be configured
# note that these should be in dependency order for now. # note that these should be in dependency order for now.
all_targets="libs examples tools docs" all_targets="libs examples docs"
# all targets available are enabled, by default. # all targets available are enabled, by default.
for t in ${all_targets}; do for t in ${all_targets}; do
[ -f "${source_path}/${t}.mk" ] && enable_feature ${t} [ -f "${source_path}/${t}.mk" ] && enable_feature ${t}
done done
if ! diff --version >/dev/null; then
die "diff missing: Try installing diffutils via your package manager."
fi
if ! perl --version >/dev/null; then if ! perl --version >/dev/null; then
die "Perl is required to build" die "Perl is required to build"
fi fi
if [ "`cd \"${source_path}\" && pwd`" != "`pwd`" ]; then if [ "`cd \"${source_path}\" && pwd`" != "`pwd`" ]; then
# test to see if source_path already configured # test to see if source_path already configured
if [ -f "${source_path}/vpx_config.h" ]; then if [ -f "${source_path}/vpx_config.h" ]; then
@ -202,10 +198,6 @@ if [ ${doxy_major:-0} -ge 1 ]; then
[ $doxy_minor -eq 5 ] && [ $doxy_patch -ge 3 ] && enable_feature doxygen [ $doxy_minor -eq 5 ] && [ $doxy_patch -ge 3 ] && enable_feature doxygen
fi fi
# disable codecs when their source directory does not exist
[ -d "${source_path}/vp8" ] || disable_codec vp8
[ -d "${source_path}/vp9" ] || disable_codec vp9
# install everything except the sources, by default. sources will have # install everything except the sources, by default. sources will have
# to be enabled when doing dist builds, since that's no longer a common # to be enabled when doing dist builds, since that's no longer a common
# case. # case.
@ -215,31 +207,57 @@ enable_feature install_libs
enable_feature static enable_feature static
enable_feature optimizations enable_feature optimizations
enable_feature dependency_tracking enable_feature fast_unaligned #allow unaligned accesses, if supported by hw
enable_feature spatial_resampling enable_feature spatial_resampling
enable_feature multithread enable_feature multithread
enable_feature os_support enable_feature os_support
enable_feature temporal_denoising enable_feature temporal_denoising
CODECS=" [ -d "${source_path}/../include" ] && enable_feature alt_tree_layout
vp8_encoder for d in vp8 vp9; do
vp8_decoder [ -d "${source_path}/${d}" ] && disable_feature alt_tree_layout;
vp9_encoder done
vp9_decoder
" if ! enabled alt_tree_layout; then
CODEC_FAMILIES=" # development environment
vp8 [ -d "${source_path}/vp8" ] && CODECS="${CODECS} vp8_encoder vp8_decoder"
vp9 [ -d "${source_path}/vp9" ] && CODECS="${CODECS} vp9_encoder vp9_decoder"
" else
# customer environment
[ -f "${source_path}/../include/vpx/vp8cx.h" ] && CODECS="${CODECS} vp8_encoder"
[ -f "${source_path}/../include/vpx/vp8dx.h" ] && CODECS="${CODECS} vp8_decoder"
[ -f "${source_path}/../include/vpx/vp9cx.h" ] && CODECS="${CODECS} vp9_encoder"
[ -f "${source_path}/../include/vpx/vp9dx.h" ] && CODECS="${CODECS} vp9_decoder"
[ -f "${source_path}/../include/vpx/vp8cx.h" ] || disable_feature vp8_encoder
[ -f "${source_path}/../include/vpx/vp8dx.h" ] || disable_feature vp8_decoder
[ -f "${source_path}/../include/vpx/vp9cx.h" ] || disable_feature vp9_encoder
[ -f "${source_path}/../include/vpx/vp9dx.h" ] || disable_feature vp9_decoder
[ -f "${source_path}/../lib/*/*mt.lib" ] && soft_enable static_msvcrt
fi
CODECS="$(echo ${CODECS} | tr ' ' '\n')"
CODEC_FAMILIES="$(for c in ${CODECS}; do echo ${c%_*}; done | sort | uniq)"
ARCH_LIST=" ARCH_LIST="
arm arm
mips mips
x86 x86
x86_64 x86_64
ppc ppc32
ppc64
" "
ARCH_EXT_LIST_X86=" ARCH_EXT_LIST="
edsp
media
neon
neon_asm
mips32
dspr2
mips64
mmx mmx
sse sse
sse2 sse2
@ -248,45 +266,55 @@ ARCH_EXT_LIST_X86="
sse4_1 sse4_1
avx avx
avx2 avx2
avx512
"
ARCH_EXT_LIST_LOONGSON=" altivec
mmi
"
ARCH_EXT_LIST="
neon
neon_asm
mips32
dspr2
msa
mips64
${ARCH_EXT_LIST_X86}
vsx
${ARCH_EXT_LIST_LOONGSON}
" "
HAVE_LIST=" HAVE_LIST="
${ARCH_EXT_LIST} ${ARCH_EXT_LIST}
vpx_ports vpx_ports
stdint_h
alt_tree_layout
pthread_h pthread_h
sys_mman_h
unistd_h unistd_h
" "
EXPERIMENT_LIST=" EXPERIMENT_LIST="
spatial_svc
vp9_temporal_denoising
fp_mb_stats fp_mb_stats
emulate_hardware emulate_hardware
tx64x64
filterintra
ext_tx
tx_skip
supertx
copy_mode
interintra
wedge_partition
global_motion
palette
new_quant
intrabc
loop_postfilter
row_tile
new_inter
bitstream_fixes
newmvref
misc_entropy
wavelets
ext_partition
qctx_tprobs
sr_mode
multi_ref
ext_coding_unit_size
" "
CONFIG_LIST=" CONFIG_LIST="
dependency_tracking
external_build external_build
install_docs install_docs
install_bins install_bins
install_libs install_libs
install_srcs install_srcs
use_x86inc
debug debug
gprof gprof
gcov gcov
@ -298,6 +326,10 @@ CONFIG_LIST="
codec_srcs codec_srcs
debug_libs debug_libs
fast_unaligned
mem_manager
mem_tracker
mem_checks
dequant_tokens dequant_tokens
dc_recon dc_recon
@ -327,17 +359,13 @@ CONFIG_LIST="
encode_perf_tests encode_perf_tests
multi_res_encoding multi_res_encoding
temporal_denoising temporal_denoising
vp9_temporal_denoising
coefficient_range_checking coefficient_range_checking
vp9_highbitdepth vp9_highbitdepth
better_hw_compatibility
experimental experimental
size_limit size_limit
always_adjust_bpm
${EXPERIMENT_LIST} ${EXPERIMENT_LIST}
" "
CMDLINE_SELECT=" CMDLINE_SELECT="
dependency_tracking
external_build external_build
extra_warnings extra_warnings
werror werror
@ -349,6 +377,7 @@ CMDLINE_SELECT="
gprof gprof
gcov gcov
pic pic
use_x86inc
optimizations optimizations
ccache ccache
runtime_cpu_detect runtime_cpu_detect
@ -356,11 +385,11 @@ CMDLINE_SELECT="
libs libs
examples examples
tools
docs docs
libc libc
as as
size_limit size_limit
fast_unaligned
codec_srcs codec_srcs
debug_libs debug_libs
@ -373,6 +402,7 @@ CMDLINE_SELECT="
${CODECS} ${CODECS}
${CODEC_FAMILIES} ${CODEC_FAMILIES}
static_msvcrt static_msvcrt
mem_tracker
spatial_resampling spatial_resampling
realtime_only realtime_only
onthefly_bitpacking onthefly_bitpacking
@ -388,31 +418,24 @@ CMDLINE_SELECT="
encode_perf_tests encode_perf_tests
multi_res_encoding multi_res_encoding
temporal_denoising temporal_denoising
vp9_temporal_denoising
coefficient_range_checking coefficient_range_checking
better_hw_compatibility
vp9_highbitdepth vp9_highbitdepth
experimental experimental
always_adjust_bpm
" "
process_cmdline() { process_cmdline() {
for opt do for opt do
optval="${opt#*=}" optval="${opt#*=}"
case "$opt" in case "$opt" in
--disable-codecs) --disable-codecs) for c in ${CODECS}; do disable_feature $c; done ;;
for c in ${CODEC_FAMILIES}; do disable_codec $c; done
;;
--enable-?*|--disable-?*) --enable-?*|--disable-?*)
eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
if is_in ${option} ${EXPERIMENT_LIST}; then if echo "${EXPERIMENT_LIST}" | grep "^ *$option\$" >/dev/null; then
if enabled experimental; then if enabled experimental; then
${action}_feature $option ${action}_feature $option
else else
log_echo "Ignoring $opt -- not in experimental mode." log_echo "Ignoring $opt -- not in experimental mode."
fi fi
elif is_in ${option} "${CODECS} ${CODEC_FAMILIES}"; then
${action}_codec ${option}
else else
process_common_cmdline $opt process_common_cmdline $opt
fi fi
@ -426,6 +449,14 @@ process_cmdline() {
post_process_cmdline() { post_process_cmdline() {
c="" c=""
# If the codec family is disabled, disable all components of that family.
# If the codec family is enabled, enable all components of that family.
log_echo "Configuring selected codecs"
for c in ${CODECS}; do
disabled ${c%%_*} && disable_feature ${c}
enabled ${c%%_*} && enable_feature ${c}
done
# Enable all detected codecs, if they haven't been disabled # Enable all detected codecs, if they haven't been disabled
for c in ${CODECS}; do soft_enable $c; done for c in ${CODECS}; do soft_enable $c; done
@ -443,8 +474,24 @@ post_process_cmdline() {
process_targets() { process_targets() {
enabled child || write_common_config_banner enabled child || write_common_config_banner
write_common_target_config_h ${BUILD_PFX}vpx_config.h enabled universal || write_common_target_config_h ${BUILD_PFX}vpx_config.h
# TODO: add host tools target (obj_int_extract, etc)
# For fat binaries, call configure recursively to configure for each
# binary architecture to be included.
if enabled universal; then
# Call configure (ourselves) for each subarchitecture
for arch in $fat_bin_archs; do
BUILD_PFX=${arch}/ toolchain=${arch} $self --child $cmdline_args || exit $?
done
fi
# The write_common_config (config.mk) logic is deferred until after the
# recursive calls to configure complete, because we want our universal
# targets to be executed last.
write_common_config_targets write_common_config_targets
enabled universal && echo "FAT_ARCHS=${fat_bin_archs}" >> config.mk
# Calculate the default distribution name, based on the enabled features # Calculate the default distribution name, based on the enabled features
cf="" cf=""
@ -503,7 +550,7 @@ EOF
# #
# Write makefiles for all enabled targets # Write makefiles for all enabled targets
# #
for tgt in libs examples tools docs solution; do for tgt in libs examples docs solution; do
tgt_fn="$tgt-$toolchain.mk" tgt_fn="$tgt-$toolchain.mk"
if enabled $tgt; then if enabled $tgt; then
@ -520,18 +567,13 @@ process_detect() {
# Can only build shared libs on a subset of platforms. Doing this check # Can only build shared libs on a subset of platforms. Doing this check
# here rather than at option parse time because the target auto-detect # here rather than at option parse time because the target auto-detect
# magic happens after the command line has been parsed. # magic happens after the command line has been parsed.
case "${tgt_os}" in if ! enabled linux; then
linux|os2|darwin*|iphonesimulator*)
# Supported platforms
;;
*)
if enabled gnu; then if enabled gnu; then
echo "--enable-shared is only supported on ELF; assuming this is OK" echo "--enable-shared is only supported on ELF; assuming this is OK"
else else
die "--enable-shared only supported on ELF, OS/2, and Darwin for now" die "--enable-shared only supported on ELF for now"
fi fi
;; fi
esac
fi fi
if [ -z "$CC" ] || enabled external_build; then if [ -z "$CC" ] || enabled external_build; then
echo "Bypassing toolchain for environment detection." echo "Bypassing toolchain for environment detection."
@ -558,12 +600,16 @@ process_detect() {
# Specialize windows and POSIX environments. # Specialize windows and POSIX environments.
case $toolchain in case $toolchain in
*-win*-*) *-win*-*)
# Don't check for any headers in Windows builds. case $header-$toolchain in
false stdint*-gcc) true;;
;; *) false;;
esac && enable_feature $var
;;
*) *)
case $header in case $header in
stdint.h) true;;
pthread.h) true;; pthread.h) true;;
sys/mman.h) true;;
unistd.h) true;; unistd.h) true;;
*) false;; *) false;;
esac && enable_feature $var esac && enable_feature $var
@ -579,7 +625,9 @@ process_detect() {
int main(void) {return 0;} int main(void) {return 0;}
EOF EOF
# check system headers # check system headers
check_header stdint.h
check_header pthread.h check_header pthread.h
check_header sys/mman.h
check_header unistd.h # for sysconf(3) and friends. check_header unistd.h # for sysconf(3) and friends.
check_header vpx/vpx_integer.h -I${source_path} && enable_feature vpx_ports check_header vpx/vpx_integer.h -I${source_path} && enable_feature vpx_ports
@ -588,37 +636,53 @@ EOF
process_toolchain() { process_toolchain() {
process_common_toolchain process_common_toolchain
# Handle universal binaries for this architecture
case $toolchain in
universal-darwin*)
darwin_ver=${tgt_os##darwin}
# Snow Leopard (10.6/darwin10) dropped support for PPC
# Include PPC support for all prior versions
if [ $darwin_ver -lt 10 ]; then
fat_bin_archs="$fat_bin_archs ppc32-${tgt_os}-gcc"
fi
# Tiger (10.4/darwin8) brought support for x86
if [ $darwin_ver -ge 8 ]; then
fat_bin_archs="$fat_bin_archs x86-${tgt_os}-${tgt_cc}"
fi
# Leopard (10.5/darwin9) brought 64 bit support
if [ $darwin_ver -ge 9 ]; then
fat_bin_archs="$fat_bin_archs x86_64-${tgt_os}-${tgt_cc}"
fi
;;
esac
# Enable some useful compiler flags # Enable some useful compiler flags
if enabled gcc; then if enabled gcc; then
enabled werror && check_add_cflags -Werror enabled werror && check_add_cflags -Werror
check_add_cflags -Wall check_add_cflags -Wall
check_add_cflags -Wdeclaration-after-statement check_add_cflags -Wdeclaration-after-statement
check_add_cflags -Wdisabled-optimization check_add_cflags -Wdisabled-optimization
check_add_cflags -Wfloat-conversion
check_add_cflags -Wparentheses-equality
check_add_cflags -Wpointer-arith check_add_cflags -Wpointer-arith
check_add_cflags -Wtype-limits check_add_cflags -Wtype-limits
check_add_cflags -Wcast-qual check_add_cflags -Wcast-qual
check_add_cflags -Wvla check_add_cflags -Wvla
check_add_cflags -Wimplicit-function-declaration check_add_cflags -Wimplicit-function-declaration
check_add_cflags -Wuninitialized check_add_cflags -Wuninitialized
check_add_cflags -Wunused check_add_cflags -Wunused-variable
# -Wextra has some tricky cases. Rather than fix them all now, get the case ${CC} in
# flag for as many files as possible and fix the remaining issues *clang*)
# piecemeal. # libvpx and/or clang have issues with aliasing:
# https://bugs.chromium.org/p/webm/issues/detail?id=1069 # https://code.google.com/p/webm/issues/detail?id=603
check_add_cflags -Wextra # work around them until they are fixed
# check_add_cflags also adds to cxxflags. gtest does not do well with check_add_cflags -fno-strict-aliasing
# these flags so add them explicitly to CFLAGS only. ;;
check_cflags -Wundef && add_cflags_only -Wundef *) check_add_cflags -Wunused-but-set-variable ;;
check_cflags -Wframe-larger-than=52000 && \ esac
add_cflags_only -Wframe-larger-than=52000 enabled extra_warnings || check_add_cflags -Wno-unused-function
if enabled mips || [ -z "${INLINE}" ]; then
enabled extra_warnings || check_add_cflags -Wno-unused-function
fi
# Avoid this warning for third_party C++ sources. Some reorganization
# would be needed to apply this only to test/*.cc.
check_cflags -Wshorten-64-to-32 && add_cflags_only -Wshorten-64-to-32
fi fi
if enabled icc; then if enabled icc; then
@ -666,16 +730,24 @@ process_toolchain() {
vs*) enable_feature msvs vs*) enable_feature msvs
enable_feature solution enable_feature solution
vs_version=${tgt_cc##vs} vs_version=${tgt_cc##vs}
VCPROJ_SFX=vcxproj case $vs_version in
gen_vcproj_cmd=${source_path}/build/make/gen_msvs_vcxproj.sh [789])
enabled werror && gen_vcproj_cmd="${gen_vcproj_cmd} --enable-werror" VCPROJ_SFX=vcproj
gen_vcproj_cmd=${source_path}/build/make/gen_msvs_proj.sh
;;
10|11|12)
VCPROJ_SFX=vcxproj
gen_vcproj_cmd=${source_path}/build/make/gen_msvs_vcxproj.sh
enabled werror && gen_vcproj_cmd="${gen_vcproj_cmd} --enable-werror"
;;
esac
all_targets="${all_targets} solution" all_targets="${all_targets} solution"
INLINE="__inline" INLINE="__forceinline"
;; ;;
esac esac
# Other toolchain specific defaults # Other toolchain specific defaults
case $toolchain in x86*) soft_enable postproc;; esac case $toolchain in x86*|ppc*|universal*) soft_enable postproc;; esac
if enabled postproc_visualizer; then if enabled postproc_visualizer; then
enabled postproc || die "postproc_visualizer requires postproc to be enabled" enabled postproc || die "postproc_visualizer requires postproc to be enabled"
@ -729,16 +801,6 @@ EOF
esac esac
# libwebm needs to be linked with C++ standard library # libwebm needs to be linked with C++ standard library
enabled webm_io && LD=${CXX} enabled webm_io && LD=${CXX}
# append any user defined extra cflags
if [ -n "${extra_cflags}" ] ; then
check_add_cflags ${extra_cflags} || \
die "Requested extra CFLAGS '${extra_cflags}' not supported by compiler"
fi
if [ -n "${extra_cxxflags}" ]; then
check_add_cxxflags ${extra_cxxflags} || \
die "Requested extra CXXFLAGS '${extra_cxxflags}' not supported by compiler"
fi
} }
@ -749,7 +811,6 @@ CONFIGURE_ARGS="$@"
process "$@" process "$@"
print_webm_license ${BUILD_PFX}vpx_config.c "/*" " */" print_webm_license ${BUILD_PFX}vpx_config.c "/*" " */"
cat <<EOF >> ${BUILD_PFX}vpx_config.c cat <<EOF >> ${BUILD_PFX}vpx_config.c
#include "vpx/vpx_codec.h"
static const char* const cfg = "$CONFIGURE_ARGS"; static const char* const cfg = "$CONFIGURE_ARGS";
const char *vpx_codec_build_config(void) {return cfg;} const char *vpx_codec_build_config(void) {return cfg;}
EOF EOF

View File

@ -22,18 +22,17 @@ LIBYUV_SRCS += third_party/libyuv/include/libyuv/basic_types.h \
third_party/libyuv/source/planar_functions.cc \ third_party/libyuv/source/planar_functions.cc \
third_party/libyuv/source/row_any.cc \ third_party/libyuv/source/row_any.cc \
third_party/libyuv/source/row_common.cc \ third_party/libyuv/source/row_common.cc \
third_party/libyuv/source/row_gcc.cc \
third_party/libyuv/source/row_mips.cc \ third_party/libyuv/source/row_mips.cc \
third_party/libyuv/source/row_neon.cc \ third_party/libyuv/source/row_neon.cc \
third_party/libyuv/source/row_neon64.cc \ third_party/libyuv/source/row_neon64.cc \
third_party/libyuv/source/row_posix.cc \
third_party/libyuv/source/row_win.cc \ third_party/libyuv/source/row_win.cc \
third_party/libyuv/source/scale.cc \ third_party/libyuv/source/scale.cc \
third_party/libyuv/source/scale_any.cc \
third_party/libyuv/source/scale_common.cc \ third_party/libyuv/source/scale_common.cc \
third_party/libyuv/source/scale_gcc.cc \
third_party/libyuv/source/scale_mips.cc \ third_party/libyuv/source/scale_mips.cc \
third_party/libyuv/source/scale_neon.cc \ third_party/libyuv/source/scale_neon.cc \
third_party/libyuv/source/scale_neon64.cc \ third_party/libyuv/source/scale_neon64.cc \
third_party/libyuv/source/scale_posix.cc \
third_party/libyuv/source/scale_win.cc \ third_party/libyuv/source/scale_win.cc \
LIBWEBM_COMMON_SRCS += third_party/libwebm/common/hdr_util.cc \ LIBWEBM_COMMON_SRCS += third_party/libwebm/common/hdr_util.cc \
@ -57,17 +56,16 @@ LIBWEBM_PARSER_SRCS = third_party/libwebm/mkvparser/mkvparser.cc \
# Add compile flags and include path for libwebm sources. # Add compile flags and include path for libwebm sources.
ifeq ($(CONFIG_WEBM_IO),yes) ifeq ($(CONFIG_WEBM_IO),yes)
CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/libwebm
INC_PATH-yes += $(SRC_PATH_BARE)/third_party/libwebm INC_PATH-yes += $(SRC_PATH_BARE)/third_party/libwebm
endif endif
# List of examples to build. UTILS are tools meant for distribution # List of examples to build. UTILS are tools meant for distribution
# while EXAMPLES demonstrate specific portions of the API. # while EXAMPLES demonstrate specific portions of the API.
UTILS-$(CONFIG_DECODERS) += vpxdec.c UTILS-$(CONFIG_DECODERS) += vpxdec.c
vpxdec.SRCS += md5_utils.c md5_utils.h vpxdec.SRCS += md5_utils.c md5_utils.h
vpxdec.SRCS += vpx_ports/mem_ops.h vpxdec.SRCS += vpx_ports/mem_ops.h
vpxdec.SRCS += vpx_ports/mem_ops_aligned.h vpxdec.SRCS += vpx_ports/mem_ops_aligned.h
vpxdec.SRCS += vpx_ports/msvc.h
vpxdec.SRCS += vpx_ports/vpx_timer.h vpxdec.SRCS += vpx_ports/vpx_timer.h
vpxdec.SRCS += vpx/vpx_integer.h vpxdec.SRCS += vpx/vpx_integer.h
vpxdec.SRCS += args.c args.h vpxdec.SRCS += args.c args.h
@ -76,7 +74,6 @@ vpxdec.SRCS += tools_common.c tools_common.h
vpxdec.SRCS += y4menc.c y4menc.h vpxdec.SRCS += y4menc.c y4menc.h
ifeq ($(CONFIG_LIBYUV),yes) ifeq ($(CONFIG_LIBYUV),yes)
vpxdec.SRCS += $(LIBYUV_SRCS) vpxdec.SRCS += $(LIBYUV_SRCS)
$(BUILD_PFX)third_party/libyuv/%.cc.o: CXXFLAGS += -Wno-unused-parameter
endif endif
ifeq ($(CONFIG_WEBM_IO),yes) ifeq ($(CONFIG_WEBM_IO),yes)
vpxdec.SRCS += $(LIBWEBM_COMMON_SRCS) vpxdec.SRCS += $(LIBWEBM_COMMON_SRCS)
@ -95,7 +92,6 @@ vpxenc.SRCS += tools_common.c tools_common.h
vpxenc.SRCS += warnings.c warnings.h vpxenc.SRCS += warnings.c warnings.h
vpxenc.SRCS += vpx_ports/mem_ops.h vpxenc.SRCS += vpx_ports/mem_ops.h
vpxenc.SRCS += vpx_ports/mem_ops_aligned.h vpxenc.SRCS += vpx_ports/mem_ops_aligned.h
vpxenc.SRCS += vpx_ports/msvc.h
vpxenc.SRCS += vpx_ports/vpx_timer.h vpxenc.SRCS += vpx_ports/vpx_timer.h
vpxenc.SRCS += vpxstats.c vpxstats.h vpxenc.SRCS += vpxstats.c vpxstats.h
ifeq ($(CONFIG_LIBYUV),yes) ifeq ($(CONFIG_LIBYUV),yes)
@ -110,29 +106,10 @@ endif
vpxenc.GUID = 548DEC74-7A15-4B2B-AFC3-AA102E7C25C1 vpxenc.GUID = 548DEC74-7A15-4B2B-AFC3-AA102E7C25C1
vpxenc.DESCRIPTION = Full featured encoder vpxenc.DESCRIPTION = Full featured encoder
EXAMPLES-$(CONFIG_VP9_ENCODER) += vp9_spatial_svc_encoder.c
vp9_spatial_svc_encoder.SRCS += args.c args.h
vp9_spatial_svc_encoder.SRCS += ivfenc.c ivfenc.h
vp9_spatial_svc_encoder.SRCS += tools_common.c tools_common.h
vp9_spatial_svc_encoder.SRCS += video_common.h
vp9_spatial_svc_encoder.SRCS += video_writer.h video_writer.c
vp9_spatial_svc_encoder.SRCS += vpx_ports/msvc.h
vp9_spatial_svc_encoder.SRCS += vpxstats.c vpxstats.h
vp9_spatial_svc_encoder.GUID = 4A38598D-627D-4505-9C7B-D4020C84100D
vp9_spatial_svc_encoder.DESCRIPTION = VP9 Spatial SVC Encoder
ifneq ($(CONFIG_SHARED),yes) ifneq ($(CONFIG_SHARED),yes)
EXAMPLES-$(CONFIG_VP9_ENCODER) += resize_util.c EXAMPLES-$(CONFIG_VP9_ENCODER) += resize_util.c
endif endif
EXAMPLES-$(CONFIG_ENCODERS) += vpx_temporal_svc_encoder.c
vpx_temporal_svc_encoder.SRCS += ivfenc.c ivfenc.h
vpx_temporal_svc_encoder.SRCS += tools_common.c tools_common.h
vpx_temporal_svc_encoder.SRCS += video_common.h
vpx_temporal_svc_encoder.SRCS += video_writer.h video_writer.c
vpx_temporal_svc_encoder.SRCS += vpx_ports/msvc.h
vpx_temporal_svc_encoder.GUID = B18C08F2-A439-4502-A78E-849BE3D60947
vpx_temporal_svc_encoder.DESCRIPTION = Temporal SVC Encoder
EXAMPLES-$(CONFIG_DECODERS) += simple_decoder.c EXAMPLES-$(CONFIG_DECODERS) += simple_decoder.c
simple_decoder.GUID = D3BBF1E9-2427-450D-BBFF-B2843C1D44CC simple_decoder.GUID = D3BBF1E9-2427-450D-BBFF-B2843C1D44CC
simple_decoder.SRCS += ivfdec.h ivfdec.c simple_decoder.SRCS += ivfdec.h ivfdec.c
@ -141,7 +118,6 @@ simple_decoder.SRCS += video_common.h
simple_decoder.SRCS += video_reader.h video_reader.c simple_decoder.SRCS += video_reader.h video_reader.c
simple_decoder.SRCS += vpx_ports/mem_ops.h simple_decoder.SRCS += vpx_ports/mem_ops.h
simple_decoder.SRCS += vpx_ports/mem_ops_aligned.h simple_decoder.SRCS += vpx_ports/mem_ops_aligned.h
simple_decoder.SRCS += vpx_ports/msvc.h
simple_decoder.DESCRIPTION = Simplified decoder loop simple_decoder.DESCRIPTION = Simplified decoder loop
EXAMPLES-$(CONFIG_DECODERS) += postproc.c EXAMPLES-$(CONFIG_DECODERS) += postproc.c
postproc.SRCS += ivfdec.h ivfdec.c postproc.SRCS += ivfdec.h ivfdec.c
@ -150,7 +126,6 @@ postproc.SRCS += video_common.h
postproc.SRCS += video_reader.h video_reader.c postproc.SRCS += video_reader.h video_reader.c
postproc.SRCS += vpx_ports/mem_ops.h postproc.SRCS += vpx_ports/mem_ops.h
postproc.SRCS += vpx_ports/mem_ops_aligned.h postproc.SRCS += vpx_ports/mem_ops_aligned.h
postproc.SRCS += vpx_ports/msvc.h
postproc.GUID = 65E33355-F35E-4088-884D-3FD4905881D7 postproc.GUID = 65E33355-F35E-4088-884D-3FD4905881D7
postproc.DESCRIPTION = Decoder postprocessor control postproc.DESCRIPTION = Decoder postprocessor control
EXAMPLES-$(CONFIG_DECODERS) += decode_to_md5.c EXAMPLES-$(CONFIG_DECODERS) += decode_to_md5.c
@ -161,7 +136,6 @@ decode_to_md5.SRCS += video_common.h
decode_to_md5.SRCS += video_reader.h video_reader.c decode_to_md5.SRCS += video_reader.h video_reader.c
decode_to_md5.SRCS += vpx_ports/mem_ops.h decode_to_md5.SRCS += vpx_ports/mem_ops.h
decode_to_md5.SRCS += vpx_ports/mem_ops_aligned.h decode_to_md5.SRCS += vpx_ports/mem_ops_aligned.h
decode_to_md5.SRCS += vpx_ports/msvc.h
decode_to_md5.GUID = 59120B9B-2735-4BFE-B022-146CA340FE42 decode_to_md5.GUID = 59120B9B-2735-4BFE-B022-146CA340FE42
decode_to_md5.DESCRIPTION = Frame by frame MD5 checksum decode_to_md5.DESCRIPTION = Frame by frame MD5 checksum
EXAMPLES-$(CONFIG_ENCODERS) += simple_encoder.c EXAMPLES-$(CONFIG_ENCODERS) += simple_encoder.c
@ -169,7 +143,6 @@ simple_encoder.SRCS += ivfenc.h ivfenc.c
simple_encoder.SRCS += tools_common.h tools_common.c simple_encoder.SRCS += tools_common.h tools_common.c
simple_encoder.SRCS += video_common.h simple_encoder.SRCS += video_common.h
simple_encoder.SRCS += video_writer.h video_writer.c simple_encoder.SRCS += video_writer.h video_writer.c
simple_encoder.SRCS += vpx_ports/msvc.h
simple_encoder.GUID = 4607D299-8A71-4D2C-9B1D-071899B6FBFD simple_encoder.GUID = 4607D299-8A71-4D2C-9B1D-071899B6FBFD
simple_encoder.DESCRIPTION = Simplified encoder loop simple_encoder.DESCRIPTION = Simplified encoder loop
EXAMPLES-$(CONFIG_VP9_ENCODER) += vp9_lossless_encoder.c EXAMPLES-$(CONFIG_VP9_ENCODER) += vp9_lossless_encoder.c
@ -177,7 +150,6 @@ vp9_lossless_encoder.SRCS += ivfenc.h ivfenc.c
vp9_lossless_encoder.SRCS += tools_common.h tools_common.c vp9_lossless_encoder.SRCS += tools_common.h tools_common.c
vp9_lossless_encoder.SRCS += video_common.h vp9_lossless_encoder.SRCS += video_common.h
vp9_lossless_encoder.SRCS += video_writer.h video_writer.c vp9_lossless_encoder.SRCS += video_writer.h video_writer.c
vp9_lossless_encoder.SRCS += vpx_ports/msvc.h
vp9_lossless_encoder.GUID = B63C7C88-5348-46DC-A5A6-CC151EF93366 vp9_lossless_encoder.GUID = B63C7C88-5348-46DC-A5A6-CC151EF93366
vp9_lossless_encoder.DESCRIPTION = Simplified lossless VP9 encoder vp9_lossless_encoder.DESCRIPTION = Simplified lossless VP9 encoder
EXAMPLES-$(CONFIG_ENCODERS) += twopass_encoder.c EXAMPLES-$(CONFIG_ENCODERS) += twopass_encoder.c
@ -185,7 +157,6 @@ twopass_encoder.SRCS += ivfenc.h ivfenc.c
twopass_encoder.SRCS += tools_common.h tools_common.c twopass_encoder.SRCS += tools_common.h tools_common.c
twopass_encoder.SRCS += video_common.h twopass_encoder.SRCS += video_common.h
twopass_encoder.SRCS += video_writer.h video_writer.c twopass_encoder.SRCS += video_writer.h video_writer.c
twopass_encoder.SRCS += vpx_ports/msvc.h
twopass_encoder.GUID = 73494FA6-4AF9-4763-8FBB-265C92402FD8 twopass_encoder.GUID = 73494FA6-4AF9-4763-8FBB-265C92402FD8
twopass_encoder.DESCRIPTION = Two-pass encoder loop twopass_encoder.DESCRIPTION = Two-pass encoder loop
EXAMPLES-$(CONFIG_DECODERS) += decode_with_drops.c EXAMPLES-$(CONFIG_DECODERS) += decode_with_drops.c
@ -195,7 +166,6 @@ decode_with_drops.SRCS += video_common.h
decode_with_drops.SRCS += video_reader.h video_reader.c decode_with_drops.SRCS += video_reader.h video_reader.c
decode_with_drops.SRCS += vpx_ports/mem_ops.h decode_with_drops.SRCS += vpx_ports/mem_ops.h
decode_with_drops.SRCS += vpx_ports/mem_ops_aligned.h decode_with_drops.SRCS += vpx_ports/mem_ops_aligned.h
decode_with_drops.SRCS += vpx_ports/msvc.h
decode_with_drops.GUID = CE5C53C4-8DDA-438A-86ED-0DDD3CDB8D26 decode_with_drops.GUID = CE5C53C4-8DDA-438A-86ED-0DDD3CDB8D26
decode_with_drops.DESCRIPTION = Drops frames while decoding decode_with_drops.DESCRIPTION = Drops frames while decoding
EXAMPLES-$(CONFIG_ENCODERS) += set_maps.c EXAMPLES-$(CONFIG_ENCODERS) += set_maps.c
@ -203,7 +173,6 @@ set_maps.SRCS += ivfenc.h ivfenc.c
set_maps.SRCS += tools_common.h tools_common.c set_maps.SRCS += tools_common.h tools_common.c
set_maps.SRCS += video_common.h set_maps.SRCS += video_common.h
set_maps.SRCS += video_writer.h video_writer.c set_maps.SRCS += video_writer.h video_writer.c
set_maps.SRCS += vpx_ports/msvc.h
set_maps.GUID = ECB2D24D-98B8-4015-A465-A4AF3DCC145F set_maps.GUID = ECB2D24D-98B8-4015-A465-A4AF3DCC145F
set_maps.DESCRIPTION = Set active and ROI maps set_maps.DESCRIPTION = Set active and ROI maps
EXAMPLES-$(CONFIG_VP8_ENCODER) += vp8cx_set_ref.c EXAMPLES-$(CONFIG_VP8_ENCODER) += vp8cx_set_ref.c
@ -211,21 +180,15 @@ vp8cx_set_ref.SRCS += ivfenc.h ivfenc.c
vp8cx_set_ref.SRCS += tools_common.h tools_common.c vp8cx_set_ref.SRCS += tools_common.h tools_common.c
vp8cx_set_ref.SRCS += video_common.h vp8cx_set_ref.SRCS += video_common.h
vp8cx_set_ref.SRCS += video_writer.h video_writer.c vp8cx_set_ref.SRCS += video_writer.h video_writer.c
vp8cx_set_ref.SRCS += vpx_ports/msvc.h
vp8cx_set_ref.GUID = C5E31F7F-96F6-48BD-BD3E-10EBF6E8057A vp8cx_set_ref.GUID = C5E31F7F-96F6-48BD-BD3E-10EBF6E8057A
vp8cx_set_ref.DESCRIPTION = VP8 set encoder reference frame vp8cx_set_ref.DESCRIPTION = VP8 set encoder reference frame
EXAMPLES-$(CONFIG_VP9_ENCODER) += vp9cx_set_ref.c
ifeq ($(CONFIG_VP9_ENCODER),yes)
ifeq ($(CONFIG_DECODERS),yes)
EXAMPLES-yes += vp9cx_set_ref.c
vp9cx_set_ref.SRCS += ivfenc.h ivfenc.c vp9cx_set_ref.SRCS += ivfenc.h ivfenc.c
vp9cx_set_ref.SRCS += tools_common.h tools_common.c vp9cx_set_ref.SRCS += tools_common.h tools_common.c
vp9cx_set_ref.SRCS += video_common.h vp9cx_set_ref.SRCS += video_common.h
vp9cx_set_ref.SRCS += video_writer.h video_writer.c vp9cx_set_ref.SRCS += video_writer.h video_writer.c
vp9cx_set_ref.GUID = 65D7F14A-2EE6-4293-B958-AB5107A03B55 vp9cx_set_ref.GUID = 65D7F14A-2EE6-4293-B958-AB5107A03B55
vp9cx_set_ref.DESCRIPTION = VP9 set encoder reference frame vp9cx_set_ref.DESCRIPTION = VP9 set encoder reference frame
endif
endif
ifeq ($(CONFIG_MULTI_RES_ENCODING),yes) ifeq ($(CONFIG_MULTI_RES_ENCODING),yes)
ifeq ($(CONFIG_LIBYUV),yes) ifeq ($(CONFIG_LIBYUV),yes)
@ -233,7 +196,6 @@ EXAMPLES-$(CONFIG_VP8_ENCODER) += vp8_multi_resolution_encoder.c
vp8_multi_resolution_encoder.SRCS += ivfenc.h ivfenc.c vp8_multi_resolution_encoder.SRCS += ivfenc.h ivfenc.c
vp8_multi_resolution_encoder.SRCS += tools_common.h tools_common.c vp8_multi_resolution_encoder.SRCS += tools_common.h tools_common.c
vp8_multi_resolution_encoder.SRCS += video_writer.h video_writer.c vp8_multi_resolution_encoder.SRCS += video_writer.h video_writer.c
vp8_multi_resolution_encoder.SRCS += vpx_ports/msvc.h
vp8_multi_resolution_encoder.SRCS += $(LIBYUV_SRCS) vp8_multi_resolution_encoder.SRCS += $(LIBYUV_SRCS)
vp8_multi_resolution_encoder.GUID = 04f8738e-63c8-423b-90fa-7c2703a374de vp8_multi_resolution_encoder.GUID = 04f8738e-63c8-423b-90fa-7c2703a374de
vp8_multi_resolution_encoder.DESCRIPTION = VP8 Multiple-resolution Encoding vp8_multi_resolution_encoder.DESCRIPTION = VP8 Multiple-resolution Encoding
@ -294,6 +256,14 @@ CODEC_EXTRA_LIBS=$(sort $(call enabled,CODEC_EXTRA_LIBS))
$(foreach ex,$(ALL_EXAMPLES),$(eval $(notdir $(ex:.c=)).SRCS += $(ex) examples.mk)) $(foreach ex,$(ALL_EXAMPLES),$(eval $(notdir $(ex:.c=)).SRCS += $(ex) examples.mk))
# If this is a universal (fat) binary, then all the subarchitectures have
# already been built and our job is to stitch them together. The
# BUILD_OBJS variable indicates whether we should be building
# (compiling, linking) the library. The LIPO_OBJS variable indicates
# that we're stitching.
$(eval $(if $(filter universal%,$(TOOLCHAIN)),LIPO_OBJS,BUILD_OBJS):=yes)
# Create build/install dependencies for all examples. The common case # Create build/install dependencies for all examples. The common case
# is handled here. The MSVS case is handled below. # is handled here. The MSVS case is handled below.
NOT_MSVS = $(if $(CONFIG_MSVS),,yes) NOT_MSVS = $(if $(CONFIG_MSVS),,yes)
@ -301,28 +271,24 @@ DIST-BINS-$(NOT_MSVS) += $(addprefix bin/,$(ALL_EXAMPLES:.c=$(EXE_SFX)))
INSTALL-BINS-$(NOT_MSVS) += $(addprefix bin/,$(UTILS:.c=$(EXE_SFX))) INSTALL-BINS-$(NOT_MSVS) += $(addprefix bin/,$(UTILS:.c=$(EXE_SFX)))
DIST-SRCS-yes += $(ALL_SRCS) DIST-SRCS-yes += $(ALL_SRCS)
INSTALL-SRCS-yes += $(UTIL_SRCS) INSTALL-SRCS-yes += $(UTIL_SRCS)
OBJS-$(NOT_MSVS) += $(call objs,$(ALL_SRCS)) OBJS-$(NOT_MSVS) += $(if $(BUILD_OBJS),$(call objs,$(ALL_SRCS)))
BINS-$(NOT_MSVS) += $(addprefix $(BUILD_PFX),$(ALL_EXAMPLES:.c=$(EXE_SFX))) BINS-$(NOT_MSVS) += $(addprefix $(BUILD_PFX),$(ALL_EXAMPLES:.c=$(EXE_SFX)))
# Instantiate linker template for all examples. # Instantiate linker template for all examples.
CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),vpx_g,vpx) CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),vpx_g,vpx)
ifneq ($(filter darwin%,$(TGT_OS)),) SHARED_LIB_SUF=$(if $(filter darwin%,$(TGT_OS)),.dylib,.so)
SHARED_LIB_SUF=.dylib
else
ifneq ($(filter os2%,$(TGT_OS)),)
SHARED_LIB_SUF=_dll.a
else
SHARED_LIB_SUF=.so
endif
endif
CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a) CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a)
$(foreach bin,$(BINS-yes),\ $(foreach bin,$(BINS-yes),\
$(eval $(bin):$(LIB_PATH)/lib$(CODEC_LIB)$(CODEC_LIB_SUF))\ $(if $(BUILD_OBJS),$(eval $(bin):\
$(eval $(call linker_template,$(bin),\ $(LIB_PATH)/lib$(CODEC_LIB)$(CODEC_LIB_SUF)))\
$(if $(BUILD_OBJS),$(eval $(call linker_template,$(bin),\
$(call objs,$($(notdir $(bin:$(EXE_SFX)=)).SRCS)) \ $(call objs,$($(notdir $(bin:$(EXE_SFX)=)).SRCS)) \
-l$(CODEC_LIB) $(addprefix -l,$(CODEC_EXTRA_LIBS))\ -l$(CODEC_LIB) $(addprefix -l,$(CODEC_EXTRA_LIBS))\
))) )))\
$(if $(LIPO_OBJS),$(eval $(call lipo_bin_template,$(bin))))\
)
# The following pairs define a mapping of locations in the distribution # The following pairs define a mapping of locations in the distribution
# tree to locations in the source/build trees. # tree to locations in the source/build trees.
@ -350,8 +316,8 @@ endif
# the makefiles). We may want to revisit this. # the makefiles). We may want to revisit this.
define vcproj_template define vcproj_template
$(1): $($(1:.$(VCPROJ_SFX)=).SRCS) vpx.$(VCPROJ_SFX) $(1): $($(1:.$(VCPROJ_SFX)=).SRCS) vpx.$(VCPROJ_SFX)
$(if $(quiet),@echo " [vcproj] $$@") @echo " [vcproj] $$@"
$(qexec)$$(GEN_VCPROJ)\ $$(GEN_VCPROJ)\
--exe\ --exe\
--target=$$(TOOLCHAIN)\ --target=$$(TOOLCHAIN)\
--name=$$(@:.$(VCPROJ_SFX)=)\ --name=$$(@:.$(VCPROJ_SFX)=)\
@ -374,7 +340,6 @@ $(foreach proj,$(call enabled,PROJECTS),\
# #
%.dox: %.c %.dox: %.c
@echo " [DOXY] $@" @echo " [DOXY] $@"
@mkdir -p $(dir $@)
@echo "/*!\page example_$(@F:.dox=) $(@F:.dox=)" > $@ @echo "/*!\page example_$(@F:.dox=) $(@F:.dox=)" > $@
@echo " \includelineno $(<F)" >> $@ @echo " \includelineno $(<F)" >> $@
@echo "*/" >> $@ @echo "*/" >> $@

View File

@ -36,9 +36,9 @@
#include "vpx/vp8dx.h" #include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "../md5_utils.h" #include "./md5_utils.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_reader.h" #include "./video_reader.h"
#include "./vpx_config.h" #include "./vpx_config.h"
static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) { static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
@ -65,12 +65,13 @@ static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
static void print_md5(FILE *stream, unsigned char digest[16]) { static void print_md5(FILE *stream, unsigned char digest[16]) {
int i; int i;
for (i = 0; i < 16; ++i) fprintf(stream, "%02x", digest[i]); for (i = 0; i < 16; ++i)
fprintf(stream, "%02x", digest[i]);
} }
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -85,10 +86,12 @@ int main(int argc, char **argv) {
exec_name = argv[0]; exec_name = argv[0];
if (argc != 3) die("Invalid number of arguments."); if (argc != 3)
die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]); reader = vpx_video_reader_open(argv[1]);
if (!reader) die("Failed to open %s for reading.", argv[1]); if (!reader)
die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb"))) if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]); die("Failed to open %s for writing.", argv[2]);
@ -96,7 +99,8 @@ int main(int argc, char **argv) {
info = vpx_video_reader_get_info(reader); info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
if (!decoder) die("Unknown input codec."); if (!decoder)
die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@ -107,8 +111,8 @@ int main(int argc, char **argv) {
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL; vpx_image_t *img = NULL;
size_t frame_size = 0; size_t frame_size = 0;
const unsigned char *frame = const unsigned char *frame = vpx_video_reader_get_frame(reader,
vpx_video_reader_get_frame(reader, &frame_size); &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0)) if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame"); die_codec(&codec, "Failed to decode frame");
@ -117,13 +121,14 @@ int main(int argc, char **argv) {
get_image_md5(img, digest); get_image_md5(img, digest);
print_md5(outfile, digest); print_md5(outfile, digest);
fprintf(outfile, " img-%dx%d-%04d.i420\n", img->d_w, img->d_h, fprintf(outfile, " img-%dx%d-%04d.i420\n",
++frame_cnt); img->d_w, img->d_h, ++frame_cnt);
} }
} }
printf("Processed %d frames.\n", frame_cnt); printf("Processed %d frames.\n", frame_cnt);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_reader_close(reader); vpx_video_reader_close(reader);

View File

@ -59,13 +59,13 @@
#include "vpx/vp8dx.h" #include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_reader.h" #include "./video_reader.h"
#include "./vpx_config.h" #include "./vpx_config.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <infile> <outfile> <N-M|N/M>\n", exec_name); fprintf(stderr, "Usage: %s <infile> <outfile> <N-M|N/M>\n", exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -84,16 +84,18 @@ int main(int argc, char **argv) {
exec_name = argv[0]; exec_name = argv[0];
if (argc != 4) die("Invalid number of arguments."); if (argc != 4)
die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]); reader = vpx_video_reader_open(argv[1]);
if (!reader) die("Failed to open %s for reading.", argv[1]); if (!reader)
die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb"))) if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]); die("Failed to open %s for writing.", argv[2]);
n = (int)strtol(argv[3], &nptr, 0); n = strtol(argv[3], &nptr, 0);
m = (int)strtol(nptr + 1, NULL, 0); m = strtol(nptr + 1, NULL, 0);
is_range = (*nptr == '-'); is_range = (*nptr == '-');
if (!n || !m || (*nptr != '-' && *nptr != '/')) if (!n || !m || (*nptr != '-' && *nptr != '/'))
die("Couldn't parse pattern %s.\n", argv[3]); die("Couldn't parse pattern %s.\n", argv[3]);
@ -101,7 +103,8 @@ int main(int argc, char **argv) {
info = vpx_video_reader_get_info(reader); info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
if (!decoder) die("Unknown input codec."); if (!decoder)
die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@ -113,8 +116,8 @@ int main(int argc, char **argv) {
vpx_image_t *img = NULL; vpx_image_t *img = NULL;
size_t frame_size = 0; size_t frame_size = 0;
int skip; int skip;
const unsigned char *frame = const unsigned char *frame = vpx_video_reader_get_frame(reader,
vpx_video_reader_get_frame(reader, &frame_size); &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0)) if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame."); die_codec(&codec, "Failed to decode frame.");
@ -136,7 +139,8 @@ int main(int argc, char **argv) {
} }
printf("Processed %d frames.\n", frame_cnt); printf("Processed %d frames.\n", frame_cnt);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n", printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]); info->frame_width, info->frame_height, argv[2]);

View File

@ -46,13 +46,13 @@
#include "vpx/vp8dx.h" #include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_reader.h" #include "./video_reader.h"
#include "./vpx_config.h" #include "./vpx_config.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -68,10 +68,12 @@ int main(int argc, char **argv) {
exec_name = argv[0]; exec_name = argv[0];
if (argc != 3) die("Invalid number of arguments."); if (argc != 3)
die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]); reader = vpx_video_reader_open(argv[1]);
if (!reader) die("Failed to open %s for reading.", argv[1]); if (!reader)
die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb"))) if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing", argv[2]); die("Failed to open %s for writing", argv[2]);
@ -79,7 +81,8 @@ int main(int argc, char **argv) {
info = vpx_video_reader_get_info(reader); info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
if (!decoder) die("Unknown input codec."); if (!decoder)
die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@ -88,25 +91,26 @@ int main(int argc, char **argv) {
if (res == VPX_CODEC_INCAPABLE) if (res == VPX_CODEC_INCAPABLE)
die_codec(&codec, "Postproc not supported by this decoder."); die_codec(&codec, "Postproc not supported by this decoder.");
if (res) die_codec(&codec, "Failed to initialize decoder."); if (res)
die_codec(&codec, "Failed to initialize decoder.");
while (vpx_video_reader_read_frame(reader)) { while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL; vpx_image_t *img = NULL;
size_t frame_size = 0; size_t frame_size = 0;
const unsigned char *frame = const unsigned char *frame = vpx_video_reader_get_frame(reader,
vpx_video_reader_get_frame(reader, &frame_size); &frame_size);
++frame_cnt; ++frame_cnt;
if (frame_cnt % 30 == 1) { if (frame_cnt % 30 == 1) {
vp8_postproc_cfg_t pp = { 0, 0, 0 }; vp8_postproc_cfg_t pp = {0, 0, 0};
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
die_codec(&codec, "Failed to turn off postproc."); die_codec(&codec, "Failed to turn off postproc.");
} else if (frame_cnt % 30 == 16) { } else if (frame_cnt % 30 == 16) {
vp8_postproc_cfg_t pp = { VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE, 4, vp8_postproc_cfg_t pp = {VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE,
0 }; 4, 0};
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
die_codec(&codec, "Failed to turn on postproc."); die_codec(&codec, "Failed to turn on postproc.");
}; };
@ -121,7 +125,8 @@ int main(int argc, char **argv) {
} }
printf("Processed %d frames.\n", frame_cnt); printf("Processed %d frames.\n", frame_cnt);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec"); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n", printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]); info->frame_width, info->frame_height, argv[2]);

View File

@ -15,27 +15,21 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../tools_common.h" #include "./vp9/encoder/vp9_resize.h"
#include "../vp9/encoder/vp9_resize.h"
static const char *exec_name = NULL; static void usage(char *progname) {
static void usage() {
printf("Usage:\n"); printf("Usage:\n");
printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ", printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ",
exec_name); progname);
printf("<output_yuv> [<frames>]\n"); printf("<output_yuv> [<frames>]\n");
} }
void usage_exit(void) {
usage();
exit(EXIT_FAILURE);
}
static int parse_dim(char *v, int *width, int *height) { static int parse_dim(char *v, int *width, int *height) {
char *x = strchr(v, 'x'); char *x = strchr(v, 'x');
if (x == NULL) x = strchr(v, 'X'); if (x == NULL)
if (x == NULL) return 0; x = strchr(v, 'X');
if (x == NULL)
return 0;
*width = atoi(v); *width = atoi(v);
*height = atoi(&x[1]); *height = atoi(&x[1]);
if (*width <= 0 || *height <= 0) if (*width <= 0 || *height <= 0)
@ -53,11 +47,9 @@ int main(int argc, char *argv[]) {
int f, frames; int f, frames;
int width, height, target_width, target_height; int width, height, target_width, target_height;
exec_name = argv[0];
if (argc < 5) { if (argc < 5) {
printf("Incorrect parameters:\n"); printf("Incorrect parameters:\n");
usage(); usage(argv[0]);
return 1; return 1;
} }
@ -65,25 +57,25 @@ int main(int argc, char *argv[]) {
fout = argv[4]; fout = argv[4];
if (!parse_dim(argv[2], &width, &height)) { if (!parse_dim(argv[2], &width, &height)) {
printf("Incorrect parameters: %s\n", argv[2]); printf("Incorrect parameters: %s\n", argv[2]);
usage(); usage(argv[0]);
return 1; return 1;
} }
if (!parse_dim(argv[3], &target_width, &target_height)) { if (!parse_dim(argv[3], &target_width, &target_height)) {
printf("Incorrect parameters: %s\n", argv[3]); printf("Incorrect parameters: %s\n", argv[3]);
usage(); usage(argv[0]);
return 1; return 1;
} }
fpin = fopen(fin, "rb"); fpin = fopen(fin, "rb");
if (fpin == NULL) { if (fpin == NULL) {
printf("Can't open file %s to read\n", fin); printf("Can't open file %s to read\n", fin);
usage(); usage(argv[0]);
return 1; return 1;
} }
fpout = fopen(fout, "wb"); fpout = fopen(fout, "wb");
if (fpout == NULL) { if (fpout == NULL) {
printf("Can't open file %s to write\n", fout); printf("Can't open file %s to write\n", fout);
usage(); usage(argv[0]);
return 1; return 1;
} }
if (argc >= 6) if (argc >= 6)
@ -91,25 +83,30 @@ int main(int argc, char *argv[]) {
else else
frames = INT_MAX; frames = INT_MAX;
printf("Input size: %dx%d\n", width, height); printf("Input size: %dx%d\n",
printf("Target size: %dx%d, Frames: ", target_width, target_height); width, height);
printf("Target size: %dx%d, Frames: ",
target_width, target_height);
if (frames == INT_MAX) if (frames == INT_MAX)
printf("All\n"); printf("All\n");
else else
printf("%d\n", frames); printf("%d\n", frames);
inbuf = (uint8_t *)malloc(width * height * 3 / 2); inbuf = (uint8_t*)malloc(width * height * 3 / 2);
outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2); outbuf = (uint8_t*)malloc(target_width * target_height * 3 / 2);
inbuf_u = inbuf + width * height; inbuf_u = inbuf + width * height;
inbuf_v = inbuf_u + width * height / 4; inbuf_v = inbuf_u + width * height / 4;
outbuf_u = outbuf + target_width * target_height; outbuf_u = outbuf + target_width * target_height;
outbuf_v = outbuf_u + target_width * target_height / 4; outbuf_v = outbuf_u + target_width * target_height / 4;
f = 0; f = 0;
while (f < frames) { while (f < frames) {
if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break; if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1)
vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height, break;
width, outbuf, target_width, outbuf_u, outbuf_v, vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2,
target_width / 2, target_height, target_width); height, width,
outbuf, target_width, outbuf_u, outbuf_v,
target_width / 2,
target_height, target_width);
fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout); fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
f++; f++;
} }

View File

@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
// VP8 Set Active and ROI Maps // VP8 Set Active and ROI Maps
// =========================== // ===========================
// //
@ -49,12 +50,12 @@
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_writer.h" #include "./video_writer.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n",
exec_name); exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -85,7 +86,8 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
roi.static_threshold[3] = 0; roi.static_threshold[3] = 0;
roi.roi_map = (uint8_t *)malloc(roi.rows * roi.cols); roi.roi_map = (uint8_t *)malloc(roi.rows * roi.cols);
for (i = 0; i < roi.rows * roi.cols; ++i) roi.roi_map[i] = i % 4; for (i = 0; i < roi.rows * roi.cols; ++i)
roi.roi_map[i] = i % 4;
if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi)) if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi))
die_codec(codec, "Failed to set ROI map"); die_codec(codec, "Failed to set ROI map");
@ -96,13 +98,14 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
static void set_active_map(const vpx_codec_enc_cfg_t *cfg, static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
vpx_codec_ctx_t *codec) { vpx_codec_ctx_t *codec) {
unsigned int i; unsigned int i;
vpx_active_map_t map = { 0, 0, 0 }; vpx_active_map_t map = {0, 0, 0};
map.rows = (cfg->g_h + 15) / 16; map.rows = (cfg->g_h + 15) / 16;
map.cols = (cfg->g_w + 15) / 16; map.cols = (cfg->g_w + 15) / 16;
map.active_map = (uint8_t *)malloc(map.rows * map.cols); map.active_map = (uint8_t *)malloc(map.rows * map.cols);
for (i = 0; i < map.rows * map.cols; ++i) map.active_map[i] = i % 2; for (i = 0; i < map.rows * map.cols; ++i)
map.active_map[i] = i % 2;
if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map)) if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map))
die_codec(codec, "Failed to set active map"); die_codec(codec, "Failed to set active map");
@ -112,7 +115,7 @@ static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
static void unset_active_map(const vpx_codec_enc_cfg_t *cfg, static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
vpx_codec_ctx_t *codec) { vpx_codec_ctx_t *codec) {
vpx_active_map_t map = { 0, 0, 0 }; vpx_active_map_t map = {0, 0, 0};
map.rows = (cfg->g_h + 15) / 16; map.rows = (cfg->g_h + 15) / 16;
map.cols = (cfg->g_w + 15) / 16; map.cols = (cfg->g_w + 15) / 16;
@ -122,21 +125,25 @@ static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
die_codec(codec, "Failed to set active map"); die_codec(codec, "Failed to set active map");
} }
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *codec,
int frame_index, VpxVideoWriter *writer) { vpx_image_t *img,
int frame_index,
VpxVideoWriter *writer) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
vpx_codec_encode(codec, img, frame_index, 1, 0, VPX_DL_GOOD_QUALITY); VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame"); if (res != VPX_CODEC_OK)
die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) { pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame"); die_codec(codec, "Failed to write compressed frame");
@ -160,11 +167,12 @@ int main(int argc, char **argv) {
VpxVideoInfo info; VpxVideoInfo info;
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
const int fps = 2; // TODO(dkovalev) add command line argument const int fps = 2; // TODO(dkovalev) add command line argument
const double bits_per_pixel_per_frame = 0.067; const double bits_per_pixel_per_frame = 0.067;
exec_name = argv[0]; exec_name = argv[0];
if (argc != 6) die("Invalid number of arguments"); if (argc != 6)
die("Invalid number of arguments");
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
@ -174,36 +182,40 @@ int main(int argc, char **argv) {
} }
assert(encoder != NULL); assert(encoder != NULL);
info.codec_fourcc = encoder->fourcc; info.codec_fourcc = encoder->fourcc;
info.frame_width = (int)strtol(argv[2], NULL, 0); info.frame_width = strtol(argv[2], NULL, 0);
info.frame_height = (int)strtol(argv[3], NULL, 0); info.frame_height = strtol(argv[3], NULL, 0);
info.time_base.numerator = 1; info.time_base.numerator = 1;
info.time_base.denominator = fps; info.time_base.denominator = fps;
if (info.frame_width <= 0 || info.frame_height <= 0 || if (info.frame_width <= 0 ||
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) { info.frame_height <= 0 ||
(info.frame_width % 2) != 0 ||
(info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
} }
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
info.frame_height, 1)) { info.frame_height, 1)) {
die("Failed to allocate image."); die("Failed to allocate image.");
} }
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&codec, "Failed to get default codec config."); if (res)
die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width; cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height; cfg.g_h = info.frame_height;
cfg.g_timebase.num = info.time_base.numerator; cfg.g_timebase.num = info.time_base.numerator;
cfg.g_timebase.den = info.time_base.denominator; cfg.g_timebase.den = info.time_base.denominator;
cfg.rc_target_bitrate = cfg.rc_target_bitrate = (unsigned int)(bits_per_pixel_per_frame * cfg.g_w *
(unsigned int)(bits_per_pixel_per_frame * cfg.g_w * cfg.g_h * fps / 1000); cfg.g_h * fps / 1000);
cfg.g_lag_in_frames = 0; cfg.g_lag_in_frames = 0;
writer = vpx_video_writer_open(argv[5], kContainerIVF, &info); writer = vpx_video_writer_open(argv[5], kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", argv[5]); if (!writer)
die("Failed to open %s for writing.", argv[5]);
if (!(infile = fopen(argv[4], "rb"))) if (!(infile = fopen(argv[4], "rb")))
die("Failed to open %s for reading.", argv[4]); die("Failed to open %s for reading.", argv[4]);
@ -227,15 +239,15 @@ int main(int argc, char **argv) {
} }
// Flush encoder. // Flush encoder.
while (encode_frame(&codec, NULL, -1, writer)) { while (encode_frame(&codec, NULL, -1, writer)) {}
}
printf("\n"); printf("\n");
fclose(infile); fclose(infile);
printf("Processed %d frames.\n", frame_count); printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw); vpx_img_free(&raw);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer); vpx_video_writer_close(writer);

View File

@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
// Simple Decoder // Simple Decoder
// ============== // ==============
// //
@ -81,13 +82,13 @@
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_reader.h" #include "./video_reader.h"
#include "./vpx_config.h" #include "./vpx_config.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -102,10 +103,12 @@ int main(int argc, char **argv) {
exec_name = argv[0]; exec_name = argv[0];
if (argc != 3) die("Invalid number of arguments."); if (argc != 3)
die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]); reader = vpx_video_reader_open(argv[1]);
if (!reader) die("Failed to open %s for reading.", argv[1]); if (!reader)
die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb"))) if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]); die("Failed to open %s for writing.", argv[2]);
@ -113,7 +116,8 @@ int main(int argc, char **argv) {
info = vpx_video_reader_get_info(reader); info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
if (!decoder) die("Unknown input codec."); if (!decoder)
die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@ -124,8 +128,8 @@ int main(int argc, char **argv) {
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL; vpx_image_t *img = NULL;
size_t frame_size = 0; size_t frame_size = 0;
const unsigned char *frame = const unsigned char *frame = vpx_video_reader_get_frame(reader,
vpx_video_reader_get_frame(reader, &frame_size); &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0)) if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame."); die_codec(&codec, "Failed to decode frame.");
@ -136,7 +140,8 @@ int main(int argc, char **argv) {
} }
printf("Processed %d frames.\n", frame_cnt); printf("Processed %d frames.\n", frame_cnt);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec"); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n", printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]); info->frame_width, info->frame_height, argv[2]);

View File

@ -101,35 +101,40 @@
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_writer.h" #include "./video_writer.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, fprintf(stderr,
"Usage: %s <codec> <width> <height> <infile> <outfile> " "Usage: %s <codec> <width> <height> <infile> <outfile> "
"<keyframe-interval> <error-resilient> <frames to encode>\n" "<keyframe-interval> [<error-resilient>]\nSee comments in "
"See comments in simple_encoder.c for more information.\n", "simple_encoder.c for more information.\n",
exec_name); exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *codec,
int frame_index, int flags, VpxVideoWriter *writer) { vpx_image_t *img,
int frame_index,
int flags,
VpxVideoWriter *writer) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY); flags, VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame"); if (res != VPX_CODEC_OK)
die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) { pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame"); die_codec(codec, "Failed to write compressed frame");
@ -142,7 +147,6 @@ static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
return got_pkts; return got_pkts;
} }
// TODO(tomfinegan): Improve command line parsing and add args for bitrate/fps.
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *infile = NULL; FILE *infile = NULL;
vpx_codec_ctx_t codec; vpx_codec_ctx_t codec;
@ -150,14 +154,15 @@ int main(int argc, char **argv) {
int frame_count = 0; int frame_count = 0;
vpx_image_t raw; vpx_image_t raw;
vpx_codec_err_t res; vpx_codec_err_t res;
VpxVideoInfo info = { 0, 0, 0, { 0, 0 } }; VpxVideoInfo info = {0};
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
const int fps = 30; const int fps = 30; // TODO(dkovalev) add command line argument
const int bitrate = 200; const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
int keyframe_interval = 0; int keyframe_interval = 0;
int max_frames = 0;
int frames_encoded = 0; // TODO(dkovalev): Add some simple command line parsing code to make the
// command line more flexible.
const char *codec_arg = NULL; const char *codec_arg = NULL;
const char *width_arg = NULL; const char *width_arg = NULL;
const char *height_arg = NULL; const char *height_arg = NULL;
@ -167,7 +172,8 @@ int main(int argc, char **argv) {
exec_name = argv[0]; exec_name = argv[0];
if (argc != 9) die("Invalid number of arguments"); if (argc < 7)
die("Invalid number of arguments");
codec_arg = argv[1]; codec_arg = argv[1];
width_arg = argv[2]; width_arg = argv[2];
@ -175,44 +181,49 @@ int main(int argc, char **argv) {
infile_arg = argv[4]; infile_arg = argv[4];
outfile_arg = argv[5]; outfile_arg = argv[5];
keyframe_interval_arg = argv[6]; keyframe_interval_arg = argv[6];
max_frames = (int)strtol(argv[8], NULL, 0);
encoder = get_vpx_encoder_by_name(codec_arg); encoder = get_vpx_encoder_by_name(codec_arg);
if (!encoder) die("Unsupported codec."); if (!encoder)
die("Unsupported codec.");
info.codec_fourcc = encoder->fourcc; info.codec_fourcc = encoder->fourcc;
info.frame_width = (int)strtol(width_arg, NULL, 0); info.frame_width = strtol(width_arg, NULL, 0);
info.frame_height = (int)strtol(height_arg, NULL, 0); info.frame_height = strtol(height_arg, NULL, 0);
info.time_base.numerator = 1; info.time_base.numerator = 1;
info.time_base.denominator = fps; info.time_base.denominator = fps;
if (info.frame_width <= 0 || info.frame_height <= 0 || if (info.frame_width <= 0 ||
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) { info.frame_height <= 0 ||
(info.frame_width % 2) != 0 ||
(info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
} }
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
info.frame_height, 1)) { info.frame_height, 1)) {
die("Failed to allocate image."); die("Failed to allocate image.");
} }
keyframe_interval = (int)strtol(keyframe_interval_arg, NULL, 0); keyframe_interval = strtol(keyframe_interval_arg, NULL, 0);
if (keyframe_interval < 0) die("Invalid keyframe interval value."); if (keyframe_interval < 0)
die("Invalid keyframe interval value.");
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&codec, "Failed to get default codec config."); if (res)
die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width; cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height; cfg.g_h = info.frame_height;
cfg.g_timebase.num = info.time_base.numerator; cfg.g_timebase.num = info.time_base.numerator;
cfg.g_timebase.den = info.time_base.denominator; cfg.g_timebase.den = info.time_base.denominator;
cfg.rc_target_bitrate = bitrate; cfg.rc_target_bitrate = bitrate;
cfg.g_error_resilient = (vpx_codec_er_flags_t)strtoul(argv[7], NULL, 0); cfg.g_error_resilient = argc > 7 ? strtol(argv[7], NULL, 0) : 0;
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info); writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", outfile_arg); if (!writer)
die("Failed to open %s for writing.", outfile_arg);
if (!(infile = fopen(infile_arg, "rb"))) if (!(infile = fopen(infile_arg, "rb")))
die("Failed to open %s for reading.", infile_arg); die("Failed to open %s for reading.", infile_arg);
@ -226,20 +237,18 @@ int main(int argc, char **argv) {
if (keyframe_interval > 0 && frame_count % keyframe_interval == 0) if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
flags |= VPX_EFLAG_FORCE_KF; flags |= VPX_EFLAG_FORCE_KF;
encode_frame(&codec, &raw, frame_count++, flags, writer); encode_frame(&codec, &raw, frame_count++, flags, writer);
frames_encoded++;
if (max_frames > 0 && frames_encoded >= max_frames) break;
} }
// Flush encoder. // Flush encoder.
while (encode_frame(&codec, NULL, -1, 0, writer)) { while (encode_frame(&codec, NULL, -1, 0, writer)) {};
}
printf("\n"); printf("\n");
fclose(infile); fclose(infile);
printf("Processed %d frames.\n", frame_count); printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw); vpx_img_free(&raw);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer); vpx_video_writer_close(writer);

View File

@ -53,29 +53,31 @@
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_writer.h" #include "./video_writer.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n",
"Usage: %s <codec> <width> <height> <infile> <outfile> "
"<frame limit>\n",
exec_name); exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static int get_frame_stats(vpx_codec_ctx_t *ctx, const vpx_image_t *img, static int get_frame_stats(vpx_codec_ctx_t *ctx,
vpx_codec_pts_t pts, unsigned int duration, const vpx_image_t *img,
vpx_enc_frame_flags_t flags, unsigned int deadline, vpx_codec_pts_t pts,
unsigned int duration,
vpx_enc_frame_flags_t flags,
unsigned int deadline,
vpx_fixed_buf_t *stats) { vpx_fixed_buf_t *stats) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
vpx_codec_encode(ctx, img, pts, duration, flags, deadline); deadline);
if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to get frame stats."); if (res != VPX_CODEC_OK)
die_codec(ctx, "Failed to get frame stats.");
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
@ -92,16 +94,20 @@ static int get_frame_stats(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
return got_pkts; return got_pkts;
} }
static int encode_frame(vpx_codec_ctx_t *ctx, const vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *ctx,
vpx_codec_pts_t pts, unsigned int duration, const vpx_image_t *img,
vpx_enc_frame_flags_t flags, unsigned int deadline, vpx_codec_pts_t pts,
unsigned int duration,
vpx_enc_frame_flags_t flags,
unsigned int deadline,
VpxVideoWriter *writer) { VpxVideoWriter *writer) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
vpx_codec_encode(ctx, img, pts, duration, flags, deadline); deadline);
if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to encode frame."); if (res != VPX_CODEC_OK)
die_codec(ctx, "Failed to encode frame.");
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
@ -109,8 +115,8 @@ static int encode_frame(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) pkt->data.frame.pts))
die_codec(ctx, "Failed to write compressed frame."); die_codec(ctx, "Failed to write compressed frame.");
printf(keyframe ? "K" : "."); printf(keyframe ? "K" : ".");
fflush(stdout); fflush(stdout);
@ -120,12 +126,13 @@ static int encode_frame(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
return got_pkts; return got_pkts;
} }
static vpx_fixed_buf_t pass0(vpx_image_t *raw, FILE *infile, static vpx_fixed_buf_t pass0(vpx_image_t *raw,
FILE *infile,
const VpxInterface *encoder, const VpxInterface *encoder,
const vpx_codec_enc_cfg_t *cfg, int max_frames) { const vpx_codec_enc_cfg_t *cfg) {
vpx_codec_ctx_t codec; vpx_codec_ctx_t codec;
int frame_count = 0; int frame_count = 0;
vpx_fixed_buf_t stats = { NULL, 0 }; vpx_fixed_buf_t stats = {NULL, 0};
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
die_codec(&codec, "Failed to initialize encoder"); die_codec(&codec, "Failed to initialize encoder");
@ -135,33 +142,37 @@ static vpx_fixed_buf_t pass0(vpx_image_t *raw, FILE *infile,
++frame_count; ++frame_count;
get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
&stats); &stats);
if (max_frames > 0 && frame_count >= max_frames) break;
} }
// Flush encoder. // Flush encoder.
while (get_frame_stats(&codec, NULL, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, while (get_frame_stats(&codec, NULL, frame_count, 1, 0,
&stats)) { VPX_DL_GOOD_QUALITY, &stats)) {}
}
printf("Pass 0 complete. Processed %d frames.\n", frame_count); printf("Pass 0 complete. Processed %d frames.\n", frame_count);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
return stats; return stats;
} }
static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name, static void pass1(vpx_image_t *raw,
const VpxInterface *encoder, const vpx_codec_enc_cfg_t *cfg, FILE *infile,
int max_frames) { const char *outfile_name,
VpxVideoInfo info = { encoder->fourcc, const VpxInterface *encoder,
cfg->g_w, const vpx_codec_enc_cfg_t *cfg) {
cfg->g_h, VpxVideoInfo info = {
{ cfg->g_timebase.num, cfg->g_timebase.den } }; encoder->fourcc,
cfg->g_w,
cfg->g_h,
{cfg->g_timebase.num, cfg->g_timebase.den}
};
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
vpx_codec_ctx_t codec; vpx_codec_ctx_t codec;
int frame_count = 0; int frame_count = 0;
writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info); writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing", outfile_name); if (!writer)
die("Failed to open %s for writing", outfile_name);
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
die_codec(&codec, "Failed to initialize encoder"); die_codec(&codec, "Failed to initialize encoder");
@ -170,17 +181,15 @@ static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name,
while (vpx_img_read(raw, infile)) { while (vpx_img_read(raw, infile)) {
++frame_count; ++frame_count;
encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer); encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer);
if (max_frames > 0 && frame_count >= max_frames) break;
} }
// Flush encoder. // Flush encoder.
while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) { while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {}
}
printf("\n"); printf("\n");
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer); vpx_video_writer_close(writer);
@ -197,27 +206,26 @@ int main(int argc, char **argv) {
vpx_fixed_buf_t stats; vpx_fixed_buf_t stats;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
const int fps = 30; // TODO(dkovalev) add command line argument const int fps = 30; // TODO(dkovalev) add command line argument
const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
const char *const codec_arg = argv[1]; const char *const codec_arg = argv[1];
const char *const width_arg = argv[2]; const char *const width_arg = argv[2];
const char *const height_arg = argv[3]; const char *const height_arg = argv[3];
const char *const infile_arg = argv[4]; const char *const infile_arg = argv[4];
const char *const outfile_arg = argv[5]; const char *const outfile_arg = argv[5];
int max_frames = 0;
exec_name = argv[0]; exec_name = argv[0];
if (argc != 7) die("Invalid number of arguments."); if (argc != 6)
die("Invalid number of arguments.");
max_frames = (int)strtol(argv[6], NULL, 0);
encoder = get_vpx_encoder_by_name(codec_arg); encoder = get_vpx_encoder_by_name(codec_arg);
if (!encoder) die("Unsupported codec."); if (!encoder)
die("Unsupported codec.");
w = (int)strtol(width_arg, NULL, 0); w = strtol(width_arg, NULL, 0);
h = (int)strtol(height_arg, NULL, 0); h = strtol(height_arg, NULL, 0);
if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0) if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
die("Invalid frame size: %dx%d", w, h); die("Invalid frame size: %dx%d", w, h);
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1)) if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1))
@ -227,7 +235,8 @@ int main(int argc, char **argv) {
// Configuration // Configuration
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&codec, "Failed to get default codec config."); if (res)
die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = w; cfg.g_w = w;
cfg.g_h = h; cfg.g_h = h;
@ -240,13 +249,13 @@ int main(int argc, char **argv) {
// Pass 0 // Pass 0
cfg.g_pass = VPX_RC_FIRST_PASS; cfg.g_pass = VPX_RC_FIRST_PASS;
stats = pass0(&raw, infile, encoder, &cfg, max_frames); stats = pass0(&raw, infile, encoder, &cfg);
// Pass 1 // Pass 1
rewind(infile); rewind(infile);
cfg.g_pass = VPX_RC_LAST_PASS; cfg.g_pass = VPX_RC_LAST_PASS;
cfg.rc_twopass_stats_in = stats; cfg.rc_twopass_stats_in = stats;
pass1(&raw, infile, outfile_arg, encoder, &cfg, max_frames); pass1(&raw, infile, outfile_arg, encoder, &cfg);
free(stats.buf); free(stats.buf);
vpx_img_free(&raw); vpx_img_free(&raw);

View File

@ -8,444 +8,150 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
/*
* This is an example demonstrating multi-resolution encoding in VP8.
* High-resolution input video is down-sampled to lower-resolutions. The
* encoder then encodes the video and outputs multiple bitstreams with
* different resolutions.
*
* This test also allows for settings temporal layers for each spatial layer.
* Different number of temporal layers per spatial stream may be used.
* Currently up to 3 temporal layers per spatial stream (encoder) are supported
* in this test.
*/
#include "./vpx_config.h" // This is an example demonstrating multi-resolution encoding in VP8.
// High-resolution input video is down-sampled to lower-resolutions. The
// encoder then encodes the video and outputs multiple bitstreams with
// different resolutions.
//
// Configure with --enable-multi-res-encoding flag to enable this example.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <assert.h>
#include <sys/time.h>
#include "vpx_ports/vpx_timer.h"
#include "vpx/vpx_encoder.h"
#include "vpx/vp8cx.h"
#include "vpx_ports/mem_ops.h"
#include "../tools_common.h"
#define interface (vpx_codec_vp8_cx())
#define fourcc 0x30385056
void usage_exit(void) { exit(EXIT_FAILURE); }
/*
* The input video frame is downsampled several times to generate a multi-level
* hierarchical structure. NUM_ENCODERS is defined as the number of encoding
* levels required. For example, if the size of input video is 1280x720,
* NUM_ENCODERS is 3, and down-sampling factor is 2, the encoder outputs 3
* bitstreams with resolution of 1280x720(level 0), 640x360(level 1), and
* 320x180(level 2) respectively.
*/
/* Number of encoders (spatial resolutions) used in this test. */
#define NUM_ENCODERS 3
/* Maximum number of temporal layers allowed for this test. */
#define MAX_NUM_TEMPORAL_LAYERS 3
/* This example uses the scaler function in libyuv. */
#include "third_party/libyuv/include/libyuv/basic_types.h" #include "third_party/libyuv/include/libyuv/basic_types.h"
#include "third_party/libyuv/include/libyuv/scale.h" #include "third_party/libyuv/include/libyuv/scale.h"
#include "third_party/libyuv/include/libyuv/cpu_id.h" #include "third_party/libyuv/include/libyuv/cpu_id.h"
int (*read_frame_p)(FILE *f, vpx_image_t *img); #include "vpx/vpx_encoder.h"
#include "vpx/vp8cx.h"
static int read_frame(FILE *f, vpx_image_t *img) { #include "./tools_common.h"
size_t nbytes, to_read; #include "./video_writer.h"
int res = 1;
to_read = img->w * img->h * 3 / 2; // The input video frame is downsampled several times to generate a
nbytes = fread(img->planes[0], 1, to_read, f); // multi-level hierarchical structure. kNumEncoders is defined as the number
if (nbytes != to_read) { // of encoding levels required. For example, if the size of input video is
res = 0; // 1280x720, kNumEncoders is 3, and down-sampling factor is 2, the encoder
if (nbytes > 0) // outputs 3 bitstreams with resolution of 1280x720(level 0),
printf("Warning: Read partial frame. Check your width & height!\n"); // 640x360(level 1), and 320x180(level 2) respectively.
} #define kNumEncoders 3
return res;
static const char *exec_name;
void usage_exit() {
fprintf(stderr,
"Usage: %s <width> <height> <infile> <outfile(s)> <output psnr?>\n",
exec_name);
exit(EXIT_FAILURE);
} }
static int read_frame_by_row(FILE *f, vpx_image_t *img) { int main(int argc, char *argv[]) {
size_t nbytes, to_read;
int res = 1;
int plane;
for (plane = 0; plane < 3; plane++) {
unsigned char *ptr;
int w = (plane ? (1 + img->d_w) / 2 : img->d_w);
int h = (plane ? (1 + img->d_h) / 2 : img->d_h);
int r;
/* Determine the correct plane based on the image format. The for-loop
* always counts in Y,U,V order, but this may not match the order of
* the data on disk.
*/
switch (plane) {
case 1:
ptr = img->planes[img->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V
: VPX_PLANE_U];
break;
case 2:
ptr = img->planes[img->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U
: VPX_PLANE_V];
break;
default: ptr = img->planes[plane];
}
for (r = 0; r < h; r++) {
to_read = w;
nbytes = fread(ptr, 1, to_read, f);
if (nbytes != to_read) {
res = 0;
if (nbytes > 0)
printf("Warning: Read partial frame. Check your width & height!\n");
break;
}
ptr += img->stride[plane];
}
if (!res) break;
}
return res;
}
static void write_ivf_file_header(FILE *outfile, const vpx_codec_enc_cfg_t *cfg,
int frame_cnt) {
char header[32];
if (cfg->g_pass != VPX_RC_ONE_PASS && cfg->g_pass != VPX_RC_LAST_PASS) return;
header[0] = 'D';
header[1] = 'K';
header[2] = 'I';
header[3] = 'F';
mem_put_le16(header + 4, 0); /* version */
mem_put_le16(header + 6, 32); /* headersize */
mem_put_le32(header + 8, fourcc); /* headersize */
mem_put_le16(header + 12, cfg->g_w); /* width */
mem_put_le16(header + 14, cfg->g_h); /* height */
mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */
mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */
mem_put_le32(header + 24, frame_cnt); /* length */
mem_put_le32(header + 28, 0); /* unused */
(void)fwrite(header, 1, 32, outfile);
}
static void write_ivf_frame_header(FILE *outfile,
const vpx_codec_cx_pkt_t *pkt) {
char header[12];
vpx_codec_pts_t pts;
if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return;
pts = pkt->data.frame.pts;
mem_put_le32(header, (int)pkt->data.frame.sz);
mem_put_le32(header + 4, pts & 0xFFFFFFFF);
mem_put_le32(header + 8, pts >> 32);
(void)fwrite(header, 1, 12, outfile);
}
/* Temporal scaling parameters */
/* This sets all the temporal layer parameters given |num_temporal_layers|,
* including the target bit allocation across temporal layers. Bit allocation
* parameters will be passed in as user parameters in another version.
*/
static void set_temporal_layer_pattern(int num_temporal_layers,
vpx_codec_enc_cfg_t *cfg, int bitrate,
int *layer_flags) {
assert(num_temporal_layers <= MAX_NUM_TEMPORAL_LAYERS);
switch (num_temporal_layers) {
case 1: {
/* 1-layer */
cfg->ts_number_layers = 1;
cfg->ts_periodicity = 1;
cfg->ts_rate_decimator[0] = 1;
cfg->ts_layer_id[0] = 0;
cfg->ts_target_bitrate[0] = bitrate;
// Update L only.
layer_flags[0] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
break;
}
case 2: {
/* 2-layers, with sync point at first frame of layer 1. */
cfg->ts_number_layers = 2;
cfg->ts_periodicity = 2;
cfg->ts_rate_decimator[0] = 2;
cfg->ts_rate_decimator[1] = 1;
cfg->ts_layer_id[0] = 0;
cfg->ts_layer_id[1] = 1;
// Use 60/40 bit allocation as example.
cfg->ts_target_bitrate[0] = (int)(0.6f * bitrate);
cfg->ts_target_bitrate[1] = bitrate;
/* 0=L, 1=GF */
// ARF is used as predictor for all frames, and is only updated on
// key frame. Sync point every 8 frames.
// Layer 0: predict from L and ARF, update L and G.
layer_flags[0] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: sync point: predict from L and ARF, and update G.
layer_flags[1] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
// Layer 0, predict from L and ARF, update L.
layer_flags[2] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: predict from L, G and ARF, and update G.
layer_flags[3] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0
layer_flags[4] = layer_flags[2];
// Layer 1
layer_flags[5] = layer_flags[3];
// Layer 0
layer_flags[6] = layer_flags[4];
// Layer 1
layer_flags[7] = layer_flags[5];
break;
}
case 3:
default: {
// 3-layers structure where ARF is used as predictor for all frames,
// and is only updated on key frame.
// Sync points for layer 1 and 2 every 8 frames.
cfg->ts_number_layers = 3;
cfg->ts_periodicity = 4;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
cfg->ts_layer_id[0] = 0;
cfg->ts_layer_id[1] = 2;
cfg->ts_layer_id[2] = 1;
cfg->ts_layer_id[3] = 2;
// Use 45/20/35 bit allocation as example.
cfg->ts_target_bitrate[0] = (int)(0.45f * bitrate);
cfg->ts_target_bitrate[1] = (int)(0.65f * bitrate);
cfg->ts_target_bitrate[2] = bitrate;
/* 0=L, 1=GF, 2=ARF */
// Layer 0: predict from L and ARF; update L and G.
layer_flags[0] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: sync point: predict from L and ARF; update none.
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 1: sync point: predict from L and ARF; update G.
layer_flags[2] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[3] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0: predict from L and ARF; update L.
layer_flags[4] =
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[5] = layer_flags[3];
// Layer 1: predict from L, G, ARF; update G.
layer_flags[6] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[7] = layer_flags[3];
break;
}
}
}
/* The periodicity of the pattern given the number of temporal layers. */
static int periodicity_to_num_layers[MAX_NUM_TEMPORAL_LAYERS] = { 1, 8, 8 };
int main(int argc, char **argv) {
FILE *infile, *outfile[NUM_ENCODERS];
FILE *downsampled_input[NUM_ENCODERS - 1];
char filename[50];
vpx_codec_ctx_t codec[NUM_ENCODERS];
vpx_codec_enc_cfg_t cfg[NUM_ENCODERS];
int frame_cnt = 0; int frame_cnt = 0;
vpx_image_t raw[NUM_ENCODERS]; FILE *infile = NULL;
vpx_codec_err_t res[NUM_ENCODERS]; VpxVideoWriter *writers[kNumEncoders];
vpx_codec_ctx_t codec[kNumEncoders];
vpx_codec_enc_cfg_t cfg[kNumEncoders];
vpx_image_t raw[kNumEncoders];
const VpxInterface *const encoder = get_vpx_encoder_by_name("vp8");
// Currently, only realtime mode is supported in multi-resolution encoding.
const int arg_deadline = VPX_DL_REALTIME;
int i; int i;
int width; int width = 0;
int height; int height = 0;
int length_frame; int frame_avail = 0;
int frame_avail; int got_data = 0;
int got_data;
int flags = 0;
int layer_id = 0;
int layer_flags[VPX_TS_MAX_PERIODICITY * NUM_ENCODERS] = { 0 }; // Set show_psnr to 1/0 to show/not show PSNR. Choose show_psnr=0 if you
int flag_periodicity; // don't need to know PSNR, which will skip PSNR calculation and save
// encoding time.
/*Currently, only realtime mode is supported in multi-resolution encoding.*/
int arg_deadline = VPX_DL_REALTIME;
/* Set show_psnr to 1/0 to show/not show PSNR. Choose show_psnr=0 if you
don't need to know PSNR, which will skip PSNR calculation and save
encoding time. */
int show_psnr = 0; int show_psnr = 0;
int key_frame_insert = 0; uint64_t psnr_sse_total[kNumEncoders] = {0};
uint64_t psnr_sse_total[NUM_ENCODERS] = { 0 }; uint64_t psnr_samples_total[kNumEncoders] = {0};
uint64_t psnr_samples_total[NUM_ENCODERS] = { 0 }; double psnr_totals[kNumEncoders][4] = {{0, 0}};
double psnr_totals[NUM_ENCODERS][4] = { { 0, 0 } }; int psnr_count[kNumEncoders] = {0};
int psnr_count[NUM_ENCODERS] = { 0 };
int64_t cx_time = 0; // Set the required target bitrates for each resolution level.
// If target bitrate for highest-resolution level is set to 0,
// (i.e. target_bitrate[0]=0), we skip encoding at that level.
unsigned int target_bitrate[kNumEncoders] = {1000, 500, 100};
/* Set the required target bitrates for each resolution level. // Enter the frame rate of the input video.
* If target bitrate for highest-resolution level is set to 0, const int framerate = 30;
* (i.e. target_bitrate[0]=0), we skip encoding at that level. // Set down-sampling factor for each resolution level.
*/ // dsf[0] controls down sampling from level 0 to level 1;
unsigned int target_bitrate[NUM_ENCODERS] = { 1000, 500, 100 }; // dsf[1] controls down sampling from level 1 to level 2;
// dsf[2] is not used.
vpx_rational_t dsf[kNumEncoders] = {{2, 1}, {2, 1}, {1, 1}};
/* Enter the frame rate of the input video */ exec_name = argv[0];
int framerate = 30;
/* Set down-sampling factor for each resolution level. if (!encoder)
dsf[0] controls down sampling from level 0 to level 1; die("Unsupported codec.");
dsf[1] controls down sampling from level 1 to level 2;
dsf[2] is not used. */
vpx_rational_t dsf[NUM_ENCODERS] = { { 2, 1 }, { 2, 1 }, { 1, 1 } };
/* Set the number of temporal layers for each encoder/resolution level, // exe_name, input width, input height, input file,
* starting from highest resoln down to lowest resoln. */ // output file 1, output file 2, output file 3, psnr on/off
unsigned int num_temporal_layers[NUM_ENCODERS] = { 3, 3, 3 }; if (argc != (5 + kNumEncoders))
die("Invalid number of input options.");
if (argc != (7 + 3 * NUM_ENCODERS)) printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
die("Usage: %s <width> <height> <frame_rate> <infile> <outfile(s)> "
"<rate_encoder(s)> <temporal_layer(s)> <key_frame_insert> <output "
"psnr?> \n",
argv[0]);
printf("Using %s\n", vpx_codec_iface_name(interface)); width = strtol(argv[1], NULL, 0);
height = strtol(argv[2], NULL, 0);
width = (int)strtol(argv[1], NULL, 0);
height = (int)strtol(argv[2], NULL, 0);
framerate = (int)strtol(argv[3], NULL, 0);
if (width < 16 || width % 2 || height < 16 || height % 2) if (width < 16 || width % 2 || height < 16 || height % 2)
die("Invalid resolution: %ldx%ld", width, height); die("Invalid resolution: %ldx%ld", width, height);
/* Open input video file for encoding */ // Open input video file for encoding
if (!(infile = fopen(argv[4], "rb"))) if (!(infile = fopen(argv[3], "rb")))
die("Failed to open %s for reading", argv[4]); die("Failed to open %s for reading", argv[3]);
/* Open output file for each encoder to output bitstreams */ show_psnr = strtol(argv[kNumEncoders + 4], NULL, 0);
for (i = 0; i < NUM_ENCODERS; i++) {
if (!target_bitrate[i]) {
outfile[i] = NULL;
continue;
}
if (!(outfile[i] = fopen(argv[i + 5], "wb"))) // Populate default encoder configuration
die("Failed to open %s for writing", argv[i + 4]); for (i = 0; i < kNumEncoders; ++i) {
} vpx_codec_err_t res =
vpx_codec_enc_config_default(encoder->codec_interface(), &cfg[i], 0);
// Bitrates per spatial layer: overwrite default rates above. if (res != VPX_CODEC_OK) {
for (i = 0; i < NUM_ENCODERS; i++) { printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
target_bitrate[i] = (int)strtol(argv[NUM_ENCODERS + 5 + i], NULL, 0);
}
// Temporal layers per spatial layers: overwrite default settings above.
for (i = 0; i < NUM_ENCODERS; i++) {
num_temporal_layers[i] =
(int)strtol(argv[2 * NUM_ENCODERS + 5 + i], NULL, 0);
if (num_temporal_layers[i] < 1 || num_temporal_layers[i] > 3)
die("Invalid temporal layers: %d, Must be 1, 2, or 3. \n",
num_temporal_layers);
}
/* Open file to write out each spatially downsampled input stream. */
for (i = 0; i < NUM_ENCODERS - 1; i++) {
// Highest resoln is encoder 0.
if (sprintf(filename, "ds%d.yuv", NUM_ENCODERS - i) < 0) {
return EXIT_FAILURE;
}
downsampled_input[i] = fopen(filename, "wb");
}
key_frame_insert = (int)strtol(argv[3 * NUM_ENCODERS + 5], NULL, 0);
show_psnr = (int)strtol(argv[3 * NUM_ENCODERS + 6], NULL, 0);
/* Populate default encoder configuration */
for (i = 0; i < NUM_ENCODERS; i++) {
res[i] = vpx_codec_enc_config_default(interface, &cfg[i], 0);
if (res[i]) {
printf("Failed to get config: %s\n", vpx_codec_err_to_string(res[i]));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
/* // Update the default configuration according to needs of the application.
* Update the default configuration according to needs of the application. // Highest-resolution encoder settings
*/
/* Highest-resolution encoder settings */
cfg[0].g_w = width; cfg[0].g_w = width;
cfg[0].g_h = height; cfg[0].g_h = height;
cfg[0].rc_dropframe_thresh = 0; cfg[0].g_threads = 1;
cfg[0].rc_dropframe_thresh = 30;
cfg[0].rc_end_usage = VPX_CBR; cfg[0].rc_end_usage = VPX_CBR;
cfg[0].rc_resize_allowed = 0; cfg[0].rc_resize_allowed = 0;
cfg[0].rc_min_quantizer = 2; cfg[0].rc_min_quantizer = 4;
cfg[0].rc_max_quantizer = 56; cfg[0].rc_max_quantizer = 56;
cfg[0].rc_undershoot_pct = 100; cfg[0].rc_undershoot_pct = 98;
cfg[0].rc_overshoot_pct = 15; cfg[0].rc_overshoot_pct = 100;
cfg[0].rc_buf_initial_sz = 500; cfg[0].rc_buf_initial_sz = 500;
cfg[0].rc_buf_optimal_sz = 600; cfg[0].rc_buf_optimal_sz = 600;
cfg[0].rc_buf_sz = 1000; cfg[0].rc_buf_sz = 1000;
cfg[0].g_error_resilient = 1; /* Enable error resilient mode */ cfg[0].g_error_resilient = 1;
cfg[0].g_lag_in_frames = 0; cfg[0].g_lag_in_frames = 0;
cfg[0].kf_mode = VPX_KF_AUTO; // VPX_KF_DISABLED
/* Disable automatic keyframe placement */
/* Note: These 3 settings are copied to all levels. But, except the lowest
* resolution level, all other levels are set to VPX_KF_DISABLED internally.
*/
cfg[0].kf_mode = VPX_KF_AUTO;
cfg[0].kf_min_dist = 3000; cfg[0].kf_min_dist = 3000;
cfg[0].kf_max_dist = 3000; cfg[0].kf_max_dist = 3000;
cfg[0].rc_target_bitrate = target_bitrate[0];
cfg[0].rc_target_bitrate = target_bitrate[0]; /* Set target bitrate */ cfg[0].g_timebase.num = 1;
cfg[0].g_timebase.num = 1; /* Set fps */
cfg[0].g_timebase.den = framerate; cfg[0].g_timebase.den = framerate;
/* Other-resolution encoder settings */ // Other-resolution encoder settings
for (i = 1; i < NUM_ENCODERS; i++) { for (i = 1; i < kNumEncoders; ++i) {
memcpy(&cfg[i], &cfg[0], sizeof(vpx_codec_enc_cfg_t)); cfg[i] = cfg[0];
cfg[i].g_threads = 1;
cfg[i].rc_target_bitrate = target_bitrate[i]; cfg[i].rc_target_bitrate = target_bitrate[i];
/* Note: Width & height of other-resolution encoders are calculated // Note: Width & height of other-resolution encoders are calculated
* from the highest-resolution encoder's size and the corresponding // from the highest-resolution encoder's size and the corresponding
* down_sampling_factor. // down_sampling_factor.
*/
{ {
unsigned int iw = cfg[i - 1].g_w * dsf[i - 1].den + dsf[i - 1].num - 1; unsigned int iw = cfg[i - 1].g_w * dsf[i - 1].den + dsf[i - 1].num - 1;
unsigned int ih = cfg[i - 1].g_h * dsf[i - 1].den + dsf[i - 1].num - 1; unsigned int ih = cfg[i - 1].g_h * dsf[i - 1].den + dsf[i - 1].num - 1;
@ -453,214 +159,141 @@ int main(int argc, char **argv) {
cfg[i].g_h = ih / dsf[i - 1].num; cfg[i].g_h = ih / dsf[i - 1].num;
} }
/* Make width & height to be multiplier of 2. */ // Make width & height to be multiplier of 2.
// Should support odd size ??? if ((cfg[i].g_w) % 2)
if ((cfg[i].g_w) % 2) cfg[i].g_w++; cfg[i].g_w++;
if ((cfg[i].g_h) % 2) cfg[i].g_h++;
if ((cfg[i].g_h) % 2)
cfg[i].g_h++;
} }
// Set the number of threads per encode/spatial layer. // Open output file for each encoder to output bitstreams
// (1, 1, 1) means no encoder threading. for (i = 0; i < kNumEncoders; ++i) {
cfg[0].g_threads = 1; VpxVideoInfo info = {
cfg[1].g_threads = 1; encoder->fourcc,
cfg[2].g_threads = 1; cfg[i].g_w,
cfg[i].g_h,
{cfg[i].g_timebase.num, cfg[i].g_timebase.den}
};
/* Allocate image for each encoder */ if (!(writers[i] = vpx_video_writer_open(argv[i+4], kContainerIVF, &info)))
for (i = 0; i < NUM_ENCODERS; i++) die("Failed to open %s for writing", argv[i+4]);
}
// Allocate image for each encoder
for (i = 0; i < kNumEncoders; ++i)
if (!vpx_img_alloc(&raw[i], VPX_IMG_FMT_I420, cfg[i].g_w, cfg[i].g_h, 32)) if (!vpx_img_alloc(&raw[i], VPX_IMG_FMT_I420, cfg[i].g_w, cfg[i].g_h, 32))
die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h); die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h);
if (raw[0].stride[VPX_PLANE_Y] == (int)raw[0].d_w) // Initialize multi-encoder
read_frame_p = read_frame; if (vpx_codec_enc_init_multi(&codec[0], encoder->codec_interface(), &cfg[0],
else kNumEncoders,
read_frame_p = read_frame_by_row; show_psnr ? VPX_CODEC_USE_PSNR : 0, &dsf[0]))
for (i = 0; i < NUM_ENCODERS; i++)
if (outfile[i]) write_ivf_file_header(outfile[i], &cfg[i], 0);
/* Temporal layers settings */
for (i = 0; i < NUM_ENCODERS; i++) {
set_temporal_layer_pattern(num_temporal_layers[i], &cfg[i],
cfg[i].rc_target_bitrate,
&layer_flags[i * VPX_TS_MAX_PERIODICITY]);
}
/* Initialize multi-encoder */
if (vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS,
(show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0]))
die_codec(&codec[0], "Failed to initialize encoder"); die_codec(&codec[0], "Failed to initialize encoder");
/* The extra encoding configuration parameters can be set as follows. */ // The extra encoding configuration parameters can be set as follows.
/* Set encoding speed */ for (i = 0; i < kNumEncoders; i++) {
for (i = 0; i < NUM_ENCODERS; i++) { // Set encoding speed
int speed = -6; if (vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, -6))
/* Lower speed for the lowest resolution. */
if (i == NUM_ENCODERS - 1) speed = -4;
if (vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed))
die_codec(&codec[i], "Failed to set cpu_used"); die_codec(&codec[i], "Failed to set cpu_used");
}
/* Set static threshold = 1 for all encoders */ // Set static threshold.
for (i = 0; i < NUM_ENCODERS; i++) {
if (vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, 1)) if (vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, 1))
die_codec(&codec[i], "Failed to set static threshold"); die_codec(&codec[i], "Failed to set static threshold");
}
/* Set NOISE_SENSITIVITY to do TEMPORAL_DENOISING */ // Set NOISE_SENSITIVITY to do TEMPORAL_DENOISING
/* Enable denoising for the highest-resolution encoder. */ // Enable denoising for the highest-resolution encoder.
if (vpx_codec_control(&codec[0], VP8E_SET_NOISE_SENSITIVITY, 1)) if (vpx_codec_control(&codec[0], VP8E_SET_NOISE_SENSITIVITY, i == 0))
die_codec(&codec[0], "Failed to set noise_sensitivity"); die_codec(&codec[0], "Failed to set noise_sensitivity");
if (vpx_codec_control(&codec[1], VP8E_SET_NOISE_SENSITIVITY, 1))
die_codec(&codec[1], "Failed to set noise_sensitivity");
for (i = 2; i < NUM_ENCODERS; i++) {
if (vpx_codec_control(&codec[i], VP8E_SET_NOISE_SENSITIVITY, 0))
die_codec(&codec[i], "Failed to set noise_sensitivity");
}
/* Set the number of token partitions */
for (i = 0; i < NUM_ENCODERS; i++) {
if (vpx_codec_control(&codec[i], VP8E_SET_TOKEN_PARTITIONS, 1))
die_codec(&codec[i], "Failed to set static threshold");
}
/* Set the max intra target bitrate */
for (i = 0; i < NUM_ENCODERS; i++) {
unsigned int max_intra_size_pct =
(int)(((double)cfg[0].rc_buf_optimal_sz * 0.5) * framerate / 10);
if (vpx_codec_control(&codec[i], VP8E_SET_MAX_INTRA_BITRATE_PCT,
max_intra_size_pct))
die_codec(&codec[i], "Failed to set static threshold");
// printf("%d %d \n",i,max_intra_size_pct);
} }
frame_avail = 1; frame_avail = 1;
got_data = 0; got_data = 0;
while (frame_avail || got_data) { while (frame_avail || got_data) {
struct vpx_usec_timer timer; vpx_codec_iter_t iter[kNumEncoders] = {NULL};
vpx_codec_iter_t iter[NUM_ENCODERS] = { NULL }; const vpx_codec_cx_pkt_t *pkt[kNumEncoders];
const vpx_codec_cx_pkt_t *pkt[NUM_ENCODERS];
flags = 0; frame_avail = vpx_img_read(&raw[0], infile);
frame_avail = read_frame_p(infile, &raw[0]);
if (frame_avail) { if (frame_avail) {
for (i = 1; i < NUM_ENCODERS; i++) { for (i = 1; i < kNumEncoders; ++i) {
/*Scale the image down a number of times by downsampling factor*/ vpx_image_t *const prev = &raw[i - 1];
/* FilterMode 1 or 2 give better psnr than FilterMode 0. */
I420Scale( // Scale the image down a number of times by downsampling factor
raw[i - 1].planes[VPX_PLANE_Y], raw[i - 1].stride[VPX_PLANE_Y], // FilterMode 1 or 2 give better psnr than FilterMode 0.
raw[i - 1].planes[VPX_PLANE_U], raw[i - 1].stride[VPX_PLANE_U], I420Scale(prev->planes[VPX_PLANE_Y], prev->stride[VPX_PLANE_Y],
raw[i - 1].planes[VPX_PLANE_V], raw[i - 1].stride[VPX_PLANE_V], prev->planes[VPX_PLANE_U], prev->stride[VPX_PLANE_U],
raw[i - 1].d_w, raw[i - 1].d_h, raw[i].planes[VPX_PLANE_Y], prev->planes[VPX_PLANE_V], prev->stride[VPX_PLANE_V],
raw[i].stride[VPX_PLANE_Y], raw[i].planes[VPX_PLANE_U], prev->d_w, prev->d_h,
raw[i].stride[VPX_PLANE_U], raw[i].planes[VPX_PLANE_V], raw[i].planes[VPX_PLANE_Y], raw[i].stride[VPX_PLANE_Y],
raw[i].stride[VPX_PLANE_V], raw[i].d_w, raw[i].d_h, 1); raw[i].planes[VPX_PLANE_U], raw[i].stride[VPX_PLANE_U],
/* Write out down-sampled input. */ raw[i].planes[VPX_PLANE_V], raw[i].stride[VPX_PLANE_V],
length_frame = cfg[i].g_w * cfg[i].g_h * 3 / 2; raw[i].d_w, raw[i].d_h, 1);
if (fwrite(raw[i].planes[0], 1, length_frame,
downsampled_input[NUM_ENCODERS - i - 1]) !=
(unsigned int)length_frame) {
return EXIT_FAILURE;
}
} }
} }
/* Set the flags (reference and update) for all the encoders.*/ // Encode frame.
for (i = 0; i < NUM_ENCODERS; i++) { if (vpx_codec_encode(&codec[0], frame_avail? &raw[0] : NULL,
layer_id = cfg[i].ts_layer_id[frame_cnt % cfg[i].ts_periodicity]; frame_cnt, 1, 0, arg_deadline)) {
flags = 0;
flag_periodicity = periodicity_to_num_layers[num_temporal_layers[i] - 1];
flags = layer_flags[i * VPX_TS_MAX_PERIODICITY +
frame_cnt % flag_periodicity];
// Key frame flag for first frame.
if (frame_cnt == 0) {
flags |= VPX_EFLAG_FORCE_KF;
}
if (frame_cnt > 0 && frame_cnt == key_frame_insert) {
flags = VPX_EFLAG_FORCE_KF;
}
vpx_codec_control(&codec[i], VP8E_SET_FRAME_FLAGS, flags);
vpx_codec_control(&codec[i], VP8E_SET_TEMPORAL_LAYER_ID, layer_id);
}
/* Encode each frame at multi-levels */
/* Note the flags must be set to 0 in the encode call if they are set
for each frame with the vpx_codec_control(), as done above. */
vpx_usec_timer_start(&timer);
if (vpx_codec_encode(&codec[0], frame_avail ? &raw[0] : NULL, frame_cnt, 1,
0, arg_deadline)) {
die_codec(&codec[0], "Failed to encode frame"); die_codec(&codec[0], "Failed to encode frame");
} }
vpx_usec_timer_mark(&timer);
cx_time += vpx_usec_timer_elapsed(&timer);
for (i = NUM_ENCODERS - 1; i >= 0; i--) { for (i = kNumEncoders - 1; i >= 0; i--) {
got_data = 0; got_data = 0;
while ((pkt[i] = vpx_codec_get_cx_data(&codec[i], &iter[i]))) { while ((pkt[i] = vpx_codec_get_cx_data(&codec[i], &iter[i]))) {
got_data = 1; got_data = 1;
switch (pkt[i]->kind) { switch (pkt[i]->kind) {
case VPX_CODEC_CX_FRAME_PKT: case VPX_CODEC_CX_FRAME_PKT:
write_ivf_frame_header(outfile[i], pkt[i]); vpx_video_writer_write_frame(writers[i], pkt[i]->data.frame.buf,
(void)fwrite(pkt[i]->data.frame.buf, 1, pkt[i]->data.frame.sz, pkt[i]->data.frame.sz, frame_cnt - 1);
outfile[i]); break;
break;
case VPX_CODEC_PSNR_PKT: case VPX_CODEC_PSNR_PKT:
if (show_psnr) { if (show_psnr) {
int j; int j;
psnr_sse_total[i] += pkt[i]->data.psnr.sse[0]; psnr_sse_total[i] += pkt[i]->data.psnr.sse[0];
psnr_samples_total[i] += pkt[i]->data.psnr.samples[0]; psnr_samples_total[i] += pkt[i]->data.psnr.samples[0];
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++)
psnr_totals[i][j] += pkt[i]->data.psnr.psnr[j]; psnr_totals[i][j] += pkt[i]->data.psnr.psnr[j];
}
psnr_count[i]++; psnr_count[i]++;
} }
break; break;
default: break; default:
break;
} }
printf(pkt[i]->kind == VPX_CODEC_CX_FRAME_PKT &&
(pkt[i]->data.frame.flags & VPX_FRAME_IS_KEY)? "K":".");
fflush(stdout); fflush(stdout);
} }
} }
frame_cnt++; frame_cnt++;
} }
printf("\n"); printf("\n");
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
fclose(infile); fclose(infile);
printf("Processed %ld frames.\n", (long int)frame_cnt - 1); printf("Processed %d frames.\n", frame_cnt - 1);
for (i = 0; i < NUM_ENCODERS; i++) { for (i = 0; i < kNumEncoders; ++i) {
/* Calculate PSNR and print it out */ // Calculate PSNR and print it out
if ((show_psnr) && (psnr_count[i] > 0)) { if (show_psnr && psnr_count[i] > 0) {
int j; int j;
double ovpsnr = double ovpsnr = sse_to_psnr(psnr_samples_total[i], 255.0,
sse_to_psnr(psnr_samples_total[i], 255.0, psnr_sse_total[i]); psnr_sse_total[i]);
fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i); fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i);
fprintf(stderr, " %.3lf", ovpsnr); fprintf(stderr, " %.3lf", ovpsnr);
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++)
fprintf(stderr, " %.3lf", psnr_totals[i][j] / psnr_count[i]); fprintf(stderr, " %.3lf", psnr_totals[i][j]/psnr_count[i]);
}
} }
if (vpx_codec_destroy(&codec[i])) if (vpx_codec_destroy(&codec[i]))
die_codec(&codec[i], "Failed to destroy codec"); die_codec(&codec[i], "Failed to destroy codec");
vpx_img_free(&raw[i]); vpx_img_free(&raw[i]);
vpx_video_writer_close(writers[i]);
if (!outfile[i]) continue;
/* Try to rewrite the file header with the actual frame count */
if (!fseek(outfile[i], 0, SEEK_SET))
write_ivf_file_header(outfile[i], &cfg[i], frame_cnt - 1);
fclose(outfile[i]);
} }
printf("\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
// VP8 Set Reference Frame // VP8 Set Reference Frame
// ======================= // =======================
// //
@ -51,34 +52,37 @@
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "vp8/common/common.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_writer.h" #include "./video_writer.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> <frame>\n", fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> <frame>\n",
exec_name); exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *codec,
int frame_index, VpxVideoWriter *writer) { vpx_image_t *img,
int frame_index,
VpxVideoWriter *writer) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
vpx_codec_encode(codec, img, frame_index, 1, 0, VPX_DL_GOOD_QUALITY); VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame"); if (res != VPX_CODEC_OK)
die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) { pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame"); die_codec(codec, "Failed to write compressed frame");
@ -94,53 +98,55 @@ static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *infile = NULL; FILE *infile = NULL;
vpx_codec_ctx_t codec; vpx_codec_ctx_t codec = {0};
vpx_codec_enc_cfg_t cfg; vpx_codec_enc_cfg_t cfg = {0};
int frame_count = 0; int frame_count = 0;
vpx_image_t raw; vpx_image_t raw;
vpx_codec_err_t res; vpx_codec_err_t res;
VpxVideoInfo info; VpxVideoInfo info = {0};
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
int update_frame_num = 0; int update_frame_num = 0;
const int fps = 30; // TODO(dkovalev) add command line argument const int fps = 30; // TODO(dkovalev) add command line argument
const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
vp8_zero(codec);
vp8_zero(cfg);
vp8_zero(info);
exec_name = argv[0]; exec_name = argv[0];
if (argc != 6) die("Invalid number of arguments"); if (argc != 6)
die("Invalid number of arguments");
// TODO(dkovalev): add vp9 support and rename the file accordingly // TODO(dkovalev): add vp9 support and rename the file accordingly
encoder = get_vpx_encoder_by_name("vp8"); encoder = get_vpx_encoder_by_name("vp8");
if (!encoder) die("Unsupported codec."); if (!encoder)
die("Unsupported codec.");
update_frame_num = atoi(argv[5]); update_frame_num = atoi(argv[5]);
if (!update_frame_num) die("Couldn't parse frame number '%s'\n", argv[5]); if (!update_frame_num)
die("Couldn't parse frame number '%s'\n", argv[5]);
info.codec_fourcc = encoder->fourcc; info.codec_fourcc = encoder->fourcc;
info.frame_width = (int)strtol(argv[1], NULL, 0); info.frame_width = strtol(argv[1], NULL, 0);
info.frame_height = (int)strtol(argv[2], NULL, 0); info.frame_height = strtol(argv[2], NULL, 0);
info.time_base.numerator = 1; info.time_base.numerator = 1;
info.time_base.denominator = fps; info.time_base.denominator = fps;
if (info.frame_width <= 0 || info.frame_height <= 0 || if (info.frame_width <= 0 ||
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) { info.frame_height <= 0 ||
(info.frame_width % 2) != 0 ||
(info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
} }
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
info.frame_height, 1)) { info.frame_height, 1)) {
die("Failed to allocate image."); die("Failed to allocate image.");
} }
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&codec, "Failed to get default codec config."); if (res)
die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width; cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height; cfg.g_h = info.frame_height;
@ -149,7 +155,8 @@ int main(int argc, char **argv) {
cfg.rc_target_bitrate = bitrate; cfg.rc_target_bitrate = bitrate;
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info); writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", argv[4]); if (!writer)
die("Failed to open %s for writing.", argv[4]);
if (!(infile = fopen(argv[3], "rb"))) if (!(infile = fopen(argv[3], "rb")))
die("Failed to open %s for reading.", argv[3]); die("Failed to open %s for reading.", argv[3]);
@ -171,15 +178,15 @@ int main(int argc, char **argv) {
} }
// Flush encoder. // Flush encoder.
while (encode_frame(&codec, NULL, -1, writer)) { while (encode_frame(&codec, NULL, -1, writer)) {}
}
printf("\n"); printf("\n");
fclose(infile); fclose(infile);
printf("Processed %d frames.\n", frame_count); printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw); vpx_img_free(&raw);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer); vpx_video_writer_close(writer);

View File

@ -14,36 +14,39 @@
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#include "vp9/common/vp9_common.h"
#include "../tools_common.h" #include "./tools_common.h"
#include "../video_writer.h" #include "./video_writer.h"
static const char *exec_name; static const char *exec_name;
void usage_exit(void) { void usage_exit() {
fprintf(stderr, fprintf(stderr, "vp9_lossless_encoder: Example demonstrating VP9 lossless "
"vp9_lossless_encoder: Example demonstrating VP9 lossless " "encoding feature. Supports raw input only.\n");
"encoding feature. Supports raw input only.\n");
fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name); fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *codec,
int frame_index, int flags, VpxVideoWriter *writer) { vpx_image_t *img,
int frame_index,
int flags,
VpxVideoWriter *writer) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY); flags, VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame"); if (res != VPX_CODEC_OK)
die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1; got_pkts = 1;
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) { pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame"); die_codec(codec, "Failed to write compressed frame");
@ -63,40 +66,43 @@ int main(int argc, char **argv) {
int frame_count = 0; int frame_count = 0;
vpx_image_t raw; vpx_image_t raw;
vpx_codec_err_t res; vpx_codec_err_t res;
VpxVideoInfo info; VpxVideoInfo info = {0};
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
const int fps = 30; const int fps = 30;
vp9_zero(info);
exec_name = argv[0]; exec_name = argv[0];
if (argc < 5) die("Invalid number of arguments"); if (argc < 5)
die("Invalid number of arguments");
encoder = get_vpx_encoder_by_name("vp9"); encoder = get_vpx_encoder_by_name("vp9");
if (!encoder) die("Unsupported codec."); if (!encoder)
die("Unsupported codec.");
info.codec_fourcc = encoder->fourcc; info.codec_fourcc = encoder->fourcc;
info.frame_width = (int)strtol(argv[1], NULL, 0); info.frame_width = strtol(argv[1], NULL, 0);
info.frame_height = (int)strtol(argv[2], NULL, 0); info.frame_height = strtol(argv[2], NULL, 0);
info.time_base.numerator = 1; info.time_base.numerator = 1;
info.time_base.denominator = fps; info.time_base.denominator = fps;
if (info.frame_width <= 0 || info.frame_height <= 0 || if (info.frame_width <= 0 ||
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) { info.frame_height <= 0 ||
(info.frame_width % 2) != 0 ||
(info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
} }
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
info.frame_height, 1)) { info.frame_height, 1)) {
die("Failed to allocate image."); die("Failed to allocate image.");
} }
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&codec, "Failed to get default codec config."); if (res)
die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width; cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height; cfg.g_h = info.frame_height;
@ -104,7 +110,8 @@ int main(int argc, char **argv) {
cfg.g_timebase.den = info.time_base.denominator; cfg.g_timebase.den = info.time_base.denominator;
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info); writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", argv[4]); if (!writer)
die("Failed to open %s for writing.", argv[4]);
if (!(infile = fopen(argv[3], "rb"))) if (!(infile = fopen(argv[3], "rb")))
die("Failed to open %s for reading.", argv[3]); die("Failed to open %s for reading.", argv[3]);
@ -121,15 +128,15 @@ int main(int argc, char **argv) {
} }
// Flush encoder. // Flush encoder.
while (encode_frame(&codec, NULL, -1, 0, writer)) { while (encode_frame(&codec, NULL, -1, 0, writer)) {}
}
printf("\n"); printf("\n");
fclose(infile); fclose(infile);
printf("Processed %d frames.\n", frame_count); printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw); vpx_img_free(&raw);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer); vpx_video_writer_close(writer);

View File

@ -1,966 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* This is an example demonstrating how to implement a multi-layer
* VP9 encoding scheme based on spatial scalability for video applications
* that benefit from a scalable bitstream.
*/
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../args.h"
#include "../tools_common.h"
#include "../video_writer.h"
#include "../vpx_ports/vpx_timer.h"
#include "vpx/svc_context.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
#include "../vpxstats.h"
#include "vp9/encoder/vp9_encoder.h"
#define OUTPUT_RC_STATS 1
static const arg_def_t skip_frames_arg =
ARG_DEF("s", "skip-frames", 1, "input frames to skip");
static const arg_def_t frames_arg =
ARG_DEF("f", "frames", 1, "number of frames to encode");
static const arg_def_t threads_arg =
ARG_DEF("th", "threads", 1, "number of threads to use");
#if OUTPUT_RC_STATS
static const arg_def_t output_rc_stats_arg =
ARG_DEF("rcstat", "output_rc_stats", 1, "output rc stats");
#endif
static const arg_def_t width_arg = ARG_DEF("w", "width", 1, "source width");
static const arg_def_t height_arg = ARG_DEF("h", "height", 1, "source height");
static const arg_def_t timebase_arg =
ARG_DEF("t", "timebase", 1, "timebase (num/den)");
static const arg_def_t bitrate_arg = ARG_DEF(
"b", "target-bitrate", 1, "encoding bitrate, in kilobits per second");
static const arg_def_t spatial_layers_arg =
ARG_DEF("sl", "spatial-layers", 1, "number of spatial SVC layers");
static const arg_def_t temporal_layers_arg =
ARG_DEF("tl", "temporal-layers", 1, "number of temporal SVC layers");
static const arg_def_t temporal_layering_mode_arg =
ARG_DEF("tlm", "temporal-layering-mode", 1,
"temporal layering scheme."
"VP9E_TEMPORAL_LAYERING_MODE");
static const arg_def_t kf_dist_arg =
ARG_DEF("k", "kf-dist", 1, "number of frames between keyframes");
static const arg_def_t scale_factors_arg =
ARG_DEF("r", "scale-factors", 1, "scale factors (lowest to highest layer)");
static const arg_def_t passes_arg =
ARG_DEF("p", "passes", 1, "Number of passes (1/2)");
static const arg_def_t pass_arg =
ARG_DEF(NULL, "pass", 1, "Pass to execute (1/2)");
static const arg_def_t fpf_name_arg =
ARG_DEF(NULL, "fpf", 1, "First pass statistics file name");
static const arg_def_t min_q_arg =
ARG_DEF(NULL, "min-q", 1, "Minimum quantizer");
static const arg_def_t max_q_arg =
ARG_DEF(NULL, "max-q", 1, "Maximum quantizer");
static const arg_def_t min_bitrate_arg =
ARG_DEF(NULL, "min-bitrate", 1, "Minimum bitrate");
static const arg_def_t max_bitrate_arg =
ARG_DEF(NULL, "max-bitrate", 1, "Maximum bitrate");
static const arg_def_t lag_in_frame_arg =
ARG_DEF(NULL, "lag-in-frames", 1,
"Number of frame to input before "
"generating any outputs");
static const arg_def_t rc_end_usage_arg =
ARG_DEF(NULL, "rc-end-usage", 1, "0 - 3: VBR, CBR, CQ, Q");
static const arg_def_t speed_arg =
ARG_DEF("sp", "speed", 1, "speed configuration");
static const arg_def_t aqmode_arg =
ARG_DEF("aq", "aqmode", 1, "aq-mode off/on");
static const arg_def_t bitrates_arg =
ARG_DEF("bl", "bitrates", 1, "bitrates[sl * num_tl + tl]");
#if CONFIG_VP9_HIGHBITDEPTH
static const struct arg_enum_list bitdepth_enum[] = {
{ "8", VPX_BITS_8 }, { "10", VPX_BITS_10 }, { "12", VPX_BITS_12 }, { NULL, 0 }
};
static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
"d", "bit-depth", 1, "Bit depth for codec 8, 10 or 12. ", bitdepth_enum);
#endif // CONFIG_VP9_HIGHBITDEPTH
static const arg_def_t *svc_args[] = { &frames_arg,
&width_arg,
&height_arg,
&timebase_arg,
&bitrate_arg,
&skip_frames_arg,
&spatial_layers_arg,
&kf_dist_arg,
&scale_factors_arg,
&passes_arg,
&pass_arg,
&fpf_name_arg,
&min_q_arg,
&max_q_arg,
&min_bitrate_arg,
&max_bitrate_arg,
&temporal_layers_arg,
&temporal_layering_mode_arg,
&lag_in_frame_arg,
&threads_arg,
&aqmode_arg,
#if OUTPUT_RC_STATS
&output_rc_stats_arg,
#endif
#if CONFIG_VP9_HIGHBITDEPTH
&bitdepth_arg,
#endif
&speed_arg,
&rc_end_usage_arg,
&bitrates_arg,
NULL };
static const uint32_t default_frames_to_skip = 0;
static const uint32_t default_frames_to_code = 60 * 60;
static const uint32_t default_width = 1920;
static const uint32_t default_height = 1080;
static const uint32_t default_timebase_num = 1;
static const uint32_t default_timebase_den = 60;
static const uint32_t default_bitrate = 1000;
static const uint32_t default_spatial_layers = 5;
static const uint32_t default_temporal_layers = 1;
static const uint32_t default_kf_dist = 100;
static const uint32_t default_temporal_layering_mode = 0;
static const uint32_t default_output_rc_stats = 0;
static const int32_t default_speed = -1; // -1 means use library default.
static const uint32_t default_threads = 0; // zero means use library default.
typedef struct {
const char *input_filename;
const char *output_filename;
uint32_t frames_to_code;
uint32_t frames_to_skip;
struct VpxInputContext input_ctx;
stats_io_t rc_stats;
int passes;
int pass;
} AppInput;
static const char *exec_name;
void usage_exit(void) {
fprintf(stderr, "Usage: %s <options> input_filename output_filename\n",
exec_name);
fprintf(stderr, "Options:\n");
arg_show_usage(stderr, svc_args);
exit(EXIT_FAILURE);
}
static void parse_command_line(int argc, const char **argv_,
AppInput *app_input, SvcContext *svc_ctx,
vpx_codec_enc_cfg_t *enc_cfg) {
struct arg arg;
char **argv = NULL;
char **argi = NULL;
char **argj = NULL;
vpx_codec_err_t res;
int passes = 0;
int pass = 0;
const char *fpf_file_name = NULL;
unsigned int min_bitrate = 0;
unsigned int max_bitrate = 0;
char string_options[1024] = { 0 };
// initialize SvcContext with parameters that will be passed to vpx_svc_init
svc_ctx->log_level = SVC_LOG_DEBUG;
svc_ctx->spatial_layers = default_spatial_layers;
svc_ctx->temporal_layers = default_temporal_layers;
svc_ctx->temporal_layering_mode = default_temporal_layering_mode;
#if OUTPUT_RC_STATS
svc_ctx->output_rc_stat = default_output_rc_stats;
#endif
svc_ctx->speed = default_speed;
svc_ctx->threads = default_threads;
// start with default encoder configuration
res = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), enc_cfg, 0);
if (res) {
die("Failed to get config: %s\n", vpx_codec_err_to_string(res));
}
// update enc_cfg with app default values
enc_cfg->g_w = default_width;
enc_cfg->g_h = default_height;
enc_cfg->g_timebase.num = default_timebase_num;
enc_cfg->g_timebase.den = default_timebase_den;
enc_cfg->rc_target_bitrate = default_bitrate;
enc_cfg->kf_min_dist = default_kf_dist;
enc_cfg->kf_max_dist = default_kf_dist;
enc_cfg->rc_end_usage = VPX_CQ;
// initialize AppInput with default values
app_input->frames_to_code = default_frames_to_code;
app_input->frames_to_skip = default_frames_to_skip;
// process command line options
argv = argv_dup(argc - 1, argv_ + 1);
for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
arg.argv_step = 1;
if (arg_match(&arg, &frames_arg, argi)) {
app_input->frames_to_code = arg_parse_uint(&arg);
} else if (arg_match(&arg, &width_arg, argi)) {
enc_cfg->g_w = arg_parse_uint(&arg);
} else if (arg_match(&arg, &height_arg, argi)) {
enc_cfg->g_h = arg_parse_uint(&arg);
} else if (arg_match(&arg, &timebase_arg, argi)) {
enc_cfg->g_timebase = arg_parse_rational(&arg);
} else if (arg_match(&arg, &bitrate_arg, argi)) {
enc_cfg->rc_target_bitrate = arg_parse_uint(&arg);
} else if (arg_match(&arg, &skip_frames_arg, argi)) {
app_input->frames_to_skip = arg_parse_uint(&arg);
} else if (arg_match(&arg, &spatial_layers_arg, argi)) {
svc_ctx->spatial_layers = arg_parse_uint(&arg);
} else if (arg_match(&arg, &temporal_layers_arg, argi)) {
svc_ctx->temporal_layers = arg_parse_uint(&arg);
#if OUTPUT_RC_STATS
} else if (arg_match(&arg, &output_rc_stats_arg, argi)) {
svc_ctx->output_rc_stat = arg_parse_uint(&arg);
#endif
} else if (arg_match(&arg, &speed_arg, argi)) {
svc_ctx->speed = arg_parse_uint(&arg);
} else if (arg_match(&arg, &aqmode_arg, argi)) {
svc_ctx->aqmode = arg_parse_uint(&arg);
} else if (arg_match(&arg, &threads_arg, argi)) {
svc_ctx->threads = arg_parse_uint(&arg);
} else if (arg_match(&arg, &temporal_layering_mode_arg, argi)) {
svc_ctx->temporal_layering_mode = enc_cfg->temporal_layering_mode =
arg_parse_int(&arg);
if (svc_ctx->temporal_layering_mode) {
enc_cfg->g_error_resilient = 1;
}
} else if (arg_match(&arg, &kf_dist_arg, argi)) {
enc_cfg->kf_min_dist = arg_parse_uint(&arg);
enc_cfg->kf_max_dist = enc_cfg->kf_min_dist;
} else if (arg_match(&arg, &scale_factors_arg, argi)) {
snprintf(string_options, sizeof(string_options), "%s scale-factors=%s",
string_options, arg.val);
} else if (arg_match(&arg, &bitrates_arg, argi)) {
snprintf(string_options, sizeof(string_options), "%s bitrates=%s",
string_options, arg.val);
} else if (arg_match(&arg, &passes_arg, argi)) {
passes = arg_parse_uint(&arg);
if (passes < 1 || passes > 2) {
die("Error: Invalid number of passes (%d)\n", passes);
}
} else if (arg_match(&arg, &pass_arg, argi)) {
pass = arg_parse_uint(&arg);
if (pass < 1 || pass > 2) {
die("Error: Invalid pass selected (%d)\n", pass);
}
} else if (arg_match(&arg, &fpf_name_arg, argi)) {
fpf_file_name = arg.val;
} else if (arg_match(&arg, &min_q_arg, argi)) {
snprintf(string_options, sizeof(string_options), "%s min-quantizers=%s",
string_options, arg.val);
} else if (arg_match(&arg, &max_q_arg, argi)) {
snprintf(string_options, sizeof(string_options), "%s max-quantizers=%s",
string_options, arg.val);
} else if (arg_match(&arg, &min_bitrate_arg, argi)) {
min_bitrate = arg_parse_uint(&arg);
} else if (arg_match(&arg, &max_bitrate_arg, argi)) {
max_bitrate = arg_parse_uint(&arg);
} else if (arg_match(&arg, &lag_in_frame_arg, argi)) {
enc_cfg->g_lag_in_frames = arg_parse_uint(&arg);
} else if (arg_match(&arg, &rc_end_usage_arg, argi)) {
enc_cfg->rc_end_usage = arg_parse_uint(&arg);
#if CONFIG_VP9_HIGHBITDEPTH
} else if (arg_match(&arg, &bitdepth_arg, argi)) {
enc_cfg->g_bit_depth = arg_parse_enum_or_int(&arg);
switch (enc_cfg->g_bit_depth) {
case VPX_BITS_8:
enc_cfg->g_input_bit_depth = 8;
enc_cfg->g_profile = 0;
break;
case VPX_BITS_10:
enc_cfg->g_input_bit_depth = 10;
enc_cfg->g_profile = 2;
break;
case VPX_BITS_12:
enc_cfg->g_input_bit_depth = 12;
enc_cfg->g_profile = 2;
break;
default:
die("Error: Invalid bit depth selected (%d)\n", enc_cfg->g_bit_depth);
break;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
} else {
++argj;
}
}
// There will be a space in front of the string options
if (strlen(string_options) > 0)
vpx_svc_set_options(svc_ctx, string_options + 1);
if (passes == 0 || passes == 1) {
if (pass) {
fprintf(stderr, "pass is ignored since there's only one pass\n");
}
enc_cfg->g_pass = VPX_RC_ONE_PASS;
} else {
if (pass == 0) {
die("pass must be specified when passes is 2\n");
}
if (fpf_file_name == NULL) {
die("fpf must be specified when passes is 2\n");
}
if (pass == 1) {
enc_cfg->g_pass = VPX_RC_FIRST_PASS;
if (!stats_open_file(&app_input->rc_stats, fpf_file_name, 0)) {
fatal("Failed to open statistics store");
}
} else {
enc_cfg->g_pass = VPX_RC_LAST_PASS;
if (!stats_open_file(&app_input->rc_stats, fpf_file_name, 1)) {
fatal("Failed to open statistics store");
}
enc_cfg->rc_twopass_stats_in = stats_get(&app_input->rc_stats);
}
app_input->passes = passes;
app_input->pass = pass;
}
if (enc_cfg->rc_target_bitrate > 0) {
if (min_bitrate > 0) {
enc_cfg->rc_2pass_vbr_minsection_pct =
min_bitrate * 100 / enc_cfg->rc_target_bitrate;
}
if (max_bitrate > 0) {
enc_cfg->rc_2pass_vbr_maxsection_pct =
max_bitrate * 100 / enc_cfg->rc_target_bitrate;
}
}
// Check for unrecognized options
for (argi = argv; *argi; ++argi)
if (argi[0][0] == '-' && strlen(argi[0]) > 1)
die("Error: Unrecognized option %s\n", *argi);
if (argv[0] == NULL || argv[1] == 0) {
usage_exit();
}
app_input->input_filename = argv[0];
app_input->output_filename = argv[1];
free(argv);
if (enc_cfg->g_w < 16 || enc_cfg->g_w % 2 || enc_cfg->g_h < 16 ||
enc_cfg->g_h % 2)
die("Invalid resolution: %d x %d\n", enc_cfg->g_w, enc_cfg->g_h);
printf(
"Codec %s\nframes: %d, skip: %d\n"
"layers: %d\n"
"width %d, height: %d,\n"
"num: %d, den: %d, bitrate: %d,\n"
"gop size: %d\n",
vpx_codec_iface_name(vpx_codec_vp9_cx()), app_input->frames_to_code,
app_input->frames_to_skip, svc_ctx->spatial_layers, enc_cfg->g_w,
enc_cfg->g_h, enc_cfg->g_timebase.num, enc_cfg->g_timebase.den,
enc_cfg->rc_target_bitrate, enc_cfg->kf_max_dist);
}
#if OUTPUT_RC_STATS
// For rate control encoding stats.
struct RateControlStats {
// Number of input frames per layer.
int layer_input_frames[VPX_MAX_LAYERS];
// Total (cumulative) number of encoded frames per layer.
int layer_tot_enc_frames[VPX_MAX_LAYERS];
// Number of encoded non-key frames per layer.
int layer_enc_frames[VPX_MAX_LAYERS];
// Framerate per layer (cumulative).
double layer_framerate[VPX_MAX_LAYERS];
// Target average frame size per layer (per-frame-bandwidth per layer).
double layer_pfb[VPX_MAX_LAYERS];
// Actual average frame size per layer.
double layer_avg_frame_size[VPX_MAX_LAYERS];
// Average rate mismatch per layer (|target - actual| / target).
double layer_avg_rate_mismatch[VPX_MAX_LAYERS];
// Actual encoding bitrate per layer (cumulative).
double layer_encoding_bitrate[VPX_MAX_LAYERS];
// Average of the short-time encoder actual bitrate.
// TODO(marpan): Should we add these short-time stats for each layer?
double avg_st_encoding_bitrate;
// Variance of the short-time encoder actual bitrate.
double variance_st_encoding_bitrate;
// Window (number of frames) for computing short-time encoding bitrate.
int window_size;
// Number of window measurements.
int window_count;
};
// Note: these rate control stats assume only 1 key frame in the
// sequence (i.e., first frame only).
static void set_rate_control_stats(struct RateControlStats *rc,
vpx_codec_enc_cfg_t *cfg) {
unsigned int sl, tl;
// Set the layer (cumulative) framerate and the target layer (non-cumulative)
// per-frame-bandwidth, for the rate control encoding stats below.
const double framerate = cfg->g_timebase.den / cfg->g_timebase.num;
for (sl = 0; sl < cfg->ss_number_layers; ++sl) {
for (tl = 0; tl < cfg->ts_number_layers; ++tl) {
const int layer = sl * cfg->ts_number_layers + tl;
if (cfg->ts_number_layers == 1)
rc->layer_framerate[layer] = framerate;
else
rc->layer_framerate[layer] = framerate / cfg->ts_rate_decimator[tl];
if (tl > 0) {
rc->layer_pfb[layer] =
1000.0 *
(cfg->layer_target_bitrate[layer] -
cfg->layer_target_bitrate[layer - 1]) /
(rc->layer_framerate[layer] - rc->layer_framerate[layer - 1]);
} else {
rc->layer_pfb[layer] = 1000.0 * cfg->layer_target_bitrate[layer] /
rc->layer_framerate[layer];
}
rc->layer_input_frames[layer] = 0;
rc->layer_enc_frames[layer] = 0;
rc->layer_tot_enc_frames[layer] = 0;
rc->layer_encoding_bitrate[layer] = 0.0;
rc->layer_avg_frame_size[layer] = 0.0;
rc->layer_avg_rate_mismatch[layer] = 0.0;
}
}
rc->window_count = 0;
rc->window_size = 15;
rc->avg_st_encoding_bitrate = 0.0;
rc->variance_st_encoding_bitrate = 0.0;
}
static void printout_rate_control_summary(struct RateControlStats *rc,
vpx_codec_enc_cfg_t *cfg,
int frame_cnt) {
unsigned int sl, tl;
double perc_fluctuation = 0.0;
int tot_num_frames = 0;
printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
printf("Rate control layer stats for sl%d tl%d layer(s):\n\n",
cfg->ss_number_layers, cfg->ts_number_layers);
for (sl = 0; sl < cfg->ss_number_layers; ++sl) {
tot_num_frames = 0;
for (tl = 0; tl < cfg->ts_number_layers; ++tl) {
const int layer = sl * cfg->ts_number_layers + tl;
const int num_dropped =
(tl > 0)
? (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer])
: (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer] -
1);
tot_num_frames += rc->layer_input_frames[layer];
rc->layer_encoding_bitrate[layer] = 0.001 * rc->layer_framerate[layer] *
rc->layer_encoding_bitrate[layer] /
tot_num_frames;
rc->layer_avg_frame_size[layer] =
rc->layer_avg_frame_size[layer] / rc->layer_enc_frames[layer];
rc->layer_avg_rate_mismatch[layer] = 100.0 *
rc->layer_avg_rate_mismatch[layer] /
rc->layer_enc_frames[layer];
printf("For layer#: sl%d tl%d \n", sl, tl);
printf("Bitrate (target vs actual): %d %f.0 kbps\n",
cfg->layer_target_bitrate[layer],
rc->layer_encoding_bitrate[layer]);
printf("Average frame size (target vs actual): %f %f bits\n",
rc->layer_pfb[layer], rc->layer_avg_frame_size[layer]);
printf("Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[layer]);
printf(
"Number of input frames, encoded (non-key) frames, "
"and percent dropped frames: %d %d %f.0 \n",
rc->layer_input_frames[layer], rc->layer_enc_frames[layer],
100.0 * num_dropped / rc->layer_input_frames[layer]);
printf("\n");
}
}
rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
rc->variance_st_encoding_bitrate =
rc->variance_st_encoding_bitrate / rc->window_count -
(rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
rc->avg_st_encoding_bitrate;
printf("Short-time stats, for window of %d frames: \n", rc->window_size);
printf("Average, rms-variance, and percent-fluct: %f %f %f \n",
rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
perc_fluctuation);
printf("Num of input, num of encoded (super) frames: %d %d \n", frame_cnt,
tot_num_frames);
}
vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz,
uint64_t sizes[8], int *count) {
// A chunk ending with a byte matching 0xc0 is an invalid chunk unless
// it is a super frame index. If the last byte of real video compression
// data is 0xc0 the encoder must add a 0 byte. If we have the marker but
// not the associated matching marker byte at the front of the index we have
// an invalid bitstream and need to return an error.
uint8_t marker;
marker = *(data + data_sz - 1);
*count = 0;
if ((marker & 0xe0) == 0xc0) {
const uint32_t frames = (marker & 0x7) + 1;
const uint32_t mag = ((marker >> 3) & 0x3) + 1;
const size_t index_sz = 2 + mag * frames;
// This chunk is marked as having a superframe index but doesn't have
// enough data for it, thus it's an invalid superframe index.
if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
{
const uint8_t marker2 = *(data + data_sz - index_sz);
// This chunk is marked as having a superframe index but doesn't have
// the matching marker byte at the front of the index therefore it's an
// invalid chunk.
if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
}
{
// Found a valid superframe index.
uint32_t i, j;
const uint8_t *x = &data[data_sz - index_sz + 1];
for (i = 0; i < frames; ++i) {
uint32_t this_sz = 0;
for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
sizes[i] = this_sz;
}
*count = frames;
}
}
return VPX_CODEC_OK;
}
#endif
// Example pattern for spatial layers and 2 temporal layers used in the
// bypass/flexible mode. The pattern corresponds to the pattern
// VP9E_TEMPORAL_LAYERING_MODE_0101 (temporal_layering_mode == 2) used in
// non-flexible mode.
void set_frame_flags_bypass_mode(int tl, int num_spatial_layers,
int is_key_frame,
vpx_svc_ref_frame_config_t *ref_frame_config) {
int sl;
for (sl = 0; sl < num_spatial_layers; ++sl) {
if (!tl) {
if (!sl) {
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
} else {
if (is_key_frame) {
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
} else {
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
}
}
} else if (tl == 1) {
if (!sl) {
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_GF;
} else {
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
if (sl == num_spatial_layers - 1)
ref_frame_config->frame_flags[sl] =
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
}
}
if (tl == 0) {
ref_frame_config->lst_fb_idx[sl] = sl;
if (sl) {
if (is_key_frame) {
ref_frame_config->lst_fb_idx[sl] = sl - 1;
ref_frame_config->gld_fb_idx[sl] = sl;
} else {
ref_frame_config->gld_fb_idx[sl] = sl - 1;
}
} else {
ref_frame_config->gld_fb_idx[sl] = 0;
}
ref_frame_config->alt_fb_idx[sl] = 0;
} else if (tl == 1) {
ref_frame_config->lst_fb_idx[sl] = sl;
ref_frame_config->gld_fb_idx[sl] = num_spatial_layers + sl - 1;
ref_frame_config->alt_fb_idx[sl] = num_spatial_layers + sl;
}
}
}
int main(int argc, const char **argv) {
AppInput app_input;
VpxVideoWriter *writer = NULL;
VpxVideoInfo info;
vpx_codec_ctx_t codec;
vpx_codec_enc_cfg_t enc_cfg;
SvcContext svc_ctx;
uint32_t i;
uint32_t frame_cnt = 0;
vpx_image_t raw;
vpx_codec_err_t res;
int pts = 0; /* PTS starts at 0 */
int frame_duration = 1; /* 1 timebase tick per frame */
FILE *infile = NULL;
int end_of_stream = 0;
int frames_received = 0;
#if OUTPUT_RC_STATS
VpxVideoWriter *outfile[VPX_SS_MAX_LAYERS] = { NULL };
struct RateControlStats rc;
vpx_svc_layer_id_t layer_id;
vpx_svc_ref_frame_config_t ref_frame_config;
unsigned int sl, tl;
double sum_bitrate = 0.0;
double sum_bitrate2 = 0.0;
double framerate = 30.0;
#endif
struct vpx_usec_timer timer;
int64_t cx_time = 0;
memset(&svc_ctx, 0, sizeof(svc_ctx));
memset(&app_input, 0, sizeof(AppInput));
memset(&info, 0, sizeof(VpxVideoInfo));
exec_name = argv[0];
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
// Allocate image buffer
#if CONFIG_VP9_HIGHBITDEPTH
if (!vpx_img_alloc(&raw,
enc_cfg.g_input_bit_depth == 8 ? VPX_IMG_FMT_I420
: VPX_IMG_FMT_I42016,
enc_cfg.g_w, enc_cfg.g_h, 32)) {
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
}
#else
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, enc_cfg.g_w, enc_cfg.g_h, 32)) {
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
if (!(infile = fopen(app_input.input_filename, "rb")))
die("Failed to open %s for reading\n", app_input.input_filename);
// Initialize codec
if (vpx_svc_init(&svc_ctx, &codec, vpx_codec_vp9_cx(), &enc_cfg) !=
VPX_CODEC_OK)
die("Failed to initialize encoder\n");
#if OUTPUT_RC_STATS
rc.window_count = 1;
rc.window_size = 15; // Silence a static analysis warning.
rc.avg_st_encoding_bitrate = 0.0;
rc.variance_st_encoding_bitrate = 0.0;
if (svc_ctx.output_rc_stat) {
set_rate_control_stats(&rc, &enc_cfg);
framerate = enc_cfg.g_timebase.den / enc_cfg.g_timebase.num;
}
#endif
info.codec_fourcc = VP9_FOURCC;
info.time_base.numerator = enc_cfg.g_timebase.num;
info.time_base.denominator = enc_cfg.g_timebase.den;
if (!(app_input.passes == 2 && app_input.pass == 1)) {
// We don't save the bitstream for the 1st pass on two pass rate control
writer =
vpx_video_writer_open(app_input.output_filename, kContainerIVF, &info);
if (!writer)
die("Failed to open %s for writing\n", app_input.output_filename);
}
#if OUTPUT_RC_STATS
// Write out spatial layer stream.
// TODO(marpan/jianj): allow for writing each spatial and temporal stream.
if (svc_ctx.output_rc_stat) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
char file_name[PATH_MAX];
snprintf(file_name, sizeof(file_name), "%s_s%d.ivf",
app_input.output_filename, sl);
outfile[sl] = vpx_video_writer_open(file_name, kContainerIVF, &info);
if (!outfile[sl]) die("Failed to open %s for writing", file_name);
}
}
#endif
// skip initial frames
for (i = 0; i < app_input.frames_to_skip; ++i) vpx_img_read(&raw, infile);
if (svc_ctx.speed != -1)
vpx_codec_control(&codec, VP8E_SET_CPUUSED, svc_ctx.speed);
if (svc_ctx.threads) {
vpx_codec_control(&codec, VP9E_SET_TILE_COLUMNS, get_msb(svc_ctx.threads));
if (svc_ctx.threads > 1)
vpx_codec_control(&codec, VP9E_SET_ROW_MT, 1);
else
vpx_codec_control(&codec, VP9E_SET_ROW_MT, 0);
}
if (svc_ctx.speed >= 5 && svc_ctx.aqmode == 1)
vpx_codec_control(&codec, VP9E_SET_AQ_MODE, 3);
if (svc_ctx.speed >= 5)
vpx_codec_control(&codec, VP8E_SET_STATIC_THRESHOLD, 1);
vpx_codec_control(&codec, VP8E_SET_MAX_INTRA_BITRATE_PCT, 900);
vpx_codec_control(&codec, VP9E_SET_SVC_INTER_LAYER_PRED, 0);
vpx_codec_control(&codec, VP9E_SET_NOISE_SENSITIVITY, 0);
// Encode frames
while (!end_of_stream) {
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *cx_pkt;
if (frame_cnt >= app_input.frames_to_code || !vpx_img_read(&raw, infile)) {
// We need one extra vpx_svc_encode call at end of stream to flush
// encoder and get remaining data
end_of_stream = 1;
}
// For BYPASS/FLEXIBLE mode, set the frame flags (reference and updates)
// and the buffer indices for each spatial layer of the current
// (super)frame to be encoded. The temporal layer_id for the current frame
// also needs to be set.
// TODO(marpan): Should rename the "VP9E_TEMPORAL_LAYERING_MODE_BYPASS"
// mode to "VP9E_LAYERING_MODE_BYPASS".
if (svc_ctx.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
layer_id.spatial_layer_id = 0;
// Example for 2 temporal layers.
if (frame_cnt % 2 == 0)
layer_id.temporal_layer_id = 0;
else
layer_id.temporal_layer_id = 1;
// Note that we only set the temporal layer_id, since we are calling
// the encode for the whole superframe. The encoder will internally loop
// over all the spatial layers for the current superframe.
vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id);
// TODO(jianj): Fix the parameter passing for "is_key_frame" in
// set_frame_flags_bypass_model() for case of periodic key frames.
set_frame_flags_bypass_mode(layer_id.temporal_layer_id,
svc_ctx.spatial_layers, frame_cnt == 0,
&ref_frame_config);
vpx_codec_control(&codec, VP9E_SET_SVC_REF_FRAME_CONFIG,
&ref_frame_config);
// Keep track of input frames, to account for frame drops in rate control
// stats/metrics.
for (sl = 0; sl < (unsigned int)enc_cfg.ss_number_layers; ++sl) {
++rc.layer_input_frames[sl * enc_cfg.ts_number_layers +
layer_id.temporal_layer_id];
}
} else {
// For the fixed pattern SVC, temporal layer is given by superframe count.
unsigned int tl = 0;
if (enc_cfg.ts_number_layers == 2)
tl = (frame_cnt % 2 != 0);
else if (enc_cfg.ts_number_layers == 3) {
if (frame_cnt % 2 != 0) tl = 2;
if ((frame_cnt > 1) && ((frame_cnt - 2) % 4 == 0)) tl = 1;
}
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl)
++rc.layer_input_frames[sl * enc_cfg.ts_number_layers + tl];
}
vpx_usec_timer_start(&timer);
res = vpx_svc_encode(
&svc_ctx, &codec, (end_of_stream ? NULL : &raw), pts, frame_duration,
svc_ctx.speed >= 5 ? VPX_DL_REALTIME : VPX_DL_GOOD_QUALITY);
vpx_usec_timer_mark(&timer);
cx_time += vpx_usec_timer_elapsed(&timer);
fflush(stdout);
if (res != VPX_CODEC_OK) {
die_codec(&codec, "Failed to encode frame");
}
while ((cx_pkt = vpx_codec_get_cx_data(&codec, &iter)) != NULL) {
switch (cx_pkt->kind) {
case VPX_CODEC_CX_FRAME_PKT: {
SvcInternal_t *const si = (SvcInternal_t *)svc_ctx.internal;
if (cx_pkt->data.frame.sz > 0) {
#if OUTPUT_RC_STATS
uint64_t sizes[8];
uint64_t sizes_parsed[8];
int count = 0;
vp9_zero(sizes);
vp9_zero(sizes_parsed);
#endif
vpx_video_writer_write_frame(writer, cx_pkt->data.frame.buf,
cx_pkt->data.frame.sz,
cx_pkt->data.frame.pts);
#if OUTPUT_RC_STATS
// TODO(marpan): Put this (to line728) in separate function.
if (svc_ctx.output_rc_stat) {
vpx_codec_control(&codec, VP9E_GET_SVC_LAYER_ID, &layer_id);
parse_superframe_index(cx_pkt->data.frame.buf,
cx_pkt->data.frame.sz, sizes_parsed,
&count);
if (enc_cfg.ss_number_layers == 1)
sizes[0] = cx_pkt->data.frame.sz;
if (svc_ctx.temporal_layering_mode !=
VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
int num_layers_encoded = 0;
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
sizes[sl] = 0;
if (cx_pkt->data.frame.spatial_layer_encoded[sl]) {
sizes[sl] = sizes_parsed[num_layers_encoded];
num_layers_encoded++;
}
}
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
unsigned int sl2;
uint64_t tot_size = 0;
for (sl2 = 0; sl2 <= sl; ++sl2) {
if (cx_pkt->data.frame.spatial_layer_encoded[sl2])
tot_size += sizes[sl2];
}
if (tot_size > 0)
vpx_video_writer_write_frame(
outfile[sl], cx_pkt->data.frame.buf, (size_t)(tot_size),
cx_pkt->data.frame.pts);
}
}
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
if (cx_pkt->data.frame.spatial_layer_encoded[sl]) {
for (tl = layer_id.temporal_layer_id;
tl < enc_cfg.ts_number_layers; ++tl) {
const int layer = sl * enc_cfg.ts_number_layers + tl;
++rc.layer_tot_enc_frames[layer];
rc.layer_encoding_bitrate[layer] += 8.0 * sizes[sl];
// Keep count of rate control stats per layer, for non-key
// frames.
if (tl == (unsigned int)layer_id.temporal_layer_id &&
!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY)) {
rc.layer_avg_frame_size[layer] += 8.0 * sizes[sl];
rc.layer_avg_rate_mismatch[layer] +=
fabs(8.0 * sizes[sl] - rc.layer_pfb[layer]) /
rc.layer_pfb[layer];
++rc.layer_enc_frames[layer];
}
}
}
}
// Update for short-time encoding bitrate states, for moving
// window of size rc->window, shifted by rc->window / 2.
// Ignore first window segment, due to key frame.
if (frame_cnt > (unsigned int)rc.window_size) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
if (cx_pkt->data.frame.spatial_layer_encoded[sl])
sum_bitrate += 0.001 * 8.0 * sizes[sl] * framerate;
}
if (frame_cnt % rc.window_size == 0) {
rc.window_count += 1;
rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
rc.variance_st_encoding_bitrate +=
(sum_bitrate / rc.window_size) *
(sum_bitrate / rc.window_size);
sum_bitrate = 0.0;
}
}
// Second shifted window.
if (frame_cnt >
(unsigned int)(rc.window_size + rc.window_size / 2)) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
sum_bitrate2 += 0.001 * 8.0 * sizes[sl] * framerate;
}
if (frame_cnt > (unsigned int)(2 * rc.window_size) &&
frame_cnt % rc.window_size == 0) {
rc.window_count += 1;
rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
rc.variance_st_encoding_bitrate +=
(sum_bitrate2 / rc.window_size) *
(sum_bitrate2 / rc.window_size);
sum_bitrate2 = 0.0;
}
}
}
#endif
}
/*
printf("SVC frame: %d, kf: %d, size: %d, pts: %d\n", frames_received,
!!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY),
(int)cx_pkt->data.frame.sz, (int)cx_pkt->data.frame.pts);
*/
if (enc_cfg.ss_number_layers == 1 && enc_cfg.ts_number_layers == 1)
si->bytes_sum[0] += (int)cx_pkt->data.frame.sz;
++frames_received;
break;
}
case VPX_CODEC_STATS_PKT: {
stats_write(&app_input.rc_stats, cx_pkt->data.twopass_stats.buf,
cx_pkt->data.twopass_stats.sz);
break;
}
default: { break; }
}
}
if (!end_of_stream) {
++frame_cnt;
pts += frame_duration;
}
}
// Compensate for the extra frame count for the bypass mode.
if (svc_ctx.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
const int layer =
sl * enc_cfg.ts_number_layers + layer_id.temporal_layer_id;
--rc.layer_input_frames[layer];
}
}
printf("Processed %d frames\n", frame_cnt);
fclose(infile);
#if OUTPUT_RC_STATS
if (svc_ctx.output_rc_stat) {
printout_rate_control_summary(&rc, &enc_cfg, frame_cnt);
printf("\n");
}
#endif
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
if (app_input.passes == 2) stats_close(&app_input.rc_stats, 1);
if (writer) {
vpx_video_writer_close(writer);
}
#if OUTPUT_RC_STATS
if (svc_ctx.output_rc_stat) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
vpx_video_writer_close(outfile[sl]);
}
}
#endif
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
vpx_img_free(&raw);
// display average size, psnr
vpx_svc_dump_statistics(&svc_ctx);
vpx_svc_release(&svc_ctx);
return EXIT_SUCCESS;
}

View File

@ -8,8 +8,9 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
// VP9 Set Reference Frame // VP9 Set Reference Frame
// ============================ // =======================
// //
// This is an example demonstrating how to overwrite the VP9 encoder's // This is an example demonstrating how to overwrite the VP9 encoder's
// internal reference frame. In the sample we set the last frame to the // internal reference frame. In the sample we set the last frame to the
@ -23,8 +24,7 @@
// Usage // Usage
// ----- // -----
// This example encodes a raw video. And the last argument passed in specifies // This example encodes a raw video. And the last argument passed in specifies
// the frame number to update the reference frame on. For example, run // the frame number to update the reference frame on.
// examples/vp9cx_set_ref 352 288 in.yuv out.ivf 4 30
// The parameter is parsed as follows: // The parameter is parsed as follows:
// //
// //
@ -53,7 +53,6 @@
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "vp9/common/vp9_common.h"
#include "./tools_common.h" #include "./tools_common.h"
#include "./video_writer.h" #include "./video_writer.h"
@ -61,9 +60,8 @@
static const char *exec_name; static const char *exec_name;
void usage_exit() { void usage_exit() {
fprintf(stderr, fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> "
"Usage: %s <width> <height> <infile> <outfile> " "<frame>\n",
"<frame> <limit(optional)>\n",
exec_name); exec_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -71,7 +69,8 @@ void usage_exit() {
static int compare_img(const vpx_image_t *const img1, static int compare_img(const vpx_image_t *const img1,
const vpx_image_t *const img2) { const vpx_image_t *const img2) {
uint32_t l_w = img1->d_w; uint32_t l_w = img1->d_w;
uint32_t c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; uint32_t c_w =
(img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift;
const uint32_t c_h = const uint32_t c_h =
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift;
uint32_t i; uint32_t i;
@ -99,10 +98,10 @@ static int compare_img(const vpx_image_t *const img1,
return match; return match;
} }
#define mmin(a, b) ((a) < (b) ? (a) : (b)) #define mmin(a, b) ((a) < (b) ? (a) : (b))
static void find_mismatch(const vpx_image_t *const img1, static void find_mismatch(const vpx_image_t *const img1,
const vpx_image_t *const img2, int yloc[4], const vpx_image_t *const img2,
int uloc[4], int vloc[4]) { int yloc[4], int uloc[4], int vloc[4]) {
const uint32_t bsize = 64; const uint32_t bsize = 64;
const uint32_t bsizey = bsize >> img1->y_chroma_shift; const uint32_t bsizey = bsize >> img1->y_chroma_shift;
const uint32_t bsizex = bsize >> img1->x_chroma_shift; const uint32_t bsizex = bsize >> img1->x_chroma_shift;
@ -190,17 +189,21 @@ static void find_mismatch(const vpx_image_t *const img1,
} }
} }
static void testing_decode(vpx_codec_ctx_t *encoder, vpx_codec_ctx_t *decoder, static void testing_decode(vpx_codec_ctx_t *encoder,
unsigned int frame_out, int *mismatch_seen) { vpx_codec_ctx_t *decoder,
vpx_codec_enc_cfg_t *cfg,
unsigned int frame_out,
int *mismatch_seen) {
vpx_image_t enc_img, dec_img; vpx_image_t enc_img, dec_img;
struct vp9_ref_frame ref_enc, ref_dec; struct vp9_ref_frame ref_enc, ref_dec;
if (*mismatch_seen) return; if (*mismatch_seen)
return;
ref_enc.idx = 0; ref_enc.idx = 0;
ref_dec.idx = 0; ref_dec.idx = 0;
if (vpx_codec_control(encoder, VP9_GET_REFERENCE, &ref_enc)) if (vpx_codec_control(encoder, VP9_GET_REFERENCE, &ref_enc))
die_codec(encoder, "Failed to get encoder reference frame"); die_codec(encoder, "Failed to get encoder reference frame");
enc_img = ref_enc.img; enc_img = ref_enc.img;
if (vpx_codec_control(decoder, VP9_GET_REFERENCE, &ref_dec)) if (vpx_codec_control(decoder, VP9_GET_REFERENCE, &ref_dec))
die_codec(decoder, "Failed to get decoder reference frame"); die_codec(decoder, "Failed to get decoder reference frame");
@ -212,30 +215,37 @@ static void testing_decode(vpx_codec_ctx_t *encoder, vpx_codec_ctx_t *decoder,
*mismatch_seen = 1; *mismatch_seen = 1;
find_mismatch(&enc_img, &dec_img, y, u, v); find_mismatch(&enc_img, &dec_img, y, u, v);
printf( printf("Encode/decode mismatch on frame %d at"
"Encode/decode mismatch on frame %d at" " Y[%d, %d] {%d/%d},"
" Y[%d, %d] {%d/%d}," " U[%d, %d] {%d/%d},"
" U[%d, %d] {%d/%d}," " V[%d, %d] {%d/%d}",
" V[%d, %d] {%d/%d}", frame_out,
frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1], y[0], y[1], y[2], y[3],
v[2], v[3]); u[0], u[1], u[2], u[3],
v[0], v[1], v[2], v[3]);
} }
vpx_img_free(&enc_img); vpx_img_free(&enc_img);
vpx_img_free(&dec_img); vpx_img_free(&dec_img);
} }
static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_image_t *img, static int encode_frame(vpx_codec_ctx_t *ecodec,
unsigned int frame_in, VpxVideoWriter *writer, vpx_codec_enc_cfg_t *cfg,
int test_decode, vpx_codec_ctx_t *dcodec, vpx_image_t *img,
unsigned int *frame_out, int *mismatch_seen) { unsigned int frame_in,
VpxVideoWriter *writer,
int test_decode,
vpx_codec_ctx_t *dcodec,
unsigned int *frame_out,
int *mismatch_seen) {
int got_pkts = 0; int got_pkts = 0;
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL; const vpx_codec_cx_pkt_t *pkt = NULL;
int got_data; int got_data;
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(ecodec, img, frame_in, 1,
vpx_codec_encode(ecodec, img, frame_in, 1, 0, VPX_DL_GOOD_QUALITY); 0, VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK) die_codec(ecodec, "Failed to encode frame"); if (res != VPX_CODEC_OK)
die_codec(ecodec, "Failed to encode frame");
got_data = 0; got_data = 0;
@ -246,10 +256,11 @@ static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_image_t *img,
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) { if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
*frame_out += 1; *frame_out += 1;
} }
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf, if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz, pkt->data.frame.sz,
pkt->data.frame.pts)) { pkt->data.frame.pts)) {
die_codec(ecodec, "Failed to write compressed frame"); die_codec(ecodec, "Failed to write compressed frame");
@ -269,7 +280,7 @@ static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_image_t *img,
// Mismatch checking // Mismatch checking
if (got_data && test_decode) { if (got_data && test_decode) {
testing_decode(ecodec, dcodec, *frame_out, mismatch_seen); testing_decode(ecodec, dcodec, cfg, *frame_out, mismatch_seen);
} }
return got_pkts; return got_pkts;
@ -278,12 +289,12 @@ static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_image_t *img,
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *infile = NULL; FILE *infile = NULL;
// Encoder // Encoder
vpx_codec_ctx_t ecodec; vpx_codec_ctx_t ecodec = {0};
vpx_codec_enc_cfg_t cfg; vpx_codec_enc_cfg_t cfg = {0};
unsigned int frame_in = 0; unsigned int frame_in = 0;
vpx_image_t raw; vpx_image_t raw;
vpx_codec_err_t res; vpx_codec_err_t res;
VpxVideoInfo info; VpxVideoInfo info = {0};
VpxVideoWriter *writer = NULL; VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL; const VpxInterface *encoder = NULL;
@ -294,80 +305,69 @@ int main(int argc, char **argv) {
unsigned int frame_out = 0; unsigned int frame_out = 0;
// The frame number to set reference frame on // The frame number to set reference frame on
unsigned int update_frame_num = 0; int update_frame_num = 0;
int mismatch_seen = 0; int mismatch_seen = 0;
const int fps = 30; const int fps = 30;
const int bitrate = 500; const int bitrate = 500;
const char *codec_used = "vp9";
const char *width_arg = NULL; const char *width_arg = NULL;
const char *height_arg = NULL; const char *height_arg = NULL;
const char *infile_arg = NULL; const char *infile_arg = NULL;
const char *outfile_arg = NULL; const char *outfile_arg = NULL;
const char *update_frame_num_arg = NULL;
unsigned int limit = 0;
vp9_zero(ecodec);
vp9_zero(cfg);
vp9_zero(info);
exec_name = argv[0]; exec_name = argv[0];
if (argc < 6) die("Invalid number of arguments"); if (argc != 6)
die("Invalid number of arguments");
width_arg = argv[1]; width_arg = argv[1];
height_arg = argv[2]; height_arg = argv[2];
infile_arg = argv[3]; infile_arg = argv[3];
outfile_arg = argv[4]; outfile_arg = argv[4];
update_frame_num_arg = argv[5];
encoder = get_vpx_encoder_by_name("vp9"); encoder = get_vpx_encoder_by_name(codec_used);
if (!encoder) die("Unsupported codec."); if (!encoder)
die("Unsupported codec.");
update_frame_num = (unsigned int)strtoul(update_frame_num_arg, NULL, 0); update_frame_num = atoi(argv[5]);
// In VP9, the reference buffers (cm->buffer_pool->frame_bufs[i].buf) are if (update_frame_num <= 0)
// allocated while calling vpx_codec_encode(), thus, setting reference for die("Couldn't parse frame number '%s'\n", argv[5]);
// 1st frame isn't supported.
if (update_frame_num <= 1) {
die("Couldn't parse frame number '%s'\n", update_frame_num_arg);
}
if (argc > 6) {
limit = (unsigned int)strtoul(argv[6], NULL, 0);
if (update_frame_num > limit)
die("Update frame number couldn't larger than limit\n");
}
info.codec_fourcc = encoder->fourcc; info.codec_fourcc = encoder->fourcc;
info.frame_width = (int)strtol(width_arg, NULL, 0); info.frame_width = strtol(width_arg, NULL, 0);
info.frame_height = (int)strtol(height_arg, NULL, 0); info.frame_height = strtol(height_arg, NULL, 0);
info.time_base.numerator = 1; info.time_base.numerator = 1;
info.time_base.denominator = fps; info.time_base.denominator = fps;
if (info.frame_width <= 0 || info.frame_height <= 0 || if (info.frame_width <= 0 ||
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) { info.frame_height <= 0 ||
(info.frame_width % 2) != 0 ||
(info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
} }
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
info.frame_height, 1)) { info.frame_height, 1)) {
die("Failed to allocate image."); die("Failed to allocate image.");
} }
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) die_codec(&ecodec, "Failed to get default codec config."); if (res)
die_codec(&ecodec, "Failed to get default codec config.");
cfg.g_w = info.frame_width; cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height; cfg.g_h = info.frame_height;
cfg.g_timebase.num = info.time_base.numerator; cfg.g_timebase.num = info.time_base.numerator;
cfg.g_timebase.den = info.time_base.denominator; cfg.g_timebase.den = info.time_base.denominator;
cfg.rc_target_bitrate = bitrate; cfg.rc_target_bitrate = bitrate;
cfg.g_lag_in_frames = 3; cfg.g_lag_in_frames = 25;
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info); writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", outfile_arg); if (!writer)
die("Failed to open %s for writing.", outfile_arg);
if (!(infile = fopen(infile_arg, "rb"))) if (!(infile = fopen(infile_arg, "rb")))
die("Failed to open %s for reading.", infile_arg); die("Failed to open %s for reading.", infile_arg);
@ -380,14 +380,16 @@ int main(int argc, char **argv) {
die_codec(&ecodec, "Failed to set enable auto alt ref"); die_codec(&ecodec, "Failed to set enable auto alt ref");
if (test_decode) { if (test_decode) {
const VpxInterface *decoder = get_vpx_decoder_by_name("vp9"); const VpxInterface *decoder = get_vpx_decoder_by_name(codec_used);
if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0)) if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0))
die_codec(&dcodec, "Failed to initialize decoder."); die_codec(&dcodec, "Failed to initialize decoder.");
} }
// Encode frames. // Encode frames.
while (vpx_img_read(&raw, infile)) { while (vpx_img_read(&raw, infile)) {
if (limit && frame_in >= limit) break; // In VP9, the reference buffers (cm->frame_buffs[i].buf) are allocated
// while calling vpx_codec_encode(), thus, setting reference for 1st frame
// isn't supported.
if (update_frame_num > 1 && frame_out + 1 == update_frame_num) { if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
vpx_ref_frame_t ref; vpx_ref_frame_t ref;
ref.frame_type = VP8_LAST_FRAME; ref.frame_type = VP8_LAST_FRAME;
@ -395,7 +397,6 @@ int main(int argc, char **argv) {
// Set reference frame in encoder. // Set reference frame in encoder.
if (vpx_codec_control(&ecodec, VP8_SET_REFERENCE, &ref)) if (vpx_codec_control(&ecodec, VP8_SET_REFERENCE, &ref))
die_codec(&ecodec, "Failed to set reference frame"); die_codec(&ecodec, "Failed to set reference frame");
printf(" <SET_REF>");
// If set_reference in decoder is commented out, the enc/dec mismatch // If set_reference in decoder is commented out, the enc/dec mismatch
// would be seen. // would be seen.
@ -405,17 +406,17 @@ int main(int argc, char **argv) {
} }
} }
encode_frame(&ecodec, &raw, frame_in, writer, test_decode, &dcodec, encode_frame(&ecodec, &cfg, &raw, frame_in, writer, test_decode,
&frame_out, &mismatch_seen); &dcodec, &frame_out, &mismatch_seen);
frame_in++; frame_in++;
if (mismatch_seen) break; if (mismatch_seen)
break;
} }
// Flush encoder. // Flush encoder.
if (!mismatch_seen) if (!mismatch_seen)
while (encode_frame(&ecodec, NULL, frame_in, writer, test_decode, &dcodec, while (encode_frame(&ecodec, &cfg, NULL, frame_in, writer, test_decode,
&frame_out, &mismatch_seen)) { &dcodec, &frame_out, &mismatch_seen)) {};
}
printf("\n"); printf("\n");
fclose(infile); fclose(infile);

View File

@ -1,952 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This is an example demonstrating how to implement a multi-layer VPx
// encoding scheme based on temporal scalability for video applications
// that benefit from a scalable bitstream.
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "./vpx_config.h"
#include "../vpx_ports/vpx_timer.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
#include "vpx_ports/bitops.h"
#include "../tools_common.h"
#include "../video_writer.h"
#define ROI_MAP 0
#define zero(Dest) memset(&Dest, 0, sizeof(Dest));
static const char *exec_name;
void usage_exit(void) { exit(EXIT_FAILURE); }
// Denoiser states for vp8, for temporal denoising.
enum denoiserStateVp8 {
kVp8DenoiserOff,
kVp8DenoiserOnYOnly,
kVp8DenoiserOnYUV,
kVp8DenoiserOnYUVAggressive,
kVp8DenoiserOnAdaptive
};
// Denoiser states for vp9, for temporal denoising.
enum denoiserStateVp9 {
kVp9DenoiserOff,
kVp9DenoiserOnYOnly,
// For SVC: denoise the top two spatial layers.
kVp9DenoiserOnYTwoSpatialLayers
};
static int mode_to_num_layers[13] = { 1, 2, 2, 3, 3, 3, 3, 5, 2, 3, 3, 3, 3 };
// For rate control encoding stats.
struct RateControlMetrics {
// Number of input frames per layer.
int layer_input_frames[VPX_TS_MAX_LAYERS];
// Total (cumulative) number of encoded frames per layer.
int layer_tot_enc_frames[VPX_TS_MAX_LAYERS];
// Number of encoded non-key frames per layer.
int layer_enc_frames[VPX_TS_MAX_LAYERS];
// Framerate per layer layer (cumulative).
double layer_framerate[VPX_TS_MAX_LAYERS];
// Target average frame size per layer (per-frame-bandwidth per layer).
double layer_pfb[VPX_TS_MAX_LAYERS];
// Actual average frame size per layer.
double layer_avg_frame_size[VPX_TS_MAX_LAYERS];
// Average rate mismatch per layer (|target - actual| / target).
double layer_avg_rate_mismatch[VPX_TS_MAX_LAYERS];
// Actual encoding bitrate per layer (cumulative).
double layer_encoding_bitrate[VPX_TS_MAX_LAYERS];
// Average of the short-time encoder actual bitrate.
// TODO(marpan): Should we add these short-time stats for each layer?
double avg_st_encoding_bitrate;
// Variance of the short-time encoder actual bitrate.
double variance_st_encoding_bitrate;
// Window (number of frames) for computing short-timee encoding bitrate.
int window_size;
// Number of window measurements.
int window_count;
int layer_target_bitrate[VPX_MAX_LAYERS];
};
// Note: these rate control metrics assume only 1 key frame in the
// sequence (i.e., first frame only). So for temporal pattern# 7
// (which has key frame for every frame on base layer), the metrics
// computation will be off/wrong.
// TODO(marpan): Update these metrics to account for multiple key frames
// in the stream.
static void set_rate_control_metrics(struct RateControlMetrics *rc,
vpx_codec_enc_cfg_t *cfg) {
unsigned int i = 0;
// Set the layer (cumulative) framerate and the target layer (non-cumulative)
// per-frame-bandwidth, for the rate control encoding stats below.
const double framerate = cfg->g_timebase.den / cfg->g_timebase.num;
rc->layer_framerate[0] = framerate / cfg->ts_rate_decimator[0];
rc->layer_pfb[0] =
1000.0 * rc->layer_target_bitrate[0] / rc->layer_framerate[0];
for (i = 0; i < cfg->ts_number_layers; ++i) {
if (i > 0) {
rc->layer_framerate[i] = framerate / cfg->ts_rate_decimator[i];
rc->layer_pfb[i] =
1000.0 *
(rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
(rc->layer_framerate[i] - rc->layer_framerate[i - 1]);
}
rc->layer_input_frames[i] = 0;
rc->layer_enc_frames[i] = 0;
rc->layer_tot_enc_frames[i] = 0;
rc->layer_encoding_bitrate[i] = 0.0;
rc->layer_avg_frame_size[i] = 0.0;
rc->layer_avg_rate_mismatch[i] = 0.0;
}
rc->window_count = 0;
rc->window_size = 15;
rc->avg_st_encoding_bitrate = 0.0;
rc->variance_st_encoding_bitrate = 0.0;
}
static void printout_rate_control_summary(struct RateControlMetrics *rc,
vpx_codec_enc_cfg_t *cfg,
int frame_cnt) {
unsigned int i = 0;
int tot_num_frames = 0;
double perc_fluctuation = 0.0;
printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
printf("Rate control layer stats for %d layer(s):\n\n",
cfg->ts_number_layers);
for (i = 0; i < cfg->ts_number_layers; ++i) {
const int num_dropped =
(i > 0) ? (rc->layer_input_frames[i] - rc->layer_enc_frames[i])
: (rc->layer_input_frames[i] - rc->layer_enc_frames[i] - 1);
tot_num_frames += rc->layer_input_frames[i];
rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[i] *
rc->layer_encoding_bitrate[i] /
tot_num_frames;
rc->layer_avg_frame_size[i] =
rc->layer_avg_frame_size[i] / rc->layer_enc_frames[i];
rc->layer_avg_rate_mismatch[i] =
100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[i];
printf("For layer#: %d \n", i);
printf("Bitrate (target vs actual): %d %f \n", rc->layer_target_bitrate[i],
rc->layer_encoding_bitrate[i]);
printf("Average frame size (target vs actual): %f %f \n", rc->layer_pfb[i],
rc->layer_avg_frame_size[i]);
printf("Average rate_mismatch: %f \n", rc->layer_avg_rate_mismatch[i]);
printf(
"Number of input frames, encoded (non-key) frames, "
"and perc dropped frames: %d %d %f \n",
rc->layer_input_frames[i], rc->layer_enc_frames[i],
100.0 * num_dropped / rc->layer_input_frames[i]);
printf("\n");
}
rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
rc->variance_st_encoding_bitrate =
rc->variance_st_encoding_bitrate / rc->window_count -
(rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
rc->avg_st_encoding_bitrate;
printf("Short-time stats, for window of %d frames: \n", rc->window_size);
printf("Average, rms-variance, and percent-fluct: %f %f %f \n",
rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
perc_fluctuation);
if ((frame_cnt - 1) != tot_num_frames)
die("Error: Number of input frames not equal to output! \n");
}
#if ROI_MAP
static void set_roi_map(const char *enc_name, vpx_codec_enc_cfg_t *cfg,
vpx_roi_map_t *roi) {
unsigned int i, j;
int block_size = 0;
uint8_t is_vp8 = strncmp(enc_name, "vp8", 3) == 0 ? 1 : 0;
uint8_t is_vp9 = strncmp(enc_name, "vp9", 3) == 0 ? 1 : 0;
if (!is_vp8 && !is_vp9) {
die("unsupported codec.");
}
zero(*roi);
block_size = is_vp9 && !is_vp8 ? 8 : 16;
// ROI is based on the segments (4 for vp8, 8 for vp9), smallest unit for
// segment is 16x16 for vp8, 8x8 for vp9.
roi->rows = (cfg->g_h + block_size - 1) / block_size;
roi->cols = (cfg->g_w + block_size - 1) / block_size;
// Applies delta QP on the segment blocks, varies from -63 to 63.
// Setting to negative means lower QP (better quality).
// Below we set delta_q to the extreme (-63) to show strong effect.
// VP8 uses the first 4 segments. VP9 uses all 8 segments.
zero(roi->delta_q);
roi->delta_q[1] = -63;
// Applies delta loopfilter strength on the segment blocks, varies from -63 to
// 63. Setting to positive means stronger loopfilter. VP8 uses the first 4
// segments. VP9 uses all 8 segments.
zero(roi->delta_lf);
if (is_vp8) {
// Applies skip encoding threshold on the segment blocks, varies from 0 to
// UINT_MAX. Larger value means more skipping of encoding is possible.
// This skip threshold only applies on delta frames.
zero(roi->static_threshold);
}
if (is_vp9) {
// Apply skip segment. Setting to 1 means this block will be copied from
// previous frame.
zero(roi->skip);
}
if (is_vp9) {
// Apply ref frame segment.
// -1 : Do not apply this segment.
// 0 : Froce using intra.
// 1 : Force using last.
// 2 : Force using golden.
// 3 : Force using alfref but not used in non-rd pickmode for 0 lag.
memset(roi->ref_frame, -1, sizeof(roi->ref_frame));
roi->ref_frame[1] = 1;
}
// Use 2 states: 1 is center square, 0 is the rest.
roi->roi_map =
(uint8_t *)calloc(roi->rows * roi->cols, sizeof(*roi->roi_map));
for (i = 0; i < roi->rows; ++i) {
for (j = 0; j < roi->cols; ++j) {
if (i > (roi->rows >> 2) && i < ((roi->rows * 3) >> 2) &&
j > (roi->cols >> 2) && j < ((roi->cols * 3) >> 2)) {
roi->roi_map[i * roi->cols + j] = 1;
}
}
}
}
#endif
// Temporal scaling parameters:
// NOTE: The 3 prediction frames cannot be used interchangeably due to
// differences in the way they are handled throughout the code. The
// frames should be allocated to layers in the order LAST, GF, ARF.
// Other combinations work, but may produce slightly inferior results.
static void set_temporal_layer_pattern(int layering_mode,
vpx_codec_enc_cfg_t *cfg,
int *layer_flags,
int *flag_periodicity) {
switch (layering_mode) {
case 0: {
// 1-layer.
int ids[1] = { 0 };
cfg->ts_periodicity = 1;
*flag_periodicity = 1;
cfg->ts_number_layers = 1;
cfg->ts_rate_decimator[0] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// Update L only.
layer_flags[0] =
VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
break;
}
case 1: {
// 2-layers, 2-frame period.
int ids[2] = { 0, 1 };
cfg->ts_periodicity = 2;
*flag_periodicity = 2;
cfg->ts_number_layers = 2;
cfg->ts_rate_decimator[0] = 2;
cfg->ts_rate_decimator[1] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
#if 1
// 0=L, 1=GF, Intra-layer prediction enabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF;
layer_flags[1] =
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_REF_ARF;
#else
// 0=L, 1=GF, Intra-layer prediction disabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF;
layer_flags[1] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_LAST;
#endif
break;
}
case 2: {
// 2-layers, 3-frame period.
int ids[3] = { 0, 1, 1 };
cfg->ts_periodicity = 3;
*flag_periodicity = 3;
cfg->ts_number_layers = 2;
cfg->ts_rate_decimator[0] = 3;
cfg->ts_rate_decimator[1] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, Intra-layer prediction enabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[1] = layer_flags[2] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF |
VP8_EFLAG_NO_UPD_LAST;
break;
}
case 3: {
// 3-layers, 6-frame period.
int ids[6] = { 0, 2, 2, 1, 2, 2 };
cfg->ts_periodicity = 6;
*flag_periodicity = 6;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 6;
cfg->ts_rate_decimator[1] = 3;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[3] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
layer_flags[1] = layer_flags[2] = layer_flags[4] = layer_flags[5] =
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST;
break;
}
case 4: {
// 3-layers, 4-frame period.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
layer_flags[1] = layer_flags[3] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
break;
}
case 5: {
// 3-layers, 4-frame period.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled in layer 1, disabled
// in layer 2.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[1] = layer_flags[3] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
break;
}
case 6: {
// 3-layers, 4-frame period.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[1] = layer_flags[3] =
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
break;
}
case 7: {
// NOTE: Probably of academic interest only.
// 5-layers, 16-frame period.
int ids[16] = { 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4 };
cfg->ts_periodicity = 16;
*flag_periodicity = 16;
cfg->ts_number_layers = 5;
cfg->ts_rate_decimator[0] = 16;
cfg->ts_rate_decimator[1] = 8;
cfg->ts_rate_decimator[2] = 4;
cfg->ts_rate_decimator[3] = 2;
cfg->ts_rate_decimator[4] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
layer_flags[0] = VPX_EFLAG_FORCE_KF;
layer_flags[1] = layer_flags[3] = layer_flags[5] = layer_flags[7] =
layer_flags[9] = layer_flags[11] = layer_flags[13] = layer_flags[15] =
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] = layer_flags[6] = layer_flags[10] = layer_flags[14] =
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF;
layer_flags[4] = layer_flags[12] =
VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[8] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF;
break;
}
case 8: {
// 2-layers, with sync point at first frame of layer 1.
int ids[2] = { 0, 1 };
cfg->ts_periodicity = 2;
*flag_periodicity = 8;
cfg->ts_number_layers = 2;
cfg->ts_rate_decimator[0] = 2;
cfg->ts_rate_decimator[1] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF.
// ARF is used as predictor for all frames, and is only updated on
// key frame. Sync point every 8 frames.
// Layer 0: predict from L and ARF, update L and G.
layer_flags[0] =
VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: sync point: predict from L and ARF, and update G.
layer_flags[1] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
// Layer 0, predict from L and ARF, update L.
layer_flags[2] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: predict from L, G and ARF, and update G.
layer_flags[3] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0.
layer_flags[4] = layer_flags[2];
// Layer 1.
layer_flags[5] = layer_flags[3];
// Layer 0.
layer_flags[6] = layer_flags[4];
// Layer 1.
layer_flags[7] = layer_flags[5];
break;
}
case 9: {
// 3-layers: Sync points for layer 1 and 2 every 8 frames.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[3] = layer_flags[5] =
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
layer_flags[4] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
layer_flags[6] =
VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[7] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_ENTROPY;
break;
}
case 10: {
// 3-layers structure where ARF is used as predictor for all frames,
// and is only updated on key frame.
// Sync points for layer 1 and 2 every 8 frames.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
// Layer 0: predict from L and ARF; update L and G.
layer_flags[0] =
VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: sync point: predict from L and ARF; update none.
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 1: sync point: predict from L and ARF; update G.
layer_flags[2] =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[3] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0: predict from L and ARF; update L.
layer_flags[4] =
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[5] = layer_flags[3];
// Layer 1: predict from L, G, ARF; update G.
layer_flags[6] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[7] = layer_flags[3];
break;
}
case 11: {
// 3-layers structure with one reference frame.
// This works same as temporal_layering_mode 3.
// This was added to compare with vp9_spatial_svc_encoder.
// 3-layers, 4-frame period.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
layer_flags[0] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
layer_flags[3] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
break;
}
case 12:
default: {
// 3-layers structure as in case 10, but no sync/refresh points for
// layer 1 and 2.
int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
// Layer 0: predict from L and ARF; update L.
layer_flags[0] =
VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
layer_flags[4] = layer_flags[0];
// Layer 1: predict from L, G, ARF; update G.
layer_flags[2] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
layer_flags[6] = layer_flags[2];
// Layer 2: predict from L, G, ARF; update none.
layer_flags[1] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
layer_flags[3] = layer_flags[1];
layer_flags[5] = layer_flags[1];
layer_flags[7] = layer_flags[1];
break;
}
}
}
int main(int argc, char **argv) {
VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = { NULL };
vpx_codec_ctx_t codec;
vpx_codec_enc_cfg_t cfg;
int frame_cnt = 0;
vpx_image_t raw;
vpx_codec_err_t res;
unsigned int width;
unsigned int height;
uint32_t error_resilient = 0;
int speed;
int frame_avail;
int got_data;
int flags = 0;
unsigned int i;
int pts = 0; // PTS starts at 0.
int frame_duration = 1; // 1 timebase tick per frame.
int layering_mode = 0;
int layer_flags[VPX_TS_MAX_PERIODICITY] = { 0 };
int flag_periodicity = 1;
#if ROI_MAP
vpx_roi_map_t roi;
#endif
vpx_svc_layer_id_t layer_id = { 0, 0 };
const VpxInterface *encoder = NULL;
FILE *infile = NULL;
struct RateControlMetrics rc;
int64_t cx_time = 0;
const int min_args_base = 13;
#if CONFIG_VP9_HIGHBITDEPTH
vpx_bit_depth_t bit_depth = VPX_BITS_8;
int input_bit_depth = 8;
const int min_args = min_args_base + 1;
#else
const int min_args = min_args_base;
#endif // CONFIG_VP9_HIGHBITDEPTH
double sum_bitrate = 0.0;
double sum_bitrate2 = 0.0;
double framerate = 30.0;
zero(rc.layer_target_bitrate);
exec_name = argv[0];
// Check usage and arguments.
if (argc < min_args) {
#if CONFIG_VP9_HIGHBITDEPTH
die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
"<rate_num> <rate_den> <speed> <frame_drop_threshold> "
"<error_resilient> <threads> <mode> "
"<Rate_0> ... <Rate_nlayers-1> <bit-depth> \n",
argv[0]);
#else
die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
"<rate_num> <rate_den> <speed> <frame_drop_threshold> "
"<error_resilient> <threads> <mode> "
"<Rate_0> ... <Rate_nlayers-1> \n",
argv[0]);
#endif // CONFIG_VP9_HIGHBITDEPTH
}
encoder = get_vpx_encoder_by_name(argv[3]);
if (!encoder) die("Unsupported codec.");
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
width = (unsigned int)strtoul(argv[4], NULL, 0);
height = (unsigned int)strtoul(argv[5], NULL, 0);
if (width < 16 || width % 2 || height < 16 || height % 2) {
die("Invalid resolution: %d x %d", width, height);
}
layering_mode = (int)strtol(argv[12], NULL, 0);
if (layering_mode < 0 || layering_mode > 13) {
die("Invalid layering mode (0..12) %s", argv[12]);
}
if (argc != min_args + mode_to_num_layers[layering_mode]) {
die("Invalid number of arguments");
}
#if CONFIG_VP9_HIGHBITDEPTH
switch (strtol(argv[argc - 1], NULL, 0)) {
case 8:
bit_depth = VPX_BITS_8;
input_bit_depth = 8;
break;
case 10:
bit_depth = VPX_BITS_10;
input_bit_depth = 10;
break;
case 12:
bit_depth = VPX_BITS_12;
input_bit_depth = 12;
break;
default: die("Invalid bit depth (8, 10, 12) %s", argv[argc - 1]);
}
if (!vpx_img_alloc(
&raw, bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
width, height, 32)) {
die("Failed to allocate image", width, height);
}
#else
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
die("Failed to allocate image", width, height);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
// Populate encoder configuration.
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
if (res) {
printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
return EXIT_FAILURE;
}
// Update the default configuration with our settings.
cfg.g_w = width;
cfg.g_h = height;
#if CONFIG_VP9_HIGHBITDEPTH
if (bit_depth != VPX_BITS_8) {
cfg.g_bit_depth = bit_depth;
cfg.g_input_bit_depth = input_bit_depth;
cfg.g_profile = 2;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
// Timebase format e.g. 30fps: numerator=1, demoninator = 30.
cfg.g_timebase.num = (int)strtol(argv[6], NULL, 0);
cfg.g_timebase.den = (int)strtol(argv[7], NULL, 0);
speed = (int)strtol(argv[8], NULL, 0);
if (speed < 0) {
die("Invalid speed setting: must be positive");
}
for (i = min_args_base;
(int)i < min_args_base + mode_to_num_layers[layering_mode]; ++i) {
rc.layer_target_bitrate[i - 13] = (int)strtol(argv[i], NULL, 0);
if (strncmp(encoder->name, "vp8", 3) == 0)
cfg.ts_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
else if (strncmp(encoder->name, "vp9", 3) == 0)
cfg.layer_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
}
// Real time parameters.
cfg.rc_dropframe_thresh = (unsigned int)strtoul(argv[9], NULL, 0);
cfg.rc_end_usage = VPX_CBR;
cfg.rc_min_quantizer = 2;
cfg.rc_max_quantizer = 56;
if (strncmp(encoder->name, "vp9", 3) == 0) cfg.rc_max_quantizer = 52;
cfg.rc_undershoot_pct = 50;
cfg.rc_overshoot_pct = 50;
cfg.rc_buf_initial_sz = 600;
cfg.rc_buf_optimal_sz = 600;
cfg.rc_buf_sz = 1000;
// Disable dynamic resizing by default.
cfg.rc_resize_allowed = 0;
// Use 1 thread as default.
cfg.g_threads = (unsigned int)strtoul(argv[11], NULL, 0);
error_resilient = (uint32_t)strtoul(argv[10], NULL, 0);
if (error_resilient != 0 && error_resilient != 1) {
die("Invalid value for error resilient (0, 1): %d.", error_resilient);
}
// Enable error resilient mode.
cfg.g_error_resilient = error_resilient;
cfg.g_lag_in_frames = 0;
cfg.kf_mode = VPX_KF_AUTO;
// Disable automatic keyframe placement.
cfg.kf_min_dist = cfg.kf_max_dist = 3000;
cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
set_temporal_layer_pattern(layering_mode, &cfg, layer_flags,
&flag_periodicity);
set_rate_control_metrics(&rc, &cfg);
// Target bandwidth for the whole stream.
// Set to layer_target_bitrate for highest layer (total bitrate).
cfg.rc_target_bitrate = rc.layer_target_bitrate[cfg.ts_number_layers - 1];
// Open input file.
if (!(infile = fopen(argv[1], "rb"))) {
die("Failed to open %s for reading", argv[1]);
}
framerate = cfg.g_timebase.den / cfg.g_timebase.num;
// Open an output file for each stream.
for (i = 0; i < cfg.ts_number_layers; ++i) {
char file_name[PATH_MAX];
VpxVideoInfo info;
info.codec_fourcc = encoder->fourcc;
info.frame_width = cfg.g_w;
info.frame_height = cfg.g_h;
info.time_base.numerator = cfg.g_timebase.num;
info.time_base.denominator = cfg.g_timebase.den;
snprintf(file_name, sizeof(file_name), "%s_%d.ivf", argv[2], i);
outfile[i] = vpx_video_writer_open(file_name, kContainerIVF, &info);
if (!outfile[i]) die("Failed to open %s for writing", file_name);
assert(outfile[i] != NULL);
}
// No spatial layers in this encoder.
cfg.ss_number_layers = 1;
// Initialize codec.
#if CONFIG_VP9_HIGHBITDEPTH
if (vpx_codec_enc_init(
&codec, encoder->codec_interface(), &cfg,
bit_depth == VPX_BITS_8 ? 0 : VPX_CODEC_USE_HIGHBITDEPTH))
#else
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
#endif // CONFIG_VP9_HIGHBITDEPTH
die_codec(&codec, "Failed to initialize encoder");
if (strncmp(encoder->name, "vp8", 3) == 0) {
vpx_codec_control(&codec, VP8E_SET_CPUUSED, -speed);
vpx_codec_control(&codec, VP8E_SET_NOISE_SENSITIVITY, kVp8DenoiserOff);
vpx_codec_control(&codec, VP8E_SET_STATIC_THRESHOLD, 1);
vpx_codec_control(&codec, VP8E_SET_GF_CBR_BOOST_PCT, 0);
#if ROI_MAP
set_roi_map(encoder->name, &cfg, &roi);
if (vpx_codec_control(&codec, VP8E_SET_ROI_MAP, &roi))
die_codec(&codec, "Failed to set ROI map");
#endif
} else if (strncmp(encoder->name, "vp9", 3) == 0) {
vpx_svc_extra_cfg_t svc_params;
memset(&svc_params, 0, sizeof(svc_params));
vpx_codec_control(&codec, VP8E_SET_CPUUSED, speed);
vpx_codec_control(&codec, VP9E_SET_AQ_MODE, 3);
vpx_codec_control(&codec, VP9E_SET_GF_CBR_BOOST_PCT, 0);
vpx_codec_control(&codec, VP9E_SET_FRAME_PARALLEL_DECODING, 0);
vpx_codec_control(&codec, VP9E_SET_FRAME_PERIODIC_BOOST, 0);
vpx_codec_control(&codec, VP9E_SET_NOISE_SENSITIVITY, kVp9DenoiserOff);
vpx_codec_control(&codec, VP8E_SET_STATIC_THRESHOLD, 1);
vpx_codec_control(&codec, VP9E_SET_TUNE_CONTENT, 0);
vpx_codec_control(&codec, VP9E_SET_TILE_COLUMNS, get_msb(cfg.g_threads));
#if ROI_MAP
set_roi_map(encoder->name, &cfg, &roi);
if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi))
die_codec(&codec, "Failed to set ROI map");
vpx_codec_control(&codec, VP9E_SET_AQ_MODE, 0);
#endif
// TODO(marpan/jianj): There is an issue with row-mt for low resolutons at
// high speed settings, disable its use for those cases for now.
if (cfg.g_threads > 1 && ((cfg.g_w > 320 && cfg.g_h > 240) || speed < 7))
vpx_codec_control(&codec, VP9E_SET_ROW_MT, 1);
else
vpx_codec_control(&codec, VP9E_SET_ROW_MT, 0);
if (vpx_codec_control(&codec, VP9E_SET_SVC, layering_mode > 0 ? 1 : 0))
die_codec(&codec, "Failed to set SVC");
for (i = 0; i < cfg.ts_number_layers; ++i) {
svc_params.max_quantizers[i] = cfg.rc_max_quantizer;
svc_params.min_quantizers[i] = cfg.rc_min_quantizer;
}
svc_params.scaling_factor_num[0] = cfg.g_h;
svc_params.scaling_factor_den[0] = cfg.g_h;
vpx_codec_control(&codec, VP9E_SET_SVC_PARAMETERS, &svc_params);
}
if (strncmp(encoder->name, "vp8", 3) == 0) {
vpx_codec_control(&codec, VP8E_SET_SCREEN_CONTENT_MODE, 0);
}
vpx_codec_control(&codec, VP8E_SET_TOKEN_PARTITIONS, 1);
// This controls the maximum target size of the key frame.
// For generating smaller key frames, use a smaller max_intra_size_pct
// value, like 100 or 200.
{
const int max_intra_size_pct = 1000;
vpx_codec_control(&codec, VP8E_SET_MAX_INTRA_BITRATE_PCT,
max_intra_size_pct);
}
frame_avail = 1;
while (frame_avail || got_data) {
struct vpx_usec_timer timer;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt;
// Update the temporal layer_id. No spatial layers in this test.
layer_id.spatial_layer_id = 0;
layer_id.temporal_layer_id =
cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
if (strncmp(encoder->name, "vp9", 3) == 0) {
vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id);
} else if (strncmp(encoder->name, "vp8", 3) == 0) {
vpx_codec_control(&codec, VP8E_SET_TEMPORAL_LAYER_ID,
layer_id.temporal_layer_id);
}
flags = layer_flags[frame_cnt % flag_periodicity];
if (layering_mode == 0) flags = 0;
frame_avail = vpx_img_read(&raw, infile);
if (frame_avail) ++rc.layer_input_frames[layer_id.temporal_layer_id];
vpx_usec_timer_start(&timer);
if (vpx_codec_encode(&codec, frame_avail ? &raw : NULL, pts, 1, flags,
VPX_DL_REALTIME)) {
die_codec(&codec, "Failed to encode frame");
}
vpx_usec_timer_mark(&timer);
cx_time += vpx_usec_timer_elapsed(&timer);
// Reset KF flag.
if (layering_mode != 7) {
layer_flags[0] &= ~VPX_EFLAG_FORCE_KF;
}
got_data = 0;
while ((pkt = vpx_codec_get_cx_data(&codec, &iter))) {
got_data = 1;
switch (pkt->kind) {
case VPX_CODEC_CX_FRAME_PKT:
for (i = cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
i < cfg.ts_number_layers; ++i) {
vpx_video_writer_write_frame(outfile[i], pkt->data.frame.buf,
pkt->data.frame.sz, pts);
++rc.layer_tot_enc_frames[i];
rc.layer_encoding_bitrate[i] += 8.0 * pkt->data.frame.sz;
// Keep count of rate control stats per layer (for non-key frames).
if (i == cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity] &&
!(pkt->data.frame.flags & VPX_FRAME_IS_KEY)) {
rc.layer_avg_frame_size[i] += 8.0 * pkt->data.frame.sz;
rc.layer_avg_rate_mismatch[i] +=
fabs(8.0 * pkt->data.frame.sz - rc.layer_pfb[i]) /
rc.layer_pfb[i];
++rc.layer_enc_frames[i];
}
}
// Update for short-time encoding bitrate states, for moving window
// of size rc->window, shifted by rc->window / 2.
// Ignore first window segment, due to key frame.
if (frame_cnt > rc.window_size) {
sum_bitrate += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
if (frame_cnt % rc.window_size == 0) {
rc.window_count += 1;
rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
rc.variance_st_encoding_bitrate +=
(sum_bitrate / rc.window_size) *
(sum_bitrate / rc.window_size);
sum_bitrate = 0.0;
}
}
// Second shifted window.
if (frame_cnt > rc.window_size + rc.window_size / 2) {
sum_bitrate2 += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
if (frame_cnt > 2 * rc.window_size &&
frame_cnt % rc.window_size == 0) {
rc.window_count += 1;
rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
rc.variance_st_encoding_bitrate +=
(sum_bitrate2 / rc.window_size) *
(sum_bitrate2 / rc.window_size);
sum_bitrate2 = 0.0;
}
}
break;
default: break;
}
}
++frame_cnt;
pts += frame_duration;
}
fclose(infile);
printout_rate_control_summary(&rc, &cfg, frame_cnt);
printf("\n");
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
// Try to rewrite the output file headers with the actual frame count.
for (i = 0; i < cfg.ts_number_layers; ++i) vpx_video_writer_close(outfile[i]);
vpx_img_free(&raw);
#if ROI_MAP
free(roi.roi_map);
#endif
return EXIT_SUCCESS;
}

View File

@ -23,7 +23,7 @@ static void fix_framerate(int *num, int *den) {
// we can guess the framerate using only the timebase in this // we can guess the framerate using only the timebase in this
// case. Other files would require reading ahead to guess the // case. Other files would require reading ahead to guess the
// timebase, like we do for webm. // timebase, like we do for webm.
if (*den > 0 && *den < 1000000000 && *num > 0 && *num < 1000) { if (*num < 1000) {
// Correct for the factor of 2 applied to the timebase in the encoder. // Correct for the factor of 2 applied to the timebase in the encoder.
if (*num & 1) if (*num & 1)
*den *= 2; *den *= 2;
@ -46,8 +46,7 @@ int file_is_ivf(struct VpxInputContext *input_ctx) {
is_ivf = 1; is_ivf = 1;
if (mem_get_le16(raw_hdr + 4) != 0) { if (mem_get_le16(raw_hdr + 4) != 0) {
fprintf(stderr, fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
"Error: Unrecognized IVF version! This file may not"
" decode properly."); " decode properly.");
} }
@ -70,13 +69,14 @@ int file_is_ivf(struct VpxInputContext *input_ctx) {
return is_ivf; return is_ivf;
} }
int ivf_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, int ivf_read_frame(FILE *infile, uint8_t **buffer,
size_t *buffer_size) { size_t *bytes_read, size_t *buffer_size) {
char raw_header[IVF_FRAME_HDR_SZ] = { 0 }; char raw_header[IVF_FRAME_HDR_SZ] = {0};
size_t frame_size = 0; size_t frame_size = 0;
if (fread(raw_header, IVF_FRAME_HDR_SZ, 1, infile) != 1) { if (fread(raw_header, IVF_FRAME_HDR_SZ, 1, infile) != 1) {
if (!feof(infile)) warn("Failed to read frame size\n"); if (!feof(infile))
warn("Failed to read frame size\n");
} else { } else {
frame_size = mem_get_le32(raw_header); frame_size = mem_get_le32(raw_header);

View File

@ -18,11 +18,11 @@ extern "C" {
int file_is_ivf(struct VpxInputContext *input); int file_is_ivf(struct VpxInputContext *input);
int ivf_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, int ivf_read_frame(FILE *infile, uint8_t **buffer,
size_t *buffer_size); size_t *bytes_read, size_t *buffer_size);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif // IVFDEC_H_ #endif // IVFDEC_H_

View File

@ -13,8 +13,10 @@
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "vpx_ports/mem_ops.h" #include "vpx_ports/mem_ops.h"
void ivf_write_file_header(FILE *outfile, const struct vpx_codec_enc_cfg *cfg, void ivf_write_file_header(FILE *outfile,
unsigned int fourcc, int frame_cnt) { const struct vpx_codec_enc_cfg *cfg,
unsigned int fourcc,
int frame_cnt) {
char header[32]; char header[32];
header[0] = 'D'; header[0] = 'D';

View File

@ -19,15 +19,17 @@ struct vpx_codec_cx_pkt;
extern "C" { extern "C" {
#endif #endif
void ivf_write_file_header(FILE *outfile, const struct vpx_codec_enc_cfg *cfg, void ivf_write_file_header(FILE *outfile,
uint32_t fourcc, int frame_cnt); const struct vpx_codec_enc_cfg *cfg,
uint32_t fourcc,
int frame_cnt);
void ivf_write_frame_header(FILE *outfile, int64_t pts, size_t frame_size); void ivf_write_frame_header(FILE *outfile, int64_t pts, size_t frame_size);
void ivf_write_frame_size(FILE *outfile, size_t frame_size); void ivf_write_frame_size(FILE *outfile, size_t frame_size);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif // IVFENC_H_ #endif // IVFENC_H_

View File

@ -36,7 +36,7 @@ DOXYFILE_ENCODING = UTF-8
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded # The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project. # by quotes) that should identify the project.
PROJECT_NAME = "WebM Codec SDK" PROJECT_NAME = "WebM VP8 Codec SDK"
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put. # base path where the generated documentation will be put.
@ -943,6 +943,18 @@ GENERATE_XML = NO
XML_OUTPUT = xml XML_OUTPUT = xml
# The XML_SCHEMA tag can be used to specify an XML schema,
# which can be used by a validating XML parser to check the
# syntax of the XML files.
XML_SCHEMA =
# The XML_DTD tag can be used to specify an XML DTD,
# which can be used by a validating XML parser to check the
# syntax of the XML files.
XML_DTD =
# If the XML_PROGRAMLISTING tag is set to YES Doxygen will # If the XML_PROGRAMLISTING tag is set to YES Doxygen will
# dump the program listings (including syntax highlighting # dump the program listings (including syntax highlighting
# and cross-referencing information) to the XML output. Note that # and cross-referencing information) to the XML output. Note that

320
libs.mk
View File

@ -12,11 +12,37 @@
# ARM assembly files are written in RVCT-style. We use some make magic to # ARM assembly files are written in RVCT-style. We use some make magic to
# filter those files to allow GCC compilation # filter those files to allow GCC compilation
ifeq ($(ARCH_ARM),yes) ifeq ($(ARCH_ARM),yes)
ASM:=$(if $(filter yes,$(CONFIG_GCC)$(CONFIG_MSVS)),.asm.S,.asm) ASM:=$(if $(filter yes,$(CONFIG_GCC)$(CONFIG_MSVS)),.asm.s,.asm)
else else
ASM:=.asm ASM:=.asm
endif endif
#
# Calculate platform- and compiler-specific offsets for hand coded assembly
#
ifeq ($(filter icc gcc,$(TGT_CC)), $(TGT_CC))
OFFSET_PATTERN:='^[a-zA-Z0-9_]* EQU'
define asm_offsets_template
$$(BUILD_PFX)$(1): $$(BUILD_PFX)$(2).S
@echo " [CREATE] $$@"
$$(qexec)LC_ALL=C grep $$(OFFSET_PATTERN) $$< | tr -d '$$$$\#' $$(ADS2GAS) > $$@
$$(BUILD_PFX)$(2).S: $(2)
CLEAN-OBJS += $$(BUILD_PFX)$(1) $(2).S
endef
else
ifeq ($(filter rvct,$(TGT_CC)), $(TGT_CC))
define asm_offsets_template
$$(BUILD_PFX)$(1): obj_int_extract
$$(BUILD_PFX)$(1): $$(BUILD_PFX)$(2).o
@echo " [CREATE] $$@"
$$(qexec)./obj_int_extract rvds $$< $$(ADS2GAS) > $$@
OBJS-yes += $$(BUILD_PFX)$(2).o
CLEAN-OBJS += $$(BUILD_PFX)$(1)
$$(filter %$$(ASM).o,$$(OBJS-yes)): $$(BUILD_PFX)$(1)
endef
endif # rvct
endif # !gcc
# #
# Rule to generate runtime cpu detection files # Rule to generate runtime cpu detection files
# #
@ -25,7 +51,7 @@ $$(BUILD_PFX)$(1).h: $$(SRC_PATH_BARE)/$(2)
@echo " [CREATE] $$@" @echo " [CREATE] $$@"
$$(qexec)$$(SRC_PATH_BARE)/build/make/rtcd.pl --arch=$$(TGT_ISA) \ $$(qexec)$$(SRC_PATH_BARE)/build/make/rtcd.pl --arch=$$(TGT_ISA) \
--sym=$(1) \ --sym=$(1) \
--config=$$(CONFIG_DIR)$$(target)-$$(TOOLCHAIN).mk \ --config=$$(CONFIG_DIR)$$(target)$$(if $$(FAT_ARCHS),,-$$(TOOLCHAIN)).mk \
$$(RTCD_OPTIONS) $$^ > $$@ $$(RTCD_OPTIONS) $$^ > $$@
CLEAN-OBJS += $$(BUILD_PFX)$(1).h CLEAN-OBJS += $$(BUILD_PFX)$(1).h
RTCD += $$(BUILD_PFX)$(1).h RTCD += $$(BUILD_PFX)$(1).h
@ -34,6 +60,13 @@ endef
CODEC_SRCS-yes += CHANGELOG CODEC_SRCS-yes += CHANGELOG
CODEC_SRCS-yes += libs.mk CODEC_SRCS-yes += libs.mk
# If this is a universal (fat) binary, then all the subarchitectures have
# already been built and our job is to stitch them together. The
# BUILD_LIBVPX variable indicates whether we should be building
# (compiling, linking) the library. The LIPO_LIBVPX variable indicates
# that we're stitching.
$(eval $(if $(filter universal%,$(TOOLCHAIN)),LIPO_LIBVPX,BUILD_LIBVPX):=yes)
include $(SRC_PATH_BARE)/vpx/vpx_codec.mk include $(SRC_PATH_BARE)/vpx/vpx_codec.mk
CODEC_SRCS-yes += $(addprefix vpx/,$(call enabled,API_SRCS)) CODEC_SRCS-yes += $(addprefix vpx/,$(call enabled,API_SRCS))
CODEC_DOC_SRCS += $(addprefix vpx/,$(call enabled,API_DOC_SRCS)) CODEC_DOC_SRCS += $(addprefix vpx/,$(call enabled,API_DOC_SRCS))
@ -47,13 +80,7 @@ CODEC_SRCS-yes += $(addprefix vpx_scale/,$(call enabled,SCALE_SRCS))
include $(SRC_PATH_BARE)/vpx_ports/vpx_ports.mk include $(SRC_PATH_BARE)/vpx_ports/vpx_ports.mk
CODEC_SRCS-yes += $(addprefix vpx_ports/,$(call enabled,PORTS_SRCS)) CODEC_SRCS-yes += $(addprefix vpx_ports/,$(call enabled,PORTS_SRCS))
include $(SRC_PATH_BARE)/vpx_dsp/vpx_dsp.mk ifneq ($(CONFIG_VP8_ENCODER)$(CONFIG_VP8_DECODER),)
CODEC_SRCS-yes += $(addprefix vpx_dsp/,$(call enabled,DSP_SRCS))
include $(SRC_PATH_BARE)/vpx_util/vpx_util.mk
CODEC_SRCS-yes += $(addprefix vpx_util/,$(call enabled,UTIL_SRCS))
ifeq ($(CONFIG_VP8),yes)
VP8_PREFIX=vp8/ VP8_PREFIX=vp8/
include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk
endif endif
@ -76,7 +103,7 @@ ifeq ($(CONFIG_VP8_DECODER),yes)
CODEC_DOC_SECTIONS += vp8 vp8_decoder CODEC_DOC_SECTIONS += vp8 vp8_decoder
endif endif
ifeq ($(CONFIG_VP9),yes) ifneq ($(CONFIG_VP9_ENCODER)$(CONFIG_VP9_DECODER),)
VP9_PREFIX=vp9/ VP9_PREFIX=vp9/
include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9_common.mk include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9_common.mk
endif endif
@ -88,7 +115,6 @@ ifeq ($(CONFIG_VP9_ENCODER),yes)
CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_CX_EXPORTS)) CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_CX_EXPORTS))
CODEC_SRCS-yes += $(VP9_PREFIX)vp9cx.mk vpx/vp8.h vpx/vp8cx.h CODEC_SRCS-yes += $(VP9_PREFIX)vp9cx.mk vpx/vp8.h vpx/vp8cx.h
INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
INSTALL-LIBS-yes += include/vpx/svc_context.h
INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/% INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/%
CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8cx.h CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8cx.h
CODEC_DOC_SECTIONS += vp9 vp9_encoder CODEC_DOC_SECTIONS += vp9 vp9_encoder
@ -106,6 +132,9 @@ ifeq ($(CONFIG_VP9_DECODER),yes)
CODEC_DOC_SECTIONS += vp9 vp9_decoder CODEC_DOC_SECTIONS += vp9 vp9_decoder
endif endif
VP9_PREFIX=vp9/
$(BUILD_PFX)$(VP9_PREFIX)%.c.o: CFLAGS += -Wextra
ifeq ($(CONFIG_ENCODERS),yes) ifeq ($(CONFIG_ENCODERS),yes)
CODEC_DOC_SECTIONS += encoder CODEC_DOC_SECTIONS += encoder
endif endif
@ -113,12 +142,6 @@ ifeq ($(CONFIG_DECODERS),yes)
CODEC_DOC_SECTIONS += decoder CODEC_DOC_SECTIONS += decoder
endif endif
# Suppress -Wextra warnings in third party code.
$(BUILD_PFX)third_party/googletest/%.cc.o: CXXFLAGS += -Wno-missing-field-initializers
# Suppress -Wextra warnings in first party code pending investigation.
# https://bugs.chromium.org/p/webm/issues/detail?id=1069
$(BUILD_PFX)vp8/encoder/onyx_if.c.o: CFLAGS += -Wno-unknown-warning-option -Wno-clobbered
$(BUILD_PFX)vp8/decoder/onyxd_if.c.o: CFLAGS += -Wno-unknown-warning-option -Wno-clobbered
ifeq ($(CONFIG_MSVS),yes) ifeq ($(CONFIG_MSVS),yes)
CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),vpxmt,vpxmd) CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),vpxmt,vpxmd)
@ -139,21 +162,19 @@ INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/% $(p)/Release/%)
INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/% $(p)/Debug/%) INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/% $(p)/Debug/%)
endif endif
CODEC_SRCS-yes += build/make/version.sh CODEC_SRCS-$(BUILD_LIBVPX) += build/make/version.sh
CODEC_SRCS-yes += build/make/rtcd.pl CODEC_SRCS-$(BUILD_LIBVPX) += build/make/rtcd.pl
CODEC_SRCS-yes += vpx_ports/emmintrin_compat.h CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/emmintrin_compat.h
CODEC_SRCS-yes += vpx_ports/mem_ops.h CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/mem_ops.h
CODEC_SRCS-yes += vpx_ports/mem_ops_aligned.h CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/mem_ops_aligned.h
CODEC_SRCS-yes += vpx_ports/vpx_once.h CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/vpx_once.h
CODEC_SRCS-yes += $(BUILD_PFX)vpx_config.c CODEC_SRCS-$(BUILD_LIBVPX) += $(BUILD_PFX)vpx_config.c
INSTALL-SRCS-no += $(BUILD_PFX)vpx_config.c INSTALL-SRCS-no += $(BUILD_PFX)vpx_config.c
ifeq ($(ARCH_X86)$(ARCH_X86_64),yes) ifeq ($(ARCH_X86)$(ARCH_X86_64),yes)
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += third_party/x86inc/x86inc.asm INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += third_party/x86inc/x86inc.asm
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += vpx_dsp/x86/bitdepth_conversion_sse2.asm
endif endif
CODEC_EXPORTS-yes += vpx/exports_com CODEC_EXPORTS-$(BUILD_LIBVPX) += vpx/exports_com
CODEC_EXPORTS-$(CONFIG_ENCODERS) += vpx/exports_enc CODEC_EXPORTS-$(CONFIG_ENCODERS) += vpx/exports_enc
CODEC_EXPORTS-$(CONFIG_VP9_ENCODER) += vpx/exports_spatial_svc
CODEC_EXPORTS-$(CONFIG_DECODERS) += vpx/exports_dec CODEC_EXPORTS-$(CONFIG_DECODERS) += vpx/exports_dec
INSTALL-LIBS-yes += include/vpx/vpx_codec.h INSTALL-LIBS-yes += include/vpx/vpx_codec.h
@ -183,20 +204,33 @@ INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(call enabled,CODEC_EXPORTS)
# based build systems. # based build systems.
libvpx_srcs.txt: libvpx_srcs.txt:
@echo " [CREATE] $@" @echo " [CREATE] $@"
@echo $(CODEC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ @echo $(CODEC_SRCS) | xargs -n1 echo | sort -u > $@
CLEAN-OBJS += libvpx_srcs.txt CLEAN-OBJS += libvpx_srcs.txt
# Assembly files that are included, but don't define symbols themselves.
# Filtered out to avoid Windows build warnings.
ASM_INCLUDES := \
third_party/x86inc/x86inc.asm \
vpx_config.asm \
vpx_ports/x86_abi_support.asm \
vpx_dsp/x86/bitdepth_conversion_sse2.asm \
ifeq ($(CONFIG_EXTERNAL_BUILD),yes) ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes) ifeq ($(CONFIG_MSVS),yes)
obj_int_extract.bat: $(SRC_PATH_BARE)/build/$(MSVS_ARCH_DIR)/obj_int_extract.bat
@cp $^ $@
obj_int_extract.$(VCPROJ_SFX): obj_int_extract.bat
obj_int_extract.$(VCPROJ_SFX): $(SRC_PATH_BARE)/build/make/obj_int_extract.c
@echo " [CREATE] $@"
$(qexec)$(GEN_VCPROJ) \
--exe \
--target=$(TOOLCHAIN) \
--name=obj_int_extract \
--ver=$(CONFIG_VS_VERSION) \
--proj-guid=E1360C65-D375-4335-8057-7ED99CC3F9B2 \
--src-path-bare="$(SRC_PATH_BARE)" \
$(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
--out=$@ $^ \
-I. \
-I"$(SRC_PATH_BARE)" \
PROJECTS-$(BUILD_LIBVPX) += obj_int_extract.$(VCPROJ_SFX)
vpx.def: $(call enabled,CODEC_EXPORTS) vpx.def: $(call enabled,CODEC_EXPORTS)
@echo " [CREATE] $@" @echo " [CREATE] $@"
$(qexec)$(SRC_PATH_BARE)/build/make/gen_msvs_def.sh\ $(qexec)$(SRC_PATH_BARE)/build/make/gen_msvs_def.sh\
@ -204,9 +238,14 @@ vpx.def: $(call enabled,CODEC_EXPORTS)
--out=$@ $^ --out=$@ $^
CLEAN-OBJS += vpx.def CLEAN-OBJS += vpx.def
vpx.$(VCPROJ_SFX): VCPROJ_SRCS=$(filter-out $(addprefix %, $(ASM_INCLUDES)), $^) # Assembly files that are included, but don't define symbols themselves.
# Filtered out to avoid Visual Studio build warnings.
ASM_INCLUDES := \
third_party/x86inc/x86inc.asm \
vpx_config.asm \
vpx_ports/x86_abi_support.asm \
vpx.$(VCPROJ_SFX): $(CODEC_SRCS) vpx.def vpx.$(VCPROJ_SFX): $(CODEC_SRCS) vpx.def obj_int_extract.$(VCPROJ_SFX)
@echo " [CREATE] $@" @echo " [CREATE] $@"
$(qexec)$(GEN_VCPROJ) \ $(qexec)$(GEN_VCPROJ) \
$(if $(CONFIG_SHARED),--dll,--lib) \ $(if $(CONFIG_SHARED),--dll,--lib) \
@ -218,68 +257,43 @@ vpx.$(VCPROJ_SFX): $(CODEC_SRCS) vpx.def
--ver=$(CONFIG_VS_VERSION) \ --ver=$(CONFIG_VS_VERSION) \
--src-path-bare="$(SRC_PATH_BARE)" \ --src-path-bare="$(SRC_PATH_BARE)" \
--out=$@ $(CFLAGS) \ --out=$@ $(CFLAGS) \
$(filter $(SRC_PATH_BARE)/vp8/%.c, $(VCPROJ_SRCS)) \ $(filter-out $(addprefix %, $(ASM_INCLUDES)), $^) \
$(filter $(SRC_PATH_BARE)/vp8/%.h, $(VCPROJ_SRCS)) \
$(filter $(SRC_PATH_BARE)/vp9/%.c, $(VCPROJ_SRCS)) \
$(filter $(SRC_PATH_BARE)/vp9/%.h, $(VCPROJ_SRCS)) \
$(filter $(SRC_PATH_BARE)/vpx/%, $(VCPROJ_SRCS)) \
$(filter $(SRC_PATH_BARE)/vpx_dsp/%, $(VCPROJ_SRCS)) \
$(filter-out $(addprefix $(SRC_PATH_BARE)/, \
vp8/%.c vp8/%.h vp9/%.c vp9/%.h vpx/% vpx_dsp/%), \
$(VCPROJ_SRCS)) \
--src-path-bare="$(SRC_PATH_BARE)" \ --src-path-bare="$(SRC_PATH_BARE)" \
PROJECTS-yes += vpx.$(VCPROJ_SFX) PROJECTS-$(BUILD_LIBVPX) += vpx.$(VCPROJ_SFX)
vpx.$(VCPROJ_SFX): vpx_config.asm vpx.$(VCPROJ_SFX): vpx_config.asm
vpx.$(VCPROJ_SFX): $(RTCD) vpx.$(VCPROJ_SFX): $(RTCD)
endif endif
else else
LIBVPX_OBJS=$(call objs, $(filter-out $(ASM_INCLUDES), $(CODEC_SRCS))) LIBVPX_OBJS=$(call objs,$(CODEC_SRCS))
OBJS-yes += $(LIBVPX_OBJS) OBJS-$(BUILD_LIBVPX) += $(LIBVPX_OBJS)
LIBS-$(if yes,$(CONFIG_STATIC)) += $(BUILD_PFX)libvpx.a $(BUILD_PFX)libvpx_g.a LIBS-$(if $(BUILD_LIBVPX),$(CONFIG_STATIC)) += $(BUILD_PFX)libvpx.a $(BUILD_PFX)libvpx_g.a
$(BUILD_PFX)libvpx_g.a: $(LIBVPX_OBJS) $(BUILD_PFX)libvpx_g.a: $(LIBVPX_OBJS)
SO_VERSION_MAJOR := 5
SO_VERSION_MINOR := 0 BUILD_LIBVPX_SO := $(if $(BUILD_LIBVPX),$(CONFIG_SHARED))
SO_VERSION_PATCH := 0
ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS)) ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS))
LIBVPX_SO := libvpx.$(SO_VERSION_MAJOR).dylib LIBVPX_SO := libvpx.$(VERSION_MAJOR).dylib
SHARED_LIB_SUF := .dylib
EXPORT_FILE := libvpx.syms EXPORT_FILE := libvpx.syms
LIBVPX_SO_SYMLINKS := $(addprefix $(LIBSUBDIR)/, \ LIBVPX_SO_SYMLINKS := $(addprefix $(LIBSUBDIR)/, \
libvpx.dylib ) libvpx.dylib )
else else
ifeq ($(filter iphonesimulator%,$(TGT_OS)),$(TGT_OS)) LIBVPX_SO := libvpx.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
LIBVPX_SO := libvpx.$(SO_VERSION_MAJOR).dylib
SHARED_LIB_SUF := .dylib
EXPORT_FILE := libvpx.syms
LIBVPX_SO_SYMLINKS := $(addprefix $(LIBSUBDIR)/, libvpx.dylib)
else
ifeq ($(filter os2%,$(TGT_OS)),$(TGT_OS))
LIBVPX_SO := libvpx$(SO_VERSION_MAJOR).dll
SHARED_LIB_SUF := _dll.a
EXPORT_FILE := libvpx.def
LIBVPX_SO_SYMLINKS :=
LIBVPX_SO_IMPLIB := libvpx_dll.a
else
LIBVPX_SO := libvpx.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH)
SHARED_LIB_SUF := .so
EXPORT_FILE := libvpx.ver EXPORT_FILE := libvpx.ver
SYM_LINK := libvpx.so
LIBVPX_SO_SYMLINKS := $(addprefix $(LIBSUBDIR)/, \ LIBVPX_SO_SYMLINKS := $(addprefix $(LIBSUBDIR)/, \
libvpx.so libvpx.so.$(SO_VERSION_MAJOR) \ libvpx.so libvpx.so.$(VERSION_MAJOR) \
libvpx.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR)) libvpx.so.$(VERSION_MAJOR).$(VERSION_MINOR))
endif
endif
endif endif
LIBS-$(CONFIG_SHARED) += $(BUILD_PFX)$(LIBVPX_SO)\ LIBS-$(BUILD_LIBVPX_SO) += $(BUILD_PFX)$(LIBVPX_SO)\
$(notdir $(LIBVPX_SO_SYMLINKS)) \ $(notdir $(LIBVPX_SO_SYMLINKS))
$(if $(LIBVPX_SO_IMPLIB), $(BUILD_PFX)$(LIBVPX_SO_IMPLIB))
$(BUILD_PFX)$(LIBVPX_SO): $(LIBVPX_OBJS) $(EXPORT_FILE) $(BUILD_PFX)$(LIBVPX_SO): $(LIBVPX_OBJS) $(EXPORT_FILE)
$(BUILD_PFX)$(LIBVPX_SO): extralibs += -lm $(BUILD_PFX)$(LIBVPX_SO): extralibs += -lm
$(BUILD_PFX)$(LIBVPX_SO): SONAME = libvpx.so.$(SO_VERSION_MAJOR) $(BUILD_PFX)$(LIBVPX_SO): SONAME = libvpx.so.$(VERSION_MAJOR)
$(BUILD_PFX)$(LIBVPX_SO): EXPORTS_FILE = $(EXPORT_FILE) $(BUILD_PFX)$(LIBVPX_SO): EXPORTS_FILE = $(EXPORT_FILE)
libvpx.ver: $(call enabled,CODEC_EXPORTS) libvpx.ver: $(call enabled,CODEC_EXPORTS)
@ -294,19 +308,6 @@ libvpx.syms: $(call enabled,CODEC_EXPORTS)
$(qexec)awk '{print "_"$$2}' $^ >$@ $(qexec)awk '{print "_"$$2}' $^ >$@
CLEAN-OBJS += libvpx.syms CLEAN-OBJS += libvpx.syms
libvpx.def: $(call enabled,CODEC_EXPORTS)
@echo " [CREATE] $@"
$(qexec)echo LIBRARY $(LIBVPX_SO:.dll=) INITINSTANCE TERMINSTANCE > $@
$(qexec)echo "DATA MULTIPLE NONSHARED" >> $@
$(qexec)echo "EXPORTS" >> $@
$(qexec)awk '!/vpx_svc_*/ {print "_"$$2}' $^ >>$@
CLEAN-OBJS += libvpx.def
libvpx_dll.a: $(LIBVPX_SO)
@echo " [IMPLIB] $@"
$(qexec)emximp -o $@ $<
CLEAN-OBJS += libvpx_dll.a
define libvpx_symlink_template define libvpx_symlink_template
$(1): $(2) $(1): $(2)
@echo " [LN] $(2) $$@" @echo " [LN] $(2) $$@"
@ -322,12 +323,11 @@ $(eval $(call libvpx_symlink_template,\
$(LIBVPX_SO))) $(LIBVPX_SO)))
INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBVPX_SO_SYMLINKS) INSTALL-LIBS-$(BUILD_LIBVPX_SO) += $(LIBVPX_SO_SYMLINKS)
INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBSUBDIR)/$(LIBVPX_SO) INSTALL-LIBS-$(BUILD_LIBVPX_SO) += $(LIBSUBDIR)/$(LIBVPX_SO)
INSTALL-LIBS-$(CONFIG_SHARED) += $(if $(LIBVPX_SO_IMPLIB),$(LIBSUBDIR)/$(LIBVPX_SO_IMPLIB))
LIBS-yes += vpx.pc LIBS-$(BUILD_LIBVPX) += vpx.pc
vpx.pc: config.mk libs.mk vpx.pc: config.mk libs.mk
@echo " [CREATE] $@" @echo " [CREATE] $@"
$(qexec)echo '# pkg-config file from libvpx $(VERSION_STRING)' > $@ $(qexec)echo '# pkg-config file from libvpx $(VERSION_STRING)' > $@
@ -353,6 +353,9 @@ INSTALL_MAPS += $(LIBSUBDIR)/pkgconfig/%.pc %.pc
CLEAN-OBJS += vpx.pc CLEAN-OBJS += vpx.pc
endif endif
LIBS-$(LIPO_LIBVPX) += libvpx.a
$(eval $(if $(LIPO_LIBVPX),$(call lipo_lib_template,libvpx.a)))
# #
# Rule to make assembler configuration file from C configuration file # Rule to make assembler configuration file from C configuration file
# #
@ -373,9 +376,9 @@ CLEAN-OBJS += $(BUILD_PFX)vpx_config.asm
endif endif
# #
# Add assembler dependencies for configuration. # Add assembler dependencies for configuration and offsets
# #
$(filter %.S.o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm $(filter %.s.o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm
$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm $(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm
@ -397,32 +400,20 @@ LIBVPX_TEST_DATA_PATH ?= .
include $(SRC_PATH_BARE)/test/test.mk include $(SRC_PATH_BARE)/test/test.mk
LIBVPX_TEST_SRCS=$(addprefix test/,$(call enabled,LIBVPX_TEST_SRCS)) LIBVPX_TEST_SRCS=$(addprefix test/,$(call enabled,LIBVPX_TEST_SRCS))
LIBVPX_TEST_BIN=./test_libvpx$(EXE_SFX) LIBVPX_TEST_BINS=./test_libvpx$(EXE_SFX)
LIBVPX_TEST_DATA=$(addprefix $(LIBVPX_TEST_DATA_PATH)/,\ LIBVPX_TEST_DATA=$(addprefix $(LIBVPX_TEST_DATA_PATH)/,\
$(call enabled,LIBVPX_TEST_DATA)) $(call enabled,LIBVPX_TEST_DATA))
libvpx_test_data_url=https://storage.googleapis.com/downloads.webmproject.org/test_data/libvpx/$(1) libvpx_test_data_url=http://downloads.webmproject.org/test_data/libvpx/$(1)
TEST_INTRA_PRED_SPEED_BIN=./test_intra_pred_speed$(EXE_SFX)
TEST_INTRA_PRED_SPEED_SRCS=$(addprefix test/,$(call enabled,TEST_INTRA_PRED_SPEED_SRCS))
TEST_INTRA_PRED_SPEED_OBJS := $(sort $(call objs,$(TEST_INTRA_PRED_SPEED_SRCS)))
libvpx_test_srcs.txt: libvpx_test_srcs.txt:
@echo " [CREATE] $@" @echo " [CREATE] $@"
@echo $(LIBVPX_TEST_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ @echo $(LIBVPX_TEST_SRCS) | xargs -n1 echo | sort -u > $@
CLEAN-OBJS += libvpx_test_srcs.txt CLEAN-OBJS += libvpx_test_srcs.txt
$(LIBVPX_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1 $(LIBVPX_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1
@echo " [DOWNLOAD] $@" @echo " [DOWNLOAD] $@"
# Attempt to download the file using curl, retrying once if it fails for a $(qexec)trap 'rm -f $@' INT TERM &&\
# partial file (18). curl -L -o $@ $(call libvpx_test_data_url,$(@F))
$(qexec)( \
trap 'rm -f $@' INT TERM; \
curl="curl --retry 1 -L -o $@ $(call libvpx_test_data_url,$(@F))"; \
$$curl; \
case "$$?" in \
18) $$curl -C -;; \
esac \
)
testdata:: $(LIBVPX_TEST_DATA) testdata:: $(LIBVPX_TEST_DATA)
$(qexec)[ -x "$$(which sha1sum)" ] && sha1sum=sha1sum;\ $(qexec)[ -x "$$(which sha1sum)" ] && sha1sum=sha1sum;\
@ -431,10 +422,12 @@ testdata:: $(LIBVPX_TEST_DATA)
if [ -n "$${sha1sum}" ]; then\ if [ -n "$${sha1sum}" ]; then\
set -e;\ set -e;\
echo "Checking test data:";\ echo "Checking test data:";\
for f in $(call enabled,LIBVPX_TEST_DATA); do\ if [ -n "$(LIBVPX_TEST_DATA)" ]; then\
grep $$f $(SRC_PATH_BARE)/test/test-data.sha1 |\ for f in $(call enabled,LIBVPX_TEST_DATA); do\
(cd $(LIBVPX_TEST_DATA_PATH); $${sha1sum} -c);\ grep $$f $(SRC_PATH_BARE)/test/test-data.sha1 |\
done; \ (cd $(LIBVPX_TEST_DATA_PATH); $${sha1sum} -c);\
done; \
fi; \
else\ else\
echo "Skipping test data integrity check, sha1sum not found.";\ echo "Skipping test data integrity check, sha1sum not found.";\
fi fi
@ -476,25 +469,7 @@ test_libvpx.$(VCPROJ_SFX): $(LIBVPX_TEST_SRCS) vpx.$(VCPROJ_SFX) gtest.$(VCPROJ_
PROJECTS-$(CONFIG_MSVS) += test_libvpx.$(VCPROJ_SFX) PROJECTS-$(CONFIG_MSVS) += test_libvpx.$(VCPROJ_SFX)
LIBVPX_TEST_BIN := $(addprefix $(TGT_OS:win64=x64)/Release/,$(notdir $(LIBVPX_TEST_BIN))) LIBVPX_TEST_BINS := $(addprefix $(TGT_OS:win64=x64)/Release/,$(notdir $(LIBVPX_TEST_BINS)))
ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
PROJECTS-$(CONFIG_MSVS) += test_intra_pred_speed.$(VCPROJ_SFX)
test_intra_pred_speed.$(VCPROJ_SFX): $(TEST_INTRA_PRED_SPEED_SRCS) vpx.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
@echo " [CREATE] $@"
$(qexec)$(GEN_VCPROJ) \
--exe \
--target=$(TOOLCHAIN) \
--name=test_intra_pred_speed \
-D_VARIADIC_MAX=10 \
--proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
--ver=$(CONFIG_VS_VERSION) \
--src-path-bare="$(SRC_PATH_BARE)" \
$(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
--out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
-I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
-L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
endif # TEST_INTRA_PRED_SPEED
endif endif
else else
@ -505,54 +480,45 @@ ifeq ($(filter win%,$(TGT_OS)),$(TGT_OS))
# Disabling pthreads globally will cause issues on darwin and possibly elsewhere # Disabling pthreads globally will cause issues on darwin and possibly elsewhere
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -DGTEST_HAS_PTHREAD=0 $(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -DGTEST_HAS_PTHREAD=0
endif endif
GTEST_INCLUDES := -I$(SRC_PATH_BARE)/third_party/googletest/src $(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src
GTEST_INCLUDES += -I$(SRC_PATH_BARE)/third_party/googletest/src/include $(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES) OBJS-$(BUILD_LIBVPX) += $(GTEST_OBJS)
OBJS-yes += $(GTEST_OBJS) LIBS-$(BUILD_LIBVPX) += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
LIBS-yes += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
$(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS) $(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS)
LIBVPX_TEST_OBJS=$(sort $(call objs,$(LIBVPX_TEST_SRCS))) LIBVPX_TEST_OBJS=$(sort $(call objs,$(LIBVPX_TEST_SRCS)))
$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES) $(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src
OBJS-yes += $(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
BINS-yes += $(LIBVPX_TEST_BIN) OBJS-$(BUILD_LIBVPX) += $(LIBVPX_TEST_OBJS)
BINS-$(BUILD_LIBVPX) += $(LIBVPX_TEST_BINS)
CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),vpx_g,vpx) CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),vpx_g,vpx)
CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a) CODEC_LIB_SUF=$(if $(CONFIG_SHARED),.so,.a)
TEST_LIBS := lib$(CODEC_LIB)$(CODEC_LIB_SUF) libgtest.a $(foreach bin,$(LIBVPX_TEST_BINS),\
$(LIBVPX_TEST_BIN): $(TEST_LIBS) $(if $(BUILD_LIBVPX),$(eval $(bin): \
$(eval $(call linkerxx_template,$(LIBVPX_TEST_BIN), \ lib$(CODEC_LIB)$(CODEC_LIB_SUF) libgtest.a ))\
$(LIBVPX_TEST_OBJS) \ $(if $(BUILD_LIBVPX),$(eval $(call linkerxx_template,$(bin),\
-L. -lvpx -lgtest $(extralibs) -lm)) $(LIBVPX_TEST_OBJS) \
-L. -lvpx -lgtest $(extralibs) -lm)\
)))\
$(if $(LIPO_LIBS),$(eval $(call lipo_bin_template,$(bin))))\
ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),) endif
$(TEST_INTRA_PRED_SPEED_OBJS) $(TEST_INTRA_PRED_SPEED_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
OBJS-yes += $(TEST_INTRA_PRED_SPEED_OBJS)
BINS-yes += $(TEST_INTRA_PRED_SPEED_BIN)
$(TEST_INTRA_PRED_SPEED_BIN): $(TEST_LIBS)
$(eval $(call linkerxx_template,$(TEST_INTRA_PRED_SPEED_BIN), \
$(TEST_INTRA_PRED_SPEED_OBJS) \
-L. -lvpx -lgtest $(extralibs) -lm))
endif # TEST_INTRA_PRED_SPEED
endif # CONFIG_UNIT_TESTS
# Install test sources only if codec source is included # Install test sources only if codec source is included
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\ INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\
$(shell find $(SRC_PATH_BARE)/third_party/googletest -type f)) $(shell find $(SRC_PATH_BARE)/third_party/googletest -type f))
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBVPX_TEST_SRCS) INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBVPX_TEST_SRCS)
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(TEST_INTRA_PRED_SPEED_SRCS)
define test_shard_template define test_shard_template
test:: test_shard.$(1) test:: test_shard.$(1)
test-no-data-check:: test_shard_ndc.$(1) test_shard.$(1): $(LIBVPX_TEST_BINS) testdata
test_shard.$(1) test_shard_ndc.$(1): $(LIBVPX_TEST_BIN)
@set -e; \ @set -e; \
export GTEST_SHARD_INDEX=$(1); \ for t in $(LIBVPX_TEST_BINS); do \
export GTEST_TOTAL_SHARDS=$(2); \ export GTEST_SHARD_INDEX=$(1); \
$(LIBVPX_TEST_BIN) export GTEST_TOTAL_SHARDS=$(2); \
test_shard.$(1): testdata $$$$t; \
done
.PHONY: test_shard.$(1) .PHONY: test_shard.$(1)
endef endef
@ -575,11 +541,7 @@ libs.doxy: $(CODEC_DOC_SRCS)
@echo "ENABLED_SECTIONS += $(sort $(CODEC_DOC_SECTIONS))" >> $@ @echo "ENABLED_SECTIONS += $(sort $(CODEC_DOC_SECTIONS))" >> $@
## Generate rtcd.h for all objects ## Generate rtcd.h for all objects
ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
$(OBJS-yes:.o=.d): $(RTCD) $(OBJS-yes:.o=.d): $(RTCD)
else
$(OBJS-yes): $(RTCD)
endif
## Update the global src list ## Update the global src list
SRCS += $(CODEC_SRCS) $(LIBVPX_TEST_SRCS) $(GTEST_SRCS) SRCS += $(CODEC_SRCS) $(LIBVPX_TEST_SRCS) $(GTEST_SRCS)
@ -597,16 +559,15 @@ ifeq ($(CONFIG_MSVS),yes)
# TODO(tomfinegan): Support running the debug versions of tools? # TODO(tomfinegan): Support running the debug versions of tools?
TEST_BIN_PATH := $(addsuffix /$(TGT_OS:win64=x64)/Release, $(TEST_BIN_PATH)) TEST_BIN_PATH := $(addsuffix /$(TGT_OS:win64=x64)/Release, $(TEST_BIN_PATH))
endif endif
utiltest utiltest-no-data-check: utiltest: testdata
$(qexec)$(SRC_PATH_BARE)/test/vpxdec.sh \ $(qexec)$(SRC_PATH_BARE)/test/vpxdec.sh \
--test-data-path $(LIBVPX_TEST_DATA_PATH) \ --test-data-path $(LIBVPX_TEST_DATA_PATH) \
--bin-path $(TEST_BIN_PATH) --bin-path $(TEST_BIN_PATH)
$(qexec)$(SRC_PATH_BARE)/test/vpxenc.sh \ $(qexec)$(SRC_PATH_BARE)/test/vpxenc.sh \
--test-data-path $(LIBVPX_TEST_DATA_PATH) \ --test-data-path $(LIBVPX_TEST_DATA_PATH) \
--bin-path $(TEST_BIN_PATH) --bin-path $(TEST_BIN_PATH)
utiltest: testdata
else else
utiltest utiltest-no-data-check: utiltest:
@echo Unit tests must be enabled to make the utiltest target. @echo Unit tests must be enabled to make the utiltest target.
endif endif
@ -624,12 +585,11 @@ ifeq ($(CONFIG_MSVS),yes)
# TODO(tomfinegan): Support running the debug versions of tools? # TODO(tomfinegan): Support running the debug versions of tools?
EXAMPLES_BIN_PATH := $(TGT_OS:win64=x64)/Release EXAMPLES_BIN_PATH := $(TGT_OS:win64=x64)/Release
endif endif
exampletest exampletest-no-data-check: examples exampletest: examples testdata
$(qexec)$(SRC_PATH_BARE)/test/examples.sh \ $(qexec)$(SRC_PATH_BARE)/test/examples.sh \
--test-data-path $(LIBVPX_TEST_DATA_PATH) \ --test-data-path $(LIBVPX_TEST_DATA_PATH) \
--bin-path $(EXAMPLES_BIN_PATH) --bin-path $(EXAMPLES_BIN_PATH)
exampletest: testdata
else else
exampletest exampletest-no-data-check: exampletest:
@echo Unit tests must be enabled to make the exampletest target. @echo Unit tests must be enabled to make the exampletest target.
endif endif

View File

@ -1,4 +1,4 @@
/*!\mainpage WebM Codec SDK /*!\mainpage WebM VP8 Codec SDK
\section main_contents Page Contents \section main_contents Page Contents
- \ref main_intro - \ref main_intro
@ -6,11 +6,11 @@
- \ref main_support - \ref main_support
\section main_intro Introduction \section main_intro Introduction
Welcome to the WebM Codec SDK. This SDK allows you to integrate your Welcome to the WebM VP8 Codec SDK. This SDK allows you to integrate your
applications with the VP8 and VP9 video codecs, high quality, royalty free, applications with the VP8 video codec, a high quality, royalty free, open
open source codecs deployed on billions of computers and devices worldwide. source codec deployed on millions of computers and devices worldwide.
This distribution of the WebM Codec SDK includes the following support: This distribution of the WebM VP8 Codec SDK includes the following support:
\if vp8_encoder \if vp8_encoder
- \ref vp8_encoder - \ref vp8_encoder
@ -28,12 +28,12 @@
- Read the \ref samples "sample code" for examples of how to interact with the - Read the \ref samples "sample code" for examples of how to interact with the
codec. codec.
- \ref codec reference - \ref codec reference
\if encoder \if encoder
- \ref encoder reference - \ref encoder reference
\endif \endif
\if decoder \if decoder
- \ref decoder reference - \ref decoder reference
\endif \endif
\section main_support Support Options & FAQ \section main_support Support Options & FAQ
The WebM project is an open source project supported by its community. For The WebM project is an open source project supported by its community. For

View File

@ -20,17 +20,19 @@
* Still in the public domain. * Still in the public domain.
*/ */
#include <string.h> /* for memcpy() */ #include <string.h> /* for memcpy() */
#include "md5_utils.h" #include "md5_utils.h"
static void byteSwap(UWORD32 *buf, unsigned words) { void
byteSwap(UWORD32 *buf, unsigned words) {
md5byte *p; md5byte *p;
/* Only swap bytes for big endian machines */ /* Only swap bytes for big endian machines */
int i = 1; int i = 1;
if (*(char *)&i == 1) return; if (*(char *)&i == 1)
return;
p = (md5byte *)buf; p = (md5byte *)buf;
@ -45,7 +47,8 @@ static void byteSwap(UWORD32 *buf, unsigned words) {
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants. * initialization constants.
*/ */
void MD5Init(struct MD5Context *ctx) { void
MD5Init(struct MD5Context *ctx) {
ctx->buf[0] = 0x67452301; ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89; ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe; ctx->buf[2] = 0x98badcfe;
@ -59,7 +62,8 @@ void MD5Init(struct MD5Context *ctx) {
* Update context to reflect the concatenation of another buffer full * Update context to reflect the concatenation of another buffer full
* of bytes. * of bytes.
*/ */
void MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) { void
MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) {
UWORD32 t; UWORD32 t;
/* Update byte count */ /* Update byte count */
@ -67,9 +71,9 @@ void MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) {
t = ctx->bytes[0]; t = ctx->bytes[0];
if ((ctx->bytes[0] = t + len) < t) if ((ctx->bytes[0] = t + len) < t)
ctx->bytes[1]++; /* Carry from low to high */ ctx->bytes[1]++; /* Carry from low to high */
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
if (t > len) { if (t > len) {
memcpy((md5byte *)ctx->in + 64 - t, buf, len); memcpy((md5byte *)ctx->in + 64 - t, buf, len);
@ -100,7 +104,8 @@ void MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) {
* Final wrapup - pad to 64-byte boundary with the bit pattern * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first) * 1 0* (64-bit count of bits processed, MSB-first)
*/ */
void MD5Final(md5byte digest[16], struct MD5Context *ctx) { void
MD5Final(md5byte digest[16], struct MD5Context *ctx) {
int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
md5byte *p = (md5byte *)ctx->in + count; md5byte *p = (md5byte *)ctx->in + count;
@ -110,7 +115,7 @@ void MD5Final(md5byte digest[16], struct MD5Context *ctx) {
/* Bytes of padding needed to make 56 bytes (-8..55) */ /* Bytes of padding needed to make 56 bytes (-8..55) */
count = 56 - 1 - count; count = 56 - 1 - count;
if (count < 0) { /* Padding forces an extra block */ if (count < 0) { /* Padding forces an extra block */
memset(p, 0, count + 8); memset(p, 0, count + 8);
byteSwap(ctx->in, 16); byteSwap(ctx->in, 16);
MD5Transform(ctx->buf, ctx->in); MD5Transform(ctx->buf, ctx->in);
@ -142,27 +147,16 @@ void MD5Final(md5byte digest[16], struct MD5Context *ctx) {
#define F4(x, y, z) (y ^ (x | ~z)) #define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */ /* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, in, s) \ #define MD5STEP(f,w,x,y,z,in,s) \
(w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x) (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
#if defined(__clang__) && defined(__has_attribute)
#if __has_attribute(no_sanitize)
#define VPX_NO_UNSIGNED_OVERFLOW_CHECK \
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
#endif
#ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK
#define VPX_NO_UNSIGNED_OVERFLOW_CHECK
#endif
/* /*
* The core of the MD5 algorithm, this alters an existing MD5 hash to * The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks * reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine. * the data and converts bytes into longwords for this routine.
*/ */
VPX_NO_UNSIGNED_OVERFLOW_CHECK void MD5Transform(UWORD32 buf[4], void
UWORD32 const in[16]) { MD5Transform(UWORD32 buf[4], UWORD32 const in[16]) {
register UWORD32 a, b, c, d; register UWORD32 a, b, c, d;
a = buf[0]; a = buf[0];
@ -244,6 +238,4 @@ VPX_NO_UNSIGNED_OVERFLOW_CHECK void MD5Transform(UWORD32 buf[4],
buf[3] += d; buf[3] += d;
} }
#undef VPX_NO_UNSIGNED_OVERFLOW_CHECK
#endif #endif

View File

@ -37,13 +37,7 @@ struct rate_hist {
struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg, struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg,
const vpx_rational_t *fps) { const vpx_rational_t *fps) {
int i; int i;
struct rate_hist *hist = calloc(1, sizeof(*hist)); struct rate_hist *hist = malloc(sizeof(*hist));
if (hist == NULL || cfg == NULL || fps == NULL || fps->num == 0 ||
fps->den == 0) {
destroy_rate_histogram(hist);
return NULL;
}
// Determine the number of samples in the buffer. Use the file's framerate // Determine the number of samples in the buffer. Use the file's framerate
// to determine the number of frames in rc_buf_sz milliseconds, with an // to determine the number of frames in rc_buf_sz milliseconds, with an
@ -51,7 +45,8 @@ struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg,
hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000; hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000;
// prevent division by zero // prevent division by zero
if (hist->samples == 0) hist->samples = 1; if (hist->samples == 0)
hist->samples = 1;
hist->frames = 0; hist->frames = 0;
hist->total = 0; hist->total = 0;
@ -83,20 +78,15 @@ void update_rate_histogram(struct rate_hist *hist,
int64_t avg_bitrate = 0; int64_t avg_bitrate = 0;
int64_t sum_sz = 0; int64_t sum_sz = 0;
const int64_t now = pkt->data.frame.pts * 1000 * const int64_t now = pkt->data.frame.pts * 1000 *
(uint64_t)cfg->g_timebase.num / (uint64_t)cfg->g_timebase.num /
(uint64_t)cfg->g_timebase.den; (uint64_t)cfg->g_timebase.den;
int idx; int idx = hist->frames++ % hist->samples;
if (hist == NULL || cfg == NULL || pkt == NULL) return;
idx = hist->frames++ % hist->samples;
hist->pts[idx] = now; hist->pts[idx] = now;
hist->sz[idx] = (int)pkt->data.frame.sz; hist->sz[idx] = (int)pkt->data.frame.sz;
if (now < cfg->rc_buf_initial_sz) return; if (now < cfg->rc_buf_initial_sz)
return;
if (!cfg->rc_target_bitrate) return;
then = now; then = now;
@ -105,16 +95,20 @@ void update_rate_histogram(struct rate_hist *hist,
const int i_idx = (i - 1) % hist->samples; const int i_idx = (i - 1) % hist->samples;
then = hist->pts[i_idx]; then = hist->pts[i_idx];
if (now - then > cfg->rc_buf_sz) break; if (now - then > cfg->rc_buf_sz)
break;
sum_sz += hist->sz[i_idx]; sum_sz += hist->sz[i_idx];
} }
if (now == then) return; if (now == then)
return;
avg_bitrate = sum_sz * 8 * 1000 / (now - then); avg_bitrate = sum_sz * 8 * 1000 / (now - then);
idx = (int)(avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000)); idx = (int)(avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000));
if (idx < 0) idx = 0; if (idx < 0)
if (idx > RATE_BINS - 1) idx = RATE_BINS - 1; idx = 0;
if (idx > RATE_BINS - 1)
idx = RATE_BINS - 1;
if (hist->bucket[idx].low > avg_bitrate) if (hist->bucket[idx].low > avg_bitrate)
hist->bucket[idx].low = (int)avg_bitrate; hist->bucket[idx].low = (int)avg_bitrate;
if (hist->bucket[idx].high < avg_bitrate) if (hist->bucket[idx].high < avg_bitrate)
@ -123,22 +117,19 @@ void update_rate_histogram(struct rate_hist *hist,
hist->total++; hist->total++;
} }
static int merge_hist_buckets(struct hist_bucket *bucket, int max_buckets, static int merge_hist_buckets(struct hist_bucket *bucket,
int *num_buckets) { int max_buckets, int *num_buckets) {
int small_bucket = 0, merge_bucket = INT_MAX, big_bucket = 0; int small_bucket = 0, merge_bucket = INT_MAX, big_bucket = 0;
int buckets; int buckets = *num_buckets;
int i; int i;
assert(bucket != NULL);
assert(num_buckets != NULL);
buckets = *num_buckets;
/* Find the extrema for this list of buckets */ /* Find the extrema for this list of buckets */
big_bucket = small_bucket = 0; big_bucket = small_bucket = 0;
for (i = 0; i < buckets; i++) { for (i = 0; i < buckets; i++) {
if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; if (bucket[i].count < bucket[small_bucket].count)
if (bucket[i].count > bucket[big_bucket].count) big_bucket = i; small_bucket = i;
if (bucket[i].count > bucket[big_bucket].count)
big_bucket = i;
} }
/* If we have too many buckets, merge the smallest with an adjacent /* If we have too many buckets, merge the smallest with an adjacent
@ -180,10 +171,13 @@ static int merge_hist_buckets(struct hist_bucket *bucket, int max_buckets,
*/ */
big_bucket = small_bucket = 0; big_bucket = small_bucket = 0;
for (i = 0; i < buckets; i++) { for (i = 0; i < buckets; i++) {
if (i > merge_bucket) bucket[i] = bucket[i + 1]; if (i > merge_bucket)
bucket[i] = bucket[i + 1];
if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; if (bucket[i].count < bucket[small_bucket].count)
if (bucket[i].count > bucket[big_bucket].count) big_bucket = i; small_bucket = i;
if (bucket[i].count > bucket[big_bucket].count)
big_bucket = i;
} }
} }
@ -191,13 +185,11 @@ static int merge_hist_buckets(struct hist_bucket *bucket, int max_buckets,
return bucket[big_bucket].count; return bucket[big_bucket].count;
} }
static void show_histogram(const struct hist_bucket *bucket, int buckets, static void show_histogram(const struct hist_bucket *bucket,
int total, int scale) { int buckets, int total, int scale) {
const char *pat1, *pat2; const char *pat1, *pat2;
int i; int i;
assert(bucket != NULL);
switch ((int)(log(bucket[buckets - 1].high) / log(10)) + 1) { switch ((int)(log(bucket[buckets - 1].high) / log(10)) + 1) {
case 1: case 1:
case 2: case 2:
@ -237,7 +229,8 @@ static void show_histogram(const struct hist_bucket *bucket, int buckets,
pct = (float)(100.0 * bucket[i].count / total); pct = (float)(100.0 * bucket[i].count / total);
len = HIST_BAR_MAX * bucket[i].count / scale; len = HIST_BAR_MAX * bucket[i].count / scale;
if (len < 1) len = 1; if (len < 1)
len = 1;
assert(len <= HIST_BAR_MAX); assert(len <= HIST_BAR_MAX);
if (bucket[i].low == bucket[i].high) if (bucket[i].low == bucket[i].high)
@ -245,7 +238,8 @@ static void show_histogram(const struct hist_bucket *bucket, int buckets,
else else
fprintf(stderr, pat2, bucket[i].low, bucket[i].high); fprintf(stderr, pat2, bucket[i].low, bucket[i].high);
for (j = 0; j < HIST_BAR_MAX; j++) fprintf(stderr, j < len ? "=" : " "); for (j = 0; j < HIST_BAR_MAX; j++)
fprintf(stderr, j < len ? "=" : " ");
fprintf(stderr, "\t%5d (%6.2f%%)\n", bucket[i].count, pct); fprintf(stderr, "\t%5d (%6.2f%%)\n", bucket[i].count, pct);
} }
} }
@ -271,15 +265,14 @@ void show_q_histogram(const int counts[64], int max_buckets) {
show_histogram(bucket, buckets, total, scale); show_histogram(bucket, buckets, total, scale);
} }
void show_rate_histogram(struct rate_hist *hist, const vpx_codec_enc_cfg_t *cfg, void show_rate_histogram(struct rate_hist *hist,
int max_buckets) { const vpx_codec_enc_cfg_t *cfg, int max_buckets) {
int i, scale; int i, scale;
int buckets = 0; int buckets = 0;
if (hist == NULL || cfg == NULL) return;
for (i = 0; i < RATE_BINS; i++) { for (i = 0; i < RATE_BINS; i++) {
if (hist->bucket[i].low == INT_MAX) continue; if (hist->bucket[i].low == INT_MAX)
continue;
hist->bucket[buckets++] = hist->bucket[i]; hist->bucket[buckets++] = hist->bucket[i];
} }

View File

@ -9,7 +9,7 @@
## ##
# libvpx reverse dependencies (targets that depend on libvpx) # libvpx reverse dependencies (targets that depend on libvpx)
VPX_NONDEPS=$(addsuffix .$(VCPROJ_SFX),vpx gtest) VPX_NONDEPS=$(addsuffix .$(VCPROJ_SFX),vpx gtest obj_int_extract)
VPX_RDEPS=$(foreach vcp,\ VPX_RDEPS=$(foreach vcp,\
$(filter-out $(VPX_NONDEPS),$^), --dep=$(vcp:.$(VCPROJ_SFX)=):vpx) $(filter-out $(VPX_NONDEPS),$^), --dep=$(vcp:.$(VCPROJ_SFX)=):vpx)
@ -17,6 +17,7 @@ vpx.sln: $(wildcard *.$(VCPROJ_SFX))
@echo " [CREATE] $@" @echo " [CREATE] $@"
$(SRC_PATH_BARE)/build/make/gen_msvs_sln.sh \ $(SRC_PATH_BARE)/build/make/gen_msvs_sln.sh \
$(if $(filter vpx.$(VCPROJ_SFX),$^),$(VPX_RDEPS)) \ $(if $(filter vpx.$(VCPROJ_SFX),$^),$(VPX_RDEPS)) \
--dep=vpx:obj_int_extract \
--dep=test_libvpx:gtest \ --dep=test_libvpx:gtest \
--ver=$(CONFIG_VS_VERSION)\ --ver=$(CONFIG_VS_VERSION)\
--out=$@ $^ --out=$@ $^

View File

@ -11,10 +11,6 @@
#ifndef TEST_ACM_RANDOM_H_ #ifndef TEST_ACM_RANDOM_H_
#define TEST_ACM_RANDOM_H_ #define TEST_ACM_RANDOM_H_
#include <assert.h>
#include <limits>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_integer.h" #include "vpx/vpx_integer.h"
@ -27,24 +23,20 @@ class ACMRandom {
explicit ACMRandom(int seed) : random_(seed) {} explicit ACMRandom(int seed) : random_(seed) {}
void Reset(int seed) { random_.Reseed(seed); } void Reset(int seed) {
random_.Reseed(seed);
}
uint16_t Rand16(void) { uint16_t Rand16(void) {
const uint32_t value = const uint32_t value =
random_.Generate(testing::internal::Random::kMaxRange); random_.Generate(testing::internal::Random::kMaxRange);
return (value >> 15) & 0xffff; return (value >> 16) & 0xffff;
}
int16_t Rand9Signed(void) {
// Use 9 bits: values between 255 (0x0FF) and -256 (0x100).
const uint32_t value = random_.Generate(512);
return static_cast<int16_t>(value) - 256;
} }
uint8_t Rand8(void) { uint8_t Rand8(void) {
const uint32_t value = const uint32_t value =
random_.Generate(testing::internal::Random::kMaxRange); random_.Generate(testing::internal::Random::kMaxRange);
// There's a bit more entropy in the upper bits of this implementation. // There's a bit more entropy in the upper bits of this implementation.
return (value >> 23) & 0xff; return (value >> 24) & 0xff;
} }
uint8_t Rand8Extremes(void) { uint8_t Rand8Extremes(void) {
@ -54,18 +46,17 @@ class ACMRandom {
return r < 128 ? r << 4 : r >> 4; return r < 128 ? r << 4 : r >> 4;
} }
uint32_t RandRange(const uint32_t range) { int PseudoUniform(int range) {
// testing::internal::Random::Generate provides values in the range
// testing::internal::Random::kMaxRange.
assert(range <= testing::internal::Random::kMaxRange);
return random_.Generate(range); return random_.Generate(range);
} }
int PseudoUniform(int range) { return random_.Generate(range); } int operator()(int n) {
return PseudoUniform(n);
}
int operator()(int n) { return PseudoUniform(n); } static int DeterministicSeed(void) {
return 0xbaba;
static int DeterministicSeed(void) { return 0xbaba; } }
private: private:
testing::internal::Random random_; testing::internal::Random random_;

View File

@ -1,128 +0,0 @@
/*
* Copyright (c) 2015 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <algorithm>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/util.h"
#include "test/y4m_video_source.h"
namespace {
// Check if any pixel in a 16x16 macroblock varies between frames.
int CheckMb(const vpx_image_t &current, const vpx_image_t &previous, int mb_r,
int mb_c) {
for (int plane = 0; plane < 3; plane++) {
int r = 16 * mb_r;
int c0 = 16 * mb_c;
int r_top = std::min(r + 16, static_cast<int>(current.d_h));
int c_top = std::min(c0 + 16, static_cast<int>(current.d_w));
r = std::max(r, 0);
c0 = std::max(c0, 0);
if (plane > 0 && current.x_chroma_shift) {
c_top = (c_top + 1) >> 1;
c0 >>= 1;
}
if (plane > 0 && current.y_chroma_shift) {
r_top = (r_top + 1) >> 1;
r >>= 1;
}
for (; r < r_top; ++r) {
for (int c = c0; c < c_top; ++c) {
if (current.planes[plane][current.stride[plane] * r + c] !=
previous.planes[plane][previous.stride[plane] * r + c]) {
return 1;
}
}
}
}
return 0;
}
void GenerateMap(int mb_rows, int mb_cols, const vpx_image_t &current,
const vpx_image_t &previous, uint8_t *map) {
for (int mb_r = 0; mb_r < mb_rows; ++mb_r) {
for (int mb_c = 0; mb_c < mb_cols; ++mb_c) {
map[mb_r * mb_cols + mb_c] = CheckMb(current, previous, mb_r, mb_c);
}
}
}
const int kAqModeCyclicRefresh = 3;
class ActiveMapRefreshTest
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
protected:
ActiveMapRefreshTest() : EncoderTest(GET_PARAM(0)) {}
virtual ~ActiveMapRefreshTest() {}
virtual void SetUp() {
InitializeConfig();
SetMode(GET_PARAM(1));
cpu_used_ = GET_PARAM(2);
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
::libvpx_test::Y4mVideoSource *y4m_video =
static_cast<libvpx_test::Y4mVideoSource *>(video);
if (video->frame() == 1) {
encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
encoder->Control(VP9E_SET_AQ_MODE, kAqModeCyclicRefresh);
} else if (video->frame() >= 2 && video->img()) {
vpx_image_t *current = video->img();
vpx_image_t *previous = y4m_holder_->img();
ASSERT_TRUE(previous != NULL);
vpx_active_map_t map = vpx_active_map_t();
const int width = static_cast<int>(current->d_w);
const int height = static_cast<int>(current->d_h);
const int mb_width = (width + 15) / 16;
const int mb_height = (height + 15) / 16;
uint8_t *active_map = new uint8_t[mb_width * mb_height];
GenerateMap(mb_height, mb_width, *current, *previous, active_map);
map.cols = mb_width;
map.rows = mb_height;
map.active_map = active_map;
encoder->Control(VP8E_SET_ACTIVEMAP, &map);
delete[] active_map;
}
if (video->img()) {
y4m_video->SwapBuffers(y4m_holder_);
}
}
int cpu_used_;
::libvpx_test::Y4mVideoSource *y4m_holder_;
};
TEST_P(ActiveMapRefreshTest, Test) {
cfg_.g_lag_in_frames = 0;
cfg_.g_profile = 1;
cfg_.rc_target_bitrate = 600;
cfg_.rc_resize_allowed = 0;
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 30;
cfg_.g_pass = VPX_RC_ONE_PASS;
cfg_.rc_end_usage = VPX_CBR;
cfg_.kf_max_dist = 90000;
::libvpx_test::Y4mVideoSource video("desktop_credits.y4m", 0, 30);
::libvpx_test::Y4mVideoSource video_holder("desktop_credits.y4m", 0, 30);
video_holder.Begin();
y4m_holder_ = &video_holder;
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
VP9_INSTANTIATE_TEST_CASE(ActiveMapRefreshTest,
::testing::Values(::libvpx_test::kRealTime),
::testing::Range(5, 6));
} // namespace

View File

@ -39,7 +39,6 @@ class ActiveMapTest
encoder->Control(VP8E_SET_CPUUSED, cpu_used_); encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
} else if (video->frame() == 3) { } else if (video->frame() == 3) {
vpx_active_map_t map = vpx_active_map_t(); vpx_active_map_t map = vpx_active_map_t();
/* clang-format off */
uint8_t active_map[9 * 13] = { uint8_t active_map[9 * 13] = {
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
@ -51,7 +50,6 @@ class ActiveMapTest
0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
}; };
/* clang-format on */
map.cols = (kWidth + 15) / 16; map.cols = (kWidth + 15) / 16;
map.rows = (kHeight + 15) / 16; map.rows = (kHeight + 15) / 16;
ASSERT_EQ(map.cols, 13u); ASSERT_EQ(map.cols, 13u);
@ -79,13 +77,13 @@ TEST_P(ActiveMapTest, Test) {
cfg_.rc_end_usage = VPX_CBR; cfg_.rc_end_usage = VPX_CBR;
cfg_.kf_max_dist = 90000; cfg_.kf_max_dist = 90000;
::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30, 1, ::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30,
0, 20); 1, 0, 20);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }
VP9_INSTANTIATE_TEST_CASE(ActiveMapTest, VP9_INSTANTIATE_TEST_CASE(ActiveMapTest,
::testing::Values(::libvpx_test::kRealTime), ::testing::Values(::libvpx_test::kRealTime),
::testing::Range(0, 9)); ::testing::Range(0, 6));
} // namespace } // namespace

View File

@ -1,136 +0,0 @@
/*
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_dsp_rtcd.h"
#include "vpx/vpx_integer.h"
#include "vpx_dsp/postproc.h"
#include "vpx_mem/vpx_mem.h"
namespace {
static const int kNoiseSize = 3072;
// TODO(jimbankoski): make width and height integers not unsigned.
typedef void (*AddNoiseFunc)(uint8_t *start, const int8_t *noise,
int blackclamp, int whiteclamp, int width,
int height, int pitch);
class AddNoiseTest : public ::testing::TestWithParam<AddNoiseFunc> {
public:
virtual void TearDown() { libvpx_test::ClearSystemState(); }
virtual ~AddNoiseTest() {}
};
double stddev6(char a, char b, char c, char d, char e, char f) {
const double n = (a + b + c + d + e + f) / 6.0;
const double v = ((a - n) * (a - n) + (b - n) * (b - n) + (c - n) * (c - n) +
(d - n) * (d - n) + (e - n) * (e - n) + (f - n) * (f - n)) /
6.0;
return sqrt(v);
}
TEST_P(AddNoiseTest, CheckNoiseAdded) {
const int width = 64;
const int height = 64;
const int image_size = width * height;
int8_t noise[kNoiseSize];
const int clamp = vpx_setup_noise(4.4, noise, kNoiseSize);
uint8_t *const s =
reinterpret_cast<uint8_t *>(vpx_calloc(image_size, sizeof(*s)));
ASSERT_TRUE(s != NULL);
memset(s, 99, image_size * sizeof(*s));
ASM_REGISTER_STATE_CHECK(
GetParam()(s, noise, clamp, clamp, width, height, width));
// Check to make sure we don't end up having either the same or no added
// noise either vertically or horizontally.
for (int i = 0; i < image_size - 6 * width - 6; ++i) {
const double hd = stddev6(s[i] - 99, s[i + 1] - 99, s[i + 2] - 99,
s[i + 3] - 99, s[i + 4] - 99, s[i + 5] - 99);
const double vd = stddev6(s[i] - 99, s[i + width] - 99,
s[i + 2 * width] - 99, s[i + 3 * width] - 99,
s[i + 4 * width] - 99, s[i + 5 * width] - 99);
EXPECT_NE(hd, 0);
EXPECT_NE(vd, 0);
}
// Initialize pixels in the image to 255 and check for roll over.
memset(s, 255, image_size);
ASM_REGISTER_STATE_CHECK(
GetParam()(s, noise, clamp, clamp, width, height, width));
// Check to make sure don't roll over.
for (int i = 0; i < image_size; ++i) {
EXPECT_GT(static_cast<int>(s[i]), clamp) << "i = " << i;
}
// Initialize pixels in the image to 0 and check for roll under.
memset(s, 0, image_size);
ASM_REGISTER_STATE_CHECK(
GetParam()(s, noise, clamp, clamp, width, height, width));
// Check to make sure don't roll under.
for (int i = 0; i < image_size; ++i) {
EXPECT_LT(static_cast<int>(s[i]), 255 - clamp) << "i = " << i;
}
vpx_free(s);
}
TEST_P(AddNoiseTest, CheckCvsAssembly) {
const int width = 64;
const int height = 64;
const int image_size = width * height;
int8_t noise[kNoiseSize];
const int clamp = vpx_setup_noise(4.4, noise, kNoiseSize);
uint8_t *const s = reinterpret_cast<uint8_t *>(vpx_calloc(image_size, 1));
uint8_t *const d = reinterpret_cast<uint8_t *>(vpx_calloc(image_size, 1));
ASSERT_TRUE(s != NULL);
ASSERT_TRUE(d != NULL);
memset(s, 99, image_size);
memset(d, 99, image_size);
srand(0);
ASM_REGISTER_STATE_CHECK(
GetParam()(s, noise, clamp, clamp, width, height, width));
srand(0);
ASM_REGISTER_STATE_CHECK(
vpx_plane_add_noise_c(d, noise, clamp, clamp, width, height, width));
for (int i = 0; i < image_size; ++i) {
EXPECT_EQ(static_cast<int>(s[i]), static_cast<int>(d[i])) << "i = " << i;
}
vpx_free(d);
vpx_free(s);
}
INSTANTIATE_TEST_CASE_P(C, AddNoiseTest,
::testing::Values(vpx_plane_add_noise_c));
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(SSE2, AddNoiseTest,
::testing::Values(vpx_plane_add_noise_sse2));
#endif
#if HAVE_MSA
INSTANTIATE_TEST_CASE_P(MSA, AddNoiseTest,
::testing::Values(vpx_plane_add_noise_msa));
#endif
} // namespace

View File

@ -1,157 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"
namespace {
class AltRefAqSegmentTest
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
protected:
AltRefAqSegmentTest() : EncoderTest(GET_PARAM(0)) {}
virtual ~AltRefAqSegmentTest() {}
virtual void SetUp() {
InitializeConfig();
SetMode(GET_PARAM(1));
set_cpu_used_ = GET_PARAM(2);
aq_mode_ = 0;
alt_ref_aq_mode_ = 0;
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
if (video->frame() == 1) {
encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
encoder->Control(VP9E_SET_ALT_REF_AQ, alt_ref_aq_mode_);
encoder->Control(VP9E_SET_AQ_MODE, aq_mode_);
encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 100);
}
}
int set_cpu_used_;
int aq_mode_;
int alt_ref_aq_mode_;
};
// Validate that this ALT_REF_AQ/AQ segmentation mode
// (ALT_REF_AQ=0, AQ=0/no_aq)
// encodes and decodes without a mismatch.
TEST_P(AltRefAqSegmentTest, TestNoMisMatchAltRefAQ0) {
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_VBR;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_target_bitrate = 300;
aq_mode_ = 0;
alt_ref_aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
// Validate that this ALT_REF_AQ/AQ segmentation mode
// (ALT_REF_AQ=0, AQ=1/variance_aq)
// encodes and decodes without a mismatch.
TEST_P(AltRefAqSegmentTest, TestNoMisMatchAltRefAQ1) {
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_VBR;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_target_bitrate = 300;
aq_mode_ = 1;
alt_ref_aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
// Validate that this ALT_REF_AQ/AQ segmentation mode
// (ALT_REF_AQ=0, AQ=2/complexity_aq)
// encodes and decodes without a mismatch.
TEST_P(AltRefAqSegmentTest, TestNoMisMatchAltRefAQ2) {
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_VBR;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_target_bitrate = 300;
aq_mode_ = 2;
alt_ref_aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
// Validate that this ALT_REF_AQ/AQ segmentation mode
// (ALT_REF_AQ=0, AQ=3/cyclicrefresh_aq)
// encodes and decodes without a mismatch.
TEST_P(AltRefAqSegmentTest, TestNoMisMatchAltRefAQ3) {
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_VBR;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_target_bitrate = 300;
aq_mode_ = 3;
alt_ref_aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
// Validate that this ALT_REF_AQ/AQ segmentation mode
// (ALT_REF_AQ=0, AQ=4/equator360_aq)
// encodes and decodes without a mismatch.
TEST_P(AltRefAqSegmentTest, TestNoMisMatchAltRefAQ4) {
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_VBR;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_target_bitrate = 300;
aq_mode_ = 4;
alt_ref_aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
VP9_INSTANTIATE_TEST_CASE(AltRefAqSegmentTest,
::testing::Values(::libvpx_test::kOnePassGood,
::libvpx_test::kTwoPassGood),
::testing::Range(2, 5));
} // namespace

View File

@ -14,14 +14,12 @@
#include "test/util.h" #include "test/util.h"
namespace { namespace {
#if CONFIG_VP8_ENCODER
// lookahead range: [kLookAheadMin, kLookAheadMax). // lookahead range: [kLookAheadMin, kLookAheadMax).
const int kLookAheadMin = 5; const int kLookAheadMin = 5;
const int kLookAheadMax = 26; const int kLookAheadMax = 26;
class AltRefTest : public ::libvpx_test::EncoderTest, class AltRefTest : public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWithParam<int> { public ::libvpx_test::CodecTestWithParam<int> {
protected: protected:
AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {} AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {}
virtual ~AltRefTest() {} virtual ~AltRefTest() {}
@ -31,7 +29,9 @@ class AltRefTest : public ::libvpx_test::EncoderTest,
SetMode(libvpx_test::kTwoPassGood); SetMode(libvpx_test::kTwoPassGood);
} }
virtual void BeginPassHook(unsigned int /*pass*/) { altref_count_ = 0; } virtual void BeginPassHook(unsigned int pass) {
altref_count_ = 0;
}
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
libvpx_test::Encoder *encoder) { libvpx_test::Encoder *encoder) {
@ -63,90 +63,7 @@ TEST_P(AltRefTest, MonotonicTimestamps) {
EXPECT_GE(altref_count(), 1); EXPECT_GE(altref_count(), 1);
} }
VP8_INSTANTIATE_TEST_CASE(AltRefTest, VP8_INSTANTIATE_TEST_CASE(AltRefTest,
::testing::Range(kLookAheadMin, kLookAheadMax)); ::testing::Range(kLookAheadMin, kLookAheadMax));
#endif // CONFIG_VP8_ENCODER
class AltRefForcedKeyTestLarge
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
protected:
AltRefForcedKeyTestLarge()
: EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {}
virtual ~AltRefForcedKeyTestLarge() {}
virtual void SetUp() {
InitializeConfig();
SetMode(encoding_mode_);
cfg_.rc_end_usage = VPX_VBR;
cfg_.g_threads = 0;
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
if (video->frame() == 0) {
encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
#if CONFIG_VP9_ENCODER
// override test default for tile columns if necessary.
if (GET_PARAM(0) == &libvpx_test::kVP9) {
encoder->Control(VP9E_SET_TILE_COLUMNS, 6);
}
#endif
}
frame_flags_ =
(video->frame() == forced_kf_frame_num_) ? VPX_EFLAG_FORCE_KF : 0;
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
if (frame_num_ == forced_kf_frame_num_) {
ASSERT_TRUE(!!(pkt->data.frame.flags & VPX_FRAME_IS_KEY))
<< "Frame #" << frame_num_ << " isn't a keyframe!";
}
++frame_num_;
}
::libvpx_test::TestMode encoding_mode_;
int cpu_used_;
unsigned int forced_kf_frame_num_;
unsigned int frame_num_;
};
TEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) {
const vpx_rational timebase = { 1, 30 };
const int lag_values[] = { 3, 15, 25, -1 };
forced_kf_frame_num_ = 1;
for (int i = 0; lag_values[i] != -1; ++i) {
frame_num_ = 0;
cfg_.g_lag_in_frames = lag_values[i];
libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
timebase.den, timebase.num, 0, 30);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
}
TEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) {
const vpx_rational timebase = { 1, 30 };
const int lag_values[] = { 3, 15, 25, -1 };
for (int i = 0; lag_values[i] != -1; ++i) {
frame_num_ = 0;
forced_kf_frame_num_ = lag_values[i] - 1;
cfg_.g_lag_in_frames = lag_values[i];
libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
timebase.den, timebase.num, 0, 30);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
}
VP8_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
::testing::Values(::libvpx_test::kOnePassGood),
::testing::Range(0, 9));
VP9_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge,
::testing::Values(::libvpx_test::kOnePassGood),
::testing::Range(0, 9));
} // namespace } // namespace

View File

@ -32,7 +32,6 @@ LOCAL_CPP_EXTENSION := .cc
LOCAL_MODULE := gtest LOCAL_MODULE := gtest
LOCAL_C_INCLUDES := $(LOCAL_PATH)/third_party/googletest/src/ LOCAL_C_INCLUDES := $(LOCAL_PATH)/third_party/googletest/src/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/third_party/googletest/src/include/ LOCAL_C_INCLUDES += $(LOCAL_PATH)/third_party/googletest/src/include/
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/third_party/googletest/src/include/
LOCAL_SRC_FILES := ./third_party/googletest/src/src/gtest-all.cc LOCAL_SRC_FILES := ./third_party/googletest/src/src/gtest-all.cc
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
@ -41,17 +40,9 @@ include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm LOCAL_ARM_MODE := arm
LOCAL_MODULE := libvpx_test LOCAL_MODULE := libvpx_test
LOCAL_STATIC_LIBRARIES := gtest libwebm LOCAL_STATIC_LIBRARIES := gtest libwebm
LOCAL_SHARED_LIBRARIES := vpx
ifeq ($(ENABLE_SHARED),1)
LOCAL_SHARED_LIBRARIES := vpx
else
LOCAL_STATIC_LIBRARIES += vpx
endif
include $(LOCAL_PATH)/test/test.mk include $(LOCAL_PATH)/test/test.mk
LOCAL_C_INCLUDES := $(BINDINGS_DIR) LOCAL_C_INCLUDES := $(BINDINGS_DIR)
FILTERED_SRC := $(sort $(filter %.cc %.c, $(LIBVPX_TEST_SRCS-yes))) FILTERED_SRC := $(sort $(filter %.cc %.c, $(LIBVPX_TEST_SRCS-yes)))
LOCAL_SRC_FILES := $(addprefix ./test/, $(FILTERED_SRC)) LOCAL_SRC_FILES := $(addprefix ./test/, $(FILTERED_SRC))
# some test files depend on *_rtcd.h, ensure they're generated first.
$(eval $(call rtcd_dep_template))
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)

View File

@ -57,7 +57,7 @@ TEST_P(AqSegmentTest, TestNoMisMatchAQ1) {
aq_mode_ = 1; aq_mode_ = 1;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100); 30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }
@ -77,7 +77,7 @@ TEST_P(AqSegmentTest, TestNoMisMatchAQ2) {
aq_mode_ = 2; aq_mode_ = 2;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100); 30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }
@ -97,7 +97,7 @@ TEST_P(AqSegmentTest, TestNoMisMatchAQ3) {
aq_mode_ = 3; aq_mode_ = 3;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 100); 30, 1, 0, 100);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }

View File

@ -1,581 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vp9_rtcd.h"
#include "./vpx_config.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/vpx_timer.h"
using libvpx_test::ACMRandom;
namespace {
class AverageTestBase : public ::testing::Test {
public:
AverageTestBase(int width, int height) : width_(width), height_(height) {}
static void SetUpTestCase() {
source_data_ = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBlockSize));
}
static void TearDownTestCase() {
vpx_free(source_data_);
source_data_ = NULL;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
// Handle blocks up to 4 blocks 64x64 with stride up to 128
static const int kDataAlignment = 16;
static const int kDataBlockSize = 64 * 128;
virtual void SetUp() {
source_stride_ = (width_ + 31) & ~31;
rnd_.Reset(ACMRandom::DeterministicSeed());
}
// Sum Pixels
static unsigned int ReferenceAverage8x8(const uint8_t *source, int pitch) {
unsigned int average = 0;
for (int h = 0; h < 8; ++h) {
for (int w = 0; w < 8; ++w) average += source[h * pitch + w];
}
return ((average + 32) >> 6);
}
static unsigned int ReferenceAverage4x4(const uint8_t *source, int pitch) {
unsigned int average = 0;
for (int h = 0; h < 4; ++h) {
for (int w = 0; w < 4; ++w) average += source[h * pitch + w];
}
return ((average + 8) >> 4);
}
void FillConstant(uint8_t fill_constant) {
for (int i = 0; i < width_ * height_; ++i) {
source_data_[i] = fill_constant;
}
}
void FillRandom() {
for (int i = 0; i < width_ * height_; ++i) {
source_data_[i] = rnd_.Rand8();
}
}
int width_, height_;
static uint8_t *source_data_;
int source_stride_;
ACMRandom rnd_;
};
typedef unsigned int (*AverageFunction)(const uint8_t *s, int pitch);
typedef ::testing::tuple<int, int, int, int, AverageFunction> AvgFunc;
class AverageTest : public AverageTestBase,
public ::testing::WithParamInterface<AvgFunc> {
public:
AverageTest() : AverageTestBase(GET_PARAM(0), GET_PARAM(1)) {}
protected:
void CheckAverages() {
const int block_size = GET_PARAM(3);
unsigned int expected = 0;
if (block_size == 8) {
expected =
ReferenceAverage8x8(source_data_ + GET_PARAM(2), source_stride_);
} else if (block_size == 4) {
expected =
ReferenceAverage4x4(source_data_ + GET_PARAM(2), source_stride_);
}
ASM_REGISTER_STATE_CHECK(
GET_PARAM(4)(source_data_ + GET_PARAM(2), source_stride_));
unsigned int actual =
GET_PARAM(4)(source_data_ + GET_PARAM(2), source_stride_);
EXPECT_EQ(expected, actual);
}
};
typedef void (*IntProRowFunc)(int16_t hbuf[16], uint8_t const *ref,
const int ref_stride, const int height);
typedef ::testing::tuple<int, IntProRowFunc, IntProRowFunc> IntProRowParam;
class IntProRowTest : public AverageTestBase,
public ::testing::WithParamInterface<IntProRowParam> {
public:
IntProRowTest()
: AverageTestBase(16, GET_PARAM(0)), hbuf_asm_(NULL), hbuf_c_(NULL) {
asm_func_ = GET_PARAM(1);
c_func_ = GET_PARAM(2);
}
protected:
virtual void SetUp() {
hbuf_asm_ = reinterpret_cast<int16_t *>(
vpx_memalign(kDataAlignment, sizeof(*hbuf_asm_) * 16));
hbuf_c_ = reinterpret_cast<int16_t *>(
vpx_memalign(kDataAlignment, sizeof(*hbuf_c_) * 16));
}
virtual void TearDown() {
vpx_free(hbuf_c_);
hbuf_c_ = NULL;
vpx_free(hbuf_asm_);
hbuf_asm_ = NULL;
}
void RunComparison() {
ASM_REGISTER_STATE_CHECK(c_func_(hbuf_c_, source_data_, 0, height_));
ASM_REGISTER_STATE_CHECK(asm_func_(hbuf_asm_, source_data_, 0, height_));
EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * 16))
<< "Output mismatch";
}
private:
IntProRowFunc asm_func_;
IntProRowFunc c_func_;
int16_t *hbuf_asm_;
int16_t *hbuf_c_;
};
typedef int16_t (*IntProColFunc)(uint8_t const *ref, const int width);
typedef ::testing::tuple<int, IntProColFunc, IntProColFunc> IntProColParam;
class IntProColTest : public AverageTestBase,
public ::testing::WithParamInterface<IntProColParam> {
public:
IntProColTest() : AverageTestBase(GET_PARAM(0), 1), sum_asm_(0), sum_c_(0) {
asm_func_ = GET_PARAM(1);
c_func_ = GET_PARAM(2);
}
protected:
void RunComparison() {
ASM_REGISTER_STATE_CHECK(sum_c_ = c_func_(source_data_, width_));
ASM_REGISTER_STATE_CHECK(sum_asm_ = asm_func_(source_data_, width_));
EXPECT_EQ(sum_c_, sum_asm_) << "Output mismatch";
}
private:
IntProColFunc asm_func_;
IntProColFunc c_func_;
int16_t sum_asm_;
int16_t sum_c_;
};
typedef int (*SatdFunc)(const tran_low_t *coeffs, int length);
typedef ::testing::tuple<int, SatdFunc> SatdTestParam;
class SatdTest : public ::testing::Test,
public ::testing::WithParamInterface<SatdTestParam> {
protected:
virtual void SetUp() {
satd_size_ = GET_PARAM(0);
satd_func_ = GET_PARAM(1);
rnd_.Reset(ACMRandom::DeterministicSeed());
src_ = reinterpret_cast<tran_low_t *>(
vpx_memalign(16, sizeof(*src_) * satd_size_));
ASSERT_TRUE(src_ != NULL);
}
virtual void TearDown() {
libvpx_test::ClearSystemState();
vpx_free(src_);
}
void FillConstant(const tran_low_t val) {
for (int i = 0; i < satd_size_; ++i) src_[i] = val;
}
void FillRandom() {
for (int i = 0; i < satd_size_; ++i) {
const int16_t tmp = rnd_.Rand16();
src_[i] = (tran_low_t)tmp;
}
}
void Check(const int expected) {
int total;
ASM_REGISTER_STATE_CHECK(total = satd_func_(src_, satd_size_));
EXPECT_EQ(expected, total);
}
int satd_size_;
private:
tran_low_t *src_;
SatdFunc satd_func_;
ACMRandom rnd_;
};
typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff,
const tran_low_t *dqcoeff, int block_size);
typedef ::testing::tuple<int, BlockErrorFunc> BlockErrorTestFPParam;
class BlockErrorTestFP
: public ::testing::Test,
public ::testing::WithParamInterface<BlockErrorTestFPParam> {
protected:
virtual void SetUp() {
txfm_size_ = GET_PARAM(0);
block_error_func_ = GET_PARAM(1);
rnd_.Reset(ACMRandom::DeterministicSeed());
coeff_ = reinterpret_cast<tran_low_t *>(
vpx_memalign(16, sizeof(*coeff_) * txfm_size_));
dqcoeff_ = reinterpret_cast<tran_low_t *>(
vpx_memalign(16, sizeof(*dqcoeff_) * txfm_size_));
ASSERT_TRUE(coeff_ != NULL);
ASSERT_TRUE(dqcoeff_ != NULL);
}
virtual void TearDown() {
libvpx_test::ClearSystemState();
vpx_free(coeff_);
vpx_free(dqcoeff_);
}
void FillConstant(const tran_low_t coeff_val, const tran_low_t dqcoeff_val) {
for (int i = 0; i < txfm_size_; ++i) coeff_[i] = coeff_val;
for (int i = 0; i < txfm_size_; ++i) dqcoeff_[i] = dqcoeff_val;
}
void FillRandom() {
// Just two fixed seeds
rnd_.Reset(0xb0b9);
for (int i = 0; i < txfm_size_; ++i) coeff_[i] = rnd_.Rand16() >> 1;
rnd_.Reset(0xb0c8);
for (int i = 0; i < txfm_size_; ++i) dqcoeff_[i] = rnd_.Rand16() >> 1;
}
void Check(const int64_t expected) {
int64_t total;
ASM_REGISTER_STATE_CHECK(
total = block_error_func_(coeff_, dqcoeff_, txfm_size_));
EXPECT_EQ(expected, total);
}
int txfm_size_;
private:
tran_low_t *coeff_;
tran_low_t *dqcoeff_;
BlockErrorFunc block_error_func_;
ACMRandom rnd_;
};
uint8_t *AverageTestBase::source_data_ = NULL;
TEST_P(AverageTest, MinValue) {
FillConstant(0);
CheckAverages();
}
TEST_P(AverageTest, MaxValue) {
FillConstant(255);
CheckAverages();
}
TEST_P(AverageTest, Random) {
// The reference frame, but not the source frame, may be unaligned for
// certain types of searches.
for (int i = 0; i < 1000; i++) {
FillRandom();
CheckAverages();
}
}
TEST_P(IntProRowTest, MinValue) {
FillConstant(0);
RunComparison();
}
TEST_P(IntProRowTest, MaxValue) {
FillConstant(255);
RunComparison();
}
TEST_P(IntProRowTest, Random) {
FillRandom();
RunComparison();
}
TEST_P(IntProColTest, MinValue) {
FillConstant(0);
RunComparison();
}
TEST_P(IntProColTest, MaxValue) {
FillConstant(255);
RunComparison();
}
TEST_P(IntProColTest, Random) {
FillRandom();
RunComparison();
}
TEST_P(SatdTest, MinValue) {
const int kMin = -32640;
const int expected = -kMin * satd_size_;
FillConstant(kMin);
Check(expected);
}
TEST_P(SatdTest, MaxValue) {
const int kMax = 32640;
const int expected = kMax * satd_size_;
FillConstant(kMax);
Check(expected);
}
TEST_P(SatdTest, Random) {
int expected;
switch (satd_size_) {
case 16: expected = 205298; break;
case 64: expected = 1113950; break;
case 256: expected = 4268415; break;
case 1024: expected = 16954082; break;
default:
FAIL() << "Invalid satd size (" << satd_size_
<< ") valid: 16/64/256/1024";
}
FillRandom();
Check(expected);
}
TEST_P(SatdTest, DISABLED_Speed) {
const int kCountSpeedTestBlock = 20000;
vpx_usec_timer timer;
DECLARE_ALIGNED(16, tran_low_t, coeff[1024]);
const int blocksize = GET_PARAM(0);
vpx_usec_timer_start(&timer);
for (int i = 0; i < kCountSpeedTestBlock; ++i) {
GET_PARAM(1)(coeff, blocksize);
}
vpx_usec_timer_mark(&timer);
const int elapsed_time = static_cast<int>(vpx_usec_timer_elapsed(&timer));
printf("blocksize: %4d time: %4d us\n", blocksize, elapsed_time);
}
TEST_P(BlockErrorTestFP, MinValue) {
const int64_t kMin = -32640;
const int64_t expected = kMin * kMin * txfm_size_;
FillConstant(kMin, 0);
Check(expected);
}
TEST_P(BlockErrorTestFP, MaxValue) {
const int64_t kMax = 32640;
const int64_t expected = kMax * kMax * txfm_size_;
FillConstant(kMax, 0);
Check(expected);
}
TEST_P(BlockErrorTestFP, Random) {
int64_t expected;
switch (txfm_size_) {
case 16: expected = 2051681432; break;
case 64: expected = 11075114379; break;
case 256: expected = 44386271116; break;
case 1024: expected = 184774996089; break;
default:
FAIL() << "Invalid satd size (" << txfm_size_
<< ") valid: 16/64/256/1024";
}
FillRandom();
Check(expected);
}
TEST_P(BlockErrorTestFP, DISABLED_Speed) {
const int kCountSpeedTestBlock = 20000;
vpx_usec_timer timer;
DECLARE_ALIGNED(16, tran_low_t, coeff[1024]);
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[1024]);
const int blocksize = GET_PARAM(0);
vpx_usec_timer_start(&timer);
for (int i = 0; i < kCountSpeedTestBlock; ++i) {
GET_PARAM(1)(coeff, dqcoeff, blocksize);
}
vpx_usec_timer_mark(&timer);
const int elapsed_time = static_cast<int>(vpx_usec_timer_elapsed(&timer));
printf("blocksize: %4d time: %4d us\n", blocksize, elapsed_time);
}
using ::testing::make_tuple;
INSTANTIATE_TEST_CASE_P(
C, AverageTest,
::testing::Values(make_tuple(16, 16, 1, 8, &vpx_avg_8x8_c),
make_tuple(16, 16, 1, 4, &vpx_avg_4x4_c)));
INSTANTIATE_TEST_CASE_P(C, SatdTest,
::testing::Values(make_tuple(16, &vpx_satd_c),
make_tuple(64, &vpx_satd_c),
make_tuple(256, &vpx_satd_c),
make_tuple(1024, &vpx_satd_c)));
INSTANTIATE_TEST_CASE_P(
C, BlockErrorTestFP,
::testing::Values(make_tuple(16, &vp9_block_error_fp_c),
make_tuple(64, &vp9_block_error_fp_c),
make_tuple(256, &vp9_block_error_fp_c),
make_tuple(1024, &vp9_block_error_fp_c)));
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
SSE2, AverageTest,
::testing::Values(make_tuple(16, 16, 0, 8, &vpx_avg_8x8_sse2),
make_tuple(16, 16, 5, 8, &vpx_avg_8x8_sse2),
make_tuple(32, 32, 15, 8, &vpx_avg_8x8_sse2),
make_tuple(16, 16, 0, 4, &vpx_avg_4x4_sse2),
make_tuple(16, 16, 5, 4, &vpx_avg_4x4_sse2),
make_tuple(32, 32, 15, 4, &vpx_avg_4x4_sse2)));
INSTANTIATE_TEST_CASE_P(
SSE2, IntProRowTest,
::testing::Values(make_tuple(16, &vpx_int_pro_row_sse2, &vpx_int_pro_row_c),
make_tuple(32, &vpx_int_pro_row_sse2, &vpx_int_pro_row_c),
make_tuple(64, &vpx_int_pro_row_sse2,
&vpx_int_pro_row_c)));
INSTANTIATE_TEST_CASE_P(
SSE2, IntProColTest,
::testing::Values(make_tuple(16, &vpx_int_pro_col_sse2, &vpx_int_pro_col_c),
make_tuple(32, &vpx_int_pro_col_sse2, &vpx_int_pro_col_c),
make_tuple(64, &vpx_int_pro_col_sse2,
&vpx_int_pro_col_c)));
INSTANTIATE_TEST_CASE_P(SSE2, SatdTest,
::testing::Values(make_tuple(16, &vpx_satd_sse2),
make_tuple(64, &vpx_satd_sse2),
make_tuple(256, &vpx_satd_sse2),
make_tuple(1024, &vpx_satd_sse2)));
INSTANTIATE_TEST_CASE_P(
SSE2, BlockErrorTestFP,
::testing::Values(make_tuple(16, &vp9_block_error_fp_sse2),
make_tuple(64, &vp9_block_error_fp_sse2),
make_tuple(256, &vp9_block_error_fp_sse2),
make_tuple(1024, &vp9_block_error_fp_sse2)));
#endif // HAVE_SSE2
#if HAVE_AVX2
INSTANTIATE_TEST_CASE_P(AVX2, SatdTest,
::testing::Values(make_tuple(16, &vpx_satd_avx2),
make_tuple(64, &vpx_satd_avx2),
make_tuple(256, &vpx_satd_avx2),
make_tuple(1024, &vpx_satd_avx2)));
INSTANTIATE_TEST_CASE_P(
AVX2, BlockErrorTestFP,
::testing::Values(make_tuple(16, &vp9_block_error_fp_avx2),
make_tuple(64, &vp9_block_error_fp_avx2),
make_tuple(256, &vp9_block_error_fp_avx2),
make_tuple(1024, &vp9_block_error_fp_avx2)));
#endif
#if HAVE_NEON
INSTANTIATE_TEST_CASE_P(
NEON, AverageTest,
::testing::Values(make_tuple(16, 16, 0, 8, &vpx_avg_8x8_neon),
make_tuple(16, 16, 5, 8, &vpx_avg_8x8_neon),
make_tuple(32, 32, 15, 8, &vpx_avg_8x8_neon),
make_tuple(16, 16, 0, 4, &vpx_avg_4x4_neon),
make_tuple(16, 16, 5, 4, &vpx_avg_4x4_neon),
make_tuple(32, 32, 15, 4, &vpx_avg_4x4_neon)));
INSTANTIATE_TEST_CASE_P(
NEON, IntProRowTest,
::testing::Values(make_tuple(16, &vpx_int_pro_row_neon, &vpx_int_pro_row_c),
make_tuple(32, &vpx_int_pro_row_neon, &vpx_int_pro_row_c),
make_tuple(64, &vpx_int_pro_row_neon,
&vpx_int_pro_row_c)));
INSTANTIATE_TEST_CASE_P(
NEON, IntProColTest,
::testing::Values(make_tuple(16, &vpx_int_pro_col_neon, &vpx_int_pro_col_c),
make_tuple(32, &vpx_int_pro_col_neon, &vpx_int_pro_col_c),
make_tuple(64, &vpx_int_pro_col_neon,
&vpx_int_pro_col_c)));
INSTANTIATE_TEST_CASE_P(NEON, SatdTest,
::testing::Values(make_tuple(16, &vpx_satd_neon),
make_tuple(64, &vpx_satd_neon),
make_tuple(256, &vpx_satd_neon),
make_tuple(1024, &vpx_satd_neon)));
// TODO(jianj): Remove the highbitdepth flag once the SIMD functions are
// in place.
#if !CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
NEON, BlockErrorTestFP,
::testing::Values(make_tuple(16, &vp9_block_error_fp_neon),
make_tuple(64, &vp9_block_error_fp_neon),
make_tuple(256, &vp9_block_error_fp_neon),
make_tuple(1024, &vp9_block_error_fp_neon)));
#endif // !CONFIG_VP9_HIGHBITDEPTH
#endif // HAVE_NEON
#if HAVE_MSA
INSTANTIATE_TEST_CASE_P(
MSA, AverageTest,
::testing::Values(make_tuple(16, 16, 0, 8, &vpx_avg_8x8_msa),
make_tuple(16, 16, 5, 8, &vpx_avg_8x8_msa),
make_tuple(32, 32, 15, 8, &vpx_avg_8x8_msa),
make_tuple(16, 16, 0, 4, &vpx_avg_4x4_msa),
make_tuple(16, 16, 5, 4, &vpx_avg_4x4_msa),
make_tuple(32, 32, 15, 4, &vpx_avg_4x4_msa)));
INSTANTIATE_TEST_CASE_P(
MSA, IntProRowTest,
::testing::Values(make_tuple(16, &vpx_int_pro_row_msa, &vpx_int_pro_row_c),
make_tuple(32, &vpx_int_pro_row_msa, &vpx_int_pro_row_c),
make_tuple(64, &vpx_int_pro_row_msa,
&vpx_int_pro_row_c)));
INSTANTIATE_TEST_CASE_P(
MSA, IntProColTest,
::testing::Values(make_tuple(16, &vpx_int_pro_col_msa, &vpx_int_pro_col_c),
make_tuple(32, &vpx_int_pro_col_msa, &vpx_int_pro_col_c),
make_tuple(64, &vpx_int_pro_col_msa,
&vpx_int_pro_col_c)));
// TODO(jingning): Remove the highbitdepth flag once the SIMD functions are
// in place.
#if !CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(MSA, SatdTest,
::testing::Values(make_tuple(16, &vpx_satd_msa),
make_tuple(64, &vpx_satd_msa),
make_tuple(256, &vpx_satd_msa),
make_tuple(1024, &vpx_satd_msa)));
#endif // !CONFIG_VP9_HIGHBITDEPTH
#endif // HAVE_MSA
} // namespace

View File

@ -1,223 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h"
#if CONFIG_VP9_ENCODER
#include "./vp9_rtcd.h"
#endif
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vpx_mem/vpx_mem.h"
extern "C" double vp9_get_blockiness(const unsigned char *img1, int img1_pitch,
const unsigned char *img2, int img2_pitch,
int width, int height);
using libvpx_test::ACMRandom;
namespace {
class BlockinessTestBase : public ::testing::Test {
public:
BlockinessTestBase(int width, int height) : width_(width), height_(height) {}
static void SetUpTestCase() {
source_data_ = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
reference_data_ = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
}
static void TearDownTestCase() {
vpx_free(source_data_);
source_data_ = NULL;
vpx_free(reference_data_);
reference_data_ = NULL;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
// Handle frames up to 640x480
static const int kDataAlignment = 16;
static const int kDataBufferSize = 640 * 480;
virtual void SetUp() {
source_stride_ = (width_ + 31) & ~31;
reference_stride_ = width_ * 2;
rnd_.Reset(ACMRandom::DeterministicSeed());
}
void FillConstant(uint8_t *data, int stride, uint8_t fill_constant, int width,
int height) {
for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) {
data[h * stride + w] = fill_constant;
}
}
}
void FillConstant(uint8_t *data, int stride, uint8_t fill_constant) {
FillConstant(data, stride, fill_constant, width_, height_);
}
void FillRandom(uint8_t *data, int stride, int width, int height) {
for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) {
data[h * stride + w] = rnd_.Rand8();
}
}
}
void FillRandom(uint8_t *data, int stride) {
FillRandom(data, stride, width_, height_);
}
void FillRandomBlocky(uint8_t *data, int stride) {
for (int h = 0; h < height_; h += 4) {
for (int w = 0; w < width_; w += 4) {
FillRandom(data + h * stride + w, stride, 4, 4);
}
}
}
void FillCheckerboard(uint8_t *data, int stride) {
for (int h = 0; h < height_; h += 4) {
for (int w = 0; w < width_; w += 4) {
if (((h / 4) ^ (w / 4)) & 1) {
FillConstant(data + h * stride + w, stride, 255, 4, 4);
} else {
FillConstant(data + h * stride + w, stride, 0, 4, 4);
}
}
}
}
void Blur(uint8_t *data, int stride, int taps) {
int sum = 0;
int half_taps = taps / 2;
for (int h = 0; h < height_; ++h) {
for (int w = 0; w < taps; ++w) {
sum += data[w + h * stride];
}
for (int w = taps; w < width_; ++w) {
sum += data[w + h * stride] - data[w - taps + h * stride];
data[w - half_taps + h * stride] = (sum + half_taps) / taps;
}
}
for (int w = 0; w < width_; ++w) {
for (int h = 0; h < taps; ++h) {
sum += data[h + w * stride];
}
for (int h = taps; h < height_; ++h) {
sum += data[w + h * stride] - data[(h - taps) * stride + w];
data[(h - half_taps) * stride + w] = (sum + half_taps) / taps;
}
}
}
int width_, height_;
static uint8_t *source_data_;
int source_stride_;
static uint8_t *reference_data_;
int reference_stride_;
ACMRandom rnd_;
};
#if CONFIG_VP9_ENCODER
typedef ::testing::tuple<int, int> BlockinessParam;
class BlockinessVP9Test
: public BlockinessTestBase,
public ::testing::WithParamInterface<BlockinessParam> {
public:
BlockinessVP9Test() : BlockinessTestBase(GET_PARAM(0), GET_PARAM(1)) {}
protected:
double GetBlockiness() const {
return vp9_get_blockiness(source_data_, source_stride_, reference_data_,
reference_stride_, width_, height_);
}
};
#endif // CONFIG_VP9_ENCODER
uint8_t *BlockinessTestBase::source_data_ = NULL;
uint8_t *BlockinessTestBase::reference_data_ = NULL;
#if CONFIG_VP9_ENCODER
TEST_P(BlockinessVP9Test, SourceBlockierThanReference) {
// Source is blockier than reference.
FillRandomBlocky(source_data_, source_stride_);
FillConstant(reference_data_, reference_stride_, 128);
const double super_blocky = GetBlockiness();
EXPECT_DOUBLE_EQ(0.0, super_blocky)
<< "Blocky source should produce 0 blockiness.";
}
TEST_P(BlockinessVP9Test, ReferenceBlockierThanSource) {
// Source is blockier than reference.
FillConstant(source_data_, source_stride_, 128);
FillRandomBlocky(reference_data_, reference_stride_);
const double super_blocky = GetBlockiness();
EXPECT_GT(super_blocky, 0.0)
<< "Blocky reference should score high for blockiness.";
}
TEST_P(BlockinessVP9Test, BlurringDecreasesBlockiness) {
// Source is blockier than reference.
FillConstant(source_data_, source_stride_, 128);
FillRandomBlocky(reference_data_, reference_stride_);
const double super_blocky = GetBlockiness();
Blur(reference_data_, reference_stride_, 4);
const double less_blocky = GetBlockiness();
EXPECT_GT(super_blocky, less_blocky)
<< "A straight blur should decrease blockiness.";
}
TEST_P(BlockinessVP9Test, WorstCaseBlockiness) {
// Source is blockier than reference.
FillConstant(source_data_, source_stride_, 128);
FillCheckerboard(reference_data_, reference_stride_);
const double super_blocky = GetBlockiness();
Blur(reference_data_, reference_stride_, 4);
const double less_blocky = GetBlockiness();
EXPECT_GT(super_blocky, less_blocky)
<< "A straight blur should decrease blockiness.";
}
#endif // CONFIG_VP9_ENCODER
using ::testing::make_tuple;
//------------------------------------------------------------------------------
// C functions
#if CONFIG_VP9_ENCODER
const BlockinessParam c_vp9_tests[] = {
make_tuple(320, 240), make_tuple(318, 242), make_tuple(318, 238)
};
INSTANTIATE_TEST_CASE_P(C, BlockinessVP9Test, ::testing::ValuesIn(c_vp9_tests));
#endif
} // namespace

View File

@ -17,9 +17,8 @@
namespace { namespace {
class BordersTest class BordersTest : public ::libvpx_test::EncoderTest,
: public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
protected: protected:
BordersTest() : EncoderTest(GET_PARAM(0)) {} BordersTest() : EncoderTest(GET_PARAM(0)) {}
virtual ~BordersTest() {} virtual ~BordersTest() {}
@ -53,7 +52,7 @@ TEST_P(BordersTest, TestEncodeHighBitrate) {
// extend into the border and test the border condition. // extend into the border and test the border condition.
cfg_.g_lag_in_frames = 25; cfg_.g_lag_in_frames = 25;
cfg_.rc_2pass_vbr_minsection_pct = 5; cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 2000; cfg_.rc_target_bitrate = 2000;
cfg_.rc_max_quantizer = 10; cfg_.rc_max_quantizer = 10;
@ -79,6 +78,6 @@ TEST_P(BordersTest, TestLowBitrate) {
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }
VP9_INSTANTIATE_TEST_CASE(BordersTest, VP9_INSTANTIATE_TEST_CASE(BordersTest, ::testing::Values(
::testing::Values(::libvpx_test::kTwoPassGood)); ::libvpx_test::kTwoPassGood));
} // namespace } // namespace

View File

@ -1,382 +0,0 @@
/*
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef TEST_BUFFER_H_
#define TEST_BUFFER_H_
#include <stdio.h>
#include <limits>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "vpx/vpx_integer.h"
#include "vpx_mem/vpx_mem.h"
namespace libvpx_test {
template <typename T>
class Buffer {
public:
Buffer(int width, int height, int top_padding, int left_padding,
int right_padding, int bottom_padding)
: width_(width), height_(height), top_padding_(top_padding),
left_padding_(left_padding), right_padding_(right_padding),
bottom_padding_(bottom_padding), alignment_(0), padding_value_(0),
stride_(0), raw_size_(0), num_elements_(0), raw_buffer_(NULL) {}
Buffer(int width, int height, int top_padding, int left_padding,
int right_padding, int bottom_padding, unsigned int alignment)
: width_(width), height_(height), top_padding_(top_padding),
left_padding_(left_padding), right_padding_(right_padding),
bottom_padding_(bottom_padding), alignment_(alignment),
padding_value_(0), stride_(0), raw_size_(0), num_elements_(0),
raw_buffer_(NULL) {}
Buffer(int width, int height, int padding)
: width_(width), height_(height), top_padding_(padding),
left_padding_(padding), right_padding_(padding),
bottom_padding_(padding), alignment_(0), padding_value_(0), stride_(0),
raw_size_(0), num_elements_(0), raw_buffer_(NULL) {}
Buffer(int width, int height, int padding, unsigned int alignment)
: width_(width), height_(height), top_padding_(padding),
left_padding_(padding), right_padding_(padding),
bottom_padding_(padding), alignment_(alignment), padding_value_(0),
stride_(0), raw_size_(0), num_elements_(0), raw_buffer_(NULL) {}
~Buffer() {
if (alignment_) {
vpx_free(raw_buffer_);
} else {
delete[] raw_buffer_;
}
}
T *TopLeftPixel() const;
int stride() const { return stride_; }
// Set the buffer (excluding padding) to 'value'.
void Set(const T value);
// Set the buffer (excluding padding) to the output of ACMRandom function
// 'rand_func'.
void Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)());
// Set the buffer (excluding padding) to the output of ACMRandom function
// 'RandRange' with range 'low' to 'high' which typically must be within
// testing::internal::Random::kMaxRange (1u << 31). However, because we want
// to allow negative low (and high) values, it is restricted to INT32_MAX
// here.
void Set(ACMRandom *rand_class, const T low, const T high);
// Copy the contents of Buffer 'a' (excluding padding).
void CopyFrom(const Buffer<T> &a);
void DumpBuffer() const;
// Highlight the differences between two buffers if they are the same size.
void PrintDifference(const Buffer<T> &a) const;
bool HasPadding() const;
// Sets all the values in the buffer to 'padding_value'.
void SetPadding(const T padding_value);
// Checks if all the values (excluding padding) are equal to 'value' if the
// Buffers are the same size.
bool CheckValues(const T value) const;
// Check that padding matches the expected value or there is no padding.
bool CheckPadding() const;
// Compare the non-padding portion of two buffers if they are the same size.
bool CheckValues(const Buffer<T> &a) const;
bool Init() {
if (raw_buffer_ != NULL) return false;
EXPECT_GT(width_, 0);
EXPECT_GT(height_, 0);
EXPECT_GE(top_padding_, 0);
EXPECT_GE(left_padding_, 0);
EXPECT_GE(right_padding_, 0);
EXPECT_GE(bottom_padding_, 0);
stride_ = left_padding_ + width_ + right_padding_;
num_elements_ = stride_ * (top_padding_ + height_ + bottom_padding_);
raw_size_ = num_elements_ * sizeof(T);
if (alignment_) {
EXPECT_GE(alignment_, sizeof(T));
// Ensure alignment of the first value will be preserved.
EXPECT_EQ((left_padding_ * sizeof(T)) % alignment_, 0u);
// Ensure alignment of the subsequent rows will be preserved when there is
// a stride.
if (stride_ != width_) {
EXPECT_EQ((stride_ * sizeof(T)) % alignment_, 0u);
}
raw_buffer_ = reinterpret_cast<T *>(vpx_memalign(alignment_, raw_size_));
} else {
raw_buffer_ = new (std::nothrow) T[num_elements_];
}
EXPECT_TRUE(raw_buffer_ != NULL);
SetPadding(std::numeric_limits<T>::max());
return !::testing::Test::HasFailure();
}
private:
bool BufferSizesMatch(const Buffer<T> &a) const;
const int width_;
const int height_;
const int top_padding_;
const int left_padding_;
const int right_padding_;
const int bottom_padding_;
const unsigned int alignment_;
T padding_value_;
int stride_;
int raw_size_;
int num_elements_;
T *raw_buffer_;
};
template <typename T>
T *Buffer<T>::TopLeftPixel() const {
if (!raw_buffer_) return NULL;
return raw_buffer_ + (top_padding_ * stride_) + left_padding_;
}
template <typename T>
void Buffer<T>::Set(const T value) {
if (!raw_buffer_) return;
T *src = TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
src[width] = value;
}
src += stride_;
}
}
template <typename T>
void Buffer<T>::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) {
if (!raw_buffer_) return;
T *src = TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
src[width] = (*rand_class.*rand_func)();
}
src += stride_;
}
}
template <typename T>
void Buffer<T>::Set(ACMRandom *rand_class, const T low, const T high) {
if (!raw_buffer_) return;
EXPECT_LE(low, high);
EXPECT_LE(static_cast<int64_t>(high) - low,
std::numeric_limits<int32_t>::max());
T *src = TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
// 'low' will be promoted to unsigned given the return type of RandRange.
// Store the value as an int to avoid unsigned overflow warnings when
// 'low' is negative.
const int32_t value =
static_cast<int32_t>((*rand_class).RandRange(high - low));
src[width] = static_cast<T>(value + low);
}
src += stride_;
}
}
template <typename T>
void Buffer<T>::CopyFrom(const Buffer<T> &a) {
if (!raw_buffer_) return;
if (!BufferSizesMatch(a)) return;
T *a_src = a.TopLeftPixel();
T *b_src = this->TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
b_src[width] = a_src[width];
}
a_src += a.stride();
b_src += this->stride();
}
}
template <typename T>
void Buffer<T>::DumpBuffer() const {
if (!raw_buffer_) return;
for (int height = 0; height < height_ + top_padding_ + bottom_padding_;
++height) {
for (int width = 0; width < stride_; ++width) {
printf("%4d", raw_buffer_[height + width * stride_]);
}
printf("\n");
}
}
template <typename T>
bool Buffer<T>::HasPadding() const {
if (!raw_buffer_) return false;
return top_padding_ || left_padding_ || right_padding_ || bottom_padding_;
}
template <typename T>
void Buffer<T>::PrintDifference(const Buffer<T> &a) const {
if (!raw_buffer_) return;
if (!BufferSizesMatch(a)) return;
T *a_src = a.TopLeftPixel();
T *b_src = TopLeftPixel();
printf("This buffer:\n");
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
if (a_src[width] != b_src[width]) {
printf("*%3d", b_src[width]);
} else {
printf("%4d", b_src[width]);
}
}
printf("\n");
a_src += a.stride();
b_src += this->stride();
}
a_src = a.TopLeftPixel();
b_src = TopLeftPixel();
printf("Reference buffer:\n");
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
if (a_src[width] != b_src[width]) {
printf("*%3d", a_src[width]);
} else {
printf("%4d", a_src[width]);
}
}
printf("\n");
a_src += a.stride();
b_src += this->stride();
}
}
template <typename T>
void Buffer<T>::SetPadding(const T padding_value) {
if (!raw_buffer_) return;
padding_value_ = padding_value;
T *src = raw_buffer_;
for (int i = 0; i < num_elements_; ++i) {
src[i] = padding_value;
}
}
template <typename T>
bool Buffer<T>::CheckValues(const T value) const {
if (!raw_buffer_) return false;
T *src = TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
if (value != src[width]) {
return false;
}
}
src += stride_;
}
return true;
}
template <typename T>
bool Buffer<T>::CheckPadding() const {
if (!raw_buffer_) return false;
if (!HasPadding()) return true;
// Top padding.
T const *top = raw_buffer_;
for (int i = 0; i < stride_ * top_padding_; ++i) {
if (padding_value_ != top[i]) {
return false;
}
}
// Left padding.
T const *left = TopLeftPixel() - left_padding_;
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < left_padding_; ++width) {
if (padding_value_ != left[width]) {
return false;
}
}
left += stride_;
}
// Right padding.
T const *right = TopLeftPixel() + width_;
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < right_padding_; ++width) {
if (padding_value_ != right[width]) {
return false;
}
}
right += stride_;
}
// Bottom padding
T const *bottom = raw_buffer_ + (top_padding_ + height_) * stride_;
for (int i = 0; i < stride_ * bottom_padding_; ++i) {
if (padding_value_ != bottom[i]) {
return false;
}
}
return true;
}
template <typename T>
bool Buffer<T>::CheckValues(const Buffer<T> &a) const {
if (!raw_buffer_) return false;
if (!BufferSizesMatch(a)) return false;
T *a_src = a.TopLeftPixel();
T *b_src = this->TopLeftPixel();
for (int height = 0; height < height_; ++height) {
for (int width = 0; width < width_; ++width) {
if (a_src[width] != b_src[width]) {
return false;
}
}
a_src += a.stride();
b_src += this->stride();
}
return true;
}
template <typename T>
bool Buffer<T>::BufferSizesMatch(const Buffer<T> &a) const {
if (!raw_buffer_) return false;
if (a.width_ != this->width_ || a.height_ != this->height_) {
printf(
"Reference buffer of size %dx%d does not match this buffer which is "
"size %dx%d\n",
a.width_, a.height_, this->width_, this->height_);
return false;
}
return true;
}
} // namespace libvpx_test
#endif // TEST_BUFFER_H_

View File

@ -1,184 +0,0 @@
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <string>
#include "./vpx_config.h"
#include "test/codec_factory.h"
#include "test/decode_test_driver.h"
#include "test/md5_helper.h"
#include "test/util.h"
#if CONFIG_WEBM_IO
#include "test/webm_video_source.h"
#endif
namespace {
#if CONFIG_WEBM_IO
const int kLegacyByteAlignment = 0;
const int kLegacyYPlaneByteAlignment = 32;
const int kNumPlanesToCheck = 3;
const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
const char kVP9Md5File[] = "vp90-2-02-size-lf-1920x1080.webm.md5";
struct ByteAlignmentTestParam {
int byte_alignment;
vpx_codec_err_t expected_value;
bool decode_remaining;
};
const ByteAlignmentTestParam kBaTestParams[] = {
{ kLegacyByteAlignment, VPX_CODEC_OK, true },
{ 32, VPX_CODEC_OK, true },
{ 64, VPX_CODEC_OK, true },
{ 128, VPX_CODEC_OK, true },
{ 256, VPX_CODEC_OK, true },
{ 512, VPX_CODEC_OK, true },
{ 1024, VPX_CODEC_OK, true },
{ 1, VPX_CODEC_INVALID_PARAM, false },
{ -2, VPX_CODEC_INVALID_PARAM, false },
{ 4, VPX_CODEC_INVALID_PARAM, false },
{ 16, VPX_CODEC_INVALID_PARAM, false },
{ 255, VPX_CODEC_INVALID_PARAM, false },
{ 2048, VPX_CODEC_INVALID_PARAM, false },
};
// Class for testing byte alignment of reference buffers.
class ByteAlignmentTest
: public ::testing::TestWithParam<ByteAlignmentTestParam> {
protected:
ByteAlignmentTest() : video_(NULL), decoder_(NULL), md5_file_(NULL) {}
virtual void SetUp() {
video_ = new libvpx_test::WebMVideoSource(kVP9TestFile);
ASSERT_TRUE(video_ != NULL);
video_->Init();
video_->Begin();
const vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
decoder_ = new libvpx_test::VP9Decoder(cfg, 0);
ASSERT_TRUE(decoder_ != NULL);
OpenMd5File(kVP9Md5File);
}
virtual void TearDown() {
if (md5_file_ != NULL) fclose(md5_file_);
delete decoder_;
delete video_;
}
void SetByteAlignment(int byte_alignment, vpx_codec_err_t expected_value) {
decoder_->Control(VP9_SET_BYTE_ALIGNMENT, byte_alignment, expected_value);
}
vpx_codec_err_t DecodeOneFrame(int byte_alignment_to_check) {
const vpx_codec_err_t res =
decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
CheckDecodedFrames(byte_alignment_to_check);
if (res == VPX_CODEC_OK) video_->Next();
return res;
}
vpx_codec_err_t DecodeRemainingFrames(int byte_alignment_to_check) {
for (; video_->cxdata() != NULL; video_->Next()) {
const vpx_codec_err_t res =
decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
if (res != VPX_CODEC_OK) return res;
CheckDecodedFrames(byte_alignment_to_check);
}
return VPX_CODEC_OK;
}
private:
// Check if |data| is aligned to |byte_alignment_to_check|.
// |byte_alignment_to_check| must be a power of 2.
void CheckByteAlignment(const uint8_t *data, int byte_alignment_to_check) {
ASSERT_EQ(0u, reinterpret_cast<size_t>(data) % byte_alignment_to_check);
}
// Iterate through the planes of the decoded frames and check for
// alignment based off |byte_alignment_to_check|.
void CheckDecodedFrames(int byte_alignment_to_check) {
libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData();
const vpx_image_t *img;
// Get decompressed data
while ((img = dec_iter.Next()) != NULL) {
if (byte_alignment_to_check == kLegacyByteAlignment) {
CheckByteAlignment(img->planes[0], kLegacyYPlaneByteAlignment);
} else {
for (int i = 0; i < kNumPlanesToCheck; ++i) {
CheckByteAlignment(img->planes[i], byte_alignment_to_check);
}
}
CheckMd5(*img);
}
}
// TODO(fgalligan): Move the MD5 testing code into another class.
void OpenMd5File(const std::string &md5_file_name_) {
md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
ASSERT_TRUE(md5_file_ != NULL)
<< "MD5 file open failed. Filename: " << md5_file_name_;
}
void CheckMd5(const vpx_image_t &img) {
ASSERT_TRUE(md5_file_ != NULL);
char expected_md5[33];
char junk[128];
// Read correct md5 checksums.
const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
ASSERT_NE(EOF, res) << "Read md5 data failed";
expected_md5[32] = '\0';
::libvpx_test::MD5 md5_res;
md5_res.Add(&img);
const char *const actual_md5 = md5_res.Get();
// Check md5 match.
ASSERT_STREQ(expected_md5, actual_md5) << "MD5 checksums don't match";
}
libvpx_test::WebMVideoSource *video_;
libvpx_test::VP9Decoder *decoder_;
FILE *md5_file_;
};
TEST_F(ByteAlignmentTest, SwitchByteAlignment) {
const int num_elements = 14;
const int byte_alignments[] = { 0, 32, 64, 128, 256, 512, 1024,
0, 1024, 32, 512, 64, 256, 128 };
for (int i = 0; i < num_elements; ++i) {
SetByteAlignment(byte_alignments[i], VPX_CODEC_OK);
ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame(byte_alignments[i]));
}
SetByteAlignment(byte_alignments[0], VPX_CODEC_OK);
ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames(byte_alignments[0]));
}
TEST_P(ByteAlignmentTest, TestAlignment) {
const ByteAlignmentTestParam t = GetParam();
SetByteAlignment(t.byte_alignment, t.expected_value);
if (t.decode_remaining) {
ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames(t.byte_alignment));
}
}
INSTANTIATE_TEST_CASE_P(Alignments, ByteAlignmentTest,
::testing::ValuesIn(kBaTestParams));
#endif // CONFIG_WEBM_IO
} // namespace

View File

@ -11,13 +11,19 @@
#define TEST_CLEAR_SYSTEM_STATE_H_ #define TEST_CLEAR_SYSTEM_STATE_H_
#include "./vpx_config.h" #include "./vpx_config.h"
#include "vpx_ports/system_state.h" #if ARCH_X86 || ARCH_X86_64
# include "vpx_ports/x86.h"
#endif
namespace libvpx_test { namespace libvpx_test {
// Reset system to a known state. This function should be used for all non-API // Reset system to a known state. This function should be used for all non-API
// test cases. // test cases.
inline void ClearSystemState() { vpx_clear_system_state(); } inline void ClearSystemState() {
#if ARCH_X86 || ARCH_X86_64
vpx_reset_mmx_state();
#endif
}
} // namespace libvpx_test } // namespace libvpx_test
#endif // TEST_CLEAR_SYSTEM_STATE_H_ #endif // TEST_CLEAR_SYSTEM_STATE_H_

View File

@ -32,12 +32,10 @@ class CodecFactory {
virtual ~CodecFactory() {} virtual ~CodecFactory() {}
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const = 0; virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
unsigned long deadline) const = 0;
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
const vpx_codec_flags_t flags) const = 0;
virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg,
unsigned long deadline, unsigned long deadline,
const unsigned long init_flags, const unsigned long init_flags,
TwopassStatsStore *stats) const = 0; TwopassStatsStore *stats) const = 0;
@ -50,25 +48,20 @@ class CodecFactory {
* to avoid having to include a pointer to the CodecFactory in every test * to avoid having to include a pointer to the CodecFactory in every test
* definition. * definition.
*/ */
template <class T1> template<class T1>
class CodecTestWithParam class CodecTestWithParam : public ::testing::TestWithParam<
: public ::testing::TestWithParam< std::tr1::tuple< const libvpx_test::CodecFactory*, T1 > > {
::testing::tuple<const libvpx_test::CodecFactory *, T1> > {}; };
template <class T1, class T2> template<class T1, class T2>
class CodecTestWith2Params class CodecTestWith2Params : public ::testing::TestWithParam<
: public ::testing::TestWithParam< std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2 > > {
::testing::tuple<const libvpx_test::CodecFactory *, T1, T2> > {}; };
template <class T1, class T2, class T3> template<class T1, class T2, class T3>
class CodecTestWith3Params class CodecTestWith3Params : public ::testing::TestWithParam<
: public ::testing::TestWithParam< std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2, T3 > > {
::testing::tuple<const libvpx_test::CodecFactory *, T1, T2, T3> > {}; };
template <class T1, class T2, class T3, class T4>
class CodecTestWith4Params
: public ::testing::TestWithParam< ::testing::tuple<
const libvpx_test::CodecFactory *, T1, T2, T3, T4> > {};
/* /*
* VP8 Codec Definitions * VP8 Codec Definitions
@ -76,13 +69,11 @@ class CodecTestWith4Params
#if CONFIG_VP8 #if CONFIG_VP8
class VP8Decoder : public Decoder { class VP8Decoder : public Decoder {
public: public:
explicit VP8Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {} VP8Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
: Decoder(cfg, deadline) {}
VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
: Decoder(cfg, flag) {}
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const { virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP8_DECODER #if CONFIG_VP8_DECODER
return &vpx_codec_vp8_dx_algo; return &vpx_codec_vp8_dx_algo;
#else #else
@ -98,7 +89,7 @@ class VP8Encoder : public Encoder {
: Encoder(cfg, deadline, init_flags, stats) {} : Encoder(cfg, deadline, init_flags, stats) {}
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const { virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP8_ENCODER #if CONFIG_VP8_ENCODER
return &vpx_codec_vp8_cx_algo; return &vpx_codec_vp8_cx_algo;
#else #else
@ -111,32 +102,22 @@ class VP8CodecFactory : public CodecFactory {
public: public:
VP8CodecFactory() : CodecFactory() {} VP8CodecFactory() : CodecFactory() {}
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
return CreateDecoder(cfg, 0); unsigned long deadline) const {
}
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
const vpx_codec_flags_t flags) const {
#if CONFIG_VP8_DECODER #if CONFIG_VP8_DECODER
return new VP8Decoder(cfg, flags); return new VP8Decoder(cfg, deadline);
#else #else
(void)cfg;
(void)flags;
return NULL; return NULL;
#endif #endif
} }
virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
unsigned long deadline, unsigned long deadline,
const unsigned long init_flags, const unsigned long init_flags,
TwopassStatsStore *stats) const { TwopassStatsStore *stats) const {
#if CONFIG_VP8_ENCODER #if CONFIG_VP8_ENCODER
return new VP8Encoder(cfg, deadline, init_flags, stats); return new VP8Encoder(cfg, deadline, init_flags, stats);
#else #else
(void)cfg;
(void)deadline;
(void)init_flags;
(void)stats;
return NULL; return NULL;
#endif #endif
} }
@ -146,8 +127,6 @@ class VP8CodecFactory : public CodecFactory {
#if CONFIG_VP8_ENCODER #if CONFIG_VP8_ENCODER
return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage); return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
#else #else
(void)cfg;
(void)usage;
return VPX_CODEC_INCAPABLE; return VPX_CODEC_INCAPABLE;
#endif #endif
} }
@ -155,30 +134,28 @@ class VP8CodecFactory : public CodecFactory {
const libvpx_test::VP8CodecFactory kVP8; const libvpx_test::VP8CodecFactory kVP8;
#define VP8_INSTANTIATE_TEST_CASE(test, ...) \ #define VP8_INSTANTIATE_TEST_CASE(test, ...)\
INSTANTIATE_TEST_CASE_P( \ INSTANTIATE_TEST_CASE_P(VP8, test, \
VP8, test, \ ::testing::Combine( \
::testing::Combine( \ ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \ &libvpx_test::kVP8)), \
&libvpx_test::kVP8)), \
__VA_ARGS__)) __VA_ARGS__))
#else #else
#define VP8_INSTANTIATE_TEST_CASE(test, ...) #define VP8_INSTANTIATE_TEST_CASE(test, ...)
#endif // CONFIG_VP8 #endif // CONFIG_VP8
/* /*
* VP9 Codec Definitions * VP9 Codec Definitions
*/ */
#if CONFIG_VP9 #if CONFIG_VP9
class VP9Decoder : public Decoder { class VP9Decoder : public Decoder {
public: public:
explicit VP9Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {} VP9Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
: Decoder(cfg, deadline) {}
VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
: Decoder(cfg, flag) {}
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const { virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP9_DECODER #if CONFIG_VP9_DECODER
return &vpx_codec_vp9_dx_algo; return &vpx_codec_vp9_dx_algo;
#else #else
@ -194,7 +171,7 @@ class VP9Encoder : public Encoder {
: Encoder(cfg, deadline, init_flags, stats) {} : Encoder(cfg, deadline, init_flags, stats) {}
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const { virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP9_ENCODER #if CONFIG_VP9_ENCODER
return &vpx_codec_vp9_cx_algo; return &vpx_codec_vp9_cx_algo;
#else #else
@ -207,32 +184,22 @@ class VP9CodecFactory : public CodecFactory {
public: public:
VP9CodecFactory() : CodecFactory() {} VP9CodecFactory() : CodecFactory() {}
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
return CreateDecoder(cfg, 0); unsigned long deadline) const {
}
virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
const vpx_codec_flags_t flags) const {
#if CONFIG_VP9_DECODER #if CONFIG_VP9_DECODER
return new VP9Decoder(cfg, flags); return new VP9Decoder(cfg, deadline);
#else #else
(void)cfg;
(void)flags;
return NULL; return NULL;
#endif #endif
} }
virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
unsigned long deadline, unsigned long deadline,
const unsigned long init_flags, const unsigned long init_flags,
TwopassStatsStore *stats) const { TwopassStatsStore *stats) const {
#if CONFIG_VP9_ENCODER #if CONFIG_VP9_ENCODER
return new VP9Encoder(cfg, deadline, init_flags, stats); return new VP9Encoder(cfg, deadline, init_flags, stats);
#else #else
(void)cfg;
(void)deadline;
(void)init_flags;
(void)stats;
return NULL; return NULL;
#endif #endif
} }
@ -242,8 +209,6 @@ class VP9CodecFactory : public CodecFactory {
#if CONFIG_VP9_ENCODER #if CONFIG_VP9_ENCODER
return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage); return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
#else #else
(void)cfg;
(void)usage;
return VPX_CODEC_INCAPABLE; return VPX_CODEC_INCAPABLE;
#endif #endif
} }
@ -251,16 +216,17 @@ class VP9CodecFactory : public CodecFactory {
const libvpx_test::VP9CodecFactory kVP9; const libvpx_test::VP9CodecFactory kVP9;
#define VP9_INSTANTIATE_TEST_CASE(test, ...) \ #define VP9_INSTANTIATE_TEST_CASE(test, ...)\
INSTANTIATE_TEST_CASE_P( \ INSTANTIATE_TEST_CASE_P(VP9, test, \
VP9, test, \ ::testing::Combine( \
::testing::Combine( \ ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \ &libvpx_test::kVP9)), \
&libvpx_test::kVP9)), \
__VA_ARGS__)) __VA_ARGS__))
#else #else
#define VP9_INSTANTIATE_TEST_CASE(test, ...) #define VP9_INSTANTIATE_TEST_CASE(test, ...)
#endif // CONFIG_VP9 #endif // CONFIG_VP9
} // namespace libvpx_test } // namespace libvpx_test
#endif // TEST_CODEC_FACTORY_H_ #endif // TEST_CODEC_FACTORY_H_

View File

@ -1,182 +0,0 @@
/*
* Copyright (c) 2017 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/buffer.h"
#include "test/register_state_check.h"
#include "vpx_ports/vpx_timer.h"
namespace {
using ::libvpx_test::ACMRandom;
using ::libvpx_test::Buffer;
typedef void (*AvgPredFunc)(uint8_t *a, const uint8_t *b, int w, int h,
const uint8_t *c, int c_stride);
uint8_t avg_with_rounding(uint8_t a, uint8_t b) { return (a + b + 1) >> 1; }
void reference_pred(const Buffer<uint8_t> &pred, const Buffer<uint8_t> &ref,
int width, int height, Buffer<uint8_t> *avg) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
avg->TopLeftPixel()[y * avg->stride() + x] =
avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x],
ref.TopLeftPixel()[y * ref.stride() + x]);
}
}
}
class AvgPredTest : public ::testing::TestWithParam<AvgPredFunc> {
public:
virtual void SetUp() {
avg_pred_func_ = GetParam();
rnd_.Reset(ACMRandom::DeterministicSeed());
}
protected:
AvgPredFunc avg_pred_func_;
ACMRandom rnd_;
};
TEST_P(AvgPredTest, SizeCombinations) {
// This is called as part of the sub pixel variance. As such it must be one of
// the variance block sizes.
for (int width_pow = 2; width_pow <= 6; ++width_pow) {
for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
++height_pow) {
// Don't test 4x2 or 64x128
if (height_pow == 1 || height_pow == 7) continue;
// The sse2 special-cases when ref width == stride, so make sure to test
// it.
for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
const int width = 1 << width_pow;
const int height = 1 << height_pow;
// Only the reference buffer may have a stride not equal to width.
Buffer<uint8_t> ref =
Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
ASSERT_TRUE(ref.Init());
Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(pred.Init());
Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(avg_ref.Init());
Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(avg_chk.Init());
ref.Set(&rnd_, &ACMRandom::Rand8);
pred.Set(&rnd_, &ACMRandom::Rand8);
reference_pred(pred, ref, width, height, &avg_ref);
ASM_REGISTER_STATE_CHECK(
avg_pred_func_(avg_chk.TopLeftPixel(), pred.TopLeftPixel(), width,
height, ref.TopLeftPixel(), ref.stride()));
EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
if (HasFailure()) {
printf("Width: %d Height: %d\n", width, height);
avg_chk.PrintDifference(avg_ref);
return;
}
}
}
}
}
TEST_P(AvgPredTest, CompareReferenceRandom) {
const int width = 64;
const int height = 32;
Buffer<uint8_t> ref = Buffer<uint8_t>(width, height, 8);
ASSERT_TRUE(ref.Init());
Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(pred.Init());
Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(avg_ref.Init());
Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(avg_chk.Init());
for (int i = 0; i < 500; ++i) {
ref.Set(&rnd_, &ACMRandom::Rand8);
pred.Set(&rnd_, &ACMRandom::Rand8);
reference_pred(pred, ref, width, height, &avg_ref);
ASM_REGISTER_STATE_CHECK(avg_pred_func_(avg_chk.TopLeftPixel(),
pred.TopLeftPixel(), width, height,
ref.TopLeftPixel(), ref.stride()));
EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
if (HasFailure()) {
printf("Width: %d Height: %d\n", width, height);
avg_chk.PrintDifference(avg_ref);
return;
}
}
}
TEST_P(AvgPredTest, DISABLED_Speed) {
for (int width_pow = 2; width_pow <= 6; ++width_pow) {
for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
++height_pow) {
// Don't test 4x2 or 64x128
if (height_pow == 1 || height_pow == 7) continue;
for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
const int width = 1 << width_pow;
const int height = 1 << height_pow;
Buffer<uint8_t> ref =
Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
ASSERT_TRUE(ref.Init());
Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(pred.Init());
Buffer<uint8_t> avg = Buffer<uint8_t>(width, height, 0, 16);
ASSERT_TRUE(avg.Init());
ref.Set(&rnd_, &ACMRandom::Rand8);
pred.Set(&rnd_, &ACMRandom::Rand8);
vpx_usec_timer timer;
vpx_usec_timer_start(&timer);
for (int i = 0; i < 10000000 / (width * height); ++i) {
avg_pred_func_(avg.TopLeftPixel(), pred.TopLeftPixel(), width, height,
ref.TopLeftPixel(), ref.stride());
}
vpx_usec_timer_mark(&timer);
const int elapsed_time =
static_cast<int>(vpx_usec_timer_elapsed(&timer));
printf("Average Test (ref_padding: %d) %dx%d time: %5d us\n",
ref_padding, width, height, elapsed_time);
}
}
}
}
INSTANTIATE_TEST_CASE_P(C, AvgPredTest,
::testing::Values(&vpx_comp_avg_pred_c));
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(SSE2, AvgPredTest,
::testing::Values(&vpx_comp_avg_pred_sse2));
#endif // HAVE_SSE2
#if HAVE_NEON
INSTANTIATE_TEST_CASE_P(NEON, AvgPredTest,
::testing::Values(&vpx_comp_avg_pred_neon));
#endif // HAVE_NEON
#if HAVE_VSX
INSTANTIATE_TEST_CASE_P(VSX, AvgPredTest,
::testing::Values(&vpx_comp_avg_pred_vsx));
#endif // HAVE_VSX
} // namespace

View File

@ -15,13 +15,11 @@
namespace { namespace {
class ConfigTest class ConfigTest : public ::libvpx_test::EncoderTest,
: public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
protected: protected:
ConfigTest() ConfigTest() : EncoderTest(GET_PARAM(0)),
: EncoderTest(GET_PARAM(0)), frame_count_in_(0), frame_count_out_(0), frame_count_in_(0), frame_count_out_(0), frame_count_max_(0) {}
frame_count_max_(0) {}
virtual ~ConfigTest() {} virtual ~ConfigTest() {}
virtual void SetUp() { virtual void SetUp() {
@ -34,12 +32,12 @@ class ConfigTest
frame_count_out_ = 0; frame_count_out_ = 0;
} }
virtual void PreEncodeFrameHook(libvpx_test::VideoSource * /*video*/) { virtual void PreEncodeFrameHook(libvpx_test::VideoSource* /*video*/) {
++frame_count_in_; ++frame_count_in_;
abort_ |= (frame_count_in_ >= frame_count_max_); abort_ |= (frame_count_in_ >= frame_count_max_);
} }
virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) { virtual void FramePktHook(const vpx_codec_cx_pkt_t* /*pkt*/) {
++frame_count_out_; ++frame_count_out_;
} }

View File

@ -1,214 +0,0 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h"
#if CONFIG_VP9_ENCODER
#include "./vp9_rtcd.h"
#endif
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vpx_dsp/ssim.h"
#include "vpx_mem/vpx_mem.h"
extern "C" double vpx_get_ssim_metrics(uint8_t *img1, int img1_pitch,
uint8_t *img2, int img2_pitch, int width,
int height, Ssimv *sv2, Metrics *m,
int do_inconsistency);
using libvpx_test::ACMRandom;
namespace {
class ConsistencyTestBase : public ::testing::Test {
public:
ConsistencyTestBase(int width, int height) : width_(width), height_(height) {}
static void SetUpTestCase() {
source_data_[0] = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
reference_data_[0] = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
source_data_[1] = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
reference_data_[1] = reinterpret_cast<uint8_t *>(
vpx_memalign(kDataAlignment, kDataBufferSize));
ssim_array_ = new Ssimv[kDataBufferSize / 16];
}
static void ClearSsim() { memset(ssim_array_, 0, kDataBufferSize / 16); }
static void TearDownTestCase() {
vpx_free(source_data_[0]);
source_data_[0] = NULL;
vpx_free(reference_data_[0]);
reference_data_[0] = NULL;
vpx_free(source_data_[1]);
source_data_[1] = NULL;
vpx_free(reference_data_[1]);
reference_data_[1] = NULL;
delete[] ssim_array_;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
// Handle frames up to 640x480
static const int kDataAlignment = 16;
static const int kDataBufferSize = 640 * 480;
virtual void SetUp() {
source_stride_ = (width_ + 31) & ~31;
reference_stride_ = width_ * 2;
rnd_.Reset(ACMRandom::DeterministicSeed());
}
void FillRandom(uint8_t *data, int stride, int width, int height) {
for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) {
data[h * stride + w] = rnd_.Rand8();
}
}
}
void FillRandom(uint8_t *data, int stride) {
FillRandom(data, stride, width_, height_);
}
void Copy(uint8_t *reference, uint8_t *source) {
memcpy(reference, source, kDataBufferSize);
}
void Blur(uint8_t *data, int stride, int taps) {
int sum = 0;
int half_taps = taps / 2;
for (int h = 0; h < height_; ++h) {
for (int w = 0; w < taps; ++w) {
sum += data[w + h * stride];
}
for (int w = taps; w < width_; ++w) {
sum += data[w + h * stride] - data[w - taps + h * stride];
data[w - half_taps + h * stride] = (sum + half_taps) / taps;
}
}
for (int w = 0; w < width_; ++w) {
for (int h = 0; h < taps; ++h) {
sum += data[h + w * stride];
}
for (int h = taps; h < height_; ++h) {
sum += data[w + h * stride] - data[(h - taps) * stride + w];
data[(h - half_taps) * stride + w] = (sum + half_taps) / taps;
}
}
}
int width_, height_;
static uint8_t *source_data_[2];
int source_stride_;
static uint8_t *reference_data_[2];
int reference_stride_;
static Ssimv *ssim_array_;
Metrics metrics_;
ACMRandom rnd_;
};
#if CONFIG_VP9_ENCODER
typedef ::testing::tuple<int, int> ConsistencyParam;
class ConsistencyVP9Test
: public ConsistencyTestBase,
public ::testing::WithParamInterface<ConsistencyParam> {
public:
ConsistencyVP9Test() : ConsistencyTestBase(GET_PARAM(0), GET_PARAM(1)) {}
protected:
double CheckConsistency(int frame) {
EXPECT_LT(frame, 2) << "Frame to check has to be less than 2.";
return vpx_get_ssim_metrics(source_data_[frame], source_stride_,
reference_data_[frame], reference_stride_,
width_, height_, ssim_array_, &metrics_, 1);
}
};
#endif // CONFIG_VP9_ENCODER
uint8_t *ConsistencyTestBase::source_data_[2] = { NULL, NULL };
uint8_t *ConsistencyTestBase::reference_data_[2] = { NULL, NULL };
Ssimv *ConsistencyTestBase::ssim_array_ = NULL;
#if CONFIG_VP9_ENCODER
TEST_P(ConsistencyVP9Test, ConsistencyIsZero) {
FillRandom(source_data_[0], source_stride_);
Copy(source_data_[1], source_data_[0]);
Copy(reference_data_[0], source_data_[0]);
Blur(reference_data_[0], reference_stride_, 3);
Copy(reference_data_[1], source_data_[0]);
Blur(reference_data_[1], reference_stride_, 3);
double inconsistency = CheckConsistency(1);
inconsistency = CheckConsistency(0);
EXPECT_EQ(inconsistency, 0.0)
<< "Should have 0 inconsistency if they are exactly the same.";
// If sources are not consistent reference frames inconsistency should
// be less than if the source is consistent.
FillRandom(source_data_[0], source_stride_);
FillRandom(source_data_[1], source_stride_);
FillRandom(reference_data_[0], reference_stride_);
FillRandom(reference_data_[1], reference_stride_);
CheckConsistency(0);
inconsistency = CheckConsistency(1);
Copy(source_data_[1], source_data_[0]);
CheckConsistency(0);
double inconsistency2 = CheckConsistency(1);
EXPECT_LT(inconsistency, inconsistency2)
<< "Should have less inconsistency if source itself is inconsistent.";
// Less of a blur should be less inconsistent than more blur coming off a
// a frame with no blur.
ClearSsim();
FillRandom(source_data_[0], source_stride_);
Copy(source_data_[1], source_data_[0]);
Copy(reference_data_[0], source_data_[0]);
Copy(reference_data_[1], source_data_[0]);
Blur(reference_data_[1], reference_stride_, 4);
CheckConsistency(0);
inconsistency = CheckConsistency(1);
ClearSsim();
Copy(reference_data_[1], source_data_[0]);
Blur(reference_data_[1], reference_stride_, 8);
CheckConsistency(0);
inconsistency2 = CheckConsistency(1);
EXPECT_LT(inconsistency, inconsistency2)
<< "Stronger Blur should produce more inconsistency.";
}
#endif // CONFIG_VP9_ENCODER
using ::testing::make_tuple;
//------------------------------------------------------------------------------
// C functions
#if CONFIG_VP9_ENCODER
const ConsistencyParam c_vp9_tests[] = {
make_tuple(320, 240), make_tuple(318, 242), make_tuple(318, 238)
};
INSTANTIATE_TEST_CASE_P(C, ConsistencyVP9Test,
::testing::ValuesIn(c_vp9_tests));
#endif
} // namespace

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,10 @@ class CpuSpeedTest
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
protected: protected:
CpuSpeedTest() CpuSpeedTest()
: EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), : EncoderTest(GET_PARAM(0)),
set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR), encoding_mode_(GET_PARAM(1)),
tune_content_(VP9E_CONTENT_DEFAULT) {} set_cpu_used_(GET_PARAM(2)),
min_psnr_(kMaxPSNR) {}
virtual ~CpuSpeedTest() {} virtual ~CpuSpeedTest() {}
virtual void SetUp() { virtual void SetUp() {
@ -40,13 +41,14 @@ class CpuSpeedTest
} }
} }
virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; } virtual void BeginPassHook(unsigned int /*pass*/) {
min_psnr_ = kMaxPSNR;
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) { ::libvpx_test::Encoder *encoder) {
if (video->frame() == 1) { if (video->frame() == 1) {
encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
if (encoding_mode_ != ::libvpx_test::kRealTime) { if (encoding_mode_ != ::libvpx_test::kRealTime) {
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7); encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
@ -57,13 +59,13 @@ class CpuSpeedTest
} }
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0]; if (pkt->data.psnr.psnr[0] < min_psnr_)
min_psnr_ = pkt->data.psnr.psnr[0];
} }
::libvpx_test::TestMode encoding_mode_; ::libvpx_test::TestMode encoding_mode_;
int set_cpu_used_; int set_cpu_used_;
double min_psnr_; double min_psnr_;
int tune_content_;
}; };
TEST_P(CpuSpeedTest, TestQ0) { TEST_P(CpuSpeedTest, TestQ0) {
@ -72,7 +74,7 @@ TEST_P(CpuSpeedTest, TestQ0) {
// the encoder to producing lots of big partitions which will likely // the encoder to producing lots of big partitions which will likely
// extend into the border and test the border condition. // extend into the border and test the border condition.
cfg_.rc_2pass_vbr_minsection_pct = 5; cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 400; cfg_.rc_target_bitrate = 400;
cfg_.rc_max_quantizer = 0; cfg_.rc_max_quantizer = 0;
cfg_.rc_min_quantizer = 0; cfg_.rc_min_quantizer = 0;
@ -90,7 +92,7 @@ TEST_P(CpuSpeedTest, TestScreencastQ0) {
::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25); ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
cfg_.g_timebase = video.timebase(); cfg_.g_timebase = video.timebase();
cfg_.rc_2pass_vbr_minsection_pct = 5; cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 400; cfg_.rc_target_bitrate = 400;
cfg_.rc_max_quantizer = 0; cfg_.rc_max_quantizer = 0;
cfg_.rc_min_quantizer = 0; cfg_.rc_min_quantizer = 0;
@ -101,28 +103,13 @@ TEST_P(CpuSpeedTest, TestScreencastQ0) {
EXPECT_GE(min_psnr_, kMaxPSNR); EXPECT_GE(min_psnr_, kMaxPSNR);
} }
TEST_P(CpuSpeedTest, TestTuneScreen) {
::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
cfg_.g_timebase = video.timebase();
cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 2000;
cfg_.rc_max_quantizer = 63;
cfg_.rc_min_quantizer = 0;
tune_content_ = VP9E_CONTENT_SCREEN;
init_flags_ = VPX_CODEC_USE_PSNR;
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
// Validate that this non multiple of 64 wide clip encodes and decodes // Validate that this non multiple of 64 wide clip encodes and decodes
// without a mismatch when passing in a very low max q. This pushes // without a mismatch when passing in a very low max q. This pushes
// the encoder to producing lots of big partitions which will likely // the encoder to producing lots of big partitions which will likely
// extend into the border and test the border condition. // extend into the border and test the border condition.
cfg_.rc_2pass_vbr_minsection_pct = 5; cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 12000; cfg_.rc_target_bitrate = 12000;
cfg_.rc_max_quantizer = 10; cfg_.rc_max_quantizer = 10;
cfg_.rc_min_quantizer = 0; cfg_.rc_min_quantizer = 0;
@ -138,7 +125,7 @@ TEST_P(CpuSpeedTest, TestLowBitrate) {
// when passing in a very high min q. This pushes the encoder to producing // when passing in a very high min q. This pushes the encoder to producing
// lots of small partitions which might will test the other condition. // lots of small partitions which might will test the other condition.
cfg_.rc_2pass_vbr_minsection_pct = 5; cfg_.rc_2pass_vbr_minsection_pct = 5;
cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_2pass_vbr_minsection_pct = 2000;
cfg_.rc_target_bitrate = 200; cfg_.rc_target_bitrate = 200;
cfg_.rc_min_quantizer = 40; cfg_.rc_min_quantizer = 40;
@ -148,9 +135,9 @@ TEST_P(CpuSpeedTest, TestLowBitrate) {
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
} }
VP9_INSTANTIATE_TEST_CASE(CpuSpeedTest, VP9_INSTANTIATE_TEST_CASE(
::testing::Values(::libvpx_test::kTwoPassGood, CpuSpeedTest,
::libvpx_test::kOnePassGood, ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
::libvpx_test::kRealTime), ::libvpx_test::kRealTime),
::testing::Range(0, 9)); ::testing::Range(0, 9));
} // namespace } // namespace

View File

@ -24,12 +24,14 @@ const int kCQLevelStep = 8;
const unsigned int kCQTargetBitrate = 2000; const unsigned int kCQTargetBitrate = 2000;
class CQTest : public ::libvpx_test::EncoderTest, class CQTest : public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWithParam<int> { public ::libvpx_test::CodecTestWithParam<int> {
public: public:
// maps the cqlevel to the bitrate produced. // maps the cqlevel to the bitrate produced.
typedef std::map<int, uint32_t> BitrateMap; typedef std::map<int, uint32_t> BitrateMap;
static void SetUpTestCase() { bitrates_.clear(); } static void SetUpTestCase() {
bitrates_.clear();
}
static void TearDownTestCase() { static void TearDownTestCase() {
ASSERT_TRUE(!HasFailure()) ASSERT_TRUE(!HasFailure())
@ -126,6 +128,7 @@ TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) {
EXPECT_GE(cq_psnr_lin, vbr_psnr_lin); EXPECT_GE(cq_psnr_lin, vbr_psnr_lin);
} }
VP8_INSTANTIATE_TEST_CASE(CQTest, ::testing::Range(kCQLevelMin, kCQLevelMax, VP8_INSTANTIATE_TEST_CASE(CQTest,
kCQLevelStep)); ::testing::Range(kCQLevelMin, kCQLevelMax,
kCQLevelStep));
} // namespace } // namespace

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
## ##
## Copyright (c) 2016 The WebM project authors. All Rights Reserved. ## Copyright (c) 2014 The WebM project authors. All Rights Reserved.
## ##
## Use of this source code is governed by a BSD-style license ## Use of this source code is governed by a BSD-style license
## that can be found in the LICENSE file in the root of the source ## that can be found in the LICENSE file in the root of the source

222
test/datarate_test.cc Normal file
View File

@ -0,0 +1,222 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./vpx_config.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"
#include "test/y4m_video_source.h"
namespace {
class DatarateTestLarge : public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
public:
DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {}
virtual ~DatarateTestLarge() {}
protected:
virtual void SetUp() {
InitializeConfig();
SetMode(GET_PARAM(1));
ResetModel();
}
virtual void ResetModel() {
last_pts_ = 0;
bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz;
frame_number_ = 0;
first_drop_ = 0;
bits_total_ = 0;
duration_ = 0.0;
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
if (video->frame() == 1) {
encoder->Control(VP8E_SET_NOISE_SENSITIVITY, denoiser_on_);
}
const vpx_rational_t tb = video->timebase();
timebase_ = static_cast<double>(tb.num) / tb.den;
duration_ = 0;
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
// Time since last timestamp = duration.
vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_;
// TODO(jimbankoski): Remove these lines when the issue:
// http://code.google.com/p/webm/issues/detail?id=496 is fixed.
// For now the codec assumes buffer starts at starting buffer rate
// plus one frame's time.
if (last_pts_ == 0)
duration = 1;
// Add to the buffer the bits we'd expect from a constant bitrate server.
bits_in_buffer_model_ += static_cast<int64_t>(
duration * timebase_ * cfg_.rc_target_bitrate * 1000);
/* Test the buffer model here before subtracting the frame. Do so because
* the way the leaky bucket model works in libvpx is to allow the buffer to
* empty - and then stop showing frames until we've got enough bits to
* show one. As noted in comment below (issue 495), this does not currently
* apply to key frames. For now exclude key frames in condition below. */
const bool key_frame = (pkt->data.frame.flags & VPX_FRAME_IS_KEY)
? true: false;
if (!key_frame) {
ASSERT_GE(bits_in_buffer_model_, 0) << "Buffer Underrun at frame "
<< pkt->data.frame.pts;
}
const size_t frame_size_in_bits = pkt->data.frame.sz * 8;
// Subtract from the buffer the bits associated with a played back frame.
bits_in_buffer_model_ -= frame_size_in_bits;
// Update the running total of bits for end of test datarate checks.
bits_total_ += frame_size_in_bits;
// If first drop not set and we have a drop set it to this time.
if (!first_drop_ && duration > 1)
first_drop_ = last_pts_ + 1;
// Update the most recent pts.
last_pts_ = pkt->data.frame.pts;
// We update this so that we can calculate the datarate minus the last
// frame encoded in the file.
bits_in_last_frame_ = frame_size_in_bits;
++frame_number_;
}
virtual void EndPassHook(void) {
if (bits_total_) {
const double file_size_in_kb = bits_total_ / 1000.; // bits per kilobit
duration_ = (last_pts_ + 1) * timebase_;
// Effective file datarate includes the time spent prebuffering.
effective_datarate_ = (bits_total_ - bits_in_last_frame_) / 1000.0
/ (cfg_.rc_buf_initial_sz / 1000.0 + duration_);
file_datarate_ = file_size_in_kb / duration_;
}
}
vpx_codec_pts_t last_pts_;
int64_t bits_in_buffer_model_;
double timebase_;
int frame_number_;
vpx_codec_pts_t first_drop_;
int64_t bits_total_;
double duration_;
double file_datarate_;
double effective_datarate_;
size_t bits_in_last_frame_;
int denoiser_on_;
};
#if CONFIG_TEMPORAL_DENOISING
// Check basic datarate targeting, for a single bitrate, but loop over the
// various denoiser settings.
TEST_P(DatarateTestLarge, DenoiserLevels) {
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_dropframe_thresh = 1;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_CBR;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 140);
for (int j = 1; j < 5; ++j) {
// Run over the denoiser levels.
// For the temporal denoiser (#if CONFIG_TEMPORAL_DENOISING) the level j
// refers to the 4 denoiser modes: denoiserYonly, denoiserOnYUV,
// denoiserOnAggressive, and denoiserOnAdaptive.
// For the spatial denoiser (if !CONFIG_TEMPORAL_DENOISING), the level j
// refers to the blur thresholds: 20, 40, 60 80.
// The j = 0 case (denoiser off) is covered in the tests below.
denoiser_on_ = j;
cfg_.rc_target_bitrate = 300;
ResetModel();
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.95)
<< " The datarate for the file exceeds the target!";
ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.3)
<< " The datarate for the file missed the target!";
}
}
#endif // CONFIG_TEMPORAL_DENOISING
TEST_P(DatarateTestLarge, BasicBufferModel) {
denoiser_on_ = 0;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_dropframe_thresh = 1;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_CBR;
// 2 pass cbr datarate control has a bug hidden by the small # of
// frames selected in this encode. The problem is that even if the buffer is
// negative we produce a keyframe on a cutscene. Ignoring datarate
// constraints
// TODO(jimbankoski): ( Fix when issue
// http://code.google.com/p/webm/issues/detail?id=495 is addressed. )
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 140);
// There is an issue for low bitrates in real-time mode, where the
// effective_datarate slightly overshoots the target bitrate.
// This is same the issue as noted about (#495).
// TODO(jimbankoski/marpan): Update test to run for lower bitrates (< 100),
// when the issue is resolved.
for (int i = 100; i < 800; i += 200) {
cfg_.rc_target_bitrate = i;
ResetModel();
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.95)
<< " The datarate for the file exceeds the target!";
ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.3)
<< " The datarate for the file missed the target!";
}
}
TEST_P(DatarateTestLarge, ChangingDropFrameThresh) {
denoiser_on_ = 0;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_max_quantizer = 36;
cfg_.rc_end_usage = VPX_CBR;
cfg_.rc_target_bitrate = 200;
cfg_.kf_mode = VPX_KF_DISABLED;
const int frame_count = 40;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, frame_count);
// Here we check that the first dropped frame gets earlier and earlier
// as the drop frame threshold is increased.
const int kDropFrameThreshTestStep = 30;
vpx_codec_pts_t last_drop = frame_count;
for (int i = 1; i < 91; i += kDropFrameThreshTestStep) {
cfg_.rc_dropframe_thresh = i;
ResetModel();
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
ASSERT_LE(first_drop_, last_drop)
<< " The first dropped frame for drop_thresh " << i
<< " > first dropped frame for drop_thresh "
<< i - kDropFrameThreshTestStep;
last_drop = first_drop_;
}
}
VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES);
} // namespace

View File

@ -13,25 +13,54 @@
#include <string.h> #include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vp9_rtcd.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h" #include "test/acm_random.h"
#include "test/clear_system_state.h" #include "test/clear_system_state.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
#include "test/util.h" #include "test/util.h"
#include "./vp9_rtcd.h"
#include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_scan.h"
#include "vpx/vpx_codec.h" #include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h" #include "vpx/vpx_integer.h"
#include "vpx_ports/mem.h"
#include "vpx_ports/msvc.h" // for round()
using libvpx_test::ACMRandom; using libvpx_test::ACMRandom;
namespace { namespace {
#ifdef _MSC_VER
static int round(double x) {
if (x < 0)
return static_cast<int>(ceil(x - 0.5));
else
return static_cast<int>(floor(x + 0.5));
}
#endif
const int kNumCoeffs = 256; const int kNumCoeffs = 256;
const double PI = 3.1415926535898;
void reference2_16x16_idct_2d(double *input, double *output) {
double x;
for (int l = 0; l < 16; ++l) {
for (int k = 0; k < 16; ++k) {
double s = 0;
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
x = cos(PI * j * (l + 0.5) / 16.0) *
cos(PI * i * (k + 0.5) / 16.0) *
input[i * 16 + j] / 256;
if (i != 0)
x *= sqrt(2.0);
if (j != 0)
x *= sqrt(2.0);
s += x;
}
}
output[k*16+l] = s;
}
}
}
const double C1 = 0.995184726672197; const double C1 = 0.995184726672197;
const double C2 = 0.98078528040323; const double C2 = 0.98078528040323;
const double C3 = 0.956940335732209; const double C3 = 0.956940335732209;
@ -54,16 +83,16 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
double temp1, temp2; double temp1, temp2;
// step 1 // step 1
step[0] = input[0] + input[15]; step[ 0] = input[0] + input[15];
step[1] = input[1] + input[14]; step[ 1] = input[1] + input[14];
step[2] = input[2] + input[13]; step[ 2] = input[2] + input[13];
step[3] = input[3] + input[12]; step[ 3] = input[3] + input[12];
step[4] = input[4] + input[11]; step[ 4] = input[4] + input[11];
step[5] = input[5] + input[10]; step[ 5] = input[5] + input[10];
step[6] = input[6] + input[9]; step[ 6] = input[6] + input[ 9];
step[7] = input[7] + input[8]; step[ 7] = input[7] + input[ 8];
step[8] = input[7] - input[8]; step[ 8] = input[7] - input[ 8];
step[9] = input[6] - input[9]; step[ 9] = input[6] - input[ 9];
step[10] = input[5] - input[10]; step[10] = input[5] - input[10];
step[11] = input[4] - input[11]; step[11] = input[4] - input[11];
step[12] = input[3] - input[12]; step[12] = input[3] - input[12];
@ -81,13 +110,13 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
output[6] = step[1] - step[6]; output[6] = step[1] - step[6];
output[7] = step[0] - step[7]; output[7] = step[0] - step[7];
temp1 = step[8] * C7; temp1 = step[ 8] * C7;
temp2 = step[15] * C9; temp2 = step[15] * C9;
output[8] = temp1 + temp2; output[ 8] = temp1 + temp2;
temp1 = step[9] * C11; temp1 = step[ 9] * C11;
temp2 = step[14] * C5; temp2 = step[14] * C5;
output[9] = temp1 - temp2; output[ 9] = temp1 - temp2;
temp1 = step[10] * C3; temp1 = step[10] * C3;
temp2 = step[13] * C13; temp2 = step[13] * C13;
@ -105,40 +134,40 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
temp2 = step[13] * C3; temp2 = step[13] * C3;
output[13] = temp2 - temp1; output[13] = temp2 - temp1;
temp1 = step[9] * C5; temp1 = step[ 9] * C5;
temp2 = step[14] * C11; temp2 = step[14] * C11;
output[14] = temp2 + temp1; output[14] = temp2 + temp1;
temp1 = step[8] * C9; temp1 = step[ 8] * C9;
temp2 = step[15] * C7; temp2 = step[15] * C7;
output[15] = temp2 - temp1; output[15] = temp2 - temp1;
// step 3 // step 3
step[0] = output[0] + output[3]; step[ 0] = output[0] + output[3];
step[1] = output[1] + output[2]; step[ 1] = output[1] + output[2];
step[2] = output[1] - output[2]; step[ 2] = output[1] - output[2];
step[3] = output[0] - output[3]; step[ 3] = output[0] - output[3];
temp1 = output[4] * C14; temp1 = output[4] * C14;
temp2 = output[7] * C2; temp2 = output[7] * C2;
step[4] = temp1 + temp2; step[ 4] = temp1 + temp2;
temp1 = output[5] * C10; temp1 = output[5] * C10;
temp2 = output[6] * C6; temp2 = output[6] * C6;
step[5] = temp1 + temp2; step[ 5] = temp1 + temp2;
temp1 = output[5] * C6; temp1 = output[5] * C6;
temp2 = output[6] * C10; temp2 = output[6] * C10;
step[6] = temp2 - temp1; step[ 6] = temp2 - temp1;
temp1 = output[4] * C2; temp1 = output[4] * C2;
temp2 = output[7] * C14; temp2 = output[7] * C14;
step[7] = temp2 - temp1; step[ 7] = temp2 - temp1;
step[8] = output[8] + output[11]; step[ 8] = output[ 8] + output[11];
step[9] = output[9] + output[10]; step[ 9] = output[ 9] + output[10];
step[10] = output[9] - output[10]; step[10] = output[ 9] - output[10];
step[11] = output[8] - output[11]; step[11] = output[ 8] - output[11];
step[12] = output[12] + output[15]; step[12] = output[12] + output[15];
step[13] = output[13] + output[14]; step[13] = output[13] + output[14];
@ -146,25 +175,25 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
step[15] = output[12] - output[15]; step[15] = output[12] - output[15];
// step 4 // step 4
output[0] = (step[0] + step[1]); output[ 0] = (step[ 0] + step[ 1]);
output[8] = (step[0] - step[1]); output[ 8] = (step[ 0] - step[ 1]);
temp1 = step[2] * C12; temp1 = step[2] * C12;
temp2 = step[3] * C4; temp2 = step[3] * C4;
temp1 = temp1 + temp2; temp1 = temp1 + temp2;
output[4] = 2 * (temp1 * C8); output[ 4] = 2*(temp1 * C8);
temp1 = step[2] * C4; temp1 = step[2] * C4;
temp2 = step[3] * C12; temp2 = step[3] * C12;
temp1 = temp2 - temp1; temp1 = temp2 - temp1;
output[12] = 2 * (temp1 * C8); output[12] = 2 * (temp1 * C8);
output[2] = 2 * ((step[4] + step[5]) * C8); output[ 2] = 2 * ((step[4] + step[ 5]) * C8);
output[14] = 2 * ((step[7] - step[6]) * C8); output[14] = 2 * ((step[7] - step[ 6]) * C8);
temp1 = step[4] - step[5]; temp1 = step[4] - step[5];
temp2 = step[6] + step[7]; temp2 = step[6] + step[7];
output[6] = (temp1 + temp2); output[ 6] = (temp1 + temp2);
output[10] = (temp1 - temp2); output[10] = (temp1 - temp2);
intermediate[8] = step[8] + step[14]; intermediate[8] = step[8] + step[14];
@ -180,18 +209,18 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
temp1 = temp2 + temp1; temp1 = temp2 + temp1;
output[13] = 2 * (temp1 * C8); output[13] = 2 * (temp1 * C8);
output[9] = 2 * ((step[10] + step[11]) * C8); output[ 9] = 2 * ((step[10] + step[11]) * C8);
intermediate[11] = step[10] - step[11]; intermediate[11] = step[10] - step[11];
intermediate[12] = step[12] + step[13]; intermediate[12] = step[12] + step[13];
intermediate[13] = step[12] - step[13]; intermediate[13] = step[12] - step[13];
intermediate[14] = step[8] - step[14]; intermediate[14] = step[ 8] - step[14];
intermediate[15] = step[9] - step[15]; intermediate[15] = step[ 9] - step[15];
output[15] = (intermediate[11] + intermediate[12]); output[15] = (intermediate[11] + intermediate[12]);
output[1] = -(intermediate[11] - intermediate[12]); output[ 1] = -(intermediate[11] - intermediate[12]);
output[7] = 2 * (intermediate[13] * C8); output[ 7] = 2 * (intermediate[13] * C8);
temp1 = intermediate[14] * C12; temp1 = intermediate[14] * C12;
temp2 = intermediate[15] * C4; temp2 = intermediate[15] * C4;
@ -201,24 +230,28 @@ void butterfly_16x16_dct_1d(double input[16], double output[16]) {
temp1 = intermediate[14] * C4; temp1 = intermediate[14] * C4;
temp2 = intermediate[15] * C12; temp2 = intermediate[15] * C12;
temp1 = temp2 + temp1; temp1 = temp2 + temp1;
output[5] = 2 * (temp1 * C8); output[ 5] = 2 * (temp1 * C8);
} }
void reference_16x16_dct_2d(int16_t input[256], double output[256]) { void reference_16x16_dct_2d(int16_t input[256], double output[256]) {
// First transform columns // First transform columns
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
double temp_in[16], temp_out[16]; double temp_in[16], temp_out[16];
for (int j = 0; j < 16; ++j) temp_in[j] = input[j * 16 + i]; for (int j = 0; j < 16; ++j)
temp_in[j] = input[j * 16 + i];
butterfly_16x16_dct_1d(temp_in, temp_out); butterfly_16x16_dct_1d(temp_in, temp_out);
for (int j = 0; j < 16; ++j) output[j * 16 + i] = temp_out[j]; for (int j = 0; j < 16; ++j)
output[j * 16 + i] = temp_out[j];
} }
// Then transform rows // Then transform rows
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
double temp_in[16], temp_out[16]; double temp_in[16], temp_out[16];
for (int j = 0; j < 16; ++j) temp_in[j] = output[j + i * 16]; for (int j = 0; j < 16; ++j)
temp_in[j] = output[j + i * 16];
butterfly_16x16_dct_1d(temp_in, temp_out); butterfly_16x16_dct_1d(temp_in, temp_out);
// Scale by some magic number // Scale by some magic number
for (int j = 0; j < 16; ++j) output[j + i * 16] = temp_out[j] / 2; for (int j = 0; j < 16; ++j)
output[j + i * 16] = temp_out[j]/2;
} }
} }
@ -229,23 +262,23 @@ typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride, typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type); int tx_type);
typedef ::testing::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> typedef std::tr1::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> Dct16x16Param;
Dct16x16Param; typedef std::tr1::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht16x16Param;
typedef ::testing::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht16x16Param; typedef std::tr1::tuple<IdctFunc, IdctFunc, int, vpx_bit_depth_t>
typedef ::testing::tuple<IdctFunc, IdctFunc, int, vpx_bit_depth_t>
Idct16x16Param; Idct16x16Param;
void fdct16x16_ref(const int16_t *in, tran_low_t *out, int stride, void fdct16x16_ref(const int16_t *in, tran_low_t *out, int stride,
int /*tx_type*/) { int /*tx_type*/) {
vpx_fdct16x16_c(in, out, stride); vp9_fdct16x16_c(in, out, stride);
} }
void idct16x16_ref(const tran_low_t *in, uint8_t *dest, int stride, void idct16x16_ref(const tran_low_t *in, uint8_t *dest, int stride,
int /*tx_type*/) { int /*tx_type*/) {
vpx_idct16x16_256_add_c(in, dest, stride); vp9_idct16x16_256_add_c(in, dest, stride);
} }
void fht16x16_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) { void fht16x16_ref(const int16_t *in, tran_low_t *out, int stride,
int tx_type) {
vp9_fht16x16_c(in, out, stride, tx_type); vp9_fht16x16_c(in, out, stride, tx_type);
} }
@ -256,57 +289,57 @@ void iht16x16_ref(const tran_low_t *in, uint8_t *dest, int stride,
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
void idct16x16_10(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_10(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_256_add_c(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct16x16_256_add_c(in, out, stride, 10);
} }
void idct16x16_12(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_12(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_256_add_c(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct16x16_256_add_c(in, out, stride, 12);
} }
void idct16x16_10_ref(const tran_low_t *in, uint8_t *out, int stride, void idct16x16_10_ref(const tran_low_t *in, uint8_t *out, int stride,
int /*tx_type*/) { int tx_type) {
idct16x16_10(in, out, stride); idct16x16_10(in, out, stride);
} }
void idct16x16_12_ref(const tran_low_t *in, uint8_t *out, int stride, void idct16x16_12_ref(const tran_low_t *in, uint8_t *out, int stride,
int /*tx_type*/) { int tx_type) {
idct16x16_12(in, out, stride); idct16x16_12(in, out, stride);
} }
void iht16x16_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) { void iht16x16_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht16x16_256_add_c(in, CAST_TO_SHORTPTR(out), stride, tx_type, 10); vp9_highbd_iht16x16_256_add_c(in, out, stride, tx_type, 10);
} }
void iht16x16_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) { void iht16x16_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht16x16_256_add_c(in, CAST_TO_SHORTPTR(out), stride, tx_type, 12); vp9_highbd_iht16x16_256_add_c(in, out, stride, tx_type, 12);
} }
#if HAVE_SSE2
void idct16x16_10_add_10_c(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_10_add_10_c(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_10_add_c(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct16x16_10_add_c(in, out, stride, 10);
} }
void idct16x16_10_add_12_c(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_10_add_12_c(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_10_add_c(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct16x16_10_add_c(in, out, stride, 12);
} }
#if HAVE_SSE2
void idct16x16_256_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_256_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_256_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct16x16_256_add_sse2(in, out, stride, 10);
} }
void idct16x16_256_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_256_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_256_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct16x16_256_add_sse2(in, out, stride, 12);
} }
void idct16x16_10_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_10_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_10_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct16x16_10_add_sse2(in, out, stride, 10);
} }
void idct16x16_10_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct16x16_10_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct16x16_10_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct16x16_10_add_sse2(in, out, stride, 12);
} }
#endif // HAVE_SSE2 #endif
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
class Trans16x16TestBase { class Trans16x16TestBase {
public: public:
@ -323,13 +356,13 @@ class Trans16x16TestBase {
int64_t total_error = 0; int64_t total_error = 0;
const int count_test_block = 10000; const int count_test_block = 10000;
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
DECLARE_ALIGNED(16, int16_t, test_input_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, test_temp_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif #endif
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
@ -347,31 +380,33 @@ class Trans16x16TestBase {
} }
} }
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
RunFwdTxfm(test_input_block, test_temp_block, pitch_)); test_temp_block, pitch_));
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_)); ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, CAST_TO_BYTEPTR(dst16), pitch_)); RunInvTxfm(test_temp_block, CONVERT_TO_BYTEPTR(dst16), pitch_));
#endif #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
const int32_t diff = const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else #else
const int32_t diff = dst[j] - src[j]; const uint32_t diff = dst[j] - src[j];
#endif #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
if (max_error < error) max_error = error; if (max_error < error)
max_error = error;
total_error += error; total_error += error;
} }
} }
EXPECT_GE(1u << 2 * (bit_depth_ - 8), max_error) EXPECT_GE(1u << 2 * (bit_depth_ - 8), max_error)
<< "Error: 16x16 FHT/IHT has an individual round trip error > 1"; << "Error: 16x16 FHT/IHT has an individual round trip error > 1";
EXPECT_GE(count_test_block << 2 * (bit_depth_ - 8), total_error) EXPECT_GE(count_test_block << 2 * (bit_depth_ - 8), total_error)
@ -381,15 +416,14 @@ class Trans16x16TestBase {
void RunCoeffCheck() { void RunCoeffCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, input_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
}
fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_); fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_)); ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
@ -403,24 +437,28 @@ class Trans16x16TestBase {
void RunMemCheck() { void RunMemCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, input_extreme_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_; input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_;
} }
if (i == 0) { if (i == 0) {
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = mask_; for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = mask_;
} else if (i == 1) { } else if (i == 1) {
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = -mask_; for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = -mask_;
} }
fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_); fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
RunFwdTxfm(input_extreme_block, output_block, pitch_)); output_block, pitch_));
// The minimum quant value is 4. // The minimum quant value is 4.
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
@ -434,59 +472,65 @@ class Trans16x16TestBase {
void RunQuantCheck(int dc_thred, int ac_thred) { void RunQuantCheck(int dc_thred, int ac_thred) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 100000; const int count_test_block = 100000;
DECLARE_ALIGNED(16, int16_t, input_extreme_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, ref16, kNumCoeffs);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
if (bit_depth_ == VPX_BITS_8)
input_block[j] = rnd.Rand8() - rnd.Rand8();
else
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_; input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_;
} }
if (i == 0) { if (i == 0)
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = mask_; for (int j = 0; j < kNumCoeffs; ++j)
} input_extreme_block[j] = mask_;
if (i == 1) { if (i == 1)
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = -mask_; for (int j = 0; j < kNumCoeffs; ++j)
} input_extreme_block[j] = -mask_;
fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_); fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
// clear reconstructed pixel buffers // clear reconstructed pixel buffers
memset(dst, 0, kNumCoeffs * sizeof(uint8_t)); vpx_memset(dst, 0, kNumCoeffs * sizeof(uint8_t));
memset(ref, 0, kNumCoeffs * sizeof(uint8_t)); vpx_memset(ref, 0, kNumCoeffs * sizeof(uint8_t));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
memset(dst16, 0, kNumCoeffs * sizeof(uint16_t)); vpx_memset(dst16, 0, kNumCoeffs * sizeof(uint16_t));
memset(ref16, 0, kNumCoeffs * sizeof(uint16_t)); vpx_memset(ref16, 0, kNumCoeffs * sizeof(uint16_t));
#endif #endif
// quantization with maximum allowed step sizes // quantization with maximum allowed step sizes
output_ref_block[0] = (output_ref_block[0] / dc_thred) * dc_thred; output_ref_block[0] = (output_ref_block[0] / dc_thred) * dc_thred;
for (int j = 1; j < kNumCoeffs; ++j) { for (int j = 1; j < kNumCoeffs; ++j)
output_ref_block[j] = (output_ref_block[j] / ac_thred) * ac_thred; output_ref_block[j] = (output_ref_block[j] / ac_thred) * ac_thred;
}
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
inv_txfm_ref(output_ref_block, ref, pitch_, tx_type_); inv_txfm_ref(output_ref_block, ref, pitch_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block, dst, pitch_)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
inv_txfm_ref(output_ref_block, CAST_TO_BYTEPTR(ref16), pitch_, inv_txfm_ref(output_ref_block, CONVERT_TO_BYTEPTR(ref16), pitch_,
tx_type_); tx_type_);
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block,
RunInvTxfm(output_ref_block, CAST_TO_BYTEPTR(dst16), pitch_)); CONVERT_TO_BYTEPTR(dst16), pitch_));
#endif #endif
} }
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
for (int j = 0; j < kNumCoeffs; ++j) EXPECT_EQ(ref[j], dst[j]); for (int j = 0; j < kNumCoeffs; ++j)
EXPECT_EQ(ref[j], dst[j]);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
for (int j = 0; j < kNumCoeffs; ++j) EXPECT_EQ(ref16[j], dst16[j]); for (int j = 0; j < kNumCoeffs; ++j)
EXPECT_EQ(ref16[j], dst16[j]);
#endif #endif
} }
} }
@ -495,14 +539,14 @@ class Trans16x16TestBase {
void RunInvAccuracyCheck() { void RunInvAccuracyCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, in[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
double out_r[kNumCoeffs]; double out_r[kNumCoeffs];
@ -518,21 +562,21 @@ class Trans16x16TestBase {
src16[j] = rnd.Rand16() & mask_; src16[j] = rnd.Rand16() & mask_;
dst16[j] = rnd.Rand16() & mask_; dst16[j] = rnd.Rand16() & mask_;
in[j] = src16[j] - dst16[j]; in[j] = src16[j] - dst16[j];
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
} }
} }
reference_16x16_dct_2d(in, out_r); reference_16x16_dct_2d(in, out_r);
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
coeff[j] = static_cast<tran_low_t>(round(out_r[j])); coeff[j] = static_cast<tran_low_t>(round(out_r[j]));
}
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, 16)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, 16));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), 16)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
#endif // CONFIG_VP9_HIGHBITDEPTH 16));
#endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
@ -541,32 +585,32 @@ class Trans16x16TestBase {
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else #else
const uint32_t diff = dst[j] - src[j]; const uint32_t diff = dst[j] - src[j];
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
EXPECT_GE(1u, error) EXPECT_GE(1u, error)
<< "Error: 16x16 IDCT has error " << error << " at index " << j; << "Error: 16x16 IDCT has error " << error
<< " at index " << j;
} }
} }
} }
void CompareInvReference(IdctFunc ref_txfm, int thresh) { void CompareInvReference(IdctFunc ref_txfm, int thresh) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 10000; const int count_test_block = 10000;
const int eob = 10; const int eob = 10;
const int16_t *scan = vp9_default_scan_orders[TX_16X16].scan; const int16_t *scan = vp9_default_scan_orders[TX_16X16].scan;
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, ref16, kNumCoeffs);
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
if (j < eob) { if (j < eob) {
// Random values less than the threshold, either positive or negative // Random values less than the threshold, either positive or negative
coeff[scan[j]] = rnd(thresh) * (1 - 2 * (i % 2)); coeff[scan[j]] = rnd(thresh) * (1-2*(i%2));
} else { } else {
coeff[scan[j]] = 0; coeff[scan[j]] = 0;
} }
@ -577,7 +621,7 @@ class Trans16x16TestBase {
} else { } else {
dst16[j] = 0; dst16[j] = 0;
ref16[j] = 0; ref16[j] = 0;
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
} }
} }
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
@ -585,10 +629,10 @@ class Trans16x16TestBase {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
} else { } else {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
ref_txfm(coeff, CAST_TO_BYTEPTR(ref16), pitch_); ref_txfm(coeff, CONVERT_TO_BYTEPTR(ref16), pitch_);
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_)); pitch_));
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
@ -597,14 +641,14 @@ class Trans16x16TestBase {
bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j];
#else #else
const uint32_t diff = dst[j] - ref[j]; const uint32_t diff = dst[j] - ref[j];
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
EXPECT_EQ(0u, error) << "Error: 16x16 IDCT Comparison has error " EXPECT_EQ(0u, error)
<< error << " at index " << j; << "Error: 16x16 IDCT Comparison has error " << error
<< " at index " << j;
} }
} }
} }
int pitch_; int pitch_;
int tx_type_; int tx_type_;
vpx_bit_depth_t bit_depth_; vpx_bit_depth_t bit_depth_;
@ -613,25 +657,32 @@ class Trans16x16TestBase {
IhtFunc inv_txfm_ref; IhtFunc inv_txfm_ref;
}; };
class Trans16x16DCT : public Trans16x16TestBase, class Trans16x16DCT
public ::testing::TestWithParam<Dct16x16Param> { : public Trans16x16TestBase,
public ::testing::TestWithParam<Dct16x16Param> {
public: public:
virtual ~Trans16x16DCT() {} virtual ~Trans16x16DCT() {}
virtual void SetUp() { virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0); fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2); tx_type_ = GET_PARAM(2);
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
pitch_ = 16; pitch_ = 16;
fwd_txfm_ref = fdct16x16_ref; fwd_txfm_ref = fdct16x16_ref;
inv_txfm_ref = idct16x16_ref; inv_txfm_ref = idct16x16_ref;
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
switch (bit_depth_) { switch (bit_depth_) {
case VPX_BITS_10: inv_txfm_ref = idct16x16_10_ref; break; case VPX_BITS_10:
case VPX_BITS_12: inv_txfm_ref = idct16x16_12_ref; break; inv_txfm_ref = idct16x16_10_ref;
default: inv_txfm_ref = idct16x16_ref; break; break;
case VPX_BITS_12:
inv_txfm_ref = idct16x16_12_ref;
break;
default:
inv_txfm_ref = idct16x16_ref;
break;
} }
#else #else
inv_txfm_ref = idct16x16_ref; inv_txfm_ref = idct16x16_ref;
@ -651,11 +702,17 @@ class Trans16x16DCT : public Trans16x16TestBase,
IdctFunc inv_txfm_; IdctFunc inv_txfm_;
}; };
TEST_P(Trans16x16DCT, AccuracyCheck) { RunAccuracyCheck(); } TEST_P(Trans16x16DCT, AccuracyCheck) {
RunAccuracyCheck();
}
TEST_P(Trans16x16DCT, CoeffCheck) { RunCoeffCheck(); } TEST_P(Trans16x16DCT, CoeffCheck) {
RunCoeffCheck();
}
TEST_P(Trans16x16DCT, MemCheck) { RunMemCheck(); } TEST_P(Trans16x16DCT, MemCheck) {
RunMemCheck();
}
TEST_P(Trans16x16DCT, QuantCheck) { TEST_P(Trans16x16DCT, QuantCheck) {
// Use maximally allowed quantization step sizes for DC and AC // Use maximally allowed quantization step sizes for DC and AC
@ -663,27 +720,36 @@ TEST_P(Trans16x16DCT, QuantCheck) {
RunQuantCheck(1336, 1828); RunQuantCheck(1336, 1828);
} }
TEST_P(Trans16x16DCT, InvAccuracyCheck) { RunInvAccuracyCheck(); } TEST_P(Trans16x16DCT, InvAccuracyCheck) {
RunInvAccuracyCheck();
}
class Trans16x16HT : public Trans16x16TestBase, class Trans16x16HT
public ::testing::TestWithParam<Ht16x16Param> { : public Trans16x16TestBase,
public ::testing::TestWithParam<Ht16x16Param> {
public: public:
virtual ~Trans16x16HT() {} virtual ~Trans16x16HT() {}
virtual void SetUp() { virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0); fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2); tx_type_ = GET_PARAM(2);
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
pitch_ = 16; pitch_ = 16;
fwd_txfm_ref = fht16x16_ref; fwd_txfm_ref = fht16x16_ref;
inv_txfm_ref = iht16x16_ref; inv_txfm_ref = iht16x16_ref;
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
switch (bit_depth_) { switch (bit_depth_) {
case VPX_BITS_10: inv_txfm_ref = iht16x16_10; break; case VPX_BITS_10:
case VPX_BITS_12: inv_txfm_ref = iht16x16_12; break; inv_txfm_ref = iht16x16_10;
default: inv_txfm_ref = iht16x16_ref; break; break;
case VPX_BITS_12:
inv_txfm_ref = iht16x16_12;
break;
default:
inv_txfm_ref = iht16x16_ref;
break;
} }
#else #else
inv_txfm_ref = iht16x16_ref; inv_txfm_ref = iht16x16_ref;
@ -703,11 +769,17 @@ class Trans16x16HT : public Trans16x16TestBase,
IhtFunc inv_txfm_; IhtFunc inv_txfm_;
}; };
TEST_P(Trans16x16HT, AccuracyCheck) { RunAccuracyCheck(); } TEST_P(Trans16x16HT, AccuracyCheck) {
RunAccuracyCheck();
}
TEST_P(Trans16x16HT, CoeffCheck) { RunCoeffCheck(); } TEST_P(Trans16x16HT, CoeffCheck) {
RunCoeffCheck();
}
TEST_P(Trans16x16HT, MemCheck) { RunMemCheck(); } TEST_P(Trans16x16HT, MemCheck) {
RunMemCheck();
}
TEST_P(Trans16x16HT, QuantCheck) { TEST_P(Trans16x16HT, QuantCheck) {
// The encoder skips any non-DC intra prediction modes, // The encoder skips any non-DC intra prediction modes,
@ -715,23 +787,24 @@ TEST_P(Trans16x16HT, QuantCheck) {
RunQuantCheck(429, 729); RunQuantCheck(429, 729);
} }
class InvTrans16x16DCT : public Trans16x16TestBase, class InvTrans16x16DCT
public ::testing::TestWithParam<Idct16x16Param> { : public Trans16x16TestBase,
public ::testing::TestWithParam<Idct16x16Param> {
public: public:
virtual ~InvTrans16x16DCT() {} virtual ~InvTrans16x16DCT() {}
virtual void SetUp() { virtual void SetUp() {
ref_txfm_ = GET_PARAM(0); ref_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
thresh_ = GET_PARAM(2); thresh_ = GET_PARAM(2);
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
pitch_ = 16; pitch_ = 16;
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
} }
virtual void TearDown() { libvpx_test::ClearSystemState(); } virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected: protected:
void RunFwdTxfm(int16_t * /*in*/, tran_low_t * /*out*/, int /*stride*/) {} void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) {}
void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) {
inv_txfm_(out, dst, stride); inv_txfm_(out, dst, stride);
} }
@ -745,21 +818,21 @@ TEST_P(InvTrans16x16DCT, CompareReference) {
CompareInvReference(ref_txfm_, thresh_); CompareInvReference(ref_txfm_, thresh_);
} }
using ::testing::make_tuple; using std::tr1::make_tuple;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
C, Trans16x16DCT, C, Trans16x16DCT,
::testing::Values( ::testing::Values(
make_tuple(&vpx_highbd_fdct16x16_c, &idct16x16_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fdct16x16_c, &idct16x16_10, 0, VPX_BITS_10),
make_tuple(&vpx_highbd_fdct16x16_c, &idct16x16_12, 0, VPX_BITS_12), make_tuple(&vp9_highbd_fdct16x16_c, &idct16x16_12, 0, VPX_BITS_12),
make_tuple(&vpx_fdct16x16_c, &vpx_idct16x16_256_add_c, 0, VPX_BITS_8))); make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
#else #else
INSTANTIATE_TEST_CASE_P(C, Trans16x16DCT, INSTANTIATE_TEST_CASE_P(
::testing::Values(make_tuple(&vpx_fdct16x16_c, C, Trans16x16DCT,
&vpx_idct16x16_256_add_c, ::testing::Values(
0, VPX_BITS_8))); make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
@ -785,47 +858,60 @@ INSTANTIATE_TEST_CASE_P(
make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8), make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8), make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3, VPX_BITS_8))); make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
#if HAVE_NEON && !CONFIG_EMULATE_HARDWARE #if HAVE_NEON_ASM && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, Trans16x16DCT, NEON, Trans16x16DCT,
::testing::Values(make_tuple(&vpx_fdct16x16_neon, ::testing::Values(
&vpx_idct16x16_256_add_neon, 0, VPX_BITS_8))); make_tuple(&vp9_fdct16x16_c,
#endif // HAVE_NEON && !CONFIG_EMULATE_HARDWARE &vp9_idct16x16_256_add_neon, 0, VPX_BITS_8)));
#endif
#if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans16x16DCT, SSE2, Trans16x16DCT,
::testing::Values(make_tuple(&vpx_fdct16x16_sse2, ::testing::Values(
&vpx_idct16x16_256_add_sse2, 0, VPX_BITS_8))); make_tuple(&vp9_fdct16x16_sse2,
&vp9_idct16x16_256_add_sse2, 0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans16x16HT, SSE2, Trans16x16HT,
::testing::Values(make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, ::testing::Values(
0, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 0,
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, VPX_BITS_8),
1, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 1,
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, VPX_BITS_8),
2, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 2,
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, VPX_BITS_8),
3, VPX_BITS_8))); make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 3,
#endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE VPX_BITS_8)));
#endif
#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans16x16DCT, SSE2, Trans16x16DCT,
::testing::Values( ::testing::Values(
make_tuple(&vpx_highbd_fdct16x16_sse2, &idct16x16_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fdct16x16_sse2,
make_tuple(&vpx_highbd_fdct16x16_c, &idct16x16_256_add_10_sse2, 0, &idct16x16_10, 0, VPX_BITS_10),
VPX_BITS_10), make_tuple(&vp9_highbd_fdct16x16_c,
make_tuple(&vpx_highbd_fdct16x16_sse2, &idct16x16_12, 0, VPX_BITS_12), &idct16x16_256_add_10_sse2, 0, VPX_BITS_10),
make_tuple(&vpx_highbd_fdct16x16_c, &idct16x16_256_add_12_sse2, 0, make_tuple(&vp9_highbd_fdct16x16_sse2,
VPX_BITS_12), &idct16x16_12, 0, VPX_BITS_12),
make_tuple(&vpx_fdct16x16_sse2, &vpx_idct16x16_256_add_c, 0, make_tuple(&vp9_highbd_fdct16x16_c,
VPX_BITS_8))); &idct16x16_256_add_12_sse2, 0, VPX_BITS_12),
make_tuple(&vp9_fdct16x16_sse2,
&vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans16x16HT, SSE2, Trans16x16HT,
::testing::Values( ::testing::Values(
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 1, VPX_BITS_10),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 2, VPX_BITS_10),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 3, VPX_BITS_10),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 0, VPX_BITS_12),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 1, VPX_BITS_12),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 2, VPX_BITS_12),
make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 3, VPX_BITS_12),
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 0, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8),
@ -835,35 +921,22 @@ INSTANTIATE_TEST_CASE_P(
// that to test both branches. // that to test both branches.
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, InvTrans16x16DCT, SSE2, InvTrans16x16DCT,
::testing::Values(make_tuple(&idct16x16_10_add_10_c,
&idct16x16_10_add_10_sse2, 3167, VPX_BITS_10),
make_tuple(&idct16x16_10, &idct16x16_256_add_10_sse2,
3167, VPX_BITS_10),
make_tuple(&idct16x16_10_add_12_c,
&idct16x16_10_add_12_sse2, 3167, VPX_BITS_12),
make_tuple(&idct16x16_12, &idct16x16_256_add_12_sse2,
3167, VPX_BITS_12)));
#endif // HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
#if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(MSA, Trans16x16DCT,
::testing::Values(make_tuple(&vpx_fdct16x16_msa,
&vpx_idct16x16_256_add_msa,
0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P(
MSA, Trans16x16HT,
::testing::Values( ::testing::Values(
make_tuple(&vp9_fht16x16_msa, &vp9_iht16x16_256_add_msa, 0, VPX_BITS_8), make_tuple(&idct16x16_10_add_10_c,
make_tuple(&vp9_fht16x16_msa, &vp9_iht16x16_256_add_msa, 1, VPX_BITS_8), &idct16x16_10_add_10_sse2, 3167, VPX_BITS_10),
make_tuple(&vp9_fht16x16_msa, &vp9_iht16x16_256_add_msa, 2, VPX_BITS_8), make_tuple(&idct16x16_10,
make_tuple(&vp9_fht16x16_msa, &vp9_iht16x16_256_add_msa, 3, &idct16x16_256_add_10_sse2, 3167, VPX_BITS_10),
VPX_BITS_8))); make_tuple(&idct16x16_10_add_12_c,
#endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE &idct16x16_10_add_12_sse2, 3167, VPX_BITS_12),
make_tuple(&idct16x16_12,
&idct16x16_256_add_12_sse2, 3167, VPX_BITS_12)));
#endif
#if HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSSE3 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(VSX, Trans16x16DCT, INSTANTIATE_TEST_CASE_P(
::testing::Values(make_tuple(&vpx_fdct16x16_c, SSSE3, Trans16x16DCT,
&vpx_idct16x16_256_add_vsx, ::testing::Values(
0, VPX_BITS_8))); make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_ssse3, 0,
#endif // HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE VPX_BITS_8)));
#endif
} // namespace } // namespace

View File

@ -13,23 +13,28 @@
#include <string.h> #include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vp9_rtcd.h"
#include "./vpx_config.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h" #include "test/acm_random.h"
#include "test/clear_system_state.h" #include "test/clear_system_state.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
#include "test/util.h" #include "test/util.h"
#include "./vpx_config.h"
#include "./vp9_rtcd.h"
#include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_entropy.h"
#include "vpx/vpx_codec.h" #include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h" #include "vpx/vpx_integer.h"
#include "vpx_ports/mem.h"
#include "vpx_ports/msvc.h" // for round()
using libvpx_test::ACMRandom; using libvpx_test::ACMRandom;
namespace { namespace {
#ifdef _MSC_VER
static int round(double x) {
if (x < 0)
return static_cast<int>(ceil(x - 0.5));
else
return static_cast<int>(floor(x + 0.5));
}
#endif
const int kNumCoeffs = 1024; const int kNumCoeffs = 1024;
const double kPi = 3.141592653589793238462643383279502884; const double kPi = 3.141592653589793238462643383279502884;
@ -37,10 +42,10 @@ void reference_32x32_dct_1d(const double in[32], double out[32]) {
const double kInvSqrt2 = 0.707106781186547524400844362104; const double kInvSqrt2 = 0.707106781186547524400844362104;
for (int k = 0; k < 32; k++) { for (int k = 0; k < 32; k++) {
out[k] = 0.0; out[k] = 0.0;
for (int n = 0; n < 32; n++) { for (int n = 0; n < 32; n++)
out[k] += in[n] * cos(kPi * (2 * n + 1) * k / 64.0); out[k] += in[n] * cos(kPi * (2 * n + 1) * k / 64.0);
} if (k == 0)
if (k == 0) out[k] = out[k] * kInvSqrt2; out[k] = out[k] * kInvSqrt2;
} }
} }
@ -49,35 +54,43 @@ void reference_32x32_dct_2d(const int16_t input[kNumCoeffs],
// First transform columns // First transform columns
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
double temp_in[32], temp_out[32]; double temp_in[32], temp_out[32];
for (int j = 0; j < 32; ++j) temp_in[j] = input[j * 32 + i]; for (int j = 0; j < 32; ++j)
temp_in[j] = input[j*32 + i];
reference_32x32_dct_1d(temp_in, temp_out); reference_32x32_dct_1d(temp_in, temp_out);
for (int j = 0; j < 32; ++j) output[j * 32 + i] = temp_out[j]; for (int j = 0; j < 32; ++j)
output[j * 32 + i] = temp_out[j];
} }
// Then transform rows // Then transform rows
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
double temp_in[32], temp_out[32]; double temp_in[32], temp_out[32];
for (int j = 0; j < 32; ++j) temp_in[j] = output[j + i * 32]; for (int j = 0; j < 32; ++j)
temp_in[j] = output[j + i*32];
reference_32x32_dct_1d(temp_in, temp_out); reference_32x32_dct_1d(temp_in, temp_out);
// Scale by some magic number // Scale by some magic number
for (int j = 0; j < 32; ++j) output[j + i * 32] = temp_out[j] / 4; for (int j = 0; j < 32; ++j)
output[j + i * 32] = temp_out[j] / 4;
} }
} }
typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride);
typedef ::testing::tuple<FwdTxfmFunc, InvTxfmFunc, int, vpx_bit_depth_t> typedef std::tr1::tuple<FwdTxfmFunc, InvTxfmFunc, int, vpx_bit_depth_t>
Trans32x32Param; Trans32x32Param;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
void idct32x32_8(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct32x32_1024_add_c(in, out, stride, 8);
}
void idct32x32_10(const tran_low_t *in, uint8_t *out, int stride) { void idct32x32_10(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct32x32_1024_add_c(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct32x32_1024_add_c(in, out, stride, 10);
} }
void idct32x32_12(const tran_low_t *in, uint8_t *out, int stride) { void idct32x32_12(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct32x32_1024_add_c(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct32x32_1024_add_c(in, out, stride, 12);
} }
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
class Trans32x32Test : public ::testing::TestWithParam<Trans32x32Param> { class Trans32x32Test : public ::testing::TestWithParam<Trans32x32Param> {
public: public:
@ -85,8 +98,8 @@ class Trans32x32Test : public ::testing::TestWithParam<Trans32x32Param> {
virtual void SetUp() { virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0); fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
version_ = GET_PARAM(2); // 0: high precision forward transform version_ = GET_PARAM(2); // 0: high precision forward transform
// 1: low precision version for rd loop // 1: low precision version for rd loop
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
} }
@ -106,13 +119,13 @@ TEST_P(Trans32x32Test, AccuracyCheck) {
uint32_t max_error = 0; uint32_t max_error = 0;
int64_t total_error = 0; int64_t total_error = 0;
const int count_test_block = 10000; const int count_test_block = 10000;
DECLARE_ALIGNED(16, int16_t, test_input_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, test_temp_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
@ -136,20 +149,21 @@ TEST_P(Trans32x32Test, AccuracyCheck) {
ASM_REGISTER_STATE_CHECK(inv_txfm_(test_temp_block, dst, 32)); ASM_REGISTER_STATE_CHECK(inv_txfm_(test_temp_block, dst, 32));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(inv_txfm_(test_temp_block,
inv_txfm_(test_temp_block, CAST_TO_BYTEPTR(dst16), 32)); CONVERT_TO_BYTEPTR(dst16), 32));
#endif #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
const int32_t diff = const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else #else
const int32_t diff = dst[j] - src[j]; const uint32_t diff = dst[j] - src[j];
#endif #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
if (max_error < error) max_error = error; if (max_error < error)
max_error = error;
total_error += error; total_error += error;
} }
} }
@ -170,17 +184,16 @@ TEST_P(Trans32x32Test, CoeffCheck) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, input_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
}
const int stride = 32; const int stride = 32;
vpx_fdct32x32_c(input_block, output_ref_block, stride); vp9_fdct32x32_c(input_block, output_ref_block, stride);
ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block, output_block, stride)); ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block, output_block, stride));
if (version_ == 0) { if (version_ == 0) {
@ -199,23 +212,27 @@ TEST_P(Trans32x32Test, MemCheck) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 2000; const int count_test_block = 2000;
DECLARE_ALIGNED(16, int16_t, input_extreme_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
input_extreme_block[j] = rnd.Rand8() & 1 ? mask_ : -mask_; input_extreme_block[j] = rnd.Rand8() & 1 ? mask_ : -mask_;
} }
if (i == 0) { if (i == 0) {
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = mask_; for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = mask_;
} else if (i == 1) { } else if (i == 1) {
for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = -mask_; for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = -mask_;
} }
const int stride = 32; const int stride = 32;
vpx_fdct32x32_c(input_extreme_block, output_ref_block, stride); vp9_fdct32x32_c(input_extreme_block, output_ref_block, stride);
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
fwd_txfm_(input_extreme_block, output_block, stride)); fwd_txfm_(input_extreme_block, output_block, stride));
@ -240,13 +257,13 @@ TEST_P(Trans32x32Test, MemCheck) {
TEST_P(Trans32x32Test, InverseAccuracy) { TEST_P(Trans32x32Test, InverseAccuracy) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, in[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
@ -268,14 +285,13 @@ TEST_P(Trans32x32Test, InverseAccuracy) {
} }
reference_32x32_dct_2d(in, out_r); reference_32x32_dct_2d(in, out_r);
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
coeff[j] = static_cast<tran_low_t>(round(out_r[j])); coeff[j] = static_cast<tran_low_t>(round(out_r[j]));
}
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, dst, 32)); ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, dst, 32));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, CAST_TO_BYTEPTR(dst16), 32)); ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, CONVERT_TO_BYTEPTR(dst16), 32));
#endif #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
@ -286,92 +302,84 @@ TEST_P(Trans32x32Test, InverseAccuracy) {
const int diff = dst[j] - src[j]; const int diff = dst[j] - src[j];
#endif #endif
const int error = diff * diff; const int error = diff * diff;
EXPECT_GE(1, error) << "Error: 32x32 IDCT has error " << error EXPECT_GE(1, error)
<< " at index " << j; << "Error: 32x32 IDCT has error " << error
<< " at index " << j;
} }
} }
} }
using ::testing::make_tuple; using std::tr1::make_tuple;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
C, Trans32x32Test, C, Trans32x32Test,
::testing::Values( ::testing::Values(
make_tuple(&vpx_highbd_fdct32x32_c, &idct32x32_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fdct32x32_c,
make_tuple(&vpx_highbd_fdct32x32_rd_c, &idct32x32_10, 1, VPX_BITS_10), &idct32x32_10, 0, VPX_BITS_10),
make_tuple(&vpx_highbd_fdct32x32_c, &idct32x32_12, 0, VPX_BITS_12), make_tuple(&vp9_highbd_fdct32x32_rd_c,
make_tuple(&vpx_highbd_fdct32x32_rd_c, &idct32x32_12, 1, VPX_BITS_12), &idct32x32_10, 1, VPX_BITS_10),
make_tuple(&vpx_fdct32x32_c, &vpx_idct32x32_1024_add_c, 0, VPX_BITS_8), make_tuple(&vp9_highbd_fdct32x32_c,
make_tuple(&vpx_fdct32x32_rd_c, &vpx_idct32x32_1024_add_c, 1, &idct32x32_12, 0, VPX_BITS_12),
VPX_BITS_8))); make_tuple(&vp9_highbd_fdct32x32_rd_c,
&idct32x32_12, 1, VPX_BITS_12),
make_tuple(&vp9_fdct32x32_c,
&vp9_idct32x32_1024_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fdct32x32_rd_c,
&vp9_idct32x32_1024_add_c, 1, VPX_BITS_8)));
#else #else
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
C, Trans32x32Test, C, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_c, &vpx_idct32x32_1024_add_c, 0, ::testing::Values(
VPX_BITS_8), make_tuple(&vp9_fdct32x32_c,
make_tuple(&vpx_fdct32x32_rd_c, &vpx_idct32x32_1024_add_c, &vp9_idct32x32_1024_add_c, 0, VPX_BITS_8),
1, VPX_BITS_8))); make_tuple(&vp9_fdct32x32_rd_c,
#endif // CONFIG_VP9_HIGHBITDEPTH &vp9_idct32x32_1024_add_c, 1, VPX_BITS_8)));
#endif
#if HAVE_NEON && !CONFIG_EMULATE_HARDWARE #if HAVE_NEON_ASM && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, Trans32x32Test, NEON, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_neon, ::testing::Values(
&vpx_idct32x32_1024_add_neon, 0, VPX_BITS_8), make_tuple(&vp9_fdct32x32_c,
make_tuple(&vpx_fdct32x32_rd_neon, &vp9_idct32x32_1024_add_neon, 0, VPX_BITS_8),
&vpx_idct32x32_1024_add_neon, 1, VPX_BITS_8))); make_tuple(&vp9_fdct32x32_rd_c,
#endif // HAVE_NEON && !CONFIG_EMULATE_HARDWARE &vp9_idct32x32_1024_add_neon, 1, VPX_BITS_8)));
#endif
#if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans32x32Test, SSE2, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_sse2, ::testing::Values(
&vpx_idct32x32_1024_add_sse2, 0, VPX_BITS_8), make_tuple(&vp9_fdct32x32_sse2,
make_tuple(&vpx_fdct32x32_rd_sse2, &vp9_idct32x32_1024_add_sse2, 0, VPX_BITS_8),
&vpx_idct32x32_1024_add_sse2, 1, VPX_BITS_8))); make_tuple(&vp9_fdct32x32_rd_sse2,
#endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE &vp9_idct32x32_1024_add_sse2, 1, VPX_BITS_8)));
#endif
#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, Trans32x32Test, SSE2, Trans32x32Test,
::testing::Values( ::testing::Values(
make_tuple(&vpx_highbd_fdct32x32_sse2, &idct32x32_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fdct32x32_sse2, &idct32x32_10, 0, VPX_BITS_10),
make_tuple(&vpx_highbd_fdct32x32_rd_sse2, &idct32x32_10, 1, make_tuple(&vp9_highbd_fdct32x32_rd_sse2, &idct32x32_10, 1,
VPX_BITS_10), VPX_BITS_10),
make_tuple(&vpx_highbd_fdct32x32_sse2, &idct32x32_12, 0, VPX_BITS_12), make_tuple(&vp9_highbd_fdct32x32_sse2, &idct32x32_12, 0, VPX_BITS_12),
make_tuple(&vpx_highbd_fdct32x32_rd_sse2, &idct32x32_12, 1, make_tuple(&vp9_highbd_fdct32x32_rd_sse2, &idct32x32_12, 1,
VPX_BITS_12), VPX_BITS_12),
make_tuple(&vpx_fdct32x32_sse2, &vpx_idct32x32_1024_add_c, 0, make_tuple(&vp9_fdct32x32_sse2, &vp9_idct32x32_1024_add_c, 0,
VPX_BITS_8), VPX_BITS_8),
make_tuple(&vpx_fdct32x32_rd_sse2, &vpx_idct32x32_1024_add_c, 1, make_tuple(&vp9_fdct32x32_rd_sse2, &vp9_idct32x32_1024_add_c, 1,
VPX_BITS_8))); VPX_BITS_8)));
#endif // HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #endif
#if HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
AVX2, Trans32x32Test, AVX2, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_avx2, ::testing::Values(
&vpx_idct32x32_1024_add_sse2, 0, VPX_BITS_8), make_tuple(&vp9_fdct32x32_avx2,
make_tuple(&vpx_fdct32x32_rd_avx2, &vp9_idct32x32_1024_add_sse2, 0, VPX_BITS_8),
&vpx_idct32x32_1024_add_sse2, 1, VPX_BITS_8))); make_tuple(&vp9_fdct32x32_rd_avx2,
#endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE &vp9_idct32x32_1024_add_sse2, 1, VPX_BITS_8)));
#endif
#if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
MSA, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_msa,
&vpx_idct32x32_1024_add_msa, 0, VPX_BITS_8),
make_tuple(&vpx_fdct32x32_rd_msa,
&vpx_idct32x32_1024_add_msa, 1, VPX_BITS_8)));
#endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
#if HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
VSX, Trans32x32Test,
::testing::Values(make_tuple(&vpx_fdct32x32_c, &vpx_idct32x32_1024_add_vsx,
0, VPX_BITS_8),
make_tuple(&vpx_fdct32x32_rd_c,
&vpx_idct32x32_1024_add_vsx, 1, VPX_BITS_8)));
#endif // HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
} // namespace } // namespace

View File

@ -1,169 +0,0 @@
/*
* Copyright (c) 2017 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/buffer.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
#include "vpx_dsp/vpx_dsp_common.h"
using ::testing::make_tuple;
using ::testing::tuple;
using libvpx_test::ACMRandom;
using libvpx_test::Buffer;
namespace {
typedef void (*PartialFdctFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef tuple<PartialFdctFunc, int /* size */, vpx_bit_depth_t>
PartialFdctParam;
tran_low_t partial_fdct_ref(const Buffer<int16_t> &in, int size) {
int64_t sum = 0;
for (int y = 0; y < size; ++y) {
for (int x = 0; x < size; ++x) {
sum += in.TopLeftPixel()[y * in.stride() + x];
}
}
switch (size) {
case 4: sum *= 2; break;
case 8: /*sum = sum;*/ break;
case 16: sum >>= 1; break;
case 32: sum >>= 3; break;
}
return static_cast<tran_low_t>(sum);
}
class PartialFdctTest : public ::testing::TestWithParam<PartialFdctParam> {
public:
PartialFdctTest() {
fwd_txfm_ = GET_PARAM(0);
size_ = GET_PARAM(1);
bit_depth_ = GET_PARAM(2);
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
void RunTest() {
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int16_t maxvalue =
clip_pixel_highbd(std::numeric_limits<int16_t>::max(), bit_depth_);
const int16_t minvalue = -maxvalue;
Buffer<int16_t> input_block =
Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
ASSERT_TRUE(input_block.Init());
Buffer<tran_low_t> output_block = Buffer<tran_low_t>(size_, size_, 0, 16);
ASSERT_TRUE(output_block.Init());
for (int i = 0; i < 100; ++i) {
if (i == 0) {
input_block.Set(maxvalue);
} else if (i == 1) {
input_block.Set(minvalue);
} else {
input_block.Set(&rnd, minvalue, maxvalue);
}
ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block.TopLeftPixel(),
output_block.TopLeftPixel(),
input_block.stride()));
EXPECT_EQ(partial_fdct_ref(input_block, size_),
output_block.TopLeftPixel()[0]);
}
}
PartialFdctFunc fwd_txfm_;
vpx_bit_depth_t bit_depth_;
int size_;
};
TEST_P(PartialFdctTest, PartialFdctTest) { RunTest(); }
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
C, PartialFdctTest,
::testing::Values(make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_12),
make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_10),
make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_12),
make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_10),
make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_12),
make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_10),
make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
C, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
SSE2, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct32x32_1_sse2, 32, VPX_BITS_8),
make_tuple(&vpx_fdct16x16_1_sse2, 16, VPX_BITS_8),
make_tuple(&vpx_fdct8x8_1_sse2, 8, VPX_BITS_8),
make_tuple(&vpx_fdct4x4_1_sse2, 4, VPX_BITS_8)));
#endif // HAVE_SSE2
#if HAVE_NEON
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
NEON, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_12),
make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_10),
make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
NEON, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // HAVE_NEON
#if HAVE_MSA
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(MSA, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct8x8_1_msa, 8,
VPX_BITS_8)));
#else // !CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
MSA, PartialFdctTest,
::testing::Values(make_tuple(&vpx_fdct32x32_1_msa, 32, VPX_BITS_8),
make_tuple(&vpx_fdct16x16_1_msa, 16, VPX_BITS_8),
make_tuple(&vpx_fdct8x8_1_msa, 8, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // HAVE_MSA
} // namespace

View File

@ -1,728 +0,0 @@
/*
* Copyright (c) 2017 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vp9_rtcd.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/buffer.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vp9/common/vp9_entropy.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
#include "vpx_ports/mem.h"
using ::testing::make_tuple;
using ::testing::tuple;
using libvpx_test::ACMRandom;
using libvpx_test::Buffer;
namespace {
typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride);
typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
int tx_type);
typedef void (*FhtFuncRef)(const Buffer<int16_t> &in, Buffer<tran_low_t> *out,
int size, int tx_type);
typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type);
typedef void (*IhtWithBdFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type, int bd);
template <FdctFunc fn>
void fdct_wrapper(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
(void)tx_type;
fn(in, out, stride);
}
template <IdctFunc fn>
void idct_wrapper(const tran_low_t *in, uint8_t *out, int stride, int tx_type,
int bd) {
(void)tx_type;
(void)bd;
fn(in, out, stride);
}
template <IhtFunc fn>
void iht_wrapper(const tran_low_t *in, uint8_t *out, int stride, int tx_type,
int bd) {
(void)bd;
fn(in, out, stride, tx_type);
}
#if CONFIG_VP9_HIGHBITDEPTH
typedef void (*HighbdIdctFunc)(const tran_low_t *in, uint16_t *out, int stride,
int bd);
typedef void (*HighbdIhtFunc)(const tran_low_t *in, uint16_t *out, int stride,
int tx_type, int bd);
template <HighbdIdctFunc fn>
void highbd_idct_wrapper(const tran_low_t *in, uint8_t *out, int stride,
int tx_type, int bd) {
(void)tx_type;
fn(in, CAST_TO_SHORTPTR(out), stride, bd);
}
template <HighbdIhtFunc fn>
void highbd_iht_wrapper(const tran_low_t *in, uint8_t *out, int stride,
int tx_type, int bd) {
fn(in, CAST_TO_SHORTPTR(out), stride, tx_type, bd);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
struct FuncInfo {
FhtFunc ft_func;
IhtWithBdFunc it_func;
int size;
int pixel_size;
};
/* forward transform, inverse transform, size, transform type, bit depth */
typedef tuple<int, const FuncInfo *, int, vpx_bit_depth_t> DctParam;
void fdct_ref(const Buffer<int16_t> &in, Buffer<tran_low_t> *out, int size,
int /*tx_type*/) {
const int16_t *i = in.TopLeftPixel();
const int i_stride = in.stride();
tran_low_t *o = out->TopLeftPixel();
if (size == 4) {
vpx_fdct4x4_c(i, o, i_stride);
} else if (size == 8) {
vpx_fdct8x8_c(i, o, i_stride);
} else if (size == 16) {
vpx_fdct16x16_c(i, o, i_stride);
} else if (size == 32) {
vpx_fdct32x32_c(i, o, i_stride);
}
}
void fht_ref(const Buffer<int16_t> &in, Buffer<tran_low_t> *out, int size,
int tx_type) {
const int16_t *i = in.TopLeftPixel();
const int i_stride = in.stride();
tran_low_t *o = out->TopLeftPixel();
if (size == 4) {
vp9_fht4x4_c(i, o, i_stride, tx_type);
} else if (size == 8) {
vp9_fht8x8_c(i, o, i_stride, tx_type);
} else if (size == 16) {
vp9_fht16x16_c(i, o, i_stride, tx_type);
}
}
void fwht_ref(const Buffer<int16_t> &in, Buffer<tran_low_t> *out, int size,
int /*tx_type*/) {
ASSERT_EQ(size, 4);
vp9_fwht4x4_c(in.TopLeftPixel(), out->TopLeftPixel(), in.stride());
}
class TransTestBase : public ::testing::TestWithParam<DctParam> {
public:
virtual void SetUp() {
rnd_.Reset(ACMRandom::DeterministicSeed());
const int idx = GET_PARAM(0);
const FuncInfo *func_info = &(GET_PARAM(1)[idx]);
tx_type_ = GET_PARAM(2);
bit_depth_ = GET_PARAM(3);
fwd_txfm_ = func_info->ft_func;
inv_txfm_ = func_info->it_func;
size_ = func_info->size;
pixel_size_ = func_info->pixel_size;
max_pixel_value_ = (1 << bit_depth_) - 1;
// Randomize stride_ to a value less than or equal to 1024
stride_ = rnd_(1024) + 1;
if (stride_ < size_) {
stride_ = size_;
}
// Align stride_ to 16 if it's bigger than 16.
if (stride_ > 16) {
stride_ &= ~15;
}
block_size_ = size_ * stride_;
src_ = reinterpret_cast<uint8_t *>(
vpx_memalign(16, pixel_size_ * block_size_));
ASSERT_TRUE(src_ != NULL);
dst_ = reinterpret_cast<uint8_t *>(
vpx_memalign(16, pixel_size_ * block_size_));
ASSERT_TRUE(dst_ != NULL);
}
virtual void TearDown() {
vpx_free(src_);
src_ = NULL;
vpx_free(dst_);
dst_ = NULL;
libvpx_test::ClearSystemState();
}
void InitMem() {
if (pixel_size_ == 1 && bit_depth_ > VPX_BITS_8) return;
if (pixel_size_ == 1) {
for (int j = 0; j < block_size_; ++j) {
src_[j] = rnd_.Rand16() & max_pixel_value_;
}
for (int j = 0; j < block_size_; ++j) {
dst_[j] = rnd_.Rand16() & max_pixel_value_;
}
} else {
ASSERT_EQ(pixel_size_, 2);
uint16_t *const src = reinterpret_cast<uint16_t *>(src_);
uint16_t *const dst = reinterpret_cast<uint16_t *>(dst_);
for (int j = 0; j < block_size_; ++j) {
src[j] = rnd_.Rand16() & max_pixel_value_;
}
for (int j = 0; j < block_size_; ++j) {
dst[j] = rnd_.Rand16() & max_pixel_value_;
}
}
}
void RunFwdTxfm(const Buffer<int16_t> &in, Buffer<tran_low_t> *out) {
fwd_txfm_(in.TopLeftPixel(), out->TopLeftPixel(), in.stride(), tx_type_);
}
void RunInvTxfm(const Buffer<tran_low_t> &in, uint8_t *out) {
inv_txfm_(in.TopLeftPixel(), out, stride_, tx_type_, bit_depth_);
}
protected:
void RunAccuracyCheck(int limit) {
if (pixel_size_ == 1 && bit_depth_ > VPX_BITS_8) return;
ACMRandom rnd(ACMRandom::DeterministicSeed());
Buffer<int16_t> test_input_block =
Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
ASSERT_TRUE(test_input_block.Init());
Buffer<tran_low_t> test_temp_block =
Buffer<tran_low_t>(size_, size_, 0, 16);
ASSERT_TRUE(test_temp_block.Init());
uint32_t max_error = 0;
int64_t total_error = 0;
const int count_test_block = 10000;
for (int i = 0; i < count_test_block; ++i) {
InitMem();
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
if (pixel_size_ == 1) {
test_input_block.TopLeftPixel()[h * test_input_block.stride() + w] =
src_[h * stride_ + w] - dst_[h * stride_ + w];
} else {
ASSERT_EQ(pixel_size_, 2);
const uint16_t *const src = reinterpret_cast<uint16_t *>(src_);
const uint16_t *const dst = reinterpret_cast<uint16_t *>(dst_);
test_input_block.TopLeftPixel()[h * test_input_block.stride() + w] =
src[h * stride_ + w] - dst[h * stride_ + w];
}
}
}
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block, &test_temp_block));
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst_));
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
int diff;
if (pixel_size_ == 1) {
diff = dst_[h * stride_ + w] - src_[h * stride_ + w];
} else {
ASSERT_EQ(pixel_size_, 2);
const uint16_t *const src = reinterpret_cast<uint16_t *>(src_);
const uint16_t *const dst = reinterpret_cast<uint16_t *>(dst_);
diff = dst[h * stride_ + w] - src[h * stride_ + w];
}
const uint32_t error = diff * diff;
if (max_error < error) max_error = error;
total_error += error;
}
}
}
EXPECT_GE(static_cast<uint32_t>(limit), max_error)
<< "Error: " << size_ << "x" << size_
<< " transform/inverse transform has an individual round trip error > "
<< limit;
EXPECT_GE(count_test_block * limit, total_error)
<< "Error: " << size_ << "x" << size_
<< " transform/inverse transform has average round trip error > "
<< limit << " per block";
}
void RunCoeffCheck() {
if (pixel_size_ == 1 && bit_depth_ > VPX_BITS_8) return;
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 5000;
Buffer<int16_t> input_block =
Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
ASSERT_TRUE(input_block.Init());
Buffer<tran_low_t> output_ref_block = Buffer<tran_low_t>(size_, size_, 0);
ASSERT_TRUE(output_ref_block.Init());
Buffer<tran_low_t> output_block = Buffer<tran_low_t>(size_, size_, 0, 16);
ASSERT_TRUE(output_block.Init());
for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-max_pixel_value_,
// max_pixel_value_].
input_block.Set(&rnd, -max_pixel_value_, max_pixel_value_);
fwd_txfm_ref(input_block, &output_ref_block, size_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, &output_block));
// The minimum quant value is 4.
EXPECT_TRUE(output_block.CheckValues(output_ref_block));
if (::testing::Test::HasFailure()) {
printf("Size: %d Transform type: %d\n", size_, tx_type_);
output_block.PrintDifference(output_ref_block);
return;
}
}
}
void RunMemCheck() {
if (pixel_size_ == 1 && bit_depth_ > VPX_BITS_8) return;
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 5000;
Buffer<int16_t> input_extreme_block =
Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
ASSERT_TRUE(input_extreme_block.Init());
Buffer<tran_low_t> output_ref_block = Buffer<tran_low_t>(size_, size_, 0);
ASSERT_TRUE(output_ref_block.Init());
Buffer<tran_low_t> output_block = Buffer<tran_low_t>(size_, size_, 0, 16);
ASSERT_TRUE(output_block.Init());
for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with -max_pixel_value_ or max_pixel_value_.
if (i == 0) {
input_extreme_block.Set(max_pixel_value_);
} else if (i == 1) {
input_extreme_block.Set(-max_pixel_value_);
} else {
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
input_extreme_block
.TopLeftPixel()[h * input_extreme_block.stride() + w] =
rnd.Rand8() % 2 ? max_pixel_value_ : -max_pixel_value_;
}
}
}
fwd_txfm_ref(input_extreme_block, &output_ref_block, size_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block, &output_block));
// The minimum quant value is 4.
EXPECT_TRUE(output_block.CheckValues(output_ref_block));
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
EXPECT_GE(
4 * DCT_MAX_VALUE << (bit_depth_ - 8),
abs(output_block.TopLeftPixel()[h * output_block.stride() + w]))
<< "Error: " << size_ << "x" << size_
<< " transform has coefficient larger than 4*DCT_MAX_VALUE"
<< " at " << w << "," << h;
if (::testing::Test::HasFailure()) {
printf("Size: %d Transform type: %d\n", size_, tx_type_);
output_block.DumpBuffer();
return;
}
}
}
}
}
void RunInvAccuracyCheck(int limit) {
if (pixel_size_ == 1 && bit_depth_ > VPX_BITS_8) return;
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000;
Buffer<int16_t> in = Buffer<int16_t>(size_, size_, 4);
ASSERT_TRUE(in.Init());
Buffer<tran_low_t> coeff = Buffer<tran_low_t>(size_, size_, 0, 16);
ASSERT_TRUE(coeff.Init());
Buffer<uint8_t> dst = Buffer<uint8_t>(size_, size_, 0, 16);
ASSERT_TRUE(dst.Init());
Buffer<uint8_t> src = Buffer<uint8_t>(size_, size_, 0);
ASSERT_TRUE(src.Init());
Buffer<uint16_t> dst16 = Buffer<uint16_t>(size_, size_, 0, 16);
ASSERT_TRUE(dst16.Init());
Buffer<uint16_t> src16 = Buffer<uint16_t>(size_, size_, 0);
ASSERT_TRUE(src16.Init());
for (int i = 0; i < count_test_block; ++i) {
InitMem();
// Initialize a test block with input range [-max_pixel_value_,
// max_pixel_value_].
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
if (pixel_size_ == 1) {
in.TopLeftPixel()[h * in.stride() + w] =
src_[h * stride_ + w] - dst_[h * stride_ + w];
} else {
ASSERT_EQ(pixel_size_, 2);
const uint16_t *const src = reinterpret_cast<uint16_t *>(src_);
const uint16_t *const dst = reinterpret_cast<uint16_t *>(dst_);
in.TopLeftPixel()[h * in.stride() + w] =
src[h * stride_ + w] - dst[h * stride_ + w];
}
}
}
fwd_txfm_ref(in, &coeff, size_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst_));
for (int h = 0; h < size_; ++h) {
for (int w = 0; w < size_; ++w) {
int diff;
if (pixel_size_ == 1) {
diff = dst_[h * stride_ + w] - src_[h * stride_ + w];
} else {
ASSERT_EQ(pixel_size_, 2);
const uint16_t *const src = reinterpret_cast<uint16_t *>(src_);
const uint16_t *const dst = reinterpret_cast<uint16_t *>(dst_);
diff = dst[h * stride_ + w] - src[h * stride_ + w];
}
const uint32_t error = diff * diff;
EXPECT_GE(static_cast<uint32_t>(limit), error)
<< "Error: " << size_ << "x" << size_
<< " inverse transform has error " << error << " at " << w << ","
<< h;
if (::testing::Test::HasFailure()) {
printf("Size: %d Transform type: %d\n", size_, tx_type_);
return;
}
}
}
}
}
FhtFunc fwd_txfm_;
FhtFuncRef fwd_txfm_ref;
IhtWithBdFunc inv_txfm_;
ACMRandom rnd_;
uint8_t *src_;
uint8_t *dst_;
vpx_bit_depth_t bit_depth_;
int tx_type_;
int max_pixel_value_;
int size_;
int stride_;
int pixel_size_;
int block_size_;
};
/* -------------------------------------------------------------------------- */
class TransDCT : public TransTestBase {
public:
TransDCT() { fwd_txfm_ref = fdct_ref; }
};
TEST_P(TransDCT, AccuracyCheck) {
int t = 1;
if (size_ == 16 && bit_depth_ > 10 && pixel_size_ == 2) {
t = 2;
} else if (size_ == 32 && bit_depth_ > 10 && pixel_size_ == 2) {
t = 7;
}
RunAccuracyCheck(t);
}
TEST_P(TransDCT, CoeffCheck) { RunCoeffCheck(); }
TEST_P(TransDCT, MemCheck) { RunMemCheck(); }
TEST_P(TransDCT, InvAccuracyCheck) { RunInvAccuracyCheck(1); }
static const FuncInfo dct_c_func_info[] = {
#if CONFIG_VP9_HIGHBITDEPTH
{ &fdct_wrapper<vpx_highbd_fdct4x4_c>,
&highbd_idct_wrapper<vpx_highbd_idct4x4_16_add_c>, 4, 2 },
{ &fdct_wrapper<vpx_highbd_fdct8x8_c>,
&highbd_idct_wrapper<vpx_highbd_idct8x8_64_add_c>, 8, 2 },
{ &fdct_wrapper<vpx_highbd_fdct16x16_c>,
&highbd_idct_wrapper<vpx_highbd_idct16x16_256_add_c>, 16, 2 },
{ &fdct_wrapper<vpx_highbd_fdct32x32_c>,
&highbd_idct_wrapper<vpx_highbd_idct32x32_1024_add_c>, 32, 2 },
#endif
{ &fdct_wrapper<vpx_fdct4x4_c>, &idct_wrapper<vpx_idct4x4_16_add_c>, 4, 1 },
{ &fdct_wrapper<vpx_fdct8x8_c>, &idct_wrapper<vpx_idct8x8_64_add_c>, 8, 1 },
{ &fdct_wrapper<vpx_fdct16x16_c>, &idct_wrapper<vpx_idct16x16_256_add_c>, 16,
1 },
{ &fdct_wrapper<vpx_fdct32x32_c>, &idct_wrapper<vpx_idct32x32_1024_add_c>, 32,
1 }
};
INSTANTIATE_TEST_CASE_P(
C, TransDCT,
::testing::Combine(
::testing::Range(0, static_cast<int>(sizeof(dct_c_func_info) /
sizeof(dct_c_func_info[0]))),
::testing::Values(dct_c_func_info), ::testing::Values(0),
::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12)));
#if !CONFIG_EMULATE_HARDWARE
#if HAVE_SSE2
static const FuncInfo dct_sse2_func_info[] = {
#if CONFIG_VP9_HIGHBITDEPTH
{ &fdct_wrapper<vpx_highbd_fdct4x4_sse2>,
&highbd_idct_wrapper<vpx_highbd_idct4x4_16_add_sse2>, 4, 2 },
{ &fdct_wrapper<vpx_highbd_fdct8x8_sse2>,
&highbd_idct_wrapper<vpx_highbd_idct8x8_64_add_sse2>, 8, 2 },
{ &fdct_wrapper<vpx_highbd_fdct16x16_sse2>,
&highbd_idct_wrapper<vpx_highbd_idct16x16_256_add_sse2>, 16, 2 },
{ &fdct_wrapper<vpx_highbd_fdct32x32_sse2>,
&highbd_idct_wrapper<vpx_highbd_idct32x32_1024_add_sse2>, 32, 2 },
#endif
{ &fdct_wrapper<vpx_fdct4x4_sse2>, &idct_wrapper<vpx_idct4x4_16_add_sse2>, 4,
1 },
{ &fdct_wrapper<vpx_fdct8x8_sse2>, &idct_wrapper<vpx_idct8x8_64_add_sse2>, 8,
1 },
{ &fdct_wrapper<vpx_fdct16x16_sse2>,
&idct_wrapper<vpx_idct16x16_256_add_sse2>, 16, 1 },
{ &fdct_wrapper<vpx_fdct32x32_sse2>,
&idct_wrapper<vpx_idct32x32_1024_add_sse2>, 32, 1 }
};
INSTANTIATE_TEST_CASE_P(
SSE2, TransDCT,
::testing::Combine(
::testing::Range(0, static_cast<int>(sizeof(dct_sse2_func_info) /
sizeof(dct_sse2_func_info[0]))),
::testing::Values(dct_sse2_func_info), ::testing::Values(0),
::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12)));
#endif // HAVE_SSE2
#if HAVE_SSSE3 && !CONFIG_VP9_HIGHBITDEPTH && ARCH_X86_64
// vpx_fdct8x8_ssse3 is only available in 64 bit builds.
static const FuncInfo dct_ssse3_func_info = {
&fdct_wrapper<vpx_fdct8x8_ssse3>, &idct_wrapper<vpx_idct8x8_64_add_sse2>, 8, 1
};
// TODO(johannkoenig): high bit depth fdct8x8.
INSTANTIATE_TEST_CASE_P(SSSE3, TransDCT,
::testing::Values(make_tuple(0, &dct_ssse3_func_info, 0,
VPX_BITS_8)));
#endif // HAVE_SSSE3 && !CONFIG_VP9_HIGHBITDEPTH && ARCH_X86_64
#if HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH
static const FuncInfo dct_avx2_func_info = {
&fdct_wrapper<vpx_fdct32x32_avx2>, &idct_wrapper<vpx_idct32x32_1024_add_sse2>,
32, 1
};
// TODO(johannkoenig): high bit depth fdct32x32.
INSTANTIATE_TEST_CASE_P(AVX2, TransDCT,
::testing::Values(make_tuple(0, &dct_avx2_func_info, 0,
VPX_BITS_8)));
#endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH
#if HAVE_NEON
static const FuncInfo dct_neon_func_info[4] = {
{ &fdct_wrapper<vpx_fdct4x4_neon>, &idct_wrapper<vpx_idct4x4_16_add_neon>, 4,
1 },
{ &fdct_wrapper<vpx_fdct8x8_neon>, &idct_wrapper<vpx_idct8x8_64_add_neon>, 8,
1 },
{ &fdct_wrapper<vpx_fdct16x16_neon>,
&idct_wrapper<vpx_idct16x16_256_add_neon>, 16, 1 },
{ &fdct_wrapper<vpx_fdct32x32_neon>,
&idct_wrapper<vpx_idct32x32_1024_add_neon>, 32, 1 }
};
INSTANTIATE_TEST_CASE_P(
NEON, TransDCT,
::testing::Combine(::testing::Range(0, 4),
::testing::Values(dct_neon_func_info),
::testing::Values(0), ::testing::Values(VPX_BITS_8)));
#endif // HAVE_NEON
#if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH
static const FuncInfo dct_msa_func_info[4] = {
{ &fdct_wrapper<vpx_fdct4x4_msa>, &idct_wrapper<vpx_idct4x4_16_add_msa>, 4,
1 },
{ &fdct_wrapper<vpx_fdct8x8_msa>, &idct_wrapper<vpx_idct8x8_64_add_msa>, 8,
1 },
{ &fdct_wrapper<vpx_fdct16x16_msa>, &idct_wrapper<vpx_idct16x16_256_add_msa>,
16, 1 },
{ &fdct_wrapper<vpx_fdct32x32_msa>, &idct_wrapper<vpx_idct32x32_1024_add_msa>,
32, 1 }
};
INSTANTIATE_TEST_CASE_P(MSA, TransDCT,
::testing::Combine(::testing::Range(0, 4),
::testing::Values(dct_msa_func_info),
::testing::Values(0),
::testing::Values(VPX_BITS_8)));
#endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH
#if HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH
static const FuncInfo dct_vsx_func_info = {
&fdct_wrapper<vpx_fdct4x4_c>, &idct_wrapper<vpx_idct4x4_16_add_vsx>, 4, 1
};
INSTANTIATE_TEST_CASE_P(VSX, TransDCT,
::testing::Values(make_tuple(0, &dct_vsx_func_info, 0,
VPX_BITS_8)));
#endif // HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH &&
#endif // !CONFIG_EMULATE_HARDWARE
/* -------------------------------------------------------------------------- */
class TransHT : public TransTestBase {
public:
TransHT() { fwd_txfm_ref = fht_ref; }
};
TEST_P(TransHT, AccuracyCheck) {
RunAccuracyCheck(size_ == 16 && bit_depth_ > 10 && pixel_size_ == 2 ? 2 : 1);
}
TEST_P(TransHT, CoeffCheck) { RunCoeffCheck(); }
TEST_P(TransHT, MemCheck) { RunMemCheck(); }
TEST_P(TransHT, InvAccuracyCheck) { RunInvAccuracyCheck(1); }
static const FuncInfo ht_c_func_info[] = {
#if CONFIG_VP9_HIGHBITDEPTH
{ &vp9_highbd_fht4x4_c, &highbd_iht_wrapper<vp9_highbd_iht4x4_16_add_c>, 4,
2 },
{ &vp9_highbd_fht8x8_c, &highbd_iht_wrapper<vp9_highbd_iht8x8_64_add_c>, 8,
2 },
{ &vp9_highbd_fht16x16_c, &highbd_iht_wrapper<vp9_highbd_iht16x16_256_add_c>,
16, 2 },
#endif
{ &vp9_fht4x4_c, &iht_wrapper<vp9_iht4x4_16_add_c>, 4, 1 },
{ &vp9_fht8x8_c, &iht_wrapper<vp9_iht8x8_64_add_c>, 8, 1 },
{ &vp9_fht16x16_c, &iht_wrapper<vp9_iht16x16_256_add_c>, 16, 1 }
};
INSTANTIATE_TEST_CASE_P(
C, TransHT,
::testing::Combine(
::testing::Range(0, static_cast<int>(sizeof(ht_c_func_info) /
sizeof(ht_c_func_info[0]))),
::testing::Values(ht_c_func_info), ::testing::Range(0, 4),
::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12)));
#if !CONFIG_EMULATE_HARDWARE
#if HAVE_NEON
static const FuncInfo ht_neon_func_info[] = {
#if CONFIG_VP9_HIGHBITDEPTH
{ &vp9_highbd_fht4x4_c, &highbd_iht_wrapper<vp9_highbd_iht4x4_16_add_neon>, 4,
2 },
{ &vp9_highbd_fht8x8_c, &highbd_iht_wrapper<vp9_highbd_iht8x8_64_add_neon>, 8,
2 },
{ &vp9_highbd_fht16x16_c,
&highbd_iht_wrapper<vp9_highbd_iht16x16_256_add_neon>, 16, 2 },
#endif
{ &vp9_fht4x4_c, &iht_wrapper<vp9_iht4x4_16_add_neon>, 4, 1 },
{ &vp9_fht8x8_c, &iht_wrapper<vp9_iht8x8_64_add_neon>, 8, 1 },
{ &vp9_fht16x16_c, &iht_wrapper<vp9_iht16x16_256_add_neon>, 16, 1 }
};
INSTANTIATE_TEST_CASE_P(
NEON, TransHT,
::testing::Combine(
::testing::Range(0, static_cast<int>(sizeof(ht_neon_func_info) /
sizeof(ht_neon_func_info[0]))),
::testing::Values(ht_neon_func_info), ::testing::Range(0, 4),
::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12)));
#endif // HAVE_NEON
#if HAVE_SSE2
static const FuncInfo ht_sse2_func_info[3] = {
{ &vp9_fht4x4_sse2, &iht_wrapper<vp9_iht4x4_16_add_sse2>, 4, 1 },
{ &vp9_fht8x8_sse2, &iht_wrapper<vp9_iht8x8_64_add_sse2>, 8, 1 },
{ &vp9_fht16x16_sse2, &iht_wrapper<vp9_iht16x16_256_add_sse2>, 16, 1 }
};
INSTANTIATE_TEST_CASE_P(SSE2, TransHT,
::testing::Combine(::testing::Range(0, 3),
::testing::Values(ht_sse2_func_info),
::testing::Range(0, 4),
::testing::Values(VPX_BITS_8)));
#endif // HAVE_SSE2
#if HAVE_SSE4_1 && CONFIG_VP9_HIGHBITDEPTH
static const FuncInfo ht_sse4_1_func_info[3] = {
{ &vp9_highbd_fht4x4_c, &highbd_iht_wrapper<vp9_highbd_iht4x4_16_add_sse4_1>,
4, 2 },
{ vp9_highbd_fht8x8_c, &highbd_iht_wrapper<vp9_highbd_iht8x8_64_add_sse4_1>,
8, 2 },
{ &vp9_highbd_fht16x16_c,
&highbd_iht_wrapper<vp9_highbd_iht16x16_256_add_sse4_1>, 16, 2 }
};
INSTANTIATE_TEST_CASE_P(
SSE4_1, TransHT,
::testing::Combine(::testing::Range(0, 3),
::testing::Values(ht_sse4_1_func_info),
::testing::Range(0, 4),
::testing::Values(VPX_BITS_8, VPX_BITS_10,
VPX_BITS_12)));
#endif // HAVE_SSE4_1 && CONFIG_VP9_HIGHBITDEPTH
#endif // !CONFIG_EMULATE_HARDWARE
/* -------------------------------------------------------------------------- */
class TransWHT : public TransTestBase {
public:
TransWHT() { fwd_txfm_ref = fwht_ref; }
};
TEST_P(TransWHT, AccuracyCheck) { RunAccuracyCheck(0); }
TEST_P(TransWHT, CoeffCheck) { RunCoeffCheck(); }
TEST_P(TransWHT, MemCheck) { RunMemCheck(); }
TEST_P(TransWHT, InvAccuracyCheck) { RunInvAccuracyCheck(0); }
static const FuncInfo wht_c_func_info[] = {
#if CONFIG_VP9_HIGHBITDEPTH
{ &fdct_wrapper<vp9_highbd_fwht4x4_c>,
&highbd_idct_wrapper<vpx_highbd_iwht4x4_16_add_c>, 4, 2 },
#endif
{ &fdct_wrapper<vp9_fwht4x4_c>, &idct_wrapper<vpx_iwht4x4_16_add_c>, 4, 1 }
};
INSTANTIATE_TEST_CASE_P(
C, TransWHT,
::testing::Combine(
::testing::Range(0, static_cast<int>(sizeof(wht_c_func_info) /
sizeof(wht_c_func_info[0]))),
::testing::Values(wht_c_func_info), ::testing::Values(0),
::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12)));
#if HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE
static const FuncInfo wht_sse2_func_info = {
&fdct_wrapper<vp9_fwht4x4_sse2>, &idct_wrapper<vpx_iwht4x4_16_add_sse2>, 4, 1
};
INSTANTIATE_TEST_CASE_P(SSE2, TransWHT,
::testing::Values(make_tuple(0, &wht_sse2_func_info, 0,
VPX_BITS_8)));
#endif // HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE
} // namespace

View File

@ -7,11 +7,10 @@
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h"
#include "test/ivf_video_source.h" #include "test/ivf_video_source.h"
#include "./vpx_config.h"
#include "vpx/vp8dx.h" #include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h" #include "vpx/vpx_decoder.h"
@ -28,7 +27,7 @@ TEST(DecodeAPI, InvalidParams) {
&vpx_codec_vp9_dx_algo, &vpx_codec_vp9_dx_algo,
#endif #endif
}; };
uint8_t buf[1] = { 0 }; uint8_t buf[1] = {0};
vpx_codec_ctx_t dec; vpx_codec_ctx_t dec;
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_dec_init(NULL, NULL, NULL, 0)); EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_dec_init(NULL, NULL, NULL, 0));
@ -51,34 +50,22 @@ TEST(DecodeAPI, InvalidParams) {
vpx_codec_decode(&dec, buf, NELEMENTS(buf), NULL, 0)); vpx_codec_decode(&dec, buf, NELEMENTS(buf), NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_decode(&dec, NULL, NELEMENTS(buf), NULL, 0)); vpx_codec_decode(&dec, NULL, NELEMENTS(buf), NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_decode(&dec, buf, 0, NULL, 0)); EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_decode(&dec, buf, 0, NULL, 0));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec)); EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec));
} }
} }
#if CONFIG_VP8_DECODER
TEST(DecodeAPI, OptionalParams) {
vpx_codec_ctx_t dec;
#if CONFIG_ERROR_CONCEALMENT
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, NULL,
VPX_CODEC_USE_ERROR_CONCEALMENT));
#else
EXPECT_EQ(VPX_CODEC_INCAPABLE,
vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, NULL,
VPX_CODEC_USE_ERROR_CONCEALMENT));
#endif // CONFIG_ERROR_CONCEALMENT
}
#endif // CONFIG_VP8_DECODER
#if CONFIG_VP9_DECODER #if CONFIG_VP9_DECODER
// Test VP9 codec controls after a decode error to ensure the code doesn't // Test VP9 codec controls after a decode error to ensure the code doesn't
// misbehave. // misbehave.
void TestVp9Controls(vpx_codec_ctx_t *dec) { void TestVp9Controls(vpx_codec_ctx_t *dec) {
static const int kControls[] = { VP8D_GET_LAST_REF_UPDATES, static const int kControls[] = {
VP8D_GET_FRAME_CORRUPTED, VP8D_GET_LAST_REF_UPDATES,
VP9D_GET_DISPLAY_SIZE, VP9D_GET_FRAME_SIZE }; VP8D_GET_FRAME_CORRUPTED,
VP9D_GET_DISPLAY_SIZE,
};
int val[2]; int val[2];
for (int i = 0; i < NELEMENTS(kControls); ++i) { for (int i = 0; i < NELEMENTS(kControls); ++i) {
@ -87,7 +74,9 @@ void TestVp9Controls(vpx_codec_ctx_t *dec) {
case VP8D_GET_FRAME_CORRUPTED: case VP8D_GET_FRAME_CORRUPTED:
EXPECT_EQ(VPX_CODEC_ERROR, res) << kControls[i]; EXPECT_EQ(VPX_CODEC_ERROR, res) << kControls[i];
break; break;
default: EXPECT_EQ(VPX_CODEC_OK, res) << kControls[i]; break; default:
EXPECT_EQ(VPX_CODEC_OK, res) << kControls[i];
break;
} }
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_control_(dec, kControls[i], NULL)); vpx_codec_control_(dec, kControls[i], NULL));
@ -124,69 +113,14 @@ TEST(DecodeAPI, Vp9InvalidDecode) {
vpx_codec_ctx_t dec; vpx_codec_ctx_t dec;
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_dec_init(&dec, codec, NULL, 0)); EXPECT_EQ(VPX_CODEC_OK, vpx_codec_dec_init(&dec, codec, NULL, 0));
const uint32_t frame_size = static_cast<uint32_t>(video.frame_size()); const uint32_t frame_size = static_cast<uint32_t>(video.frame_size());
#if CONFIG_VP9_HIGHBITDEPTH
EXPECT_EQ(VPX_CODEC_MEM_ERROR, EXPECT_EQ(VPX_CODEC_MEM_ERROR,
vpx_codec_decode(&dec, video.cxdata(), frame_size, NULL, 0)); vpx_codec_decode(&dec, video.cxdata(), frame_size, NULL, 0));
#else
EXPECT_EQ(VPX_CODEC_UNSUP_BITSTREAM,
vpx_codec_decode(&dec, video.cxdata(), frame_size, NULL, 0));
#endif
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
EXPECT_EQ(NULL, vpx_codec_get_frame(&dec, &iter)); EXPECT_EQ(NULL, vpx_codec_get_frame(&dec, &iter));
TestVp9Controls(&dec); TestVp9Controls(&dec);
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec)); EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec));
} }
TEST(DecodeAPI, Vp9PeekSI) {
const vpx_codec_iface_t *const codec = &vpx_codec_vp9_dx_algo;
// The first 9 bytes are valid and the rest of the bytes are made up. Until
// size 10, this should return VPX_CODEC_UNSUP_BITSTREAM and after that it
// should return VPX_CODEC_CORRUPT_FRAME.
const uint8_t data[32] = {
0x85, 0xa4, 0xc1, 0xa1, 0x38, 0x81, 0xa3, 0x49, 0x83, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
for (uint32_t data_sz = 1; data_sz <= 32; ++data_sz) {
// Verify behavior of vpx_codec_decode. vpx_codec_decode doesn't even get
// to decoder_peek_si_internal on frames of size < 8.
if (data_sz >= 8) {
vpx_codec_ctx_t dec;
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_dec_init(&dec, codec, NULL, 0));
EXPECT_EQ(
(data_sz < 10) ? VPX_CODEC_UNSUP_BITSTREAM : VPX_CODEC_CORRUPT_FRAME,
vpx_codec_decode(&dec, data, data_sz, NULL, 0));
vpx_codec_iter_t iter = NULL;
EXPECT_EQ(NULL, vpx_codec_get_frame(&dec, &iter));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec));
}
// Verify behavior of vpx_codec_peek_stream_info.
vpx_codec_stream_info_t si;
si.sz = sizeof(si);
EXPECT_EQ((data_sz < 10) ? VPX_CODEC_UNSUP_BITSTREAM : VPX_CODEC_OK,
vpx_codec_peek_stream_info(codec, data, data_sz, &si));
}
}
#endif // CONFIG_VP9_DECODER #endif // CONFIG_VP9_DECODER
TEST(DecodeAPI, HighBitDepthCapability) {
// VP8 should not claim VP9 HBD as a capability.
#if CONFIG_VP8_DECODER
const vpx_codec_caps_t vp8_caps = vpx_codec_get_caps(&vpx_codec_vp8_dx_algo);
EXPECT_EQ(vp8_caps & VPX_CODEC_CAP_HIGHBITDEPTH, 0);
#endif
#if CONFIG_VP9_DECODER
const vpx_codec_caps_t vp9_caps = vpx_codec_get_caps(&vpx_codec_vp9_dx_algo);
#if CONFIG_VP9_HIGHBITDEPTH
EXPECT_EQ(vp9_caps & VPX_CODEC_CAP_HIGHBITDEPTH, VPX_CODEC_CAP_HIGHBITDEPTH);
#else
EXPECT_EQ(vp9_caps & VPX_CODEC_CAP_HIGHBITDEPTH, 0);
#endif
#endif
}
} // namespace } // namespace

View File

@ -8,20 +8,16 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <string>
#include "test/codec_factory.h" #include "test/codec_factory.h"
#include "test/decode_test_driver.h" #include "test/decode_test_driver.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/ivf_video_source.h" #include "test/ivf_video_source.h"
#include "test/md5_helper.h" #include "test/md5_helper.h"
#include "test/util.h" #include "test/util.h"
#include "test/webm_video_source.h" #include "test/webm_video_source.h"
#include "vpx_ports/vpx_timer.h" #include "vpx_ports/vpx_timer.h"
#include "./ivfenc.h"
#include "./vpx_version.h" #include "./vpx_version.h"
using ::testing::make_tuple; using std::tr1::make_tuple;
namespace { namespace {
@ -29,12 +25,11 @@ namespace {
#define THREADS 1 #define THREADS 1
const double kUsecsInSec = 1000000.0; const double kUsecsInSec = 1000000.0;
const char kNewEncodeOutputFile[] = "new_encode.ivf";
/* /*
DecodePerfTest takes a tuple of filename + number of threads to decode with DecodePerfTest takes a tuple of filename + number of threads to decode with
*/ */
typedef ::testing::tuple<const char *, unsigned> DecodePerfParam; typedef std::tr1::tuple<const char *, unsigned> DecodePerfParam;
const DecodePerfParam kVP9DecodePerfVectors[] = { const DecodePerfParam kVP9DecodePerfVectors[] = {
make_tuple("vp90-2-bbb_426x240_tile_1x1_180kbps.webm", 1), make_tuple("vp90-2-bbb_426x240_tile_1x1_180kbps.webm", 1),
@ -69,7 +64,8 @@ const DecodePerfParam kVP9DecodePerfVectors[] = {
power/temp/min max frame decode times/etc power/temp/min max frame decode times/etc
*/ */
class DecodePerfTest : public ::testing::TestWithParam<DecodePerfParam> {}; class DecodePerfTest : public ::testing::TestWithParam<DecodePerfParam> {
};
TEST_P(DecodePerfTest, PerfTest) { TEST_P(DecodePerfTest, PerfTest) {
const char *const video_name = GET_PARAM(VIDEO_NAME); const char *const video_name = GET_PARAM(VIDEO_NAME);
@ -90,7 +86,8 @@ TEST_P(DecodePerfTest, PerfTest) {
} }
vpx_usec_timer_mark(&t); vpx_usec_timer_mark(&t);
const double elapsed_secs = double(vpx_usec_timer_elapsed(&t)) / kUsecsInSec; const double elapsed_secs = double(vpx_usec_timer_elapsed(&t))
/ kUsecsInSec;
const unsigned frames = video.frame_number(); const unsigned frames = video.frame_number();
const double fps = double(frames) / elapsed_secs; const double fps = double(frames) / elapsed_secs;
@ -108,154 +105,4 @@ TEST_P(DecodePerfTest, PerfTest) {
INSTANTIATE_TEST_CASE_P(VP9, DecodePerfTest, INSTANTIATE_TEST_CASE_P(VP9, DecodePerfTest,
::testing::ValuesIn(kVP9DecodePerfVectors)); ::testing::ValuesIn(kVP9DecodePerfVectors));
class VP9NewEncodeDecodePerfTest
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
protected:
VP9NewEncodeDecodePerfTest()
: EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), speed_(0),
outfile_(0), out_frames_(0) {}
virtual ~VP9NewEncodeDecodePerfTest() {}
virtual void SetUp() {
InitializeConfig();
SetMode(encoding_mode_);
cfg_.g_lag_in_frames = 25;
cfg_.rc_min_quantizer = 2;
cfg_.rc_max_quantizer = 56;
cfg_.rc_dropframe_thresh = 0;
cfg_.rc_undershoot_pct = 50;
cfg_.rc_overshoot_pct = 50;
cfg_.rc_buf_sz = 1000;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 600;
cfg_.rc_resize_allowed = 0;
cfg_.rc_end_usage = VPX_VBR;
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
if (video->frame() == 1) {
encoder->Control(VP8E_SET_CPUUSED, speed_);
encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
encoder->Control(VP9E_SET_TILE_COLUMNS, 2);
}
}
virtual void BeginPassHook(unsigned int /*pass*/) {
const std::string data_path = getenv("LIBVPX_TEST_DATA_PATH");
const std::string path_to_source = data_path + "/" + kNewEncodeOutputFile;
outfile_ = fopen(path_to_source.c_str(), "wb");
ASSERT_TRUE(outfile_ != NULL);
}
virtual void EndPassHook() {
if (outfile_ != NULL) {
if (!fseek(outfile_, 0, SEEK_SET)) {
ivf_write_file_header(outfile_, &cfg_, VP9_FOURCC, out_frames_);
}
fclose(outfile_);
outfile_ = NULL;
}
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
++out_frames_;
// Write initial file header if first frame.
if (pkt->data.frame.pts == 0) {
ivf_write_file_header(outfile_, &cfg_, VP9_FOURCC, out_frames_);
}
// Write frame header and data.
ivf_write_frame_header(outfile_, out_frames_, pkt->data.frame.sz);
ASSERT_EQ(fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_),
pkt->data.frame.sz);
}
virtual bool DoDecode() const { return false; }
void set_speed(unsigned int speed) { speed_ = speed; }
private:
libvpx_test::TestMode encoding_mode_;
uint32_t speed_;
FILE *outfile_;
uint32_t out_frames_;
};
struct EncodePerfTestVideo {
EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
uint32_t bitrate_, int frames_)
: name(name_), width(width_), height(height_), bitrate(bitrate_),
frames(frames_) {}
const char *name;
uint32_t width;
uint32_t height;
uint32_t bitrate;
int frames;
};
const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
};
TEST_P(VP9NewEncodeDecodePerfTest, PerfTest) {
SetUp();
// TODO(JBB): Make this work by going through the set of given files.
const int i = 0;
const vpx_rational timebase = { 33333333, 1000000000 };
cfg_.g_timebase = timebase;
cfg_.rc_target_bitrate = kVP9EncodePerfTestVectors[i].bitrate;
init_flags_ = VPX_CODEC_USE_PSNR;
const char *video_name = kVP9EncodePerfTestVectors[i].name;
libvpx_test::I420VideoSource video(
video_name, kVP9EncodePerfTestVectors[i].width,
kVP9EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0,
kVP9EncodePerfTestVectors[i].frames);
set_speed(2);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
const uint32_t threads = 4;
libvpx_test::IVFVideoSource decode_video(kNewEncodeOutputFile);
decode_video.Init();
vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
cfg.threads = threads;
libvpx_test::VP9Decoder decoder(cfg, 0);
vpx_usec_timer t;
vpx_usec_timer_start(&t);
for (decode_video.Begin(); decode_video.cxdata() != NULL;
decode_video.Next()) {
decoder.DecodeFrame(decode_video.cxdata(), decode_video.frame_size());
}
vpx_usec_timer_mark(&t);
const double elapsed_secs =
static_cast<double>(vpx_usec_timer_elapsed(&t)) / kUsecsInSec;
const unsigned decode_frames = decode_video.frame_number();
const double fps = static_cast<double>(decode_frames) / elapsed_secs;
printf("{\n");
printf("\t\"type\" : \"decode_perf_test\",\n");
printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
printf("\t\"videoName\" : \"%s\",\n", kNewEncodeOutputFile);
printf("\t\"threadCount\" : %u,\n", threads);
printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs);
printf("\t\"totalFrames\" : %u,\n", decode_frames);
printf("\t\"framesPerSecond\" : %f\n", fps);
printf("}\n");
}
VP9_INSTANTIATE_TEST_CASE(VP9NewEncodeDecodePerfTest,
::testing::Values(::libvpx_test::kTwoPassGood));
} // namespace } // namespace

View File

@ -1,124 +0,0 @@
/*
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <string>
#include "test/codec_factory.h"
#include "test/decode_test_driver.h"
#include "test/ivf_video_source.h"
#include "test/test_vectors.h"
#include "test/util.h"
namespace {
const unsigned int kNumFrames = 19;
class DecodeSvcTest : public ::libvpx_test::DecoderTest,
public ::libvpx_test::CodecTestWithParam<const char *> {
protected:
DecodeSvcTest() : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)) {}
virtual ~DecodeSvcTest() {}
virtual void PreDecodeFrameHook(
const libvpx_test::CompressedVideoSource &video,
libvpx_test::Decoder *decoder) {
if (video.frame_number() == 0)
decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, spatial_layer_);
}
virtual void DecompressedFrameHook(const vpx_image_t &img,
const unsigned int frame_number) {
ASSERT_EQ(img.d_w, width_);
ASSERT_EQ(img.d_h, height_);
total_frames_ = frame_number;
}
int spatial_layer_;
unsigned int width_;
unsigned int height_;
unsigned int total_frames_;
};
// SVC test vector is 1280x720, with 3 spatial layers, and 20 frames.
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
// spatial layer 0. Verify the resolution of each decoded frame and the total
// number of frames decoded. This results in 1/4x1/4 resolution (320x180).
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer0) {
const std::string filename = GET_PARAM(1);
testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
video.reset(new libvpx_test::IVFVideoSource(filename));
ASSERT_TRUE(video.get() != NULL);
video->Init();
total_frames_ = 0;
spatial_layer_ = 0;
width_ = 320;
height_ = 180;
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
ASSERT_EQ(total_frames_, kNumFrames);
}
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
// spatial layer 1. Verify the resolution of each decoded frame and the total
// number of frames decoded. This results in 1/2x1/2 resolution (640x360).
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer1) {
const std::string filename = GET_PARAM(1);
testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
video.reset(new libvpx_test::IVFVideoSource(filename));
ASSERT_TRUE(video.get() != NULL);
video->Init();
total_frames_ = 0;
spatial_layer_ = 1;
width_ = 640;
height_ = 360;
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
ASSERT_EQ(total_frames_, kNumFrames);
}
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
// spatial layer 2. Verify the resolution of each decoded frame and the total
// number of frames decoded. This results in the full resolution (1280x720).
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer2) {
const std::string filename = GET_PARAM(1);
testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
video.reset(new libvpx_test::IVFVideoSource(filename));
ASSERT_TRUE(video.get() != NULL);
video->Init();
total_frames_ = 0;
spatial_layer_ = 2;
width_ = 1280;
height_ = 720;
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
ASSERT_EQ(total_frames_, kNumFrames);
}
// Decode the SVC test vector, which has 3 spatial layers, and decode up to
// spatial layer 10. Verify the resolution of each decoded frame and the total
// number of frames decoded. This is beyond the number of spatial layers, so
// the decoding should result in the full resolution (1280x720).
TEST_P(DecodeSvcTest, DecodeSvcTestUpToSpatialLayer10) {
const std::string filename = GET_PARAM(1);
testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
video.reset(new libvpx_test::IVFVideoSource(filename));
ASSERT_TRUE(video.get() != NULL);
video->Init();
total_frames_ = 0;
spatial_layer_ = 10;
width_ = 1280;
height_ = 720;
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
ASSERT_EQ(total_frames_, kNumFrames);
}
VP9_INSTANTIATE_TEST_CASE(
DecodeSvcTest, ::testing::ValuesIn(libvpx_test::kVP9TestVectorsSvc,
libvpx_test::kVP9TestVectorsSvc +
libvpx_test::kNumVP9TestVectorsSvc));
} // namespace

View File

@ -7,11 +7,9 @@
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/codec_factory.h" #include "test/codec_factory.h"
#include "test/decode_test_driver.h" #include "test/decode_test_driver.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
#include "test/video_source.h" #include "test/video_source.h"
@ -21,8 +19,9 @@ const char kVP8Name[] = "WebM Project VP8";
vpx_codec_err_t Decoder::PeekStream(const uint8_t *cxdata, size_t size, vpx_codec_err_t Decoder::PeekStream(const uint8_t *cxdata, size_t size,
vpx_codec_stream_info_t *stream_info) { vpx_codec_stream_info_t *stream_info) {
return vpx_codec_peek_stream_info( return vpx_codec_peek_stream_info(CodecInterface(),
CodecInterface(), cxdata, static_cast<unsigned int>(size), stream_info); cxdata, static_cast<unsigned int>(size),
stream_info);
} }
vpx_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) { vpx_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) {
@ -34,8 +33,9 @@ vpx_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size,
vpx_codec_err_t res_dec; vpx_codec_err_t res_dec;
InitOnce(); InitOnce();
API_REGISTER_STATE_CHECK( API_REGISTER_STATE_CHECK(
res_dec = vpx_codec_decode( res_dec = vpx_codec_decode(&decoder_,
&decoder_, cxdata, static_cast<unsigned int>(size), user_priv, 0)); cxdata, static_cast<unsigned int>(size),
user_priv, 0));
return res_dec; return res_dec;
} }
@ -52,21 +52,20 @@ void DecoderTest::HandlePeekResult(Decoder *const decoder,
/* Vp8's implementation of PeekStream returns an error if the frame you /* Vp8's implementation of PeekStream returns an error if the frame you
* pass it is not a keyframe, so we only expect VPX_CODEC_OK on the first * pass it is not a keyframe, so we only expect VPX_CODEC_OK on the first
* frame, which must be a keyframe. */ * frame, which must be a keyframe. */
if (video->frame_number() == 0) { if (video->frame_number() == 0)
ASSERT_EQ(VPX_CODEC_OK, res_peek) ASSERT_EQ(VPX_CODEC_OK, res_peek) << "Peek return failed: "
<< "Peek return failed: " << vpx_codec_err_to_string(res_peek); << vpx_codec_err_to_string(res_peek);
}
} else { } else {
/* The Vp9 implementation of PeekStream returns an error only if the /* The Vp9 implementation of PeekStream returns an error only if the
* data passed to it isn't a valid Vp9 chunk. */ * data passed to it isn't a valid Vp9 chunk. */
ASSERT_EQ(VPX_CODEC_OK, res_peek) ASSERT_EQ(VPX_CODEC_OK, res_peek) << "Peek return failed: "
<< "Peek return failed: " << vpx_codec_err_to_string(res_peek); << vpx_codec_err_to_string(res_peek);
} }
} }
void DecoderTest::RunLoop(CompressedVideoSource *video, void DecoderTest::RunLoop(CompressedVideoSource *video,
const vpx_codec_dec_cfg_t &dec_cfg) { const vpx_codec_dec_cfg_t &dec_cfg) {
Decoder *const decoder = codec_->CreateDecoder(dec_cfg, flags_); Decoder* const decoder = codec_->CreateDecoder(dec_cfg, 0);
ASSERT_TRUE(decoder != NULL); ASSERT_TRUE(decoder != NULL);
bool end_of_file = false; bool end_of_file = false;
@ -79,14 +78,16 @@ void DecoderTest::RunLoop(CompressedVideoSource *video,
stream_info.sz = sizeof(stream_info); stream_info.sz = sizeof(stream_info);
if (video->cxdata() != NULL) { if (video->cxdata() != NULL) {
const vpx_codec_err_t res_peek = decoder->PeekStream( const vpx_codec_err_t res_peek = decoder->PeekStream(video->cxdata(),
video->cxdata(), video->frame_size(), &stream_info); video->frame_size(),
&stream_info);
HandlePeekResult(decoder, video, res_peek); HandlePeekResult(decoder, video, res_peek);
ASSERT_FALSE(::testing::Test::HasFailure()); ASSERT_FALSE(::testing::Test::HasFailure());
vpx_codec_err_t res_dec = vpx_codec_err_t res_dec = decoder->DecodeFrame(video->cxdata(),
decoder->DecodeFrame(video->cxdata(), video->frame_size()); video->frame_size());
if (!HandleDecodeResult(res_dec, *video, decoder)) break; if (!HandleDecodeResult(res_dec, *video, decoder))
break;
} else { } else {
// Signal end of the file to the decoder. // Signal end of the file to the decoder.
const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0); const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0);
@ -98,9 +99,8 @@ void DecoderTest::RunLoop(CompressedVideoSource *video,
const vpx_image_t *img = NULL; const vpx_image_t *img = NULL;
// Get decompressed data // Get decompressed data
while ((img = dec_iter.Next())) { while ((img = dec_iter.Next()))
DecompressedFrameHook(*img, video->frame_number()); DecompressedFrameHook(*img, video->frame_number());
}
} }
delete decoder; delete decoder;
} }
@ -110,10 +110,4 @@ void DecoderTest::RunLoop(CompressedVideoSource *video) {
RunLoop(video, dec_cfg); RunLoop(video, dec_cfg);
} }
void DecoderTest::set_cfg(const vpx_codec_dec_cfg_t &dec_cfg) {
memcpy(&cfg_, &dec_cfg, sizeof(cfg_));
}
void DecoderTest::set_flags(const vpx_codec_flags_t flags) { flags_ = flags; }
} // namespace libvpx_test } // namespace libvpx_test

View File

@ -26,11 +26,13 @@ class DxDataIterator {
explicit DxDataIterator(vpx_codec_ctx_t *decoder) explicit DxDataIterator(vpx_codec_ctx_t *decoder)
: decoder_(decoder), iter_(NULL) {} : decoder_(decoder), iter_(NULL) {}
const vpx_image_t *Next() { return vpx_codec_get_frame(decoder_, &iter_); } const vpx_image_t *Next() {
return vpx_codec_get_frame(decoder_, &iter_);
}
private: private:
vpx_codec_ctx_t *decoder_; vpx_codec_ctx_t *decoder_;
vpx_codec_iter_t iter_; vpx_codec_iter_t iter_;
}; };
// Provides a simplified interface to manage one video decoding. // Provides a simplified interface to manage one video decoding.
@ -38,18 +40,15 @@ class DxDataIterator {
// as more tests are added. // as more tests are added.
class Decoder { class Decoder {
public: public:
explicit Decoder(vpx_codec_dec_cfg_t cfg) Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
: cfg_(cfg), flags_(0), init_done_(false) { : cfg_(cfg), deadline_(deadline), init_done_(false) {
memset(&decoder_, 0, sizeof(decoder_)); memset(&decoder_, 0, sizeof(decoder_));
} }
Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag) virtual ~Decoder() {
: cfg_(cfg), flags_(flag), init_done_(false) { vpx_codec_destroy(&decoder_);
memset(&decoder_, 0, sizeof(decoder_));
} }
virtual ~Decoder() { vpx_codec_destroy(&decoder_); }
vpx_codec_err_t PeekStream(const uint8_t *cxdata, size_t size, vpx_codec_err_t PeekStream(const uint8_t *cxdata, size_t size,
vpx_codec_stream_info_t *stream_info); vpx_codec_stream_info_t *stream_info);
@ -58,9 +57,19 @@ class Decoder {
vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size, vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size,
void *user_priv); void *user_priv);
DxDataIterator GetDxData() { return DxDataIterator(&decoder_); } DxDataIterator GetDxData() {
return DxDataIterator(&decoder_);
}
void Control(int ctrl_id, int arg) { Control(ctrl_id, arg, VPX_CODEC_OK); } void set_deadline(unsigned long deadline) {
deadline_ = deadline;
}
void Control(int ctrl_id, int arg) {
InitOnce();
const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
}
void Control(int ctrl_id, const void *arg) { void Control(int ctrl_id, const void *arg) {
InitOnce(); InitOnce();
@ -68,13 +77,7 @@ class Decoder {
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError(); ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
} }
void Control(int ctrl_id, int arg, vpx_codec_err_t expected_value) { const char* DecodeError() {
InitOnce();
const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
ASSERT_EQ(expected_value, res) << DecodeError();
}
const char *DecodeError() {
const char *detail = vpx_codec_error_detail(&decoder_); const char *detail = vpx_codec_error_detail(&decoder_);
return detail ? detail : vpx_codec_error(&decoder_); return detail ? detail : vpx_codec_error(&decoder_);
} }
@ -84,34 +87,33 @@ class Decoder {
vpx_get_frame_buffer_cb_fn_t cb_get, vpx_get_frame_buffer_cb_fn_t cb_get,
vpx_release_frame_buffer_cb_fn_t cb_release, void *user_priv) { vpx_release_frame_buffer_cb_fn_t cb_release, void *user_priv) {
InitOnce(); InitOnce();
return vpx_codec_set_frame_buffer_functions(&decoder_, cb_get, cb_release, return vpx_codec_set_frame_buffer_functions(
user_priv); &decoder_, cb_get, cb_release, user_priv);
} }
const char *GetDecoderName() const { const char* GetDecoderName() const {
return vpx_codec_iface_name(CodecInterface()); return vpx_codec_iface_name(CodecInterface());
} }
bool IsVP8() const; bool IsVP8() const;
vpx_codec_ctx_t *GetDecoder() { return &decoder_; }
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const = 0; virtual vpx_codec_iface_t* CodecInterface() const = 0;
void InitOnce() { void InitOnce() {
if (!init_done_) { if (!init_done_) {
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_dec_init(&decoder_,
vpx_codec_dec_init(&decoder_, CodecInterface(), &cfg_, flags_); CodecInterface(),
&cfg_, 0);
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError(); ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
init_done_ = true; init_done_ = true;
} }
} }
vpx_codec_ctx_t decoder_; vpx_codec_ctx_t decoder_;
vpx_codec_dec_cfg_t cfg_; vpx_codec_dec_cfg_t cfg_;
vpx_codec_flags_t flags_; unsigned int deadline_;
bool init_done_; bool init_done_;
}; };
// Common test functionality for all Decoder tests. // Common test functionality for all Decoder tests.
@ -122,39 +124,33 @@ class DecoderTest {
virtual void RunLoop(CompressedVideoSource *video, virtual void RunLoop(CompressedVideoSource *video,
const vpx_codec_dec_cfg_t &dec_cfg); const vpx_codec_dec_cfg_t &dec_cfg);
virtual void set_cfg(const vpx_codec_dec_cfg_t &dec_cfg);
virtual void set_flags(const vpx_codec_flags_t flags);
// Hook to be called before decompressing every frame. // Hook to be called before decompressing every frame.
virtual void PreDecodeFrameHook(const CompressedVideoSource & /*video*/, virtual void PreDecodeFrameHook(const CompressedVideoSource& /*video*/,
Decoder * /*decoder*/) {} Decoder* /*decoder*/) {}
// Hook to be called to handle decode result. Return true to continue. // Hook to be called to handle decode result. Return true to continue.
virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
const CompressedVideoSource & /*video*/, const CompressedVideoSource& /*video*/,
Decoder *decoder) { Decoder *decoder) {
EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError(); EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
return VPX_CODEC_OK == res_dec; return VPX_CODEC_OK == res_dec;
} }
// Hook to be called on every decompressed frame. // Hook to be called on every decompressed frame.
virtual void DecompressedFrameHook(const vpx_image_t & /*img*/, virtual void DecompressedFrameHook(const vpx_image_t& /*img*/,
const unsigned int /*frame_number*/) {} const unsigned int /*frame_number*/) {}
// Hook to be called on peek result // Hook to be called on peek result
virtual void HandlePeekResult(Decoder *const decoder, virtual void HandlePeekResult(Decoder* const decoder,
CompressedVideoSource *video, CompressedVideoSource *video,
const vpx_codec_err_t res_peek); const vpx_codec_err_t res_peek);
protected: protected:
explicit DecoderTest(const CodecFactory *codec) explicit DecoderTest(const CodecFactory *codec) : codec_(codec) {}
: codec_(codec), cfg_(), flags_(0) {}
virtual ~DecoderTest() {} virtual ~DecoderTest() {}
const CodecFactory *codec_; const CodecFactory *codec_;
vpx_codec_dec_cfg_t cfg_;
vpx_codec_flags_t flags_;
}; };
} // namespace libvpx_test } // namespace libvpx_test

View File

@ -1,195 +0,0 @@
/*
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
namespace {
#define NELEMENTS(x) static_cast<int>(sizeof(x) / sizeof(x[0]))
TEST(EncodeAPI, InvalidParams) {
static const vpx_codec_iface_t *kCodecs[] = {
#if CONFIG_VP8_ENCODER
&vpx_codec_vp8_cx_algo,
#endif
#if CONFIG_VP9_ENCODER
&vpx_codec_vp9_cx_algo,
#endif
};
uint8_t buf[1] = { 0 };
vpx_image_t img;
vpx_codec_ctx_t enc;
vpx_codec_enc_cfg_t cfg;
EXPECT_EQ(&img, vpx_img_wrap(&img, VPX_IMG_FMT_I420, 1, 1, 1, buf));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_enc_init(NULL, NULL, NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_enc_init(&enc, NULL, NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_encode(NULL, NULL, 0, 0, 0, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_encode(NULL, &img, 0, 0, 0, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_destroy(NULL));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_config_default(NULL, NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_config_default(NULL, &cfg, 0));
EXPECT_TRUE(vpx_codec_error(NULL) != NULL);
for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
SCOPED_TRACE(vpx_codec_iface_name(kCodecs[i]));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_init(NULL, kCodecs[i], NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_init(&enc, kCodecs[i], NULL, 0));
EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_config_default(kCodecs[i], &cfg, 1));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_enc_config_default(kCodecs[i], &cfg, 0));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_enc_init(&enc, kCodecs[i], &cfg, 0));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_encode(&enc, NULL, 0, 0, 0, 0));
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&enc));
}
}
TEST(EncodeAPI, HighBitDepthCapability) {
// VP8 should not claim VP9 HBD as a capability.
#if CONFIG_VP8_ENCODER
const vpx_codec_caps_t vp8_caps = vpx_codec_get_caps(&vpx_codec_vp8_cx_algo);
EXPECT_EQ(vp8_caps & VPX_CODEC_CAP_HIGHBITDEPTH, 0);
#endif
#if CONFIG_VP9_ENCODER
const vpx_codec_caps_t vp9_caps = vpx_codec_get_caps(&vpx_codec_vp9_cx_algo);
#if CONFIG_VP9_HIGHBITDEPTH
EXPECT_EQ(vp9_caps & VPX_CODEC_CAP_HIGHBITDEPTH, VPX_CODEC_CAP_HIGHBITDEPTH);
#else
EXPECT_EQ(vp9_caps & VPX_CODEC_CAP_HIGHBITDEPTH, 0);
#endif
#endif
}
#if CONFIG_VP8_ENCODER
TEST(EncodeAPI, ImageSizeSetting) {
const int width = 711;
const int height = 360;
const int bps = 12;
vpx_image_t img;
vpx_codec_ctx_t enc;
vpx_codec_enc_cfg_t cfg;
uint8_t *img_buf = reinterpret_cast<uint8_t *>(
calloc(width * height * bps / 8, sizeof(*img_buf)));
vpx_codec_enc_config_default(vpx_codec_vp8_cx(), &cfg, 0);
cfg.g_w = width;
cfg.g_h = height;
vpx_img_wrap(&img, VPX_IMG_FMT_I420, width, height, 1, img_buf);
vpx_codec_enc_init(&enc, vpx_codec_vp8_cx(), &cfg, 0);
EXPECT_EQ(VPX_CODEC_OK, vpx_codec_encode(&enc, &img, 0, 1, 0, 0));
free(img_buf);
vpx_codec_destroy(&enc);
}
#endif
// Set up 2 spatial streams with 2 temporal layers per stream, and generate
// invalid configuration by setting the temporal layer rate allocation
// (ts_target_bitrate[]) to 0 for both layers. This should fail independent of
// CONFIG_MULTI_RES_ENCODING.
TEST(EncodeAPI, MultiResEncode) {
static const vpx_codec_iface_t *kCodecs[] = {
#if CONFIG_VP8_ENCODER
&vpx_codec_vp8_cx_algo,
#endif
#if CONFIG_VP9_ENCODER
&vpx_codec_vp9_cx_algo,
#endif
};
const int width = 1280;
const int height = 720;
const int width_down = width / 2;
const int height_down = height / 2;
const int target_bitrate = 1000;
const int framerate = 30;
for (int c = 0; c < NELEMENTS(kCodecs); ++c) {
const vpx_codec_iface_t *const iface = kCodecs[c];
vpx_codec_ctx_t enc[2];
vpx_codec_enc_cfg_t cfg[2];
vpx_rational_t dsf[2] = { { 2, 1 }, { 2, 1 } };
memset(enc, 0, sizeof(enc));
for (int i = 0; i < 2; i++) {
vpx_codec_enc_config_default(iface, &cfg[i], 0);
}
/* Highest-resolution encoder settings */
cfg[0].g_w = width;
cfg[0].g_h = height;
cfg[0].rc_dropframe_thresh = 0;
cfg[0].rc_end_usage = VPX_CBR;
cfg[0].rc_resize_allowed = 0;
cfg[0].rc_min_quantizer = 2;
cfg[0].rc_max_quantizer = 56;
cfg[0].rc_undershoot_pct = 100;
cfg[0].rc_overshoot_pct = 15;
cfg[0].rc_buf_initial_sz = 500;
cfg[0].rc_buf_optimal_sz = 600;
cfg[0].rc_buf_sz = 1000;
cfg[0].g_error_resilient = 1; /* Enable error resilient mode */
cfg[0].g_lag_in_frames = 0;
cfg[0].kf_mode = VPX_KF_AUTO;
cfg[0].kf_min_dist = 3000;
cfg[0].kf_max_dist = 3000;
cfg[0].rc_target_bitrate = target_bitrate; /* Set target bitrate */
cfg[0].g_timebase.num = 1; /* Set fps */
cfg[0].g_timebase.den = framerate;
memcpy(&cfg[1], &cfg[0], sizeof(cfg[0]));
cfg[1].rc_target_bitrate = 500;
cfg[1].g_w = width_down;
cfg[1].g_h = height_down;
for (int i = 0; i < 2; i++) {
cfg[i].ts_number_layers = 2;
cfg[i].ts_periodicity = 2;
cfg[i].ts_rate_decimator[0] = 2;
cfg[i].ts_rate_decimator[1] = 1;
cfg[i].ts_layer_id[0] = 0;
cfg[i].ts_layer_id[1] = 1;
// Invalid parameters.
cfg[i].ts_target_bitrate[0] = 0;
cfg[i].ts_target_bitrate[1] = 0;
}
// VP9 should report incapable, VP8 invalid for all configurations.
const char kVP9Name[] = "WebM Project VP9";
const bool is_vp9 = strncmp(kVP9Name, vpx_codec_iface_name(iface),
sizeof(kVP9Name) - 1) == 0;
EXPECT_EQ(is_vp9 ? VPX_CODEC_INCAPABLE : VPX_CODEC_INVALID_PARAM,
vpx_codec_enc_init_multi(&enc[0], iface, &cfg[0], 2, 0, &dsf[0]));
for (int i = 0; i < 2; i++) {
vpx_codec_destroy(&enc[i]);
}
}
}
} // namespace

View File

@ -7,7 +7,6 @@
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h" #include "./vpx_config.h"
#include "./vpx_version.h" #include "./vpx_version.h"
@ -26,7 +25,10 @@ const double kUsecsInSec = 1000000.0;
struct EncodePerfTestVideo { struct EncodePerfTestVideo {
EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_, EncodePerfTestVideo(const char *name_, uint32_t width_, uint32_t height_,
uint32_t bitrate_, int frames_) uint32_t bitrate_, int frames_)
: name(name_), width(width_), height(height_), bitrate(bitrate_), : name(name_),
width(width_),
height(height_),
bitrate(bitrate_),
frames(frames_) {} frames(frames_) {}
const char *name; const char *name;
uint32_t width; uint32_t width;
@ -42,14 +44,13 @@ const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
EncodePerfTestVideo("macmarcostationary_640_480_30.yuv", 640, 480, 200, 718), EncodePerfTestVideo("macmarcostationary_640_480_30.yuv", 640, 480, 200, 718),
EncodePerfTestVideo("niklas_640_480_30.yuv", 640, 480, 200, 471), EncodePerfTestVideo("niklas_640_480_30.yuv", 640, 480, 200, 471),
EncodePerfTestVideo("tacomanarrows_640_480_30.yuv", 640, 480, 200, 300), EncodePerfTestVideo("tacomanarrows_640_480_30.yuv", 640, 480, 200, 300),
EncodePerfTestVideo("tacomasmallcameramovement_640_480_30.yuv", 640, 480, 200, EncodePerfTestVideo("tacomasmallcameramovement_640_480_30.yuv",
300), 640, 480, 200, 300),
EncodePerfTestVideo("thaloundeskmtg_640_480_30.yuv", 640, 480, 200, 300), EncodePerfTestVideo("thaloundeskmtg_640_480_30.yuv", 640, 480, 200, 300),
EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470), EncodePerfTestVideo("niklas_1280_720_30.yuv", 1280, 720, 600, 470),
}; };
const int kEncodePerfTestSpeeds[] = { 5, 6, 7, 8 }; const int kEncodePerfTestSpeeds[] = { 5, 6, 7, 12 };
const int kEncodePerfTestThreads[] = { 1, 2, 4 };
#define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0])) #define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
@ -58,8 +59,11 @@ class VP9EncodePerfTest
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
protected: protected:
VP9EncodePerfTest() VP9EncodePerfTest()
: EncoderTest(GET_PARAM(0)), min_psnr_(kMaxPsnr), nframes_(0), : EncoderTest(GET_PARAM(0)),
encoding_mode_(GET_PARAM(1)), speed_(0), threads_(1) {} min_psnr_(kMaxPsnr),
nframes_(0),
encoding_mode_(GET_PARAM(1)),
speed_(0) {}
virtual ~VP9EncodePerfTest() {} virtual ~VP9EncodePerfTest() {}
@ -78,18 +82,12 @@ class VP9EncodePerfTest
cfg_.rc_buf_optimal_sz = 600; cfg_.rc_buf_optimal_sz = 600;
cfg_.rc_resize_allowed = 0; cfg_.rc_resize_allowed = 0;
cfg_.rc_end_usage = VPX_CBR; cfg_.rc_end_usage = VPX_CBR;
cfg_.g_error_resilient = 1;
cfg_.g_threads = threads_;
} }
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) { ::libvpx_test::Encoder *encoder) {
if (video->frame() == 0) { if (video->frame() == 1) {
const int log2_tile_columns = 3;
encoder->Control(VP8E_SET_CPUUSED, speed_); encoder->Control(VP8E_SET_CPUUSED, speed_);
encoder->Control(VP9E_SET_TILE_COLUMNS, log2_tile_columns);
encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
} }
} }
@ -100,89 +98,73 @@ class VP9EncodePerfTest
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
if (pkt->data.psnr.psnr[0] < min_psnr_) { if (pkt->data.psnr.psnr[0] < min_psnr_) {
min_psnr_ = pkt->data.psnr.psnr[0]; min_psnr_= pkt->data.psnr.psnr[0];
} }
} }
// for performance reasons don't decode // for performance reasons don't decode
virtual bool DoDecode() const { return false; } virtual bool DoDecode() { return 0; }
double min_psnr() const { return min_psnr_; } double min_psnr() const {
return min_psnr_;
}
void set_speed(unsigned int speed) { speed_ = speed; } void set_speed(unsigned int speed) {
speed_ = speed;
void set_threads(unsigned int threads) { threads_ = threads; } }
private: private:
double min_psnr_; double min_psnr_;
unsigned int nframes_; unsigned int nframes_;
libvpx_test::TestMode encoding_mode_; libvpx_test::TestMode encoding_mode_;
unsigned speed_; unsigned speed_;
unsigned int threads_;
}; };
TEST_P(VP9EncodePerfTest, PerfTest) { TEST_P(VP9EncodePerfTest, PerfTest) {
for (size_t i = 0; i < NELEMENTS(kVP9EncodePerfTestVectors); ++i) { for (size_t i = 0; i < NELEMENTS(kVP9EncodePerfTestVectors); ++i) {
for (size_t j = 0; j < NELEMENTS(kEncodePerfTestSpeeds); ++j) { for (size_t j = 0; j < NELEMENTS(kEncodePerfTestSpeeds); ++j) {
for (size_t k = 0; k < NELEMENTS(kEncodePerfTestThreads); ++k) { SetUp();
if (kVP9EncodePerfTestVectors[i].width < 512 &&
kEncodePerfTestThreads[k] > 1) {
continue;
} else if (kVP9EncodePerfTestVectors[i].width < 1024 &&
kEncodePerfTestThreads[k] > 2) {
continue;
}
set_threads(kEncodePerfTestThreads[k]); const vpx_rational timebase = { 33333333, 1000000000 };
SetUp(); cfg_.g_timebase = timebase;
cfg_.rc_target_bitrate = kVP9EncodePerfTestVectors[i].bitrate;
const vpx_rational timebase = { 33333333, 1000000000 }; init_flags_ = VPX_CODEC_USE_PSNR;
cfg_.g_timebase = timebase;
cfg_.rc_target_bitrate = kVP9EncodePerfTestVectors[i].bitrate;
init_flags_ = VPX_CODEC_USE_PSNR; const unsigned frames = kVP9EncodePerfTestVectors[i].frames;
const char *video_name = kVP9EncodePerfTestVectors[i].name;
libvpx_test::I420VideoSource video(
video_name,
kVP9EncodePerfTestVectors[i].width,
kVP9EncodePerfTestVectors[i].height,
timebase.den, timebase.num, 0,
kVP9EncodePerfTestVectors[i].frames);
set_speed(kEncodePerfTestSpeeds[j]);
const unsigned frames = kVP9EncodePerfTestVectors[i].frames; vpx_usec_timer t;
const char *video_name = kVP9EncodePerfTestVectors[i].name; vpx_usec_timer_start(&t);
libvpx_test::I420VideoSource video(
video_name, kVP9EncodePerfTestVectors[i].width,
kVP9EncodePerfTestVectors[i].height, timebase.den, timebase.num, 0,
kVP9EncodePerfTestVectors[i].frames);
set_speed(kEncodePerfTestSpeeds[j]);
vpx_usec_timer t; ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
vpx_usec_timer_start(&t);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); vpx_usec_timer_mark(&t);
const double elapsed_secs = vpx_usec_timer_elapsed(&t) / kUsecsInSec;
const double fps = frames / elapsed_secs;
const double minimum_psnr = min_psnr();
vpx_usec_timer_mark(&t); printf("{\n");
const double elapsed_secs = vpx_usec_timer_elapsed(&t) / kUsecsInSec; printf("\t\"type\" : \"encode_perf_test\",\n");
const double fps = frames / elapsed_secs; printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
const double minimum_psnr = min_psnr(); printf("\t\"videoName\" : \"%s\",\n", video_name);
std::string display_name(video_name); printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs);
if (kEncodePerfTestThreads[k] > 1) { printf("\t\"totalFrames\" : %u,\n", frames);
char thread_count[32]; printf("\t\"framesPerSecond\" : %f,\n", fps);
snprintf(thread_count, sizeof(thread_count), "_t-%d", printf("\t\"minPsnr\" : %f,\n", minimum_psnr);
kEncodePerfTestThreads[k]); printf("\t\"speed\" : %d\n", kEncodePerfTestSpeeds[j]);
display_name += thread_count; printf("}\n");
}
printf("{\n");
printf("\t\"type\" : \"encode_perf_test\",\n");
printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP);
printf("\t\"videoName\" : \"%s\",\n", display_name.c_str());
printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs);
printf("\t\"totalFrames\" : %u,\n", frames);
printf("\t\"framesPerSecond\" : %f,\n", fps);
printf("\t\"minPsnr\" : %f,\n", minimum_psnr);
printf("\t\"speed\" : %d,\n", kEncodePerfTestSpeeds[j]);
printf("\t\"threads\" : %d\n", kEncodePerfTestThreads[k]);
printf("}\n");
}
} }
} }
} }
VP9_INSTANTIATE_TEST_CASE(VP9EncodePerfTest, VP9_INSTANTIATE_TEST_CASE(
::testing::Values(::libvpx_test::kRealTime)); VP9EncodePerfTest, ::testing::Values(::libvpx_test::kRealTime));
} // namespace } // namespace

View File

@ -8,61 +8,27 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h" #include "./vpx_config.h"
#include "test/codec_factory.h" #include "test/codec_factory.h"
#include "test/decode_test_driver.h"
#include "test/encode_test_driver.h" #include "test/encode_test_driver.h"
#include "test/decode_test_driver.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
#include "test/video_source.h" #include "test/video_source.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
namespace libvpx_test { namespace libvpx_test {
void Encoder::InitEncoder(VideoSource *video) {
vpx_codec_err_t res;
const vpx_image_t *img = video->img();
if (video->img() && !encoder_.priv) {
cfg_.g_w = img->d_w;
cfg_.g_h = img->d_h;
cfg_.g_timebase = video->timebase();
cfg_.rc_twopass_stats_in = stats_->buf();
res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_, init_flags_);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
#if CONFIG_VP9_ENCODER
if (CodecInterface() == &vpx_codec_vp9_cx_algo) {
// Default to 1 tile column for VP9.
const int log2_tile_columns = 0;
res = vpx_codec_control_(&encoder_, VP9E_SET_TILE_COLUMNS,
log2_tile_columns);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} else
#endif
{
#if CONFIG_VP8_ENCODER
ASSERT_EQ(&vpx_codec_vp8_cx_algo, CodecInterface())
<< "Unknown Codec Interface";
#endif
}
}
}
void Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { void Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) {
if (video->img()) { if (video->img())
EncodeFrameInternal(*video, frame_flags); EncodeFrameInternal(*video, frame_flags);
} else { else
Flush(); Flush();
}
// Handle twopass stats // Handle twopass stats
CxDataIterator iter = GetCxData(); CxDataIterator iter = GetCxData();
while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
if (pkt->kind != VPX_CODEC_STATS_PKT) continue; if (pkt->kind != VPX_CODEC_STATS_PKT)
continue;
stats_->Append(*pkt); stats_->Append(*pkt);
} }
@ -73,6 +39,17 @@ void Encoder::EncodeFrameInternal(const VideoSource &video,
vpx_codec_err_t res; vpx_codec_err_t res;
const vpx_image_t *img = video.img(); const vpx_image_t *img = video.img();
// Handle first frame initialization
if (!encoder_.priv) {
cfg_.g_w = img->d_w;
cfg_.g_h = img->d_h;
cfg_.g_timebase = video.timebase();
cfg_.rc_twopass_stats_in = stats_->buf();
res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_,
init_flags_);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
// Handle frame resizing // Handle frame resizing
if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) { if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) {
cfg_.g_w = img->d_w; cfg_.g_w = img->d_w;
@ -82,15 +59,16 @@ void Encoder::EncodeFrameInternal(const VideoSource &video,
} }
// Encode the frame // Encode the frame
API_REGISTER_STATE_CHECK(res = vpx_codec_encode(&encoder_, img, video.pts(), API_REGISTER_STATE_CHECK(
video.duration(), frame_flags, res = vpx_codec_encode(&encoder_,
deadline_)); video.img(), video.pts(), video.duration(),
frame_flags, deadline_));
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} }
void Encoder::Flush() { void Encoder::Flush() {
const vpx_codec_err_t res = const vpx_codec_err_t res = vpx_codec_encode(&encoder_, NULL, 0, 0, 0,
vpx_codec_encode(&encoder_, NULL, 0, 0, 0, deadline_); deadline_);
if (!encoder_.priv) if (!encoder_.priv)
ASSERT_EQ(VPX_CODEC_ERROR, res) << EncoderError(); ASSERT_EQ(VPX_CODEC_ERROR, res) << EncoderError();
else else
@ -99,110 +77,103 @@ void Encoder::Flush() {
void EncoderTest::InitializeConfig() { void EncoderTest::InitializeConfig() {
const vpx_codec_err_t res = codec_->DefaultEncoderConfig(&cfg_, 0); const vpx_codec_err_t res = codec_->DefaultEncoderConfig(&cfg_, 0);
dec_cfg_ = vpx_codec_dec_cfg_t();
ASSERT_EQ(VPX_CODEC_OK, res); ASSERT_EQ(VPX_CODEC_OK, res);
} }
void EncoderTest::SetMode(TestMode mode) { void EncoderTest::SetMode(TestMode mode) {
switch (mode) { switch (mode) {
case kRealTime: deadline_ = VPX_DL_REALTIME; break; case kRealTime:
deadline_ = VPX_DL_REALTIME;
break;
case kOnePassGood: case kOnePassGood:
case kTwoPassGood: deadline_ = VPX_DL_GOOD_QUALITY; break; case kTwoPassGood:
deadline_ = VPX_DL_GOOD_QUALITY;
break;
case kOnePassBest: case kOnePassBest:
case kTwoPassBest: deadline_ = VPX_DL_BEST_QUALITY; break; case kTwoPassBest:
deadline_ = VPX_DL_BEST_QUALITY;
break;
default: ASSERT_TRUE(false) << "Unexpected mode " << mode; default:
ASSERT_TRUE(false) << "Unexpected mode " << mode;
} }
if (mode == kTwoPassGood || mode == kTwoPassBest) { if (mode == kTwoPassGood || mode == kTwoPassBest)
passes_ = 2; passes_ = 2;
} else { else
passes_ = 1; passes_ = 1;
}
} }
// The function should return "true" most of the time, therefore no early // The function should return "true" most of the time, therefore no early
// break-out is implemented within the match checking process. // break-out is implemented within the match checking process.
static bool compare_img(const vpx_image_t *img1, const vpx_image_t *img2) { static bool compare_img(const vpx_image_t *img1,
bool match = (img1->fmt == img2->fmt) && (img1->cs == img2->cs) && const vpx_image_t *img2) {
(img1->d_w == img2->d_w) && (img1->d_h == img2->d_h); bool match = (img1->fmt == img2->fmt) &&
(img1->cs == img2->cs) &&
(img1->d_w == img2->d_w) &&
(img1->d_h == img2->d_h);
const unsigned int width_y = img1->d_w; const unsigned int width_y = img1->d_w;
const unsigned int height_y = img1->d_h; const unsigned int height_y = img1->d_h;
unsigned int i; unsigned int i;
for (i = 0; i < height_y; ++i) { for (i = 0; i < height_y; ++i)
match = (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y], match = (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y],
img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y], img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y],
width_y) == 0) && width_y) == 0) && match;
match; const unsigned int width_uv = (img1->d_w + 1) >> 1;
}
const unsigned int width_uv = (img1->d_w + 1) >> 1;
const unsigned int height_uv = (img1->d_h + 1) >> 1; const unsigned int height_uv = (img1->d_h + 1) >> 1;
for (i = 0; i < height_uv; ++i) { for (i = 0; i < height_uv; ++i)
match = (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U], match = (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U], img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U],
width_uv) == 0) && width_uv) == 0) && match;
match; for (i = 0; i < height_uv; ++i)
}
for (i = 0; i < height_uv; ++i) {
match = (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V], match = (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V],
img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V], img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V],
width_uv) == 0) && width_uv) == 0) && match;
match;
}
return match; return match;
} }
void EncoderTest::MismatchHook(const vpx_image_t * /*img1*/, void EncoderTest::MismatchHook(const vpx_image_t* /*img1*/,
const vpx_image_t * /*img2*/) { const vpx_image_t* /*img2*/) {
ASSERT_TRUE(0) << "Encode/Decode mismatch found"; ASSERT_TRUE(0) << "Encode/Decode mismatch found";
} }
void EncoderTest::RunLoop(VideoSource *video) { void EncoderTest::RunLoop(VideoSource *video) {
vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t(); vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t();
#if CONFIG_ROW_TILE
// Decode all tiles.
dec_cfg.tile_col = -1;
dec_cfg.tile_row = -1;
#endif // CONFIG_ROW_TILE
stats_.Reset(); stats_.Reset();
ASSERT_TRUE(passes_ == 1 || passes_ == 2); ASSERT_TRUE(passes_ == 1 || passes_ == 2);
for (unsigned int pass = 0; pass < passes_; pass++) { for (unsigned int pass = 0; pass < passes_; pass++) {
last_pts_ = 0; last_pts_ = 0;
if (passes_ == 1) { if (passes_ == 1)
cfg_.g_pass = VPX_RC_ONE_PASS; cfg_.g_pass = VPX_RC_ONE_PASS;
} else if (pass == 0) { else if (pass == 0)
cfg_.g_pass = VPX_RC_FIRST_PASS; cfg_.g_pass = VPX_RC_FIRST_PASS;
} else { else
cfg_.g_pass = VPX_RC_LAST_PASS; cfg_.g_pass = VPX_RC_LAST_PASS;
}
BeginPassHook(pass); BeginPassHook(pass);
testing::internal::scoped_ptr<Encoder> encoder( Encoder* const encoder = codec_->CreateEncoder(cfg_, deadline_, init_flags_,
codec_->CreateEncoder(cfg_, deadline_, init_flags_, &stats_)); &stats_);
ASSERT_TRUE(encoder.get() != NULL); ASSERT_TRUE(encoder != NULL);
Decoder* const decoder = codec_->CreateDecoder(dec_cfg, 0);
ASSERT_NO_FATAL_FAILURE(video->Begin());
encoder->InitEncoder(video);
ASSERT_FALSE(::testing::Test::HasFatalFailure());
unsigned long dec_init_flags = 0; // NOLINT
// Use fragment decoder if encoder outputs partitions.
// NOTE: fragment decoder and partition encoder are only supported by VP8.
if (init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) {
dec_init_flags |= VPX_CODEC_USE_INPUT_FRAGMENTS;
}
testing::internal::scoped_ptr<Decoder> decoder(
codec_->CreateDecoder(dec_cfg, dec_init_flags));
bool again; bool again;
for (again = true; again; video->Next()) { for (again = true, video->Begin(); again; video->Next()) {
again = (video->img() != NULL); again = (video->img() != NULL);
PreEncodeFrameHook(video); PreEncodeFrameHook(video);
PreEncodeFrameHook(video, encoder.get()); PreEncodeFrameHook(video, encoder);
encoder->EncodeFrame(video, frame_flags_); encoder->EncodeFrame(video, frame_flags_);
PostEncodeFrameHook();
CxDataIterator iter = encoder->GetCxData(); CxDataIterator iter = encoder->GetCxData();
bool has_cxdata = false; bool has_cxdata = false;
@ -213,11 +184,12 @@ void EncoderTest::RunLoop(VideoSource *video) {
switch (pkt->kind) { switch (pkt->kind) {
case VPX_CODEC_CX_FRAME_PKT: case VPX_CODEC_CX_FRAME_PKT:
has_cxdata = true; has_cxdata = true;
if (decoder.get() != NULL && DoDecode()) { if (decoder && DoDecode()) {
vpx_codec_err_t res_dec = decoder->DecodeFrame( vpx_codec_err_t res_dec = decoder->DecodeFrame(
(const uint8_t *)pkt->data.frame.buf, pkt->data.frame.sz); (const uint8_t*)pkt->data.frame.buf, pkt->data.frame.sz);
if (!HandleDecodeResult(res_dec, *video, decoder.get())) break; if (!HandleDecodeResult(res_dec, *video, decoder))
break;
has_dxdata = true; has_dxdata = true;
} }
@ -226,20 +198,15 @@ void EncoderTest::RunLoop(VideoSource *video) {
FramePktHook(pkt); FramePktHook(pkt);
break; break;
case VPX_CODEC_PSNR_PKT: PSNRPktHook(pkt); break; case VPX_CODEC_PSNR_PKT:
PSNRPktHook(pkt);
break;
case VPX_CODEC_STATS_PKT: StatsPktHook(pkt); break; default:
break;
default: break;
} }
} }
// Flush the decoder when there are no more fragments.
if ((init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) && has_dxdata) {
const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0);
if (!HandleDecodeResult(res_dec, *video, decoder.get())) break;
}
if (has_dxdata && has_cxdata) { if (has_dxdata && has_cxdata) {
const vpx_image_t *img_enc = encoder->GetPreviewFrame(); const vpx_image_t *img_enc = encoder->GetPreviewFrame();
DxDataIterator dec_iter = decoder->GetDxData(); DxDataIterator dec_iter = decoder->GetDxData();
@ -250,14 +217,21 @@ void EncoderTest::RunLoop(VideoSource *video) {
MismatchHook(img_enc, img_dec); MismatchHook(img_enc, img_dec);
} }
} }
if (img_dec) DecompressedFrameHook(*img_dec, video->pts()); if (img_dec)
DecompressedFrameHook(*img_dec, video->pts());
} }
if (!Continue()) break; if (!Continue())
break;
} }
EndPassHook(); EndPassHook();
if (!Continue()) break; if (decoder)
delete decoder;
delete encoder;
if (!Continue())
break;
} }
} }

View File

@ -13,13 +13,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_config.h" #include "./vpx_config.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_encoder.h"
#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#endif #endif
#include "vpx/vpx_encoder.h"
namespace libvpx_test { namespace libvpx_test {
@ -33,17 +32,19 @@ enum TestMode {
kTwoPassGood, kTwoPassGood,
kTwoPassBest kTwoPassBest
}; };
#define ALL_TEST_MODES \ #define ALL_TEST_MODES ::testing::Values(::libvpx_test::kRealTime, \
::testing::Values(::libvpx_test::kRealTime, ::libvpx_test::kOnePassGood, \ ::libvpx_test::kOnePassGood, \
::libvpx_test::kOnePassBest, ::libvpx_test::kTwoPassGood, \ ::libvpx_test::kOnePassBest, \
::libvpx_test::kTwoPassBest) ::libvpx_test::kTwoPassGood, \
::libvpx_test::kTwoPassBest)
#define ONE_PASS_TEST_MODES \ #define ONE_PASS_TEST_MODES ::testing::Values(::libvpx_test::kRealTime, \
::testing::Values(::libvpx_test::kRealTime, ::libvpx_test::kOnePassGood, \ ::libvpx_test::kOnePassGood, \
::libvpx_test::kOnePassBest) ::libvpx_test::kOnePassBest)
#define TWO_PASS_TEST_MODES ::testing::Values(::libvpx_test::kTwoPassGood, \
::libvpx_test::kTwoPassBest)
#define TWO_PASS_TEST_MODES \
::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kTwoPassBest)
// Provides an object to handle the libvpx get_cx_data() iteration pattern // Provides an object to handle the libvpx get_cx_data() iteration pattern
class CxDataIterator { class CxDataIterator {
@ -56,8 +57,8 @@ class CxDataIterator {
} }
private: private:
vpx_codec_ctx_t *encoder_; vpx_codec_ctx_t *encoder_;
vpx_codec_iter_t iter_; vpx_codec_iter_t iter_;
}; };
// Implements an in-memory store for libvpx twopass statistics // Implements an in-memory store for libvpx twopass statistics
@ -73,12 +74,15 @@ class TwopassStatsStore {
return buf; return buf;
} }
void Reset() { buffer_.clear(); } void Reset() {
buffer_.clear();
}
protected: protected:
std::string buffer_; std::string buffer_;
}; };
// Provides a simplified interface to manage one video encoding pass, given // Provides a simplified interface to manage one video encoding pass, given
// a configuration and video source. // a configuration and video source.
// //
@ -92,11 +96,13 @@ class Encoder {
memset(&encoder_, 0, sizeof(encoder_)); memset(&encoder_, 0, sizeof(encoder_));
} }
virtual ~Encoder() { vpx_codec_destroy(&encoder_); } virtual ~Encoder() {
vpx_codec_destroy(&encoder_);
}
CxDataIterator GetCxData() { return CxDataIterator(&encoder_); } CxDataIterator GetCxData() {
return CxDataIterator(&encoder_);
void InitEncoder(VideoSource *video); }
const vpx_image_t *GetPreviewFrame() { const vpx_image_t *GetPreviewFrame() {
return vpx_codec_get_preview_frame(&encoder_); return vpx_codec_get_preview_frame(&encoder_);
@ -106,14 +112,11 @@ class Encoder {
void EncodeFrame(VideoSource *video, const unsigned long frame_flags); void EncodeFrame(VideoSource *video, const unsigned long frame_flags);
// Convenience wrapper for EncodeFrame() // Convenience wrapper for EncodeFrame()
void EncodeFrame(VideoSource *video) { EncodeFrame(video, 0); } void EncodeFrame(VideoSource *video) {
EncodeFrame(video, 0);
void Control(int ctrl_id, int arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} }
void Control(int ctrl_id, int *arg) { void Control(int ctrl_id, int arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg); const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} }
@ -123,46 +126,19 @@ class Encoder {
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} }
void Control(int ctrl_id, struct vpx_svc_layer_id *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
void Control(int ctrl_id, struct vpx_svc_ref_frame_config *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
void Control(int ctrl_id, struct vpx_svc_parameters *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
void Control(int ctrl_id, struct vpx_svc_frame_drop *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
void Control(int ctrl_id, vpx_active_map_t *arg) { void Control(int ctrl_id, vpx_active_map_t *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg); const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
} }
void Control(int ctrl_id, vpx_roi_map_t *arg) {
const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
}
#endif #endif
void Config(const vpx_codec_enc_cfg_t *cfg) {
const vpx_codec_err_t res = vpx_codec_enc_config_set(&encoder_, cfg);
ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
cfg_ = *cfg;
}
void set_deadline(unsigned long deadline) { deadline_ = deadline; } void set_deadline(unsigned long deadline) {
deadline_ = deadline;
}
protected: protected:
virtual vpx_codec_iface_t *CodecInterface() const = 0; virtual vpx_codec_iface_t* CodecInterface() const = 0;
const char *EncoderError() { const char *EncoderError() {
const char *detail = vpx_codec_error_detail(&encoder_); const char *detail = vpx_codec_error_detail(&encoder_);
@ -176,11 +152,11 @@ class Encoder {
// Flush the encoder on EOS // Flush the encoder on EOS
void Flush(); void Flush();
vpx_codec_ctx_t encoder_; vpx_codec_ctx_t encoder_;
vpx_codec_enc_cfg_t cfg_; vpx_codec_enc_cfg_t cfg_;
unsigned long deadline_; unsigned long deadline_;
unsigned long init_flags_; unsigned long init_flags_;
TwopassStatsStore *stats_; TwopassStatsStore *stats_;
}; };
// Common test functionality for all Encoder tests. // Common test functionality for all Encoder tests.
@ -194,10 +170,7 @@ class EncoderTest {
protected: protected:
explicit EncoderTest(const CodecFactory *codec) explicit EncoderTest(const CodecFactory *codec)
: codec_(codec), abort_(false), init_flags_(0), frame_flags_(0), : codec_(codec), abort_(false), init_flags_(0), frame_flags_(0),
last_pts_(0) { last_pts_(0) {}
// Default to 1 thread.
cfg_.g_threads = 1;
}
virtual ~EncoderTest() {} virtual ~EncoderTest() {}
@ -207,11 +180,6 @@ class EncoderTest {
// Map the TestMode enum to the deadline_ and passes_ variables. // Map the TestMode enum to the deadline_ and passes_ variables.
void SetMode(TestMode mode); void SetMode(TestMode mode);
// Set encoder flag.
void set_init_flags(unsigned long flag) { // NOLINT(runtime/int)
init_flags_ = flag;
}
// Main loop // Main loop
virtual void RunLoop(VideoSource *video); virtual void RunLoop(VideoSource *video);
@ -222,40 +190,36 @@ class EncoderTest {
virtual void EndPassHook() {} virtual void EndPassHook() {}
// Hook to be called before encoding a frame. // Hook to be called before encoding a frame.
virtual void PreEncodeFrameHook(VideoSource * /*video*/) {} virtual void PreEncodeFrameHook(VideoSource* /*video*/) {}
virtual void PreEncodeFrameHook(VideoSource * /*video*/, virtual void PreEncodeFrameHook(VideoSource* /*video*/,
Encoder * /*encoder*/) {} Encoder* /*encoder*/) {}
virtual void PostEncodeFrameHook() {}
// Hook to be called on every compressed data packet. // Hook to be called on every compressed data packet.
virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) {} virtual void FramePktHook(const vpx_codec_cx_pkt_t* /*pkt*/) {}
// Hook to be called on every PSNR packet. // Hook to be called on every PSNR packet.
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t * /*pkt*/) {} virtual void PSNRPktHook(const vpx_codec_cx_pkt_t* /*pkt*/) {}
// Hook to be called on every first pass stats packet.
virtual void StatsPktHook(const vpx_codec_cx_pkt_t * /*pkt*/) {}
// Hook to determine whether the encode loop should continue. // Hook to determine whether the encode loop should continue.
virtual bool Continue() const { virtual bool Continue() const {
return !(::testing::Test::HasFatalFailure() || abort_); return !(::testing::Test::HasFatalFailure() || abort_);
} }
const CodecFactory *codec_; const CodecFactory *codec_;
// Hook to determine whether to decode frame after encoding // Hook to determine whether to decode frame after encoding
virtual bool DoDecode() const { return 1; } virtual bool DoDecode() const { return 1; }
// Hook to handle encode/decode mismatch // Hook to handle encode/decode mismatch
virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2); virtual void MismatchHook(const vpx_image_t *img1,
const vpx_image_t *img2);
// Hook to be called on every decompressed frame. // Hook to be called on every decompressed frame.
virtual void DecompressedFrameHook(const vpx_image_t & /*img*/, virtual void DecompressedFrameHook(const vpx_image_t& /*img*/,
vpx_codec_pts_t /*pts*/) {} vpx_codec_pts_t /*pts*/) {}
// Hook to be called to handle decode result. Return true to continue. // Hook to be called to handle decode result. Return true to continue.
virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
const VideoSource & /*video*/, const VideoSource& /*video*/,
Decoder *decoder) { Decoder *decoder) {
EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError(); EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
return VPX_CODEC_OK == res_dec; return VPX_CODEC_OK == res_dec;
@ -267,15 +231,14 @@ class EncoderTest {
return pkt; return pkt;
} }
bool abort_; bool abort_;
vpx_codec_enc_cfg_t cfg_; vpx_codec_enc_cfg_t cfg_;
vpx_codec_dec_cfg_t dec_cfg_; unsigned int passes_;
unsigned int passes_; unsigned long deadline_;
unsigned long deadline_; TwopassStatsStore stats_;
TwopassStatsStore stats_; unsigned long init_flags_;
unsigned long init_flags_; unsigned long frame_flags_;
unsigned long frame_flags_; vpx_codec_pts_t last_pts_;
vpx_codec_pts_t last_pts_;
}; };
} // namespace libvpx_test } // namespace libvpx_test

146
test/error_block_test.cc Normal file
View File

@ -0,0 +1,146 @@
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cmath>
#include <cstdlib>
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "./vpx_config.h"
#include "./vp9_rtcd.h"
#include "vp9/common/vp9_entropy.h"
#include "vpx/vpx_integer.h"
using libvpx_test::ACMRandom;
namespace {
#if CONFIG_VP9_HIGHBITDEPTH
const int number_of_iterations = 1000;
typedef int64_t (*ErrorBlockFunc)(const tran_low_t *coeff,
const tran_low_t *dqcoeff, intptr_t block_size,
int64_t *ssz, int bps);
typedef std::tr1::tuple<ErrorBlockFunc, ErrorBlockFunc, vpx_bit_depth_t>
ErrorBlockParam;
class ErrorBlockTest
: public ::testing::TestWithParam<ErrorBlockParam> {
public:
virtual ~ErrorBlockTest() {}
virtual void SetUp() {
error_block_op_ = GET_PARAM(0);
ref_error_block_op_ = GET_PARAM(1);
bit_depth_ = GET_PARAM(2);
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
vpx_bit_depth_t bit_depth_;
ErrorBlockFunc error_block_op_;
ErrorBlockFunc ref_error_block_op_;
};
TEST_P(ErrorBlockTest, OperationCheck) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, 4096);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, dqcoeff, 4096);
int err_count_total = 0;
int first_failure = -1;
intptr_t block_size;
int64_t ssz;
int64_t ret;
int64_t ref_ssz;
int64_t ref_ret;
for (int i = 0; i < number_of_iterations; ++i) {
int err_count = 0;
block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
for (int j = 0; j < block_size; j++) {
coeff[j] = rnd(2<<20)-(1<<20);
dqcoeff[j] = rnd(2<<20)-(1<<20);
}
ref_ret = ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz,
bit_depth_);
ASM_REGISTER_STATE_CHECK(ret = error_block_op_(coeff, dqcoeff, block_size,
&ssz, bit_depth_));
err_count += (ref_ret != ret) | (ref_ssz != ssz);
if (err_count && !err_count_total) {
first_failure = i;
}
err_count_total += err_count;
}
EXPECT_EQ(0, err_count_total)
<< "Error: Error Block Test, C output doesn't match SSE2 output. "
<< "First failed at test case " << first_failure;
}
TEST_P(ErrorBlockTest, ExtremeValues) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, 4096);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, dqcoeff, 4096);
int err_count_total = 0;
int first_failure = -1;
intptr_t block_size;
int64_t ssz;
int64_t ret;
int64_t ref_ssz;
int64_t ref_ret;
int max_val = ((1<<20)-1);
for (int i = 0; i < number_of_iterations; ++i) {
int err_count = 0;
int k = (i / 9) % 5;
// Change the maximum coeff value, to test different bit boundaries
if ( k == 4 && (i % 9) == 0 ) {
max_val >>= 1;
}
block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
for (int j = 0; j < block_size; j++) {
if (k < 4) { // Test at maximum values
coeff[j] = k % 2 ? max_val : -max_val;
dqcoeff[j] = (k >> 1) % 2 ? max_val : -max_val;
} else {
coeff[j] = rnd(2 << 14) - (1 << 14);
dqcoeff[j] = rnd(2 << 14) - (1 << 14);
}
}
ref_ret = ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz,
bit_depth_);
ASM_REGISTER_STATE_CHECK(ret = error_block_op_(coeff, dqcoeff, block_size,
&ssz, bit_depth_));
err_count += (ref_ret != ret) | (ref_ssz != ssz);
if (err_count && !err_count_total) {
first_failure = i;
}
err_count_total += err_count;
}
EXPECT_EQ(0, err_count_total)
<< "Error: Error Block Test, C output doesn't match SSE2 output. "
<< "First failed at test case " << first_failure;
}
using std::tr1::make_tuple;
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
SSE2_C_COMPARE, ErrorBlockTest,
::testing::Values(
make_tuple(&vp9_highbd_block_error_sse2,
&vp9_highbd_block_error_c, VPX_BITS_10),
make_tuple(&vp9_highbd_block_error_sse2,
&vp9_highbd_block_error_c, VPX_BITS_12),
make_tuple(&vp9_highbd_block_error_sse2,
&vp9_highbd_block_error_c, VPX_BITS_8)));
#endif // HAVE_SSE2
#endif // CONFIG_VP9_HIGHBITDEPTH
} // namespace

View File

@ -19,13 +19,15 @@ namespace {
const int kMaxErrorFrames = 12; const int kMaxErrorFrames = 12;
const int kMaxDroppableFrames = 12; const int kMaxDroppableFrames = 12;
class ErrorResilienceTestLarge class ErrorResilienceTestLarge : public ::libvpx_test::EncoderTest,
: public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, bool> {
protected: protected:
ErrorResilienceTestLarge() ErrorResilienceTestLarge()
: EncoderTest(GET_PARAM(0)), svc_support_(GET_PARAM(2)), psnr_(0.0), : EncoderTest(GET_PARAM(0)),
nframes_(0), mismatch_psnr_(0.0), mismatch_nframes_(0), psnr_(0.0),
nframes_(0),
mismatch_psnr_(0.0),
mismatch_nframes_(0),
encoding_mode_(GET_PARAM(1)) { encoding_mode_(GET_PARAM(1)) {
Reset(); Reset();
} }
@ -35,7 +37,6 @@ class ErrorResilienceTestLarge
void Reset() { void Reset() {
error_nframes_ = 0; error_nframes_ = 0;
droppable_nframes_ = 0; droppable_nframes_ = 0;
pattern_switch_ = 0;
} }
virtual void SetUp() { virtual void SetUp() {
@ -55,77 +56,34 @@ class ErrorResilienceTestLarge
nframes_++; nframes_++;
} }
//
// Frame flags and layer id for temporal layers.
// For two layers, test pattern is:
// 1 3
// 0 2 .....
// LAST is updated on base/layer 0, GOLDEN updated on layer 1.
// Non-zero pattern_switch parameter means pattern will switch to
// not using LAST for frame_num >= pattern_switch.
int SetFrameFlags(int frame_num, int num_temp_layers, int pattern_switch) {
int frame_flags = 0;
if (num_temp_layers == 2) {
if (frame_num % 2 == 0) {
if (frame_num < pattern_switch || pattern_switch == 0) {
// Layer 0: predict from LAST and ARF, update LAST.
frame_flags =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
} else {
// Layer 0: predict from GF and ARF, update GF.
frame_flags = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ARF;
}
} else {
if (frame_num < pattern_switch || pattern_switch == 0) {
// Layer 1: predict from L, GF, and ARF, update GF.
frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
} else {
// Layer 1: predict from GF and ARF, update GF.
frame_flags = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ARF;
}
}
}
return frame_flags;
}
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video) { virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video) {
frame_flags_ &= frame_flags_ &= ~(VP8_EFLAG_NO_UPD_LAST |
~(VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF); VP8_EFLAG_NO_UPD_GF |
// For temporal layer case. VP8_EFLAG_NO_UPD_ARF);
if (cfg_.ts_number_layers > 1) { if (droppable_nframes_ > 0 &&
frame_flags_ = (cfg_.g_pass == VPX_RC_LAST_PASS || cfg_.g_pass == VPX_RC_ONE_PASS)) {
SetFrameFlags(video->frame(), cfg_.ts_number_layers, pattern_switch_);
for (unsigned int i = 0; i < droppable_nframes_; ++i) { for (unsigned int i = 0; i < droppable_nframes_; ++i) {
if (droppable_frames_[i] == video->frame()) { if (droppable_frames_[i] == video->frame()) {
std::cout << "Encoding droppable frame: " << droppable_frames_[i] std::cout << " Encoding droppable frame: "
<< "\n"; << droppable_frames_[i] << "\n";
} frame_flags_ |= (VP8_EFLAG_NO_UPD_LAST |
} VP8_EFLAG_NO_UPD_GF |
} else { VP8_EFLAG_NO_UPD_ARF);
if (droppable_nframes_ > 0 && return;
(cfg_.g_pass == VPX_RC_LAST_PASS || cfg_.g_pass == VPX_RC_ONE_PASS)) {
for (unsigned int i = 0; i < droppable_nframes_; ++i) {
if (droppable_frames_[i] == video->frame()) {
std::cout << "Encoding droppable frame: " << droppable_frames_[i]
<< "\n";
frame_flags_ |= (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF);
return;
}
} }
} }
} }
} }
double GetAveragePsnr() const { double GetAveragePsnr() const {
if (nframes_) return psnr_ / nframes_; if (nframes_)
return psnr_ / nframes_;
return 0.0; return 0.0;
} }
double GetAverageMismatchPsnr() const { double GetAverageMismatchPsnr() const {
if (mismatch_nframes_) return mismatch_psnr_ / mismatch_nframes_; if (mismatch_nframes_)
return mismatch_psnr_ / mismatch_nframes_;
return 0.0; return 0.0;
} }
@ -143,7 +101,8 @@ class ErrorResilienceTestLarge
return 1; return 1;
} }
virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) { virtual void MismatchHook(const vpx_image_t *img1,
const vpx_image_t *img2) {
double mismatch_psnr = compute_psnr(img1, img2); double mismatch_psnr = compute_psnr(img1, img2);
mismatch_psnr_ += mismatch_psnr; mismatch_psnr_ += mismatch_psnr;
++mismatch_nframes_; ++mismatch_nframes_;
@ -151,41 +110,34 @@ class ErrorResilienceTestLarge
} }
void SetErrorFrames(int num, unsigned int *list) { void SetErrorFrames(int num, unsigned int *list) {
if (num > kMaxErrorFrames) { if (num > kMaxErrorFrames)
num = kMaxErrorFrames; num = kMaxErrorFrames;
} else if (num < 0) { else if (num < 0)
num = 0; num = 0;
}
error_nframes_ = num; error_nframes_ = num;
for (unsigned int i = 0; i < error_nframes_; ++i) { for (unsigned int i = 0; i < error_nframes_; ++i)
error_frames_[i] = list[i]; error_frames_[i] = list[i];
}
} }
void SetDroppableFrames(int num, unsigned int *list) { void SetDroppableFrames(int num, unsigned int *list) {
if (num > kMaxDroppableFrames) { if (num > kMaxDroppableFrames)
num = kMaxDroppableFrames; num = kMaxDroppableFrames;
} else if (num < 0) { else if (num < 0)
num = 0; num = 0;
}
droppable_nframes_ = num; droppable_nframes_ = num;
for (unsigned int i = 0; i < droppable_nframes_; ++i) { for (unsigned int i = 0; i < droppable_nframes_; ++i)
droppable_frames_[i] = list[i]; droppable_frames_[i] = list[i];
}
} }
unsigned int GetMismatchFrames() { return mismatch_nframes_; } unsigned int GetMismatchFrames() {
return mismatch_nframes_;
void SetPatternSwitch(int frame_switch) { pattern_switch_ = frame_switch; } }
bool svc_support_;
private: private:
double psnr_; double psnr_;
unsigned int nframes_; unsigned int nframes_;
unsigned int error_nframes_; unsigned int error_nframes_;
unsigned int droppable_nframes_; unsigned int droppable_nframes_;
unsigned int pattern_switch_;
double mismatch_psnr_; double mismatch_psnr_;
unsigned int mismatch_nframes_; unsigned int mismatch_nframes_;
unsigned int error_frames_[kMaxErrorFrames]; unsigned int error_frames_[kMaxErrorFrames];
@ -249,14 +201,15 @@ TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) {
// In addition to isolated loss/drop, add a long consecutive series // In addition to isolated loss/drop, add a long consecutive series
// (of size 9) of dropped frames. // (of size 9) of dropped frames.
unsigned int num_droppable_frames = 11; unsigned int num_droppable_frames = 11;
unsigned int droppable_frame_list[] = { 5, 16, 22, 23, 24, 25, unsigned int droppable_frame_list[] = {5, 16, 22, 23, 24, 25, 26, 27, 28,
26, 27, 28, 29, 30 }; 29, 30};
SetDroppableFrames(num_droppable_frames, droppable_frame_list); SetDroppableFrames(num_droppable_frames, droppable_frame_list);
SetErrorFrames(num_droppable_frames, droppable_frame_list); SetErrorFrames(num_droppable_frames, droppable_frame_list);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
// Test that no mismatches have been found // Test that no mismatches have been found
std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n"; std::cout << " Mismatch frames: "
EXPECT_EQ(GetMismatchFrames(), (unsigned int)0); << GetMismatchFrames() << "\n";
EXPECT_EQ(GetMismatchFrames(), (unsigned int) 0);
// Reset previously set of error/droppable frames. // Reset previously set of error/droppable frames.
Reset(); Reset();
@ -283,300 +236,7 @@ TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) {
#endif #endif
} }
// Check for successful decoding and no encoder/decoder mismatch VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES);
// if we lose (i.e., drop before decoding) the enhancement layer frames for a VP9_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES);
// two layer temporal pattern. The base layer does not predict from the top
// layer, so successful decoding is expected.
TEST_P(ErrorResilienceTestLarge, 2LayersDropEnhancement) {
// This test doesn't run if SVC is not supported.
if (!svc_support_) return;
const vpx_rational timebase = { 33333333, 1000000000 };
cfg_.g_timebase = timebase;
cfg_.rc_target_bitrate = 500;
cfg_.g_lag_in_frames = 0;
cfg_.rc_end_usage = VPX_CBR;
// 2 Temporal layers, no spatial layers, CBR mode.
cfg_.ss_number_layers = 1;
cfg_.ts_number_layers = 2;
cfg_.ts_rate_decimator[0] = 2;
cfg_.ts_rate_decimator[1] = 1;
cfg_.ts_periodicity = 2;
cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100;
cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate;
init_flags_ = VPX_CODEC_USE_PSNR;
libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
timebase.den, timebase.num, 0, 40);
// Error resilient mode ON.
cfg_.g_error_resilient = 1;
cfg_.kf_mode = VPX_KF_DISABLED;
SetPatternSwitch(0);
// The odd frames are the enhancement layer for 2 layer pattern, so set
// those frames as droppable. Drop the last 7 frames.
unsigned int num_droppable_frames = 7;
unsigned int droppable_frame_list[] = { 27, 29, 31, 33, 35, 37, 39 };
SetDroppableFrames(num_droppable_frames, droppable_frame_list);
SetErrorFrames(num_droppable_frames, droppable_frame_list);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
// Test that no mismatches have been found
std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n";
EXPECT_EQ(GetMismatchFrames(), (unsigned int)0);
// Reset previously set of error/droppable frames.
Reset();
}
// Check for successful decoding and no encoder/decoder mismatch
// for a two layer temporal pattern, where at some point in the
// sequence, the LAST ref is not used anymore.
TEST_P(ErrorResilienceTestLarge, 2LayersNoRefLast) {
// This test doesn't run if SVC is not supported.
if (!svc_support_) return;
const vpx_rational timebase = { 33333333, 1000000000 };
cfg_.g_timebase = timebase;
cfg_.rc_target_bitrate = 500;
cfg_.g_lag_in_frames = 0;
cfg_.rc_end_usage = VPX_CBR;
// 2 Temporal layers, no spatial layers, CBR mode.
cfg_.ss_number_layers = 1;
cfg_.ts_number_layers = 2;
cfg_.ts_rate_decimator[0] = 2;
cfg_.ts_rate_decimator[1] = 1;
cfg_.ts_periodicity = 2;
cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100;
cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate;
init_flags_ = VPX_CODEC_USE_PSNR;
libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
timebase.den, timebase.num, 0, 100);
// Error resilient mode ON.
cfg_.g_error_resilient = 1;
cfg_.kf_mode = VPX_KF_DISABLED;
SetPatternSwitch(60);
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
// Test that no mismatches have been found
std::cout << " Mismatch frames: " << GetMismatchFrames() << "\n";
EXPECT_EQ(GetMismatchFrames(), (unsigned int)0);
// Reset previously set of error/droppable frames.
Reset();
}
class ErrorResilienceTestLargeCodecControls
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
protected:
ErrorResilienceTestLargeCodecControls()
: EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)) {
Reset();
}
virtual ~ErrorResilienceTestLargeCodecControls() {}
void Reset() {
last_pts_ = 0;
tot_frame_number_ = 0;
// For testing up to 3 layers.
for (int i = 0; i < 3; ++i) {
bits_total_[i] = 0;
}
duration_ = 0.0;
}
virtual void SetUp() {
InitializeConfig();
SetMode(encoding_mode_);
}
//
// Frame flags and layer id for temporal layers.
//
// For two layers, test pattern is:
// 1 3
// 0 2 .....
// For three layers, test pattern is:
// 1 3 5 7
// 2 6
// 0 4 ....
// LAST is always update on base/layer 0, GOLDEN is updated on layer 1,
// and ALTREF is updated on top layer for 3 layer pattern.
int SetFrameFlags(int frame_num, int num_temp_layers) {
int frame_flags = 0;
if (num_temp_layers == 2) {
if (frame_num % 2 == 0) {
// Layer 0: predict from L and ARF, update L.
frame_flags =
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
} else {
// Layer 1: predict from L, G and ARF, and update G.
frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
VP8_EFLAG_NO_UPD_ENTROPY;
}
} else if (num_temp_layers == 3) {
if (frame_num % 4 == 0) {
// Layer 0: predict from L, update L.
frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF;
} else if ((frame_num - 2) % 4 == 0) {
// Layer 1: predict from L, G, update G.
frame_flags =
VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_REF_ARF;
} else if ((frame_num - 1) % 2 == 0) {
// Layer 2: predict from L, G, ARF; update ARG.
frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST;
}
}
return frame_flags;
}
int SetLayerId(int frame_num, int num_temp_layers) {
int layer_id = 0;
if (num_temp_layers == 2) {
if (frame_num % 2 == 0) {
layer_id = 0;
} else {
layer_id = 1;
}
} else if (num_temp_layers == 3) {
if (frame_num % 4 == 0) {
layer_id = 0;
} else if ((frame_num - 2) % 4 == 0) {
layer_id = 1;
} else if ((frame_num - 1) % 2 == 0) {
layer_id = 2;
}
}
return layer_id;
}
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
libvpx_test::Encoder *encoder) {
if (cfg_.ts_number_layers > 1) {
int layer_id = SetLayerId(video->frame(), cfg_.ts_number_layers);
int frame_flags = SetFrameFlags(video->frame(), cfg_.ts_number_layers);
if (video->frame() > 0) {
encoder->Control(VP8E_SET_TEMPORAL_LAYER_ID, layer_id);
encoder->Control(VP8E_SET_FRAME_FLAGS, frame_flags);
}
const vpx_rational_t tb = video->timebase();
timebase_ = static_cast<double>(tb.num) / tb.den;
duration_ = 0;
return;
}
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
// Time since last timestamp = duration.
vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_;
if (duration > 1) {
// Update counter for total number of frames (#frames input to encoder).
// Needed for setting the proper layer_id below.
tot_frame_number_ += static_cast<int>(duration - 1);
}
int layer = SetLayerId(tot_frame_number_, cfg_.ts_number_layers);
const size_t frame_size_in_bits = pkt->data.frame.sz * 8;
// Update the total encoded bits. For temporal layers, update the cumulative
// encoded bits per layer.
for (int i = layer; i < static_cast<int>(cfg_.ts_number_layers); ++i) {
bits_total_[i] += frame_size_in_bits;
}
// Update the most recent pts.
last_pts_ = pkt->data.frame.pts;
++tot_frame_number_;
}
virtual void EndPassHook(void) {
duration_ = (last_pts_ + 1) * timebase_;
if (cfg_.ts_number_layers > 1) {
for (int layer = 0; layer < static_cast<int>(cfg_.ts_number_layers);
++layer) {
if (bits_total_[layer]) {
// Effective file datarate:
effective_datarate_[layer] =
(bits_total_[layer] / 1000.0) / duration_;
}
}
}
}
double effective_datarate_[3];
private:
libvpx_test::TestMode encoding_mode_;
vpx_codec_pts_t last_pts_;
double timebase_;
int64_t bits_total_[3];
double duration_;
int tot_frame_number_;
};
// Check two codec controls used for:
// (1) for setting temporal layer id, and (2) for settings encoder flags.
// This test invokes those controls for each frame, and verifies encoder/decoder
// mismatch and basic rate control response.
// TODO(marpan): Maybe move this test to datarate_test.cc.
TEST_P(ErrorResilienceTestLargeCodecControls, CodecControl3TemporalLayers) {
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
cfg_.rc_dropframe_thresh = 1;
cfg_.rc_min_quantizer = 2;
cfg_.rc_max_quantizer = 56;
cfg_.rc_end_usage = VPX_CBR;
cfg_.rc_dropframe_thresh = 1;
cfg_.g_lag_in_frames = 0;
cfg_.kf_mode = VPX_KF_DISABLED;
cfg_.g_error_resilient = 1;
// 3 Temporal layers. Framerate decimation (4, 2, 1).
cfg_.ts_number_layers = 3;
cfg_.ts_rate_decimator[0] = 4;
cfg_.ts_rate_decimator[1] = 2;
cfg_.ts_rate_decimator[2] = 1;
cfg_.ts_periodicity = 4;
cfg_.ts_layer_id[0] = 0;
cfg_.ts_layer_id[1] = 2;
cfg_.ts_layer_id[2] = 1;
cfg_.ts_layer_id[3] = 2;
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
30, 1, 0, 200);
for (int i = 200; i <= 800; i += 200) {
cfg_.rc_target_bitrate = i;
Reset();
// 40-20-40 bitrate allocation for 3 temporal layers.
cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100;
cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100;
cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate;
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) {
ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.75)
<< " The datarate for the file is lower than target by too much, "
"for layer: "
<< j;
ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.25)
<< " The datarate for the file is greater than target by too much, "
"for layer: "
<< j;
}
}
}
VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES,
::testing::Values(true));
VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTestLargeCodecControls,
ONE_PASS_TEST_MODES);
VP9_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES,
::testing::Values(true));
} // namespace } // namespace

View File

@ -15,7 +15,7 @@
example_tests=$(ls $(dirname $0)/*.sh) example_tests=$(ls $(dirname $0)/*.sh)
# List of script names to exclude. # List of script names to exclude.
exclude_list="examples stress tools_common" exclude_list="examples tools_common"
# Filter out the scripts in $exclude_list. # Filter out the scripts in $exclude_list.
for word in ${exclude_list}; do for word in ${exclude_list}; do

View File

@ -24,6 +24,7 @@
namespace { namespace {
const int kVideoNameParam = 1; const int kVideoNameParam = 1;
const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
struct ExternalFrameBuffer { struct ExternalFrameBuffer {
uint8_t *data; uint8_t *data;
@ -35,18 +36,20 @@ struct ExternalFrameBuffer {
class ExternalFrameBufferList { class ExternalFrameBufferList {
public: public:
ExternalFrameBufferList() ExternalFrameBufferList()
: num_buffers_(0), num_used_buffers_(0), ext_fb_list_(NULL) {} : num_buffers_(0),
ext_fb_list_(NULL) {}
virtual ~ExternalFrameBufferList() { virtual ~ExternalFrameBufferList() {
for (int i = 0; i < num_buffers_; ++i) { for (int i = 0; i < num_buffers_; ++i) {
delete[] ext_fb_list_[i].data; delete [] ext_fb_list_[i].data;
} }
delete[] ext_fb_list_; delete [] ext_fb_list_;
} }
// Creates the list to hold the external buffers. Returns true on success. // Creates the list to hold the external buffers. Returns true on success.
bool CreateBufferList(int num_buffers) { bool CreateBufferList(int num_buffers) {
if (num_buffers < 0) return false; if (num_buffers < 0)
return false;
num_buffers_ = num_buffers; num_buffers_ = num_buffers;
ext_fb_list_ = new ExternalFrameBuffer[num_buffers_]; ext_fb_list_ = new ExternalFrameBuffer[num_buffers_];
@ -62,18 +65,17 @@ class ExternalFrameBufferList {
int GetFreeFrameBuffer(size_t min_size, vpx_codec_frame_buffer_t *fb) { int GetFreeFrameBuffer(size_t min_size, vpx_codec_frame_buffer_t *fb) {
EXPECT_TRUE(fb != NULL); EXPECT_TRUE(fb != NULL);
const int idx = FindFreeBufferIndex(); const int idx = FindFreeBufferIndex();
if (idx == num_buffers_) return -1; if (idx == num_buffers_)
return -1;
if (ext_fb_list_[idx].size < min_size) { if (ext_fb_list_[idx].size < min_size) {
delete[] ext_fb_list_[idx].data; delete [] ext_fb_list_[idx].data;
ext_fb_list_[idx].data = new uint8_t[min_size]; ext_fb_list_[idx].data = new uint8_t[min_size];
memset(ext_fb_list_[idx].data, 0, min_size); memset(ext_fb_list_[idx].data, 0, min_size);
ext_fb_list_[idx].size = min_size; ext_fb_list_[idx].size = min_size;
} }
SetFrameBuffer(idx, fb); SetFrameBuffer(idx, fb);
num_used_buffers_++;
return 0; return 0;
} }
@ -82,10 +84,11 @@ class ExternalFrameBufferList {
int GetZeroFrameBuffer(size_t min_size, vpx_codec_frame_buffer_t *fb) { int GetZeroFrameBuffer(size_t min_size, vpx_codec_frame_buffer_t *fb) {
EXPECT_TRUE(fb != NULL); EXPECT_TRUE(fb != NULL);
const int idx = FindFreeBufferIndex(); const int idx = FindFreeBufferIndex();
if (idx == num_buffers_) return -1; if (idx == num_buffers_)
return -1;
if (ext_fb_list_[idx].size < min_size) { if (ext_fb_list_[idx].size < min_size) {
delete[] ext_fb_list_[idx].data; delete [] ext_fb_list_[idx].data;
ext_fb_list_[idx].data = NULL; ext_fb_list_[idx].data = NULL;
ext_fb_list_[idx].size = min_size; ext_fb_list_[idx].size = min_size;
} }
@ -94,22 +97,15 @@ class ExternalFrameBufferList {
return 0; return 0;
} }
// Marks the external frame buffer that |fb| is pointing to as free. // Marks the external frame buffer that |fb| is pointing too as free.
// Returns < 0 on an error. // Returns < 0 on an error.
int ReturnFrameBuffer(vpx_codec_frame_buffer_t *fb) { int ReturnFrameBuffer(vpx_codec_frame_buffer_t *fb) {
if (fb == NULL) { EXPECT_TRUE(fb != NULL);
EXPECT_TRUE(fb != NULL);
return -1;
}
ExternalFrameBuffer *const ext_fb = ExternalFrameBuffer *const ext_fb =
reinterpret_cast<ExternalFrameBuffer *>(fb->priv); reinterpret_cast<ExternalFrameBuffer*>(fb->priv);
if (ext_fb == NULL) { EXPECT_TRUE(ext_fb != NULL);
EXPECT_TRUE(ext_fb != NULL);
return -1;
}
EXPECT_EQ(1, ext_fb->in_use); EXPECT_EQ(1, ext_fb->in_use);
ext_fb->in_use = 0; ext_fb->in_use = 0;
num_used_buffers_--;
return 0; return 0;
} }
@ -118,15 +114,13 @@ class ExternalFrameBufferList {
void CheckXImageFrameBuffer(const vpx_image_t *img) { void CheckXImageFrameBuffer(const vpx_image_t *img) {
if (img->fb_priv != NULL) { if (img->fb_priv != NULL) {
const struct ExternalFrameBuffer *const ext_fb = const struct ExternalFrameBuffer *const ext_fb =
reinterpret_cast<ExternalFrameBuffer *>(img->fb_priv); reinterpret_cast<ExternalFrameBuffer*>(img->fb_priv);
ASSERT_TRUE(img->planes[0] >= ext_fb->data && ASSERT_TRUE(img->planes[0] >= ext_fb->data &&
img->planes[0] < (ext_fb->data + ext_fb->size)); img->planes[0] < (ext_fb->data + ext_fb->size));
} }
} }
int num_used_buffers() const { return num_used_buffers_; }
private: private:
// Returns the index of the first free frame buffer. Returns |num_buffers_| // Returns the index of the first free frame buffer. Returns |num_buffers_|
// if there are no free frame buffers. // if there are no free frame buffers.
@ -134,7 +128,8 @@ class ExternalFrameBufferList {
int i; int i;
// Find a free frame buffer. // Find a free frame buffer.
for (i = 0; i < num_buffers_; ++i) { for (i = 0; i < num_buffers_; ++i) {
if (!ext_fb_list_[i].in_use) break; if (!ext_fb_list_[i].in_use)
break;
} }
return i; return i;
} }
@ -151,26 +146,24 @@ class ExternalFrameBufferList {
} }
int num_buffers_; int num_buffers_;
int num_used_buffers_;
ExternalFrameBuffer *ext_fb_list_; ExternalFrameBuffer *ext_fb_list_;
}; };
#if CONFIG_WEBM_IO
// Callback used by libvpx to request the application to return a frame // Callback used by libvpx to request the application to return a frame
// buffer of at least |min_size| in bytes. // buffer of at least |min_size| in bytes.
int get_vp9_frame_buffer(void *user_priv, size_t min_size, int get_vp9_frame_buffer(void *user_priv, size_t min_size,
vpx_codec_frame_buffer_t *fb) { vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferList *const fb_list = ExternalFrameBufferList *const fb_list =
reinterpret_cast<ExternalFrameBufferList *>(user_priv); reinterpret_cast<ExternalFrameBufferList*>(user_priv);
return fb_list->GetFreeFrameBuffer(min_size, fb); return fb_list->GetFreeFrameBuffer(min_size, fb);
} }
// Callback used by libvpx to tell the application that |fb| is not needed // Callback used by libvpx to tell the application that |fb| is not needed
// anymore. // anymore.
int release_vp9_frame_buffer(void *user_priv, vpx_codec_frame_buffer_t *fb) { int release_vp9_frame_buffer(void *user_priv,
vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferList *const fb_list = ExternalFrameBufferList *const fb_list =
reinterpret_cast<ExternalFrameBufferList *>(user_priv); reinterpret_cast<ExternalFrameBufferList*>(user_priv);
return fb_list->ReturnFrameBuffer(fb); return fb_list->ReturnFrameBuffer(fb);
} }
@ -178,7 +171,7 @@ int release_vp9_frame_buffer(void *user_priv, vpx_codec_frame_buffer_t *fb) {
int get_vp9_zero_frame_buffer(void *user_priv, size_t min_size, int get_vp9_zero_frame_buffer(void *user_priv, size_t min_size,
vpx_codec_frame_buffer_t *fb) { vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferList *const fb_list = ExternalFrameBufferList *const fb_list =
reinterpret_cast<ExternalFrameBufferList *>(user_priv); reinterpret_cast<ExternalFrameBufferList*>(user_priv);
return fb_list->GetZeroFrameBuffer(min_size, fb); return fb_list->GetZeroFrameBuffer(min_size, fb);
} }
@ -186,7 +179,7 @@ int get_vp9_zero_frame_buffer(void *user_priv, size_t min_size,
int get_vp9_one_less_byte_frame_buffer(void *user_priv, size_t min_size, int get_vp9_one_less_byte_frame_buffer(void *user_priv, size_t min_size,
vpx_codec_frame_buffer_t *fb) { vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferList *const fb_list = ExternalFrameBufferList *const fb_list =
reinterpret_cast<ExternalFrameBufferList *>(user_priv); reinterpret_cast<ExternalFrameBufferList*>(user_priv);
return fb_list->GetFreeFrameBuffer(min_size - 1, fb); return fb_list->GetFreeFrameBuffer(min_size - 1, fb);
} }
@ -198,19 +191,19 @@ int do_not_release_vp9_frame_buffer(void *user_priv,
return 0; return 0;
} }
#endif // CONFIG_WEBM_IO
// Class for testing passing in external frame buffers to libvpx. // Class for testing passing in external frame buffers to libvpx.
class ExternalFrameBufferMD5Test class ExternalFrameBufferMD5Test
: public ::libvpx_test::DecoderTest, : public ::libvpx_test::DecoderTest,
public ::libvpx_test::CodecTestWithParam<const char *> { public ::libvpx_test::CodecTestWithParam<const char*> {
protected: protected:
ExternalFrameBufferMD5Test() ExternalFrameBufferMD5Test()
: DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)), : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)),
md5_file_(NULL), num_buffers_(0) {} md5_file_(NULL),
num_buffers_(0) {}
virtual ~ExternalFrameBufferMD5Test() { virtual ~ExternalFrameBufferMD5Test() {
if (md5_file_ != NULL) fclose(md5_file_); if (md5_file_ != NULL)
fclose(md5_file_);
} }
virtual void PreDecodeFrameHook( virtual void PreDecodeFrameHook(
@ -220,15 +213,15 @@ class ExternalFrameBufferMD5Test
// Have libvpx use frame buffers we create. // Have libvpx use frame buffers we create.
ASSERT_TRUE(fb_list_.CreateBufferList(num_buffers_)); ASSERT_TRUE(fb_list_.CreateBufferList(num_buffers_));
ASSERT_EQ(VPX_CODEC_OK, ASSERT_EQ(VPX_CODEC_OK,
decoder->SetFrameBufferFunctions(GetVP9FrameBuffer, decoder->SetFrameBufferFunctions(
ReleaseVP9FrameBuffer, this)); GetVP9FrameBuffer, ReleaseVP9FrameBuffer, this));
} }
} }
void OpenMD5File(const std::string &md5_file_name_) { void OpenMD5File(const std::string &md5_file_name_) {
md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_); md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
ASSERT_TRUE(md5_file_ != NULL) ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
<< "Md5 file open failed. Filename: " << md5_file_name_; << md5_file_name_;
} }
virtual void DecompressedFrameHook(const vpx_image_t &img, virtual void DecompressedFrameHook(const vpx_image_t &img,
@ -256,7 +249,7 @@ class ExternalFrameBufferMD5Test
static int GetVP9FrameBuffer(void *user_priv, size_t min_size, static int GetVP9FrameBuffer(void *user_priv, size_t min_size,
vpx_codec_frame_buffer_t *fb) { vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferMD5Test *const md5Test = ExternalFrameBufferMD5Test *const md5Test =
reinterpret_cast<ExternalFrameBufferMD5Test *>(user_priv); reinterpret_cast<ExternalFrameBufferMD5Test*>(user_priv);
return md5Test->fb_list_.GetFreeFrameBuffer(min_size, fb); return md5Test->fb_list_.GetFreeFrameBuffer(min_size, fb);
} }
@ -265,7 +258,7 @@ class ExternalFrameBufferMD5Test
static int ReleaseVP9FrameBuffer(void *user_priv, static int ReleaseVP9FrameBuffer(void *user_priv,
vpx_codec_frame_buffer_t *fb) { vpx_codec_frame_buffer_t *fb) {
ExternalFrameBufferMD5Test *const md5Test = ExternalFrameBufferMD5Test *const md5Test =
reinterpret_cast<ExternalFrameBufferMD5Test *>(user_priv); reinterpret_cast<ExternalFrameBufferMD5Test*>(user_priv);
return md5Test->fb_list_.ReturnFrameBuffer(fb); return md5Test->fb_list_.ReturnFrameBuffer(fb);
} }
@ -279,13 +272,13 @@ class ExternalFrameBufferMD5Test
}; };
#if CONFIG_WEBM_IO #if CONFIG_WEBM_IO
const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
const char kVP9NonRefTestFile[] = "vp90-2-22-svc_1280x720_1.webm";
// Class for testing passing in external frame buffers to libvpx. // Class for testing passing in external frame buffers to libvpx.
class ExternalFrameBufferTest : public ::testing::Test { class ExternalFrameBufferTest : public ::testing::Test {
protected: protected:
ExternalFrameBufferTest() : video_(NULL), decoder_(NULL), num_buffers_(0) {} ExternalFrameBufferTest()
: video_(NULL),
decoder_(NULL),
num_buffers_(0) {}
virtual void SetUp() { virtual void SetUp() {
video_ = new libvpx_test::WebMVideoSource(kVP9TestFile); video_ = new libvpx_test::WebMVideoSource(kVP9TestFile);
@ -300,14 +293,13 @@ class ExternalFrameBufferTest : public ::testing::Test {
virtual void TearDown() { virtual void TearDown() {
delete decoder_; delete decoder_;
decoder_ = NULL;
delete video_; delete video_;
video_ = NULL;
} }
// Passes the external frame buffer information to libvpx. // Passes the external frame buffer information to libvpx.
vpx_codec_err_t SetFrameBufferFunctions( vpx_codec_err_t SetFrameBufferFunctions(
int num_buffers, vpx_get_frame_buffer_cb_fn_t cb_get, int num_buffers,
vpx_get_frame_buffer_cb_fn_t cb_get,
vpx_release_frame_buffer_cb_fn_t cb_release) { vpx_release_frame_buffer_cb_fn_t cb_release) {
if (num_buffers > 0) { if (num_buffers > 0) {
num_buffers_ = num_buffers; num_buffers_ = num_buffers;
@ -321,7 +313,8 @@ class ExternalFrameBufferTest : public ::testing::Test {
const vpx_codec_err_t res = const vpx_codec_err_t res =
decoder_->DecodeFrame(video_->cxdata(), video_->frame_size()); decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
CheckDecodedFrames(); CheckDecodedFrames();
if (res == VPX_CODEC_OK) video_->Next(); if (res == VPX_CODEC_OK)
video_->Next();
return res; return res;
} }
@ -329,13 +322,14 @@ class ExternalFrameBufferTest : public ::testing::Test {
for (; video_->cxdata() != NULL; video_->Next()) { for (; video_->cxdata() != NULL; video_->Next()) {
const vpx_codec_err_t res = const vpx_codec_err_t res =
decoder_->DecodeFrame(video_->cxdata(), video_->frame_size()); decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
if (res != VPX_CODEC_OK) return res; if (res != VPX_CODEC_OK)
return res;
CheckDecodedFrames(); CheckDecodedFrames();
} }
return VPX_CODEC_OK; return VPX_CODEC_OK;
} }
protected: private:
void CheckDecodedFrames() { void CheckDecodedFrames() {
libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData(); libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData();
const vpx_image_t *img = NULL; const vpx_image_t *img = NULL;
@ -351,25 +345,6 @@ class ExternalFrameBufferTest : public ::testing::Test {
int num_buffers_; int num_buffers_;
ExternalFrameBufferList fb_list_; ExternalFrameBufferList fb_list_;
}; };
class ExternalFrameBufferNonRefTest : public ExternalFrameBufferTest {
protected:
virtual void SetUp() {
video_ = new libvpx_test::WebMVideoSource(kVP9NonRefTestFile);
ASSERT_TRUE(video_ != NULL);
video_->Init();
video_->Begin();
vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
decoder_ = new libvpx_test::VP9Decoder(cfg, 0);
ASSERT_TRUE(decoder_ != NULL);
}
virtual void CheckFrameBufferRelease() {
TearDown();
ASSERT_EQ(0, fb_list_.num_used_buffers());
}
};
#endif // CONFIG_WEBM_IO #endif // CONFIG_WEBM_IO
// This test runs through the set of test vectors, and decodes them. // This test runs through the set of test vectors, and decodes them.
@ -379,6 +354,7 @@ class ExternalFrameBufferNonRefTest : public ExternalFrameBufferTest {
// Otherwise, the test failed. // Otherwise, the test failed.
TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) { TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) {
const std::string filename = GET_PARAM(kVideoNameParam); const std::string filename = GET_PARAM(kVideoNameParam);
libvpx_test::CompressedVideoSource *video = NULL;
// Number of buffers equals #VP9_MAXIMUM_REF_BUFFERS + // Number of buffers equals #VP9_MAXIMUM_REF_BUFFERS +
// #VPX_MAXIMUM_WORK_BUFFERS + four jitter buffers. // #VPX_MAXIMUM_WORK_BUFFERS + four jitter buffers.
@ -393,19 +369,18 @@ TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) {
#endif #endif
// Open compressed video file. // Open compressed video file.
testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
if (filename.substr(filename.length() - 3, 3) == "ivf") { if (filename.substr(filename.length() - 3, 3) == "ivf") {
video.reset(new libvpx_test::IVFVideoSource(filename)); video = new libvpx_test::IVFVideoSource(filename);
} else { } else {
#if CONFIG_WEBM_IO #if CONFIG_WEBM_IO
video.reset(new libvpx_test::WebMVideoSource(filename)); video = new libvpx_test::WebMVideoSource(filename);
#else #else
fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n", fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
filename.c_str()); filename.c_str());
return; return;
#endif #endif
} }
ASSERT_TRUE(video.get() != NULL); ASSERT_TRUE(video != NULL);
video->Init(); video->Init();
// Construct md5 file name. // Construct md5 file name.
@ -413,7 +388,8 @@ TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) {
OpenMD5File(md5_filename); OpenMD5File(md5_filename);
// Decode frame, and check the md5 matching. // Decode frame, and check the md5 matching.
ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); ASSERT_NO_FATAL_FAILURE(RunLoop(video));
delete video;
} }
#if CONFIG_WEBM_IO #if CONFIG_WEBM_IO
@ -422,8 +398,8 @@ TEST_F(ExternalFrameBufferTest, MinFrameBuffers) {
// #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS. // #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS.
const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS; const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
ASSERT_EQ(VPX_CODEC_OK, ASSERT_EQ(VPX_CODEC_OK,
SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer, SetFrameBufferFunctions(
release_vp9_frame_buffer)); num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames()); ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
} }
@ -434,8 +410,8 @@ TEST_F(ExternalFrameBufferTest, EightJitterBuffers) {
const int num_buffers = const int num_buffers =
VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS + jitter_buffers; VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS + jitter_buffers;
ASSERT_EQ(VPX_CODEC_OK, ASSERT_EQ(VPX_CODEC_OK,
SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer, SetFrameBufferFunctions(
release_vp9_frame_buffer)); num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames()); ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
} }
@ -445,11 +421,9 @@ TEST_F(ExternalFrameBufferTest, NotEnoughBuffers) {
// only use 5 frame buffers at one time. // only use 5 frame buffers at one time.
const int num_buffers = 2; const int num_buffers = 2;
ASSERT_EQ(VPX_CODEC_OK, ASSERT_EQ(VPX_CODEC_OK,
SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer, SetFrameBufferFunctions(
release_vp9_frame_buffer)); num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame()); ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame());
// Only run this on long clips. Decoding a very short clip will return
// VPX_CODEC_OK even with only 2 buffers.
ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeRemainingFrames()); ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeRemainingFrames());
} }
@ -472,17 +446,18 @@ TEST_F(ExternalFrameBufferTest, NullRealloc) {
TEST_F(ExternalFrameBufferTest, ReallocOneLessByte) { TEST_F(ExternalFrameBufferTest, ReallocOneLessByte) {
const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS; const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
ASSERT_EQ(VPX_CODEC_OK, SetFrameBufferFunctions( ASSERT_EQ(VPX_CODEC_OK,
num_buffers, get_vp9_one_less_byte_frame_buffer, SetFrameBufferFunctions(
release_vp9_frame_buffer)); num_buffers, get_vp9_one_less_byte_frame_buffer,
release_vp9_frame_buffer));
ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame()); ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame());
} }
TEST_F(ExternalFrameBufferTest, NullGetFunction) { TEST_F(ExternalFrameBufferTest, NullGetFunction) {
const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS; const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
ASSERT_EQ( ASSERT_EQ(VPX_CODEC_INVALID_PARAM,
VPX_CODEC_INVALID_PARAM, SetFrameBufferFunctions(num_buffers, NULL,
SetFrameBufferFunctions(num_buffers, NULL, release_vp9_frame_buffer)); release_vp9_frame_buffer));
} }
TEST_F(ExternalFrameBufferTest, NullReleaseFunction) { TEST_F(ExternalFrameBufferTest, NullReleaseFunction) {
@ -495,23 +470,13 @@ TEST_F(ExternalFrameBufferTest, SetAfterDecode) {
const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS; const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame()); ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame());
ASSERT_EQ(VPX_CODEC_ERROR, ASSERT_EQ(VPX_CODEC_ERROR,
SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer, SetFrameBufferFunctions(
release_vp9_frame_buffer)); num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
}
TEST_F(ExternalFrameBufferNonRefTest, ReleaseNonRefFrameBuffer) {
const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
ASSERT_EQ(VPX_CODEC_OK,
SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer,
release_vp9_frame_buffer));
ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
CheckFrameBufferRelease();
} }
#endif // CONFIG_WEBM_IO #endif // CONFIG_WEBM_IO
VP9_INSTANTIATE_TEST_CASE( VP9_INSTANTIATE_TEST_CASE(ExternalFrameBufferMD5Test,
ExternalFrameBufferMD5Test, ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
::testing::ValuesIn(libvpx_test::kVP9TestVectors, libvpx_test::kVP9TestVectors +
libvpx_test::kVP9TestVectors + libvpx_test::kNumVP9TestVectors));
libvpx_test::kNumVP9TestVectors));
} // namespace } // namespace

536
test/fdct4x4_test.cc Normal file
View File

@ -0,0 +1,536 @@
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "./vp9_rtcd.h"
#include "vp9/common/vp9_entropy.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
using libvpx_test::ACMRandom;
namespace {
const int kNumCoeffs = 16;
typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride);
typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
int tx_type);
typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type);
typedef std::tr1::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> Dct4x4Param;
typedef std::tr1::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht4x4Param;
void fdct4x4_ref(const int16_t *in, tran_low_t *out, int stride,
int tx_type) {
vp9_fdct4x4_c(in, out, stride);
}
void fht4x4_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
vp9_fht4x4_c(in, out, stride, tx_type);
}
void fwht4x4_ref(const int16_t *in, tran_low_t *out, int stride,
int tx_type) {
vp9_fwht4x4_c(in, out, stride);
}
#if CONFIG_VP9_HIGHBITDEPTH
void idct4x4_10(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct4x4_16_add_c(in, out, stride, 10);
}
void idct4x4_12(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct4x4_16_add_c(in, out, stride, 12);
}
void iht4x4_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht4x4_16_add_c(in, out, stride, tx_type, 10);
}
void iht4x4_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht4x4_16_add_c(in, out, stride, tx_type, 12);
}
void iwht4x4_10(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_iwht4x4_16_add_c(in, out, stride, 10);
}
void iwht4x4_12(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_iwht4x4_16_add_c(in, out, stride, 12);
}
#if HAVE_SSE2
void idct4x4_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct4x4_16_add_sse2(in, out, stride, 10);
}
void idct4x4_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct4x4_16_add_sse2(in, out, stride, 12);
}
#endif
#endif
class Trans4x4TestBase {
public:
virtual ~Trans4x4TestBase() {}
protected:
virtual void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) = 0;
virtual void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) = 0;
void RunAccuracyCheck(int limit) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
uint32_t max_error = 0;
int64_t total_error = 0;
const int count_test_block = 10000;
for (int i = 0; i < count_test_block; ++i) {
DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif
// Initialize a test block with input range [-255, 255].
for (int j = 0; j < kNumCoeffs; ++j) {
if (bit_depth_ == VPX_BITS_8) {
src[j] = rnd.Rand8();
dst[j] = rnd.Rand8();
test_input_block[j] = src[j] - dst[j];
#if CONFIG_VP9_HIGHBITDEPTH
} else {
src16[j] = rnd.Rand16() & mask_;
dst16[j] = rnd.Rand16() & mask_;
test_input_block[j] = src16[j] - dst16[j];
#endif
}
}
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
test_temp_block, pitch_));
if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH
} else {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block,
CONVERT_TO_BYTEPTR(dst16), pitch_));
#endif
}
for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH
const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else
const uint32_t diff = dst[j] - src[j];
#endif
const uint32_t error = diff * diff;
if (max_error < error)
max_error = error;
total_error += error;
}
}
EXPECT_GE(static_cast<uint32_t>(limit), max_error)
<< "Error: 4x4 FHT/IHT has an individual round trip error > "
<< limit;
EXPECT_GE(count_test_block * limit, total_error)
<< "Error: 4x4 FHT/IHT has average round trip error > " << limit
<< " per block";
}
void RunCoeffCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 5000;
DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j)
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
// The minimum quant value is 4.
for (int j = 0; j < kNumCoeffs; ++j)
EXPECT_EQ(output_block[j], output_ref_block[j]);
}
}
void RunMemCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 5000;
DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) {
input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_;
}
if (i == 0) {
for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = mask_;
} else if (i == 1) {
for (int j = 0; j < kNumCoeffs; ++j)
input_extreme_block[j] = -mask_;
}
fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
output_block, pitch_));
// The minimum quant value is 4.
for (int j = 0; j < kNumCoeffs; ++j) {
EXPECT_EQ(output_block[j], output_ref_block[j]);
EXPECT_GE(4 * DCT_MAX_VALUE << (bit_depth_ - 8), abs(output_block[j]))
<< "Error: 4x4 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
}
}
}
void RunInvAccuracyCheck(int limit) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000;
DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
#endif
for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) {
if (bit_depth_ == VPX_BITS_8) {
src[j] = rnd.Rand8();
dst[j] = rnd.Rand8();
in[j] = src[j] - dst[j];
#if CONFIG_VP9_HIGHBITDEPTH
} else {
src16[j] = rnd.Rand16() & mask_;
dst16[j] = rnd.Rand16() & mask_;
in[j] = src16[j] - dst16[j];
#endif
}
}
fwd_txfm_ref(in, coeff, pitch_, tx_type_);
if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH
} else {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
pitch_));
#endif
}
for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH
const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else
const uint32_t diff = dst[j] - src[j];
#endif
const uint32_t error = diff * diff;
EXPECT_GE(static_cast<uint32_t>(limit), error)
<< "Error: 4x4 IDCT has error " << error
<< " at index " << j;
}
}
}
int pitch_;
int tx_type_;
FhtFunc fwd_txfm_ref;
vpx_bit_depth_t bit_depth_;
int mask_;
};
class Trans4x4DCT
: public Trans4x4TestBase,
public ::testing::TestWithParam<Dct4x4Param> {
public:
virtual ~Trans4x4DCT() {}
virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2);
pitch_ = 4;
fwd_txfm_ref = fdct4x4_ref;
bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
fwd_txfm_(in, out, stride);
}
void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
inv_txfm_(out, dst, stride);
}
FdctFunc fwd_txfm_;
IdctFunc inv_txfm_;
};
TEST_P(Trans4x4DCT, AccuracyCheck) {
RunAccuracyCheck(1);
}
TEST_P(Trans4x4DCT, CoeffCheck) {
RunCoeffCheck();
}
TEST_P(Trans4x4DCT, MemCheck) {
RunMemCheck();
}
TEST_P(Trans4x4DCT, InvAccuracyCheck) {
RunInvAccuracyCheck(1);
}
class Trans4x4HT
: public Trans4x4TestBase,
public ::testing::TestWithParam<Ht4x4Param> {
public:
virtual ~Trans4x4HT() {}
virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2);
pitch_ = 4;
fwd_txfm_ref = fht4x4_ref;
bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
fwd_txfm_(in, out, stride, tx_type_);
}
void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
inv_txfm_(out, dst, stride, tx_type_);
}
FhtFunc fwd_txfm_;
IhtFunc inv_txfm_;
};
TEST_P(Trans4x4HT, AccuracyCheck) {
RunAccuracyCheck(1);
}
TEST_P(Trans4x4HT, CoeffCheck) {
RunCoeffCheck();
}
TEST_P(Trans4x4HT, MemCheck) {
RunMemCheck();
}
TEST_P(Trans4x4HT, InvAccuracyCheck) {
RunInvAccuracyCheck(1);
}
class Trans4x4WHT
: public Trans4x4TestBase,
public ::testing::TestWithParam<Dct4x4Param> {
public:
virtual ~Trans4x4WHT() {}
virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2);
pitch_ = 4;
fwd_txfm_ref = fwht4x4_ref;
bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1;
}
virtual void TearDown() { libvpx_test::ClearSystemState(); }
protected:
void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
fwd_txfm_(in, out, stride);
}
void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
inv_txfm_(out, dst, stride);
}
FdctFunc fwd_txfm_;
IdctFunc inv_txfm_;
};
TEST_P(Trans4x4WHT, AccuracyCheck) {
RunAccuracyCheck(0);
}
TEST_P(Trans4x4WHT, CoeffCheck) {
RunCoeffCheck();
}
TEST_P(Trans4x4WHT, MemCheck) {
RunMemCheck();
}
TEST_P(Trans4x4WHT, InvAccuracyCheck) {
RunInvAccuracyCheck(0);
}
using std::tr1::make_tuple;
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
C, Trans4x4DCT,
::testing::Values(
make_tuple(&vp9_highbd_fdct4x4_c, &idct4x4_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fdct4x4_c, &idct4x4_12, 0, VPX_BITS_12),
make_tuple(&vp9_fdct4x4_c, &vp9_idct4x4_16_add_c, 0, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
C, Trans4x4DCT,
::testing::Values(
make_tuple(&vp9_fdct4x4_c, &vp9_idct4x4_16_add_c, 0, VPX_BITS_8)));
#endif
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
C, Trans4x4HT,
::testing::Values(
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_10, 1, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_10, 2, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_10, 3, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_12, 0, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_12, 1, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_12, 2, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_c, &iht4x4_12, 3, VPX_BITS_12),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 3, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
C, Trans4x4HT,
::testing::Values(
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 3, VPX_BITS_8)));
#endif
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
C, Trans4x4WHT,
::testing::Values(
make_tuple(&vp9_highbd_fwht4x4_c, &iwht4x4_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fwht4x4_c, &iwht4x4_12, 0, VPX_BITS_12),
make_tuple(&vp9_fwht4x4_c, &vp9_iwht4x4_16_add_c, 0, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
C, Trans4x4WHT,
::testing::Values(
make_tuple(&vp9_fwht4x4_c, &vp9_iwht4x4_16_add_c, 0, VPX_BITS_8)));
#endif
#if HAVE_NEON_ASM && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
NEON, Trans4x4DCT,
::testing::Values(
make_tuple(&vp9_fdct4x4_c,
&vp9_idct4x4_16_add_neon, 0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P(
DISABLED_NEON, Trans4x4HT,
::testing::Values(
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 0, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 1, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 2, VPX_BITS_8),
make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 3, VPX_BITS_8)));
#endif
#if CONFIG_USE_X86INC && HAVE_MMX && !CONFIG_VP9_HIGHBITDEPTH && \
!CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
MMX, Trans4x4WHT,
::testing::Values(
make_tuple(&vp9_fwht4x4_mmx, &vp9_iwht4x4_16_add_c, 0, VPX_BITS_8)));
#endif
#if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
SSE2, Trans4x4DCT,
::testing::Values(
make_tuple(&vp9_fdct4x4_sse2,
&vp9_idct4x4_16_add_sse2, 0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P(
SSE2, Trans4x4HT,
::testing::Values(
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 0, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 1, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 2, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 3, VPX_BITS_8)));
#endif
#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(
SSE2, Trans4x4DCT,
::testing::Values(
make_tuple(&vp9_highbd_fdct4x4_c, &idct4x4_10_sse2, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fdct4x4_sse2, &idct4x4_10_sse2, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fdct4x4_c, &idct4x4_12_sse2, 0, VPX_BITS_12),
make_tuple(&vp9_highbd_fdct4x4_sse2, &idct4x4_12_sse2, 0, VPX_BITS_12),
make_tuple(&vp9_fdct4x4_sse2, &vp9_idct4x4_16_add_c, 0,
VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P(
SSE2, Trans4x4HT,
::testing::Values(
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_10, 1, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_10, 2, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_10, 3, VPX_BITS_10),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_12, 0, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_12, 1, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_12, 2, VPX_BITS_12),
make_tuple(&vp9_highbd_fht4x4_sse2, &iht4x4_12, 3, VPX_BITS_12),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_c, 3, VPX_BITS_8)));
#endif
} // namespace

View File

@ -13,48 +13,26 @@
#include <string.h> #include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vp9_rtcd.h"
#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h" #include "test/acm_random.h"
#include "test/clear_system_state.h" #include "test/clear_system_state.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
#include "test/util.h" #include "test/util.h"
#include "./vp9_rtcd.h"
#include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_scan.h"
#include "vpx/vpx_codec.h" #include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h" #include "vpx/vpx_integer.h"
#include "vpx_ports/mem.h"
using libvpx_test::ACMRandom;
namespace {
const int kNumCoeffs = 64; const int kNumCoeffs = 64;
const double kPi = 3.141592653589793238462643383279502884; const double kPi = 3.141592653589793238462643383279502884;
void reference_8x8_dct_1d(const double in[8], double out[8], int stride) {
const int kSignBiasMaxDiff255 = 1500;
const int kSignBiasMaxDiff15 = 10000;
typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride);
typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
int tx_type);
typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type);
typedef ::testing::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> Dct8x8Param;
typedef ::testing::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht8x8Param;
typedef ::testing::tuple<IdctFunc, IdctFunc, int, vpx_bit_depth_t> Idct8x8Param;
void reference_8x8_dct_1d(const double in[8], double out[8]) {
const double kInvSqrt2 = 0.707106781186547524400844362104; const double kInvSqrt2 = 0.707106781186547524400844362104;
for (int k = 0; k < 8; k++) { for (int k = 0; k < 8; k++) {
out[k] = 0.0; out[k] = 0.0;
for (int n = 0; n < 8; n++) { for (int n = 0; n < 8; n++)
out[k] += in[n] * cos(kPi * (2 * n + 1) * k / 16.0); out[k] += in[n] * cos(kPi * (2 * n + 1) * k / 16.0);
} if (k == 0)
if (k == 0) out[k] = out[k] * kInvSqrt2; out[k] = out[k] * kInvSqrt2;
} }
} }
@ -63,23 +41,40 @@ void reference_8x8_dct_2d(const int16_t input[kNumCoeffs],
// First transform columns // First transform columns
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
double temp_in[8], temp_out[8]; double temp_in[8], temp_out[8];
for (int j = 0; j < 8; ++j) temp_in[j] = input[j * 8 + i]; for (int j = 0; j < 8; ++j)
reference_8x8_dct_1d(temp_in, temp_out); temp_in[j] = input[j*8 + i];
for (int j = 0; j < 8; ++j) output[j * 8 + i] = temp_out[j]; reference_8x8_dct_1d(temp_in, temp_out, 1);
for (int j = 0; j < 8; ++j)
output[j * 8 + i] = temp_out[j];
} }
// Then transform rows // Then transform rows
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
double temp_in[8], temp_out[8]; double temp_in[8], temp_out[8];
for (int j = 0; j < 8; ++j) temp_in[j] = output[j + i * 8]; for (int j = 0; j < 8; ++j)
reference_8x8_dct_1d(temp_in, temp_out); temp_in[j] = output[j + i*8];
reference_8x8_dct_1d(temp_in, temp_out, 1);
// Scale by some magic number // Scale by some magic number
for (int j = 0; j < 8; ++j) output[j + i * 8] = temp_out[j] * 2; for (int j = 0; j < 8; ++j)
output[j + i * 8] = temp_out[j] * 2;
} }
} }
void fdct8x8_ref(const int16_t *in, tran_low_t *out, int stride, using libvpx_test::ACMRandom;
int /*tx_type*/) {
vpx_fdct8x8_c(in, out, stride); namespace {
typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride);
typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride);
typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
int tx_type);
typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
int tx_type);
typedef std::tr1::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> Dct8x8Param;
typedef std::tr1::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht8x8Param;
typedef std::tr1::tuple<IdctFunc, IdctFunc, int, vpx_bit_depth_t> Idct8x8Param;
void fdct8x8_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
vp9_fdct8x8_c(in, out, stride);
} }
void fht8x8_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) { void fht8x8_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
@ -88,48 +83,47 @@ void fht8x8_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
void idct8x8_10(const tran_low_t *in, uint8_t *out, int stride) { void idct8x8_10(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_64_add_c(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct8x8_64_add_c(in, out, stride, 10);
} }
void idct8x8_12(const tran_low_t *in, uint8_t *out, int stride) { void idct8x8_12(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_64_add_c(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct8x8_64_add_c(in, out, stride, 12);
} }
void iht8x8_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) { void iht8x8_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht8x8_64_add_c(in, CAST_TO_SHORTPTR(out), stride, tx_type, 10); vp9_highbd_iht8x8_64_add_c(in, out, stride, tx_type, 10);
} }
void iht8x8_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) { void iht8x8_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
vp9_highbd_iht8x8_64_add_c(in, CAST_TO_SHORTPTR(out), stride, tx_type, 12); vp9_highbd_iht8x8_64_add_c(in, out, stride, tx_type, 12);
}
void idct8x8_10_add_10_c(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct8x8_10_add_c(in, out, stride, 10);
}
void idct8x8_10_add_12_c(const tran_low_t *in, uint8_t *out, int stride) {
vp9_highbd_idct8x8_10_add_c(in, out, stride, 12);
} }
#if HAVE_SSE2 #if HAVE_SSE2
void idct8x8_10_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
void idct8x8_12_add_10_c(const tran_low_t *in, uint8_t *out, int stride) { vp9_highbd_idct8x8_10_add_sse2(in, out, stride, 10);
vpx_highbd_idct8x8_12_add_c(in, CAST_TO_SHORTPTR(out), stride, 10);
} }
void idct8x8_12_add_12_c(const tran_low_t *in, uint8_t *out, int stride) { void idct8x8_10_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_12_add_c(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct8x8_10_add_sse2(in, out, stride, 12);
}
void idct8x8_12_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_12_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 10);
}
void idct8x8_12_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_12_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 12);
} }
void idct8x8_64_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct8x8_64_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_64_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 10); vp9_highbd_idct8x8_64_add_sse2(in, out, stride, 10);
} }
void idct8x8_64_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) { void idct8x8_64_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
vpx_highbd_idct8x8_64_add_sse2(in, CAST_TO_SHORTPTR(out), stride, 12); vp9_highbd_idct8x8_64_add_sse2(in, out, stride, 12);
} }
#endif // HAVE_SSE2 #endif
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
class FwdTrans8x8TestBase { class FwdTrans8x8TestBase {
public: public:
@ -141,8 +135,8 @@ class FwdTrans8x8TestBase {
void RunSignBiasCheck() { void RunSignBiasCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
DECLARE_ALIGNED(16, int16_t, test_input_block[64]); DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
DECLARE_ALIGNED(16, tran_low_t, test_output_block[64]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_output_block, 64);
int count_sign_block[64][2]; int count_sign_block[64][2];
const int count_test_block = 100000; const int count_test_block = 100000;
@ -150,62 +144,60 @@ class FwdTrans8x8TestBase {
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-255, 255]. // Initialize a test block with input range [-255, 255].
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j)
test_input_block[j] = ((rnd.Rand16() >> (16 - bit_depth_)) & mask_) - test_input_block[j] = ((rnd.Rand16() >> (16 - bit_depth_)) & mask_) -
((rnd.Rand16() >> (16 - bit_depth_)) & mask_); ((rnd.Rand16() >> (16 - bit_depth_)) & mask_);
}
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunFwdTxfm(test_input_block, test_output_block, pitch_)); RunFwdTxfm(test_input_block, test_output_block, pitch_));
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j) {
if (test_output_block[j] < 0) { if (test_output_block[j] < 0)
++count_sign_block[j][0]; ++count_sign_block[j][0];
} else if (test_output_block[j] > 0) { else if (test_output_block[j] > 0)
++count_sign_block[j][1]; ++count_sign_block[j][1];
}
} }
} }
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j) {
const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]); const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
const int max_diff = kSignBiasMaxDiff255; const int max_diff = 1125;
EXPECT_LT(diff, max_diff << (bit_depth_ - 8)) EXPECT_LT(diff, max_diff << (bit_depth_ - 8))
<< "Error: 8x8 FDCT/FHT has a sign bias > " << "Error: 8x8 FDCT/FHT has a sign bias > "
<< 1. * max_diff / count_test_block * 100 << "%" << 1. * max_diff / count_test_block * 100 << "%"
<< " for input range [-255, 255] at index " << j << " for input range [-255, 255] at index " << j
<< " count0: " << count_sign_block[j][0] << " count0: " << count_sign_block[j][0]
<< " count1: " << count_sign_block[j][1] << " diff: " << diff; << " count1: " << count_sign_block[j][1]
<< " diff: " << diff;
} }
memset(count_sign_block, 0, sizeof(count_sign_block)); memset(count_sign_block, 0, sizeof(count_sign_block));
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
// Initialize a test block with input range [-mask_ / 16, mask_ / 16]. // Initialize a test block with input range [-mask_/16, mask_/16].
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j)
test_input_block[j] = test_input_block[j] = ((rnd.Rand16() & mask_) >> 4) -
((rnd.Rand16() & mask_) >> 4) - ((rnd.Rand16() & mask_) >> 4); ((rnd.Rand16() & mask_) >> 4);
}
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunFwdTxfm(test_input_block, test_output_block, pitch_)); RunFwdTxfm(test_input_block, test_output_block, pitch_));
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j) {
if (test_output_block[j] < 0) { if (test_output_block[j] < 0)
++count_sign_block[j][0]; ++count_sign_block[j][0];
} else if (test_output_block[j] > 0) { else if (test_output_block[j] > 0)
++count_sign_block[j][1]; ++count_sign_block[j][1];
}
} }
} }
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j) {
const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]); const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
const int max_diff = kSignBiasMaxDiff15; const int max_diff = 10000;
EXPECT_LT(diff, max_diff << (bit_depth_ - 8)) EXPECT_LT(diff, max_diff << (bit_depth_ - 8))
<< "Error: 8x8 FDCT/FHT has a sign bias > " << "Error: 4x4 FDCT/FHT has a sign bias > "
<< 1. * max_diff / count_test_block * 100 << "%" << 1. * max_diff / count_test_block * 100 << "%"
<< " for input range [-15, 15] at index " << j << " for input range [-15, 15] at index " << j
<< " count0: " << count_sign_block[j][0] << " count0: " << count_sign_block[j][0]
<< " count1: " << count_sign_block[j][1] << " diff: " << diff; << " count1: " << count_sign_block[j][1]
<< " diff: " << diff;
} }
} }
@ -214,13 +206,13 @@ class FwdTrans8x8TestBase {
int max_error = 0; int max_error = 0;
int total_error = 0; int total_error = 0;
const int count_test_block = 100000; const int count_test_block = 100000;
DECLARE_ALIGNED(16, int16_t, test_input_block[64]); DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
DECLARE_ALIGNED(16, tran_low_t, test_temp_block[64]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, 64);
DECLARE_ALIGNED(16, uint8_t, dst[64]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, 64);
DECLARE_ALIGNED(16, uint8_t, src[64]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, 64);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[64]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, 64);
DECLARE_ALIGNED(16, uint16_t, src16[64]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, 64);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
@ -242,22 +234,23 @@ class FwdTrans8x8TestBase {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunFwdTxfm(test_input_block, test_temp_block, pitch_)); RunFwdTxfm(test_input_block, test_temp_block, pitch_));
for (int j = 0; j < 64; ++j) { for (int j = 0; j < 64; ++j) {
if (test_temp_block[j] > 0) { if (test_temp_block[j] > 0) {
test_temp_block[j] += 2; test_temp_block[j] += 2;
test_temp_block[j] /= 4; test_temp_block[j] /= 4;
test_temp_block[j] *= 4; test_temp_block[j] *= 4;
} else { } else {
test_temp_block[j] -= 2; test_temp_block[j] -= 2;
test_temp_block[j] /= 4; test_temp_block[j] /= 4;
test_temp_block[j] *= 4; test_temp_block[j] *= 4;
} }
} }
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_)); ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, CAST_TO_BYTEPTR(dst16), pitch_)); RunInvTxfm(test_temp_block, CONVERT_TO_BYTEPTR(dst16), pitch_));
#endif #endif
} }
@ -269,18 +262,19 @@ class FwdTrans8x8TestBase {
const int diff = dst[j] - src[j]; const int diff = dst[j] - src[j];
#endif #endif
const int error = diff * diff; const int error = diff * diff;
if (max_error < error) max_error = error; if (max_error < error)
max_error = error;
total_error += error; total_error += error;
} }
} }
EXPECT_GE(1 << 2 * (bit_depth_ - 8), max_error) EXPECT_GE(1 << 2 * (bit_depth_ - 8), max_error)
<< "Error: 8x8 FDCT/IDCT or FHT/IHT has an individual" << "Error: 8x8 FDCT/IDCT or FHT/IHT has an individual"
<< " roundtrip error > 1"; << " roundtrip error > 1";
EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8))/5, total_error)
<< "Error: 8x8 FDCT/IDCT or FHT/IHT has average roundtrip " << "Error: 8x8 FDCT/IDCT or FHT/IHT has average roundtrip "
<< "error > 1/5 per block"; << "error > 1/5 per block";
} }
void RunExtremalCheck() { void RunExtremalCheck() {
@ -289,14 +283,14 @@ class FwdTrans8x8TestBase {
int total_error = 0; int total_error = 0;
int total_coeff_error = 0; int total_coeff_error = 0;
const int count_test_block = 100000; const int count_test_block = 100000;
DECLARE_ALIGNED(16, int16_t, test_input_block[64]); DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
DECLARE_ALIGNED(16, tran_low_t, test_temp_block[64]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, 64);
DECLARE_ALIGNED(16, tran_low_t, ref_temp_block[64]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, ref_temp_block, 64);
DECLARE_ALIGNED(16, uint8_t, dst[64]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, 64);
DECLARE_ALIGNED(16, uint8_t, src[64]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, 64);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[64]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, 64);
DECLARE_ALIGNED(16, uint16_t, src16[64]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, 64);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
@ -336,11 +330,12 @@ class FwdTrans8x8TestBase {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
fwd_txfm_ref(test_input_block, ref_temp_block, pitch_, tx_type_)); fwd_txfm_ref(test_input_block, ref_temp_block, pitch_, tx_type_));
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_)); ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(
RunInvTxfm(test_temp_block, CAST_TO_BYTEPTR(dst16), pitch_)); RunInvTxfm(test_temp_block, CONVERT_TO_BYTEPTR(dst16), pitch_));
#endif #endif
} }
@ -352,7 +347,8 @@ class FwdTrans8x8TestBase {
const int diff = dst[j] - src[j]; const int diff = dst[j] - src[j];
#endif #endif
const int error = diff * diff; const int error = diff * diff;
if (max_error < error) max_error = error; if (max_error < error)
max_error = error;
total_error += error; total_error += error;
const int coeff_diff = test_temp_block[j] - ref_temp_block[j]; const int coeff_diff = test_temp_block[j] - ref_temp_block[j];
@ -363,7 +359,7 @@ class FwdTrans8x8TestBase {
<< "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has" << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has"
<< "an individual roundtrip error > 1"; << "an individual roundtrip error > 1";
EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8))/5, total_error)
<< "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has average" << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has average"
<< " roundtrip error > 1/5 per block"; << " roundtrip error > 1/5 per block";
@ -376,13 +372,13 @@ class FwdTrans8x8TestBase {
void RunInvAccuracyCheck() { void RunInvAccuracyCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, in[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
#endif #endif
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
@ -404,29 +400,29 @@ class FwdTrans8x8TestBase {
} }
reference_8x8_dct_2d(in, out_r); reference_8x8_dct_2d(in, out_r);
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
coeff[j] = static_cast<tran_low_t>(round(out_r[j])); coeff[j] = static_cast<tran_low_t>(round(out_r[j]));
}
if (bit_depth_ == VPX_BITS_8) { if (bit_depth_ == VPX_BITS_8) {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_)); pitch_));
#endif #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
const int diff = const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
#else #else
const int diff = dst[j] - src[j]; const uint32_t diff = dst[j] - src[j];
#endif #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
EXPECT_GE(1u << 2 * (bit_depth_ - 8), error) EXPECT_GE(1u << 2 * (bit_depth_ - 8), error)
<< "Error: 8x8 IDCT has error " << error << " at index " << j; << "Error: 8x8 IDCT has error " << error
<< " at index " << j;
} }
} }
} }
@ -434,43 +430,42 @@ class FwdTrans8x8TestBase {
void RunFwdAccuracyCheck() { void RunFwdAccuracyCheck() {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 1000; const int count_test_block = 1000;
DECLARE_ALIGNED(16, int16_t, in[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, coeff_r[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff_r, kNumCoeffs);
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
for (int i = 0; i < count_test_block; ++i) { for (int i = 0; i < count_test_block; ++i) {
double out_r[kNumCoeffs]; double out_r[kNumCoeffs];
// Initialize a test block with input range [-mask_, mask_]. // Initialize a test block with input range [-mask_, mask_].
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
in[j] = rnd.Rand8() % 2 == 0 ? mask_ : -mask_; in[j] = rnd.Rand8() % 2 == 0 ? mask_ : -mask_;
}
RunFwdTxfm(in, coeff, pitch_); RunFwdTxfm(in, coeff, pitch_);
reference_8x8_dct_2d(in, out_r); reference_8x8_dct_2d(in, out_r);
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j)
coeff_r[j] = static_cast<tran_low_t>(round(out_r[j])); coeff_r[j] = static_cast<tran_low_t>(round(out_r[j]));
}
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
const int32_t diff = coeff[j] - coeff_r[j]; const uint32_t diff = coeff[j] - coeff_r[j];
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
EXPECT_GE(9u << 2 * (bit_depth_ - 8), error) EXPECT_GE(9u << 2 * (bit_depth_ - 8), error)
<< "Error: 8x8 DCT has error " << error << " at index " << j; << "Error: 8x8 DCT has error " << error
<< " at index " << j;
} }
} }
} }
void CompareInvReference(IdctFunc ref_txfm, int thresh) { void CompareInvReference(IdctFunc ref_txfm, int thresh) {
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 10000; const int count_test_block = 10000;
const int eob = 12; const int eob = 12;
DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); DECLARE_ALIGNED_ARRAY(16, uint16_t, ref16, kNumCoeffs);
#endif #endif
const int16_t *scan = vp9_default_scan_orders[TX_8X8].scan; const int16_t *scan = vp9_default_scan_orders[TX_8X8].scan;
@ -478,7 +473,7 @@ class FwdTrans8x8TestBase {
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
if (j < eob) { if (j < eob) {
// Random values less than the threshold, either positive or negative // Random values less than the threshold, either positive or negative
coeff[scan[j]] = rnd(thresh) * (1 - 2 * (i % 2)); coeff[scan[j]] = rnd(thresh) * (1-2*(i%2));
} else { } else {
coeff[scan[j]] = 0; coeff[scan[j]] = 0;
} }
@ -497,22 +492,23 @@ class FwdTrans8x8TestBase {
ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_)); ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
} else { } else {
ref_txfm(coeff, CAST_TO_BYTEPTR(ref16), pitch_); ref_txfm(coeff, CONVERT_TO_BYTEPTR(ref16), pitch_);
ASM_REGISTER_STATE_CHECK( ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_)); pitch_));
#endif #endif
} }
for (int j = 0; j < kNumCoeffs; ++j) { for (int j = 0; j < kNumCoeffs; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
const int diff = const uint32_t diff =
bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j]; bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j];
#else #else
const int diff = dst[j] - ref[j]; const uint32_t diff = dst[j] - ref[j];
#endif #endif
const uint32_t error = diff * diff; const uint32_t error = diff * diff;
EXPECT_EQ(0u, error) EXPECT_EQ(0u, error)
<< "Error: 8x8 IDCT has error " << error << " at index " << j; << "Error: 8x8 IDCT has error " << error
<< " at index " << j;
} }
} }
} }
@ -523,16 +519,17 @@ class FwdTrans8x8TestBase {
int mask_; int mask_;
}; };
class FwdTrans8x8DCT : public FwdTrans8x8TestBase, class FwdTrans8x8DCT
public ::testing::TestWithParam<Dct8x8Param> { : public FwdTrans8x8TestBase,
public ::testing::TestWithParam<Dct8x8Param> {
public: public:
virtual ~FwdTrans8x8DCT() {} virtual ~FwdTrans8x8DCT() {}
virtual void SetUp() { virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0); fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2); tx_type_ = GET_PARAM(2);
pitch_ = 8; pitch_ = 8;
fwd_txfm_ref = fdct8x8_ref; fwd_txfm_ref = fdct8x8_ref;
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
@ -552,26 +549,37 @@ class FwdTrans8x8DCT : public FwdTrans8x8TestBase,
IdctFunc inv_txfm_; IdctFunc inv_txfm_;
}; };
TEST_P(FwdTrans8x8DCT, SignBiasCheck) { RunSignBiasCheck(); } TEST_P(FwdTrans8x8DCT, SignBiasCheck) {
RunSignBiasCheck();
}
TEST_P(FwdTrans8x8DCT, RoundTripErrorCheck) { RunRoundTripErrorCheck(); } TEST_P(FwdTrans8x8DCT, RoundTripErrorCheck) {
RunRoundTripErrorCheck();
}
TEST_P(FwdTrans8x8DCT, ExtremalCheck) { RunExtremalCheck(); } TEST_P(FwdTrans8x8DCT, ExtremalCheck) {
RunExtremalCheck();
}
TEST_P(FwdTrans8x8DCT, FwdAccuracyCheck) { RunFwdAccuracyCheck(); } TEST_P(FwdTrans8x8DCT, FwdAccuracyCheck) {
RunFwdAccuracyCheck();
}
TEST_P(FwdTrans8x8DCT, InvAccuracyCheck) { RunInvAccuracyCheck(); } TEST_P(FwdTrans8x8DCT, InvAccuracyCheck) {
RunInvAccuracyCheck();
}
class FwdTrans8x8HT : public FwdTrans8x8TestBase, class FwdTrans8x8HT
public ::testing::TestWithParam<Ht8x8Param> { : public FwdTrans8x8TestBase,
public ::testing::TestWithParam<Ht8x8Param> {
public: public:
virtual ~FwdTrans8x8HT() {} virtual ~FwdTrans8x8HT() {}
virtual void SetUp() { virtual void SetUp() {
fwd_txfm_ = GET_PARAM(0); fwd_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
tx_type_ = GET_PARAM(2); tx_type_ = GET_PARAM(2);
pitch_ = 8; pitch_ = 8;
fwd_txfm_ref = fht8x8_ref; fwd_txfm_ref = fht8x8_ref;
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
@ -591,22 +599,29 @@ class FwdTrans8x8HT : public FwdTrans8x8TestBase,
IhtFunc inv_txfm_; IhtFunc inv_txfm_;
}; };
TEST_P(FwdTrans8x8HT, SignBiasCheck) { RunSignBiasCheck(); } TEST_P(FwdTrans8x8HT, SignBiasCheck) {
RunSignBiasCheck();
}
TEST_P(FwdTrans8x8HT, RoundTripErrorCheck) { RunRoundTripErrorCheck(); } TEST_P(FwdTrans8x8HT, RoundTripErrorCheck) {
RunRoundTripErrorCheck();
}
TEST_P(FwdTrans8x8HT, ExtremalCheck) { RunExtremalCheck(); } TEST_P(FwdTrans8x8HT, ExtremalCheck) {
RunExtremalCheck();
}
class InvTrans8x8DCT : public FwdTrans8x8TestBase, class InvTrans8x8DCT
public ::testing::TestWithParam<Idct8x8Param> { : public FwdTrans8x8TestBase,
public ::testing::TestWithParam<Idct8x8Param> {
public: public:
virtual ~InvTrans8x8DCT() {} virtual ~InvTrans8x8DCT() {}
virtual void SetUp() { virtual void SetUp() {
ref_txfm_ = GET_PARAM(0); ref_txfm_ = GET_PARAM(0);
inv_txfm_ = GET_PARAM(1); inv_txfm_ = GET_PARAM(1);
thresh_ = GET_PARAM(2); thresh_ = GET_PARAM(2);
pitch_ = 8; pitch_ = 8;
bit_depth_ = GET_PARAM(3); bit_depth_ = GET_PARAM(3);
mask_ = (1 << bit_depth_) - 1; mask_ = (1 << bit_depth_) - 1;
} }
@ -617,7 +632,7 @@ class InvTrans8x8DCT : public FwdTrans8x8TestBase,
void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) {
inv_txfm_(out, dst, stride); inv_txfm_(out, dst, stride);
} }
void RunFwdTxfm(int16_t * /*out*/, tran_low_t * /*dst*/, int /*stride*/) {} void RunFwdTxfm(int16_t *out, tran_low_t *dst, int stride) {}
IdctFunc ref_txfm_; IdctFunc ref_txfm_;
IdctFunc inv_txfm_; IdctFunc inv_txfm_;
@ -628,27 +643,26 @@ TEST_P(InvTrans8x8DCT, CompareReference) {
CompareInvReference(ref_txfm_, thresh_); CompareInvReference(ref_txfm_, thresh_);
} }
using ::testing::make_tuple; using std::tr1::make_tuple;
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
C, FwdTrans8x8DCT, C, FwdTrans8x8DCT,
::testing::Values( ::testing::Values(
make_tuple(&vpx_fdct8x8_c, &vpx_idct8x8_64_add_c, 0, VPX_BITS_8), make_tuple(&vp9_highbd_fdct8x8_c, &idct8x8_10, 0, VPX_BITS_10),
make_tuple(&vpx_highbd_fdct8x8_c, &idct8x8_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fdct8x8_c, &idct8x8_12, 0, VPX_BITS_12),
make_tuple(&vpx_highbd_fdct8x8_c, &idct8x8_12, 0, VPX_BITS_12))); make_tuple(&vp9_fdct8x8_c, &vp9_idct8x8_64_add_c, 0, VPX_BITS_8)));
#else #else
INSTANTIATE_TEST_CASE_P(C, FwdTrans8x8DCT, INSTANTIATE_TEST_CASE_P(
::testing::Values(make_tuple(&vpx_fdct8x8_c, C, FwdTrans8x8DCT,
&vpx_idct8x8_64_add_c, 0, ::testing::Values(
VPX_BITS_8))); make_tuple(&vp9_fdct8x8_c, &vp9_idct8x8_64_add_c, 0, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
#if CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
C, FwdTrans8x8HT, C, FwdTrans8x8HT,
::testing::Values( ::testing::Values(
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 0, VPX_BITS_10), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 0, VPX_BITS_10),
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 1, VPX_BITS_10), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 1, VPX_BITS_10),
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 2, VPX_BITS_10), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_10, 2, VPX_BITS_10),
@ -657,6 +671,7 @@ INSTANTIATE_TEST_CASE_P(
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 1, VPX_BITS_12), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 1, VPX_BITS_12),
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 2, VPX_BITS_12), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 2, VPX_BITS_12),
make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 3, VPX_BITS_12), make_tuple(&vp9_highbd_fht8x8_c, &iht8x8_12, 3, VPX_BITS_12),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 0, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 1, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 2, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 3, VPX_BITS_8))); make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 3, VPX_BITS_8)));
@ -668,30 +683,29 @@ INSTANTIATE_TEST_CASE_P(
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 1, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 1, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 2, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 2, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 3, VPX_BITS_8))); make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_c, 3, VPX_BITS_8)));
#endif // CONFIG_VP9_HIGHBITDEPTH #endif
#if HAVE_NEON && !CONFIG_EMULATE_HARDWARE #if HAVE_NEON_ASM && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(NEON, FwdTrans8x8DCT,
::testing::Values(make_tuple(&vpx_fdct8x8_neon,
&vpx_idct8x8_64_add_neon,
0, VPX_BITS_8)));
#if !CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, FwdTrans8x8HT, NEON, FwdTrans8x8DCT,
::testing::Values(
make_tuple(&vp9_fdct8x8_neon, &vp9_idct8x8_64_add_neon, 0,
VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P(
DISABLED_NEON, FwdTrans8x8HT,
::testing::Values( ::testing::Values(
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 0, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 0, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 1, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 1, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 2, VPX_BITS_8), make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 2, VPX_BITS_8),
make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 3, VPX_BITS_8))); make_tuple(&vp9_fht8x8_c, &vp9_iht8x8_64_add_neon, 3, VPX_BITS_8)));
#endif // !CONFIG_VP9_HIGHBITDEPTH #endif
#endif // HAVE_NEON && !CONFIG_EMULATE_HARDWARE
#if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(SSE2, FwdTrans8x8DCT, INSTANTIATE_TEST_CASE_P(
::testing::Values(make_tuple(&vpx_fdct8x8_sse2, SSE2, FwdTrans8x8DCT,
&vpx_idct8x8_64_add_sse2, ::testing::Values(
0, VPX_BITS_8))); make_tuple(&vp9_fdct8x8_sse2, &vp9_idct8x8_64_add_sse2, 0,
VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, FwdTrans8x8HT, SSE2, FwdTrans8x8HT,
::testing::Values( ::testing::Values(
@ -699,21 +713,22 @@ INSTANTIATE_TEST_CASE_P(
make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 1, VPX_BITS_8), make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 1, VPX_BITS_8),
make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 2, VPX_BITS_8), make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 2, VPX_BITS_8),
make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 3, VPX_BITS_8))); make_tuple(&vp9_fht8x8_sse2, &vp9_iht8x8_64_add_sse2, 3, VPX_BITS_8)));
#endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #endif
#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, FwdTrans8x8DCT, SSE2, FwdTrans8x8DCT,
::testing::Values(make_tuple(&vpx_fdct8x8_sse2, &vpx_idct8x8_64_add_c, 0, ::testing::Values(
VPX_BITS_8), make_tuple(&vp9_highbd_fdct8x8_c,
make_tuple(&vpx_highbd_fdct8x8_c, &idct8x8_64_add_10_sse2, &idct8x8_64_add_10_sse2, 12, VPX_BITS_10),
12, VPX_BITS_10), make_tuple(&vp9_highbd_fdct8x8_sse2,
make_tuple(&vpx_highbd_fdct8x8_sse2, &idct8x8_64_add_10_sse2, 12, VPX_BITS_10),
&idct8x8_64_add_10_sse2, 12, VPX_BITS_10), make_tuple(&vp9_highbd_fdct8x8_c,
make_tuple(&vpx_highbd_fdct8x8_c, &idct8x8_64_add_12_sse2, &idct8x8_64_add_12_sse2, 12, VPX_BITS_12),
12, VPX_BITS_12), make_tuple(&vp9_highbd_fdct8x8_sse2,
make_tuple(&vpx_highbd_fdct8x8_sse2, &idct8x8_64_add_12_sse2, 12, VPX_BITS_12),
&idct8x8_64_add_12_sse2, 12, VPX_BITS_12))); make_tuple(&vp9_fdct8x8_sse2, &vp9_idct8x8_64_add_c, 0, VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, FwdTrans8x8HT, SSE2, FwdTrans8x8HT,
@ -728,40 +743,23 @@ INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, InvTrans8x8DCT, SSE2, InvTrans8x8DCT,
::testing::Values( ::testing::Values(
make_tuple(&idct8x8_12_add_10_c, &idct8x8_12_add_10_sse2, 6225, make_tuple(&idct8x8_10_add_10_c,
VPX_BITS_10), &idct8x8_10_add_10_sse2, 6225, VPX_BITS_10),
make_tuple(&idct8x8_10, &idct8x8_64_add_10_sse2, 6225, VPX_BITS_10), make_tuple(&idct8x8_10,
make_tuple(&idct8x8_12_add_12_c, &idct8x8_12_add_12_sse2, 6225, &idct8x8_64_add_10_sse2, 6225, VPX_BITS_10),
VPX_BITS_12), make_tuple(&idct8x8_10_add_12_c,
make_tuple(&idct8x8_12, &idct8x8_64_add_12_sse2, 6225, VPX_BITS_12))); &idct8x8_10_add_12_sse2, 6225, VPX_BITS_12),
#endif // HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE make_tuple(&idct8x8_12,
&idct8x8_64_add_12_sse2, 6225, VPX_BITS_12)));
#endif
#if HAVE_SSSE3 && ARCH_X86_64 && !CONFIG_VP9_HIGHBITDEPTH && \ #if HAVE_SSSE3 && ARCH_X86_64 && !CONFIG_VP9_HIGHBITDEPTH && \
!CONFIG_EMULATE_HARDWARE !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(SSSE3, FwdTrans8x8DCT,
::testing::Values(make_tuple(&vpx_fdct8x8_ssse3,
&vpx_idct8x8_64_add_sse2,
0, VPX_BITS_8)));
#endif
#if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(MSA, FwdTrans8x8DCT,
::testing::Values(make_tuple(&vpx_fdct8x8_msa,
&vpx_idct8x8_64_add_msa, 0,
VPX_BITS_8)));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
MSA, FwdTrans8x8HT, SSSE3, FwdTrans8x8DCT,
::testing::Values( ::testing::Values(
make_tuple(&vp9_fht8x8_msa, &vp9_iht8x8_64_add_msa, 0, VPX_BITS_8), make_tuple(&vp9_fdct8x8_ssse3, &vp9_idct8x8_64_add_ssse3, 0,
make_tuple(&vp9_fht8x8_msa, &vp9_iht8x8_64_add_msa, 1, VPX_BITS_8), VPX_BITS_8)));
make_tuple(&vp9_fht8x8_msa, &vp9_iht8x8_64_add_msa, 2, VPX_BITS_8), #endif
make_tuple(&vp9_fht8x8_msa, &vp9_iht8x8_64_add_msa, 3, VPX_BITS_8)));
#endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
#if HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
INSTANTIATE_TEST_CASE_P(VSX, FwdTrans8x8DCT,
::testing::Values(make_tuple(&vpx_fdct8x8_c,
&vpx_idct8x8_64_add_vsx, 0,
VPX_BITS_8)));
#endif // HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
} // namespace } // namespace

View File

@ -13,11 +13,12 @@
namespace { namespace {
class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest, class VP9FrameSizeTestsLarge
public ::testing::Test { : public ::libvpx_test::EncoderTest,
public ::testing::Test {
protected: protected:
VP9FrameSizeTestsLarge() VP9FrameSizeTestsLarge() : EncoderTest(&::libvpx_test::kVP9),
: EncoderTest(&::libvpx_test::kVP9), expected_res_(VPX_CODEC_OK) {} expected_res_(VPX_CODEC_OK) {}
virtual ~VP9FrameSizeTestsLarge() {} virtual ~VP9FrameSizeTestsLarge() {}
virtual void SetUp() { virtual void SetUp() {
@ -26,7 +27,7 @@ class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest,
} }
virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
const libvpx_test::VideoSource & /*video*/, const libvpx_test::VideoSource& /*video*/,
libvpx_test::Decoder *decoder) { libvpx_test::Decoder *decoder) {
EXPECT_EQ(expected_res_, res_dec) << decoder->DecodeError(); EXPECT_EQ(expected_res_, res_dec) << decoder->DecodeError();
return !::testing::Test::HasFailure(); return !::testing::Test::HasFailure();
@ -66,14 +67,14 @@ TEST_F(VP9FrameSizeTestsLarge, ValidSizes) {
expected_res_ = VPX_CODEC_OK; expected_res_ = VPX_CODEC_OK;
ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
#else #else
// This test produces a pretty large single frame allocation, (roughly // This test produces a pretty large single frame allocation, (roughly
// 25 megabits). The encoder allocates a good number of these frames // 25 megabits). The encoder allocates a good number of these frames
// one for each lag in frames (for 2 pass), and then one for each possible // one for each lag in frames (for 2 pass), and then one for each possible
// reference buffer (8) - we can end up with up to 30 buffers of roughly this // reference buffer (8) - we can end up with up to 30 buffers of roughly this
// size or almost 1 gig of memory. // size or almost 1 gig of memory.
// In total the allocations will exceed 2GiB which may cause a failure with // In total the allocations will exceed 2GiB which may cause a failure with
// mingw + wine, use a smaller size in that case. // mingw + wine, use a smaller size in that case.
#if defined(_WIN32) && !defined(_WIN64) || defined(__OS2__) #if defined(_WIN32) && !defined(_WIN64)
video.SetSize(4096, 3072); video.SetSize(4096, 3072);
#else #else
video.SetSize(4096, 4096); video.SetSize(4096, 4096);

View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <algorithm>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./vpx_dsp_rtcd.h"
#include "vpx_ports/vpx_timer.h"
#include "test/acm_random.h"
#include "test/register_state_check.h"
namespace {
using ::libvpx_test::ACMRandom;
typedef void (*HadamardFunc)(const int16_t *a, ptrdiff_t a_stride,
tran_low_t *b);
void hadamard_loop(const int16_t *a, int a_stride, int16_t *out) {
int16_t b[8];
for (int i = 0; i < 8; i += 2) {
b[i + 0] = a[i * a_stride] + a[(i + 1) * a_stride];
b[i + 1] = a[i * a_stride] - a[(i + 1) * a_stride];
}
int16_t c[8];
for (int i = 0; i < 8; i += 4) {
c[i + 0] = b[i + 0] + b[i + 2];
c[i + 1] = b[i + 1] + b[i + 3];
c[i + 2] = b[i + 0] - b[i + 2];
c[i + 3] = b[i + 1] - b[i + 3];
}
out[0] = c[0] + c[4];
out[7] = c[1] + c[5];
out[3] = c[2] + c[6];
out[4] = c[3] + c[7];
out[2] = c[0] - c[4];
out[6] = c[1] - c[5];
out[1] = c[2] - c[6];
out[5] = c[3] - c[7];
}
void reference_hadamard8x8(const int16_t *a, int a_stride, tran_low_t *b) {
int16_t buf[64];
int16_t buf2[64];
for (int i = 0; i < 8; ++i) hadamard_loop(a + i, a_stride, buf + i * 8);
for (int i = 0; i < 8; ++i) hadamard_loop(buf + i, 8, buf2 + i * 8);
for (int i = 0; i < 64; ++i) b[i] = (tran_low_t)buf2[i];
}
void reference_hadamard16x16(const int16_t *a, int a_stride, tran_low_t *b) {
/* The source is a 16x16 block. The destination is rearranged to 8x32.
* Input is 9 bit. */
reference_hadamard8x8(a + 0 + 0 * a_stride, a_stride, b + 0);
reference_hadamard8x8(a + 8 + 0 * a_stride, a_stride, b + 64);
reference_hadamard8x8(a + 0 + 8 * a_stride, a_stride, b + 128);
reference_hadamard8x8(a + 8 + 8 * a_stride, a_stride, b + 192);
/* Overlay the 8x8 blocks and combine. */
for (int i = 0; i < 64; ++i) {
/* 8x8 steps the range up to 15 bits. */
const tran_low_t a0 = b[0];
const tran_low_t a1 = b[64];
const tran_low_t a2 = b[128];
const tran_low_t a3 = b[192];
/* Prevent the result from escaping int16_t. */
const tran_low_t b0 = (a0 + a1) >> 1;
const tran_low_t b1 = (a0 - a1) >> 1;
const tran_low_t b2 = (a2 + a3) >> 1;
const tran_low_t b3 = (a2 - a3) >> 1;
/* Store a 16 bit value. */
b[0] = b0 + b2;
b[64] = b1 + b3;
b[128] = b0 - b2;
b[192] = b1 - b3;
++b;
}
}
class HadamardTestBase : public ::testing::TestWithParam<HadamardFunc> {
public:
virtual void SetUp() {
h_func_ = GetParam();
rnd_.Reset(ACMRandom::DeterministicSeed());
}
protected:
HadamardFunc h_func_;
ACMRandom rnd_;
};
void HadamardSpeedTest(const char *name, HadamardFunc const func,
const int16_t *input, int stride, tran_low_t *output,
int times) {
int i;
vpx_usec_timer timer;
vpx_usec_timer_start(&timer);
for (i = 0; i < times; ++i) {
func(input, stride, output);
}
vpx_usec_timer_mark(&timer);
const int elapsed_time = static_cast<int>(vpx_usec_timer_elapsed(&timer));
printf("%s[%12d runs]: %d us\n", name, times, elapsed_time);
}
class Hadamard8x8Test : public HadamardTestBase {};
void HadamardSpeedTest8x8(HadamardFunc const func, int times) {
DECLARE_ALIGNED(16, int16_t, input[64]);
DECLARE_ALIGNED(16, tran_low_t, output[64]);
memset(input, 1, sizeof(input));
HadamardSpeedTest("Hadamard8x8", func, input, 8, output, times);
}
TEST_P(Hadamard8x8Test, CompareReferenceRandom) {
DECLARE_ALIGNED(16, int16_t, a[64]);
DECLARE_ALIGNED(16, tran_low_t, b[64]);
tran_low_t b_ref[64];
for (int i = 0; i < 64; ++i) {
a[i] = rnd_.Rand9Signed();
}
memset(b, 0, sizeof(b));
memset(b_ref, 0, sizeof(b_ref));
reference_hadamard8x8(a, 8, b_ref);
ASM_REGISTER_STATE_CHECK(h_func_(a, 8, b));
// The order of the output is not important. Sort before checking.
std::sort(b, b + 64);
std::sort(b_ref, b_ref + 64);
EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
}
TEST_P(Hadamard8x8Test, VaryStride) {
DECLARE_ALIGNED(16, int16_t, a[64 * 8]);
DECLARE_ALIGNED(16, tran_low_t, b[64]);
tran_low_t b_ref[64];
for (int i = 0; i < 64 * 8; ++i) {
a[i] = rnd_.Rand9Signed();
}
for (int i = 8; i < 64; i += 8) {
memset(b, 0, sizeof(b));
memset(b_ref, 0, sizeof(b_ref));
reference_hadamard8x8(a, i, b_ref);
ASM_REGISTER_STATE_CHECK(h_func_(a, i, b));
// The order of the output is not important. Sort before checking.
std::sort(b, b + 64);
std::sort(b_ref, b_ref + 64);
EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
}
}
TEST_P(Hadamard8x8Test, DISABLED_Speed) {
HadamardSpeedTest8x8(h_func_, 10);
HadamardSpeedTest8x8(h_func_, 10000);
HadamardSpeedTest8x8(h_func_, 10000000);
}
INSTANTIATE_TEST_CASE_P(C, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_c));
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(SSE2, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_sse2));
#endif // HAVE_SSE2
#if HAVE_SSSE3 && ARCH_X86_64
INSTANTIATE_TEST_CASE_P(SSSE3, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_ssse3));
#endif // HAVE_SSSE3 && ARCH_X86_64
#if HAVE_NEON
INSTANTIATE_TEST_CASE_P(NEON, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_neon));
#endif // HAVE_NEON
// TODO(jingning): Remove highbitdepth flag when the SIMD functions are
// in place and turn on the unit test.
#if !CONFIG_VP9_HIGHBITDEPTH
#if HAVE_MSA
INSTANTIATE_TEST_CASE_P(MSA, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_msa));
#endif // HAVE_MSA
#endif // !CONFIG_VP9_HIGHBITDEPTH
#if HAVE_VSX
INSTANTIATE_TEST_CASE_P(VSX, Hadamard8x8Test,
::testing::Values(&vpx_hadamard_8x8_vsx));
#endif // HAVE_VSX
class Hadamard16x16Test : public HadamardTestBase {};
void HadamardSpeedTest16x16(HadamardFunc const func, int times) {
DECLARE_ALIGNED(16, int16_t, input[256]);
DECLARE_ALIGNED(16, tran_low_t, output[256]);
memset(input, 1, sizeof(input));
HadamardSpeedTest("Hadamard16x16", func, input, 16, output, times);
}
TEST_P(Hadamard16x16Test, CompareReferenceRandom) {
DECLARE_ALIGNED(16, int16_t, a[16 * 16]);
DECLARE_ALIGNED(16, tran_low_t, b[16 * 16]);
tran_low_t b_ref[16 * 16];
for (int i = 0; i < 16 * 16; ++i) {
a[i] = rnd_.Rand9Signed();
}
memset(b, 0, sizeof(b));
memset(b_ref, 0, sizeof(b_ref));
reference_hadamard16x16(a, 16, b_ref);
ASM_REGISTER_STATE_CHECK(h_func_(a, 16, b));
// The order of the output is not important. Sort before checking.
std::sort(b, b + 16 * 16);
std::sort(b_ref, b_ref + 16 * 16);
EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
}
TEST_P(Hadamard16x16Test, VaryStride) {
DECLARE_ALIGNED(16, int16_t, a[16 * 16 * 8]);
DECLARE_ALIGNED(16, tran_low_t, b[16 * 16]);
tran_low_t b_ref[16 * 16];
for (int i = 0; i < 16 * 16 * 8; ++i) {
a[i] = rnd_.Rand9Signed();
}
for (int i = 8; i < 64; i += 8) {
memset(b, 0, sizeof(b));
memset(b_ref, 0, sizeof(b_ref));
reference_hadamard16x16(a, i, b_ref);
ASM_REGISTER_STATE_CHECK(h_func_(a, i, b));
// The order of the output is not important. Sort before checking.
std::sort(b, b + 16 * 16);
std::sort(b_ref, b_ref + 16 * 16);
EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
}
}
TEST_P(Hadamard16x16Test, DISABLED_Speed) {
HadamardSpeedTest16x16(h_func_, 10);
HadamardSpeedTest16x16(h_func_, 10000);
HadamardSpeedTest16x16(h_func_, 10000000);
}
INSTANTIATE_TEST_CASE_P(C, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_c));
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(SSE2, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_sse2));
#endif // HAVE_SSE2
#if HAVE_AVX2
INSTANTIATE_TEST_CASE_P(AVX2, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_avx2));
#endif // HAVE_AVX2
#if HAVE_VSX
INSTANTIATE_TEST_CASE_P(VSX, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_vsx));
#endif // HAVE_VSX
#if HAVE_NEON
INSTANTIATE_TEST_CASE_P(NEON, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_neon));
#endif // HAVE_NEON
#if !CONFIG_VP9_HIGHBITDEPTH
#if HAVE_MSA
INSTANTIATE_TEST_CASE_P(MSA, Hadamard16x16Test,
::testing::Values(&vpx_hadamard_16x16_msa));
#endif // HAVE_MSA
#endif // !CONFIG_VP9_HIGHBITDEPTH
} // namespace

View File

@ -21,11 +21,14 @@ namespace libvpx_test {
// so that we can do actual file encodes. // so that we can do actual file encodes.
class I420VideoSource : public YUVVideoSource { class I420VideoSource : public YUVVideoSource {
public: public:
I420VideoSource(const std::string &file_name, unsigned int width, I420VideoSource(const std::string &file_name,
unsigned int height, int rate_numerator, int rate_denominator, unsigned int width, unsigned int height,
int rate_numerator, int rate_denominator,
unsigned int start, int limit) unsigned int start, int limit)
: YUVVideoSource(file_name, VPX_IMG_FMT_I420, width, height, : YUVVideoSource(file_name, VPX_IMG_FMT_I420,
rate_numerator, rate_denominator, start, limit) {} width, height,
rate_numerator, rate_denominator,
start, limit) {}
}; };
} // namespace libvpx_test } // namespace libvpx_test

Some files were not shown because too many files have changed in this diff Show More