justinjoy / gst-android-camera

GNU Lesser General Public License v2.1
32 stars 9 forks source link

Camera View is black #13

Closed jainricha closed 3 years ago

jainricha commented 3 years ago

Hi,

I am trying to use gstreamer to stream my android phone camera to gstreamer server. I managed to run this app on my android phone, however the camera is not being shown. All I can see is black screen where the camera stream should have come.

Refer screenshot.

I tried the other app available in your repo which is native-camera2, and it does work as expected.

What can i do to make gst-android-camera work? What can be the problem here? I am not an expert in android development and hence would like to seek your advise.

Looking forward for some quick help.

justinjoy commented 3 years ago

Have you checked application permission whether it is able to access camera device?

jainricha commented 3 years ago

Have you checked application permission whether it is able to access camera device?

Yes. The camera permission is On. Do you have native-camera2 and gstreamer integrated in the same app? As i said native-camera2 app is able to show the camera. I have been trying to make gst-android-camera work from last two weeks with no success :( badly need help here. Please suggest.

jainricha commented 3 years ago

Have you checked application permission whether it is able to access camera device?

Any updates to this issue?

justinjoy commented 3 years ago

Any updates to this issue?

Could you share a gstreamer log with GST_DEBUG=ahcsrc:5,*:3 ?

jainricha commented 3 years ago

Any updates to this issue?

Could you share a gstreamer log with GST_DEBUG=ahcsrc:5,*:3 ? Attaching the logs here. You may see rtsp connection issues in the logs because my rtsp server was not running, but the primary issue is that the camera surface view is black. app.txt

jainricha commented 3 years ago

Any updates to this issue?

Could you share a gstreamer log with GST_DEBUG=ahcsrc:5,*:3 ? Attaching the logs here. You may see rtsp connection issues in the logs because my rtsp server was not running, but the primary issue is that the camera surface view is black. app.txt

Did you get a chance to check the logs please?

justinjoy commented 3 years ago

From the attached log, I can see the following message. It seems that you are not using the right version of GStreamer SDK. Or, at least, your android package is missing some build files. Which version of SDK are you using and what's the exact sequence to build this project?

2020-09-25 17:54:14.752 25891-25891/org.freedesktop.gstreamer.examples.camera E/GStreamer+ahc: 0:00:00.109839423 0x7c7db4ed20 ../sys/androidmedia/gst-android-hardware-camera.c:1763:_init_classes Failed to initialize android.hardware.Camera classes: Failed to get static field ID EFFECT_EMBOSS (Ljava/lang/String;): java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "EFFECT_EMBOSS" in class "Landroid/hardware/Camera$Parameters;" or its superclasses
    java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "EFFECT_EMBOSS" in class "Landroid/hardware/Camera$Parameters;" or its superclasses
        at org.freedesktop.gstreamer.GStreamer.nativeInit(Native Method)
        at org.freedesktop.gstreamer.GStreamer.init(GStreamer.java:18)
        at org.freedesktop.gstreamer.camera.GstAhc.init(GstAhc.java:92)
        at org.freedesktop.gstreamer.camera.CameraActivity.onCreate(CameraActivity.java:120)
        at android.app.Activity.performCreate(Activity.java:7963)
        at android.app.Activity.performCreate(Activity.java:7952)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLa

Also when you run, your application couldn't find ahcsrc and x264enc. I guess it's the issue of build and packaging, rather than this project.

2020-09-25 17:54:14.799 25891-25891/org.freedesktop.gstreamer.examples.camera I/GStreamer: GStreamer initialization complete
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera W/GStreamer+GST_ELEMENT_FACTORY: 0:00:00.157913538 0x7c7c7e7d20 ../gst/gstelementfactory.c:465:gst_element_factory_make no such element factory "ahcsrc"!
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera E/GStreamer+GST_PIPELINE: 0:00:00.157959461 0x7c7c7e7d20 gst/parse/grammar.y:850:priv_gst_parse_yyparse no element "ahcsrc"
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera E/GStreamer+GST_PIPELINE: 0:00:00.158041500 0x7c7c7e7d20 gst/parse/grammar.y:938:priv_gst_parse_yyparse link has no source [sink=@0x7c848d17d0]
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera W/GStreamer+GST_ELEMENT_FACTORY: 0:00:00.158055269 0x7c7c7e7d20 ../gst/gstelementfactory.c:465:gst_element_factory_make no such element factory "x264enc"!
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera E/GStreamer+GST_PIPELINE: 0:00:00.158065961 0x7c7c7e7d20 gst/parse/grammar.y:850:priv_gst_parse_yyparse no element "x264enc"
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera E/GStreamer+GST_PIPELINE: 0:00:00.158076307 0x7c7c7e7d20 gst/parse/grammar.y:938:priv_gst_parse_yyparse link has no sink [source=@0x7c848d17d0]
2020-09-25 17:54:14.800 25891-29159/org.freedesktop.gstreamer.examples.camera E/GStreamer+GST_PIPELINE: 0:00:00.158167923 0x7c7c7e7d20 gst/parse/grammar.y:938:priv_gst_parse_yyparse link has no source [sink=@0x7c848d1c20]
jainricha commented 3 years ago

@justinjoy Is it possible for you to share your working version along with the gstreamer binaries you use? So that I can try replicating your working setup. I have tried but, it is not working for me in anyway.

justinjoy commented 3 years ago

@justinjoy Is it possible for you to share your working version along with the gstreamer binaries you use? So that I can try replicating your working setup. I have tried but, it is not working for me in anyway.

I don't think I have a special different way to enable this example code. GStreamer SDK[1] and its example code[2] are better to understand.

[1] https://gstreamer.freedesktop.org/documentation/installing/for-android-development.html?gi-language=c [2] https://gstreamer.freedesktop.org/documentation/tutorials/android/index.html?gi-language=c

jainricha commented 3 years ago

@justinjoy Is it possible for you to share your working version along with the gstreamer binaries you use? So that I can try replicating your working setup. I have tried but, it is not working for me in anyway.

I don't think I have a special different way to enable this example code. GStreamer SDK[1] and its example code[2] are better to understand.

[1] https://gstreamer.freedesktop.org/documentation/installing/for-android-development.html?gi-language=c [2] https://gstreamer.freedesktop.org/documentation/tutorials/android/index.html?gi-language=c

@justinjoy Do you have any recommendations for the version of Gstreamer to use with Android api version 28-30?

justinjoy commented 3 years ago

Please refer to GStreamer official webpage to choose the right SDK version. The important thing is GStreamer compatible NDK version. According to the download page[1], you can use r18b for GSt 1.16 or r21 for GST 1.18.

[1] https://gstreamer.freedesktop.org/download

jainricha commented 3 years ago

Please refer to GStreamer official webpage to choose the right SDK version. The important thing is GStreamer compatible NDK version. According to the download page[1], you can use r18b for GSt 1.16 or r21 for GST 1.18.

[1] https://gstreamer.freedesktop.org/download

thanks, that helped. I can now see the camera view correctly.

Can you help me in getting this camera stream to use rtspclientsink location=

How can I update this piece of code:

f(!gst_element_factory_find("ahcsrc")) GST_DEBUG("Couldn't find ahcsrc"); ahc->ahcsrc = gst_element_factory_make ("ahcsrc", "ahcsrc"); if(!ahc->ahcsrc) GST_ERROR("Couldn't create ahcsrc"); ahc->vsink = gst_element_factory_make ("glimagesink", "vsink"); if(!ahc->vsink) GST_ERROR("Couldn't create vsink"); ahc->filter = gst_element_factory_make ("capsfilter", NULL); if(!ahc->filter) GST_ERROR("Couldn't create filter");

to something equivalent to the below pipeline: ahcsrc ! videoconvert ! x264enc ! rtspclientsink location=rtsp://IP:PORT

Please suggest. I tried making a few changes but every change I do again causes camera to turn black.

jainricha commented 3 years ago

Hi @justinjoy

This is working for me now, The only problem which I face now is that the output video is coming 90 degree anti- clockwise rotated.

Below is the pipeline working for me: ahcsrc ! videoconvert ! rtspclientsink location=rtsp://IP:PORT

How can I have control over the rotation of video frame. Please help here before I can close this. Thanks and advance,

justinjoy commented 3 years ago

This is working for me now,

That's good to know.

can I have control over the rotation of video frame.

There are two options for video orientation.

ahcsrc has a device-orientation property that allows setting clockwise rotation. it should be one of 0, 90, 180, and 270, but I am not sure if every device supports the property.

Another option is adding videoflip element[1], but it will consume CPU.

[1]https://gstreamer.freedesktop.org/documentation/videofilter/videoflip.html

jainricha commented 3 years ago

Thanks @justinjoy , videoflip helped.

However on another Android 10 (Huawei Mate) device I am seeing camera is again black and I am seeing few errors:

2021-03-31 17:48:38.434 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Callback buffer was too small! Expected 3191552 bytes, but got 3179904 bytes!

2021-03-31 17:48:38.434 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Couldn't allocate byte array for JPEG data

2021-03-31 17:48:38.467 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Callback buffer was too small! Expected 3191552 bytes, but got 3179904 bytes!

2021-03-31 17:48:38.467 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Couldn't allocate byte array for JPEG data

2021-03-31 17:48:38.504 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Callback buffer was too small! Expected 3191552 bytes, but got 3179904 bytes!

2021-03-31 17:48:38.505 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Couldn't allocate byte array for JPEG data

2021-03-31 17:48:38.537 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Callback buffer was too small! Expected 3191552 bytes, but got 3179904 bytes!

2021-03-31 17:48:38.537 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Couldn't allocate byte array for JPEG data

2021-03-31 17:48:38.571 1718-1747/org.freedesktop.gstreamer.examples.camera E/Camera-JNI: Callback buffer was too small! Expected 3191552 bytes, but got 3179904 bytes!

What could be the possible root cause and resolution? Please help. Probably this is the last step for what I want to achieve.

justinjoy commented 3 years ago

What could be the possible root cause and resolution?

Not sure but it looks like the message comes from your changes because this example doesn't use JPEG. Even it doesn't pass any data from native to Java except glimagesink.

jainricha commented 3 years ago

What could be the possible root cause and resolution?

Not sure but it looks like the message comes from your changes because this example doesn't use JPEG. Even it doesn't pass any data from native to Java except glimagesink.

@justinjoy Even my changes does not have any JPEG reference. I also removed all my changes, and I am still seeing this issue on this particular device.

justinjoy commented 3 years ago

@justinjoy Even my changes does not have any JPEG reference. I also removed all my changes, and I am still seeing this issue on this particular device.

I guess you already know the reason because you were able to see the issue in the particular devices.

IMHO, the default output of the device is 'JPEG'. If saying as gstreamer norm, it will be image/jpeg.

You can change the format by setting a right caps to capsfilter before going to PLAYING.

Or, using jpegdec right after ahcsrc can be a solution if the device sends jpeg stream.

jainricha commented 3 years ago

@justinjoy capsfilter worked. Thanks for all the help. Closing this issue.