forked from havlenapetr/FFMpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ee92bd
commit bb8d6b6
Showing
2 changed files
with
88 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,89 @@ | ||
#include <android/log.h> | ||
|
||
extern "C" { | ||
|
||
#include "libavcodec/avcodec.h" | ||
#include "libavformat/avformat.h" | ||
|
||
} | ||
|
||
#include "output.h" | ||
#include "renderer.h" | ||
|
||
#define TAG "FFMpegRenderer" | ||
|
||
Renderer::Renderer() | ||
{ | ||
mQueue = new PacketQueue(); | ||
} | ||
|
||
Renderer::~Renderer() | ||
{ | ||
} | ||
|
||
bool Renderer::init(JNIEnv *env, jobject jsurface) | ||
{ | ||
if(Output::VideoDriver_register(env, jsurface) != ANDROID_SURFACE_RESULT_SUCCESS) { | ||
return false; | ||
} | ||
if(Output::AudioDriver_register() != ANDROID_AUDIOTRACK_RESULT_SUCCESS) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
PacketQueue* Renderer::queue() | ||
{ | ||
return mQueue; | ||
} | ||
|
||
bool Renderer::startAsync(const char* err) | ||
{ | ||
pthread_create(&mThread, NULL, startRendering, this); | ||
return true; | ||
} | ||
|
||
void* Renderer::startRendering(void* ptr) | ||
{ | ||
__android_log_print(ANDROID_LOG_INFO, TAG, "starting renderer thread"); | ||
Renderer* renderer = (Renderer *) ptr; | ||
renderer->mRendering = true; | ||
renderer->render(ptr); | ||
renderer->mRendering = false; | ||
__android_log_print(ANDROID_LOG_INFO, TAG, "decoder renderer ended"); | ||
} | ||
|
||
bool Renderer::render(void* ptr) | ||
{ | ||
AVPacket pPacket; | ||
|
||
while(mRendering) | ||
{ | ||
if(mQueue->get(&pPacket, true) < 0) | ||
{ | ||
mRendering = false; | ||
return false; | ||
} | ||
|
||
// Free the packet that was allocated by av_read_frame | ||
av_free_packet(&pPacket); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int Renderer::wait() | ||
{ | ||
return pthread_join(mThread, NULL); | ||
} | ||
|
||
void Renderer::stop() | ||
{ | ||
mQueue->abort(); | ||
__android_log_print(ANDROID_LOG_INFO, TAG, "waiting on end of renderer thread"); | ||
int ret = -1; | ||
if((ret = wait()) != 0) { | ||
__android_log_print(ANDROID_LOG_ERROR, TAG, "Couldn't cancel renderer: %i", ret); | ||
return; | ||
} | ||
} |
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