Skip to content

Commit

Permalink
RFC: media: Add media_request_{pin,unpin} API
Browse files Browse the repository at this point in the history
This is probably not the API we will want to add, but it
should show what semantics are needed by drivers.

The goal is to allow the OUTPUT (aka source) buffer and the
controls associated to a request to be released from the request,
and in particular return the OUTPUT buffer back to userspace,
without signalling the media request fd.

This is useful for devices that are able to pre-process
the OUTPUT buffer, therefore able to release it before
the decoding is finished. These drivers should signal
the media request fd only after the CAPTURE buffer is done.

Tested-by: John Cox <jc@kynesim.co.uk>
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
  • Loading branch information
ezequielgarcia authored and popcornmix committed Nov 25, 2024
1 parent e346788 commit 5f046c0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions drivers/media/mc/mc-request.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,38 @@ void media_request_object_complete(struct media_request_object *obj)
media_request_put(req);
}
EXPORT_SYMBOL_GPL(media_request_object_complete);

void media_request_pin(struct media_request *req)
{
unsigned long flags;

spin_lock_irqsave(&req->lock, flags);
if (WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
goto unlock;
req->num_incomplete_objects++;
unlock:
spin_unlock_irqrestore(&req->lock, flags);
}
EXPORT_SYMBOL_GPL(media_request_pin);

void media_request_unpin(struct media_request *req)
{
unsigned long flags;
bool completed = false;

spin_lock_irqsave(&req->lock, flags);
if (WARN_ON(!req->num_incomplete_objects) ||
WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
goto unlock;

if (!--req->num_incomplete_objects) {
req->state = MEDIA_REQUEST_STATE_COMPLETE;
wake_up_interruptible_all(&req->poll_wait);
completed = true;
}
unlock:
spin_unlock_irqrestore(&req->lock, flags);
if (completed)
media_request_put(req);
}
EXPORT_SYMBOL_GPL(media_request_unpin);
12 changes: 12 additions & 0 deletions include/media/media-request.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ static inline void media_request_get(struct media_request *req)
*/
void media_request_put(struct media_request *req);

void media_request_pin(struct media_request *req);

void media_request_unpin(struct media_request *req);

/**
* media_request_get_by_fd - Get a media request by fd
*
Expand Down Expand Up @@ -228,6 +232,14 @@ static inline void media_request_put(struct media_request *req)
{
}

static inline void media_request_pin(struct media_request *req)
{
}

static inline void media_request_unpin(struct media_request *req)
{
}

static inline struct media_request *
media_request_get_by_fd(struct media_device *mdev, int request_fd)
{
Expand Down

0 comments on commit 5f046c0

Please sign in to comment.