Closed Bug 1143694 Opened 9 years ago Closed 9 years ago

WebRTC looks garbled on Lollipop Gonk

Categories

(Core :: WebRTC, defect, P1)

ARM
Gonk (Firefox OS)
defect

Tracking

()

RESOLVED FIXED
mozilla40
blocking-b2g 2.2+
Tracking Status
firefox38 --- wontfix
firefox39 --- wontfix
firefox40 --- verified
b2g-v2.2 --- fixed
b2g-master --- fixed

People

(Reporter: diego, Assigned: sotaro)

References

Details

(Keywords: verifyme, Whiteboard: [caf priority: p1][CR 810038])

Attachments

(3 files, 3 obsolete files)

Loopback works fine [1].

In an actual apprtc [2] session the outgoing video of the L-gonk phone looks garbled on the remote KK phone side [3]. The incoming video looks fine on the L-gonk phone[4]. I tried this with L-phone to KK-gonk phone and L-gonk phone to Desktop. I got the same result.

Did you get a chance to try a phone to phone session on v2.2 Lollipop?

[1] http://mozilla.github.io/webrtc-landing/pc_test.html
[2] https://apprtc.appspot.com/
[3] https://www.dropbox.com/s/u9uum0yk0gy73zw/2015-03-13%2014.29.27.jpg?dl=0
[4] https://www.dropbox.com/s/umi9zo4kvw7gd8n/2015-03-13%2014.29.32.jpg?dl=0
Depends on: 1137515
diego, thanks for creating the bug. Do you enable H.264 WebRTC with the following?

> pref("media.peerconnection.video.h264_enabled", true);
Flags: needinfo?(dwilson)
I did h.264 WebRTC session with [2] between v2.2 nexus-5-l and v2.2 flame-kk, but I did not saw the problem. It might be device dependent problem.
(In reply to Sotaro Ikeda [:sotaro] from comment #1)
> diego, thanks for creating the bug. Do you enable H.264 WebRTC with the
> following?
> 
> > pref("media.peerconnection.video.h264_enabled", true);

I can reproduce this issue on my device with either H.264 enabled or disabled.
Flags: needinfo?(dwilson)
blocking-b2g: --- → 2.2?
One possibility is the following.
- WebRTC gonk implementation expect YUV420SP as camera preview's color format.
- The device's camera preview might not be YUV420SP and ConvertToI420() failed to convert the preview.
diego, can you get a log by using attachment 8578135 [details] [diff] [review] on your v2.2 lollipop device?
Flags: needinfo?(dwilson)
Remove the following from the patch.

> pref("media.peerconnection.video.h264_enabled", true);
Attachment #8578135 - Attachment is obsolete: true
Attachment #8578137 - Attachment is patch: true
Attachment #8578137 - Attachment mime type: text/x-patch → text/plain
(In reply to Sotaro Ikeda [:sotaro] from comment #6)
> diego, can you get a log by using attachment 8578135 [details] [diff] [review]
> [review] on your v2.2 lollipop device?

attachment 8578137 [details] [diff] [review] is latest log patch.
blocking-b2g: 2.2? → 2.2+
Hi Sotaro - Can you take this bug?   Thanks.
Rank: 15
Flags: needinfo?(sotaro.ikeda.g)
Flags: firefox-backlog+
Priority: -- → P1
(In reply to Maire Reavy [:mreavy] (Plz needinfo me) from comment #9)
> Hi Sotaro - Can you take this bug?   Thanks.

Okey, I could take this bug. But we do not have a hardware and development environment that could reproduce the problem. Therefore, we need help from codeaurora.
Assignee: nobody → sotaro.ikeda.g
Flags: needinfo?(sotaro.ikeda.g)
(In reply to Sotaro Ikeda [:sotaro] from comment #10)
> Okey, I could take this bug. But we do not have a hardware and development
> environment that could reproduce the problem. Therefore, we need help from
> codeaurora.

because nexus-5-l did not reproduce the problem.
Attached file Garbled preview logcat
Sotaro,

I added your patches. I see there's some color conversion errors there. I think there's something missing in the newer baseline. I'll look into in further.
Flags: needinfo?(dwilson)
Okey, thanks.
Whiteboard: [CR 810038]
Whiteboard: [CR 810038] → [caf priority: p2][CR 810038]
(ni? :dwilson based on comment 12)
Flags: needinfo?(dwilson)
Whiteboard: [caf priority: p2][CR 810038] → [caf priority: p1][CR 810038]
Turns out the issue is somewhere in webrtc image rotation:

https://mxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#722

On my device it unsuccessfully rotates the camera frames by 270 degrees which garbles the video before encoding. If I force a 0 degree rotation the video looks fine but with the wrong rotation.

Any idea what could be going wrong here?
Flags: needinfo?(dwilson) → needinfo?(sotaro.ikeda.g)
diego, mRotation seems to be calculated by MediaEngineGonkVideoSource::GetRotation(). Can you analyze it on your device?
Flags: needinfo?(sotaro.ikeda.g) → needinfo?(dwilson)
(In reply to Sotaro Ikeda [:sotaro] from comment #16)
> diego, mRotation seems to be calculated by
> MediaEngineGonkVideoSource::GetRotation().

https://dxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#522
(In reply to Sotaro Ikeda [:sotaro] from comment #17)
> (In reply to Sotaro Ikeda [:sotaro] from comment #16)
> > diego, mRotation seems to be calculated by
> > MediaEngineGonkVideoSource::GetRotation().
> 
> https://dxr.mozilla.org/mozilla-central/source/dom/media/webrtc/
> MediaEngineGonkVideoSource.cpp#522

I believe the rotation value of 270 degrees is correct. The problem is that performing that rotation [1] looks messed up. Perhaps the stride calculations [2] are not taking rotation?

[1] https://mxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#772
[2] https://mxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#770
Flags: needinfo?(dwilson)
This seems to be an alignment/rotation issue. If I force the rotated width to be aligned to 16 pixels [1] the same way the stride is being aligned [2] then the video looks ok (except for a green bar filling up the extra alignment padding).

[1] https://mxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#741
[2] https://mxr.mozilla.org/mozilla-central/source/dom/media/webrtc/MediaEngineGonkVideoSource.cpp#770
Flags: needinfo?(sotaro.ikeda.g)
(In reply to Diego Wilson [:diego] from comment #18)
> (In reply to Sotaro Ikeda [:sotaro] from comment #17)
> > (In reply to Sotaro Ikeda [:sotaro] from comment #16)
> > > diego, mRotation seems to be calculated by
> > > MediaEngineGonkVideoSource::GetRotation().
> > 
> > https://dxr.mozilla.org/mozilla-central/source/dom/media/webrtc/
> > MediaEngineGonkVideoSource.cpp#522
> 
> I believe the rotation value of 270 degrees is correct. The problem is that
> performing that rotation [1] looks messed up. Perhaps the stride
> calculations [2] are not taking rotation?

I just checked flame-kk. Its camera was also 270 degree.
Flags: needinfo?(sotaro.ikeda.g)
(In reply to Diego Wilson [:diego] from comment #18)
> (In reply to Sotaro Ikeda [:sotaro] from comment #17)
> > (In reply to Sotaro Ikeda [:sotaro] from comment #16)
> > > diego, mRotation seems to be calculated by
> > > MediaEngineGonkVideoSource::GetRotation().
> > 
> > https://dxr.mozilla.org/mozilla-central/source/dom/media/webrtc/
> > MediaEngineGonkVideoSource.cpp#522
> 
> I believe the rotation value of 270 degrees is correct. The problem is that
> performing that rotation [1] looks messed up. Perhaps the stride
> calculations [2] are not taking rotation?

Destination uses HAL_PIXEL_FORMAT_YV12, its stride is based on the following. The way of the calculation seems correct.

http://androidxref.com/5.1.0_r1/xref/system/core/include/system/graphics.h#92
(In reply to Sotaro Ikeda [:sotaro] from comment #20)
> (In reply to Diego Wilson [:diego] from comment #18)
> > (In reply to Sotaro Ikeda [:sotaro] from comment #17)
> > > (In reply to Sotaro Ikeda [:sotaro] from comment #16)
> > > > diego, mRotation seems to be calculated by
> > > > MediaEngineGonkVideoSource::GetRotation().
> > > 
> > > https://dxr.mozilla.org/mozilla-central/source/dom/media/webrtc/
> > > MediaEngineGonkVideoSource.cpp#522
> > 
> > I believe the rotation value of 270 degrees is correct. The problem is that
> > performing that rotation [1] looks messed up. Perhaps the stride
> > calculations [2] are not taking rotation?
> 
> I just checked flame-kk. Its camera was also 270 degree.

I believe the Flame camera preview defaults to 176x144 which is already 16 pixel aligned.
Add log around stride.
Attachment #8578137 - Attachment is obsolete: true
Diego, can you take a log by using attachment 8584694 [details] [diff] [review]? I wanted to know concrete stride info. Thanks.
Flags: needinfo?(dwilson)
Diego, can you test how attachment 8584717 [details] [diff] [review] works?
Sotaro,

It's definitely a stride issue. The webrtc video capture pipeline does not carry over the stride of the camera frames. One solution is to align the webrtc Y stride for YV12 to 16 pixels here:

https://mxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/common_video/libyuv/webrtc_libyuv.cc#248

What do you think?
Flags: needinfo?(dwilson) → needinfo?(sotaro.ikeda.g)
Is the 16-pixel alignment a requirement of YV12 per-se?  If so, that would be a reasonable place to put code to enforce it (or code to complain if it isn't).  However, a more general fix (perhaps additional, since it would cover all formats as needed) would be to do the graphicBuffer->GetStride() calls in the code that calls this.

(Speaking of which: sotaro, shouldn't it use GetStride for both the ConvertToI420() calls in that function?  Other than that question, r+ for the GetStride patch.)
(In reply to Diego Wilson [:diego] from comment #27)
> Sotaro,
> 
> It's definitely a stride issue. The webrtc video capture pipeline does not
> carry over the stride of the camera frames. One solution is to align the
> webrtc Y stride for YV12 to 16 pixels here:
> 
> https://mxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/
> common_video/libyuv/webrtc_libyuv.cc#248
> 
> What do you think?

I also checked the code, therefore, I created attachment 8584717 [details] [diff] [review], could you respond to comment 24 and comment 25?
Flags: needinfo?(sotaro.ikeda.g) → needinfo?(dwilson)
(In reply to Randell Jesup [:jesup] from comment #28)
> Is the 16-pixel alignment a requirement of YV12 per-se? 

I do not think it is a requirement of YV12. But it might happen often because of performance reason.
(In reply to Sotaro Ikeda [:sotaro] from comment #29)
> I also checked the code, therefore, I created attachment 8584717 [details] [diff] [review]
> [diff] [review], could you respond to comment 24 and comment 25?

Sotaro,

Your patch is for the non-gralloc case. Camera buffers (on my device at least) are gralloc buffers. When I do an equivalent change for gralloc it doesn't work. It seems the stride and the width need to have different values here as I suggest in comment 27.

And I agree with Randell that ideally we would explicitly carry over the stride but that would require changing the mediapipeline to include stride values in addition to width/height.
Flags: needinfo?(dwilson)
(In reply to Diego Wilson [:diego] from comment #31)
> (In reply to Sotaro Ikeda [:sotaro] from comment #29)
> > I also checked the code, therefore, I created attachment 8584717 [details] [diff] [review]
> > [diff] [review], could you respond to comment 24 and comment 25?
> 
> Sotaro,
> 
> Your patch is for the non-gralloc case.

Sorry, about it.

> Camera buffers (on my device at
> least) are gralloc buffers. When I do an equivalent change for gralloc it
> doesn't work. It seems the stride and the width need to have different
> values here as I suggest in comment 27.

I assume that the reason it did not work is related to the following code.

https://dxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/common_video/libyuv/webrtc_libyuv.cc#
(In reply to Sotaro Ikeda [:sotaro] from comment #32)
> I assume that the reason it did not work is related to the following code.
> 
> https://dxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/
> common_video/libyuv/webrtc_libyuv.cc#

Sorry, like was missing.

https://dxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/common_video/libyuv/webrtc_libyuv.cc#245
So what do you think of my suggestion in comment 27? Do you think that solution is too narrow?
Flags: needinfo?(sotaro.ikeda.g)
(In reply to Diego Wilson [:diego] from comment #27)
> Sotaro,
> 
> It's definitely a stride issue. The webrtc video capture pipeline does not
> carry over the stride of the camera frames. One solution is to align the
> webrtc Y stride for YV12 to 16 pixels here:
> 
> https://mxr.mozilla.org/mozilla-central/source/media/webrtc/trunk/webrtc/
> common_video/libyuv/webrtc_libyuv.cc#248
> 
> What do you think?

This code is gonk specific. It is not general YV12 code. Then as a simple fix, " Y stride for YV12 to 16 pixels" seems reasonable.
Flags: needinfo?(sotaro.ikeda.g)
But as a long term fix, we need general fix. because it is not a android YV12's requirement.
(In reply to Sotaro Ikeda [:sotaro] from comment #36)
> But as a long term fix, we need general fix. because it is not a android
> YV12's requirement.

Sorry, I misunderstood it. From the following, it is a requirement of android's YV12. Therefore, "Y stride for YV12 to 16 pixels" could be long term solution.

http://androidxref.com/5.1.0_r1/xref/system/core/include/system/graphics.h#104
Attachment #8584717 - Attachment is obsolete: true
Diego, does attachment 8587030 [details] [diff] [review] works on your device?
Flags: needinfo?(dwilson)
Comment on attachment 8587030 [details] [diff] [review]
patch - Care about gralloc YV12 stride

Review of attachment 8587030 [details] [diff] [review]:
-----------------------------------------------------------------

This patch fixes it for me. Cleared for landing!
Attachment #8587030 - Flags: feedback+
Flags: needinfo?(dwilson)
(In reply to Diego Wilson [:diego] from comment #40)
> 
> This patch fixes it for me. Cleared for landing!

Thanks for the checking!
Attachment #8587030 - Flags: review?(rjesup)
Attachment #8587030 - Flags: review?(rjesup) → review+
https://hg.mozilla.org/mozilla-central/rev/21e4e3a2b33d
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla40
Attachment #8587030 - Flags: approval-mozilla-b2g37?
Attachment #8587030 - Flags: approval-mozilla-b2g37? → approval-mozilla-b2g37+
verify 2.2 with below build

* test env
Build ID               20150406162505
Gaia Revision          485322797a069e5b185931e87d15d4e921e25b64
Gaia Date              2015-04-06 18:36:29
Gecko Revision         https://hg.mozilla.org/releases/mozilla-b2g37_v2_2/rev/f766e5052b39
Gecko Version          37.0
Device Name            hammerhead
Firmware(Release)      5.0
Firmware(Incremental)  eng.cltbld.20150406.195612
Firmware Date          Mon Apr  6 19:56:28 EDT 2015
Bootloader             HHZ12d
We don't have the device or build mentioned on comment 46. Removing this bug from our queries.
QA Whiteboard: [QAExclude]
Flags: needinfo?(jmercado)
Flags: needinfo?(jmercado)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: