android_media_Utils.h revision 3c233ee291cfe1b765184920b6b7a69cb1bb82d9
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
29namespace android {
30
31class FileStream : public piex::StreamInterface {
32private:
33    FILE *mFile;
34    size_t mPosition;
35    size_t mSize;
36
37public:
38    FileStream(const String8 filename);
39    ~FileStream();
40
41    // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
42    // provided by the caller, guaranteed to be at least "length" bytes long.
43    // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
44    // 'offset' bytes from the start of the stream.
45    // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
46    // change the contents of 'data'.
47    piex::Error GetData(
48            const size_t offset, const size_t length, std::uint8_t* data) override;
49    bool exists() const;
50    size_t size() const;
51};
52
53// Reads EXIF metadata from a given raw image via piex.
54// And returns true if the operation is successful; otherwise, false.
55bool GetExifFromRawImage(
56        FileStream* stream, const String8& filename, piex::PreviewImageData& image_data);
57
58// Returns true if the conversion is successful; otherwise, false.
59bool ConvertKeyValueArraysToKeyedVector(
60        JNIEnv *env, jobjectArray keys, jobjectArray values,
61        KeyedVector<String8, String8>* vector);
62
63struct AMessage;
64status_t ConvertMessageToMap(
65        JNIEnv *env, const sp<AMessage> &msg, jobject *map);
66
67status_t ConvertKeyValueArraysToMessage(
68        JNIEnv *env, jobjectArray keys, jobjectArray values,
69        sp<AMessage> *msg);
70
71};  // namespace android
72
73#endif //  _ANDROID_MEDIA_UTILS_H_
74