VideoFrame.h revision 37007147edde731cd3dc74febd7bb7e093a35020
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// A simple buffer to hold binary data
29class MediaAlbumArt
30{
31public:
32    MediaAlbumArt(): mSize(0), mData(0) {}
33
34    explicit MediaAlbumArt(const char* url) {
35        mSize = 0;
36        mData = NULL;
37        FILE *in = fopen(url, "r");
38        if (!in) {
39            return;
40        }
41        fseek(in, 0, SEEK_END);
42        mSize = ftell(in);  // Allocating buffer of size equals to the external file size.
43        if (mSize == 0 || (mData = new uint8_t[mSize]) == NULL) {
44            fclose(in);
45            if (mSize != 0) {
46                mSize = 0;
47            }
48            return;
49        }
50        rewind(in);
51        if (fread(mData, 1, mSize, in) != mSize) {  // Read failed.
52            delete[] mData;
53            mData = NULL;
54            mSize = 0;
55            return;
56        }
57        fclose(in);
58    }
59
60    MediaAlbumArt(const MediaAlbumArt& copy) {
61        mSize = copy.mSize;
62        mData = NULL;  // initialize it first
63        if (mSize > 0 && copy.mData != NULL) {
64           mData = new uint8_t[copy.mSize];
65           if (mData != NULL) {
66               memcpy(mData, copy.mData, mSize);
67           } else {
68               mSize = 0;
69           }
70        }
71    }
72
73    ~MediaAlbumArt() {
74        if (mData != 0) {
75            delete[] mData;
76        }
77    }
78
79    // Intentional public access modifier:
80    // We have to know the internal structure in order to share it between
81    // processes?
82    uint32_t mSize;            // Number of bytes in mData
83    uint8_t* mData;            // Actual binary data
84};
85
86// Represents a color converted (RGB-based) video frame
87// with bitmap pixels stored in FrameBuffer
88class VideoFrame
89{
90public:
91    VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0),
92            mRotationAngle(0) {}
93
94    VideoFrame(const VideoFrame& copy) {
95        mWidth = copy.mWidth;
96        mHeight = copy.mHeight;
97        mDisplayWidth = copy.mDisplayWidth;
98        mDisplayHeight = copy.mDisplayHeight;
99        mSize = copy.mSize;
100        mData = NULL;  // initialize it first
101        if (mSize > 0 && copy.mData != NULL) {
102            mData = new uint8_t[mSize];
103            if (mData != NULL) {
104                memcpy(mData, copy.mData, mSize);
105            } else {
106                mSize = 0;
107            }
108        }
109        mRotationAngle = copy.mRotationAngle;
110    }
111
112    ~VideoFrame() {
113        if (mData != 0) {
114            delete[] mData;
115        }
116    }
117
118    // Intentional public access modifier:
119    uint32_t mWidth;
120    uint32_t mHeight;
121    uint32_t mDisplayWidth;
122    uint32_t mDisplayHeight;
123    uint32_t mSize;            // Number of bytes in mData
124    uint8_t* mData;            // Actual binary data
125    int32_t  mRotationAngle;   // rotation angle, clockwise
126};
127
128}; // namespace android
129
130#endif // ANDROID_VIDEO_FRAME_H
131