android_media_Streams.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2019, 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. #ifndef _ANDROID_MEDIA_STREAMS_H_
  17. #define _ANDROID_MEDIA_STREAMS_H_
  18. #include "src/piex_types.h"
  19. #include "src/piex.h"
  20. #include <jni.h>
  21. #include <nativehelper/JNIHelp.h>
  22. #include <utils/KeyedVector.h>
  23. #include <utils/String8.h>
  24. #include <utils/StrongPointer.h>
  25. #include <SkStream.h>
  26. namespace android {
  27. class AssetStream : public piex::StreamInterface {
  28. private:
  29. SkStream *mStream;
  30. size_t mPosition;
  31. public:
  32. explicit AssetStream(SkStream* stream);
  33. ~AssetStream();
  34. // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
  35. // provided by the caller, guaranteed to be at least "length" bytes long.
  36. // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
  37. // 'offset' bytes from the start of the stream.
  38. // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
  39. // change the contents of 'data'.
  40. piex::Error GetData(
  41. const size_t offset, const size_t length, std::uint8_t* data) override;
  42. };
  43. class BufferedStream : public piex::StreamInterface {
  44. private:
  45. SkStream *mStream;
  46. // Growable memory stream
  47. SkDynamicMemoryWStream mStreamBuffer;
  48. // Minimum size to read on filling the buffer.
  49. const size_t kMinSizeToRead = 8192;
  50. public:
  51. explicit BufferedStream(SkStream* stream);
  52. ~BufferedStream();
  53. // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
  54. // provided by the caller, guaranteed to be at least "length" bytes long.
  55. // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
  56. // 'offset' bytes from the start of the stream.
  57. // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
  58. // change the contents of 'data'.
  59. piex::Error GetData(
  60. const size_t offset, const size_t length, std::uint8_t* data) override;
  61. };
  62. class FileStream : public piex::StreamInterface {
  63. private:
  64. FILE *mFile;
  65. size_t mPosition;
  66. public:
  67. explicit FileStream(const int fd);
  68. explicit FileStream(const String8 filename);
  69. ~FileStream();
  70. // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
  71. // provided by the caller, guaranteed to be at least "length" bytes long.
  72. // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
  73. // 'offset' bytes from the start of the stream.
  74. // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
  75. // change the contents of 'data'.
  76. piex::Error GetData(
  77. const size_t offset, const size_t length, std::uint8_t* data) override;
  78. bool exists() const;
  79. };
  80. // Reads EXIF metadata from a given raw image via piex.
  81. // And returns true if the operation is successful; otherwise, false.
  82. bool GetExifFromRawImage(
  83. piex::StreamInterface* stream, const String8& filename, piex::PreviewImageData& image_data);
  84. // Returns true if the conversion is successful; otherwise, false.
  85. bool ConvertKeyValueArraysToKeyedVector(
  86. JNIEnv *env, jobjectArray keys, jobjectArray values,
  87. KeyedVector<String8, String8>* vector);
  88. struct AMessage;
  89. status_t ConvertMessageToMap(
  90. JNIEnv *env, const sp<AMessage> &msg, jobject *map);
  91. status_t ConvertKeyValueArraysToMessage(
  92. JNIEnv *env, jobjectArray keys, jobjectArray values,
  93. sp<AMessage> *msg);
  94. }; // namespace android
  95. #endif // _ANDROID_MEDIA_STREAMS_H_