+++ /dev/null
-/*
- * 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 {
-
-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";
-
-#if CONFIG_WEBM_IO
-
-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
}
void Control(int ctrl_id, int arg) {
- Control(ctrl_id, arg, VPX_CODEC_OK);
- }
-
- void Control(int ctrl_id, const void *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, int arg, vpx_codec_err_t expected_value) {
+ void Control(int ctrl_id, const void *arg) {
InitOnce();
const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
- ASSERT_EQ(expected_value, res) << DecodeError();
+ ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
}
const char* DecodeError() {
LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += cq_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += keyframe_test.cc
-LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += byte_alignment_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += external_frame_buffer_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += invalid_file_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += user_priv_test.cc
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS,
- cm->byte_alignment) < 0)
+ VP9_ENC_BORDER_IN_PIXELS) < 0)
goto fail;
if (cm->frame_bufs[i].mvs == NULL) {
cm->frame_bufs[i].mvs =
int frame_parallel_decoding_mode;
int log2_tile_cols, log2_tile_rows;
- int byte_alignment;
// Private data associated with the frame buffer callbacks.
void *cb_priv;
cm->use_highbitdepth,
#endif
VP9_DEC_BORDER_IN_PIXELS,
- cm->byte_alignment,
&cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
cm->cb_priv)) {
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
cm->use_highbitdepth,
#endif
VP9_DEC_BORDER_IN_PIXELS,
- cm->byte_alignment,
&cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
cm->cb_priv)) {
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
#endif
int border) {
int i, fail;
- const int legacy_byte_alignment = 0;
assert(denoiser != NULL);
for (i = 0; i < MAX_REF_FRAMES; ++i) {
#if CONFIG_VP9_HIGHBITDEPTH
use_highbitdepth,
#endif
- border, legacy_byte_alignment);
+ border);
if (fail) {
vp9_denoiser_free(denoiser);
return 1;
#if CONFIG_VP9_HIGHBITDEPTH
use_highbitdepth,
#endif
- border, legacy_byte_alignment);
+ border);
if (fail) {
vp9_denoiser_free(denoiser);
return 1;
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate altref buffer");
}
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate last frame buffer");
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate scaled source buffer");
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate scaled last source buffer");
}
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to reallocate alt_ref_buffer");
}
cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
cm->use_highbitdepth,
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL);
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf,
(int)cm->bit_depth);
#else
vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL);
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf);
#endif // CONFIG_VP9_HIGHBITDEPTH
cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
- NULL, NULL, NULL);
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
alloc_util_frame_buffers(cpi);
init_motion_estimation(cpi);
// Allocate the lookahead structures
ctx = calloc(1, sizeof(*ctx));
if (ctx) {
- const int legacy_byte_alignment = 0;
unsigned int i;
ctx->max_sz = depth;
ctx->buf = calloc(depth, sizeof(*ctx->buf));
#if CONFIG_VP9_HIGHBITDEPTH
use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS,
- legacy_byte_alignment))
+ VP9_ENC_BORDER_IN_PIXELS))
goto bail;
}
return ctx;
#if CONFIG_VP9_HIGHBITDEPTH
cpi->common.use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS,
- cpi->common.byte_alignment,
- NULL, NULL, NULL))
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate empty frame for multiple frame "
"contexts");
#if CONFIG_VP9_HIGHBITDEPTH
cm->use_highbitdepth,
#endif
- VP9_ENC_BORDER_IN_PIXELS,
- cm->byte_alignment,
- NULL, NULL, NULL)) {
+ VP9_ENC_BORDER_IN_PIXELS, NULL, NULL,
+ NULL)) {
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Failed to reallocate alt_ref_buffer");
}
int flushed;
int invert_tile_order;
int frame_parallel_decode; // frame-based threading.
- int byte_alignment;
// External frame buffer info to save for VP9 common.
void *ext_priv; // Private data associated with the external frame buffers.
VP9_COMMON *const cm = &ctx->pbi->common;
cm->new_fb_idx = -1;
- cm->byte_alignment = ctx->byte_alignment;
if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
cm->get_fb_cb = ctx->get_ext_fb_cb;
return VPX_CODEC_OK;
}
-static vpx_codec_err_t ctrl_set_byte_alignment(vpx_codec_alg_priv_t *ctx,
- va_list args) {
- const int legacy_byte_alignment = 0;
- const int min_byte_alignment = 32;
- const int max_byte_alignment = 1024;
- const int byte_alignment = va_arg(args, int);
-
- if (byte_alignment != legacy_byte_alignment &&
- (byte_alignment < min_byte_alignment ||
- byte_alignment > max_byte_alignment ||
- (byte_alignment & (byte_alignment - 1)) != 0))
- return VPX_CODEC_INVALID_PARAM;
-
- ctx->byte_alignment = byte_alignment;
- if (ctx->pbi != NULL) {
- VP9_COMMON *const cm = &ctx->pbi->common;
- cm->byte_alignment = byte_alignment;
- }
- return VPX_CODEC_OK;
-}
-
static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
{VP8_COPY_REFERENCE, ctrl_copy_reference},
{VP8_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options},
{VP9_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order},
{VPXD_SET_DECRYPTOR, ctrl_set_decryptor},
- {VP9_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment},
// Getters
{VP8D_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates},
/** control function to get the bit depth of the stream. */
VP9D_GET_BIT_DEPTH,
- /** control function to set the byte alignment of the planes in the reference
- * buffers. Valid values are power of 2, from 32 to 1024. A value of 0 sets
- * legacy alignment. I.e. Y plane is aligned to 32 bytes, U plane directly
- * follows Y plane, and V plane directly follows U plane. Default value is 0.
- */
- VP9_SET_BYTE_ALIGNMENT,
-
/** For testing. */
VP9_INVERT_TILE_DECODE_ORDER,
int use_highbitdepth,
#endif
int border,
- int byte_alignment,
vpx_codec_frame_buffer_t *fb,
vpx_get_frame_buffer_cb_fn_t cb,
void *cb_priv) {
if (ybf) {
- const int vp9_byte_align = (byte_alignment == 0) ? 1 : byte_alignment;
const int aligned_width = (width + 7) & ~7;
const int aligned_height = (height + 7) & ~7;
const int y_stride = ((aligned_width + 2 * border) + 31) & ~31;
const uint64_t yplane_size = (aligned_height + 2 * border) *
- (uint64_t)y_stride + byte_alignment;
+ (uint64_t)y_stride;
const int uv_width = aligned_width >> ss_x;
const int uv_height = aligned_height >> ss_y;
const int uv_stride = y_stride >> ss_x;
const int uv_border_w = border >> ss_x;
const int uv_border_h = border >> ss_y;
const uint64_t uvplane_size = (uv_height + 2 * uv_border_h) *
- (uint64_t)uv_stride + byte_alignment;
-
+ (uint64_t)uv_stride;
#if CONFIG_ALPHA
const int alpha_width = aligned_width;
const int alpha_height = aligned_height;
const int alpha_border_w = border;
const int alpha_border_h = border;
const uint64_t alpha_plane_size = (alpha_height + 2 * alpha_border_h) *
- (uint64_t)alpha_stride + byte_alignment;
+ (uint64_t)alpha_stride;
#if CONFIG_VP9_HIGHBITDEPTH
const uint64_t frame_size = (1 + use_highbitdepth) *
(yplane_size + 2 * uvplane_size + alpha_plane_size);
const uint64_t frame_size = yplane_size + 2 * uvplane_size;
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // CONFIG_ALPHA
-
- uint8_t *buf = NULL;
-
if (cb != NULL) {
const int align_addr_extra_size = 31;
const uint64_t external_frame_size = frame_size + align_addr_extra_size;
ybf->subsampling_x = ss_x;
ybf->subsampling_y = ss_y;
- buf = ybf->buffer_alloc;
#if CONFIG_VP9_HIGHBITDEPTH
if (use_highbitdepth) {
// Store uint16 addresses when using 16bit framebuffers
- buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
+ uint8_t *p = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
+ ybf->y_buffer = p + (border * y_stride) + border;
+ ybf->u_buffer = p + yplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
+ ybf->v_buffer = p + yplane_size + uvplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
ybf->flags = YV12_FLAG_HIGHBITDEPTH;
} else {
+ ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
+ ybf->u_buffer = ybf->buffer_alloc + yplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
+ ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
ybf->flags = 0;
}
+#else
+ ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
+ ybf->u_buffer = ybf->buffer_alloc + yplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
+ ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size +
+ (uv_border_h * uv_stride) + uv_border_w;
#endif // CONFIG_VP9_HIGHBITDEPTH
- ybf->y_buffer = (uint8_t *)yv12_align_addr(
- buf + (border * y_stride) + border, vp9_byte_align);
- ybf->u_buffer = (uint8_t *)yv12_align_addr(
- buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
- vp9_byte_align);
- ybf->v_buffer = (uint8_t *)yv12_align_addr(
- buf + yplane_size + uvplane_size + (uv_border_h * uv_stride) +
- uv_border_w, vp9_byte_align);
-
#if CONFIG_ALPHA
ybf->alpha_width = alpha_width;
ybf->alpha_height = alpha_height;
ybf->alpha_stride = alpha_stride;
- ybf->alpha_buffer = (uint8_t *)yv12_align_addr(
- buf + yplane_size + 2 * uvplane_size +
- (alpha_border_h * alpha_stride) + alpha_border_w, vp9_byte_align);
+ ybf->alpha_buffer = ybf->buffer_alloc + yplane_size + 2 * uvplane_size +
+ (alpha_border_h * alpha_stride) + alpha_border_w;
#endif
ybf->corrupted = 0; /* assume not corrupted by errors */
return 0;
#if CONFIG_VP9_HIGHBITDEPTH
int use_highbitdepth,
#endif
- int border,
- int byte_alignment) {
+ int border) {
if (ybf) {
vp9_free_frame_buffer(ybf);
return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y,
#if CONFIG_VP9_HIGHBITDEPTH
use_highbitdepth,
#endif
- border, byte_alignment, NULL, NULL, NULL);
+ border, NULL, NULL, NULL);
}
return -2;
}
#if CONFIG_VP9_HIGHBITDEPTH
int use_highbitdepth,
#endif
- int border, int byte_alignment);
+ int border);
-// Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
-// be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
+// Updates the yv12 buffer config with the frame buffer. If cb is not
// NULL, then libvpx is using the frame buffer callbacks to handle memory.
// If cb is not NULL, libvpx will call cb with minimum size in bytes needed
// to decode the current frame. If cb is NULL, libvpx will allocate memory
int use_highbitdepth,
#endif
int border,
- int byte_alignment,
vpx_codec_frame_buffer_t *fb,
vpx_get_frame_buffer_cb_fn_t cb,
void *cb_priv);