blob: 11e1704050bca6ce0878253312674cd7e370847c [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
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
26namespace android {
27
Chong Zhang3f4e6dd2018-04-24 16:12:57 -070028// 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 Project89fa4ad2009-03-03 19:31:44 -080033class VideoFrame
34{
35public:
Chong Zhangb51ca282017-07-26 16:25:28 -070036 // Construct a VideoFrame object with the specified parameters,
Chong Zhang3f4e6dd2018-04-24 16:12:57 -070037 // will calculate frame buffer size if |hasData| is set to true.
Chong Zhangb51ca282017-07-26 16:25:28 -070038 VideoFrame(uint32_t width, uint32_t height,
39 uint32_t displayWidth, uint32_t displayHeight,
Chong Zhang0c1407f2018-05-02 17:09:05 -070040 uint32_t tileWidth, uint32_t tileHeight,
Dichen Zhangf4066492022-02-17 17:32:53 -080041 uint32_t angle, uint32_t bpp, uint32_t bitDepth, bool hasData, size_t iccSize):
Chong Zhangb51ca282017-07-26 16:25:28 -070042 mWidth(width), mHeight(height),
43 mDisplayWidth(displayWidth), mDisplayHeight(displayHeight),
Chong Zhang0af4db62019-08-23 15:34:58 -070044 mTileWidth(tileWidth), mTileHeight(tileHeight), mDurationUs(0),
Songyue Hanc5ecdd42022-09-20 21:55:52 +000045 mRotationAngle(angle), mBytesPerPixel(bpp), mIccSize(iccSize),
46 mBitDepth(bitDepth) {
47 uint32_t multVal;
48 mRowBytes = __builtin_mul_overflow(bpp, width, &multVal) ? 0 : multVal;
49 mSize = __builtin_mul_overflow(multVal, height, &multVal) ? 0 : multVal;
50 if (hasData && (mRowBytes == 0 || mSize == 0)) {
51 ALOGE("Frame rowBytes/ size overflow %dx%d bpp %d", width, height, bpp);
Songyue Han22e34a52022-10-27 20:27:10 +000052 android_errorWriteLog(0x534e4554, "233006499");
Songyue Hanc5ecdd42022-09-20 21:55:52 +000053 }
Chong Zhangb51ca282017-07-26 16:25:28 -070054 }
55
Chong Zhang3f4e6dd2018-04-24 16:12:57 -070056 void init(const VideoFrame& copy, const void* iccData, size_t iccSize) {
57 *this = copy;
58 if (mIccSize == iccSize && iccSize > 0 && iccData != NULL) {
59 memcpy(getFlattenedIccData(), iccData, iccSize);
60 } else {
61 mIccSize = 0;
Chong Zhangb51ca282017-07-26 16:25:28 -070062 }
63 }
64
65 // Calculate the flattened size to put it in IMemory
66 size_t getFlattenedSize() const {
67 return sizeof(VideoFrame) + mSize + mIccSize;
68 }
69
70 // Get the pointer to the frame data in a flattened VideoFrame in IMemory
71 uint8_t* getFlattenedData() const {
72 return (uint8_t*)this + sizeof(VideoFrame);
73 }
74
75 // Get the pointer to the ICC data in a flattened VideoFrame in IMemory
76 uint8_t* getFlattenedIccData() const {
77 return (uint8_t*)this + sizeof(VideoFrame) + mSize;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 }
79
80 // Intentional public access modifier:
Chong Zhangb51ca282017-07-26 16:25:28 -070081 uint32_t mWidth; // Decoded image width before rotation
82 uint32_t mHeight; // Decoded image height before rotation
83 uint32_t mDisplayWidth; // Display width before rotation
84 uint32_t mDisplayHeight; // Display height before rotation
Chong Zhang0c1407f2018-05-02 17:09:05 -070085 uint32_t mTileWidth; // Tile width (0 if image doesn't have grid)
86 uint32_t mTileHeight; // Tile height (0 if image doesn't have grid)
Chong Zhang0af4db62019-08-23 15:34:58 -070087 int64_t mDurationUs; // Frame duration in microseconds
Chong Zhangb51ca282017-07-26 16:25:28 -070088 int32_t mRotationAngle; // Rotation angle, clockwise, should be multiple of 90
89 uint32_t mBytesPerPixel; // Number of bytes per pixel
90 uint32_t mRowBytes; // Number of bytes per row before rotation
Chong Zhang3f4e6dd2018-04-24 16:12:57 -070091 uint32_t mSize; // Number of bytes of frame data
92 uint32_t mIccSize; // Number of bytes of ICC data
Dichen Zhangf4066492022-02-17 17:32:53 -080093 uint32_t mBitDepth; // number of bits per R / G / B channel
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080094};
95
96}; // namespace android
97
98#endif // ANDROID_VIDEO_FRAME_H