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
26namespace android {
27
28// Represents a color converted (RGB-based) video frame
29// with bitmap pixels stored in FrameBuffer
30class VideoFrame
31{
32public:
33    VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0),
34            mRotationAngle(0) {}
35
36    VideoFrame(const VideoFrame& copy) {
37        mWidth = copy.mWidth;
38        mHeight = copy.mHeight;
39        mDisplayWidth = copy.mDisplayWidth;
40        mDisplayHeight = copy.mDisplayHeight;
41        mSize = copy.mSize;
42        mData = NULL;  // initialize it first
43        if (mSize > 0 && copy.mData != NULL) {
44            mData = new uint8_t[mSize];
45            if (mData != NULL) {
46                memcpy(mData, copy.mData, mSize);
47            } else {
48                mSize = 0;
49            }
50        }
51        mRotationAngle = copy.mRotationAngle;
52    }
53
54    ~VideoFrame() {
55        if (mData != 0) {
56            delete[] mData;
57        }
58    }
59
60    // Intentional public access modifier:
61    uint32_t mWidth;
62    uint32_t mHeight;
63    uint32_t mDisplayWidth;
64    uint32_t mDisplayHeight;
65    uint32_t mSize;            // Number of bytes in mData
66    int32_t  mRotationAngle;   // rotation angle, clockwise, should be multiple of 90
67    // mData should be 64 bit aligned to prevent additional padding
68    uint8_t* mData;            // Actual binary data
69    // pad structure so it's the same size on 64 bit and 32 bit
70    char     mPadding[8 - sizeof(mData)];
71};
72
73}; // namespace android
74
75#endif // ANDROID_VIDEO_FRAME_H
76