VideoFrame.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. **
  3. ** Copyright (C) 2008 The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #ifndef ANDROID_VIDEO_FRAME_H
  18. #define ANDROID_VIDEO_FRAME_H
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <utils/Log.h>
  23. namespace android {
  24. // Represents a color converted (RGB-based) video frame with bitmap
  25. // pixels stored in FrameBuffer.
  26. // In a VideoFrame struct stored in IMemory, frame data and ICC data
  27. // come after the VideoFrame structure. Their locations can be retrieved
  28. // by getFlattenedData() and getFlattenedIccData();
  29. class VideoFrame
  30. {
  31. public:
  32. // Construct a VideoFrame object with the specified parameters,
  33. // will calculate frame buffer size if |hasData| is set to true.
  34. VideoFrame(uint32_t width, uint32_t height,
  35. uint32_t displayWidth, uint32_t displayHeight,
  36. uint32_t tileWidth, uint32_t tileHeight,
  37. uint32_t angle, uint32_t bpp, bool hasData, size_t iccSize):
  38. mWidth(width), mHeight(height),
  39. mDisplayWidth(displayWidth), mDisplayHeight(displayHeight),
  40. mTileWidth(tileWidth), mTileHeight(tileHeight),
  41. mRotationAngle(angle), mBytesPerPixel(bpp), mRowBytes(bpp * width),
  42. mSize(hasData ? (bpp * width * height) : 0),
  43. mIccSize(iccSize), mReserved(0) {
  44. }
  45. void init(const VideoFrame& copy, const void* iccData, size_t iccSize) {
  46. *this = copy;
  47. if (mIccSize == iccSize && iccSize > 0 && iccData != NULL) {
  48. memcpy(getFlattenedIccData(), iccData, iccSize);
  49. } else {
  50. mIccSize = 0;
  51. }
  52. }
  53. // Calculate the flattened size to put it in IMemory
  54. size_t getFlattenedSize() const {
  55. return sizeof(VideoFrame) + mSize + mIccSize;
  56. }
  57. // Get the pointer to the frame data in a flattened VideoFrame in IMemory
  58. uint8_t* getFlattenedData() const {
  59. return (uint8_t*)this + sizeof(VideoFrame);
  60. }
  61. // Get the pointer to the ICC data in a flattened VideoFrame in IMemory
  62. uint8_t* getFlattenedIccData() const {
  63. return (uint8_t*)this + sizeof(VideoFrame) + mSize;
  64. }
  65. // Intentional public access modifier:
  66. uint32_t mWidth; // Decoded image width before rotation
  67. uint32_t mHeight; // Decoded image height before rotation
  68. uint32_t mDisplayWidth; // Display width before rotation
  69. uint32_t mDisplayHeight; // Display height before rotation
  70. uint32_t mTileWidth; // Tile width (0 if image doesn't have grid)
  71. uint32_t mTileHeight; // Tile height (0 if image doesn't have grid)
  72. int32_t mRotationAngle; // Rotation angle, clockwise, should be multiple of 90
  73. uint32_t mBytesPerPixel; // Number of bytes per pixel
  74. uint32_t mRowBytes; // Number of bytes per row before rotation
  75. uint32_t mSize; // Number of bytes of frame data
  76. uint32_t mIccSize; // Number of bytes of ICC data
  77. uint32_t mReserved; // (padding to make mData 64-bit aligned)
  78. };
  79. }; // namespace android
  80. #endif // ANDROID_VIDEO_FRAME_H