Closed
Bug 844248
Opened 11 years ago
Closed 11 years ago
MediaStreamGraph adds lag to CameraPreview drawing update
Categories
(Core :: Audio/Video, defect)
Tracking
()
People
(Reporter: sotaro, Assigned: sotaro)
References
Details
Attachments
(3 files, 16 obsolete files)
110.41 KB,
application/pdf
|
Details | |
12.92 KB,
patch
|
sotaro
:
review+
|
Details | Diff | Splinter Review |
12.91 KB,
patch
|
sotaro
:
review+
|
Details | Diff | Splinter Review |
Camera preview has a noticeable lag. It is very slow than android's preivew screen. And preview update is jaggy, not smooth. It seems that a camera hal regularly drops preview frames. The camera hal expects following. - preview images are rendered as soon as possible - rendered images are returned to ANativeWindow as soon as possible But MediaStreamGraph add some delay(about 30ms) to preview images and they are not released soon. MediaStreamGraph is not the only place of the camera preview's lag. But it is one of the major place to do it.
Assignee | ||
Comment 1•11 years ago
|
||
Camera preview images are put into MediaStreamGraph in DOMCameraPreview::ReceiveFrame(). And they come out from MediaStreamGraph in MediaStreamGraphImpl::PlayVideo() by calling VideoFrameContainer::SetCurrentFrame(). http://mxr.mozilla.org/mozilla-central/source/dom/camera/DOMCameraPreview.cpp#202 http://mxr.mozilla.org/mozilla-central/source/content/media/MediaStreamGraph.cpp#818
Assignee | ||
Comment 2•11 years ago
|
||
The patch add logout with timestamp by ms resolution.
Assignee | ||
Comment 3•11 years ago
|
||
Assignee | ||
Comment 4•11 years ago
|
||
Total camera Preview delay seems more than 100ms. I am going to measure a delay around MediaStreamGraph more correctly.
Assignee | ||
Comment 5•11 years ago
|
||
A diagram to help understanding around DOMCameraPreview.
Assignee | ||
Comment 6•11 years ago
|
||
I found following problems around using MediaStreamGraph for camera preview. [1] MediaStreamGraph is a framework for synchronized audio/video processing and playback.But camera preview's requirements are totally opposite. Render images as soon as possible and release them as soon as possible. But we need to use MediaStreamGraph to render camera preview to video tag. [2] DOMCameraPreview set the TrackTick's resolution to preview FPS. The FPS of otoro device is 30. Then each frame becomes 33.3 ms. It is too low resolution. MediaStreamGraph controls video out and buffers free depend on the TrackTick. Images rendering and release could delay by 33.3 ms resolution. [3] camera preview FPS is best effort. The FPS is not guaranteed. MediaStreamGraph expects FPS is guranteed. On otoro device, it seems that an autual FPS is more fast. More Images are going to stored within MediaStreamGraph. But because of this, camera hal becomes starved of Images and stop to post new preview image. After when MediaStreamGraph renders and releases images, camera hal can receive new image for preview and re-start to post new preview image. [4] MediaStreamGraph expects video track buffers images until 30ms future rendering. If it is not, the track is decided as blocked. [5] StreamBuffer release Images by 50ms resolution. It could delay release Images. [6] Media graph thread runs by 10ms resolution.
Assignee | ||
Comment 7•11 years ago
|
||
add log of actual delay of Image within MediaStreamGraph.
Attachment #717266 -
Attachment is obsolete: true
Assignee | ||
Comment 8•11 years ago
|
||
Image get delay about 30ms and 70ms each.
Attachment #717267 -
Attachment is obsolete: true
Assignee | ||
Comment 9•11 years ago
|
||
Just a temporary patch to use Timestamp. But by applying the patch, frame delay and jitter becomes more significant. It happens because GraphcBuffers are not returned to GonkNativeWindow soon, then camera hal starves GraphcBuffer and slowdown preview frames update.
Assignee | ||
Comment 12•11 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #9) > Created attachment 723605 [details] [diff] [review] > Temporary patch - add timestamp > > Just a temporary patch to use Timestamp. > But by applying the patch, frame delay and jitter becomes more significant. > It happens because GraphcBuffers are not returned to GonkNativeWindow soon, > then camera hal starves GraphcBuffer and slowdown preview frames update. To address timestamp problem, it is also nedessary to solve the buffer starvation problem.
Assignee | ||
Comment 13•11 years ago
|
||
As I wrote in Bug 848627 comment #6 . There are two ways to solve the buffer starvation problem. > There are 2 ways to solve this problem. Both ways are very risky and need > more gralloc buffers. > [1] Increment MIN_UNDEQUEUED_BUFFERS from 2 to some value. Ensure the max > number of gralloc buffers between GonkNativeWindow and Compositor. Modify > camera hal to accept MIN_UNDEQUEUED_BUFFERS more than 2. > > [2] Copy preview frames for rendering and GonkNativeWindow run in async > mode. The copied frames are throwed out of GonkNativeWindow for rendering. > Original frames stay within GonkNativeWindow.
Assignee | ||
Comment 14•11 years ago
|
||
[1] needs to fix camera hal. I do not have a way to do it. Then I am going to write temporary patch of [2].
Comment 15•11 years ago
|
||
What about modifying MediaStream to not hold onto so many frames? Even if we solve the other problems, MediaStream hanging onto three frames means the preview will lag reality by at least ~100ms (and I typically measure more like ~200ms).
Assignee | ||
Comment 16•11 years ago
|
||
Implement [2] and add timestamp. I confirmed the patch on unagi. Preview update seems work. It becomes much better. On recording mode without recording, preview FPS becomes about 29-30. But in camera mode, after when I took a picture. camera app abort because of out of memory(gralloc buffer). As a side effect, mode change between "video mode" and "camera mode" becomes very fast. Current implementation is very slow of the change, it seems that dequeueBuffer() slowness make it happens.
Assignee | ||
Comment 17•11 years ago
|
||
(In reply to Mike Habicher [:mikeh] from comment #15) > What about modifying MediaStream to not hold onto so many frames? Even if > we solve the other problems, MediaStream hanging onto three frames means the > preview will lag reality by at least ~100ms (and I typically measure more > like ~200ms). Yeah, it is necessary. [1] is a correct way to fix buffer starvation problem. To do it, it is necessary.
Assignee | ||
Comment 18•11 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #16) > Created attachment 724585 [details] [diff] [review] > Temporary patch - add timestamp, copy video frames and GonkNativeWindow run > in async mode > > Implement [2] and add timestamp. > > I confirmed the patch on unagi. Preview update seems work. It becomes much > better. On recording mode without recording, preview FPS becomes about > 29-30. But in camera mode, after when I took a picture. camera app abort > because of out of memory(gralloc buffer). In camera mode, preview video size is 480*320, it is larger than record mode(352*288). And the copy takes about 10ms-25ms. It is a very very long time. Then [1] is a way to correct fix.
Comment 19•11 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #6) > I found following problems around using MediaStreamGraph for camera preview. > > [3] camera preview FPS is best effort. The FPS is not guaranteed. > MediaStreamGraph expects FPS is guranteed. On otoro device, it seems that an > autual FPS is more fast. More Images are going to stored within > MediaStreamGraph. But because of this, camera hal becomes starved of Images > and stop to post new preview image. After when MediaStreamGraph renders and > releases images, camera hal can receive new image for preview and re-start > to post new preview image. Could we config the graph to render as soon as possible? Maybe roc could give some input about media graph.
Comment 20•11 years ago
|
||
See bug 848627 comment 15.
Assignee | ||
Comment 22•11 years ago
|
||
checked the delay within MediaStreamGraph by applying the following patches - attachment 724585 [details] [diff] [review] - attachment 725046 [details] [diff] [review] Camera mode: ~120ms delay Video mode: ~90ms delay
Assignee | ||
Comment 23•11 years ago
|
||
Add a custom MediaStream "CameraPreviewMediaStream". The class directly send Image to VideoFrameContainer without delay and buffering. The patch is a temporary ugly hack patch. It is just to confirm "no delay" and "no buffering" at MediaStream on unagi device. The patch cause crash when changing camera/video mode in camera app.
Assignee | ||
Comment 24•11 years ago
|
||
In previous patch, I forgot to add CameraPreviewMediaStream...
Attachment #725475 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Attachment #721763 -
Attachment is obsolete: true
Assignee | ||
Comment 25•11 years ago
|
||
Comment on attachment 725478 [details] [diff] [review] Temporary patch v2 - add a custom media stream for camera preview roc, can you give me an advice about how to solve the delay and jitter problem? I am thinking to create the custom MediaStream. Is it a way to go?
Attachment #725478 -
Flags: feedback?(roc)
Assignee | ||
Comment 26•11 years ago
|
||
fix crash after video/camera mode change.
Attachment #725478 -
Attachment is obsolete: true
Attachment #725478 -
Flags: feedback?(roc)
Assignee | ||
Updated•11 years ago
|
Attachment #726207 -
Flags: feedback?(roc)
Assignee | ||
Comment 27•11 years ago
|
||
a patch for b2g18 of attachment 726207 [details] [diff] [review]
Comment 28•11 years ago
|
||
Confirmed on unagi built against inbound-src. That's a noticeable and significant improvement to the viewfinder.
Comment on attachment 726207 [details] [diff] [review] Temporary patch v3 - add a custom media stream for camera preview Review of attachment 726207 [details] [diff] [review]: ----------------------------------------------------------------- I think this is a reasonable temporary fix. ::: dom/camera/CameraPreviewMediaStream.cpp @@ +35,5 @@ > + mIsConsumed = true; > + for (uint32_t j = 0; j < mListeners.Length(); ++j) { > + MediaStreamListener* l = mListeners[j]; > + l->NotifyConsumptionChanged(gm, MediaStreamListener::CONSUMED); > + } You're not handling the case where there are multiple video outputs for the same stream.
Attachment #726207 -
Flags: feedback?(roc) → feedback+
Assignee | ||
Comment 30•11 years ago
|
||
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #29) > Comment on attachment 726207 [details] [diff] [review] > Temporary patch v3 - add a custom media stream for camera preview > > Review of attachment 726207 [details] [diff] [review]: > ----------------------------------------------------------------- > > I think this is a reasonable temporary fix. > > ::: dom/camera/CameraPreviewMediaStream.cpp > @@ +35,5 @@ > > + mIsConsumed = true; > > + for (uint32_t j = 0; j < mListeners.Length(); ++j) { > > + MediaStreamListener* l = mListeners[j]; > > + l->NotifyConsumptionChanged(gm, MediaStreamListener::CONSUMED); > > + } > > You're not handling the case where there are multiple video outputs for the > same stream. Thank you for the comment. I will fix it in a next patch.
Assignee | ||
Updated•11 years ago
|
Attachment #723605 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Attachment #724585 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Attachment #725046 -
Attachment is obsolete: true
Assignee | ||
Comment 31•11 years ago
|
||
address the comment.
Attachment #726207 -
Attachment is obsolete: true
Assignee | ||
Comment 33•11 years ago
|
||
Comment on attachment 726939 [details] [diff] [review] patch v5 - add a custom media stream for camera preview roc, can you review the patch?
Attachment #726939 -
Flags: review?(roc)
Attachment #726939 -
Flags: review?(roc) → review+
Assignee | ||
Comment 34•11 years ago
|
||
commitable patch. Carry "roc: review+".
Attachment #726939 -
Attachment is obsolete: true
Attachment #726993 -
Flags: review+
Assignee | ||
Comment 35•11 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&rev=2a5148ee5563
Assignee | ||
Comment 36•11 years ago
|
||
unbitrot. Carry "roc: review+".
Attachment #726993 -
Attachment is obsolete: true
Attachment #727167 -
Flags: review+
Assignee | ||
Comment 37•11 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #35) > https://tbpl.mozilla.org/?tree=Try&rev=2a5148ee5563 There are some oranges in some platforms than B2G. They are not related to the patch. Camera API is enabled only on b2g right now.
Assignee | ||
Updated•11 years ago
|
Attachment #726242 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Keywords: checkin-needed
Comment 38•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/34a9d115d704
Keywords: checkin-needed
Assignee | ||
Comment 39•11 years ago
|
||
A patch for b2g 18. attachment 727167 [details] [diff] [review] is not applicable to b2g18. Confirmed the patch on unagi phone.
Assignee | ||
Comment 40•11 years ago
|
||
Comment on attachment 727189 [details] [diff] [review] patch v7 for b2g18 - add a custom media stream for camera preview Carry "roc: review+".
Attachment #727189 -
Flags: review+
Assignee | ||
Comment 41•11 years ago
|
||
Add header to the patch. Carry "roc: review+".
Attachment #727189 -
Attachment is obsolete: true
Attachment #727311 -
Flags: review+
Comment 42•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/34a9d115d704
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla22
Comment 43•11 years ago
|
||
https://hg.mozilla.org/releases/mozilla-b2g18/rev/66374e4c72b3 https://hg.mozilla.org/releases/mozilla-b2g18_v1_0_1/rev/6436bb6e2070
status-b2g18:
--- → fixed
status-b2g18-v1.0.0:
--- → wontfix
status-b2g18-v1.0.1:
--- → fixed
status-firefox20:
--- → wontfix
status-firefox21:
--- → wontfix
status-firefox22:
--- → fixed
Comment 44•11 years ago
|
||
Backed out on v1_0_1 for warnings-as-errors bustage. I didn't feel comfortable removing the line myself not knowing if the variable not being used was on purpose or an oversight. https://hg.mozilla.org/releases/mozilla-b2g18_v1_0_1/rev/832054c341d1 https://tbpl.mozilla.org/php/getParsedLog.php?id=20932196&tree=Mozilla-B2g18_v1_0_1 ../../../../dom/camera/CameraPreviewMediaStream.cpp:83:21: error: unused variable 'gm' [-Werror,-Wunused-variable] MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); ^ 1 error generated. make[7]: *** [CameraPreviewMediaStream.o] Error 1
Comment 45•11 years ago
|
||
Backed out on b2g18 for the same reason. https://hg.mozilla.org/releases/mozilla-b2g18/rev/7f909f971542
Assignee | ||
Comment 46•11 years ago
|
||
(In reply to Ryan VanderMeulen [:RyanVM] from comment #44) > Backed out on v1_0_1 for warnings-as-errors bustage. I didn't feel > comfortable removing the line myself not knowing if the variable not being > used was on purpose or an oversight. > https://hg.mozilla.org/releases/mozilla-b2g18_v1_0_1/rev/832054c341d1 > > https://tbpl.mozilla.org/php/getParsedLog.php?id=20932196&tree=Mozilla- > B2g18_v1_0_1 > > ../../../../dom/camera/CameraPreviewMediaStream.cpp:83:21: error: unused > variable 'gm' [-Werror,-Wunused-variable] > MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); > ^ > 1 error generated. > make[7]: *** [CameraPreviewMediaStream.o] Error 1 sorry for the bustage.
Assignee | ||
Comment 47•11 years ago
|
||
fix "unused variable". Carry "roc: review+".
Attachment #727311 -
Attachment is obsolete: true
Attachment #727829 -
Flags: review+
Assignee | ||
Comment 48•11 years ago
|
||
confirm fix for b2g18 on try https://tbpl.mozilla.org/?tree=Try&rev=ecb514d9053f
Comment 49•11 years ago
|
||
https://hg.mozilla.org/releases/mozilla-b2g18/rev/375c6e57eaa1 https://hg.mozilla.org/releases/mozilla-b2g18_v1_0_1/rev/03a9ad79a72d
You need to log in
before you can comment on or make changes to this bug.
Description
•