mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-03-02 07:53:51 +08:00
OmxEncoder: new function set_state, set and wait state changed (#19906)
* free buffers after state is loaded * set_data_blocking * fix indentation * Empty commit,trigger Build
This commit is contained in:
@@ -34,7 +34,8 @@ extern ExitHandler do_exit;
|
||||
|
||||
// ***** OMX callback functions *****
|
||||
|
||||
void OmxEncoder::wait_for_state(OMX_STATETYPE state) {
|
||||
void OmxEncoder::set_state_blocking(OMX_STATETYPE state) {
|
||||
OMX_CHECK(OMX_SendCommand(this->handle, OMX_CommandStateSet, state, NULL));
|
||||
pthread_mutex_lock(&this->state_lock);
|
||||
while (this->state != state) {
|
||||
pthread_cond_wait(&this->state_cv, &this->state_lock);
|
||||
@@ -304,7 +305,7 @@ OmxEncoder::OmxEncoder(const char* filename, int width, int height, int fps, int
|
||||
// printf("profile %d level 0x%x\n", params.eProfile, params.eLevel);
|
||||
// }
|
||||
|
||||
OMX_CHECK(OMX_SendCommand(this->handle, OMX_CommandStateSet, OMX_StateIdle, NULL));
|
||||
set_state_blocking(OMX_StateIdle);
|
||||
|
||||
for (auto &buf : this->in_buf_headers) {
|
||||
OMX_CHECK(OMX_AllocateBuffer(this->handle, &buf, PORT_INDEX_IN, this,
|
||||
@@ -316,11 +317,7 @@ OmxEncoder::OmxEncoder(const char* filename, int width, int height, int fps, int
|
||||
out_port.nBufferSize));
|
||||
}
|
||||
|
||||
wait_for_state(OMX_StateIdle);
|
||||
|
||||
OMX_CHECK(OMX_SendCommand(this->handle, OMX_CommandStateSet, OMX_StateExecuting, NULL));
|
||||
|
||||
wait_for_state(OMX_StateExecuting);
|
||||
set_state_blocking(OMX_StateExecuting);
|
||||
|
||||
// give omx all the output buffers
|
||||
for (auto &buf : this->out_buf_headers) {
|
||||
@@ -593,11 +590,8 @@ void OmxEncoder::encoder_close() {
|
||||
OmxEncoder::~OmxEncoder() {
|
||||
assert(!this->is_open);
|
||||
|
||||
OMX_CHECK(OMX_SendCommand(this->handle, OMX_CommandStateSet, OMX_StateIdle, NULL));
|
||||
|
||||
wait_for_state(OMX_StateIdle);
|
||||
|
||||
OMX_CHECK(OMX_SendCommand(this->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL));
|
||||
set_state_blocking(OMX_StateIdle);
|
||||
set_state_blocking(OMX_StateLoaded);
|
||||
|
||||
for (auto &buf : this->in_buf_headers) {
|
||||
OMX_CHECK(OMX_FreeBuffer(this->handle, PORT_INDEX_IN, buf));
|
||||
@@ -607,8 +601,6 @@ OmxEncoder::~OmxEncoder() {
|
||||
OMX_CHECK(OMX_FreeBuffer(this->handle, PORT_INDEX_OUT, buf));
|
||||
}
|
||||
|
||||
wait_for_state(OMX_StateLoaded);
|
||||
|
||||
OMX_CHECK(OMX_FreeHandle(this->handle));
|
||||
|
||||
OMX_BUFFERHEADERTYPE *out_buf;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
OMX_BUFFERHEADERTYPE *buffer);
|
||||
|
||||
private:
|
||||
void wait_for_state(OMX_STATETYPE state);
|
||||
void set_state_blocking(OMX_STATETYPE state);
|
||||
static void handle_out_buf(OmxEncoder *e, OMX_BUFFERHEADERTYPE *out_buf);
|
||||
|
||||
pthread_mutex_t lock;
|
||||
|
||||
Reference in New Issue
Block a user