Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_SERVERS_CAMERA_CAMERA2_STREAMINGPROCESSOR_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERA2_STREAMINGPROCESSOR_H |
| 19 | |
| 20 | #include <utils/Mutex.h> |
| 21 | #include <utils/String16.h> |
| 22 | #include <gui/BufferItemConsumer.h> |
| 23 | |
| 24 | #include "Parameters.h" |
Igor Murashkin | 7efa520 | 2013-02-13 15:53:56 -0800 | [diff] [blame] | 25 | #include "camera/CameraMetadata.h" |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | class Camera2Client; |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame^] | 30 | class CameraDeviceBase; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 31 | class IMemory; |
| 32 | |
| 33 | namespace camera2 { |
| 34 | |
| 35 | class Camera2Heap; |
| 36 | |
| 37 | /** |
| 38 | * Management and processing for preview and recording streams |
| 39 | */ |
| 40 | class StreamingProcessor: public BufferItemConsumer::FrameAvailableListener { |
| 41 | public: |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame^] | 42 | StreamingProcessor(sp<Camera2Client> client); |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 43 | ~StreamingProcessor(); |
| 44 | |
| 45 | status_t setPreviewWindow(sp<ANativeWindow> window); |
| 46 | |
| 47 | bool haveValidPreviewWindow() const; |
| 48 | |
| 49 | status_t updatePreviewRequest(const Parameters ¶ms); |
| 50 | status_t updatePreviewStream(const Parameters ¶ms); |
| 51 | status_t deletePreviewStream(); |
| 52 | int getPreviewStreamId() const; |
| 53 | |
| 54 | status_t setRecordingBufferCount(size_t count); |
| 55 | status_t updateRecordingRequest(const Parameters ¶ms); |
| 56 | status_t updateRecordingStream(const Parameters ¶ms); |
| 57 | status_t deleteRecordingStream(); |
| 58 | int getRecordingStreamId() const; |
| 59 | |
| 60 | enum StreamType { |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 61 | NONE, |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 62 | PREVIEW, |
| 63 | RECORD |
| 64 | }; |
| 65 | status_t startStream(StreamType type, |
| 66 | const Vector<uint8_t> &outputStreams); |
| 67 | |
| 68 | status_t stopStream(); |
| 69 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 70 | // Returns the request ID for the currently streaming request |
| 71 | // Returns 0 if there is no active request. |
| 72 | status_t getActiveRequestId() const; |
| 73 | status_t incrementStreamingIds(); |
| 74 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 75 | // Callback for new recording frames from HAL |
| 76 | virtual void onFrameAvailable(); |
| 77 | // Callback from stagefright which returns used recording frames |
| 78 | void releaseRecordingFrame(const sp<IMemory>& mem); |
| 79 | |
| 80 | status_t dump(int fd, const Vector<String16>& args); |
| 81 | |
| 82 | private: |
| 83 | mutable Mutex mMutex; |
| 84 | |
| 85 | enum { |
| 86 | NO_STREAM = -1 |
| 87 | }; |
| 88 | |
| 89 | wp<Camera2Client> mClient; |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame^] | 90 | wp<CameraDeviceBase> mDevice; |
| 91 | int mId; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 92 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 93 | StreamType mActiveRequest; |
| 94 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 95 | // Preview-related members |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 96 | int32_t mPreviewRequestId; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 97 | int mPreviewStreamId; |
| 98 | CameraMetadata mPreviewRequest; |
| 99 | sp<ANativeWindow> mPreviewWindow; |
| 100 | |
| 101 | // Recording-related members |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 102 | int32_t mRecordingRequestId; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 103 | int mRecordingStreamId; |
| 104 | int mRecordingFrameCount; |
| 105 | sp<BufferItemConsumer> mRecordingConsumer; |
| 106 | sp<ANativeWindow> mRecordingWindow; |
| 107 | CameraMetadata mRecordingRequest; |
| 108 | sp<camera2::Camera2Heap> mRecordingHeap; |
| 109 | |
| 110 | static const size_t kDefaultRecordingHeapCount = 8; |
| 111 | size_t mRecordingHeapCount; |
| 112 | Vector<BufferItemConsumer::BufferItem> mRecordingBuffers; |
| 113 | size_t mRecordingHeapHead, mRecordingHeapFree; |
| 114 | |
| 115 | }; |
| 116 | |
| 117 | |
| 118 | }; // namespace camera2 |
| 119 | }; // namespace android |
| 120 | |
| 121 | #endif |