Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sailfishos][webrtc] Enable support for WebRTC video. JB#53982 #3

Merged
merged 1 commit into from Aug 27, 2021

Conversation

d-grigorev
Copy link
Contributor

No description provided.

@d-grigorev d-grigorev marked this pull request as draft June 25, 2021 18:33
+namespace webrtc {
+namespace videocapturemodule {
+
+#define GST_DROID_CAMERA_PRIMARY "primary"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these still valid? I think we have to use the camera number now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is reported as camera ID, see GstDroidCameraManager::GetDeviceName() below. These names are later translated to native wording, see https://github.com/sailfishos/sailfish-components-webview/blob/7b47472eac71d31792bff2ee6766e03683a890e2/import/popups/WebrtcPermissionDialog.qml#L36

@d-grigorev d-grigorev marked this pull request as ready for review July 1, 2021 18:34
Copy link
Member

@llewelld llewelld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to do much more than a sanity check of the code I'm afraid. It broadly looks sensible and builds fine. I've made a few comments, but nothing major.

However, when I tried it on an XA2 with gmp-droid-0.2-1.2.1 I got some strange output when testing it with the meetecho Janus test server you recommended. I get the same results with both the front and back cameras, but I don't know why this is I'm afraid.

ipc::Shmem* aMem) = 0;
virtual void Dealloc(ipc::Shmem& aMem) = 0;

+ Mutex mMutex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally left it public. Thank you.

// 3* is because we're using 3 buffers per frame for i420 data for now.
- if ((NumInUse(GMPSharedMem::kGMPFrameData) >
- 3 * GMPSharedMem::kGMPBufLimit) ||
+ if ((NumInUse(GMPSharedMem::kGMPFrameData) > 3 * GMPSharedMem::kGMPBufLimit) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just an accidental formatting change. If so, it might be better to skip it from the patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've been fiddling with these lines. This is a candidate for future revision. Will remove this from the patch.

- 3 * GMPSharedMem::kGMPBufLimit) ||
+ if ((NumInUse(GMPSharedMem::kGMPFrameData) > 3 * GMPSharedMem::kGMPBufLimit) ||
(NumInUse(GMPSharedMem::kGMPEncodedData) > GMPSharedMem::kGMPBufLimit)) {
+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here; the extra newline looks unintentional.

+
+ if (deviceNameLength >= strlen(cameraName))
+ {
+ memcpy(deviceNameUTF8, cameraName, strlen(cameraName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If deviceNameLength == strlen(cameraName) then this could leave deviceNameUTF8 without a null terminator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I copied this code from media/webrtc/trunk/webrtc/modules/video_capture/linux/ and edited just to fit my internal Camera interface. I never tested it and it is not listed in supported camera types. Will review that better.

+ char* deviceUniqueIdUTF8,
+ uint32_t deviceUniqueIdUTF8Length,
+ char* productUniqueIdUTF8,
+ uint32_t productUniqueIdUTF8Length,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter that productUniqueIdUTF8 is never populated (in particular, is there any danger the caller will assume the return value will be null terminated)?

+ {
+ memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length);
+ memcpy(deviceUniqueIdUTF8, cap.bus_info,
+ strlen((const char*) cap.bus_info));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if deviceUniqueIdUTF8Length == strlen((const char*) cap.bus_info) this could leave the returned buffer without a null terminator I think.

+ rtc::scoped_refptr<Camera> OpenCamera (const char* deviceUniqueIdUTF8);
+private:
+ int32_t FillCapabilities(int fd, std::vector<VideoCaptureCapability>& caps);
+ unsigned _numberOfDevices;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _numberOfDevices needed? It looks unused.

@d-grigorev
Copy link
Contributor Author

I'm not able to do much more than a sanity check of the code I'm afraid. It broadly looks sensible and builds fine. I've made a few comments, but nothing major.

However, when I tried it on an XA2 with gmp-droid-0.2-1.2.1 I got some strange output when testing it with the meetecho Janus test server you recommended. I get the same results with both the front and back cameras, but I don't know why this is I'm afraid.

That's bad. Looks like the image format from viewfinder is totally different. I have no access to XA2 to check, and gecko is cut off the logging in production build. I will ask is someone has the device.

@d-grigorev d-grigorev marked this pull request as draft July 7, 2021 07:57
@d-grigorev d-grigorev force-pushed the jb53982 branch 2 times, most recently from f0cdb8f to d31b1f3 Compare August 6, 2021 19:46
@d-grigorev d-grigorev marked this pull request as ready for review August 6, 2021 19:53
@d-grigorev
Copy link
Contributor Author

d-grigorev commented Aug 7, 2021

Although I tested it on a sony device and it works, I found out that sony's video encoder doesn't support I420 pixel format input. The problem is in gmp-droid, a fix PR is coming soon. Unfortunately sony uses semi-planar format internally, which is not compatible with gecko's internals. Gecko has surprisingly bad design of video input, however I see some optimization opportunities here.
The only known working scenario is local echo, like https://mozilla.github.io/webrtc-landing/gum_test.html.

@d-grigorev
Copy link
Contributor Author

This patch uses https://github.com/d-grigorev/amber-camera/tree/initial as a video input library. It contains two specs, a library and a plugin. The plugin uses droidmedia-devel at build time and droidmedia at runtime.

@d-grigorev
Copy link
Contributor Author

The encoder issue is fixed in sailfishos/gmp-droid#15.

Copy link
Contributor

@adenexter adenexter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I resolved the issue with applying the last patch the echo test worked on an Xperia XA2 which was one of the earlier problem devices.

Not a lot stands out in the code otherwise.

I guess we'll need to sort out a process for promoting and reviewing amber-camera as well. The standout thing to me is there might be some similar push back to the separate spec file for the droidmedia plugin. It might be better received if it's in a separate project, or combined into a single spec with conditions.

@d-grigorev
Copy link
Contributor Author

d-grigorev commented Aug 10, 2021

I guess we'll need to sort out a process for promoting and reviewing amber-camera as well.

The lawers gave permission to contibute it to github.com/sailfishos, so what are next steps?. You can leave comments in https://github.com/d-grigorev/amber-camera/pull/1.

It might be better received if it's in a separate project, or combined into a single spec with conditions.

Isn't that convenient to have multiple specs? amber-camera headers should be accessible from pj:oss, amber-camera-droid-plugin should be built in a (common) adaptation project. The spec will be chosen depending on the OBS project name - looks clear for me. What are the disadvantages?

@adenexter
Copy link
Contributor

I guess we'll need to sort out a process for promoting and reviewing amber-camera as well.

The layers gave permission to contibute it to github.com/sailfishos, so what are next steps?. You can leave comments in d-grigorev/amber-camera#1.

An admin will need to create the project under the sailfishos group. Could you create a task in bugzilla requesting it?

It might be better received if it's in a separate project, or combined into a single spec with conditions.

Isn't that convenient to have multiple specs?

Refer to the discussion in the droidmedia split bug. I argued for separate files there because droidmedia in a unique project, but based on that I would expect a similar objection again.

@d-grigorev
Copy link
Contributor Author

Changes from the previous version:

  • The patch now applies cleanly
  • Fixed reported issues
  • Fixed hardware-backed VP8 encoding using gmp-droid

@d-grigorev
Copy link
Contributor Author

Changes from the previous version:

Copy link
Contributor

@adenexter adenexter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still want to verify this works on a Jolla C and I checked in on the promotion build of the droidmedia changes this depends on and there's a couple compilation failures related to age of the build environment.

But if I can see this working there, I think I'm ready to approve.

@d-grigorev
Copy link
Contributor Author

I still want to verify this works on a Jolla C and I checked in on the promotion build of the droidmedia changes this depends on and there's a couple compilation failures related to age of the build environment.

Unfortunately I don't have a Jolla C. The code for YCbCr template may need to be fixed in gecko-camera, if the picture is weird.

But if I can see this working there, I think I'm ready to approve.

Thank you. I have a fix for audio getting out of sync with video in the incoming stream, but I think it is matter of the following commits.

@adenexter
Copy link
Contributor

Unfortunately I don't have a Jolla C. The code for YCbCr template may need to be fixed in gecko-camera, if the picture is weird.

The droidmedia promotion has succeeded on that hardware now. And it appears to work without any display issues.

Copy link

@okodron okodron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's ready now.

@adenexter adenexter merged commit 6bf0c08 into sailfishos:master Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants