• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "Camera3-BufferManager"
19 #define ATRACE_TAG ATRACE_TAG_CAMERA
20 
21 #include <gui/ISurfaceComposer.h>
22 #include <private/gui/ComposerService.h>
23 #include <utils/Log.h>
24 #include <utils/Trace.h>
25 #include "utils/CameraTraces.h"
26 #include "Camera3BufferManager.h"
27 
28 namespace android {
29 
30 namespace camera3 {
31 
Camera3BufferManager()32 Camera3BufferManager::Camera3BufferManager() {
33 }
34 
~Camera3BufferManager()35 Camera3BufferManager::~Camera3BufferManager() {
36 }
37 
registerStream(wp<Camera3OutputStream> & stream,const StreamInfo & streamInfo)38 status_t Camera3BufferManager::registerStream(wp<Camera3OutputStream>& stream,
39         const StreamInfo& streamInfo) {
40     ATRACE_CALL();
41 
42     int streamId = streamInfo.streamId;
43     StreamSetKey streamSetKey = {streamInfo.streamSetId, streamInfo.isMultiRes};
44 
45     if (streamId == CAMERA3_STREAM_ID_INVALID ||
46             streamSetKey.id == CAMERA3_STREAM_SET_ID_INVALID) {
47         ALOGE("%s: Stream id (%d) or stream set id (%d) is invalid",
48                 __FUNCTION__, streamId, streamSetKey.id);
49         return BAD_VALUE;
50     }
51     if (streamInfo.totalBufferCount > kMaxBufferCount || streamInfo.totalBufferCount == 0) {
52         ALOGE("%s: Stream id (%d) with stream set id (%d) total buffer count %zu is invalid",
53                 __FUNCTION__, streamId, streamSetKey.id, streamInfo.totalBufferCount);
54         return BAD_VALUE;
55     }
56     if (!streamInfo.isConfigured) {
57         ALOGE("%s: Stream (%d) is not configured", __FUNCTION__, streamId);
58         return BAD_VALUE;
59     }
60 
61     // For Gralloc v1, try to allocate a buffer and see if it is successful, otherwise, stream
62     // buffer sharing for this newly added stream is not supported. For Gralloc v0, we don't
63     // need check this, as the buffers are not really shared between streams, the buffers are
64     // allocated for each stream individually, the allocation failure will be checked in
65     // getBufferForStream() call.
66     if (mGrallocVersion > HARDWARE_DEVICE_API_VERSION(0,1)) {
67         // TODO: To be implemented.
68 
69         // In case allocation fails, return invalid operation
70         return INVALID_OPERATION;
71     }
72 
73     Mutex::Autolock l(mLock);
74 
75     // Check if this stream was registered with different stream set ID, if so, error out.
76     for (size_t i = 0; i < mStreamSetMap.size(); i++) {
77         ssize_t streamIdx = mStreamSetMap[i].streamInfoMap.indexOfKey(streamId);
78         if (streamIdx != NAME_NOT_FOUND &&
79             mStreamSetMap[i].streamInfoMap[streamIdx].streamSetId != streamInfo.streamSetId &&
80             mStreamSetMap[i].streamInfoMap[streamIdx].isMultiRes != streamInfo.isMultiRes) {
81             ALOGE("%s: It is illegal to register the same stream id with different stream set",
82                     __FUNCTION__);
83             return BAD_VALUE;
84         }
85     }
86     // Check if there is an existing stream set registered; if not, create one; otherwise, add this
87     // stream info to the existing stream set entry.
88     ssize_t setIdx = mStreamSetMap.indexOfKey(streamSetKey);
89     if (setIdx == NAME_NOT_FOUND) {
90         ALOGV("%s: stream set %d(%d) is not registered to stream set map yet, create it.",
91                 __FUNCTION__, streamSetKey.id, streamSetKey.isMultiRes);
92         // Create stream info map, then add to mStreamsetMap.
93         StreamSet newStreamSet;
94         setIdx = mStreamSetMap.add(streamSetKey, newStreamSet);
95     }
96     // Update stream set map and water mark.
97     StreamSet& currentStreamSet = mStreamSetMap.editValueAt(setIdx);
98     ssize_t streamIdx = currentStreamSet.streamInfoMap.indexOfKey(streamId);
99     if (streamIdx != NAME_NOT_FOUND) {
100         ALOGW("%s: stream %d was already registered with stream set %d(%d)",
101                 __FUNCTION__, streamId, streamSetKey.id, streamSetKey.isMultiRes);
102         return OK;
103     }
104     currentStreamSet.streamInfoMap.add(streamId, streamInfo);
105     currentStreamSet.handoutBufferCountMap.add(streamId, 0);
106     currentStreamSet.attachedBufferCountMap.add(streamId, 0);
107     mStreamMap.add(streamId, stream);
108 
109     // The max allowed buffer count should be the max of buffer count of each stream inside a stream
110     // set.
111     if (streamInfo.totalBufferCount > currentStreamSet.maxAllowedBufferCount) {
112        currentStreamSet.maxAllowedBufferCount = streamInfo.totalBufferCount;
113     }
114 
115     return OK;
116 }
117 
unregisterStream(int streamId,int streamSetId,bool isMultiRes)118 status_t Camera3BufferManager::unregisterStream(int streamId, int streamSetId, bool isMultiRes) {
119     ATRACE_CALL();
120 
121     Mutex::Autolock l(mLock);
122     ALOGV("%s: unregister stream %d with stream set %d(%d)", __FUNCTION__,
123             streamId, streamSetId, isMultiRes);
124 
125     StreamSetKey streamSetKey = {streamSetId, isMultiRes};
126     if (!checkIfStreamRegisteredLocked(streamId, streamSetKey)){
127         ALOGE("%s: stream %d with set %d(%d) wasn't properly registered to this"
128                 " buffer manager!", __FUNCTION__, streamId, streamSetId, isMultiRes);
129         return BAD_VALUE;
130     }
131 
132     // De-list all the buffers associated with this stream first.
133     StreamSet& currentSet = mStreamSetMap.editValueFor(streamSetKey);
134     BufferCountMap& handOutBufferCounts = currentSet.handoutBufferCountMap;
135     BufferCountMap& attachedBufferCounts = currentSet.attachedBufferCountMap;
136     InfoMap& infoMap = currentSet.streamInfoMap;
137     handOutBufferCounts.removeItem(streamId);
138     attachedBufferCounts.removeItem(streamId);
139 
140     // Remove the stream info from info map and recalculate the buffer count water mark.
141     infoMap.removeItem(streamId);
142     currentSet.maxAllowedBufferCount = 0;
143     for (size_t i = 0; i < infoMap.size(); i++) {
144         if (infoMap[i].totalBufferCount > currentSet.maxAllowedBufferCount) {
145             currentSet.maxAllowedBufferCount = infoMap[i].totalBufferCount;
146         }
147     }
148     mStreamMap.removeItem(streamId);
149 
150     // Lazy solution: when a stream is unregistered, the streams will be reconfigured, reset
151     // the water mark and let it grow again.
152     currentSet.allocatedBufferWaterMark = 0;
153 
154     // Remove this stream set if all its streams have been removed.
155     if (handOutBufferCounts.size() == 0 && infoMap.size() == 0) {
156         mStreamSetMap.removeItem(streamSetKey);
157     }
158 
159     return OK;
160 }
161 
notifyBufferRemoved(int streamId,int streamSetId,bool isMultiRes)162 void Camera3BufferManager::notifyBufferRemoved(int streamId, int streamSetId, bool isMultiRes) {
163     Mutex::Autolock l(mLock);
164     StreamSetKey streamSetKey = {streamSetId, isMultiRes};
165     StreamSet &streamSet = mStreamSetMap.editValueFor(streamSetKey);
166     size_t& attachedBufferCount =
167             streamSet.attachedBufferCountMap.editValueFor(streamId);
168     attachedBufferCount--;
169 }
170 
checkAndFreeBufferOnOtherStreamsLocked(int streamId,StreamSetKey streamSetKey)171 status_t Camera3BufferManager::checkAndFreeBufferOnOtherStreamsLocked(
172         int streamId, StreamSetKey streamSetKey) {
173     StreamId firstOtherStreamId = CAMERA3_STREAM_ID_INVALID;
174     StreamSet &streamSet = mStreamSetMap.editValueFor(streamSetKey);
175     if (streamSet.streamInfoMap.size() == 1) {
176         ALOGV("StreamSet %d(%d) has no other stream available to free",
177                 streamSetKey.id, streamSetKey.isMultiRes);
178         return OK;
179     }
180 
181     bool freeBufferIsAttached = false;
182     for (size_t i = 0; i < streamSet.streamInfoMap.size(); i++) {
183         firstOtherStreamId = streamSet.streamInfoMap[i].streamId;
184         if (firstOtherStreamId != streamId) {
185 
186             size_t otherBufferCount  =
187                     streamSet.handoutBufferCountMap.valueFor(firstOtherStreamId);
188             size_t otherAttachedBufferCount =
189                     streamSet.attachedBufferCountMap.valueFor(firstOtherStreamId);
190             if (otherAttachedBufferCount > otherBufferCount) {
191                 freeBufferIsAttached = true;
192                 break;
193             }
194         }
195         firstOtherStreamId = CAMERA3_STREAM_ID_INVALID;
196     }
197     if (firstOtherStreamId == CAMERA3_STREAM_ID_INVALID || !freeBufferIsAttached) {
198         ALOGV("StreamSet %d(%d) has no buffer available to free",
199                 streamSetKey.id, streamSetKey.isMultiRes);
200         return OK;
201     }
202 
203 
204     // This will drop the reference to one free buffer, which will effectively free one
205     // buffer (from the free buffer list) for the inactive streams.
206     size_t totalAllocatedBufferCount = 0;
207     for (size_t i = 0; i < streamSet.attachedBufferCountMap.size(); i++) {
208         totalAllocatedBufferCount += streamSet.attachedBufferCountMap[i];
209     }
210     if (totalAllocatedBufferCount > streamSet.allocatedBufferWaterMark) {
211         ALOGV("Stream %d: Freeing buffer: detach", firstOtherStreamId);
212         sp<Camera3OutputStream> stream =
213                 mStreamMap.valueFor(firstOtherStreamId).promote();
214         if (stream == nullptr) {
215             ALOGE("%s: unable to promote stream %d to detach buffer", __FUNCTION__,
216                     firstOtherStreamId);
217             return INVALID_OPERATION;
218         }
219 
220         // Detach and then drop the buffer.
221         //
222         // Need to unlock because the stream may also be calling
223         // into the buffer manager in parallel to signal buffer
224         // release, or acquire a new buffer.
225         bool bufferFreed = false;
226         {
227             mLock.unlock();
228             sp<GraphicBuffer> buffer;
229             stream->detachBuffer(&buffer, /*fenceFd*/ nullptr);
230             mLock.lock();
231             if (buffer.get() != nullptr) {
232                 bufferFreed = true;
233             }
234         }
235         if (bufferFreed) {
236             size_t& otherAttachedBufferCount =
237                     streamSet.attachedBufferCountMap.editValueFor(firstOtherStreamId);
238             otherAttachedBufferCount--;
239         }
240     }
241 
242     return OK;
243 }
244 
getBufferForStream(int streamId,int streamSetId,bool isMultiRes,sp<GraphicBuffer> * gb,int * fenceFd,bool noFreeBufferAtConsumer)245 status_t Camera3BufferManager::getBufferForStream(int streamId, int streamSetId,
246         bool isMultiRes, sp<GraphicBuffer>* gb, int* fenceFd, bool noFreeBufferAtConsumer) {
247     ATRACE_CALL();
248 
249     Mutex::Autolock l(mLock);
250     ALOGV("%s: get buffer for stream %d with stream set %d(%d)", __FUNCTION__,
251             streamId, streamSetId, isMultiRes);
252 
253     StreamSetKey streamSetKey = {streamSetId, isMultiRes};
254     if (!checkIfStreamRegisteredLocked(streamId, streamSetKey)) {
255         ALOGE("%s: stream %d is not registered with stream set %d(%d) yet!!!",
256                 __FUNCTION__, streamId, streamSetId, isMultiRes);
257         return BAD_VALUE;
258     }
259 
260     StreamSet &streamSet = mStreamSetMap.editValueFor(streamSetKey);
261     BufferCountMap& handOutBufferCounts = streamSet.handoutBufferCountMap;
262     size_t& bufferCount = handOutBufferCounts.editValueFor(streamId);
263     BufferCountMap& attachedBufferCounts = streamSet.attachedBufferCountMap;
264     size_t& attachedBufferCount = attachedBufferCounts.editValueFor(streamId);
265 
266     if (noFreeBufferAtConsumer) {
267         attachedBufferCount = bufferCount;
268     }
269 
270     if (bufferCount >= streamSet.maxAllowedBufferCount) {
271         ALOGE("%s: bufferCount (%zu) exceeds the max allowed buffer count (%zu) of this stream set",
272                 __FUNCTION__, bufferCount, streamSet.maxAllowedBufferCount);
273         return INVALID_OPERATION;
274     }
275 
276     if (attachedBufferCount > bufferCount) {
277         // We've already attached more buffers to this stream than we currently have
278         // outstanding, so have the stream just use an already-attached buffer
279         bufferCount++;
280         return ALREADY_EXISTS;
281     }
282     ALOGV("Stream %d set %d(%d): Get buffer for stream: Allocate new",
283             streamId, streamSetId, isMultiRes);
284 
285     if (mGrallocVersion < HARDWARE_DEVICE_API_VERSION(1,0)) {
286         const StreamInfo& info = streamSet.streamInfoMap.valueFor(streamId);
287         GraphicBufferEntry buffer;
288         buffer.fenceFd = -1;
289         buffer.graphicBuffer = new GraphicBuffer(
290                 info.width, info.height, PixelFormat(info.format), info.combinedUsage,
291                 std::string("Camera3BufferManager pid [") +
292                         std::to_string(getpid()) + "]");
293         status_t res = buffer.graphicBuffer->initCheck();
294 
295         ALOGV("%s: allocating a new graphic buffer (%dx%d, format 0x%x) %p with handle %p",
296                 __FUNCTION__, info.width, info.height, info.format,
297                 buffer.graphicBuffer.get(), buffer.graphicBuffer->handle);
298         if (res < 0) {
299             ALOGE("%s: graphic buffer allocation failed: (error %d %s) ",
300                     __FUNCTION__, res, strerror(-res));
301             return res;
302         }
303         ALOGV("%s: allocation done", __FUNCTION__);
304 
305         // Increase the hand-out and attached buffer counts for tracking purposes.
306         bufferCount++;
307         attachedBufferCount++;
308         // Update the water mark to be the max hand-out buffer count + 1. An additional buffer is
309         // added to reduce the chance of buffer allocation during stream steady state, especially
310         // for cases where one stream is active, the other stream may request some buffers randomly.
311         if (bufferCount + 1 > streamSet.allocatedBufferWaterMark) {
312             streamSet.allocatedBufferWaterMark = bufferCount + 1;
313         }
314         *gb = buffer.graphicBuffer;
315         *fenceFd = buffer.fenceFd;
316         ALOGV("%s: get buffer (%p) with handle (%p).",
317                 __FUNCTION__, buffer.graphicBuffer.get(), buffer.graphicBuffer->handle);
318 
319         // Proactively free buffers for other streams if the current number of allocated buffers
320         // exceeds the water mark. This only for Gralloc V1, for V2, this logic can also be handled
321         // in returnBufferForStream() if we want to free buffer more quickly.
322         // TODO: probably should find out all the inactive stream IDs, and free the firstly found
323         // buffers for them.
324         res = checkAndFreeBufferOnOtherStreamsLocked(streamId, streamSetKey);
325         if (res != OK) {
326             return res;
327         }
328         // Since we just allocated one new buffer above, try free one more buffer from other streams
329         // to prevent total buffer count from growing
330         res = checkAndFreeBufferOnOtherStreamsLocked(streamId, streamSetKey);
331         if (res != OK) {
332             return res;
333         }
334     } else {
335         // TODO: implement this.
336         return BAD_VALUE;
337     }
338 
339     return OK;
340 }
341 
onBufferReleased(int streamId,int streamSetId,bool isMultiRes,bool * shouldFreeBuffer)342 status_t Camera3BufferManager::onBufferReleased(
343         int streamId, int streamSetId, bool isMultiRes, bool* shouldFreeBuffer) {
344     ATRACE_CALL();
345 
346     if (shouldFreeBuffer == nullptr) {
347         ALOGE("%s: shouldFreeBuffer is null", __FUNCTION__);
348         return BAD_VALUE;
349     }
350 
351     Mutex::Autolock l(mLock);
352     ALOGV("Stream %d set %d(%d): Buffer released", streamId, streamSetId, isMultiRes);
353     *shouldFreeBuffer = false;
354 
355     StreamSetKey streamSetKey = {streamSetId, isMultiRes};
356     if (!checkIfStreamRegisteredLocked(streamId, streamSetKey)){
357         ALOGV("%s: signaling buffer release for an already unregistered stream "
358                 "(stream %d with set id %d(%d))", __FUNCTION__, streamId, streamSetId,
359                 isMultiRes);
360         return OK;
361     }
362 
363     if (mGrallocVersion < HARDWARE_DEVICE_API_VERSION(1,0)) {
364         StreamSet& streamSet = mStreamSetMap.editValueFor(streamSetKey);
365         BufferCountMap& handOutBufferCounts = streamSet.handoutBufferCountMap;
366         size_t& bufferCount = handOutBufferCounts.editValueFor(streamId);
367         bufferCount--;
368         ALOGV("%s: Stream %d set %d(%d): Buffer count now %zu", __FUNCTION__, streamId,
369                 streamSetId, isMultiRes, bufferCount);
370 
371         size_t totalAllocatedBufferCount = 0;
372         size_t totalHandOutBufferCount = 0;
373         for (size_t i = 0; i < streamSet.attachedBufferCountMap.size(); i++) {
374             totalAllocatedBufferCount += streamSet.attachedBufferCountMap[i];
375             totalHandOutBufferCount += streamSet.handoutBufferCountMap[i];
376         }
377 
378         size_t newWaterMark = totalHandOutBufferCount + BUFFER_WATERMARK_DEC_THRESHOLD;
379         if (totalAllocatedBufferCount > newWaterMark &&
380                     streamSet.allocatedBufferWaterMark > newWaterMark) {
381             // BufferManager got more than enough buffers, so decrease watermark
382             // to trigger more buffers free operation.
383             streamSet.allocatedBufferWaterMark = newWaterMark;
384             ALOGV("%s: Stream %d set %d(%d): watermark--; now %zu",
385                     __FUNCTION__, streamId, streamSetId, isMultiRes,
386                     streamSet.allocatedBufferWaterMark);
387         }
388 
389         size_t attachedBufferCount = streamSet.attachedBufferCountMap.valueFor(streamId);
390         if (attachedBufferCount <= bufferCount) {
391             ALOGV("%s: stream %d has no buffer available to free.", __FUNCTION__, streamId);
392         }
393 
394         bool freeBufferIsAttached = (attachedBufferCount > bufferCount);
395         if (freeBufferIsAttached &&
396                 totalAllocatedBufferCount > streamSet.allocatedBufferWaterMark &&
397                 attachedBufferCount > bufferCount + BUFFER_FREE_THRESHOLD) {
398             ALOGV("%s: free a buffer from stream %d", __FUNCTION__, streamId);
399             *shouldFreeBuffer = true;
400         }
401     } else {
402         // TODO: implement gralloc V1 support
403         return BAD_VALUE;
404     }
405 
406     return OK;
407 }
408 
onBuffersRemoved(int streamId,int streamSetId,bool isMultiRes,size_t count)409 status_t Camera3BufferManager::onBuffersRemoved(int streamId, int streamSetId,
410         bool isMultiRes, size_t count) {
411     ATRACE_CALL();
412     Mutex::Autolock l(mLock);
413 
414     ALOGV("Stream %d set %d(%d): Buffer removed", streamId, streamSetId, isMultiRes);
415 
416     StreamSetKey streamSetKey = {streamSetId, isMultiRes};
417     if (!checkIfStreamRegisteredLocked(streamId, streamSetKey)){
418         ALOGV("%s: signaling buffer removal for an already unregistered stream "
419                 "(stream %d with set id %d(%d))", __FUNCTION__, streamId, streamSetId, isMultiRes);
420         return OK;
421     }
422 
423     if (mGrallocVersion < HARDWARE_DEVICE_API_VERSION(1,0)) {
424         StreamSet& streamSet = mStreamSetMap.editValueFor(streamSetKey);
425         BufferCountMap& handOutBufferCounts = streamSet.handoutBufferCountMap;
426         size_t& totalHandoutCount = handOutBufferCounts.editValueFor(streamId);
427         BufferCountMap& attachedBufferCounts = streamSet.attachedBufferCountMap;
428         size_t& totalAttachedCount = attachedBufferCounts.editValueFor(streamId);
429 
430         if (count > totalHandoutCount) {
431             ALOGE("%s: Removed buffer count %zu greater than current handout count %zu",
432                     __FUNCTION__, count, totalHandoutCount);
433             return BAD_VALUE;
434         }
435         if (count > totalAttachedCount) {
436             ALOGE("%s: Removed buffer count %zu greater than current attached count %zu",
437                   __FUNCTION__, count, totalAttachedCount);
438             return BAD_VALUE;
439         }
440 
441         totalHandoutCount -= count;
442         totalAttachedCount -= count;
443         ALOGV("%s: Stream %d set %d(%d): Buffer count now %zu, attached buffer count now %zu",
444                 __FUNCTION__, streamId, streamSetId, isMultiRes, totalHandoutCount,
445                 totalAttachedCount);
446     } else {
447         // TODO: implement gralloc V1 support
448         return BAD_VALUE;
449     }
450 
451     return OK;
452 }
453 
dump(int fd,const Vector<String16> & args) const454 void Camera3BufferManager::dump(int fd, const Vector<String16>& args) const {
455     Mutex::Autolock l(mLock);
456 
457     (void) args;
458     String8 lines;
459     lines.appendFormat("      Total stream sets: %zu\n", mStreamSetMap.size());
460     for (size_t i = 0; i < mStreamSetMap.size(); i++) {
461         lines.appendFormat("        Stream set %d(%d) has below streams:\n",
462                 mStreamSetMap.keyAt(i).id, mStreamSetMap.keyAt(i).isMultiRes);
463         for (size_t j = 0; j < mStreamSetMap[i].streamInfoMap.size(); j++) {
464             lines.appendFormat("          Stream %d\n", mStreamSetMap[i].streamInfoMap[j].streamId);
465         }
466         lines.appendFormat("          Stream set max allowed buffer count: %zu\n",
467                 mStreamSetMap[i].maxAllowedBufferCount);
468         lines.appendFormat("          Stream set buffer count water mark: %zu\n",
469                 mStreamSetMap[i].allocatedBufferWaterMark);
470         lines.appendFormat("          Handout buffer counts:\n");
471         for (size_t m = 0; m < mStreamSetMap[i].handoutBufferCountMap.size(); m++) {
472             int streamId = mStreamSetMap[i].handoutBufferCountMap.keyAt(m);
473             size_t bufferCount = mStreamSetMap[i].handoutBufferCountMap.valueAt(m);
474             lines.appendFormat("            stream id: %d, buffer count: %zu.\n",
475                     streamId, bufferCount);
476         }
477         lines.appendFormat("          Attached buffer counts:\n");
478         for (size_t m = 0; m < mStreamSetMap[i].attachedBufferCountMap.size(); m++) {
479             int streamId = mStreamSetMap[i].attachedBufferCountMap.keyAt(m);
480             size_t bufferCount = mStreamSetMap[i].attachedBufferCountMap.valueAt(m);
481             lines.appendFormat("            stream id: %d, attached buffer count: %zu.\n",
482                     streamId, bufferCount);
483         }
484     }
485     write(fd, lines.string(), lines.size());
486 }
487 
checkIfStreamRegisteredLocked(int streamId,StreamSetKey streamSetKey) const488 bool Camera3BufferManager::checkIfStreamRegisteredLocked(int streamId,
489         StreamSetKey streamSetKey) const {
490     ssize_t setIdx = mStreamSetMap.indexOfKey(streamSetKey);
491     if (setIdx == NAME_NOT_FOUND) {
492         ALOGV("%s: stream set %d(%d) is not registered to stream set map yet!",
493                 __FUNCTION__, streamSetKey.id, streamSetKey.isMultiRes);
494         return false;
495     }
496 
497     ssize_t streamIdx = mStreamSetMap.valueAt(setIdx).streamInfoMap.indexOfKey(streamId);
498     if (streamIdx == NAME_NOT_FOUND) {
499         ALOGV("%s: stream %d is not registered to stream info map yet!", __FUNCTION__, streamId);
500         return false;
501     }
502 
503     size_t bufferWaterMark = mStreamSetMap[setIdx].maxAllowedBufferCount;
504     if (bufferWaterMark == 0 || bufferWaterMark > kMaxBufferCount) {
505         ALOGW("%s: stream %d with stream set %d(%d) is not registered correctly to stream set map,"
506                 " as the water mark (%zu) is wrong!",
507                 __FUNCTION__, streamId, streamSetKey.id, streamSetKey.isMultiRes,
508                 bufferWaterMark);
509         return false;
510     }
511 
512     return true;
513 }
514 
515 } // namespace camera3
516 } // namespace android
517