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

Streamed annotation responses #946

Open
mzur opened this issue Oct 10, 2024 · 1 comment · May be fixed by #967
Open

Streamed annotation responses #946

mzur opened this issue Oct 10, 2024 · 1 comment · May be fixed by #967
Assignees

Comments

@mzur
Copy link
Member

mzur commented Oct 10, 2024

We had a case of a long video where the request to get all video annotations ran into the memory limit. To avoid this we can send a streamed JSON response and fetch the annotations lazily in chunks. Here is a proof of concept for the VideoAnnotationController:

public function index(Request $request, $id)
{
    $video = Video::findOrFail($id);
    $this->authorize('access', $video);

    $user = $request->user();
    $session = $video->volume->getActiveAnnotationSession($user);
    $load = ['labels.label', 'labels.user'];

    if ($session) {
        return $session->getVolumeFileAnnotations($video, $user)->load($load);
    }

    $yieldAnnotations = function () use ($video, $load): \Generator {
        foreach ($video->annotations()->with($load)->lazy() as $annotation) {
            yield $annotation;
        }
    };

    return response()->streamJson($yieldAnnotations());
}

The same could be done in the ImageAnnotationController.

In the proof of concept above the streaming does not work if there is an active annotation session. The getVolumeFileAnnotations() method of an annotation session has to be updated to support streaming like that.

@mzur mzur moved this to Medium Priority in BIIGLE Roadmap Oct 10, 2024
@mzur
Copy link
Member Author

mzur commented Oct 22, 2024

Here is an example how a streamed response can be tested:

$response = $this
    ->getJson("/api/v1/videos/{$this->video->id}/annotations")
    ->assertStatus(200);

ob_start();
$response->sendContent();
$content = ob_get_clean();
$response = new \Illuminate\Testing\TestResponse(
    new \Symfony\Component\HttpFoundation\Response($content,
        $response->baseResponse->getStatusCode(),
        $response->baseResponse->headers->all()
    )
);

$response->assertJsonFragment(['frames' => [1.0]])
    ->assertJsonFragment(['points' => [[10, 20]]])
    ->assertJsonFragment(['color' => 'bada55'])
    ->assertJsonFragment(['name' => 'My label']);

@lehecht lehecht linked a pull request Nov 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Medium Priority
Development

Successfully merging a pull request may close this issue.

2 participants