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 28 // A simple buffer to hold binary data 29 class MediaAlbumArt 30 { 31 public: MediaAlbumArt()32 MediaAlbumArt(): mSize(0), mData(0) {} 33 MediaAlbumArt(const char * url)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 MediaAlbumArt(const MediaAlbumArt & copy)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 ~MediaAlbumArt()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 88 class VideoFrame 89 { 90 public: VideoFrame()91 VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0) {} 92 VideoFrame(const VideoFrame & copy)93 VideoFrame(const VideoFrame& copy) { 94 mWidth = copy.mWidth; 95 mHeight = copy.mHeight; 96 mDisplayWidth = copy.mDisplayWidth; 97 mDisplayHeight = copy.mDisplayHeight; 98 mSize = copy.mSize; 99 mData = NULL; // initialize it first 100 if (mSize > 0 && copy.mData != NULL) { 101 mData = new uint8_t[mSize]; 102 if (mData != NULL) { 103 memcpy(mData, copy.mData, mSize); 104 } else { 105 mSize = 0; 106 } 107 } 108 } 109 ~VideoFrame()110 ~VideoFrame() { 111 if (mData != 0) { 112 delete[] mData; 113 } 114 } 115 116 // Intentional public access modifier: 117 uint32_t mWidth; 118 uint32_t mHeight; 119 uint32_t mDisplayWidth; 120 uint32_t mDisplayHeight; 121 uint32_t mSize; // Number of bytes in mData 122 uint8_t* mData; // Actual binary data 123 int32_t mRotationAngle; // rotation angle, clockwise 124 }; 125 126 }; // namespace android 127 128 #endif // ANDROID_VIDEO_FRAME_H 129