android_media_Utils.h revision 0ab416269a866c8afa8f65d9351afa2407abee4c
1/* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _ANDROID_MEDIA_UTILS_H_ 18#define _ANDROID_MEDIA_UTILS_H_ 19 20#include "src/piex_types.h" 21#include "src/piex.h" 22 23#include <android_runtime/AndroidRuntime.h> 24#include <jni.h> 25#include <JNIHelp.h> 26#include <utils/KeyedVector.h> 27#include <utils/String8.h> 28#include <gui/CpuConsumer.h> 29#include <camera3.h> 30 31namespace android { 32 33class FileStream : public piex::StreamInterface { 34private: 35 FILE *mFile; 36 size_t mPosition; 37 size_t mSize; 38 39public: 40 FileStream(const int fd); 41 FileStream(const String8 filename); 42 ~FileStream(); 43 44 // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer 45 // provided by the caller, guaranteed to be at least "length" bytes long. 46 // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at 47 // 'offset' bytes from the start of the stream. 48 // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not 49 // change the contents of 'data'. 50 piex::Error GetData( 51 const size_t offset, const size_t length, std::uint8_t* data) override; 52 bool exists() const; 53 size_t size() const; 54}; 55 56// Reads EXIF metadata from a given raw image via piex. 57// And returns true if the operation is successful; otherwise, false. 58bool GetExifFromRawImage( 59 FileStream* stream, const String8& filename, piex::PreviewImageData& image_data); 60 61// Returns true if the conversion is successful; otherwise, false. 62bool ConvertKeyValueArraysToKeyedVector( 63 JNIEnv *env, jobjectArray keys, jobjectArray values, 64 KeyedVector<String8, String8>* vector); 65 66struct AMessage; 67status_t ConvertMessageToMap( 68 JNIEnv *env, const sp<AMessage> &msg, jobject *map); 69 70status_t ConvertKeyValueArraysToMessage( 71 JNIEnv *env, jobjectArray keys, jobjectArray values, 72 sp<AMessage> *msg); 73 74// -----------Utility functions used by ImageReader/Writer JNI----------------- 75 76typedef CpuConsumer::LockedBuffer LockedImage; 77 78bool usingRGBAToJpegOverride(int32_t imageFormat, int32_t containerFormat); 79 80int32_t applyFormatOverrides(int32_t imageFormat, int32_t containerFormat); 81 82uint32_t Image_getJpegSize(LockedImage* buffer, bool usingRGBAOverride); 83 84bool isFormatOpaque(int format); 85 86bool isPossiblyYUV(PixelFormat format); 87 88status_t getLockedImageInfo(LockedImage* buffer, int idx, int32_t containerFormat, 89 uint8_t **base, uint32_t *size, int *pixelStride, int *rowStride); 90 91status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage, 92 const Rect& rect, int fenceFd, LockedImage* outputImage); 93 94status_t lockImageFromBuffer(BufferItem* bufferItem, uint32_t inUsage, 95 int fenceFd, LockedImage* outputImage); 96 97int getBufferWidth(BufferItem *buffer); 98 99int getBufferHeight(BufferItem *buffer); 100 101}; // namespace android 102 103#endif // _ANDROID_MEDIA_UTILS_H_ 104