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

Finalize recording state policy #44

Merged
merged 5 commits into from
Apr 1, 2022
Merged

Finalize recording state policy #44

merged 5 commits into from
Apr 1, 2022

Conversation

matze
Copy link
Contributor

@matze matze commented Aug 13, 2014

This change fixes and unifies handling of different "is-recording" states. First
of all there are potentially two different states: the priv->is_recording state
from the base class and some device-specific state. Device authors can override
the "is-recording" property to provide device-specific information. This change
sets the global recording state as follows:

  1. uca_camera_is_recording returns the value of ::is-recording.
  2. priv->is_recording is the default state that is returned for ::is-recording
    and set after successfully calling uca_camera_start_recording and
    uca_camera_stop_recording.
  3. uca_camera_start_recording, uca_camera_stop_recording, uca_camera_trigger
    use ::is-recording to determine how to proceed.
  4. For performance reasons, uca_camera_grab relies on priv->is_recording.

@matze
Copy link
Contributor Author

matze commented Aug 13, 2014

Related to #44.

@Tomago: please run the branch and check if it works. Superficial eye review is not going to make it this time.

@tfarago
Copy link
Contributor

tfarago commented Aug 13, 2014

If you tell me where libuca on the camera1 machine is. It is not in /opt

@tfarago
Copy link
Contributor

tfarago commented Aug 13, 2014

Never mind, found it.

@tfarago
Copy link
Contributor

tfarago commented Aug 13, 2014

$ uca-camera-control -c pco
Segmentation fault

@matze
Copy link
Contributor Author

matze commented Aug 13, 2014

On 08/13/14 13:24, Tomas Farago wrote:

If you tell me where libuca on the camera1 machine is. It is not in /opt

It's in /root/libuca.

@matze
Copy link
Contributor Author

matze commented Aug 13, 2014

Could you give me a bit more detailed information? For example by giving me the output of

$ gdb uca-camera-control -c pco
> r -c pco
> bt

@tfarago
Copy link
Contributor

tfarago commented Aug 13, 2014

There is tens of thousands of lines, but they all repeat this pattern:

#28482 0x00007ffff57de837 in g_object_get () from /usr/lib64/libgobject-2.0.so.0
#28483 0x00007ffff78d7036 in uca_camera_is_recording () from /usr/lib64/libuca.so.2
#28484 0x00007fffeeb0e1cf in uca_pco_camera_get_property () from /usr/lib64/uca/libucapco.so
#28485 0x00007ffff57de3ae in g_object_get_valist () from /usr/lib64/libgobject-2.0.so.

Matthias Vogelgesang and others added 2 commits March 18, 2022 11:47
This change fixes and unifies handling of different "is-recording" states. First
of all there are potentially two different states: the priv->is_recording state
from the base class and some device-specific state. Device authors can override
the "is-recording" property to provide device-specific information. This change
sets the global recording state as follows:

1. uca_camera_is_recording returns the value of ::is-recording.

2. priv->is_recording is the default state that is returned for ::is-recording
and set after successfully calling uca_camera_start_recording and
uca_camera_stop_recording.

3. uca_camera_start_recording, uca_camera_stop_recording, uca_camera_trigger
use ::is-recording to determine how to proceed.

4. For performance reasons, uca_camera_grab relies on priv->is_recording.
@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

This would require this change to uca-net (git diff, I think it says it best):

 uca_net_camera_dispose (GObject *object)
 {
-    g_object_unref (UCA_NET_CAMERA_GET_PRIVATE (object)->client);
+    UcaNetCameraPrivate *priv;
+
+    priv = UCA_NET_CAMERA_GET_PRIVATE (object);
+
     G_OBJECT_CLASS (uca_net_camera_parent_class)->dispose (object);
+    g_clear_object (&priv->client);
 }

the change from unref to clear is not so huge, but unless we release the connection after we call parent, the is-recording check will try to use the released connections, jajks. I didn't read the docs too carefully yet, maybe @matze can comment whether this will doom us completely or not. The alternative is to a) release the client in the finalize or b) do not stop recording in parent.

@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

The segfault came from both btw, the error being freed when not initialized and the connection usage after freeing it, that's fixed now.

@matze
Copy link
Contributor Author

matze commented Mar 18, 2022

I didn't read the docs too carefully yet, maybe @matze can comment whether this will doom us completely or not.

You are half-way there. g_clear_object is used to unref an object or no-op if the pointer is NULL, so that is good. But you should definitely swap the order of clearing and calling the parent disposal method.

@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

yep, but then the recording cannot be stopped in the parent, because it will try to use our freed connection.

@matze
Copy link
Contributor Author

matze commented Mar 18, 2022

Then do the obvious thing, reset the state properly when destroying the object so that calling stop will not use any freed connection.

@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

Sure, when I find 10 minutes between other things. Just FYI: it's not about the stop but about the uca_camera_is_recording, which tries to get the property from ucad.

tfarago added a commit to ufo-kit/uca-net that referenced this pull request Mar 18, 2022
@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

Done there.

tfarago added a commit to ufo-kit/uca-net that referenced this pull request Mar 18, 2022
@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

  1. or performance reasons, uca_camera_grab relies on priv->is_recording.

When I kill a concert session (no stop recording) and start it again, the state is correct but the grab will fail because of this. But sure, we cannot be checking over network all the time if the camera is recording. This should be addressed before we merge.

src/uca-camera.c Outdated
@@ -926,6 +926,7 @@ uca_camera_is_recording (UcaCamera *camera)
gboolean result;
g_return_val_if_fail (UCA_IS_CAMERA (camera), FALSE);
g_object_get (camera, "is-recording", &result, NULL);
camera->priv->is_recording = result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will I go to hell?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean you like it or I will? 😄 Anyway, it's not good yet, more on Monday...

Copy link
Contributor

Choose a reason for hiding this comment

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

Got rid of this.

@tfarago
Copy link
Contributor

tfarago commented Mar 18, 2022

This solves point 4.

@tfarago
Copy link
Contributor

tfarago commented Mar 19, 2022

Todo: make sure the property is consistent with the parameter. Right now child's property getter will not update the cached state, whereas call to is_recording will.

tfarago added a commit to ufo-kit/uca-net that referenced this pull request Mar 21, 2022
stop_recording used the property and start_recording the cached value.
Also make sure the caches are updated according to real state values.
@tfarago
Copy link
Contributor

tfarago commented Mar 21, 2022

Alright, so now the camera calls plugin getters when the construction is done to make sure that the cached states (priv->is_recording and priv->is_readout) are the ones obtained from actual devices. This way we make sure that when we construct the object we are synced with the actual device and it allows e.g. to use the net camera after client crash without restarting ucad. I am still a total rookie regarding GObject but from what I read constructed() seems like an appropriate place we can do this and the non-construct-properties do not matter since is-readout and is-recording are "computed".

Some remarks:

  • After construction, the cached value can go out-of-sync with the getter on special occasion (camera stopped recording automatically because buffer is full), but this must be detectable by the camera and/or its user code and recoverable
  • I propose to change 3. and use priv->is_recording also in trigger(), I can imagine that one wants to quickly trigger & grab

tfarago referenced this pull request in ufo-kit/uca-pco Mar 21, 2022
For the past history of this plugin refer to the libuca Git history.
tfarago added a commit to ufo-kit/uca-pco that referenced this pull request Mar 22, 2022
tfarago added a commit to ufo-kit/uca-pco that referenced this pull request Mar 22, 2022
tfarago added a commit to ufo-kit/uca-pco that referenced this pull request Mar 22, 2022
@tfarago
Copy link
Contributor

tfarago commented Mar 25, 2022

@matze, does your silence mean approval or the opposite? Or you don't like it but don't have a better solution yet? 😄

@tfarago
Copy link
Contributor

tfarago commented Mar 25, 2022

By the way, if we merge this it will probably go to the Guiness world records book for the longest open PR 😄

@matze
Copy link
Contributor Author

matze commented Mar 25, 2022

@matze, does your silence mean approval or the opposite?

There is only noise coming from me when confused ;-) so take my approval!

@tfarago tfarago merged commit 81fd70b into master Apr 1, 2022
@tfarago tfarago deleted the unify-is-recording branch April 1, 2022 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants