-
Notifications
You must be signed in to change notification settings - Fork 774
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
Implement async callback for Android mediacodec #4105
Open
trengginas
wants to merge
5
commits into
master
Choose a base branch
from
async-mediacodec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee60ba1
Implement async callback for Android mediacodec
trengginas 8b97e99
move atomic_queue to pjlib
trengginas 42b8d75
Change the interface
trengginas 0672e06
Add checks and doc.
trengginas d7b56f6
Modification based on comments
trengginas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2024 Teluu Inc. (http://www.teluu.com) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
#ifndef __ATOMIC_QUEUE_HPP__ | ||
#define __ATOMIC_QUEUE_HPP__ | ||
|
||
#include <atomic> | ||
|
||
/* Atomic queue (ring buffer) for single consumer & single producer. | ||
* | ||
* Producer invokes 'put(item)' to put an item to the back of the queue and | ||
* consumer invokes 'get(item)' to get an item from the head of the queue. | ||
* | ||
* For producer, there is write pointer 'ptrWrite' that will be incremented | ||
* every time a item is queued to the back of the queue. If the queue is | ||
* almost full (the write pointer is right before the read pointer) the | ||
* producer will forcefully discard the oldest item in the head of the | ||
* queue by incrementing read pointer. | ||
* | ||
* For consumer, there is read pointer 'ptrRead' that will be incremented | ||
* every time a item is fetched from the head of the queue, only if the | ||
* pointer is not modified by producer (in case of queue full). | ||
*/ | ||
class AtomicQueue { | ||
public: | ||
/** | ||
* Constructor | ||
*/ | ||
AtomicQueue(unsigned max_item_cnt, unsigned item_size, | ||
const char* name_); | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~AtomicQueue(); | ||
|
||
/** | ||
* Get a item from the head of the queue | ||
*/ | ||
bool get(void* item); | ||
|
||
/** | ||
* Put a item to the back of the queue | ||
*/ | ||
void put(void* item); | ||
|
||
private: | ||
unsigned maxItemCnt; | ||
unsigned itemSize; | ||
std::atomic<unsigned> ptrWrite; | ||
std::atomic<unsigned> ptrRead; | ||
char *buffer; | ||
const char *name; | ||
|
||
/* Increment read pointer, only if producer not incemented it already. | ||
* Producer may increment the read pointer if the write pointer is | ||
* right before the read pointer (buffer almost full). | ||
*/ | ||
bool inc_ptr_read_if_not_yet(unsigned old_ptr); | ||
|
||
/* Increment write pointer */ | ||
unsigned inc_ptr_write(unsigned old_ptr); | ||
|
||
AtomicQueue() {} | ||
}; | ||
|
||
#endif | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include
dir are meant to be public API, so by convention it should use a specific prefix such aspj
orpjmedia
.pj_atomic_queue
, and perhaps part of PJLIB instead of PJMEDIA, note that the implementation can still use C++.