2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * This class simulates a hardware JPEG compressor. It receives image buffers
20 * in RGBA_8888 format, processes them in a worker thread, and then pushes them
21 * out to their destination stream.
24 #ifndef HW_EMULATOR_CAMERA2_JPEG_H
25 #define HW_EMULATOR_CAMERA2_JPEG_H
27 #include "utils/Thread.h"
28 #include "utils/Mutex.h"
29 #include "utils/Timers.h"
41 class JpegCompressor: private Thread, public virtual RefBase {
48 // Called when JPEG compression has finished, or encountered an error
49 virtual void onJpegDone(const StreamBuffer &jpegBuffer,
51 // Called when the input buffer for JPEG is not needed any more,
52 // if the buffer came from the framework.
53 virtual void onJpegInputDone(const StreamBuffer &inputBuffer) = 0;
54 virtual ~JpegListener();
57 // Start compressing COMPRESSED format buffers; JpegCompressor takes
58 // ownership of the Buffers vector.
59 status_t start(Buffers *buffers, JpegListener *listener);
61 // Compress and block until buffer is complete.
62 status_t compressSynchronous(Buffers *buffers);
67 bool isStreamInUse(uint32_t id);
69 bool waitForDone(nsecs_t timeout);
72 static const size_t kMaxJpegSize = 300000;
83 JpegListener *mListener;
85 StreamBuffer mJpegBuffer, mAuxBuffer;
86 bool mFoundJpeg, mFoundAux;
88 jpeg_compress_struct mCInfo;
90 struct JpegError : public jpeg_error_mgr {
91 JpegCompressor *parent;
93 j_common_ptr mJpegErrorInfo;
95 struct JpegDestination : public jpeg_destination_mgr {
96 JpegCompressor *parent;
99 static void jpegErrorHandler(j_common_ptr cinfo);
101 static void jpegInitDestination(j_compress_ptr cinfo);
102 static boolean jpegEmptyOutputBuffer(j_compress_ptr cinfo);
103 static void jpegTermDestination(j_compress_ptr cinfo);
105 bool checkError(const char *msg);
111 * Inherited Thread virtual overrides
114 virtual status_t readyToRun();
115 virtual bool threadLoop();
118 } // namespace android