The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 18 | #ifndef ANDROID_VIDEO_FRAME_H |
| 19 | #define ANDROID_VIDEO_FRAME_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <utils/Log.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 28 | // Represents a color converted (RGB-based) video frame with bitmap |
| 29 | // pixels stored in FrameBuffer. |
| 30 | // In a VideoFrame struct stored in IMemory, frame data and ICC data |
| 31 | // come after the VideoFrame structure. Their locations can be retrieved |
| 32 | // by getFlattenedData() and getFlattenedIccData(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | class VideoFrame |
| 34 | { |
| 35 | public: |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 36 | // Construct a VideoFrame object with the specified parameters, |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 37 | // will calculate frame buffer size if |hasData| is set to true. |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 38 | VideoFrame(uint32_t width, uint32_t height, |
| 39 | uint32_t displayWidth, uint32_t displayHeight, |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 40 | uint32_t tileWidth, uint32_t tileHeight, |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 41 | uint32_t angle, uint32_t bpp, bool hasData, size_t iccSize): |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 42 | mWidth(width), mHeight(height), |
| 43 | mDisplayWidth(displayWidth), mDisplayHeight(displayHeight), |
Chong Zhang | 0af4db6 | 2019-08-23 15:34:58 -0700 | [diff] [blame] | 44 | mTileWidth(tileWidth), mTileHeight(tileHeight), mDurationUs(0), |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 45 | mRotationAngle(angle), mBytesPerPixel(bpp), mRowBytes(bpp * width), |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 46 | mSize(hasData ? (bpp * width * height) : 0), |
| 47 | mIccSize(iccSize), mReserved(0) { |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 50 | void init(const VideoFrame& copy, const void* iccData, size_t iccSize) { |
| 51 | *this = copy; |
| 52 | if (mIccSize == iccSize && iccSize > 0 && iccData != NULL) { |
| 53 | memcpy(getFlattenedIccData(), iccData, iccSize); |
| 54 | } else { |
| 55 | mIccSize = 0; |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | // Calculate the flattened size to put it in IMemory |
| 60 | size_t getFlattenedSize() const { |
| 61 | return sizeof(VideoFrame) + mSize + mIccSize; |
| 62 | } |
| 63 | |
| 64 | // Get the pointer to the frame data in a flattened VideoFrame in IMemory |
| 65 | uint8_t* getFlattenedData() const { |
| 66 | return (uint8_t*)this + sizeof(VideoFrame); |
| 67 | } |
| 68 | |
| 69 | // Get the pointer to the ICC data in a flattened VideoFrame in IMemory |
| 70 | uint8_t* getFlattenedIccData() const { |
| 71 | return (uint8_t*)this + sizeof(VideoFrame) + mSize; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | // Intentional public access modifier: |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 75 | uint32_t mWidth; // Decoded image width before rotation |
| 76 | uint32_t mHeight; // Decoded image height before rotation |
| 77 | uint32_t mDisplayWidth; // Display width before rotation |
| 78 | uint32_t mDisplayHeight; // Display height before rotation |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 79 | uint32_t mTileWidth; // Tile width (0 if image doesn't have grid) |
| 80 | uint32_t mTileHeight; // Tile height (0 if image doesn't have grid) |
Chong Zhang | 0af4db6 | 2019-08-23 15:34:58 -0700 | [diff] [blame] | 81 | int64_t mDurationUs; // Frame duration in microseconds |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 82 | int32_t mRotationAngle; // Rotation angle, clockwise, should be multiple of 90 |
| 83 | uint32_t mBytesPerPixel; // Number of bytes per pixel |
| 84 | uint32_t mRowBytes; // Number of bytes per row before rotation |
Chong Zhang | 3f4e6dd | 2018-04-24 16:12:57 -0700 | [diff] [blame] | 85 | uint32_t mSize; // Number of bytes of frame data |
| 86 | uint32_t mIccSize; // Number of bytes of ICC data |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 87 | uint32_t mReserved; // (padding to make mData 64-bit aligned) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | }; // namespace android |
| 91 | |
| 92 | #endif // ANDROID_VIDEO_FRAME_H |