Skip to content

Commit

Permalink
Made transcoding correct
Browse files Browse the repository at this point in the history
  • Loading branch information
sapharow committed Feb 24, 2017
1 parent f018ca0 commit 008ae56
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
5 changes: 3 additions & 2 deletions include/transcode/coreIVVideoTranscoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace fp {
void onEOS(const omx::ComponentRef& component, uint32_t port) override;
void onError(const omx::ComponentRef& component, uint32_t errorCode) override;
void onConfigurationChanged(const omx::ComponentRef& component, uint32_t index) override;
void onFillBufferDone(const omx::ComponentRef& component) override;
void onEmptyBufferDone(const omx::ComponentRef& component) override;
void onFillBufferDone(const omx::ComponentRef& component, OMX_BUFFERHEADERTYPE* pBuffer) override;
void onEmptyBufferDone(const omx::ComponentRef& component, OMX_BUFFERHEADERTYPE* pBuffer) override;

private:
omx::TunnelRef m_Tunnel;
Expand All @@ -69,6 +69,7 @@ namespace fp {

FILE* m_File = nullptr;
std::mutex m_Mutex;
bool m_EncoderSet = false;
};

}
Expand Down
8 changes: 4 additions & 4 deletions include/transcode/openmax/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace fp {
* When a buffer passed to an output port using the fillBuffer call is returned with this callback.
* The user may then use the getOutputBuffer to retrieve the buffer
*/
virtual void onFillBufferDone(const ComponentRef& component) {}
virtual void onFillBufferDone(const ComponentRef& component, OMX_BUFFERHEADERTYPE* pBuffer) {}

/**
* When a buffer passed to an input port using the emptyBuffer call is returned with this callback.
* The user may then use the getInputBuffer to retrieve the buffer
*/
virtual void onEmptyBufferDone(const ComponentRef& component) {}
virtual void onEmptyBufferDone(const ComponentRef& component, OMX_BUFFERHEADERTYPE* pBuffer) {}

private:
ComponentRef createComponent(const String& name,
Expand All @@ -69,8 +69,8 @@ namespace fp {
static void omxEOSCallback(void *userdata, COMPONENT_T *comp, OMX_U32 data);
static void omxErrorCallback(void *userdata, COMPONENT_T *comp, OMX_U32 data);
static void omxConfChangedCallback(void *userdata, COMPONENT_T *comp, OMX_U32 data);
static void omxFillBufferDoneCallback(void *userdata, COMPONENT_T *comp);
static void omxEmptyBufferDoneCallback(void *userdata, COMPONENT_T *comp);
static void omxFillBufferDoneCallback(void *userdata, COMPONENT_T *comp, OMX_BUFFERHEADERTYPE* pBuffer);
static void omxEmptyBufferDoneCallback(void *userdata, COMPONENT_T *comp, OMX_BUFFERHEADERTYPE* pBuffer);


ILCLIENT_T* m_Client = nullptr;
Expand Down
58 changes: 40 additions & 18 deletions src/transcode/coreIVVideoTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ namespace fp {
m_File = fopen("test.h264", "wb");
}

CoreIVVideoTranscoder::~CoreIVVideoTranscoder() {
if (m_File) {
fclose(m_File);
}
m_Tunnel = nullptr;
}

static String getCompressionFormatStr(OMX_VIDEO_CODINGTYPE coding) {
switch (coding) {
case OMX_VIDEO_CodingUnused: return "Unused";
Expand Down Expand Up @@ -227,6 +220,7 @@ namespace fp {
std::lock_guard<std::mutex> lock(m_Mutex);
m_Encoder->disablePortBuffers(201);
m_Encoder->enablePortBuffers(201);
m_EncoderSet = true;
}
}

Expand All @@ -242,11 +236,20 @@ namespace fp {
printf("!!!! Callback onConfigurationChanged (%s -> index %d)\n", component->name().c_str(), index);
}

void CoreIVVideoTranscoder::onFillBufferDone(const omx::ComponentRef& component) {
void CoreIVVideoTranscoder::onFillBufferDone(const omx::ComponentRef& component, OMX_BUFFERHEADERTYPE* buf) {
printf("!!!! Callback onFillBufferDone (%s)\n", component->name().c_str());
if (buf) {
if (buf->nFilledLen) {
printf("\tencoder: filled output buffer with %u bytes of data\n", buf->nFilledLen);
fwrite(buf->pBuffer, 1, buf->nFilledLen, m_File);
buf->nFilledLen = 0;
} else {
printf("Got empty buffer!!!\n");
}
}
}

void CoreIVVideoTranscoder::onEmptyBufferDone(const omx::ComponentRef& component) {
void CoreIVVideoTranscoder::onEmptyBufferDone(const omx::ComponentRef& component, OMX_BUFFERHEADERTYPE* pBuffer) {
printf("!!!! Callback onEmptyBufferDone (%s)\n", component->name().c_str());
}

Expand Down Expand Up @@ -429,17 +432,16 @@ namespace fp {
m_Decoder->emptyBuffer(buf);
printf("\tdecoder: emptied input buffer\n");
}
#if 1
std::lock_guard<std::mutex> lock(m_Mutex);
while ( (buf = m_Encoder->getOutputBuffer(201, false)) != nullptr) {
printf("\tencoder: filling output buffer\n");
m_Encoder->fillBuffer(buf);
printf("\tencoder: filled output buffer\n");
if (buf->nFilledLen) {
fwrite(buf->pBuffer, 1, buf->nFilledLen, m_File);
buf->nFilledLen = 0;

if (m_EncoderSet) {
while ( (buf = m_Encoder->getOutputBuffer(201, false)) != nullptr ) {
printf("\tencoder: filling output buffer\n");
m_Encoder->fillBuffer(buf);
printf("\tencoder: filled output buffer\n");
}
}

#if 1
#endif

#if 0
Expand Down Expand Up @@ -467,6 +469,26 @@ namespace fp {
printf("... Supplied frame %d ................\n", i++);
}

CoreIVVideoTranscoder::~CoreIVVideoTranscoder() {

OMX_BUFFERHEADERTYPE* buf = m_Decoder->getInputBuffer(130, true);
buf->nFilledLen = 0;
buf->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN | OMX_BUFFERFLAG_EOS;
m_Decoder->emptyBuffer(buf);
if (m_EncoderSet) {
while ( (buf = m_Encoder->getOutputBuffer(201, false)) != nullptr ) {
printf("\tencoder: filling output buffer\n");
m_Encoder->fillBuffer(buf);
printf("\tencoder: filled output buffer\n");
}
}

if (m_File) {
fclose(m_File);
}
m_Tunnel = nullptr;
}

DecoderContextRef CoreIVVideoTranscoder::createDecoder() {
return std::make_shared<CoreIVDecoderContext>();
}
Expand Down
8 changes: 4 additions & 4 deletions src/transcode/openmax/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,28 @@ namespace fp {
}
}

void Client::omxFillBufferDoneCallback(void *userdata, COMPONENT_T *comp) {
void Client::omxFillBufferDoneCallback(void *userdata, COMPONENT_T *comp, OMX_BUFFERHEADERTYPE* pBuffer) {
Client* client = (Client*)userdata;
std::unique_lock<std::mutex> lock(client->m_Mutex);
auto it = client->m_Components.find(comp);
if (it != client->m_Components.end()) {
auto component = it->second.lock();
if (component) {
lock.unlock();
client->onFillBufferDone(component);
client->onFillBufferDone(component, pBuffer);
}
}
}

void Client::omxEmptyBufferDoneCallback(void *userdata, COMPONENT_T *comp) {
void Client::omxEmptyBufferDoneCallback(void *userdata, COMPONENT_T *comp, OMX_BUFFERHEADERTYPE* pBuffer) {
Client* client = (Client*)userdata;
std::unique_lock<std::mutex> lock(client->m_Mutex);
auto it = client->m_Components.find(comp);
if (it != client->m_Components.end()) {
auto component = it->second.lock();
if (component) {
lock.unlock();
client->onEmptyBufferDone(component);
client->onEmptyBufferDone(component, pBuffer);
}
}
}
Expand Down

0 comments on commit 008ae56

Please sign in to comment.