VideoFrame.h revision 10db45259545989a80fae0cd6fd6a252f3c9924a
119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/* 219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** 3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o** Copyright (C) 2008 The Android Open Source Project 419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** 519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** Licensed under the Apache License, Version 2.0 (the "License"); 619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** you may not use this file except in compliance with the License. 719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** You may obtain a copy of the License at 819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** 919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** http://www.apache.org/licenses/LICENSE-2.0 1019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** 1119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** Unless required by applicable law or agreed to in writing, software 1219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** distributed under the License is distributed on an "AS IS" BASIS, 1319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** See the License for the specific language governing permissions and 1519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o** limitations under the License. 1619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o*/ 1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 1819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#ifndef ANDROID_VIDEO_FRAME_H 1919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ANDROID_VIDEO_FRAME_H 2019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 2119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdint.h> 2219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdio.h> 2354c637d4d29af3e6365779f8b12976abe95a4753Theodore Ts'o#include <stdlib.h> 2419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <utils/Log.h> 2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 2619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'onamespace android { 2719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 2819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o// A simple buffer to hold binary data 2919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oclass MediaAlbumArt 3019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{ 3119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'opublic: 3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o MediaAlbumArt(): mSize(0), mData(0) {} 3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o explicit MediaAlbumArt(const char* url) { 3519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = 0; 3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mData = NULL; 3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o FILE *in = fopen(url, "r"); 3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (!in) { 39dfcdc32f8d6623a35a9e66f503c535e4081b7266Theodore Ts'o return; 4019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 4119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o fseek(in, 0, SEEK_END); 42efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o mSize = ftell(in); // Allocating buffer of size equals to the external file size. 4319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mSize == 0 || (mData = new uint8_t[mSize]) == NULL) { 4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o fclose(in); 4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mSize != 0) { 4619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = 0; 4719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o return; 4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 5019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o rewind(in); 5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (fread(mData, 1, mSize, in) != mSize) { // Read failed. 5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o delete[] mData; 5319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mData = NULL; 5419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = 0; 5519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o return; 5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o fclose(in); 58efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o } 5919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 6019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o MediaAlbumArt(const MediaAlbumArt& copy) { 6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = copy.mSize; 6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mData = NULL; // initialize it first 6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mSize > 0 && copy.mData != NULL) { 6419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mData = new uint8_t[copy.mSize]; 6519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mData != NULL) { 6619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o memcpy(mData, copy.mData, mSize); 6719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } else { 6819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = 0; 6919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 7019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 7119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 7219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 7319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o ~MediaAlbumArt() { 7419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mData != 0) { 7519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o delete[] mData; 7619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 7719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 7819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 7919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o // Intentional public access modifier: 8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o // We have to know the internal structure in order to share it between 8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o // processes? 8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mSize; // Number of bytes in mData 8319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint8_t* mData; // Actual binary data 8419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}; 8519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 8619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o// Represents a color converted (RGB-based) video frame 8719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o// with bitmap pixels stored in FrameBuffer 8819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oclass VideoFrame 8919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{ 9019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'opublic: 9119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0), 9219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mRotationAngle(0) {} 9319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 9419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o VideoFrame(const VideoFrame& copy) { 9519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mWidth = copy.mWidth; 9619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mHeight = copy.mHeight; 9719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mDisplayWidth = copy.mDisplayWidth; 9819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mDisplayHeight = copy.mDisplayHeight; 9919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = copy.mSize; 10019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mData = NULL; // initialize it first 10119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mSize > 0 && copy.mData != NULL) { 102dfcdc32f8d6623a35a9e66f503c535e4081b7266Theodore Ts'o mData = new uint8_t[mSize]; 10319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mData != NULL) { 10419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o memcpy(mData, copy.mData, mSize); 10519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } else { 10619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o mSize = 0; 10719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 10819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 109efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o mRotationAngle = copy.mRotationAngle; 11019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 11119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 11219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o ~VideoFrame() { 11319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o if (mData != 0) { 11419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o delete[] mData; 11519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 11619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o } 11719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 11819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o // Intentional public access modifier: 11919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mWidth; 12019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mHeight; 12119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mDisplayWidth; 12219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mDisplayHeight; 12319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint32_t mSize; // Number of bytes in mData 12419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o uint8_t* mData; // Actual binary data 12519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o int32_t mRotationAngle; // rotation angle, clockwise 12619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}; 12719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 12819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}; // namespace android 12919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o 13019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#endif // ANDROID_VIDEO_FRAME_H 13119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o