| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_VIDEO_PACKET_LAYOUT_H_ |
| 6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_VIDEO_PACKET_LAYOUT_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace media { |
| 14 |
| 15 // Describes the layout of a video packet. |
| 16 class VideoPacketLayout { |
| 17 public: |
| 18 static const size_t kFrameSizeAlignment = 16; |
| 19 static const size_t kFrameSizePadding = 16; |
| 20 static const size_t kYPlaneIndex = 0; |
| 21 static const size_t kARGBPlaneIndex = 0; |
| 22 static const size_t kUPlaneIndex = 1; |
| 23 static const size_t kUVPlaneIndex = 1; |
| 24 static const size_t kVPlaneIndex = 2; |
| 25 static const size_t kAPlaneIndex = 3; |
| 26 static const size_t kMaxPlaneIndex = 3; |
| 27 |
| 28 // Width and height. |
| 29 struct Extent { |
| 30 Extent() : width_(0), height_(0) {} |
| 31 Extent(int width, int height) : width_(width), height_(height) {} |
| 32 size_t width() const { return width_; } |
| 33 size_t height() const { return height_; } |
| 34 |
| 35 private: |
| 36 size_t width_; |
| 37 size_t height_; |
| 38 }; |
| 39 |
| 40 // Information regarding a pixel format. |
| 41 struct PixelFormatInfo { |
| 42 // Returns the number of bytes per element for the specified plane. |
| 43 size_t bytes_per_element_for_plane(size_t plane) const { |
| 44 MOJO_DCHECK(plane < plane_count_); |
| 45 return bytes_per_element_[plane]; |
| 46 } |
| 47 |
| 48 // Returns the sample size of the specified plane. |
| 49 const Extent& sample_size_for_plane(size_t plane) const { |
| 50 MOJO_DCHECK(plane < plane_count_); |
| 51 return sample_size_[plane]; |
| 52 } |
| 53 |
| 54 // Returns the row count for the specified plane. |
| 55 size_t RowCount(size_t plane, size_t height) const; |
| 56 |
| 57 // Returns the column count for the specified plane. |
| 58 size_t ColumnCount(size_t plane, size_t width) const; |
| 59 |
| 60 // Returns the number of bytes per row for the specified plane. |
| 61 size_t BytesPerRow(size_t plane, size_t width) const; |
| 62 |
| 63 // Calculates an aligned size from an unaligned size. |
| 64 Extent AlignedSize(const Extent& unaligned_size) const; |
| 65 |
| 66 // Determines a common alignment for all planes. |
| 67 Extent CommonAlignment() const; |
| 68 |
| 69 const size_t plane_count_; |
| 70 const size_t bytes_per_element_[kMaxPlaneIndex + 1]; |
| 71 const Extent sample_size_[kMaxPlaneIndex + 1]; |
| 72 }; |
| 73 |
| 74 // Gets information for the specified pixel format. |
| 75 static const PixelFormatInfo& InfoForPixelFormat(PixelFormat pixel_format); |
| 76 |
| 77 VideoPacketLayout(); |
| 78 |
| 79 VideoPacketLayout(PixelFormat pixel_format, |
| 80 uint32_t width, |
| 81 uint32_t height, |
| 82 uint32_t coded_width, |
| 83 uint32_t coded_height); |
| 84 |
| 85 ~VideoPacketLayout(); |
| 86 |
| 87 PixelFormat pixel_format() const { return pixel_format_; } |
| 88 |
| 89 uint32_t width() const { return width_; } |
| 90 |
| 91 uint32_t height() const { return height_; } |
| 92 |
| 93 uint32_t coded_width() const { return coded_width_; } |
| 94 |
| 95 uint32_t coded_height() const { return coded_height_; } |
| 96 |
| 97 size_t plane_count() const { return plane_count_; } |
| 98 |
| 99 size_t size() const { return size_; } |
| 100 |
| 101 size_t line_stride_for_plane(size_t plane) { |
| 102 MOJO_DCHECK(plane < plane_count_); |
| 103 return line_stride_[plane]; |
| 104 } |
| 105 |
| 106 size_t plane_offset_for_plane(size_t plane) { |
| 107 MOJO_DCHECK(plane < plane_count_); |
| 108 return plane_offset_[plane]; |
| 109 } |
| 110 |
| 111 const PixelFormatInfo& GetPixelFormatInfo() const { |
| 112 return InfoForPixelFormat(pixel_format_); |
| 113 } |
| 114 |
| 115 private: |
| 116 PixelFormat pixel_format_; |
| 117 uint32_t width_; |
| 118 uint32_t height_; |
| 119 uint32_t coded_width_; |
| 120 uint32_t coded_height_; |
| 121 size_t plane_count_; |
| 122 size_t line_stride_[kMaxPlaneIndex + 1]; |
| 123 size_t plane_offset_[kMaxPlaneIndex + 1]; |
| 124 size_t size_; |
| 125 }; |
| 126 |
| 127 } // namespace media |
| 128 } // namespace mojo |
| 129 |
| 130 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_VIDEO_PACKET_LAYOUT_H_ |
| OLD | NEW |