Index: cc/resources/video_resource_updater.cc |
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc |
index 2ad91ae0674558bb9ad7f5963aa68c50d6554c38..e36c92045d0cfa6800752413bf22a049fd6a68de 100644 |
--- a/cc/resources/video_resource_updater.cc |
+++ b/cc/resources/video_resource_updater.cc |
@@ -298,86 +298,14 @@ static gfx::Size SoftwarePlaneDimension(media::VideoFrame* input_frame, |
return gfx::Size(plane_width, plane_height); |
} |
-namespace { |
-// By OR-ing with 0x3800, 10-bit numbers become half-floats in the |
-// range [0.5..1) and 9-bit numbers get the range [0.5..0.75). |
-// |
-// Half-floats are evaluated as: |
-// float value = pow(2.0, exponent - 25) * (0x400 + fraction); |
-// |
-// In our case the exponent is 14 (since we or with 0x3800) and |
-// pow(2.0, 14-25) * 0x400 evaluates to 0.5 (our offset) and |
-// pow(2.0, 14-25) * fraction is [0..0.49951171875] for 10-bit and |
-// [0..0.24951171875] for 9-bit. |
-// |
-// https://en.wikipedia.org/wiki/Half-precision_floating-point_format |
-class HalfFloatMaker_xor : public VideoResourceUpdater::HalfFloatMaker { |
- public: |
- explicit HalfFloatMaker_xor(int bits_per_channel) |
- : bits_per_channel_(bits_per_channel) {} |
- float Offset() const override { return 0.5; } |
- float Multiplier() const override { |
- int max_input_value = (1 << bits_per_channel_) - 1; |
- // 2 << 11 = 2048 would be 1.0 with our exponent. |
- return 2048.0 / max_input_value; |
- } |
- void MakeHalfFloats(const uint16_t* src, size_t num, uint16_t* dst) override { |
- // Micro-benchmarking indicates that the compiler does |
- // a good enough job of optimizing this loop that trying |
- // to manually operate on one uint64 at a time is not |
- // actually helpful. |
- // Note to future optimizers: Benchmark your optimizations! |
- for (size_t i = 0; i < num; i++) |
- dst[i] = src[i] | 0x3800; |
- } |
- |
- private: |
- int bits_per_channel_; |
-}; |
- |
-class HalfFloatMaker_libyuv : public VideoResourceUpdater::HalfFloatMaker { |
- public: |
- explicit HalfFloatMaker_libyuv(int bits_per_channel) { |
- int max_value = (1 << bits_per_channel) - 1; |
- // For less than 15 bits, we can give libyuv a multiplier of |
- // 1.0, which is faster on some platforms. If bits is 16 or larger, |
- // a multiplier of 1.0 would cause overflows. However, a multiplier |
- // of 1/max_value would cause subnormal floats, which perform |
- // very poorly on some platforms. |
- if (bits_per_channel <= 15) { |
- libyuv_multiplier_ = 1.0f; |
- } else { |
- // This multiplier makes sure that we avoid subnormal values. |
- libyuv_multiplier_ = 1.0f / 4096.0f; |
- } |
- resource_multiplier_ = 1.0f / libyuv_multiplier_ / max_value; |
- } |
- float Offset() const override { return 0.0f; } |
- float Multiplier() const override { return resource_multiplier_; } |
- void MakeHalfFloats(const uint16_t* src, size_t num, uint16_t* dst) override { |
- // Source and dest stride can be zero since we're only copying |
- // one row at a time. |
- int stride = 0; |
- int rows = 1; |
- libyuv::HalfFloatPlane(src, stride, dst, stride, libyuv_multiplier_, num, |
- rows); |
- } |
- |
- private: |
- float libyuv_multiplier_; |
- float resource_multiplier_; |
-}; |
- |
-} // namespace |
- |
-std::unique_ptr<VideoResourceUpdater::HalfFloatMaker> |
-VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) { |
+std::unique_ptr<media::HalfFloatMaker> VideoResourceUpdater::NewHalfFloatMaker( |
hubbe
2017/03/22 17:48:22
Move this function to media
Uzair
2017/03/23 07:13:30
Done.
|
+ int bits_per_channel) { |
if (bits_per_channel < 11) { |
- return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
- new HalfFloatMaker_xor(bits_per_channel)); |
+ return std::unique_ptr<media::HalfFloatMaker>( |
+ new media::HalfFloatMaker_xor(bits_per_channel)); |
} else { |
- return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
- new HalfFloatMaker_libyuv(bits_per_channel)); |
+ return std::unique_ptr<media::HalfFloatMaker>( |
+ new media::HalfFloatMaker_libyuv(bits_per_channel)); |
} |
} |
@@ -518,7 +446,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
return external_resources; |
} |
- std::unique_ptr<HalfFloatMaker> half_float_maker; |
+ std::unique_ptr<media::HalfFloatMaker> half_float_maker; |
if (resource_provider_->YuvResourceFormat(bits_per_channel) == |
LUMINANCE_F16) { |
half_float_maker = NewHalfFloatMaker(bits_per_channel); |